3b13d8
From 3adb695ea6a7f50d7631a4c048f75dae078889fa Mon Sep 17 00:00:00 2001
3b13d8
From: Jack Magne <jmagne@redhat.com>
3b13d8
Date: Thu, 24 Aug 2023 20:41:00 -0400
3b13d8
Subject: [PATCH 5/8] Fix Bug 2180920 add AES support for TMS server-side
3b13d8
 keygen on latest HSM / FIPS environment [RHCS 9.7.z]
3b13d8
3b13d8
Back port AES KWP wrap alg support only for JSS in this branch to allow for the TMS bug referenced above to work.
3b13d8
---
3b13d8
 org/mozilla/jss/crypto/Algorithm.c           | 3 ++-
3b13d8
 org/mozilla/jss/crypto/Algorithm.h           | 2 +-
3b13d8
 org/mozilla/jss/crypto/Algorithm.java        | 2 ++
3b13d8
 org/mozilla/jss/crypto/KeyWrapAlgorithm.java | 8 ++++++++
3b13d8
 4 files changed, 13 insertions(+), 2 deletions(-)
3b13d8
3b13d8
diff --git a/org/mozilla/jss/crypto/Algorithm.c b/org/mozilla/jss/crypto/Algorithm.c
3b13d8
index 84290ad..9492d01 100644
3b13d8
--- a/org/mozilla/jss/crypto/Algorithm.c
3b13d8
+++ b/org/mozilla/jss/crypto/Algorithm.c
3b13d8
@@ -96,7 +96,8 @@ JSS_AlgInfo JSS_AlgTable[NUM_ALGS] = {
3b13d8
 /* the CKM_AES_KEY_WRAP_* have different defs than CKM_NSS_AES_KEY_WRAP_*  */
3b13d8
 /* 65 */    {CKM_AES_KEY_WRAP, PK11_MECH},
3b13d8
 /* 66 */    {CKM_AES_KEY_WRAP_PAD, PK11_MECH},
3b13d8
-/* 67 */    {SEC_OID_PKCS1_RSA_PSS_SIGNATURE, SEC_OID_TAG}
3b13d8
+/* 67 */    {SEC_OID_PKCS1_RSA_PSS_SIGNATURE, SEC_OID_TAG},
3b13d8
+/* 68 */    {CKM_AES_KEY_WRAP_KWP, PK11_MECH}
3b13d8
 /* REMEMBER TO UPDATE NUM_ALGS!!! */
3b13d8
 };
3b13d8
 
3b13d8
diff --git a/org/mozilla/jss/crypto/Algorithm.h b/org/mozilla/jss/crypto/Algorithm.h
3b13d8
index 09b5869..6bf4d96 100644
3b13d8
--- a/org/mozilla/jss/crypto/Algorithm.h
3b13d8
+++ b/org/mozilla/jss/crypto/Algorithm.h
3b13d8
@@ -24,7 +24,7 @@ typedef struct JSS_AlgInfoStr {
3b13d8
     JSS_AlgType type;
3b13d8
 } JSS_AlgInfo;
3b13d8
 
3b13d8
-#define NUM_ALGS 68
3b13d8
+#define NUM_ALGS 69
3b13d8
 
3b13d8
 extern JSS_AlgInfo JSS_AlgTable[];
3b13d8
 extern CK_ULONG JSS_symkeyUsage[];
3b13d8
diff --git a/org/mozilla/jss/crypto/Algorithm.java b/org/mozilla/jss/crypto/Algorithm.java
3b13d8
index 26d4758..bd93f13 100644
3b13d8
--- a/org/mozilla/jss/crypto/Algorithm.java
3b13d8
+++ b/org/mozilla/jss/crypto/Algorithm.java
3b13d8
@@ -229,5 +229,7 @@ public class Algorithm {
3b13d8
     protected static final short CKM_AES_KEY_WRAP_PAD=66;
3b13d8
     // RSA-PSS
3b13d8
     protected static final short SEC_OID_PKCS1_RSA_PSS_SIGNATURE = 67;
3b13d8
+    // CKM_AES_KEY_WRAP_KWP for HSM support
3b13d8
+    protected static final int CKM_AES_KEY_WRAP_KWP = 68;
3b13d8
 
3b13d8
 }
3b13d8
diff --git a/org/mozilla/jss/crypto/KeyWrapAlgorithm.java b/org/mozilla/jss/crypto/KeyWrapAlgorithm.java
3b13d8
index 3113f61..346eca7 100644
3b13d8
--- a/org/mozilla/jss/crypto/KeyWrapAlgorithm.java
3b13d8
+++ b/org/mozilla/jss/crypto/KeyWrapAlgorithm.java
3b13d8
@@ -130,6 +130,14 @@ public class KeyWrapAlgorithm extends Algorithm {
3b13d8
     AES_KEY_WRAP_PAD = new KeyWrapAlgorithm(CKM_NSS_AES_KEY_WRAP_PAD, "AES KeyWrap/Padding",
3b13d8
                 (Class) null, true, 8);
3b13d8
 
3b13d8
+    /*
3b13d8
+     * Added to support HSMs. There is no CKM_NSS equivalent, unlike the
3b13d8
+     * above two mechanisms.
3b13d8
+    */
3b13d8
+    public static final KeyWrapAlgorithm
3b13d8
+    AES_KEY_WRAP_PAD_KWP = new KeyWrapAlgorithm(CKM_AES_KEY_WRAP_KWP, "AES KeyWrap/Wrapped",
3b13d8
+                (Class) null, true, 8);
3b13d8
+
3b13d8
     public static final OBJECT_IDENTIFIER AES_KEY_WRAP_PAD_OID = new OBJECT_IDENTIFIER("2.16.840.1.101.3.4.1.8");
3b13d8
     public static final OBJECT_IDENTIFIER AES_KEY_WRAP_OID = new OBJECT_IDENTIFIER("2.16.840.1.101.3.4.1.5");
3b13d8
     public static final OBJECT_IDENTIFIER AES_CBC_PAD_OID = new OBJECT_IDENTIFIER("2.16.840.1.101.3.4.1.2");
3b13d8
-- 
3b13d8
1.8.3.1
3b13d8