當前位置: 首頁>>代碼示例>>Java>>正文


Java CertificateNotYetValidException類代碼示例

本文整理匯總了Java中java.security.cert.CertificateNotYetValidException的典型用法代碼示例。如果您正苦於以下問題:Java CertificateNotYetValidException類的具體用法?Java CertificateNotYetValidException怎麽用?Java CertificateNotYetValidException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CertificateNotYetValidException類屬於java.security.cert包,在下文中一共展示了CertificateNotYetValidException類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: verify

import java.security.cert.CertificateNotYetValidException; //導入依賴的package包/類
/**
 * verify that the given certificate successfully handles and confirms
 * the signature associated with this signer and, if a signingTime
 * attribute is available, that the certificate was valid at the time the
 * signature was generated.
 * @deprecated use verify(ContentVerifierProvider)
 */
public boolean verify(
    X509Certificate cert,
    Provider        sigProvider)
    throws NoSuchAlgorithmException,
        CertificateExpiredException, CertificateNotYetValidException,
        CMSException
{
    Time signingTime = getSigningTime();
    if (signingTime != null)
    {
        cert.checkValidity(signingTime.getDate());
    }

    return doVerify(cert.getPublicKey(), sigProvider); 
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:23,代碼來源:SignerInformation.java

示例2: getCertificateValidityString

import java.security.cert.CertificateNotYetValidException; //導入依賴的package包/類
public static String getCertificateValidityString(X509Certificate cert, Resources res) {
    try {
        cert.checkValidity();
    } catch (CertificateExpiredException ce) {
        return "EXPIRED: ";
    } catch (CertificateNotYetValidException cny) {
        return "NOT YET VALID: ";
    }
    Date certNotAfter = cert.getNotAfter();
    Date now = new Date();
    long timeLeft = certNotAfter.getTime() - now.getTime(); // Time left in ms
    // More than 72h left, display days
    // More than 3 months display months
    if (timeLeft > 90l * 24 * 3600 * 1000) {
        long months = getMonthsDifference(now, certNotAfter);
        return res.getString(R.string.months_left, months);
    } else if (timeLeft > 72 * 3600 * 1000) {
        long days = timeLeft / (24 * 3600 * 1000);
        return res.getString(R.string.days_left, days);
    } else {
        long hours = timeLeft / (3600 * 1000);
        return res.getString(R.string.hours_left, hours);
    }
}
 
開發者ID:akashdeepsingh9988,項目名稱:Cybernet-VPN,代碼行數:25,代碼來源:X509Utils.java

示例3: valid

import java.security.cert.CertificateNotYetValidException; //導入依賴的package包/類
/**
 * Verify that that the passed time is within the validity period.
 *
 * @exception CertificateExpiredException if the certificate has expired
 * with respect to the <code>Date</code> supplied.
 * @exception CertificateNotYetValidException if the certificate is not
 * yet valid with respect to the <code>Date</code> supplied.
 *
 */
public void valid(Date now)
throws CertificateNotYetValidException, CertificateExpiredException {
    /*
     * we use the internal Dates rather than the passed in Date
     * because someone could override the Date methods after()
     * and before() to do something entirely different.
     */
    if (notBefore.after(now)) {
        throw new CertificateNotYetValidException("NotBefore: " +
                                                  notBefore.toString());
    }
    if (notAfter.before(now)) {
        throw new CertificateExpiredException("NotAfter: " +
                                              notAfter.toString());
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:26,代碼來源:PrivateKeyUsageExtension.java

示例4: valid

import java.security.cert.CertificateNotYetValidException; //導入依賴的package包/類
/**
 * Verify that that the passed time is within the validity period.
 *
 * @exception CertificateExpiredException if the certificate has expired
 * with respect to the <code>Date</code> supplied.
 * @exception CertificateNotYetValidException if the certificate is not
 * yet valid with respect to the <code>Date</code> supplied.
 *
 */
public void valid(Date now)
throws CertificateNotYetValidException, CertificateExpiredException {
    Objects.requireNonNull(now);
    /*
     * we use the internal Dates rather than the passed in Date
     * because someone could override the Date methods after()
     * and before() to do something entirely different.
     */
    if (notBefore != null && notBefore.after(now)) {
        throw new CertificateNotYetValidException("NotBefore: " +
                                                  notBefore.toString());
    }
    if (notAfter != null && notAfter.before(now)) {
        throw new CertificateExpiredException("NotAfter: " +
                                              notAfter.toString());
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:27,代碼來源:PrivateKeyUsageExtension.java

示例5: sign

import java.security.cert.CertificateNotYetValidException; //導入依賴的package包/類
@Test
public void sign() {
  final DistinguishedName caName = dn("CN=CA-Test");
  final RootCertificate ca = createSelfSignedCertificate(caName).build();
  final CSR csr = createCsr().generateRequest(dn("CN=test"));
  final X509Certificate cert = ca.signCsr(csr)
      .setRandomSerialNumber()
      .sign()
      .getX509Certificate();

  try {
    cert.checkValidity();
  } catch (CertificateExpiredException | CertificateNotYetValidException e) {
    fail("Invalid certificate: " + e.toString());
  }
  assertEquals("CN=CA-Test", cert.getIssuerX500Principal().getName());
  assertEquals("CN=test", cert.getSubjectX500Principal().getName());
  assertEquals(csr.getPublicKey(), cert.getPublicKey());
}
 
開發者ID:olivierlemasle,項目名稱:java-certificate-authority,代碼行數:20,代碼來源:SignTest.java

示例6: test_generateSelfSignedX509CertificateV1

import java.security.cert.CertificateNotYetValidException; //導入依賴的package包/類
@Test
public void test_generateSelfSignedX509CertificateV1() throws NoSuchAlgorithmException, NoSuchProviderException, CertificateExpiredException, CertificateNotYetValidException, CertificateException, InvalidKeyException, SignatureException {
    final DistinguishedName issuer = issuer();

    final X500Principal principal = issuer.toX500Principal();

    final KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(RSA.name(), BOUNCY_CASTLE);
    final KeyPair keyPair = keyPairGenerator.generateKeyPair();

    final SelfSignedX509V1CertRequest request = new SelfSignedX509V1CertRequest(
            principal,
            BigInteger.ONE,
            Instant.now(),
            Instant.ofEpochMilli(System.currentTimeMillis() + (10 * 1000)),
            keyPair
    );
    log.info(String.format("request : %s", request));

    final X509Certificate cert = certificateService.generateSelfSignedX509CertificateV1(request);
    log.info(String.format("result.getSigAlgName() = %s, result.getVersion() = %s ", cert.getSigAlgName(), cert.getVersion()));
    assertThat(cert.getVersion(), is(1));

    cert.checkValidity();
    assertThat(Arrays.areEqual(principal.getEncoded(), cert.getIssuerX500Principal().getEncoded()), is(true));
    cert.verify(cert.getPublicKey());
}
 
開發者ID:runrightfast,項目名稱:runrightfast-vertx,代碼行數:27,代碼來源:CertificateServiceImplTest.java

示例7: checkCertificateValidity

import java.security.cert.CertificateNotYetValidException; //導入依賴的package包/類
@Override
public boolean checkCertificateValidity() {
	X509Certificate sigCert = getCertSign();
	X509Certificate encCert = getCertEnc();

	if (null == sigCert || null == encCert) {
		logger.error("Cannot obtain Certificates for validation");
		// treat as invalid
		return false;
	}

	Date now = new Date();
	try {
		sigCert.checkValidity(now);
		encCert.checkValidity(now);
	} catch (CertificateExpiredException | CertificateNotYetValidException e) {
		// certificate not (yet) valid
		return false;
	}

	return true;
}
 
開發者ID:Rohde-Schwarz-Cybersecurity,項目名稱:PanBox,代碼行數:23,代碼來源:Identity.java

示例8: verifySignature

import java.security.cert.CertificateNotYetValidException; //導入依賴的package包/類
public VerificationResultCode verifySignature(VerificationContext context) throws KSIException {
    Date validAt = context.getSignature().getAggregationTime();

    SignatureData signatureData = context.getCalendarAuthenticationRecord().getSignatureData();
    Certificate certificate = context.getCertificate(signatureData.getCertificateId());
    if (certificate instanceof X509Certificate) {
        try {
            ((X509Certificate) certificate).checkValidity(validAt);
            return VerificationResultCode.OK;
        } catch (CertificateExpiredException | CertificateNotYetValidException e) {
            LOGGER.info("Certificate id {} was not valid at the aggregation time {}",
                    Base16.encode(signatureData.getCertificateId()), validAt);
        }
    }

    LOGGER.info("Unable to check certificate validity, id = {}", Base16.encode(signatureData.getCertificateId()));
    return VerificationResultCode.FAIL;
}
 
開發者ID:guardtime,項目名稱:ksi-java-sdk,代碼行數:19,代碼來源:CertificateValidityRule.java

示例9: isValidSigningCertificateChain

import java.security.cert.CertificateNotYetValidException; //導入依賴的package包/類
private boolean isValidSigningCertificateChain(X509Certificate[] signingCertificateChain) {
    // Verify issuing chain
    if (signingCertificateChain.length > 1) {
        X500Principal expectedPrincipal = signingCertificateChain[0].getIssuerX500Principal();
        for (int i = 1; i < signingCertificateChain.length; ++i) { // start at the direct issuer
            X500Principal subject = signingCertificateChain[i].getSubjectX500Principal();
            if (!subject.equals(expectedPrincipal)) {
                LOG.error("Expecting: " + expectedPrincipal + " But found: " + subject);
                return false;
            }
            expectedPrincipal = signingCertificateChain[i].getIssuerX500Principal();
        }
    }

    // Check validity of the signing certificate;
    try {
        signingCertificateChain[0].checkValidity();
    } catch (CertificateExpiredException | CertificateNotYetValidException e) {
        LOG.error("Signing certificate was invalid!");
        return false;
    }

    // All good
    return true;
}
 
開發者ID:wdawson,項目名稱:revoker,代碼行數:26,代碼來源:OCSPHealthCheck.java

示例10: checkValidity

import java.security.cert.CertificateNotYetValidException; //導入依賴的package包/類
/**
 * @see java.security.cert.X509Certificate#checkValidity()
 * method documentation for more information.
 */
public void checkValidity() throws CertificateExpiredException,
                                   CertificateNotYetValidException {
    if (notBefore == -1) {
        // retrieve and cache the value of validity period
        notBefore = tbsCert.getValidity().getNotBefore().getTime();
        notAfter = tbsCert.getValidity().getNotAfter().getTime();
    }
    long time = System.currentTimeMillis();
    if (time < notBefore) {
        throw new CertificateNotYetValidException();
    }
    if (time > notAfter) {
        throw new CertificateExpiredException();
    }
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:20,代碼來源:X509CertImpl.java

示例11: checkCertificatesValidity

import java.security.cert.CertificateNotYetValidException; //導入依賴的package包/類
private void checkCertificatesValidity(KeyStore keyStore) throws KeyStoreException {
    if (ROOT_LOGGER.isEnabled(Logger.Level.WARN)) {
        Enumeration<String> aliases = keyStore.aliases();
        while (aliases.hasMoreElements()) {
            String alias = aliases.nextElement();
            Certificate certificate = keyStore.getCertificate(alias);
            if (certificate != null && certificate instanceof X509Certificate) {
                try {
                    ((X509Certificate) certificate).checkValidity();
                } catch (CertificateExpiredException | CertificateNotYetValidException e) {
                    ROOT_LOGGER.certificateNotValid(alias, e);
                }
            }
        }
    }
}
 
開發者ID:wildfly,項目名稱:wildfly-core,代碼行數:17,代碼來源:KeyStoreService.java

示例12: checkValidity

import java.security.cert.CertificateNotYetValidException; //導入依賴的package包/類
/**
 * @see X509Certificate#checkValidity()
 * method documentation for more information.
 */
public void checkValidity() throws CertificateExpiredException,
                                   CertificateNotYetValidException {
    if (notBefore == -1) {
        // retrieve and cache the value of validity period
        notBefore = tbsCert.getValidity().getNotBefore().getTime();
        notAfter = tbsCert.getValidity().getNotAfter().getTime();
    }
    long time = System.currentTimeMillis();
    if (time < notBefore) {
        throw new CertificateNotYetValidException();
    }
    if (time > notAfter) {
        throw new CertificateExpiredException();
    }
}
 
開發者ID:nextopio,項目名稱:nextop-client,代碼行數:20,代碼來源:X509CertImpl.java

示例13: checkValidity

import java.security.cert.CertificateNotYetValidException; //導入依賴的package包/類
@Override
public void checkValidity() throws CertificateExpiredException,
CertificateNotYetValidException {
    if (!this.valid) {
        throw new CertificateExpiredException();
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:8,代碼來源:AbstractX509CertificateTests.java

示例14: checkValidity

import java.security.cert.CertificateNotYetValidException; //導入依賴的package包/類
@Override
public void checkValidity() throws CertificateExpiredException,
        CertificateNotYetValidException {
    if (!this.valid) {
        throw new CertificateExpiredException();
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:8,代碼來源:AbstractX509CertificateTests.java


注:本文中的java.security.cert.CertificateNotYetValidException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。