@@ -36,12 +36,12 @@ public final class CertificateUtils {
3636 // dNSName (2)
3737 // iPAddress (7)
3838 private static final int SAN_TYPE_DNS_NAME = 2 ;
39- private static final int SAN_TYPE_IP_ADDRESS = 7 ;
39+ private static final int SAN_TYPE_URI = 6 ;
4040
4141 private CertificateUtils () {}
4242
4343 /**
44- * Gets the principal from a certificate. It returns the cert's first IP Address SAN if set,
44+ * Gets the principal from a certificate. It returns the cert's first URI SAN if set,
4545 * otherwise the cert's first DNS SAN if set, otherwise the subject field of the certificate in
4646 * RFC 2253 format.
4747 *
@@ -52,14 +52,14 @@ public static String getPrincipal(X509Certificate cert) {
5252 try {
5353 Collection <List <?>> sans = cert .getSubjectAlternativeNames ();
5454 if (sans != null ) {
55- // Look for IP Address SAN.
55+ // Look for URI SAN (Priority 1) .
5656 for (List <?> san : sans ) {
5757 if (san .size () == 2 && san .get (0 ) instanceof Integer
58- && (Integer ) san .get (0 ) == SAN_TYPE_IP_ADDRESS ) {
58+ && (Integer ) san .get (0 ) == SAN_TYPE_URI ) {
5959 return (String ) san .get (1 );
6060 }
6161 }
62- // If no IP Address SAN, look for DNS SAN.
62+ // If no URI SAN, look for DNS SAN (Priority 2) .
6363 for (List <?> san : sans ) {
6464 if (san .size () == 2 && san .get (0 ) instanceof Integer
6565 && (Integer ) san .get (0 ) == SAN_TYPE_DNS_NAME ) {
@@ -68,12 +68,12 @@ public static String getPrincipal(X509Certificate cert) {
6868 }
6969 }
7070 } catch (java .security .cert .CertificateParsingException e ) {
71- logger .log (Level .WARNING , "Error parsing certificate SANs. This is not expected, "
72- + "falling back to the subject according to the spec." , e );
71+ logger .log (Level .FINE , "Error parsing certificate SANs." , e );
7372 }
74- return cert .getSubjectX500Principal ().getName ();
73+ return cert .getSubjectX500Principal ().getName ("RFC2253" );
7574 }
7675
76+
7777 /**
7878 * Gets the URL PEM encoded certificate. It Pem encodes first and then urlencodes.
7979 *
0 commit comments