/// <summary> /// Returns the type of OCES certificate, e.g. "company" or "employee" certificates /// </summary> /// <param name="certificate">The certificate to check</param> /// <returns>Returns the OCES certificate type</returns> public static OcesCertificateType GetCertificateType(X509Certificate certificate) { OcesCertificateType certType = OcesCertificateType.NonOces; try { //no check included for LRA and Device string subjectString = certificate.Subject; if (subjectString.Contains("PID")) { certType = OcesCertificateType.OcesPersonal; } else if (subjectString.Contains("CVR")) { if (subjectString.Contains("RID")) { certType = OcesCertificateType.OcesEmployee; } else if (subjectString.Contains("UID")) { certType = OcesCertificateType.OcesOrganisation; } } } catch (ArgumentNullException) { throw; } catch (CryptographicUnexpectedOperationException) { throw; } catch (CryptographicException) { throw; } catch (Exception e) { throw new CheckCertificateTypeUnexpectedException(e); } return(certType); }
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); }
/// <summary> /// Get the OCES certificate type from a given certificate subject. /// </summary> public static OcesCertificateType GetOcesCertificateType(CertificateSubject subject) { if (subject == null) { throw new NullArgumentException("subject"); } //The code is using the subject as identifier of the the oces type. OcesCertificateType ocesCertificateType = GetFromSubject(subject); return(ocesCertificateType); }
/// <summary> /// Get the OCES certificate type from a given certificate. /// </summary> /// <param name="certificate"></param> /// <returns></returns> public static OcesCertificateType GetOcesCertificateType(X509Certificate2 certificate) { if (certificate == null) { throw new NullArgumentException("certificate"); } OcesCertificateType ocesCertificateType; try { //The code is using the subject as identifier of the the oces type. ocesCertificateType = GetFromSubject(certificate); } catch (Exception ex) { throw new FailedGetOcesCertificateTypeException(certificate, ex); } return(ocesCertificateType); }
private void SetCertificateType() { _ocesCertificateType = GetOcesCertificateType(_x509Certificate); }
private void SetCertificateType() { this.ocesCertificateType = GetOcesCertificateType(this.x509Certificate); }