Пример #1
0
        public string ActivateLicense(string token, string payload)
        {
            ActivationResult result = new ActivationResult();
            KeyPair keyPair = _keyPairService.GetClientKeyPair();
            Debug.WriteLine(keyPair.PrivateKey);
            Debug.WriteLine(keyPair.PublicKey);

            if (!_controlService.ValidateClientToken(token))
            {
                result.WasOperationSuccessful = false;
                result.WasRequestValid = false;
                result.ActivationSuccessful = false;

                return SerializeAndEncryptResult(result, keyPair);
            }

            result.WasRequestValid = true;

            result.ServiceId = _masterService.GetMasterServiceData().ServiceId;

            string decryptedPayload = _asymmetricEncryptionProvider.DecryptPublic(payload, keyPair);
            LicenseActivationPayload activationPayload = _serializationProvider.Deserialize<LicenseActivationPayload>(decryptedPayload);

            if (!_keyService.AuthorizeLicenseForActivation(activationPayload.LicenseKey, activationPayload.ServiceLicense))
            {
                result.WasOperationSuccessful = false;
                result.ActivationSuccessful = false;
            }
            else
            {
                Guid? activiationtoken = _keyService.ActivateLicenseKey(activationPayload.LicenseKey, activationPayload.Token,
                                                                                                         activationPayload.ServiceLicense);
                if (activiationtoken.HasValue)
                {
                    _activationLogService.LogActiviation(activationPayload.LicenseKey, ActivationResults.Success, GetIpAddress());

                    result.ActivationToken = activiationtoken;
                    result.WasOperationSuccessful = true;
                    result.ActivationSuccessful = true;
                }
                else
                {
                    _activationLogService.LogActiviation(activationPayload.LicenseKey, ActivationResults.ActivationFailure, GetIpAddress());

                    result.WasOperationSuccessful = false;
                    result.ActivationSuccessful = false;
                }
            }

            return SerializeAndEncryptResult(result, keyPair);
        }
Пример #2
0
        private string SerializeAndEncryptResult(ActivationResult result, KeyPair keyPair)
        {
            string serializedResult = _serializationProvider.Serialize(result);
            string encryptedResult = _asymmetricEncryptionProvider.EncryptPrivate(serializedResult, keyPair);

            return encryptedResult;
        }