// Generate the self-signed certificate
Date startDate = new Date();
Date expiryDate = new Date( System.currentTimeMillis() + YEAR_MILLIS );
BigInteger serialNumber = BigInteger.valueOf( System.currentTimeMillis() );
X509V1CertificateGenerator certGen = new X509V1CertificateGenerator();
X500Principal issuerDn = new X500Principal( CERTIFICATE_PRINCIPAL_DN );
X500Principal subjectDn = null;
try
{
String hostName = InetAddress.getLocalHost().getHostName();
subjectDn = new X500Principal( "CN=" + hostName + "," + BASE_DN );
}
catch( Exception e )
{
LOG.warn( "failed to create certificate subject name from host name", e );
subjectDn = issuerDn;
}
certGen.setSerialNumber( serialNumber );
certGen.setIssuerDN( issuerDn );
certGen.setNotBefore( startDate );
certGen.setNotAfter( expiryDate );
certGen.setSubjectDN( subjectDn );
certGen.setPublicKey( publicKey );
certGen.setSignatureAlgorithm( "SHA1With" + ALGORITHM );
try
{
X509Certificate cert = certGen.generate( privateKey, "BC" );
entry.put( USER_CERTIFICATE_AT, cert.getEncoded() );
LOG.debug( "X509 Certificate: {}", cert );
}
catch ( Exception e )
{