Github user alopresto commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1669#discussion_r112568506
  
    --- Diff: 
nifi-toolkit/nifi-toolkit-admin/src/main/groovy/org/apache/nifi/toolkit/admin/client/NiFiClientFactory.groovy
 ---
    @@ -116,22 +121,27 @@ class NiFiClientFactory implements ClientFactory{
             return sslContext;
         }
     
    -    private static class NiFiHostnameVerifier implements HostnameVerifier {
    +    static class NiFiHostnameVerifier implements HostnameVerifier {
     
             @Override
             public boolean verify(final String hostname, final SSLSession 
ssls) {
                 try {
    -                for (final Certificate peerCertificate : 
ssls.getPeerCertificates()) {
    -                    if (peerCertificate instanceof X509Certificate) {
    -                        final X509Certificate x509Cert = (X509Certificate) 
peerCertificate;
    -                        final List<String> subjectAltNames = 
getSubjectAlternativeNames(x509Cert);
    -                        if 
(subjectAltNames.contains(hostname.toLowerCase())) {
    -                            return true;
    -                        }
    +
    +                final Certificate peerCertificate = 
ssls.getPeerCertificates()[0]
    +                final X509Certificate x509Cert = 
CertificateUtils.convertAbstractX509Certificate(peerCertificate)
    +                final String dn = x509Cert.getSubjectDN().getName().trim()
    +                final String cn = dn.tokenize(",").find { cn -> 
cn.startsWith("CN=")}
    +
    +                if(StringUtils.isNoneEmpty(cn) && 
StringUtils.substringAfter(cn,"=").toLowerCase().equals(hostname.toLowerCase())){
    +                    return true
    +                }else {
    +                    final List<String> subjectAltNames = 
getSubjectAlternativeNames(x509Cert)
    +                    if (subjectAltNames.contains(hostname.toLowerCase())) {
    --- End diff --
    
    I don't know that the SANs are guaranteed to be in lowercase. However, as 
this is Groovy, you could use the construct
    
    ```
    return getSubjectAlternativeNames(x509Cert).any { String san -> 
san.equalsIgnoreCase(hostname) }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to