1
1
/*
2
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
23
23
24
24
/*
25
25
* @test
26
- * @bug 8298127
26
+ * @bug 8298127 8347596
27
27
* @library /test/lib
28
28
* @summary tests for HSS/LMS provider
29
29
* @modules java.base/sun.security.util
40
40
import java .security .spec .X509EncodedKeySpec ;
41
41
import java .util .HexFormat ;
42
42
43
+ import jdk .test .lib .Asserts ;
43
44
import sun .security .util .*;
44
45
45
46
import jdk .test .lib .util .SerializationUtils ;
@@ -61,9 +62,7 @@ public static void main(String[] args) throws Exception {
61
62
i ++;
62
63
}
63
64
64
- if (!serializeTest ()) {
65
- throw new RuntimeException ("serializeTest failed" );
66
- }
65
+ serializeTest ();
67
66
68
67
System .out .println ("All tests passed" );
69
68
}
@@ -88,7 +87,7 @@ static boolean kat(TestCase t) throws Exception {
88
87
}
89
88
}
90
89
91
- static boolean serializeTest () throws Exception {
90
+ static void serializeTest () throws Exception {
92
91
final ObjectIdentifier oid ;
93
92
var pk = decode ("""
94
93
00000002
@@ -106,7 +105,19 @@ static boolean serializeTest() throws Exception {
106
105
throw new AssertionError (e );
107
106
}
108
107
109
- var keyBits = new DerOutputStream ().putOctetString (pk ).toByteArray ();
108
+ // Encoding without inner OCTET STRING
109
+ var pk0 = makeKey (oid , pk );
110
+ // Encoding with inner OCTET STRING
111
+ var pk1 = makeKey (oid , new DerOutputStream ().putOctetString (pk ).toByteArray ());
112
+ Asserts .assertEquals (pk0 , pk1 );
113
+
114
+ PublicKey pk2 = (PublicKey ) SerializationUtils
115
+ .deserialize (SerializationUtils .serialize (pk1 ));
116
+ Asserts .assertEquals (pk1 , pk2 );
117
+ }
118
+
119
+ static PublicKey makeKey (ObjectIdentifier oid , byte [] keyBits )
120
+ throws Exception {
110
121
var oidBytes = new DerOutputStream ().write (DerValue .tag_Sequence ,
111
122
new DerOutputStream ().putOID (oid ));
112
123
var x509encoding = new DerOutputStream ().write (DerValue .tag_Sequence ,
@@ -115,11 +126,7 @@ static boolean serializeTest() throws Exception {
115
126
.toByteArray ();
116
127
117
128
var x509KeySpec = new X509EncodedKeySpec (x509encoding );
118
- var pk1 = KeyFactory .getInstance (ALG ).generatePublic (x509KeySpec );
119
-
120
- PublicKey pk2 = (PublicKey ) SerializationUtils
121
- .deserialize (SerializationUtils .serialize (pk1 ));
122
- return pk2 .equals (pk1 );
129
+ return KeyFactory .getInstance (ALG ).generatePublic (x509KeySpec );
123
130
}
124
131
125
132
static boolean verify (byte [] pk , byte [] sig , byte [] msg ) throws Exception {
0 commit comments