Skip to content

Commit 4135168

Browse files
committed
doc: amend README (#11)
Signed-off-by: Mart Somermaa <[email protected]>
1 parent d8d246d commit 4135168

File tree

8 files changed

+195
-289
lines changed

8 files changed

+195
-289
lines changed

README.md

Lines changed: 157 additions & 245 deletions
Large diffs are not rendered by default.

src/main/java/org/webeid/security/validator/AuthTokenValidationConfiguration.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ final class AuthTokenValidationConfiguration {
4646

4747
private URI siteOrigin;
4848
private Cache<String, LocalDateTime> nonceCache;
49-
private Collection<X509Certificate> trustedRootCACertificates = new HashSet<>();
49+
private Collection<X509Certificate> trustedCACertificates = new HashSet<>();
5050
private boolean isUserCertificateRevocationCheckWithOcspEnabled = true;
5151
private Duration ocspRequestTimeout = Duration.ofSeconds(5);
5252
private Duration allowedClientClockSkew = Duration.ofMinutes(3);
@@ -63,7 +63,7 @@ final class AuthTokenValidationConfiguration {
6363
private AuthTokenValidationConfiguration(AuthTokenValidationConfiguration other) {
6464
this.siteOrigin = other.siteOrigin;
6565
this.nonceCache = other.nonceCache;
66-
this.trustedRootCACertificates = new HashSet<>(other.trustedRootCACertificates);
66+
this.trustedCACertificates = new HashSet<>(other.trustedCACertificates);
6767
this.isUserCertificateRevocationCheckWithOcspEnabled = other.isUserCertificateRevocationCheckWithOcspEnabled;
6868
this.ocspRequestTimeout = other.ocspRequestTimeout;
6969
this.allowedClientClockSkew = other.allowedClientClockSkew;
@@ -89,8 +89,8 @@ Cache<String, LocalDateTime> getNonceCache() {
8989
return nonceCache;
9090
}
9191

92-
Collection<X509Certificate> getTrustedRootCACertificates() {
93-
return trustedRootCACertificates;
92+
Collection<X509Certificate> getTrustedCACertificates() {
93+
return trustedCACertificates;
9494
}
9595

9696
boolean isUserCertificateRevocationCheckWithOcspEnabled() {
@@ -148,8 +148,8 @@ void validate() {
148148
Objects.requireNonNull(siteOrigin, "Origin URI must not be null");
149149
OriginValidator.validateIsOriginURL(siteOrigin);
150150
Objects.requireNonNull(nonceCache, "Nonce cache must not be null");
151-
if (trustedRootCACertificates.isEmpty()) {
152-
throw new IllegalArgumentException("At least one trusted root certificate authority must be provided");
151+
if (trustedCACertificates.isEmpty()) {
152+
throw new IllegalArgumentException("At least one trusted certificate authority must be provided");
153153
}
154154
requirePositiveDuration(ocspRequestTimeout, "OCSP request timeout");
155155
requirePositiveDuration(allowedClientClockSkew, "Allowed client clock skew");

src/main/java/org/webeid/security/validator/AuthTokenValidatorBuilder.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,23 @@ public AuthTokenValidatorBuilder withNonceCache(Cache<String, LocalDateTime> cac
7373
}
7474

7575
/**
76-
* Sets the list of trusted user certificate root Certificate Authorities.
77-
* In order for the user certificate to be considered valid, the root certificate of the issuer
78-
* of the user certificate must be present in this list.
76+
* Adds the given certificates to the list of trusted subject certificate intermediate Certificate Authorities.
77+
* In order for the user certificate to be considered valid, the certificate of the issuer of the user certificate
78+
* must be present in this list.
7979
* <p>
80-
* At least one trusted root Certificate Authority must be provided as mandatory configuration parameter.
80+
* At least one trusted intermediate Certificate Authority must be provided as a mandatory configuration parameter.
8181
*
82-
* @param certificates trusted root Certificate Authority certificates
82+
* @param certificates trusted intermediate Certificate Authority certificates
8383
* @return the builder instance for method chaining
8484
*/
85-
public AuthTokenValidatorBuilder withTrustedRootCertificateAuthorities(X509Certificate... certificates) {
86-
Collections.addAll(configuration.getTrustedRootCACertificates(), certificates);
87-
LOG.debug("Trusted root certificate authorities set to {}", configuration.getTrustedRootCACertificates());
85+
public AuthTokenValidatorBuilder withTrustedCertificateAuthorities(X509Certificate... certificates) {
86+
Collections.addAll(configuration.getTrustedCACertificates(), certificates);
87+
LOG.debug("Trusted intermediate certificate authorities set to {}", configuration.getTrustedCACertificates());
8888
return this;
8989
}
9090

9191
/**
92-
* Sets the list of disallowed user certificate policies.
92+
* Adds the given policies to the list of disallowed user certificate policies.
9393
* In order for the user certificate to be considered valid, it must not contain any policies
9494
* present in this list.
9595
*
@@ -130,7 +130,7 @@ public AuthTokenValidatorBuilder withOcspRequestTimeout(Duration ocspRequestTime
130130
}
131131

132132
/**
133-
* Sets the list of OCSP URLs for which the nonce protocol extension will be disabled.
133+
* Adds the given URLs to the list of OCSP URLs for which the nonce protocol extension will be disabled.
134134
* The OCSP URL is extracted from the user certificate and some OCSP services don't support the nonce extension.
135135
*
136136
* @param urls OCSP URLs for which the nonce protocol extension will be disabled

src/main/java/org/webeid/security/validator/AuthTokenValidatorImpl.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ final class AuthTokenValidatorImpl implements AuthTokenValidator {
5858
private final Supplier<OkHttpClient> httpClientSupplier;
5959
private final ValidatorBatch simpleSubjectCertificateValidators;
6060
private final ValidatorBatch tokenBodyValidators;
61-
private final Set<TrustAnchor> trustedRootCACertificateAnchors;
62-
private final CertStore trustedRootCACertificateCertStore;
61+
private final Set<TrustAnchor> trustedCACertificateAnchors;
62+
private final CertStore trustedCACertificateCertStore;
6363

6464
/**
6565
* @param configuration configuration parameters for the token validator
@@ -89,17 +89,17 @@ final class AuthTokenValidatorImpl implements AuthTokenValidator {
8989
new SiteCertificateFingerprintValidator(configuration.getSiteCertificateSha256Fingerprint())::validateSiteCertificateFingerprint
9090
);
9191

92-
// Create and cache trusted root CA certificate JCA objects for SubjectCertificateTrustedValidator.
93-
trustedRootCACertificateAnchors = configuration.getTrustedRootCACertificates()
92+
// Create and cache trusted CA certificate JCA objects for SubjectCertificateTrustedValidator.
93+
trustedCACertificateAnchors = configuration.getTrustedCACertificates()
9494
.stream()
9595
.map(cert -> new TrustAnchor(cert, null))
9696
.collect(Collectors.toSet());
9797
try {
9898
// We use the default JCE provider as there is no reason to use Bouncy Castle, moreover BC requires
9999
// the validated certificate to be in the certificate store which breaks the clean immutable usage of
100-
// trustedRootCACertificateCertStore in SubjectCertificateTrustedValidator.
101-
trustedRootCACertificateCertStore = CertStore.getInstance("Collection",
102-
new CollectionCertStoreParameters(configuration.getTrustedRootCACertificates()));
100+
// trustedCACertificateCertStore in SubjectCertificateTrustedValidator.
101+
trustedCACertificateCertStore = CertStore.getInstance("Collection",
102+
new CollectionCertStoreParameters(configuration.getTrustedCACertificates()));
103103
} catch (GeneralSecurityException e) {
104104
throw new JceException(e);
105105
}
@@ -149,7 +149,7 @@ public X509Certificate validate(String authToken) throws TokenValidationExceptio
149149
*/
150150
private ValidatorBatch getCertTrustValidators() {
151151
final SubjectCertificateTrustedValidator certTrustedValidator =
152-
new SubjectCertificateTrustedValidator(trustedRootCACertificateAnchors, trustedRootCACertificateCertStore);
152+
new SubjectCertificateTrustedValidator(trustedCACertificateAnchors, trustedCACertificateCertStore);
153153
return ValidatorBatch.createFrom(
154154
certTrustedValidator::validateCertificateTrusted
155155
).addOptional(configuration.isUserCertificateRevocationCheckWithOcspEnabled(),

src/main/java/org/webeid/security/validator/validators/SubjectCertificateNotRevokedValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void validateCertificateNotRevoked(AuthTokenValidatorData actualTokenData
7777
final OCSPReq request = new OcspRequestBuilder()
7878
.certificate(certificate)
7979
.enableOcspNonce(!ocspNonceDisabled)
80-
.issuer(Objects.requireNonNull(trustValidator.getSubjectCertificateIssuerRootCertificate()))
80+
.issuer(Objects.requireNonNull(trustValidator.getSubjectCertificateIssuerCertificate()))
8181
.build();
8282

8383
LOG.debug("Sending OCSP request");

src/main/java/org/webeid/security/validator/validators/SubjectCertificateTrustedValidator.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,17 @@
3333
import java.security.cert.*;
3434
import java.util.Set;
3535

36-
/**
37-
* Validator that validates that the user certificate from the authentication token is signed by a trusted certificate authority.
38-
* <p>
39-
* We use the default JCE provider as there is no reason to use Bouncy Castle, moreover BC requires the validated certificate
40-
* to be in the certificate store which breaks the clean immutable usage of {@code trustedRootCACertificateCertStore}.
41-
*/
4236
public final class SubjectCertificateTrustedValidator {
4337

4438
private static final Logger LOG = LoggerFactory.getLogger(SubjectCertificateTrustedValidator.class);
4539

46-
private final Set<TrustAnchor> trustedRootCACertificateAnchors;
47-
private final CertStore trustedRootCACertificateCertStore;
48-
private X509Certificate subjectCertificateIssuerRootCertificate;
40+
private final Set<TrustAnchor> trustedCACertificateAnchors;
41+
private final CertStore trustedCACertificateCertStore;
42+
private X509Certificate subjectCertificateIssuerCertificate;
4943

50-
public SubjectCertificateTrustedValidator(Set<TrustAnchor> trustedRootCACertificateAnchors, CertStore trustedRootCACertificateCertStore) {
51-
this.trustedRootCACertificateAnchors = trustedRootCACertificateAnchors;
52-
this.trustedRootCACertificateCertStore = trustedRootCACertificateCertStore;
44+
public SubjectCertificateTrustedValidator(Set<TrustAnchor> trustedCACertificateAnchors, CertStore trustedCACertificateCertStore) {
45+
this.trustedCACertificateAnchors = trustedCACertificateAnchors;
46+
this.trustedCACertificateCertStore = trustedCACertificateCertStore;
5347
}
5448

5549
/**
@@ -66,15 +60,15 @@ public void validateCertificateTrusted(AuthTokenValidatorData actualTokenData) t
6660
selector.setCertificate(certificate);
6761

6862
try {
69-
final PKIXBuilderParameters pkixBuilderParameters = new PKIXBuilderParameters(trustedRootCACertificateAnchors, selector);
63+
final PKIXBuilderParameters pkixBuilderParameters = new PKIXBuilderParameters(trustedCACertificateAnchors, selector);
7064
pkixBuilderParameters.setRevocationEnabled(false);
71-
pkixBuilderParameters.addCertStore(trustedRootCACertificateCertStore);
65+
pkixBuilderParameters.addCertStore(trustedCACertificateCertStore);
7266

7367
// See the comment in AuthTokenValidatorImpl constructor why we use the default JCE provider.
7468
final CertPathBuilder certPathBuilder = CertPathBuilder.getInstance(CertPathBuilder.getDefaultType());
7569
final PKIXCertPathBuilderResult result = (PKIXCertPathBuilderResult) certPathBuilder.build(pkixBuilderParameters);
7670

77-
subjectCertificateIssuerRootCertificate = result.getTrustAnchor().getTrustedCert();
71+
subjectCertificateIssuerCertificate = result.getTrustAnchor().getTrustedCert();
7872

7973
} catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException e) {
8074
throw new JceException(e);
@@ -84,7 +78,7 @@ public void validateCertificateTrusted(AuthTokenValidatorData actualTokenData) t
8478
}
8579
}
8680

87-
public X509Certificate getSubjectCertificateIssuerRootCertificate() {
88-
return subjectCertificateIssuerRootCertificate;
81+
public X509Certificate getSubjectCertificateIssuerCertificate() {
82+
return subjectCertificateIssuerCertificate;
8983
}
9084
}

src/test/java/org/webeid/security/testutil/AuthTokenValidators.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private static AuthTokenValidatorBuilder getAuthTokenValidatorBuilder(String uri
8383
return new AuthTokenValidatorBuilder()
8484
.withSiteOrigin(URI.create(uri))
8585
.withNonceCache(cache)
86-
.withTrustedRootCertificateAuthorities(certificates);
86+
.withTrustedCertificateAuthorities(certificates);
8787
}
8888

8989
private static X509Certificate[] getCACertificates() throws CertificateException {

src/test/java/org/webeid/security/validator/AuthTokenValidatorBuilderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void testRootCertificateAuthorityMissing() {
2525
.withNonceCache(AbstractTestWithCache.createCache("AuthTokenValidatorBuilderTest"));
2626
assertThatThrownBy(builderWithMissingRootCa::build)
2727
.isInstanceOf(IllegalArgumentException.class)
28-
.hasMessageStartingWith("At least one trusted root certificate authority must be provided");
28+
.hasMessageStartingWith("At least one trusted certificate authority must be provided");
2929
}
3030

3131
}

0 commit comments

Comments
 (0)