Пример #1
0
        public MainForm()
        {
            InitializeComponent();

            this.myId = UserIdentity.GetIdOfCurrentUser();

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

            this.delegationToken = new DelegationToken();
        }
Пример #2
0
        private byte[] GetDelegationKey(Guid userId)
        {
            DelegationToken delegationToken = this.tokenStorage.FindDelegationToken(userId);

            if (delegationToken == null)
            {
                throw new InvalidOperationException("No proxy encryption delegation token was found for the user");
            }

            return(delegationToken.ToUser);
        }
Пример #3
0
        public void RegisterUser(Guid dataOwnerId, Guid userId, DelegationToken token, byte[] signPublicKey)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }
            if (token.ToUser == null)
            {
                throw new ArgumentNullException("token");
            }
            if (userId == Guid.Empty)
            {
                throw new ArgumentException("userId");
            }


            AssertInitializationAndCorrectDoId(dataOwnerId);

            this.tokenStorage.RegisterUser(userId, token, signPublicKey);
        }
Пример #4
0
        public void RegisterUser(Guid userId, DelegationToken token, byte[] signPublicKey)
        {
            LoadMetadata();

            UserMetadata        md;
            List <UserMetadata> mds = this.metadata.UserMetadata.Where(m => m.UserId == userId).ToList();

            if (mds.Count == 1)
            {
                md = mds[0];
            }
            else
            {
                md = new UserMetadata();
                this.metadata.UserMetadata.Add(md);
            }

            md.UserId          = userId;
            md.DelegationToken = Convert.ToBase64String(token.ToUser);
            md.SignPublicKey   = Convert.ToBase64String(signPublicKey);

            SaveMetadata();
        }
Пример #5
0
        private void buttonCreateUser_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.treeViewRoles.SelectedNode == null ||
                    !(this.treeViewRoles.SelectedNode.Tag is RoleDescription))
                {
                    return;
                }

                if (string.IsNullOrEmpty(this.textBoxNewUserName.Text))
                {
                    MessageBox.Show("You must enter a username");
                    return;
                }
                Guid newUserId = GuidCreator.CreateGuidFromString(this.textBoxNewUserName.Text);

                if (this.masterKeypair == null && this.keyPair == null)
                {
                    MessageBox.Show("You must load your key pair first");
                    return;
                }

                string filename = FileDialogs.AskUserForFileNameToSaveIn();
                if (!string.IsNullOrEmpty(filename))
                {
                    if (!Path.HasExtension(filename))
                    {
                        filename = filename + ".xml";
                    }

                    SignKeys        userSignKeyPair = DataSigner.GenerateSignKeyPair();
                    IPreService     proxy;
                    KeyPair         userKeypair;
                    DelegationToken userDelegationToken;

                    if (this.masterKeypair != null)
                    {
                        proxy       = GetPreProxy();
                        userKeypair = proxy.GenerateKeyPair();

                        userDelegationToken = new DelegationToken();
                        proxy = GetPreProxy();
                        userDelegationToken.ToUser = proxy.GenerateDelegationKey(this.masterKeypair.Private, userKeypair.Public);
                    }
                    else
                    {
                        userKeypair         = this.keyPair; // I am not a DO, so when creating a new user then reuse my key
                        userDelegationToken = null;         // I do not know my own delegation key. The server will put it in for me.
                    }

                    proxy = GetPreProxy();
                    byte[] username = proxy.Encrypt(this.keyPair.Public, this.textBoxNewUserName.Text.GetBytes());

                    User user = new User();
                    user.DelegationToken = userDelegationToken;
                    user.Id            = newUserId;
                    user.Name          = username;
                    user.SignPublicKey = userSignKeyPair.PublicOnly;


                    RoleDescription role         = (RoleDescription)this.treeViewRoles.SelectedNode.Tag;
                    IGatewayService gateWayproxy = GetServiceProxy();
                    gateWayproxy.CreateUser(this.myId, role.Id, user);


                    KeyCollection uk = new KeyCollection();
                    uk.PublicKey  = Convert.ToBase64String(this.keyPair.Public); // use original DO public key
                    uk.PrivateKey = Convert.ToBase64String(userKeypair.Private);
                    uk.SignKeys   = Convert.ToBase64String(userSignKeyPair.PublicAndPrivate);

                    XmlFile.WriteFile(uk, filename);

                    buttonRefreshRolesAndUsers_Click(this, EventArgs.Empty);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                Logger.LogError("Error generating user keypair", ex);
            }
        }
Пример #6
0
 public void RegisterUser(Guid dataOwnerId, Guid userId, DelegationToken token, byte[] signPublicKey)
 {
     this.gw.RegisterUser(dataOwnerId, userId, token, signPublicKey);
 }
Пример #7
0
 public void RegisterUser(Guid dataOwnerId, Guid userId, DelegationToken token, byte[] signPublicKey)
 {
     InvokeWithErrorHandling(() => this.Channel.RegisterUser(dataOwnerId, userId, token, signPublicKey));
 }