Skip to content

Commit fc03710

Browse files
committedApr 18, 2023
8287246: DSAKeyValue should check for missing params instead of relying on KeyFactory provider
Backport-of: f235955eefb1141a2e72116dfcf345e40416f059
1 parent 2bf9828 commit fc03710

File tree

1 file changed

+18
-30
lines changed

1 file changed

+18
-30
lines changed
 

‎src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMKeyValue.java

+18-30
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* under the License.
2222
*/
2323
/*
24-
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
24+
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
2525
*/
2626
package org.jcp.xml.dsig.internal.dom;
2727

@@ -300,35 +300,23 @@ DSAPublicKey unmarshalKeyValue(Element kvtElem)
300300
("unable to create DSA KeyFactory: " + e.getMessage());
301301
}
302302
}
303-
Element curElem = DOMUtils.getFirstChildElement(kvtElem);
304-
if (curElem == null) {
305-
throw new MarshalException("KeyValue must contain at least one type");
306-
}
307-
// check for P and Q
308-
BigInteger p = null;
309-
BigInteger q = null;
310-
if ("P".equals(curElem.getLocalName()) && XMLSignature.XMLNS.equals(curElem.getNamespaceURI())) {
311-
p = decode(curElem);
312-
curElem = DOMUtils.getNextSiblingElement(curElem, "Q", XMLSignature.XMLNS);
313-
q = decode(curElem);
314-
curElem = DOMUtils.getNextSiblingElement(curElem);
315-
}
316-
BigInteger g = null;
317-
if (curElem != null
318-
&& "G".equals(curElem.getLocalName()) && XMLSignature.XMLNS.equals(curElem.getNamespaceURI())) {
319-
g = decode(curElem);
320-
curElem = DOMUtils.getNextSiblingElement(curElem, "Y", XMLSignature.XMLNS);
321-
}
322-
BigInteger y = null;
323-
if (curElem != null) {
324-
y = decode(curElem);
325-
curElem = DOMUtils.getNextSiblingElement(curElem);
326-
}
327-
//if (curElem != null && "J".equals(curElem.getLocalName())) {
328-
//j = new DOMCryptoBinary(curElem.getFirstChild());
329-
// curElem = DOMUtils.getNextSiblingElement(curElem);
330-
//}
331-
//@@@ do we care about j, pgenCounter or seed?
303+
// P, Q, and G are optional according to the XML Signature
304+
// Recommendation as they might be known from application context,
305+
// but this implementation does not provide a mechanism or API for
306+
// an application to supply the missing parameters, so they are
307+
// required to be specified.
308+
Element curElem =
309+
DOMUtils.getFirstChildElement(kvtElem, "P", XMLSignature.XMLNS);
310+
BigInteger p = decode(curElem);
311+
curElem =
312+
DOMUtils.getNextSiblingElement(curElem, "Q", XMLSignature.XMLNS);
313+
BigInteger q = decode(curElem);
314+
curElem =
315+
DOMUtils.getNextSiblingElement(curElem, "G", XMLSignature.XMLNS);
316+
BigInteger g = decode(curElem);
317+
curElem =
318+
DOMUtils.getNextSiblingElement(curElem, "Y", XMLSignature.XMLNS);
319+
BigInteger y = decode(curElem);
332320
DSAPublicKeySpec spec = new DSAPublicKeySpec(y, p, q, g);
333321
return (DSAPublicKey) generatePublicKey(dsakf, spec);
334322
}

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Apr 18, 2023

@openjdk-notifier[bot]
Please sign in to comment.