From 33275922f3e27cf8596784af6a75dfa227d37876 Mon Sep 17 00:00:00 2001 From: John Jiang Date: Sun, 22 Oct 2023 03:12:00 +0800 Subject: [PATCH] TKSS-486: SM2KeyPairGenerator::initialize should not raise NullPointerException --- .../com/tencent/kona/crypto/provider/SM2KeyPairGenerator.java | 2 +- .../tencent/kona/crypto/provider/SM2KeyPairGeneratorTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kona-crypto/src/main/java/com/tencent/kona/crypto/provider/SM2KeyPairGenerator.java b/kona-crypto/src/main/java/com/tencent/kona/crypto/provider/SM2KeyPairGenerator.java index 3268054d..8679a9af 100644 --- a/kona-crypto/src/main/java/com/tencent/kona/crypto/provider/SM2KeyPairGenerator.java +++ b/kona-crypto/src/main/java/com/tencent/kona/crypto/provider/SM2KeyPairGenerator.java @@ -55,7 +55,7 @@ public void initialize(int keySize, SecureRandom random) { @Override public void initialize(AlgorithmParameterSpec params, SecureRandom random) { - if (!(params instanceof SM2ParameterSpec) + if (params == null || !(params instanceof SM2ParameterSpec) && !KnownOIDs.curveSM2.value().equals( ((NamedCurve) params).getObjectId())) { throw new IllegalArgumentException( diff --git a/kona-crypto/src/test/java/com/tencent/kona/crypto/provider/SM2KeyPairGeneratorTest.java b/kona-crypto/src/test/java/com/tencent/kona/crypto/provider/SM2KeyPairGeneratorTest.java index 16ebf6f2..12522cad 100644 --- a/kona-crypto/src/test/java/com/tencent/kona/crypto/provider/SM2KeyPairGeneratorTest.java +++ b/kona-crypto/src/test/java/com/tencent/kona/crypto/provider/SM2KeyPairGeneratorTest.java @@ -61,7 +61,7 @@ public void testInitialize() throws Exception { keyPairGen.initialize(SM2ParameterSpec.instance()); Assertions.assertThrows(IllegalArgumentException.class, () -> keyPairGen.initialize(CurveDB.P_256)); - Assertions.assertThrows(NullPointerException.class, + Assertions.assertThrows(IllegalArgumentException.class, () -> keyPairGen.initialize(null)); }