@@ -99,9 +99,14 @@ public class WolfSSLKeyStoreTest {
9999 * Example private key files:
100100 * server-keyPkcs8.der, matches to server-cert.der
101101 * ecc-keyPkcs8.der, matches to server-ecc.der
102+ * rsapss/server-rsapss-priv.der, matches to rsapss/server-rsapss.der
102103 */
103104 protected static String serverPkcs8Der = null ;
104105 protected static String eccPkcs8Der = null ;
106+ protected static String rsaPssPkcs8Der = null ;
107+
108+ /* RSA-PSS certificate file */
109+ protected static String serverRsaPssDer = null ;
105110
106111 /* RSA-based cert chain with intermediates:
107112 * server/peer: server-int-cert.der
@@ -124,8 +129,12 @@ public class WolfSSLKeyStoreTest {
124129 /* Java PrivateKey / Certificate objects containing example key/certs */
125130 private static PrivateKey serverKeyRsa = null ; /* server-keyPkcs8.der */
126131 private static PrivateKey serverKeyEcc = null ; /* ecc-keyPkcs8.der */
132+ /* server-rsapss-priv.der */
133+ private static PrivateKey serverKeyRsaPss = null ;
127134 private static Certificate serverCertRsa = null ; /* server-cert.der */
128135 private static Certificate serverCertEcc = null ; /* server-ecc.der */
136+ /* server-rsapss.der */
137+ private static Certificate serverCertRsaPss = null ;
129138 private static Certificate clientCertRsa = null ; /* client-cert.der */
130139 private static Certificate clientCertEcc = null ; /* client-ecc-cert.der */
131140 private static Certificate [] rsaServerChain = null ; /* RSA chain */
@@ -282,6 +291,14 @@ private static void createTestObjects()
282291 serverKeyEcc = derFileToPrivateKey (eccPkcs8Der , "EC" );
283292 assertNotNull (serverKeyEcc );
284293
294+ /* Create PrivateKey from server RSA-PSS private key DER,
295+ * may be null if RSASSA-PSS not supported or file not present */
296+ try {
297+ serverKeyRsaPss = derFileToPrivateKey (rsaPssPkcs8Der , "RSASSA-PSS" );
298+ } catch (Exception e ) {
299+ serverKeyRsaPss = null ;
300+ }
301+
285302 /* Create Certificate from server RSA cert */
286303 serverCertRsa = certFileToCertificate (serverCertDer );
287304 assertNotNull (serverCertRsa );
@@ -290,6 +307,14 @@ private static void createTestObjects()
290307 serverCertEcc = certFileToCertificate (serverEccDer );
291308 assertNotNull (serverCertEcc );
292309
310+ /* Create Certificate from server RSA-PSS cert,
311+ * may be null if cert file not present */
312+ try {
313+ serverCertRsaPss = certFileToCertificate (serverRsaPssDer );
314+ } catch (FileNotFoundException e ) {
315+ serverCertRsaPss = null ;
316+ }
317+
293318 /* Create Certificate from client RSA cert */
294319 clientCertRsa = certFileToCertificate (clientCertDer );
295320 assertNotNull (clientCertRsa );
@@ -364,6 +389,10 @@ public static void testSetupAndProviderInstallation()
364389 certPre .concat ("examples/certs/server-keyPkcs8.der" );
365390 eccPkcs8Der =
366391 certPre .concat ("examples/certs/ecc-keyPkcs8.der" );
392+ rsaPssPkcs8Der =
393+ certPre .concat ("examples/certs/rsapss/server-rsapss-priv.der" );
394+ serverRsaPssDer =
395+ certPre .concat ("examples/certs/rsapss/server-rsapss.der" );
367396
368397 intRsaServerCertDer =
369398 certPre .concat ("examples/certs/intermediate/server-int-cert.pem" );
@@ -373,7 +402,8 @@ public static void testSetupAndProviderInstallation()
373402 certPre .concat ("examples/certs/intermediate/ca-int2-cert.pem" );
374403
375404 intEccServerCertDer =
376- certPre .concat ("examples/certs/intermediate/server-int-ecc-cert.der" );
405+ certPre .concat (
406+ "examples/certs/intermediate/server-int-ecc-cert.der" );
377407 intEccInt1CertDer =
378408 certPre .concat ("examples/certs/intermediate/ca-int-ecc-cert.der" );
379409 intEccInt2CertDer =
@@ -2845,5 +2875,61 @@ public void testKekCacheMultipleEntriesSamePassword() throws Exception {
28452875 }
28462876 }
28472877 }
2878+
2879+ /**
2880+ * Test that RSASSA-PSS private keys can be stored and retrieved from
2881+ * a WKS KeyStore.
2882+ */
2883+ @ Test
2884+ public void testRsaPssKeyStoreAndRetrieve ()
2885+ throws Exception {
2886+
2887+ KeyStore store = null ;
2888+ PrivateKey keyOut = null ;
2889+
2890+ /* Skip if RSA-PSS key/cert not loaded (not available) */
2891+ Assume .assumeTrue ("RSA-PSS key not available" ,
2892+ serverKeyRsaPss != null );
2893+ Assume .assumeTrue ("RSA-PSS cert not available" ,
2894+ serverCertRsaPss != null );
2895+
2896+ /* Verify key algorithm is RSASSA-PSS */
2897+ assertEquals ("RSASSA-PSS" , serverKeyRsaPss .getAlgorithm ());
2898+
2899+ /* Store PSS key and cert in keystore */
2900+ store = KeyStore .getInstance (storeType , storeProvider );
2901+ store .load (null , storePass .toCharArray ());
2902+ store .setKeyEntry ("pssKey" , serverKeyRsaPss ,
2903+ storePass .toCharArray (),
2904+ new Certificate [] { serverCertRsaPss });
2905+ assertEquals (1 , store .size ());
2906+
2907+ /* Save keystore to byte array */
2908+ ByteArrayOutputStream baos = new ByteArrayOutputStream ();
2909+ store .store (baos , storePass .toCharArray ());
2910+ byte [] storeBytes = baos .toByteArray ();
2911+ assertTrue ("Stored keystore should have content" ,
2912+ storeBytes .length > 0 );
2913+
2914+ /* Reload keystore from byte array */
2915+ store = KeyStore .getInstance (storeType , storeProvider );
2916+ store .load (new ByteArrayInputStream (storeBytes ),
2917+ storePass .toCharArray ());
2918+ assertEquals (1 , store .size ());
2919+
2920+ /* Retrieve the PSS private key */
2921+ keyOut = (PrivateKey )store .getKey ("pssKey" , storePass .toCharArray ());
2922+ assertNotNull ("Retrieved PSS key should not be null" , keyOut );
2923+ assertEquals ("Retrieved key algorithm should be RSASSA-PSS" ,
2924+ "RSASSA-PSS" , keyOut .getAlgorithm ());
2925+
2926+ /* Verify the retrieved key matches the original */
2927+ assertArrayEquals ("Retrieved key encoding should match original" ,
2928+ serverKeyRsaPss .getEncoded (), keyOut .getEncoded ());
2929+
2930+ /* Verify the certificate can also be retrieved */
2931+ Certificate certOut = store .getCertificate ("pssKey" );
2932+ assertNotNull ("Retrieved PSS cert should not be null" , certOut );
2933+ }
28482934}
28492935
0 commit comments