List of usage examples for org.bouncycastle.asn1.x509 PrivateKeyUsagePeriod getNotBefore
public ASN1GeneralizedTime getNotBefore()
From source file:net.sf.keystore_explorer.crypto.x509.X509Ext.java
License:Open Source License
private String getPrivateKeyUsagePeriodStringValue(byte[] value) throws IOException { // @formatter:off /*/*from w w w . j ava2s . com*/ * PrivateKeyUsagePeriod ::= ASN1Sequence { notBefore [0] * ASN1GeneralizedTime OPTIONAL, notAfter [1] ASN1GeneralizedTime OPTIONAL } */ // @formatter:on StringBuilder sb = new StringBuilder(); PrivateKeyUsagePeriod privateKeyUsagePeriod = PrivateKeyUsagePeriod.getInstance(value); ASN1GeneralizedTime notBefore = privateKeyUsagePeriod.getNotBefore(); ASN1GeneralizedTime notAfter = privateKeyUsagePeriod.getNotAfter(); if (notBefore != null) { sb.append(MessageFormat.format(res.getString("NotBeforePrivateKeyUsagePeriod"), getGeneralizedTimeString(notBefore))); } else { sb.append(MessageFormat.format(res.getString("NotBeforePrivateKeyUsagePeriod"), res.getString("NoValue"))); } sb.append(NEWLINE); if (notAfter != null) { sb.append(MessageFormat.format(res.getString("NotAfterPrivateKeyUsagePeriod"), getGeneralizedTimeString(notAfter))); } else { sb.append( MessageFormat.format(res.getString("NotAfterPrivateKeyUsagePeriod"), res.getString("NoValue"))); } sb.append(NEWLINE); return sb.toString(); }
From source file:net.sf.keystore_explorer.gui.dialogs.extensions.DPrivateKeyUsagePeriod.java
License:Open Source License
private void prepopulateWithValue(byte[] value) throws IOException { PrivateKeyUsagePeriod privateKeyUsagePeriod = PrivateKeyUsagePeriod.getInstance(value); ASN1GeneralizedTime notBefore = privateKeyUsagePeriod.getNotBefore(); if (notBefore != null) { try {//from w w w . j av a 2s. co m jdtNotBefore.setDateTime(notBefore.getDate()); } catch (ParseException e) { throw new IOException(e); } } ASN1GeneralizedTime notAfter = privateKeyUsagePeriod.getNotAfter(); if (notAfter != null) { try { jdtNotAfter.setDateTime(notAfter.getDate()); } catch (ParseException e) { throw new IOException(e); } } }
From source file:net.sf.portecle.crypto.X509Ext.java
License:Open Source License
/** * Get Private Key Usage Period (2.5.29.16) extension value as a string. * /* w ww . j av a2s . c om*/ * <pre> * PrivateKeyUsagePeriod ::= SEQUENCE { * notBefore [0] GeneralizedTime OPTIONAL, * notAfter [1] GeneralizedTime OPTIONAL } * </pre> * * @param bValue The octet string value * @return Extension value as a string * @throws IOException If an I/O problem occurs * @throws ParseException If a date formatting problem occurs */ private String getPrivateKeyUsagePeriod(byte[] bValue) throws IOException, ParseException { PrivateKeyUsagePeriod pkup = PrivateKeyUsagePeriod.getInstance(bValue); StringBuilder strBuff = new StringBuilder(); ASN1GeneralizedTime dTime; if ((dTime = pkup.getNotBefore()) != null) { strBuff.append(MessageFormat.format(RB.getString("PrivateKeyUsagePeriodNotBefore"), formatGeneralizedTime(dTime))); } if ((dTime = pkup.getNotAfter()) != null) { if (strBuff.length() != 0) { strBuff.append("<br><br>"); } strBuff.append(MessageFormat.format(RB.getString("PrivateKeyUsagePeriodNotAfter"), formatGeneralizedTime(dTime))); } return strBuff.toString(); }
From source file:org.cesecore.certificates.ca.internal.CertificateValidity.java
License:Open Source License
/** * Checks that the PrivateKeyUsagePeriod of the certificate is valid at this time * @param cacert// ww w .j ava2s . c o m * @throws CAOfflineException if PrivateKeyUsagePeriod either is not valid yet or has expired, exception message gives details */ public static void checkPrivateKeyUsagePeriod(final X509Certificate cert) throws CAOfflineException { if (cert != null) { final PrivateKeyUsagePeriod pku = CertTools.getPrivateKeyUsagePeriod(cert); if (pku != null) { final Date now = new Date(); final ASN1GeneralizedTime notBefore = pku.getNotBefore(); final Date pkuNotBefore; final Date pkuNotAfter; try { if (notBefore == null) { pkuNotBefore = null; } else { pkuNotBefore = notBefore.getDate(); } if (log.isDebugEnabled()) { log.debug("PrivateKeyUsagePeriod.notBefore is " + pkuNotBefore); } if (pkuNotBefore != null && now.before(pkuNotBefore)) { final String msg = intres.getLocalizedMessage("createcert.privatekeyusagenotvalid", pkuNotBefore.toString(), cert.getSubjectDN().toString()); if (log.isDebugEnabled()) { log.debug(msg); } throw new CAOfflineException(msg); } final ASN1GeneralizedTime notAfter = pku.getNotAfter(); if (notAfter == null) { pkuNotAfter = null; } else { pkuNotAfter = notAfter.getDate(); } } catch (ParseException e) { throw new IllegalStateException("Could not parse dates.", e); } if (log.isDebugEnabled()) { log.debug("PrivateKeyUsagePeriod.notAfter is " + pkuNotAfter); } if (pkuNotAfter != null && now.after(pkuNotAfter)) { final String msg = intres.getLocalizedMessage("createcert.privatekeyusageexpired", pkuNotAfter.toString(), cert.getSubjectDN().toString()); if (log.isDebugEnabled()) { log.debug(msg); } throw new CAOfflineException(msg); } } else if (log.isDebugEnabled()) { log.debug("No PrivateKeyUsagePeriod available in certificate."); } } else if (log.isDebugEnabled()) { log.debug("No CA certificate available, not checking PrivateKeyUsagePeriod."); } }
From source file:org.ejbca.core.ejb.ca.sign.PrivateKeyUsageSignSessionTest.java
License:Open Source License
private void privateKeyUsageTestStartOffset(final long startOffset) throws Exception { X509Certificate cert = privateKeyUsageGetCertificate(true, startOffset, false, 0L, false); assertNotNull("Has not the extension", cert.getExtensionValue("2.5.29.16")); assertTrue("Extension is non-critical", cert.getNonCriticalExtensionOIDs().contains("2.5.29.16")); PrivateKeyUsagePeriod ext = PrivateKeyUsagePeriod .getInstance(X509ExtensionUtil.fromExtensionValue(cert.getExtensionValue("2.5.29.16"))); assertNotNull("Has notBefore", ext.getNotBefore()); assertNull("Has no notAfter", ext.getNotAfter()); assertEquals("notBefore " + startOffset + " seconds after ca cert", cert.getNotBefore().getTime() + startOffset * 1000, ext.getNotBefore().getDate().getTime()); }
From source file:org.ejbca.core.ejb.ca.sign.PrivateKeyUsageSignSessionTest.java
License:Open Source License
private void privateKeyUsageTestValidityLength(final long length) throws Exception { X509Certificate cert = privateKeyUsageGetCertificate(false, 0L, true, length, false); assertNotNull("Has the extension", cert.getExtensionValue("2.5.29.16")); assertTrue("Extension is non-critical", cert.getNonCriticalExtensionOIDs().contains("2.5.29.16")); PrivateKeyUsagePeriod ext = PrivateKeyUsagePeriod .getInstance(X509ExtensionUtil.fromExtensionValue(cert.getExtensionValue("2.5.29.16"))); assertNotNull("Has notAfter", ext.getNotAfter()); assertNull("Has no notBefore", ext.getNotBefore()); assertEquals("notAfter " + length + " seconds after issue time", cert.getNotBefore().getTime() + length * 1000, ext.getNotAfter().getDate().getTime()); }
From source file:org.ejbca.core.ejb.ca.sign.PrivateKeyUsageSignSessionTest.java
License:Open Source License
private void privateKeyUsageTestBoth(final long startOffset, final long length, boolean allowValidityOverride) throws Exception { X509Certificate cert = privateKeyUsageGetCertificate(true, startOffset, true, length, allowValidityOverride);/*from ww w .j a v a 2s . c o m*/ assertNotNull("Has the extension", cert.getExtensionValue("2.5.29.16")); assertTrue("Extension is non-critical", cert.getNonCriticalExtensionOIDs().contains("2.5.29.16")); PrivateKeyUsagePeriod ext = PrivateKeyUsagePeriod .getInstance(X509ExtensionUtil.fromExtensionValue(cert.getExtensionValue("2.5.29.16"))); assertNotNull("Has notBefore", ext.getNotBefore()); assertNotNull("Has notAfter", ext.getNotAfter()); assertEquals("notBefore " + startOffset + " seconds after ca cert", cert.getNotBefore().getTime() + startOffset * 1000, ext.getNotBefore().getDate().getTime()); assertEquals("notAfter " + length + " seconds after notBefore", ext.getNotBefore().getDate().getTime() + length * 1000, ext.getNotAfter().getDate().getTime()); }
From source file:org.ejbca.core.ejb.ca.sign.SignSessionTest.java
License:Open Source License
private void privateKeyUsageTestStartOffset(final long startOffset) throws Exception { X509Certificate cert = privateKeyUsageGetCertificate(true, startOffset, false, 0L); assertNotNull("Has the extension", cert.getExtensionValue("2.5.29.16")); assertTrue("Extension is non-critical", cert.getNonCriticalExtensionOIDs().contains("2.5.29.16")); PrivateKeyUsagePeriod ext = PrivateKeyUsagePeriod .getInstance(X509ExtensionUtil.fromExtensionValue(cert.getExtensionValue("2.5.29.16"))); assertNotNull("Has notBefore", ext.getNotBefore()); assertNull("Has no notAfter", ext.getNotAfter()); assertEquals("notBefore " + startOffset + " seconds after ca cert", cert.getNotBefore().getTime() + startOffset * 1000, ext.getNotBefore().getDate().getTime()); }
From source file:org.ejbca.core.ejb.ca.sign.SignSessionTest.java
License:Open Source License
private void privateKeyUsageTestValidityLength(final long length) throws Exception { X509Certificate cert = privateKeyUsageGetCertificate(false, 0L, true, length); assertNotNull("Has the extension", cert.getExtensionValue("2.5.29.16")); assertTrue("Extension is non-critical", cert.getNonCriticalExtensionOIDs().contains("2.5.29.16")); PrivateKeyUsagePeriod ext = PrivateKeyUsagePeriod .getInstance(X509ExtensionUtil.fromExtensionValue(cert.getExtensionValue("2.5.29.16"))); assertNotNull("Has notAfter", ext.getNotAfter()); assertNull("Has no notBefore", ext.getNotBefore()); assertEquals("notAfter " + length + " seconds after issue time", cert.getNotBefore().getTime() + length * 1000, ext.getNotAfter().getDate().getTime()); }
From source file:org.ejbca.core.ejb.ca.sign.SignSessionTest.java
License:Open Source License
private void privateKeyUsageTestBoth(final long startOffset, final long length) throws Exception { X509Certificate cert = privateKeyUsageGetCertificate(true, startOffset, true, length); assertNotNull("Has the extension", cert.getExtensionValue("2.5.29.16")); assertTrue("Extension is non-critical", cert.getNonCriticalExtensionOIDs().contains("2.5.29.16")); PrivateKeyUsagePeriod ext = PrivateKeyUsagePeriod .getInstance(X509ExtensionUtil.fromExtensionValue(cert.getExtensionValue("2.5.29.16"))); assertNotNull("Has notBefore", ext.getNotBefore()); assertNotNull("Has notAfter", ext.getNotAfter()); assertEquals("notBefore " + startOffset + " seconds after ca cert", cert.getNotBefore().getTime() + startOffset * 1000, ext.getNotBefore().getDate().getTime()); assertEquals("notAfter " + length + " seconds after notBefore", ext.getNotBefore().getDate().getTime() + length * 1000, ext.getNotAfter().getDate().getTime()); }