Class CertificatePrincipalExtractor

java.lang.Object
com.irurueta.authserver.authorization.api.web.x509.CertificatePrincipalExtractor
All Implemented Interfaces:
org.springframework.security.web.authentication.preauth.x509.X509PrincipalExtractor

public class CertificatePrincipalExtractor extends Object implements org.springframework.security.web.authentication.preauth.x509.X509PrincipalExtractor
Takes the SHA-256 fingerprint of the client certificate as the principal, as 64 lower case hexadecimal digits, which is what a binding stores and what ResolveCertificateLoginUseCase looks up. The fingerprint, and not the subject name, identifies a certificate: whoever controls a CA can issue a certificate with any subject, and none with a given fingerprint. A certificate that is expired or not yet valid has no principal: neither the TLS handshake of the dedicated port (no authority validates the chain) nor a proxy that forwards a certificate is trusted to have checked it. One extractor serves both transports, because both leave the certificate in the same request attribute.
  • Field Details

    • ALGORITHM

      private static final String ALGORITHM
      Algorithm of the fingerprint.
      See Also:
    • UNREADABLE

      static final String UNREADABLE
      Principal of a certificate that cannot be encoded or is expired or not yet valid: it is not a fingerprint, so it is bound to no account and the sign-in fails like any unknown certificate.
      See Also:
  • Constructor Details

    • CertificatePrincipalExtractor

      public CertificatePrincipalExtractor()
  • Method Details

    • extractPrincipal

      public Object extractPrincipal(X509Certificate certificate)
      Extracts the principal.
      Specified by:
      extractPrincipal in interface org.springframework.security.web.authentication.preauth.x509.X509PrincipalExtractor
      Parameters:
      certificate - the client certificate.
      Returns:
      its fingerprint, or UNREADABLE when it cannot be encoded or is not within its validity period.
    • fingerprintOf

      public String fingerprintOf(byte[] encoded)
      Computes the fingerprint of a DER encoded certificate.
      Parameters:
      encoded - the DER form of the certificate.
      Returns:
      the SHA-256 digest as lower case hexadecimal digits.