IRestRequest IRequestBuilder.SetUserKeyPair(ApiUserKeyPair apiUserKeyPair)
        {
            RestRequest request = new RestRequest(ApiConfig.ApiPostUserKeyPair, Method.POST);

            SetGeneralRestValues(request, true, apiUserKeyPair);
            return(request);
        }
Ejemplo n.º 2
0
        public Node EnableRoomEncryption(EnableRoomEncryptionRequest request)
        {
            _client.Executor.CheckApiServerVersion();

            #region Parameter Validation

            request.MustNotNull(nameof(request));
            request.DataRoomRescueKeyPassword.MustNotNullOrEmptyOrWhitespace(nameof(request.DataRoomRescueKeyPassword), true);
            request.Id.MustPositive(nameof(request.Id));

            #endregion

            ApiUserKeyPair apiDataRoomRescueKey = null;
            if (request.DataRoomRescueKeyPassword != null)
            {
                try {
                    UserKeyPair cryptoPair = Crypto.Sdk.Crypto.GenerateUserKeyPair(request.DataRoomRescueKeyPassword);
                    apiDataRoomRescueKey = UserMapper.ToApiUserKeyPair(cryptoPair);
                } catch (CryptoException ce) {
                    DracoonClient.Log.Debug(Logtag, $"Generation of user key pair failed with '{ce.Message}'!");
                    throw new DracoonCryptoException(CryptoErrorMapper.ParseCause(ce), ce);
                }
            }

            ApiEnableRoomEncryptionRequest apiEnableRoomEncryptionRequest =
                RoomMapper.ToApiEnableRoomEncryptionRequest(request, apiDataRoomRescueKey);
            IRestRequest restRequest = _client.Builder.PutEnableRoomEncryption(request.Id, apiEnableRoomEncryptionRequest);
            ApiNode      result      = _client.Executor.DoSyncApiCall <ApiNode>(restRequest, RequestType.PutEnableRoomEncryption);
            return(NodeMapper.FromApiNode(result));
        }
        public void SetUserKeyPair()
        {
            _client.Executor.CheckApiServerVersion();
            UserKeyPair    cryptoPair     = GenerateNewUserKeyPair(_client.EncryptionPassword);
            ApiUserKeyPair apiUserKeyPair = UserMapper.ToApiUserKeyPair(cryptoPair);
            IRestRequest   request        = _client.Builder.SetUserKeyPair(apiUserKeyPair);

            _client.Executor.DoSyncApiCall <VoidResponse>(request, RequestType.SetUserKeyPair);
        }
Ejemplo n.º 4
0
        internal static UserKeyPair FromApiUserKeyPair(ApiUserKeyPair apiUserKeyPair)
        {
            UserKeyPair userKeyPair = new UserKeyPair {
                UserPublicKey  = FromApiUserPublicKey(apiUserKeyPair.PublicKeyContainer),
                UserPrivateKey = FromApiUserPrivateKey(apiUserKeyPair.PrivateKeyContainer)
            };

            return(userKeyPair);
        }
Ejemplo n.º 5
0
        internal static ApiUserKeyPair ToApiUserKeyPair(UserKeyPair userKeyPair)
        {
            ApiUserKeyPair apiUserKeyPair = new ApiUserKeyPair {
                PublicKeyContainer  = ToApiUserPublicKey(userKeyPair.UserPublicKey),
                PrivateKeyContainer = ToApiUserPrivateKey(userKeyPair.UserPrivateKey)
            };

            return(apiUserKeyPair);
        }
        internal UserKeyPair GetAndCheckUserKeyPair()
        {
            try {
                IRestRequest   request     = _client.Builder.GetUserKeyPair();
                ApiUserKeyPair result      = _client.Executor.DoSyncApiCall <ApiUserKeyPair>(request, RequestType.GetUserKeyPair);
                UserKeyPair    userKeyPair = UserMapper.FromApiUserKeyPair(result);
                if (Crypto.Sdk.Crypto.CheckUserKeyPair(userKeyPair, _client.EncryptionPassword))
                {
                    return(userKeyPair);
                }

                throw new DracoonCryptoException(DracoonCryptoCode.INVALID_PASSWORD_ERROR);
            } catch (CryptoException ce) {
                DracoonClient.Log.Debug(Logtag, $"Check of user key pair failed with '{ce.Message}'!");
                throw new DracoonCryptoException(CryptoErrorMapper.ParseCause(ce), ce);
            }
        }
Ejemplo n.º 7
0
        public void FromApiUserKeyPair()
        {
            // ARRANGE
            UserKeyPair expected = FactoryUser.UserKeyPair;

            ApiUserKeyPair param = new ApiUserKeyPair {
                PrivateKeyContainer = new ApiUserPrivateKey {
                    PrivateKey = expected.UserPrivateKey.PrivateKey,
                    Version    = expected.UserPrivateKey.Version
                },
                PublicKeyContainer = new ApiUserPublicKey {
                    PublicKey = expected.UserPublicKey.PublicKey,
                    Version   = expected.UserPublicKey.Version
                }
            };

            // ACT
            UserKeyPair actual = UserMapper.FromApiUserKeyPair(param);

            // ASSERT
            Assert.Equal(expected, actual, new UserKeyPairComparer());
        }
Ejemplo n.º 8
0
        public void ToApiUserKeyPair()
        {
            // ARRANGE
            ApiUserKeyPair expected = FactoryUser.ApiUserKeyPair;

            UserKeyPair param = new UserKeyPair {
                UserPrivateKey = new UserPrivateKey {
                    PrivateKey = expected.PrivateKeyContainer.PrivateKey,
                    Version    = expected.PrivateKeyContainer.Version
                },
                UserPublicKey = new UserPublicKey {
                    PublicKey = expected.PublicKeyContainer.PublicKey,
                    Version   = expected.PublicKeyContainer.Version
                }
            };

            // ACT
            ApiUserKeyPair actual = UserMapper.ToApiUserKeyPair(param);

            // ASSERT
            Assert.Equal(expected, actual, new ApiUserKeyPairComparer());
        }
Ejemplo n.º 9
0
        internal static ApiEnableRoomEncryptionRequest ToApiEnableRoomEncryptionRequest(EnableRoomEncryptionRequest enableRoomEncryptionRequest,
                                                                                        ApiUserKeyPair dataRoomRescueKey)
        {
            ApiEnableRoomEncryptionRequest apiEnableRoomEncryptionRequest = new ApiEnableRoomEncryptionRequest {
                IsEncryptionEnabled   = enableRoomEncryptionRequest.IsEncryptionEnabled,
                UseDataSpaceRescueKey = enableRoomEncryptionRequest.UseDataSpaceRescueKey,
                DataRoomRescueKey     = dataRoomRescueKey
            };

            return(apiEnableRoomEncryptionRequest);
        }