public IActionResult Register([FromBody] CmsRequest loginRequest)
        {
            var cert = PkiProvider.IssueCertificate(loginRequest.Cms);

            var pem = PemHelper.ToPem("CERTIFICATE", cert.GetEncoded());

            return(Ok(pem));
        }
Beispiel #2
0
        public IActionResult Register([FromBody] CmsRequest loginRequest)
        {
            var cert = _pkiManager.IssueCertificate(loginRequest.Cms, new DemoBankExtensionBuilder());

            var pem = PemHelper.ToPem("CERTIFICATE", cert.GetEncoded());

            return(Ok(pem));
        }
Beispiel #3
0
        public IActionResult Register([FromBody] CmsRequest req)
        {
            var cert = _pkiManager.IssueCertificate(req.Cms, new AllReqExtensionBuilder(req.CrlLink, req.RootCertLink));

            var pem = PemHelper.ToPem("CERTIFICATE", cert.GetEncoded());

            return(Ok(pem));
        }
        public async Task <IActionResult> LoginRequest([FromBody] CmsRequest loginRequest)
        {
            var cms = PkiProvider.GetCMS(loginRequest.Cms);
            var randomArrayFromSession = HttpContext.Session.Get("RandomString");

            byte[] randomArrayFromCms;

            try
            {
                randomArrayFromCms = PkiProvider.VerifySignature(cms);
            }
            catch (Exception err)
            {
                return(BadRequest());
            }

            if (!randomArrayFromSession.SequenceEqual(randomArrayFromCms))
            {
                return(BadRequest());
            }

            var user = _paymentService.GetUser(loginRequest.ObjectId);

            _paymentService.GenerateUserPayments(user.Id);

            var claims = new List <Claim>
            {
                new Claim("UserId", user.Id.ToString()),
                new Claim("UserName", user.UserName),
                new Claim("ObjectId", loginRequest.ObjectId)
            };

            var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);

            await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
                                          new ClaimsPrincipal(claimsIdentity));

            return(Ok());
        }
Beispiel #5
0
        public IActionResult RegisterComplete([FromBody] CmsRequest loginRequest)
        {
            var res = _pkiManager.GetCMS(loginRequest.Cms);

            byte[] signedResult;

            try
            {
                signedResult = _pkiManager.VerifySignature(res);
            }
            catch (Exception err)
            {
                return(BadRequest());
            }

            var byteArr = signedResult.Select(Convert.ToChar);

            var certificateId = string.Join("", byteArr);

            if (string.IsNullOrEmpty(certificateId) || string.IsNullOrWhiteSpace(certificateId))
            {
                return(BadRequest());
            }

            var lst = _pkiManager.GetSignersCommonNames(res);

            if (lst.Count != 1)
            {
                return(BadRequest());
            }

            var commonName = lst.Dequeue();

            _paymentService.Register(commonName, certificateId);

            return(Ok());
        }