Skip to content

Commit bbf7cc5

Browse files
committed
Documented the ObjectInputFilter allow-list needed for serialized SM9 master keys.
1 parent e1cf818 commit bbf7cc5

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/sm9/SM9KeyProxy.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
* User identity keys are not standalone-decodable (their encoding omits the master
1818
* public key), so they are not serializable; their {@code writeReplace} throws
1919
* rather than routing through this proxy.
20+
* <p>
21+
* A deserialization filter sees both this class and the key readResolve returns; see the package
22+
* documentation for the allow-list that follows from that.
2023
*/
2124
class SM9KeyProxy
2225
implements Serializable

‎prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/sm9/package-info.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,25 @@
55
* {@code KeyGenerator.SM9-KEM} (and {@code KEM.SM9-KEM} on Java 21 and later). The public key
66
* interfaces these classes implement are in {@link org.bouncycastle.jcajce.interfaces}; the
77
* lightweight implementation they wrap is described in {@link org.bouncycastle.math.ec.sm9}.
8+
* <p>
9+
* <b>Serialization.</b> Only the master keys are serializable. Each is written as an
10+
* {@code SM9KeyProxy} holding its standard encoding, and rebuilt through the key factory by the
11+
* proxy's {@code readResolve}; the user keys and the key exchange's ephemeral keys refuse to be
12+
* written, and no key class accepts a stream that names it directly. A deserialization filter
13+
* ({@code java.io.ObjectInputFilter}) is also shown the object {@code readResolve} returns, so an
14+
* allow-list for SM9 master keys has to name the resolved class as well as the proxy and the byte
15+
* array it carries, for example:
16+
* <pre>
17+
* org.bouncycastle.jcajce.provider.asymmetric.sm9.SM9KeyProxy;
18+
* org.bouncycastle.jcajce.provider.asymmetric.sm9.BCSM9SigMasterPublicKey;
19+
* org.bouncycastle.jcajce.provider.asymmetric.sm9.BCSM9SigMasterPrivateKey;
20+
* org.bouncycastle.jcajce.provider.asymmetric.sm9.BCSM9EncMasterPublicKey;
21+
* org.bouncycastle.jcajce.provider.asymmetric.sm9.BCSM9EncMasterPrivateKey;
22+
* [B;!*
23+
* </pre>
24+
* (as one pattern string, without the line breaks). A filter naming the proxy alone rejects every
25+
* SM9 key. Serialization carries no integrity protection: a stream yields whatever well-formed
26+
* master key it encodes, so a stored key that must not be substituted or corrupted needs protecting
27+
* by the application.
828
*/
929
package org.bouncycastle.jcajce.provider.asymmetric.sm9;

0 commit comments

Comments
 (0)