Skip to content

Commit

Permalink
8287246: DSAKeyValue should check for missing params instead of relyi…
Browse files Browse the repository at this point in the history
…ng on KeyFactory provider

Backport-of: f235955eefb1141a2e72116dfcf345e40416f059
  • Loading branch information
GoeLin committed Apr 18, 2023
1 parent 2bf9828 commit fc03710
Showing 1 changed file with 18 additions and 30 deletions.
Expand Up @@ -21,7 +21,7 @@
* under the License.
*/
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
*/
package org.jcp.xml.dsig.internal.dom;

Expand Down Expand Up @@ -300,35 +300,23 @@ DSAPublicKey unmarshalKeyValue(Element kvtElem)
("unable to create DSA KeyFactory: " + e.getMessage());
}
}
Element curElem = DOMUtils.getFirstChildElement(kvtElem);
if (curElem == null) {
throw new MarshalException("KeyValue must contain at least one type");
}
// check for P and Q
BigInteger p = null;
BigInteger q = null;
if ("P".equals(curElem.getLocalName()) && XMLSignature.XMLNS.equals(curElem.getNamespaceURI())) {
p = decode(curElem);
curElem = DOMUtils.getNextSiblingElement(curElem, "Q", XMLSignature.XMLNS);
q = decode(curElem);
curElem = DOMUtils.getNextSiblingElement(curElem);
}
BigInteger g = null;
if (curElem != null
&& "G".equals(curElem.getLocalName()) && XMLSignature.XMLNS.equals(curElem.getNamespaceURI())) {
g = decode(curElem);
curElem = DOMUtils.getNextSiblingElement(curElem, "Y", XMLSignature.XMLNS);
}
BigInteger y = null;
if (curElem != null) {
y = decode(curElem);
curElem = DOMUtils.getNextSiblingElement(curElem);
}
//if (curElem != null && "J".equals(curElem.getLocalName())) {
//j = new DOMCryptoBinary(curElem.getFirstChild());
// curElem = DOMUtils.getNextSiblingElement(curElem);
//}
//@@@ do we care about j, pgenCounter or seed?
// P, Q, and G are optional according to the XML Signature
// Recommendation as they might be known from application context,
// but this implementation does not provide a mechanism or API for
// an application to supply the missing parameters, so they are
// required to be specified.
Element curElem =
DOMUtils.getFirstChildElement(kvtElem, "P", XMLSignature.XMLNS);
BigInteger p = decode(curElem);
curElem =
DOMUtils.getNextSiblingElement(curElem, "Q", XMLSignature.XMLNS);
BigInteger q = decode(curElem);
curElem =
DOMUtils.getNextSiblingElement(curElem, "G", XMLSignature.XMLNS);
BigInteger g = decode(curElem);
curElem =
DOMUtils.getNextSiblingElement(curElem, "Y", XMLSignature.XMLNS);
BigInteger y = decode(curElem);
DSAPublicKeySpec spec = new DSAPublicKeySpec(y, p, q, g);
return (DSAPublicKey) generatePublicKey(dsakf, spec);
}
Expand Down

1 comment on commit fc03710

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.