private static OcesCertificateType GetFromSubject(CertificateSubject subject) { OcesX509CertificateConfig config = ConfigurationHandler.GetConfigurationSection <OcesX509CertificateConfig>(); OcesCertificateType ocesCertificateType = new OcesCertificateType(); string ssn = subject.SerialNumberValue; if (string.IsNullOrEmpty(ssn)) { ocesCertificateType = OcesCertificateType.NonOces; } else if (ssn.Contains(config.EmployeeCertificateSubjectKey.SubjectKeyString)) { ocesCertificateType = OcesCertificateType.OcesEmployee; } else if (ssn.Contains(config.OrganizationCertificateSubjectKey.SubjectKeyString)) { ocesCertificateType = OcesCertificateType.OcesOrganisation; } else if (ssn.Contains(config.PersonalCertificateSubjectKey.SubjectKeyString)) { ocesCertificateType = OcesCertificateType.OcesPersonal; } else if (ssn.Contains(config.FunctionCertificateSubjetKey.SubjectKeyString)) { ocesCertificateType = OcesCertificateType.OcesFunction; } else { ocesCertificateType = OcesCertificateType.NonOces; } return(ocesCertificateType); }
static X509Certificate2 Ldap(CertificateSubject certSubject) { LdapSettings settings = ConfigurationHandler.GetConfigurationSection <LdapSettings>(); // Print out info Console.WriteLine(); Console.WriteLine("2. Certificate download"); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(" Using host"); Console.WriteLine(" " + settings.Host); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(); // Create the LDAP client LdapLookupFactory ldapClientFactory = new LdapLookupFactory(); ICertificateLookup ldapClient = ldapClientFactory.CreateLdapLookupClient(); // Lookup the certificate using LDAP X509Certificate2 certificate = ldapClient.GetCertificate(certSubject); Console.WriteLine(" Downloaded certificate with LDAP:"); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(" " + certificate.Subject); Console.ForegroundColor = ConsoleColor.White; return(certificate); }
public void MicrosoftCertificateAuthority_Sign_CngEcdh256_CertificateAuthorityRequestResponse_Issued() { string templateName = "ServerAuthentication-CngEcdh"; int keysize = 256; string commonName = "domain.com"; WindowsApi api = WindowsApi.Cng; CipherAlgorithm cipher = CipherAlgorithm.ECDH; KeyUsage keyUsage = KeyUsage.ServerAuthentication; CertificateSubject subject = new CertificateSubject(commonName); Win32CertificateProvider provider = new Win32CertificateProvider(); CertificateRequest csr = provider.CreateCsrKeyPair(subject, cipher, keysize, api, SigningRequestProtocol.Pkcs10); MicrosoftCertificateAuthority ca = new MicrosoftCertificateAuthority(new MicrosoftCertificateAuthorityOptions() { AuthenticationRealm = domain, AuthenticationType = MicrosoftCertificateAuthorityAuthenticationType.UsernamePassword, HashAlgorithm = HashAlgorithm.SHA256, ServerName = caServerName, CommonName = caCommonName, Username = username, Password = password }); CertificateAuthorityRequestResponse response = ca.Sign(csr, templateName, keyUsage); Assert.AreEqual(CertificateRequestStatus.Issued, response.CertificateRequestStatus); }
private static Dictionary <string, string> GetKeywords(CertificateSubject subject) { Dictionary <string, string> keywords = new Dictionary <string, string>(); keywords.Add("subjectstring", subject.SubjectString); return(keywords); }
/// <summary> /// Returns a selected certificate based on configuration. /// </summary> /// <param name="certificateSubject">The subject serial number of the certificate</param> /// <returns>Returns a selected certificate based on configuration.</returns> public X509Certificate2 GetCertificate(CertificateSubject certificateSubject) { CertificateLoader certificateLoader = new CertificateLoader(); switch (_config.Action) { case LdapCertificateLookupTestConfig.LookupAction.FindCertificate: // 1. Attempt to load the certificate from store: return(certificateLoader.GetCertificateFromStoreWithSSN( certificateSubject.SerialNumberValue, _config.StoreLocation, _config.StoreName )); case LdapCertificateLookupTestConfig.LookupAction.ConnectionFailed: LdapSettings settings = ConfigurationHandler.GetConfigurationSection <LdapSettings>(); throw new ConnectingToLdapServerFailedException(settings, new Exception(this.ToString())); case LdapCertificateLookupTestConfig.LookupAction.SearchFailed: throw new SearchFailedException(new Exception(this.ToString())); default: throw new NotImplementedException(); } }
private UddiLookupResponse GetLookupResponse(LookupParameters lookupParameters, UddiService uddiService, UddiBinding uddiBinding) { Identifier identifier = lookupParameters.Identifier; EndpointAddress endpointAddress = uddiBinding.GetEndpointAddress(); DateTime activationDateUtc = uddiService.GetActivationDateUtc(); DateTime expirationDateUtc = uddiService.GetExpirationDateUtc(); CertificateSubject subject = uddiService.GetCertificateSubject(); Uri termsOfUse = uddiService.GetTermsOfUseUrl(); MailAddress mail = uddiService.GetContactMail(); Version version = uddiService.GetVersion(); UddiId newerVersion = uddiService.GetNewerVersion(); UddiId serviceType = uddiBinding.GetPortType().UddiId; List <ProcessRoleDefinition> list = uddiBinding.GetProcessRoleDefinitions(); UddiLookupResponse response = new UddiLookupResponse( identifier, endpointAddress, activationDateUtc, expirationDateUtc, subject, termsOfUse, mail, version, newerVersion, serviceType, list ); return(response); }
public CertificateSubject NewCertificateSubjectFromModel(ICertificateSubjectRaw model) { List <string> san = this.ParseSubjectAlternativeName(model.SubjectAlternativeNamesRaw); CertificateSubject subject = new CertificateSubject(model.SubjectCommonName, san); if (string.IsNullOrWhiteSpace(model.SubjectCity)) { subject.City = model.SubjectCity; } if (string.IsNullOrWhiteSpace(model.SubjectCountry)) { subject.Country = model.SubjectCountry; } if (string.IsNullOrWhiteSpace(model.SubjectDepartment)) { subject.Department = model.SubjectDepartment; } if (string.IsNullOrWhiteSpace(model.SubjectOrganization)) { subject.Organization = model.SubjectOrganization; } if (string.IsNullOrWhiteSpace(model.SubjectState)) { subject.State = model.SubjectState; } return(subject); }
public void CertificateSubject_Constructor_0_AppendSandTrue_SanIsAppendedSuccess() { string commonName = "domain.com"; CertificateSubject subject = new CertificateSubject(commonName, true); Assert.IsTrue(subject.SubjectAlternativeName.Contains(commonName)); }
public static void ClassInitialize(TestContext testContext) { Win32CertificateProvider certificateProvider = new Win32CertificateProvider(); CertificateSubject subject = new CertificateSubject("Win32CertificateProviderTests.Cng.Rsa.2048"); certificateProvider.CreateSelfSignedCertificate(subject, CipherAlgorithm.RSA, 2048, WindowsApi.Cng); }
public void CertificateRequest_Constructor_NullSubject_ArgumentNullException() { ICertificateProvider provider = new Win32CertificateProvider(); CertificateSubject subject = null; List <string> san = new List <string>(); new CertificateRequest(subject); }
public void CertificateSubject_Constructor_0_CommonNameArgumentSetToCommonNamePublicProperty() { string commonName = "myfakedomain.fake"; CertificateSubject subject = new CertificateSubject(commonName); Assert.AreEqual(commonName, subject.CommonName); }
public void CertificateSubject_Constructor_0_AppendSandFalse_ContainsSubjectAlternativeNameFalse() { string commonName = "domain.com"; CertificateSubject subject = new CertificateSubject(commonName, false); Assert.IsFalse(subject.ContainsSubjectAlternativeName); }
public void CertificateSubject_Constructor_0_SanListOverload_NullSan_ContainsSubjectAlternativeNameFalse() { string commonName = "domain.com"; CertificateSubject subject = new CertificateSubject(commonName, (List <string>)null); Assert.IsFalse(subject.ContainsSubjectAlternativeName); }
public void CertificateSubject_CreateFromDistinguishedName_CommonNameSetsCommonNamePublicProperty() { string commonName = "domain.com"; string dn = string.Format("CN={0}", commonName); CertificateSubject subject = CertificateSubject.CreateFromDistinguishedName(dn); Assert.AreEqual(commonName, subject.CommonName); }
public void CertificateSubject_CreateFromDistinguishedName_DepartmentSetsDepartmentPublicProperty() { string department = "Engineering"; string dn = string.Format("OU={0}", department); CertificateSubject subject = CertificateSubject.CreateFromDistinguishedName(dn); Assert.AreEqual(department, subject.Department); }
protected OcesX509Certificate GetEndpointCertificateFromLdap(CertificateSubject certificateSubject) { LdapLookupFactory ldapClientFactory = new LdapLookupFactory(); ICertificateLookup ldapClient = ldapClientFactory.CreateLdapLookupClient(); X509Certificate2 endpointCertificate = ldapClient.GetCertificate(certificateSubject); OcesX509Certificate endpointOcesCertificate = new OcesX509Certificate(endpointCertificate); return(endpointOcesCertificate); }
public void CertificateSubject_CreateFromDistinguishedName_StateSetsStatePublicProperty() { string state = "ma"; string dn = string.Format("S={0}", state); CertificateSubject subject = CertificateSubject.CreateFromDistinguishedName(dn); Assert.AreEqual(state, subject.State); }
public void CertificateSubject_CreateFromDistinguishedName_CountrySetsCountryPublicProperty() { string country = "US"; string dn = string.Format("C={0}", country); CertificateSubject subject = CertificateSubject.CreateFromDistinguishedName(dn); Assert.AreEqual(country, subject.Country); }
public void CertificateSubject_CreateFromDistinguishedName_OrganizationSetsOrganizationPublicProperty() { string organization = "TechCorp"; string dn = string.Format("O={0}", organization); CertificateSubject subject = CertificateSubject.CreateFromDistinguishedName(dn); Assert.AreEqual(organization, subject.Organization); }
public void CertificateSubject_CreateFromDistinguishedName_CitySetsCityPublicProperty() { string city = "walpole"; string dn = string.Format("L={0}", city); CertificateSubject subject = CertificateSubject.CreateFromDistinguishedName(dn); Assert.AreEqual(city, subject.City); }
public CreatePrivateCertificateModel(X509Certificate2 cert) { CertificateSubject subject = new CertificateSubject(cert); this.SubjectCommonName = subject.CommonName; this.CipherAlgorithm = CipherAlgorithm.RSA; this.HashAlgorithm = HashAlgorithm.SHA256; this.Provider = WindowsApi.Cng; this.KeySize = 2048; }
public void CertificateSubject_Constructor_1_OrganizationArgumentSetToCommonNamePublicProperty() { string commonName = "myfakedomain.fake"; string department = "Engineering"; string organization = "TechCorp"; CertificateSubject subject = new CertificateSubject(commonName, department, organization); Assert.AreEqual(organization, subject.Organization); }
public void CertificateSubject_ToString_CommonNameOnly_CreatesValidDistinguishedName() { string commonName = "domain.com"; string expectedDn = String.Format("CN={0}", commonName); CertificateSubject subject = new CertificateSubject(commonName); string dn = subject.ToString(); Assert.AreEqual(expectedDn, dn); }
public void CertificateSubject_Constructor_1_AppendSandTrue_SanIsAppendedSuccess() { string commonName = "myfakedomain.fake"; string department = "Engineering"; string organization = "TechCorp"; CertificateSubject subject = new CertificateSubject(commonName, department, organization, true); Assert.IsTrue(subject.SubjectAlternativeName.Contains(commonName)); }
public void CertificateSubject_Constructor_1_AppendSandFalse_ContainsSubjectAlternativeNameFalse() { string commonName = "myfakedomain.fake"; string department = "Engineering"; string organization = "TechCorp"; CertificateSubject subject = new CertificateSubject(commonName, department, organization, false); Assert.IsFalse(subject.ContainsSubjectAlternativeName); }
public void CertificateSubject_CreateFromDistinguishedName_DistinguishedNameGreaterThan256Characters_ArgumentOutOfRangeException() { string dn = "CN=this is my really long subject name that must be created than 64 characters," + "OU=this is my really long organizational unit name that must be created than 64 characters" + "L=this is my really long city name that must be created than 64 characters" + "S=this is my really long state name that must be created than 64 characters" + "C=this is my really long country name that must be created than 64 characters"; CertificateSubject.CreateFromDistinguishedName(dn); }
public void CertificateSubject_Constructor_1_SanListOverload_NullSan_ContainsSubjectAlternativeNameFalse() { string commonName = "myfakedomain.fake"; string department = "Engineering"; string organization = "TechCorp"; CertificateSubject subject = new CertificateSubject(commonName, department, organization, (List <string>)null); Assert.IsFalse(subject.ContainsSubjectAlternativeName); }
public void _01_CertificateSubjectWithParantheses() { const string certificateSubjectString = "OID.2.5.4.5=CVR:14472800-FID:1201516183216 + CN=Scan-Med NEM-Handel (funktionscertifikat), O=SCAN-MED. A/S. DENMARK // CVR:14472800, C=DK"; CertificateSubject subject = new CertificateSubject(certificateSubjectString); Assert.AreEqual("DK", subject.C); Assert.AreEqual("Scan-Med NEM-Handel (funktionscertifikat)", subject.CN); Assert.AreEqual("SCAN-MED. A/S. DENMARK // CVR:14472800", subject.O); Assert.AreEqual("serialNumber=CVR:14472800-FID:1201516183216", subject.SerialNumber); }
public void _03_SpecificCertificateProblem() { const string certificateSubjectString = "SERIALNUMBER=CVR:82269118-FID:1225461072402 + CN=Navision Stat (funktionscertifikat), O=Dansk Landbrugsmusuem Gl. Estrup // CVR:82269118, C=DK"; CertificateSubject subject = new CertificateSubject(certificateSubjectString); Assert.AreEqual("DK", subject.C); Assert.AreEqual("Navision Stat (funktionscertifikat)", subject.CN); Assert.AreEqual("Dansk Landbrugsmusuem Gl. Estrup // CVR:82269118", subject.O); Assert.AreEqual("serialNumber=CVR:82269118-FID:1225461072402", subject.SerialNumber); }
public void SubjectTest() { var request = new CertificateSubject( certificateId: 1, path: "ai/processor" ); Assert.Equal(1, request.CertificateId); Assert.Equal("ai/processor", request.Path); }