class SSL {

    /**
     * Extract the common name from the subjectDN of a X509 Certificate
     */
    @Nullable
    public static String extractCN(Certificate certificate) {
        if (certificate instanceof X509Certificate) {
            return extractCN(((X509Certificate) certificate).getSubjectX500Principal().getName());
        }
        return null;
    }

    @Nullable
    public static SSLSession getSession(Channel channel) {
        SslHandler sslHandler = channel.pipeline().get(SslHandler.class);
        if (sslHandler != null) {
            return sslHandler.engine().getSession();
        }
        return null;
    }

    private static String extractCN(String subjectDN) {<FILL_FUNCTION_BODY>}
}

        /*
         * Get commonName using LdapName API
         * The DN of X509 certificates are in rfc2253 format. Ldap uses the same format.
         *
         * Doesn't use X500Name because it's internal API
         */
        try {
            LdapName ldapName = new LdapName(subjectDN);
            for (Rdn rdn : ldapName.getRdns()) {
                if ("CN".equalsIgnoreCase(rdn.getType())) {
                    return rdn.getValue().toString();
                }
            }
            throw new RuntimeException("Could not extract commonName from certificate subjectDN: " + subjectDN);
        } catch (InvalidNameException e) {
            throw new RuntimeException("Could not extract commonName from certificate", e);
        }
    
<no_super_class>