Skip to content

Commit 5ba8e7f

Browse files
committed
Change semantics of --force-new-ta-certificate, make it reissue the certificate in all cases
1 parent 3df285e commit 5ba8e7f

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

src/main/java/net/ripe/rpki/ta/TA.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,13 @@
5454

5555
import static net.ripe.rpki.commons.crypto.x509cert.X509CertificateInformationAccessDescriptor.*;
5656

57+
@Getter
5758
@Slf4j(topic = "TA")
5859
public class TA {
5960

6061
public static final IpResourceSet ALL_RESOURCES_SET = IpResourceSet.parse("AS0-AS4294967295, 0/0, 0::/0");
6162

62-
@Getter
6363
private TAState state;
64-
6564
private final ValidityPeriods validityPeriods;
6665

6766
public static TA initialise(Config config) throws GeneralSecurityException, IOException {
@@ -303,17 +302,22 @@ private Pair<TrustAnchorResponse, TAState> processRequest(final TrustAnchorReque
303302
revokeAllIssuedResourceCertificates(newTAState);
304303
}
305304

305+
// There are two cases when we need to re-issue the TA certificate:
306+
// 1. We explicitly ask for it by providing the --force-new-ta-certificate option
307+
// 2. The TA certificate publication point or the notification.xml URL has changed
308+
306309
// re-issue TA certificate if some of the publication points are changed
307-
final Optional<String> whyReissue = taCertificateHasToBeReIssued(request, signCtx.taState.getConfig());
308-
if (whyReissue.isPresent()) {
309-
if (!options.hasForceNewTaCertificate()) {
310-
throw new OperationAbortedException("TA certificate has to be re-issued: " + whyReissue.get() +
311-
", bailing out. Provide " + ProgramOptions.FORCE_NEW_TA_CERT_OPT + " option to force TA certificate re-issue.");
312-
}
310+
final Optional<String> differentLocations = locationsAreDifferent(request, signCtx.taState.getConfig());
313311

314-
// copy new SIAs to the TA config
315-
updateTaConfigUrls(request, signCtx);
312+
if (differentLocations.isPresent() && !options.hasForceNewTaCertificate()) {
313+
throw new OperationAbortedException("TA certificate has to be re-issued: " + differentLocations.get() +
314+
", bailing out. Provide " + ProgramOptions.FORCE_NEW_TA_CERT_OPT + " option to force TA certificate re-issue.");
315+
}
316316

317+
if (options.hasForceNewTaCertificate() || differentLocations.isPresent()) {
318+
if (differentLocations.isPresent()) {
319+
updateTaConfigUrls(request, signCtx);
320+
}
317321
final KeyPair keyPair = decoded.getLeft();
318322
final X509ResourceCertificate taCertificate = decoded.getRight();
319323
final BigInteger nextSerial = nextIssuedCertSerial(state);
@@ -322,7 +326,7 @@ private Pair<TrustAnchorResponse, TAState> processRequest(final TrustAnchorReque
322326
signCtx.taState.getConfig()
323327
);
324328
final X509ResourceCertificate newTACertificate = reIssueRootCertificate(keyPair,
325-
merge(ta0SiaDescriptors, request.getSiaDescriptors()), taCertificate, nextSerial);
329+
merge(ta0SiaDescriptors, request.getSiaDescriptors()), taCertificate, nextSerial);
326330

327331
TAStateBuilder taStateBuilder = new TAStateBuilder(newTAState);
328332
taStateBuilder.withCrl(newTAState.getCrl());
@@ -344,7 +348,7 @@ private Pair<TrustAnchorResponse, TAState> processRequest(final TrustAnchorReque
344348
return Pair.of(new TrustAnchorResponse(request.getCreationTimestamp(), publishedObjects, taResponses), newTAState);
345349
}
346350

347-
private Optional<String> taCertificateHasToBeReIssued(TrustAnchorRequest taRequest, Config taConfig) {
351+
private Optional<String> locationsAreDifferent(TrustAnchorRequest taRequest, Config taConfig) {
348352
if (!taConfig.getTaCertificatePublicationUri().equals(taRequest.getTaCertificatePublicationUri())) {
349353
return Optional.of("Different TA certificate location, request has '" +
350354
taRequest.getTaCertificatePublicationUri() + "', config has '" + taConfig.getTaCertificatePublicationUri() + "'");

src/main/java/net/ripe/rpki/ta/config/ProgramOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class ProgramOptions {
4848

4949
options.addOption(Option.builder().longOpt(FORCE_NEW_TA_CERT_OPT).
5050
hasArg(false).
51-
desc("Force re-issuing new TA certificate if there're SIA differences between config and request").
51+
desc("Force re-issuing new TA certificate. This option is mandatory if there are SIA differences between request and config (or request and stored TA state)").
5252
build());
5353

5454
options.addOption(Option.builder().longOpt(REVOKE_NON_REQUESTED_OBJECTS)

src/main/java/net/ripe/rpki/ta/util/ValidityPeriods.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
public class ValidityPeriods {
99

10-
private static final int TA_CERTIFICATE_VALIDITY_TIME_IN_YEARS = 100;
10+
private static final int TA_CERTIFICATE_VALIDITY_TIME_IN_MONTHS = 6;
1111

1212
// Since this program runs within a script, we can safely assume that all
1313
// calls to "now" can be replaced with a value calculated only once.
@@ -30,7 +30,7 @@ public ValidityPeriod allResourcesCertificate() {
3030

3131
public static ValidityPeriod taCertificate() {
3232
final DateTime notValidBefore = ValidityPeriods.now();
33-
return new ValidityPeriod(notValidBefore, notValidBefore.plusYears(TA_CERTIFICATE_VALIDITY_TIME_IN_YEARS));
33+
return new ValidityPeriod(notValidBefore, notValidBefore.plusMonths(TA_CERTIFICATE_VALIDITY_TIME_IN_MONTHS));
3434
}
3535

3636
public ValidityPeriod crl() {

src/test/java/net/ripe/rpki/ta/integration/MainIntegrationTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ public void test_process_request() throws Exception {
101101
run("--request=./src/test/resources/ta-request.xml --force-new-ta-certificate " +
102102
"--response=" + response.getAbsolutePath() + " --env=test").exitCode);
103103
final TAState taState2 = reloadTaState();
104-
assertEquals(BigInteger.valueOf(6L), taState2.getLastIssuedCertificateSerial());
104+
// TA certificate will be reissued, so serial numbers will be incremented
105+
assertEquals(BigInteger.valueOf(7L), taState2.getLastIssuedCertificateSerial());
105106
assertEquals(BigInteger.valueOf(2L), taState2.getLastMftSerial());
106107
assertEquals(BigInteger.valueOf(2L), taState2.getLastCrlSerial());
107108
assertEquals(2, taState2.getSignedProductionCertificates().size());
@@ -112,7 +113,8 @@ public void test_process_request() throws Exception {
112113
run("--request=./src/test/resources/ta-request.xml --force-new-ta-certificate " +
113114
"--response=" + response.getAbsolutePath() + " --env=test").exitCode);
114115
final TAState taState3 = reloadTaState();
115-
assertEquals(BigInteger.valueOf(8L), taState3.getLastIssuedCertificateSerial());
116+
// TA certificate will be re-issued simply because of the -force-new-ta-certificate
117+
assertEquals(BigInteger.valueOf(10L), taState3.getLastIssuedCertificateSerial());
116118
assertEquals(BigInteger.valueOf(3L), taState3.getLastMftSerial());
117119
assertEquals(BigInteger.valueOf(3L), taState3.getLastCrlSerial());
118120

0 commit comments

Comments
 (0)