private static ResultHolder generateTestCertificate(@Nullable final String subjectCommonName, final boolean isValid, final boolean isSelfSigned, int indexAwayFromEndEntity ) throws Exception
    {
        final KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance( KEY_ALGORITHM );
        keyPairGenerator.initialize( KEY_SIZE );

        final KeyPair subjectKeyPair;
        final KeyPair issuerKeyPair;

        if ( isSelfSigned )
        {
            // Self signed: subject and issuer are the same entity.
            subjectKeyPair = keyPairGenerator.generateKeyPair();
            issuerKeyPair = subjectKeyPair;
        }
        else
        {
            subjectKeyPair = keyPairGenerator.generateKeyPair();
            issuerKeyPair = keyPairGenerator.generateKeyPair();
        }

        final X509Certificate subjectCertificate = generateTestCertificate(subjectCommonName, isValid, issuerKeyPair, subjectKeyPair, indexAwayFromEndEntity);
        return new ResultHolder(subjectKeyPair, subjectCertificate);
    }
Instantiates a new certificate that is self-signed, of which the notAfter value is a point in time that is in the
past (as compared to the point in time of the invocation of this method).

@param subjectCommonName The CN value to use in the certificate.
@return A certificate that is self-signed and expired (never null).
@see #generateSelfSignedCertificate()
@see #generateExpiredCertificate()
xmppserver/src/test/java/org/jivesoftware/openfire/keystore/KeystoreTestUtils.java