Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,19 @@ protected void addEncryptedRequest(StepContext<M, EncryptedResponse> stepContext
stepContext.getStepLogger().writeError(getStep().id() + "-error-missing-temporary-shared-secret", "Temporary shared secret is missing", "Temporary shared secret was not derived when adding encrypted request");
return;
}
final String temporaryKeyId = (String) stepContext.getAttributes().get(TEMPORARY_KEY_ID);
if (temporaryKeyId == null) {
stepContext.getStepLogger().writeError(getStep().id() + "-error-missing-temporary-key-id", "Temporary key identifier is missing", "Temporary key identifier is missing when adding encrypted request");
return;
}
encryptorL1 = ENCRYPTOR_FACTORY.getClientEncryptor(
EncryptorId.APPLICATION_SCOPE_GENERIC,
new EncryptorParameters(model.getVersion().value(), model.getApplicationKey(), null, (String) stepContext.getAttributes().get(TEMPORARY_KEY_ID)),
new EncryptorParameters(model.getVersion().value(), model.getApplicationKey(), null, temporaryKeyId),
new AeadSecrets(sharedSecret.getEncoded(), model.getApplicationSecret())
);
encryptorL2 = ENCRYPTOR_FACTORY.getClientEncryptor(
EncryptorId.ACTIVATION_LAYER_2,
new EncryptorParameters(model.getVersion().value(), model.getApplicationKey(), null, (String) stepContext.getAttributes().get(TEMPORARY_KEY_ID)),
new EncryptorParameters(model.getVersion().value(), model.getApplicationKey(), null, temporaryKeyId),
new AeadSecrets(sharedSecret.getEncoded(), model.getApplicationSecret())
);
final SharedSecretClientContext clientContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ private static void handleSharedSecretResponse(StepContext<? extends BaseStepDat
stepContext.getAttributes().remove(TEMPORARY_CLIENT_CONTEXT);
}

private static boolean validateHybridSignatures(Map<String, JwtSignatureData> signatureData, Map<String, PublicKey> publicKeys, SharedSecretAlgorithm algorithm) throws IOException, GenericCryptoException, InvalidKeyException, CryptoProviderException {
private static boolean validateHybridSignatures(Map<String, JwtSignatureData> signatureData, Map<String, PublicKey> publicKeys, SharedSecretAlgorithm algorithm) throws IOException, GenericCryptoException {
if (algorithm != SharedSecretAlgorithm.EC_P384 && algorithm != SharedSecretAlgorithm.EC_P384_ML_L3) {
return false;
}
Expand All @@ -412,7 +412,7 @@ private static boolean validateHybridSignatures(Map<String, JwtSignatureData> si
return signaturesValid;
}

private static boolean validateJwtSignature(SignedJWT jwt, PublicKey publicKey, SharedSecretAlgorithm algorithm) throws IOException, GenericCryptoException, InvalidKeyException, CryptoProviderException {
private static boolean validateJwtSignature(SignedJWT jwt, PublicKey publicKey, SharedSecretAlgorithm algorithm) throws IOException {
final Base64URL[] jwtParts = jwt.getParsedParts();
final Base64URL encodedHeader = jwtParts[0];
final Base64URL encodedPayload = jwtParts[1];
Expand All @@ -422,12 +422,17 @@ private static boolean validateJwtSignature(SignedJWT jwt, PublicKey publicKey,
return validateEcSignature(signingInput, signatureBytes, publicKey, algorithm);
}

private static boolean validateEcSignature(byte[] signingInput, byte[] signatureBytes, PublicKey publicKey, SharedSecretAlgorithm algorithm) throws GenericCryptoException, InvalidKeyException, CryptoProviderException {
return switch (algorithm) {
case EC_P256 -> SIGNATURE_UTILS.validateECDSASignature(EcCurve.P256, signingInput, signatureBytes, publicKey);
case EC_P384, EC_P384_ML_L3 -> SIGNATURE_UTILS.validateECDSASignature(EcCurve.P384, signingInput, signatureBytes, publicKey);
default -> throw new IllegalArgumentException("Unsupported shared secret algorithm: " + algorithm);
};
private static boolean validateEcSignature(byte[] signingInput, byte[] signatureBytes, PublicKey publicKey, SharedSecretAlgorithm algorithm) {
try {
return switch (algorithm) {
case EC_P256 -> SIGNATURE_UTILS.validateECDSASignature(EcCurve.P256, signingInput, signatureBytes, publicKey);
case EC_P384, EC_P384_ML_L3 -> SIGNATURE_UTILS.validateECDSASignature(EcCurve.P384, signingInput, signatureBytes, publicKey);
default -> throw new IllegalArgumentException("Unsupported shared secret algorithm: " + algorithm);
};
} catch (GenericCryptoException | InvalidKeyException | CryptoProviderException e) {
// Can happen in case of incorrect configuration, already logged by crypto library
}
return false;
}

private static byte[] convertRawSignatureToDER(byte[] rawSignature) throws IOException {
Expand Down