use of org.mozilla.jss.netscape.security.x509.X509CertImpl in project ariADDna by StnetixDevTeam.
the class CertFactory method isValid.
public boolean isValid(File certFile) throws KeyStoreException {
try {
X509CertImpl cert = (X509CertImpl) getCertByFile(certFile);
long notBefore = cert.getNotBefore().getTime();
long notAfter = cert.getNotAfter().getTime();
long now = System.currentTimeMillis();
LOGGER.info("Certificate {} is " + (now >= notBefore && now <= notAfter ? "valid" : "not valid"), certFile.getAbsolutePath());
boolean isActive = persistHelper.isActiveCertificate(getCertSubjectName(cert));
return now >= notBefore && now <= notAfter && isActive;
} catch (Exception e) {
LOGGER.error("Exception: ", e);
throw new KeyStoreException("Caused by: ", e);
}
}
use of org.mozilla.jss.netscape.security.x509.X509CertImpl in project ariADDna by StnetixDevTeam.
the class KeyFactory method storeCertToKeyStore.
public void storeCertToKeyStore(File certFile, File keyStoreFile) throws KeyStoreException {
try {
X509CertImpl cert = (X509CertImpl) certFactory.getCertByFile(certFile);
String alias = certFactory.getCertSubjectName(cert);
LOGGER.info("Certificate with filename {} has Subject name {}", certFile.getAbsolutePath(), alias);
FileInputStream fis = new FileInputStream(keyStoreFile);
KeyStore keyStore = KeyStore.getInstance(KEYSTORE_FORMAT);
keyStore.load(fis, pass);
LOGGER.info("KeyStore load successful");
fis.close();
keyStore.setCertificateEntry(alias, cert);
FileOutputStream fos = new FileOutputStream(keyStoreFile);
keyStore.store(fos, pass);
LOGGER.info("Certificate with filename {} stored in keyStore with filename {}", certFile.getAbsolutePath(), keyStoreFile.getAbsolutePath());
fos.close();
} catch (Exception e) {
LOGGER.error("Exception: ", e);
throw new KeyStoreException("Caused by: ", e);
}
}
use of org.mozilla.jss.netscape.security.x509.X509CertImpl in project TLS-Scanner by RUB-NDS.
the class CertificateJudge method isSelfSigned.
public Boolean isSelfSigned() {
try {
// Try to verify certificate signature with its own public key
X509Certificate cert = new X509CertImpl(certificate.getEncoded());
PublicKey publicKey = cert.getPublicKey();
cert.verify(publicKey);
return true;
} catch (SignatureException | InvalidKeyException ex) {
return false;
} catch (Exception e) {
return null;
}
}
use of org.mozilla.jss.netscape.security.x509.X509CertImpl in project meecrowave by apache.
the class Keystores method createSignedCertificate.
private static X509Certificate createSignedCertificate(final X509Certificate cetrificate, final X509Certificate issuerCertificate, final PrivateKey issuerPrivateKey) {
try {
Principal issuer = issuerCertificate.getSubjectDN();
String issuerSigAlg = issuerCertificate.getSigAlgName();
byte[] inCertBytes = cetrificate.getTBSCertificate();
X509CertInfo info = new X509CertInfo(inCertBytes);
info.set(X509CertInfo.ISSUER, (X500Name) issuer);
// No need to add the BasicContraint for leaf cert
if (!cetrificate.getSubjectDN().getName().equals("CN=TOP")) {
CertificateExtensions exts = new CertificateExtensions();
BasicConstraintsExtension bce = new BasicConstraintsExtension(true, -1);
exts.set(BasicConstraintsExtension.NAME, new BasicConstraintsExtension(false, bce.getExtensionValue()));
info.set(X509CertInfo.EXTENSIONS, exts);
}
final X509CertImpl outCert = new X509CertImpl(info);
outCert.sign(issuerPrivateKey, issuerSigAlg);
return outCert;
} catch (final Exception ex) {
throw new IllegalStateException(ex);
}
}
use of org.mozilla.jss.netscape.security.x509.X509CertImpl in project ddf by codice.
the class SignerConditionTest method testIsAltNameSatisfied.
@Test
public void testIsAltNameSatisfied() throws CertificateException {
Bundle bundle = mock(Bundle.class);
Map<X509Certificate, List<X509Certificate>> trustedCerts = new HashMap<>();
X509Certificate key = new X509CertImpl(SignerConditionTest.class.getResourceAsStream("/test.der"));
trustedCerts.put(key, new ArrayList<>());
when(bundle.getSignerCertificates(Bundle.SIGNERS_TRUSTED)).thenReturn(trustedCerts);
SignerCondition principalCondition = new SignerCondition(bundle, new ConditionInfo(SignerCondition.class.getName(), new String[] { "test" }));
boolean satisfied = principalCondition.isSatisfied();
assertThat(satisfied, is(true));
// also check alt name
principalCondition = new SignerCondition(bundle, new ConditionInfo(SignerCondition.class.getName(), new String[] { "alt-test" }));
satisfied = principalCondition.isSatisfied();
assertThat(satisfied, is(true));
}
Aggregations