PeppolCertificateChecker { @Nonnull public static EPeppolCertificateCheckResult checkPeppolAPCertificate (@Nullable final X509Certificate aCert, @Nullable final LocalDateTime aCheckDT, @Nonnull final ETriState eCacheOSCResult, @Nonnull final ETriState eCheckOSCP) { final boolean bCache = eCacheOSCResult.isUndefined () ? isCacheOCSPResults () : eCacheOSCResult.isTrue (); return _checkCertificate (aCert, aCheckDT, PEPPOL_AP_CA_ISSUERS, PEPPOL_AP_CA_CERTS, bCache ? REVOCATION_CACHE_AP : null, eCheckOSCP); } private  PeppolCertificateChecker(); static boolean isOCSPEnabled(); static void setOCSPEnabled(final boolean bCheck); static boolean isCacheOCSPResults(); static void setCacheOCSPResults(final boolean bCache); static void clearOCSPCache(); @Nonnull static Consumer <? super GeneralSecurityException> getExceptionHdl(); static void setExceptionHdl(@Nonnull final Consumer <? super GeneralSecurityException> aExceptionHdl); static boolean isCertificateRevoked(@Nonnull final X509Certificate aCert,
                                              @Nonnull final ICommonsList <X509Certificate> aValidCAs,
                                              @Nullable final LocalDateTime aCheckDT,
                                              @Nonnull final ETriState eCheckOSCP,
                                              @Nonnull final Consumer <? super GeneralSecurityException> aExceptionHdl); static boolean isPeppolAPCertificateRevoked(@Nonnull final X509Certificate aCert,
                                                      @Nullable final LocalDateTime aCheckDT,
                                                      @Nonnull final ETriState eCheckOSCP,
                                                      @Nonnull final Consumer <? super GeneralSecurityException> aExceptionHdl); static boolean isPeppolSMPCertificateRevoked(@Nonnull final X509Certificate aCert,
                                                       @Nullable final LocalDateTime aCheckDT,
                                                       @Nonnull final ETriState eCheckOSCP,
                                                       @Nonnull final Consumer <? super GeneralSecurityException> aExceptionHdl); @Nonnull static EPeppolCertificateCheckResult checkPeppolAPCertificate(@Nullable final X509Certificate aCert,
                                                                        @Nullable final LocalDateTime aCheckDT,
                                                                        @Nonnull final ETriState eCacheOSCResult,
                                                                        @Nonnull final ETriState eCheckOSCP); @Nonnull static EPeppolCertificateCheckResult checkPeppolSMPCertificate(@Nullable final X509Certificate aCert,
                                                                         @Nullable final LocalDateTime aCheckDT,
                                                                         @Nonnull final ETriState eCacheOSCResult,
                                                                         @Nonnull final ETriState eCheckOSCP); static final boolean DEFAULT_OSCP_CHECK_ENABLED; static final boolean DEFAULT_CACHE_OSCP_RESULTS; }
@Test public void testBasic () { EPeppolCertificateCheckResult e = PeppolCertificateChecker.checkPeppolAPCertificate (null, null, ETriState.UNDEFINED, ETriState.UNDEFINED); assertEquals (EPeppolCertificateCheckResult.NO_CERTIFICATE_PROVIDED, e); e = PeppolCertificateChecker.checkPeppolAPCertificate (PeppolKeyStoreHelper.Config2018.CERTIFICATE_PILOT_AP, PDTFactory.createLocalDateTime (2000, Month.JANUARY, 1), ETriState.UNDEFINED, ETriState.UNDEFINED); assertEquals (EPeppolCertificateCheckResult.NOT_YET_VALID, e); e = PeppolCertificateChecker.checkPeppolAPCertificate (PeppolKeyStoreHelper.Config2018.CERTIFICATE_PILOT_AP, PDTFactory.createLocalDateTime (2099, Month.JANUARY, 1), ETriState.UNDEFINED, ETriState.UNDEFINED); assertEquals (EPeppolCertificateCheckResult.EXPIRED, e); e = PeppolCertificateChecker.checkPeppolAPCertificate (PeppolKeyStoreHelper.Config2018.CERTIFICATE_PILOT_AP, null, ETriState.UNDEFINED, ETriState.UNDEFINED); assertEquals (EPeppolCertificateCheckResult.UNSUPPORTED_ISSUER, e); }
@Test public void testRealAPCert () throws Exception { final File fAP = new File ("src/test/resources/test-ap.p12"); if (fAP.exists ()) { final KeyStore aKS = KeyStoreHelper.loadKeyStore (EKeyStoreType.PKCS12, fAP.getAbsolutePath (), "peppol").getKeyStore (); assertNotNull (aKS); final X509Certificate aCert = (X509Certificate) aKS.getCertificate (aKS.aliases ().nextElement ()); final EPeppolCertificateCheckResult e = PeppolCertificateChecker.checkPeppolAPCertificate (aCert, null, ETriState.FALSE, ETriState.TRUE); assertEquals (EPeppolCertificateCheckResult.VALID, e); } }