public static X509Certificate generateCertificate(String dn, KeyPair pair,
                                                      int days, String algorithm)
        throws  CertificateException {
        return new CertificateBuilder(days, algorithm).generate(dn, pair);
    }
Create a self-signed X.509 Certificate.
From http://bfo.com/blog/2011/03/08/odds_and_ends_creating_a_new_x_509_certificate.html.

@param dn the X.509 Distinguished Name, eg "CN=Test, L=London, C=GB"
@param pair the KeyPair
@param days how many days from now the Certificate is valid for, or - for negative values - how many days before now
@param algorithm the signing algorithm, eg "SHA1withRSA"
@return the self-signed certificate
@throws CertificateException thrown if a security error or an IO error occurred.
clients/src/test/java/org/apache/kafka/test/TestSslUtils.java