コード例 #1
0
ファイル: MainForm.cs プロジェクト: iqman/MACMSC
        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);
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: iqman/MACMSC
        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);
            }
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: iqman/MACMSC
        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);
            }
        }
コード例 #5
0
ファイル: PreService.svc.cs プロジェクト: iqman/MACMSC
 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;
     }
 }
コード例 #6
0
ファイル: MainForm.cs プロジェクト: iqman/MACMSC
        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);
            }
        }