Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        public MainForm()
        {
            InitializeComponent();

            this.myId = UserIdentity.GetIdOfCurrentUser();

            this.userKeypair = new KeyPair();
            this.textBoxYourUniqueId.Text = this.myId.ToString();

            this.delegationToken = new DelegationToken();
        }
Esempio n. 3
0
        private void buttonPickMasterKeys_Click(object sender, EventArgs e)
        {
            string filename = FileDialogs.AskUserForFileNameToOpen();
            if (filename != null)
            {
                MasterKeys masterKeys = XmlFile.ReadFile<MasterKeys>(filename);

                this.masterKeypair = new KeyPair();
                this.masterKeypair.Public = Convert.FromBase64String(masterKeys.MasterKeyPublicKey);
                this.masterKeypair.Private = Convert.FromBase64String(masterKeys.MasterKeyPrivateKey);
            }
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        private void ReadUserKeys(string filename)
        {
            KeyCollection keys = XmlFile.ReadFile<KeyCollection>(filename);

            this.keyPair = new KeyPair();
            this.keyPair.Public = Convert.FromBase64String(keys.PublicKey);
            this.keyPair.Private = Convert.FromBase64String(keys.PrivateKey);

            this.signingKeys = Convert.FromBase64String(keys.SignKeys);

            this.labelKeyStatus.Text = "Keys loaded";
        }
Esempio n. 6
0
        private void buttonPickMasterKeys_Click(object sender, EventArgs e)
        {
            string filename = FileDialogs.AskUserForFileNameToOpen();
            if (filename != null)
            {
                KeyCollection keys = XmlFile.ReadFile<KeyCollection>(filename);

                this.keyPair = new KeyPair();
                this.keyPair.Public = Convert.FromBase64String(keys.PublicKey);
                this.keyPair.Private = Convert.FromBase64String(keys.PrivateKey);

                if (keys.MasterPrivateKey != null && keys.MasterPublicKey != null)
                {
                    this.masterKeypair = new KeyPair();
                    this.masterKeypair.Public = Convert.FromBase64String(keys.MasterPublicKey);
                    this.masterKeypair.Private = Convert.FromBase64String(keys.MasterPrivateKey);
                    this.labelKeyStatus.Text = "Keys including MASTER KEYS loaded";
                }
                else
                {
                    this.labelKeyStatus.Text = "Keys but NOT master keys loaded";
                }
            }
        }
Esempio n. 7
0
        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);
            }
        }