From 6c5bcfb7ad6d54c9833b9099422a8d2caa3e1887 Mon Sep 17 00:00:00 2001 From: David Hook Date: Fri, 27 Dec 2024 11:08:27 +1100 Subject: [PATCH] added support for composite private keys nested in OCTET STRING minor refactor - removed use of toUpperCase() in BCMLDSAPrivateKey --- .../asymmetric/compositesignatures/KeyFactorySpi.java | 11 ++++++++++- .../provider/asymmetric/mldsa/BCMLDSAPrivateKey.java | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/compositesignatures/KeyFactorySpi.java b/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/compositesignatures/KeyFactorySpi.java index 600d85244d..7a3dfe850c 100644 --- a/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/compositesignatures/KeyFactorySpi.java +++ b/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/compositesignatures/KeyFactorySpi.java @@ -18,6 +18,7 @@ import java.util.Map; import org.bouncycastle.asn1.ASN1BitString; +import org.bouncycastle.asn1.ASN1Encodable; import org.bouncycastle.asn1.ASN1EncodableVector; import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.ASN1OctetString; @@ -192,7 +193,15 @@ public PrivateKey generatePrivate(PrivateKeyInfo keyInfo) // TODO: backwards compatibility code - should be deleted after 1.84. try { - seq = DERSequence.getInstance(keyInfo.parsePrivateKey()); + ASN1Encodable obj = keyInfo.parsePrivateKey(); + if (obj instanceof ASN1OctetString) + { + seq = DERSequence.getInstance(ASN1OctetString.getInstance(obj).getOctets()); + } + else + { + seq = DERSequence.getInstance(obj); + } } catch (Exception e) { diff --git a/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/mldsa/BCMLDSAPrivateKey.java b/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/mldsa/BCMLDSAPrivateKey.java index 681e116848..4cc33e8b14 100644 --- a/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/mldsa/BCMLDSAPrivateKey.java +++ b/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/mldsa/BCMLDSAPrivateKey.java @@ -51,7 +51,7 @@ private void init(MLDSAPrivateKeyParameters params, ASN1Set attributes) { this.attributes = attributes; this.params = params; - algorithm = MLDSAParameterSpec.fromName(params.getParameters().getName()).getName().toUpperCase(); + algorithm = Strings.toUpperCase(MLDSAParameterSpec.fromName(params.getParameters().getName()).getName()); } /**