Exemple #1
0
        public RootUserKeys GetRootUserKeys(int userId)
        {
            var r = _db_main.Table <RootUserKeys>().FirstOrDefault(x => x.UserId == userId);

            if (r == null)
            {
                return(null);
            }

            r.UserRootPrivateKeys = UserRootPrivateKeys.Decode(DecryptAndVerify(r.UserRootPrivateKeys_encrypted, r.UserRootPrivateKeys_hmac, r.Id, EncryptedFieldIds.RootUserKeys_UserRootPrivateKeys));
            //       WriteToLog_deepDetail($"decrypted RootUserKeys '{k.Id}'");
            return(r);
        }
Exemple #2
0
        public void AddLocalUser(string aliasId)
        {
            try
            {
                UserRootPrivateKeys.CreateUserId(1, 1, TimeSpan.FromDays(365 * 3 + 10), _drpPeerEngine.CryptoLibrary, out var userRootPrivateKeys, out var userId);
                var userCertificateWithPrivateKey = UserCertificate.GenerateKeyPairsAndSignAtSingleDevice(_drpPeerEngine.CryptoLibrary, userId, userRootPrivateKeys, DateTime.UtcNow.AddHours(-1), DateTime.UtcNow.AddYears(3));
                userCertificateWithPrivateKey.AssertHasPrivateKey();
                userCertificateWithPrivateKey.AssertIsValidNow(_drpPeerEngine.CryptoLibrary, userId, _drpPeerEngine.DateTimeNowUtc);

                var u = new User
                {
                    AliasID              = aliasId,
                    UserID               = userId,
                    OwnerLocalUserId     = 0,
                    LocalUserCertificate = userCertificateWithPrivateKey,
                };
                _db.InsertUser(u);

                var ruk = new RootUserKeys
                {
                    UserId = u.Id,
                    UserRootPrivateKeys = userRootPrivateKeys
                };
                _db.InsertRootUserKeys(ruk);

                RegistrationId.CreateNew(_drpPeerEngine.CryptoLibrary, out var regPrivateKey, out var registrationId);

                var regId = new UserRegistrationID
                {
                    UserId                 = u.Id,
                    RegistrationId         = registrationId,
                    RegistrationPrivateKey = regPrivateKey
                };
                _db.InsertUserRegistrationID(regId);

                var newLocalUser = new LocalUser
                {
                    User                = u,
                    RootUserKeys        = ruk,
                    UserRegistrationIDs = new List <UserRegistrationID> {
                        regId
                    }
                };
                LocalUsers.Add(u.Id, newLocalUser);
                newLocalUser.CreateLocalDrpPeers(this);
            }
            catch (Exception exc)
            {
                HandleException("error when adding new local user: ", exc);
            }
        }
Exemple #3
0
 public DrpTesterPeerApp(DrpPeerEngine drpPeerEngine, LocalDrpPeerConfiguration drpPeerRegistrationConfiguration, UserRootPrivateKeys userRootPrivateKeys = null, UserId userId = null)
 {
     DrpPeerRegistrationConfiguration = drpPeerRegistrationConfiguration;
     DrpPeerEngine = drpPeerEngine;
     if (userRootPrivateKeys == null || userId == null)
     {
         UserRootPrivateKeys.CreateUserId(3, 2, TimeSpan.FromDays(367), DrpPeerEngine.CryptoLibrary, out UserRootPrivateKeys, out UserId);
     }
     else
     {
         UserId = userId;
         UserRootPrivateKeys = userRootPrivateKeys;
     }
     UserCertificateWithPrivateKey = UserCertificate.GenerateKeyPairsAndSignAtSingleDevice(DrpPeerEngine.CryptoLibrary, UserId, UserRootPrivateKeys, DateTime.UtcNow.AddHours(-1), DateTime.UtcNow.AddYears(1));
 }