Exemplo n.º 1
0
        public async Task <IActionResult> UploadAndValidatePackage(
            [FromServices] ICryptoProviderService cryptoProvider,
            [FromServices] DocumentsManager manager,
            IFormFile attachmentFile)
        {
            var result = await manager.UploadAndValidatePackageAsync(cryptoProvider, attachmentFile);

            return(Json(ApiResponse.Success(result)));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> SendToSign(
            [FromHeader] Guid personUniqueId,
            [FromQuery] string documentUniqueId,
            [FromBody] SignedDraftModel model,
            [FromServices] DocumentsManager manager, [FromServices] ICryptoProviderService cryptoProvider)
        {
            await manager.SignDocumentAsync(User.Identity.Name, personUniqueId, documentUniqueId, model.Signature, cryptoProvider);

            return(Json(new ApiResponse <bool>(true)));
        }
        public async Task <IActionResult> Post([FromBody] RegistrationRequest request,
                                               [FromServices] IAuthenticationManager authentication,
                                               [FromServices] RemoteBillingService billingService,
                                               [FromServices] IEmailConfirmationService emailConfirmationService,
                                               [FromServices] ICryptoProviderService cryptoProvider)
        {
            try {
                var value     = Convert.FromBase64String(request.InitCms);
                var xml       = new UTF8Encoding(false).GetString(value);
                var encrypted = XmlSerializationHelper.DeserializeFromXml <string>(xml);
                var decrypted = AesHelper.Decrypt(encrypted);
                var isValid   = await cryptoProvider.VerifyCMSAsync(xml, request.SignedCms);

                if (!isValid)
                {
                    return(Json(ApiResponse.Failed(ApiErrorCode.ValidationError, "Сертификат не прошел проверку")));
                }
                var signUpDateTime = new DateTime(Convert.ToInt64(decrypted));
                if ((DateTime.Now - signUpDateTime).Hours > 0)
                {
                    return(Json(ApiResponse.Failed(ApiErrorCode.AuthenticationFailed, "С момента начала авторизации прошло больше часа")));
                }
            } catch {
                return(Json(ApiResponse.Failed(ApiErrorCode.AuthenticationFailed, "Сбой дешифрации сообщения")));
            }
            await authentication.RegisterAsync(request, billingService);

            string code;
            long   userId;

            if (!request.InvitedUser)
            {
                using (var repository = new Repository <User>(_provider)) {
                    var user = repository.Get(x => x.UserName == request.UserAccount.Email).Single();
                    code = emailConfirmationService.GenerateEmailConfirmationToken(user);
                    repository.Update(user);
                    repository.Commit();
                    userId = user.Id;
                }

                var callbackUrl = Url.Action(
                    "ConfirmEmail",
                    "Registration",
                    new { userId = userId, code = code },
                    protocol: HttpContext.Request.Scheme);
                callbackUrl = callbackUrl.Replace("api/Registration/ConfirmEmail", "auth/confirmemail");
                emailConfirmationService.SendConfirmationUrl(request.UserAccount.Email, callbackUrl);
            }
            return(Json(ApiResponse.Success(true)));
        }
Exemplo n.º 4
0
        public ExchangeToStableService(ILoggerFactory loggerFactory,
                                       ApplicationDbContext db,
                                       IConfiguration configuration,
                                       IRateCache rateCache,
                                       IMemoryCache cache,
                                       ICryptoProviderService cryptoProviderService,
                                       GraftService graft)
        {
            _settings = configuration
                        .GetSection("ExchangeService")
                        .Get <ExchangeServiceConfiguration>();

            _logger                = loggerFactory.CreateLogger(nameof(ExchangeService));
            _db                    = db;
            _rateCache             = rateCache;
            _cache                 = cache;
            _cryptoProviderService = cryptoProviderService;
            _graft                 = graft;
        }
Exemplo n.º 5
0
        public ExchangeService(ILoggerFactory loggerFactory,
                               ApplicationDbContext db,
                               IConfiguration configuration,
                               IRateCache rateCache,
                               IMemoryCache cache,
                               ICryptoProviderService cryptoProviderService,
                               IGraftWalletService wallet)
        {
            _settings = configuration
                        .GetSection("PaymentService")
                        .Get <PaymentServiceConfiguration>();

            _logger                = loggerFactory.CreateLogger(nameof(ExchangeService));
            _db                    = db;
            _rateCache             = rateCache;
            _cache                 = cache;
            _cryptoProviderService = cryptoProviderService;
            _wallet                = wallet;
        }
        public async Task <IActionResult> GetSubjectData([FromBody] RegistrationCmsRequest request,
                                                         [FromServices] ICryptoProviderService cryptoProvider)
        {
            var signedCms = CertificatesHelper.DecodeCmsFromString(request.Cms);
            var OSCPval   = await cryptoProvider.VerifyExpiredCert(request.Cms);

            if (OSCPval)
            {
                return(Json(ApiResponse.Failed(ApiErrorCode.ValidationError, "Отозванный сертификат невозможно использовать в системе")));
            }

            if (signedCms.Certificates.Count == 0)
            {
                return(Json(ApiResponse.Failed(ApiErrorCode.ResourceNotFound, "У сертификата отсутствуют данные")));
            }
            var certificate = signedCms.Certificates[0];
            var data        = CertificatesHelper.ReadX509CertificateCommonData(certificate);

            return(Json(ApiResponse.Success(data)));
        }