@Test public void testServerIdentitiesXmppAddr() throws Exception { final String subjectCommonName = "MySubjectCommonName"; final String subjectAltNameXmppAddr = "MySubjectAltNameXmppAddr"; final X509v3CertificateBuilder builder = new JcaX509v3CertificateBuilder( new X500Name( "CN=MyIssuer" ), BigInteger.valueOf( Math.abs( new SecureRandom().nextInt() ) ), new Date( System.currentTimeMillis() - ( 1000L * 60 * 60 * 24 * 30 ) ), new Date( System.currentTimeMillis() + ( 1000L * 60 * 60 * 24 * 99 ) ), new X500Name( "CN=" + subjectCommonName ), subjectKeyPair.getPublic() ); final DERSequence otherName = new DERSequence( new ASN1Encodable[] { XMPP_ADDR_OID, new DERUTF8String( subjectAltNameXmppAddr ) }); final GeneralNames subjectAltNames = new GeneralNames( new GeneralName(GeneralName.otherName, otherName ) ); builder.addExtension( Extension.subjectAlternativeName, true, subjectAltNames ); final X509CertificateHolder certificateHolder = builder.build( contentSigner ); final X509Certificate cert = new JcaX509CertificateConverter().getCertificate( certificateHolder ); final List<String> serverIdentities = CertificateManager.getServerIdentities( cert ); assertEquals( 1, serverIdentities.size() ); assertTrue( serverIdentities.contains( subjectAltNameXmppAddr )); assertFalse( serverIdentities.contains( subjectCommonName ) ); }
public static List<String> getServerIdentities(X509Certificate x509Certificate) { List<String> names = new ArrayList<>(); for (CertificateIdentityMapping mapping : serverCertMapping) { List<String> identities = mapping.mapIdentity(x509Certificate); Log.debug("CertificateManager: " + mapping.name() + " returned " + identities.toString()); if (!identities.isEmpty()) { names.addAll(identities); break; } } return names; }
CertificateManager { public static List<String> getServerIdentities(X509Certificate x509Certificate) { List<String> names = new ArrayList<>(); for (CertificateIdentityMapping mapping : serverCertMapping) { List<String> identities = mapping.mapIdentity(x509Certificate); Log.debug("CertificateManager: " + mapping.name() + " returned " + identities.toString()); if (!identities.isEmpty()) { names.addAll(identities); break; } } return names; } }
CertificateManager { public static List<String> getServerIdentities(X509Certificate x509Certificate) { List<String> names = new ArrayList<>(); for (CertificateIdentityMapping mapping : serverCertMapping) { List<String> identities = mapping.mapIdentity(x509Certificate); Log.debug("CertificateManager: " + mapping.name() + " returned " + identities.toString()); if (!identities.isEmpty()) { names.addAll(identities); break; } } return names; }  }
CertificateManager { public static List<String> getServerIdentities(X509Certificate x509Certificate) { List<String> names = new ArrayList<>(); for (CertificateIdentityMapping mapping : serverCertMapping) { List<String> identities = mapping.mapIdentity(x509Certificate); Log.debug("CertificateManager: " + mapping.name() + " returned " + identities.toString()); if (!identities.isEmpty()) { names.addAll(identities); break; } } return names; }  static List<String> getClientIdentities(X509Certificate x509Certificate); static List<String> getServerIdentities(X509Certificate x509Certificate); static boolean isSelfSignedCertificate(X509Certificate certificate); static boolean isSigningRequestPending(X509Certificate certificate); static String createSigningRequest(X509Certificate cert, PrivateKey privKey); static String toPemRepresentation( Object object ); static PrivateKey parsePrivateKey(String pemRepresentation, String passPhrase); static PrivateKey parsePrivateKey(InputStream pemRepresentation, String passPhrase); static Collection<X509Certificate> parseCertificates(String pemRepresentation); @SuppressWarnings("unchecked") static Collection<X509Certificate> parseCertificates(InputStream pemRepresentation); static void addListener(CertificateEventListener listener); static void removeListener(CertificateEventListener listener); static void fireCertificateStoreChanged( CertificateStore store ); @Deprecated static List<X509Certificate> order( Collection<X509Certificate> certificates ); static synchronized X509Certificate createX509V3Certificate(KeyPair kp, int days, String issuerCommonName,
                                                                        String subjectCommonName, String domain,
                                                                        String signAlgoritm); static synchronized X509Certificate createX509V3Certificate(KeyPair kp, int days, String issuerCommonName,
                                                                        String subjectCommonName, String domain,
                                                                        String signAlgoritm, Set<String> sanDnsNames); static synchronized X509Certificate createX509V3Certificate(KeyPair kp, int days, X500NameBuilder issuerBuilder,
            X500NameBuilder subjectBuilder, String domain, String signAlgoritm ); static synchronized X509Certificate createX509V3Certificate(KeyPair kp, int days, X500NameBuilder issuerBuilder,
            X500NameBuilder subjectBuilder, String domain, String signAlgoritm, Set<String> sanDnsNames ); static Set<String> determineSubjectAlternateNameDnsNameValues(); }
CertificateManager { public static List<String> getServerIdentities(X509Certificate x509Certificate) { List<String> names = new ArrayList<>(); for (CertificateIdentityMapping mapping : serverCertMapping) { List<String> identities = mapping.mapIdentity(x509Certificate); Log.debug("CertificateManager: " + mapping.name() + " returned " + identities.toString()); if (!identities.isEmpty()) { names.addAll(identities); break; } } return names; }  static List<String> getClientIdentities(X509Certificate x509Certificate); static List<String> getServerIdentities(X509Certificate x509Certificate); static boolean isSelfSignedCertificate(X509Certificate certificate); static boolean isSigningRequestPending(X509Certificate certificate); static String createSigningRequest(X509Certificate cert, PrivateKey privKey); static String toPemRepresentation( Object object ); static PrivateKey parsePrivateKey(String pemRepresentation, String passPhrase); static PrivateKey parsePrivateKey(InputStream pemRepresentation, String passPhrase); static Collection<X509Certificate> parseCertificates(String pemRepresentation); @SuppressWarnings("unchecked") static Collection<X509Certificate> parseCertificates(InputStream pemRepresentation); static void addListener(CertificateEventListener listener); static void removeListener(CertificateEventListener listener); static void fireCertificateStoreChanged( CertificateStore store ); @Deprecated static List<X509Certificate> order( Collection<X509Certificate> certificates ); static synchronized X509Certificate createX509V3Certificate(KeyPair kp, int days, String issuerCommonName,
                                                                        String subjectCommonName, String domain,
                                                                        String signAlgoritm); static synchronized X509Certificate createX509V3Certificate(KeyPair kp, int days, String issuerCommonName,
                                                                        String subjectCommonName, String domain,
                                                                        String signAlgoritm, Set<String> sanDnsNames); static synchronized X509Certificate createX509V3Certificate(KeyPair kp, int days, X500NameBuilder issuerBuilder,
            X500NameBuilder subjectBuilder, String domain, String signAlgoritm ); static synchronized X509Certificate createX509V3Certificate(KeyPair kp, int days, X500NameBuilder issuerBuilder,
            X500NameBuilder subjectBuilder, String domain, String signAlgoritm, Set<String> sanDnsNames ); static Set<String> determineSubjectAlternateNameDnsNameValues();  }