private void buttonGenerateAndSaveMasterKeypair_Click(object sender, EventArgs e) { try { IGatewayService gwProxy = GetServiceProxy(); gwProxy.InitializeSystem(this.myId); IPreService proxy = GetPreProxy(); this.masterKeypair = proxy.GenerateKeyPair(); string filename = FileDialogs.AskUserForFileNameToSaveIn(); if (!string.IsNullOrEmpty(filename)) { if (!Path.HasExtension(filename)) { filename = filename + ".xml"; } MasterKeys mk = new MasterKeys(); mk.MasterKeyPublicKey = Convert.ToBase64String(this.masterKeypair.Public); mk.MasterKeyPrivateKey = Convert.ToBase64String(this.masterKeypair.Private); XmlFile.WriteFile(mk, filename); MessageBox.Show("Done"); } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); Logger.LogError("Error generating master keypair", ex); } }
private void buttonUpdateSubRole_Click(object sender, EventArgs e) { try { if (this.treeViewRoles.SelectedNode != null && this.treeViewRoles.SelectedNode.Tag is RoleDescription && this.treeViewRoles.SelectedNode.Parent != null) { RoleDescription selectedRole = (RoleDescription)this.treeViewRoles.SelectedNode.Tag; RoleDescription parentRole = (RoleDescription)this.treeViewRoles.SelectedNode.Parent.Tag; CustomizeRoleDialog dialog = new CustomizeRoleDialog(selectedRole, "Update the role " + selectedRole.Name.GetString()); DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { IPreService preProxy = GetPreProxy(); dialog.Role.Name = preProxy.Encrypt(this.keyPair.Public, dialog.Role.Name); IGatewayService proxy = GetServiceProxy(); proxy.UpdateSubRole(this.myId, parentRole.Id, dialog.Role); buttonRefreshRolesAndUsers_Click(this, EventArgs.Empty); } } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); Logger.LogError("Error updating sub-role user", ex); } }
private void buttonGenerateAndSaveMasterKeypair_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(this.textBoxDOUsername.Text)) { MessageBox.Show("You must enter a DO user name"); return; } if (string.IsNullOrEmpty(this.textBoxDORoleName.Text)) { MessageBox.Show("You must enter a DO role name"); return; } IPreService proxy = GetPreProxy(); this.masterKeypair = proxy.GenerateKeyPair(); SignKeys doSignKeyPair = DataSigner.GenerateSignKeyPair(); proxy = GetPreProxy(); byte[] doUserName = proxy.Encrypt(this.masterKeypair.Public, this.textBoxDOUsername.Text.GetBytes()); proxy = GetPreProxy(); byte[] doRoleName = proxy.Encrypt(this.masterKeypair.Public, this.textBoxDORoleName.Text.GetBytes()); IGatewayService gwProxy = GetServiceProxy(); gwProxy.InitializeSystem(this.myId, doUserName, doRoleName, doSignKeyPair.PublicOnly); string filename = FileDialogs.AskUserForFileNameToSaveIn(); if (!string.IsNullOrEmpty(filename)) { if (!Path.HasExtension(filename)) { filename = filename + ".xml"; } KeyCollection keys = new KeyCollection(); keys.MasterPublicKey = Convert.ToBase64String(this.masterKeypair.Public); keys.MasterPrivateKey = Convert.ToBase64String(this.masterKeypair.Private); keys.PrivateKey = keys.MasterPrivateKey; keys.PublicKey = keys.MasterPublicKey; keys.SignKeys = Convert.ToBase64String(doSignKeyPair.PublicAndPrivate); XmlFile.WriteFile(keys, filename); this.labelKeyStatus.Text = "Keys including MASTER KEYS loaded"; MessageBox.Show("Done"); } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); Logger.LogError("Error generating master keypair", ex); } }
private static byte[] ReencryptToUser(User user, byte[] value) { if (user.DelegationToken != null) // can be null if user is DO, then just return the original ciphertext { IPreService preProxy = CreatePreProxy(); return(preProxy.Reencrypt(user.DelegationToken.ToUser, value)); } return(value); }
private void buttonUploadNow_Click(object sender, EventArgs e) { try { if (this.listBoxUploadKeywords.Items.Count == 0) { MessageBox.Show("At least one keyword must be associated with the data before it is uploaded"); return; } if (this.keyPair == null) { MessageBox.Show("You must load user keys first"); return; } if (this.rolesUserControlUploadData.SelectedRoles.Count == 0) { MessageBox.Show("You must select at least one role which should have access to the uploaded data"); return; } byte[] fileContent = File.ReadAllBytes(this.labelUploadData.Text); AesEncryptionInfo encryptionInfo = SymmetricEncryptor.GenerateSymmetricKeyInfo(); byte[] fileCiphertext = SymmetricEncryptor.Encrypt(fileContent, encryptionInfo); IPreService preProxy = CreatePreProxy(); byte[] encSymIv = preProxy.Encrypt(this.keyPair.Public, encryptionInfo.IV); preProxy = CreatePreProxy(); byte[] encSymKey = preProxy.Encrypt(this.keyPair.Public, encryptionInfo.Key); byte[] name = SymmetricEncryptor.Encrypt(Path.GetFileName(this.labelUploadData.Text).GetBytes(), encryptionInfo); DataEntity entity = new DataEntity(); entity.Attributes = CollectAndEncryptAttributes(encryptionInfo); entity.Payload = new FilePayload(name, fileCiphertext); entity.AesInfo = new AesEncryptionInfo(encSymKey, encSymIv); entity.Id = Guid.NewGuid(); entity.Signature = DataSigner.Sign(entity, this.signingKeys); IGatewayService proxy = CreateServiceProxy(); proxy.CreateDataEntities(this.myId, this.rolesUserControlUploadData.SelectedRoles, new[] { entity }); MessageBox.Show("Done uploading"); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); Logger.LogError("Error preparing and uploading data to server", ex); } }
private void buttonGenerateKeypairsForUser_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(this.textBoxNewUserId.Text)) { MessageBox.Show("You must enter a username"); return; } this.newUserId = GuidCreator.CreateGuidFromString(this.textBoxNewUserId.Text); if (this.masterKeypair == null) { MessageBox.Show("You must load master key pair first"); return; } string filename = FileDialogs.AskUserForFileNameToSaveIn(); if (!string.IsNullOrEmpty(filename)) { if (!Path.HasExtension(filename)) { filename = filename + ".xml"; } this.signKeyPair = DataSigner.GenerateSignKeyPair(); IPreService proxy = GetPreProxy(); this.userKeypair = proxy.GenerateKeyPair(); proxy = GetPreProxy(); this.delegationToken.ToUser = proxy.GenerateDelegationKey(this.masterKeypair.Private, this.userKeypair.Public); IGatewayService gateWayproxy = GetServiceProxy(); gateWayproxy.RegisterUser(this.myId, this.newUserId, this.delegationToken, this.signKeyPair.PublicOnly); UserKeys uk = new UserKeys(); uk.MasterKeyPublicKey = Convert.ToBase64String(this.masterKeypair.Public); uk.UserPrivateKey = Convert.ToBase64String(this.userKeypair.Private); uk.UserSignKeys = Convert.ToBase64String(this.signKeyPair.PublicAndPrivate); XmlFile.WriteFile(uk, filename); MessageBox.Show("Done"); } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); Logger.LogError("Error generating user keypair", ex); } }
public byte[] GenerateDelegationKey(byte[] privateKeyForDelegator, byte[] publicKeyForDelegatee) { try { IPreService proxy = CreateProxy(); return(proxy.GenerateDelegationKey(privateKeyForDelegator, publicKeyForDelegatee)); } catch (Exception e) { Logger.LogError("Error generating delegation key", e); throw; } }
public byte[] Encrypt(byte[] publicKey, byte[] plaintext) { try { IPreService proxy = CreateProxy(); return(proxy.Encrypt(publicKey, plaintext)); } catch (Exception e) { Logger.LogError("Error encrypting", e); throw; } }
public KeyPair GenerateKeyPair() { try { IPreService proxy = CreateProxy(); return(proxy.GenerateKeyPair()); } catch (Exception e) { Logger.LogError("Error generating key pair", e); throw; } }
public DateTime GetServiceStartTime() { try { IPreService proxy = CreateProxy(); return(proxy.GetServiceStartTime()); } catch (Exception e) { Logger.LogError("Error getting service start time", e); throw; } }
public byte[] Reencrypt(byte[] delegationKey, byte[] cipherText) { try { IPreService proxy = CreateProxy(); return(proxy.Reencrypt(delegationKey, cipherText)); } catch (Exception e) { Logger.LogError("Error reencrypting", e); throw; } }
public byte[] Decrypt(byte[] privateKey, byte[] ciphertext) { try { IPreService proxy = CreateProxy(); return(proxy.Decrypt(privateKey, ciphertext)); } catch (Exception e) { Logger.LogError("Error decrypting", e); throw; } }
private void buttonKillPreService_Click(object sender, EventArgs e) { try { IPreService preService = GetPreProxy(); preService.ResetLibPre(); MessageBox.Show("Done"); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); Logger.LogError("Error killing pre service", ex); } }
private void buttonGetServiceStartTime_Click(object sender, EventArgs e) { try { IPreService preService = GetPreProxy(); DateTime startTime = preService.GetServiceStartTime(); MessageBox.Show("Start time: " + startTime); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); Logger.LogError("Error getting pre service start time", ex); } }
private void buttonUploadNow_Click(object sender, EventArgs e) { try { if (this.listBoxUploadKeywords.Items.Count == 0) { MessageBox.Show("At least one keyword must be associated with the data before it is uploaded"); return; } if (!this.userkeysLoaded) { MessageBox.Show("You must load user keys first"); return; } byte[] fileContent = File.ReadAllBytes(this.labelUploadData.Text); AesEncryptionInfo encryptionInfo = SymmetricEncryptor.GenerateSymmetricKeyInfo(); byte[] fileCiphertext = SymmetricEncryptor.Encrypt(fileContent, encryptionInfo); IPreService preProxy = CreatePreProxy(); byte[] encSymIv = preProxy.Encrypt(this.masterPublicKey, encryptionInfo.IV); preProxy = CreatePreProxy(); byte[] encSymKey = preProxy.Encrypt(this.masterPublicKey, encryptionInfo.Key); byte[] name = SymmetricEncryptor.Encrypt(Path.GetFileName(this.labelUploadData.Text).GetBytes(), encryptionInfo); DataEntity entity = new DataEntity(); entity.Attributes = CollectAndEncryptAttributes(encryptionInfo); entity.Payload = new FilePayload(name, fileCiphertext); entity.AesInfo = new AesEncryptionInfo(encSymKey, encSymIv); entity.Id = Guid.NewGuid(); // perhaps base guid on the file path?? entity.Signature = DataSigner.Sign(entity, this.userSignKeys); IGatewayService proxy = CreateServiceProxy(); proxy.InsertData(GetUserIdentity(), entity); MessageBox.Show("Done uploading"); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); Logger.LogError("Error preparing and uploading data to server", ex); } }
private void buttonCreateSubRole_Click(object sender, EventArgs e) { try { if (this.treeViewRoles.SelectedNode != null && this.treeViewRoles.SelectedNode.Tag is RoleDescription) { RoleDescription selectedRole = (RoleDescription)this.treeViewRoles.SelectedNode.Tag; IGatewayService proxy = GetServiceProxy(); IList <DataEntity> dataEntities = proxy.GetDataEntitiesForRole(this.myId, selectedRole.Id); DecryptDataEntities(dataEntities); CustomizeRoleDialog dialog = new CustomizeRoleDialog("Create new subrole from " + selectedRole.Name.GetString()); dialog.SetDataEntities(dataEntities); DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { Role newRole = dialog.Role; newRole.Id = Guid.NewGuid(); IPreService preProxy = GetPreProxy(); newRole.Name = preProxy.Encrypt(this.keyPair.Public, newRole.Name); if (newRole.IsRoot) { newRole.Users.Add(this.myId); } proxy = GetServiceProxy(); proxy.CreateSubRole(this.myId, selectedRole.Id, newRole); buttonRefreshRolesAndUsers_Click(this, EventArgs.Empty); } } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); Logger.LogError("Error creating sub-role user", ex); } }
private DataEntity ReencryptDataEntityMetadata(DataEntity dataEntity, Guid userId) { byte[] delegationKey = GetDelegationKey(userId); DataEntity reencryptedEntity = new DataEntity(); IPreService proxy = CreatePreProxy(); byte[] reencryptedIV = proxy.Reencrypt(delegationKey, dataEntity.AesInfo.IV); proxy = CreatePreProxy(); byte[] reencryptedKey = proxy.Reencrypt(delegationKey, dataEntity.AesInfo.Key); reencryptedEntity.AesInfo = new AesEncryptionInfo(reencryptedKey, reencryptedIV); reencryptedEntity.Attributes = dataEntity.Attributes; reencryptedEntity.Payload = dataEntity.Payload; reencryptedEntity.Id = dataEntity.Id; return(reencryptedEntity); }
private void BuildUserTree(TreeNode rootNode, IEnumerable <RoleDescription> roles) { foreach (RoleDescription role in roles) { IPreService preProxy = GetPreProxy(); role.Name = preProxy.Decrypt(this.keyPair.Private, role.Name); TreeNode node = new TreeNode(role.Name.GetString(), 0, 0); node.Tag = role; rootNode.Nodes.Add(node); BuildUserTree(node, role.ChildRoles); foreach (UserDescription user in role.Users) { preProxy = GetPreProxy(); user.Name = preProxy.Decrypt(this.keyPair.Private, user.Name); TreeNode userNode = new TreeNode(user.Name.GetString(), 1, 1); userNode.Tag = user; node.Nodes.Add(userNode); } } }
private bool RefreshRoles(RolesUserControl uc) { try { IGatewayService proxy = CreateServiceProxy(); IList <RoleClientInfo> roles = proxy.GetMyImmediateRoles(this.myId); foreach (RoleClientInfo role in roles) { IPreService preService = CreatePreProxy(); role.Name = preService.Decrypt(this.keyPair.Private, role.Name); } uc.InsertRoles(roles); return(true); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); Logger.LogError("Error refreshing roles", ex); } return(false); }