CertificateReader { public boolean isCa() { final Extensions extensions = certificateHolder.getExtensions(); BasicConstraints basicConstraints = null; if (extensions != null) { basicConstraints = BasicConstraints .fromExtensions(Extensions.getInstance(extensions)); } return basicConstraints != null && basicConstraints.isCA(); } CertificateReader(final String pemString); X509Certificate getCertificate(); GeneralNames getAlternativeNames(); int getDurationDays(); ExtendedKeyUsage getExtendedKeyUsage(); X500Principal getSubjectName(); boolean isSignedByCa(final String caValue); int getKeyLength(); KeyUsage getKeyUsage(); boolean isSelfSigned(); boolean isCa(); Instant getNotAfter();  }
@Test public void isCa_whenTheCaBasicConstraintIsTrue_returnsTrue() { final CertificateReader certificateReader = new CertificateReader(SELF_SIGNED_CA_CERT); assertThat(certificateReader.isCa(), equalTo(true)); }
@Test public void isCa_whenTheCaBasicConstraintIsFalse_returnsFalse() { final CertificateReader certificateReader = new CertificateReader(SIMPLE_SELF_SIGNED_TEST_CERT); assertThat(certificateReader.isCa(), equalTo(false)); }
@Test public void isCa_whenTheCertificateIsX509V3_andDoesNotHaveBasicConstraints_returnsFalse() { final CertificateReader certificateReader = new CertificateReader( V3_CERT_WITHOUT_BASIC_CONSTRAINTS); assertThat(certificateReader.isCa(), equalTo(false)); }