Skip to content

Commit 2d30662

Browse files
committed
8344137: Update XML Security for Java to 3.0.5
Reviewed-by: mbaesken Backport-of: 18e0b343ab002b193d4db3be226394ee7dbe9f19
1 parent 0faea69 commit 2d30662

File tree

24 files changed

+628
-40
lines changed

24 files changed

+628
-40
lines changed

src/java.xml.crypto/share/classes/com/sun/org/apache/xml/internal/security/algorithms/JCEMapper.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,22 @@ public static void registerDefaultAlgorithms() {
207207
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA512,
208208
new Algorithm("EC", "SHA512withECDSA", "Signature")
209209
);
210+
algorithmsMap.put(
211+
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA3_224,
212+
new Algorithm("EC", "SHA3-224withECDSA", "Signature")
213+
);
214+
algorithmsMap.put(
215+
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA3_256,
216+
new Algorithm("EC", "SHA3-256withECDSA", "Signature")
217+
);
218+
algorithmsMap.put(
219+
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA3_384,
220+
new Algorithm("EC", "SHA3-384withECDSA", "Signature")
221+
);
222+
algorithmsMap.put(
223+
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA3_512,
224+
new Algorithm("EC", "SHA3-512withECDSA", "Signature")
225+
);
210226
algorithmsMap.put(
211227
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_RIPEMD160,
212228
new Algorithm("EC", "RIPEMD160withECDSA", "Signature")

src/java.xml.crypto/share/classes/com/sun/org/apache/xml/internal/security/algorithms/MessageDigestAlgorithm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static MessageDigestAlgorithm getInstance(
103103
return new MessageDigestAlgorithm(doc, algorithmURI);
104104
}
105105

106-
private static MessageDigest getDigestInstance(String algorithmURI) throws XMLSignatureException {
106+
public static MessageDigest getDigestInstance(String algorithmURI) throws XMLSignatureException {
107107
String algorithmID = JCEMapper.translateURItoJCEID(algorithmURI);
108108

109109
if (algorithmID == null) {

src/java.xml.crypto/share/classes/com/sun/org/apache/xml/internal/security/algorithms/SignatureAlgorithm.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,18 @@ public static void registerDefaultAlgorithms() {
494494
algorithmHash.put(
495495
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA512, SignatureECDSA.SignatureECDSASHA512.class
496496
);
497+
algorithmHash.put(
498+
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA3_224, SignatureECDSA.SignatureECDSASHA3_224.class
499+
);
500+
algorithmHash.put(
501+
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA3_256, SignatureECDSA.SignatureECDSASHA3_256.class
502+
);
503+
algorithmHash.put(
504+
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA3_384, SignatureECDSA.SignatureECDSASHA3_384.class
505+
);
506+
algorithmHash.put(
507+
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA3_512, SignatureECDSA.SignatureECDSASHA3_512.class
508+
);
497509
algorithmHash.put(
498510
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_RIPEMD160, SignatureECDSA.SignatureECDSARIPEMD160.class
499511
);

src/java.xml.crypto/share/classes/com/sun/org/apache/xml/internal/security/algorithms/implementations/ECDSAUtils.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,46 @@ public static byte[] convertXMLDSIGtoASN1(byte[] xmldsigBytes) throws IOExceptio
770770
"0340340340340340340340340340340340340340340340340340340323c313fab50589703b5ec68d3587fec60d161cc149c1ad4a91",
771771
0x2760)
772772
);
773+
774+
ecCurveDefinitions.add(
775+
new ECCurveDefinition(
776+
"brainpoolP256r1 [RFC 5639]",
777+
"1.3.36.3.3.2.8.1.1.7",
778+
"a9fb57dba1eea9bc3e660a909d838d726e3bf623d52620282013481d1f6e5377",
779+
"7d5a0975fc2c3057eef67530417affe7fb8055c126dc5c6ce94a4b44f330b5d9",
780+
"26dc5c6ce94a4b44f330b5d9bbd77cbf958416295cf7e1ce6bccdc18ff8c07b6",
781+
"8bd2aeb9cb7e57cb2c4b482ffc81b7afb9de27e1e3bd23c23a4453bd9ace3262",
782+
"547ef835c3dac4fd97f8461a14611dc9c27745132ded8e545c1d54c72f046997",
783+
"a9fb57dba1eea9bc3e660a909d838d718c397aa3b561a6f7901e0e82974856a7",
784+
1)
785+
);
786+
787+
ecCurveDefinitions.add(
788+
new ECCurveDefinition(
789+
"brainpoolP384r1 [RFC 5639]",
790+
"1.3.36.3.3.2.8.1.1.11",
791+
"8cb91e82a3386d280f5d6f7e50e641df152f7109ed5456b412b1da197fb71123acd3a729901d1a71874700133107ec53",
792+
"7bc382c63d8c150c3c72080ace05afa0c2bea28e4fb22787139165efba91f90f8aa5814a503ad4eb04a8c7dd22ce2826",
793+
"04a8c7dd22ce28268b39b55416f0447c2fb77de107dcd2a62e880ea53eeb62d57cb4390295dbc9943ab78696fa504c11",
794+
"1d1c64f068cf45ffa2a63a81b7c13f6b8847a3e77ef14fe3db7fcafe0cbd10e8e826e03436d646aaef87b2e247d4af1e",
795+
"8abe1d7520f9c2a45cb1eb8e95cfd55262b70b29feec5864e19c054ff99129280e4646217791811142820341263c5315",
796+
"8cb91e82a3386d280f5d6f7e50e641df152f7109ed5456b31f166e6cac0425a7cf3ab6af6b7fc3103b883202e9046565",
797+
1)
798+
);
799+
800+
ecCurveDefinitions.add(
801+
new ECCurveDefinition(
802+
"brainpoolP512r1 [RFC 5639]",
803+
"1.3.36.3.3.2.8.1.1.13",
804+
"aadd9db8dbe9c48b3fd4e6ae33c9fc07cb308db3b3c9d20ed6639cca703308717d4d9b009bc66842aecda12ae6a380e62881ff2f2d82c68528aa6056583a48f3",
805+
"7830a3318b603b89e2327145ac234cc594cbdd8d3df91610a83441caea9863bc2ded5d5aa8253aa10a2ef1c98b9ac8b57f1117a72bf2c7b9e7c1ac4d77fc94ca",
806+
"3df91610a83441caea9863bc2ded5d5aa8253aa10a2ef1c98b9ac8b57f1117a72bf2c7b9e7c1ac4d77fc94cadc083e67984050b75ebae5dd2809bd638016f723",
807+
"81aee4bdd82ed9645a21322e9c4c6a9385ed9f70b5d916c1b43b62eef4d0098eff3b1f78e2d0d48d50d1687b93b97d5f7c6d5047406a5e688b352209bcb9f822",
808+
"7dde385d566332ecc0eabfa9cf7822fdf209f70024a57b1aa000c55b881f8111b2dcde494a5f485e5bca4bd88a2763aed1ca2b2fa8f0540678cd1e0f3ad80892",
809+
"aadd9db8dbe9c48b3fd4e6ae33c9fc07cb308db3b3c9d20ed6639cca70330870553e5c414ca92619418661197fac10471db1d381085ddaddb58796829ca90069",
810+
1)
811+
);
812+
773813
}
774814

775815
public static String getOIDFromPublicKey(ECPublicKey ecPublicKey) {

src/java.xml.crypto/share/classes/com/sun/org/apache/xml/internal/security/algorithms/implementations/SignatureBaseRSA.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ public SignatureBaseRSA() throws XMLSignatureException {
6666
public SignatureBaseRSA(Provider provider) throws XMLSignatureException {
6767
String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
6868
this.signatureAlgorithm = getSignature(provider, algorithmID);
69-
LOG.debug("Created SignatureRSA using {0} and provider {1}",
70-
algorithmID, signatureAlgorithm.getProvider());
69+
LOG.debug("Created SignatureRSA using {0}", algorithmID);
7170
}
7271

7372
Signature getSignature(Provider provider, String algorithmID)

src/java.xml.crypto/share/classes/com/sun/org/apache/xml/internal/security/algorithms/implementations/SignatureECDSA.java

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,110 @@ public String engineGetURI() {
371371
}
372372
}
373373

374+
/**
375+
* Class SignatureECDSASHA3-224
376+
*
377+
*/
378+
public static class SignatureECDSASHA3_224 extends SignatureECDSA {
379+
380+
/**
381+
* Constructor SignatureECDSASHA3-224
382+
*
383+
* @throws XMLSignatureException
384+
*/
385+
public SignatureECDSASHA3_224() throws XMLSignatureException {
386+
super();
387+
}
388+
389+
public SignatureECDSASHA3_224(Provider provider) throws XMLSignatureException {
390+
super(provider);
391+
}
392+
393+
/** {@inheritDoc} */
394+
@Override
395+
public String engineGetURI() {
396+
return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA3_224;
397+
}
398+
}
399+
400+
/**
401+
* Class SignatureECDSASHA3-256
402+
*
403+
*/
404+
public static class SignatureECDSASHA3_256 extends SignatureECDSA {
405+
406+
/**
407+
* Constructor SignatureECDSASHA3-256
408+
*
409+
* @throws XMLSignatureException
410+
*/
411+
public SignatureECDSASHA3_256() throws XMLSignatureException {
412+
super();
413+
}
414+
415+
public SignatureECDSASHA3_256(Provider provider) throws XMLSignatureException {
416+
super(provider);
417+
}
418+
419+
/** {@inheritDoc} */
420+
@Override
421+
public String engineGetURI() {
422+
return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA3_256;
423+
}
424+
}
425+
426+
/**
427+
* Class SignatureECDSASHA3-384
428+
*
429+
*/
430+
public static class SignatureECDSASHA3_384 extends SignatureECDSA {
431+
432+
/**
433+
* Constructor SignatureECDSASHA3-384
434+
*
435+
* @throws XMLSignatureException
436+
*/
437+
public SignatureECDSASHA3_384() throws XMLSignatureException {
438+
super();
439+
}
440+
441+
public SignatureECDSASHA3_384(Provider provider) throws XMLSignatureException {
442+
super(provider);
443+
}
444+
445+
/** {@inheritDoc} */
446+
@Override
447+
public String engineGetURI() {
448+
return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA3_384;
449+
}
450+
}
451+
452+
/**
453+
* Class SignatureECDSASHA3-512
454+
*
455+
*/
456+
public static class SignatureECDSASHA3_512 extends SignatureECDSA {
457+
458+
/**
459+
* Constructor SignatureECDSASHA3-512
460+
*
461+
* @throws XMLSignatureException
462+
*/
463+
public SignatureECDSASHA3_512() throws XMLSignatureException {
464+
super();
465+
}
466+
467+
public SignatureECDSASHA3_512(Provider provider) throws XMLSignatureException {
468+
super(provider);
469+
}
470+
471+
/** {@inheritDoc} */
472+
@Override
473+
public String engineGetURI() {
474+
return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA3_512;
475+
}
476+
}
477+
374478
/**
375479
* Class SignatureECDSARIPEMD160
376480
*/

src/java.xml.crypto/share/classes/com/sun/org/apache/xml/internal/security/keys/KeyInfo.java

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,7 @@
3232
import javax.crypto.SecretKey;
3333

3434
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
35-
import com.sun.org.apache.xml.internal.security.keys.content.DEREncodedKeyValue;
36-
import com.sun.org.apache.xml.internal.security.keys.content.KeyInfoReference;
37-
import com.sun.org.apache.xml.internal.security.keys.content.KeyName;
38-
import com.sun.org.apache.xml.internal.security.keys.content.KeyValue;
39-
import com.sun.org.apache.xml.internal.security.keys.content.MgmtData;
40-
import com.sun.org.apache.xml.internal.security.keys.content.PGPData;
41-
import com.sun.org.apache.xml.internal.security.keys.content.RetrievalMethod;
42-
import com.sun.org.apache.xml.internal.security.keys.content.SPKIData;
43-
import com.sun.org.apache.xml.internal.security.keys.content.X509Data;
35+
import com.sun.org.apache.xml.internal.security.keys.content.*;
4436
import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.DSAKeyValue;
4537
import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.RSAKeyValue;
4638
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolver;
@@ -50,7 +42,6 @@
5042
import com.sun.org.apache.xml.internal.security.transforms.Transforms;
5143
import com.sun.org.apache.xml.internal.security.utils.Constants;
5244
import com.sun.org.apache.xml.internal.security.utils.ElementProxy;
53-
import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
5445
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
5546
import org.w3c.dom.Attr;
5647
import org.w3c.dom.Document;
@@ -88,7 +79,7 @@
8879
* contains the corresponding type.
8980
*
9081
*/
91-
public class KeyInfo extends SignatureElementProxy {
82+
public class KeyInfo extends ElementProxy {
9283

9384
private static final com.sun.org.slf4j.internal.Logger LOG =
9485
com.sun.org.slf4j.internal.LoggerFactory.getLogger(KeyInfo.class);
@@ -231,12 +222,24 @@ public void add(RSAKeyValue rsakeyvalue) {
231222
}
232223

233224
/**
234-
* Method add
225+
* Method adds public key encoded as KeyValue. If public key type is not supported by KeyValue, then
226+
* DEREncodedKeyValue is used. If public key type is not supported by DEREncodedKeyValue, then
227+
* IllegalArgumentException is thrown.
235228
*
236-
* @param pk
229+
* @param pk public key to be added to KeyInfo
237230
*/
238-
public void add(PublicKey pk) {
239-
this.add(new KeyValue(getDocument(), pk));
231+
public void add(PublicKey pk) {
232+
233+
if (KeyValue.isSupportedKeyType(pk)) {
234+
this.add(new KeyValue(getDocument(), pk));
235+
return;
236+
}
237+
238+
try {
239+
this.add(new DEREncodedKeyValue(getDocument(), pk));
240+
} catch (XMLSecurityException ex) {
241+
throw new IllegalArgumentException(ex);
242+
}
240243
}
241244

242245
/**
@@ -772,6 +775,7 @@ public boolean containsKeyInfoReference() {
772775
return this.lengthKeyInfoReference() > 0;
773776
}
774777

778+
775779
/**
776780
* This method returns the public key.
777781
*
@@ -1188,4 +1192,10 @@ public void addStorageResolver(StorageResolver storageResolver) {
11881192
public String getBaseLocalName() {
11891193
return Constants._TAG_KEYINFO;
11901194
}
1195+
1196+
/** {@inheritDoc} */
1197+
@Override
1198+
public String getBaseNamespace() {
1199+
return Constants.SignatureSpecNS;
1200+
}
11911201
}

src/java.xml.crypto/share/classes/com/sun/org/apache/xml/internal/security/keys/content/DEREncodedKeyValue.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@
4141
public class DEREncodedKeyValue extends Signature11ElementProxy implements KeyInfoContent {
4242

4343
/** JCA algorithm key types supported by this implementation. */
44-
private static final String[] supportedKeyTypes = { "RSA", "DSA", "EC"};
44+
private static final String[] supportedKeyTypes = { "RSA", "DSA", "EC",
45+
"DiffieHellman", "DH", "XDH", "X25519", "X448",
46+
"EdDSA", "Ed25519", "Ed448",
47+
"RSASSA-PSS"};
4548

4649
/**
4750
* Constructor DEREncodedKeyValue
@@ -144,5 +147,4 @@ protected byte[] getEncodedDER(PublicKey publicKey) throws XMLSecurityException
144147
throw new XMLSecurityException(e, "DEREncodedKeyValue.UnsupportedPublicKey", exArgs);
145148
}
146149
}
147-
148150
}

src/java.xml.crypto/share/classes/com/sun/org/apache/xml/internal/security/keys/content/KeyValue.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
* (section 6.4). The KeyValue element may include externally defined public
4242
* keys values represented as PCDATA or element types from an external
4343
* namespace.
44-
*
4544
*/
4645
public class KeyValue extends SignatureElementProxy implements KeyInfoContent {
4746

@@ -120,6 +119,20 @@ public KeyValue(Document doc, PublicKey pk) {
120119
}
121120
}
122121

122+
/**
123+
* Verifies that the XML KeyValue encoding is supported for the given key type. If the
124+
* encoding is supported, it returns true else false.
125+
*
126+
* @return true if the public key has a KeyValue encoding, false otherwise.
127+
*/
128+
public static boolean isSupportedKeyType(PublicKey publicKey) {
129+
130+
return publicKey instanceof java.security.interfaces.DSAPublicKey
131+
|| publicKey instanceof java.security.interfaces.RSAPublicKey
132+
|| publicKey instanceof java.security.interfaces.ECPublicKey;
133+
134+
}
135+
123136
/**
124137
* Constructor KeyValue
125138
*

0 commit comments

Comments
 (0)