Exemplo n.º 1
0
        public TestDataProtectionTools()
        {
            ILogger logger = Mock.Of <ILogger>();

            _dataProtectionTools = new DataProtectionTools(logger, null);
            _certificateTools    = new CertificateTools(logger);
        }
 public CertificateViewModel CertificateToViewModel(X509Certificate2 cert)
 {
     return(cert == null ? null : new CertificateViewModel
     {
         Version = cert.Version,
         SerialNumber = cert.SerialNumber,
         SignatureAlgorithmId = cert.SignatureAlgorithm.FriendlyName,
         SubjectName = cert.SubjectName.Name,
         Issuer = cert.Issuer,
         IssuerName = cert.IssuerName.Name,
         NotBefore = cert.NotBefore,
         NotAfter = cert.NotAfter,
         PublicKeyAlgorithm = cert.PublicKey.Key.SignatureAlgorithm,
         SubjectPublicKey = CertificateTools.ExportPublicKeyToPEMFormat(cert.PublicKey.Key as RSA)
     });
 }
        public HttpResponseMessage Get()
        {
            var x = ComponentSpace.SAML2.SAMLController.Configuration.LocalIdentityProviderConfiguration;

            // TODO : Map path better?
            var certFilename          = HttpContext.Current.Server.MapPath("~/" + x.LocalCertificateFile);
            var certificateCollection = new X509Certificate2Collection();

            certificateCollection.Import(certFilename, x.LocalCertificatePassword, X509KeyStorageFlags.DefaultKeySet);

            var certificates = new List <CertificateViewModel>();

            foreach (var cert in certificateCollection)
            {
                certificates.Add(new CertificateViewModel
                {
                    Version              = cert.Version,
                    SerialNumber         = cert.SerialNumber,
                    SignatureAlgorithmId = cert.SignatureAlgorithm.FriendlyName,
                    SubjectName          = cert.SubjectName.Name,
                    Issuer             = cert.Issuer,
                    IssuerName         = cert.IssuerName.Name,
                    NotBefore          = cert.NotBefore,
                    NotAfter           = cert.NotAfter,
                    PublicKeyAlgorithm = cert.PublicKey.Key.SignatureAlgorithm,
                    SubjectPublicKey   = CertificateTools.ExportPublicKeyToPEMFormat(cert.PublicKey.Key as RSA)
                });
            }

            var result = new IdentityProviderViewModel
            {
                Name         = x.Name,
                Description  = x.Description,
                Certificates = certificates
            };

            var jsonText = JsonConvert.SerializeObject(result);

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(jsonText, Encoding.UTF8, "application/json");

            return(response);
        }
Exemplo n.º 4
0
        public TestJsonWebTokenTools()
        {
            ILogger logger = Mock.Of <ILogger>();

            _jsonWebTokenTools = new JsonWebTokenTools(logger);
            Assert.NotNull(_jsonWebTokenTools);
            _certificateTools = new CertificateTools(logger);
            Assert.NotNull(_certificateTools);
            DateTime tenYearsFromNow = DateTime.UtcNow.AddYears(10);

            _fullCertificate = _certificateTools.CreateSignedPrivateCertificate("ten_year_certificate", "ten_year_certificate_password", tenYearsFromNow);
            Assert.NotNull(_fullCertificate);
            _publicCertificate = _certificateTools.GetPublicCertificate(_fullCertificate);
            Assert.NotNull(_publicCertificate);
            _payload = new Dictionary <string, object>();
            _payload.Add("string", "value");
            _payload.Add("integer", 10);
            _payload.Add("float", 99.99);
        }
Exemplo n.º 5
0
        public TestCertificateTools()
        {
            ILogger logger = Mock.Of <ILogger>();

            _certificateTools = new CertificateTools(logger);
        }