Skip to content

Commit 3df285e

Browse files
authored
Merge pull request #8 from RIPE-NCC/feature/hsm-keypair-generator-for-ee-key
Feature/hsm keypair generator for ee key
2 parents acb163e + def2531 commit 3df285e

File tree

7 files changed

+48
-27
lines changed

7 files changed

+48
-27
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ https://github.com/RIPE-NCC/rpki-ta-0/blob/main/LICENSE.txt.
1515
Changelog
1616
---------
1717

18+
### v0.5.3
19+
* Fix issues when working with HSM in FIPS 140-[23] level 3 mode
20+
21+
### v0.5.2
22+
* Releases are made using GitHub actions from now on
23+
1824
### v0.5.1
1925
* Publish releases on GitHub
2026

gradle/wrapper/gradle-wrapper.jar

-19.5 KB
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.joda.time.DateTime;
4242
import org.joda.time.DateTimeZone;
4343

44+
import javax.security.auth.DestroyFailedException;
4445
import javax.security.auth.x500.X500Principal;
4546
import java.io.*;
4647
import java.math.BigInteger;
@@ -471,10 +472,12 @@ private void fillRevokedObjects(X509CrlBuilder builder, List<? extends SignedObj
471472
}
472473

473474
private ManifestCms createNewManifest(final SignCtx signCtx) {
474-
// Generate a new key pair for the one-time-use EE certificate and do not store it, this prevents accidental
475-
// re-use in the future, and prevents keys from piling up in the HSM 'security world'
475+
// Generate a new key pair for the one-time-use EE certificate
476+
// this key _needs_ to be stored in the HSM (and thus use the HSM keypair factory) because otherwise
477+
// the operation triggers an import of the key _into_ the security world, which is not allowed
478+
// in FIPS 140-[23] level 3 mode.
476479
final KeyPairFactory keyPairFactory = new KeyPairFactory(state.getConfig().getKeystoreProvider());
477-
final KeyPair eeKeyPair = keyPairFactory.withProvider("SunRsaSign").generate();
480+
final KeyPair eeKeyPair = keyPairFactory.withProvider(state.getConfig().getKeypairGeneratorProvider()).generate();
478481
final X509ResourceCertificate eeCertificate = createEeCertificateForManifest(eeKeyPair, signCtx);
479482

480483
final ManifestCmsBuilder manifestBuilder = createBasicManifestBuilder(eeCertificate, signCtx);
@@ -486,6 +489,13 @@ private ManifestCms createNewManifest(final SignCtx signCtx) {
486489
}
487490
}
488491
final ManifestCms manifest = manifestBuilder.build(eeKeyPair.getPrivate());
492+
// Destroy the keypair to prevent it from being kept.
493+
try {
494+
eeKeyPair.getPrivate().destroy();
495+
} catch (DestroyFailedException e) {
496+
log.info("Could not destroy private key for {} provider, this is probably expected.",
497+
state.getConfig().getKeypairGeneratorProvider());
498+
}
489499
signCtx.taState.getSignedManifests().add(new SignedManifest(manifest));
490500
return manifest;
491501
}

src/main/scripts/ta.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,19 @@ fi
2222
CONF_DIR="conf"
2323
LIB_DIR="lib"
2424
CLASSPATH=${CONF_DIR}:"$LIB_DIR/*"
25-
CARDSET="TA2022"
25+
CARDSET="OCS2024"
2626
MAIN_CLASS="net.ripe.rpki.ta.Main"
2727

28-
TA_TOOL_COMMAND="${JAVA_HOME}/bin/java ${JAVA_OPTS} --module-path /opt/nfast/java/classes -classpath ${CLASSPATH} ${MAIN_CLASS} --env=${APPLICATION_ENVIRONMENT} $@"
29-
3028
if [ ${APPLICATION_ENVIRONMENT} == "production" ]; then
31-
# production uses cardset protected keys
32-
JAVA_OPTS="-Dprotect=cardset -DignorePassphrase=true $JAVA_OPTS"
29+
# production:
30+
# * uses cardset protected keys
31+
# * load the JCE provider from the module path
32+
JAVA_OPTS="-Dprotect=cardset -DignorePassphrase=true --module-path=/opt/nfast/java/classes $JAVA_OPTS"
33+
fi
3334

35+
TA_TOOL_COMMAND="${JAVA_HOME}/bin/java ${JAVA_OPTS} -classpath ${CLASSPATH} ${MAIN_CLASS} --env=${APPLICATION_ENVIRONMENT} $@"
36+
37+
if [ ${APPLICATION_ENVIRONMENT} == "production" ]; then
3438
# preload the keys (and provide OCS authorisation with 3/10 cards), then execute the trust anchor binary.
3539
${NFAST_BIN}/preload -c ${CARDSET} ${TA_TOOL_COMMAND}
3640
else

0 commit comments

Comments
 (0)