use of org.apache.xml.security.keys.content.keyvalues.DSAKeyValue in project OpenAM by OpenRock.
the class AMSignatureProvider method getPublicKeybyDSARSAkeyValue.
protected PublicKey getPublicKeybyDSARSAkeyValue(Document doc, Element reference) throws XMLSignatureException {
PublicKey pubKey = null;
Element dsaKey = (Element) reference.getElementsByTagNameNS(Constants.SignatureSpecNS, SAMLConstants.TAG_DSAKEYVALUE).item(0);
if (dsaKey != null) {
// It's DSAKey
NodeList nodes = dsaKey.getChildNodes();
int nodeCount = nodes.getLength();
if (nodeCount > 0) {
BigInteger p = null, q = null, g = null, y = null;
for (int i = 0; i < nodeCount; i++) {
Node currentNode = nodes.item(i);
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
String tagName = currentNode.getLocalName();
Node sub = currentNode.getChildNodes().item(0);
String value = sub.getNodeValue();
BigInteger v = new BigInteger(Base64.decode(SAMLUtilsCommon.removeNewLineChars(value)));
if (tagName.equals("P")) {
p = v;
} else if (tagName.equals("Q")) {
q = v;
} else if (tagName.equals("G")) {
g = v;
} else if (tagName.equals("Y")) {
y = v;
} else {
throw new XMLSignatureException(SAMLUtilsCommon.bundle.getString("errorObtainPK"));
}
}
}
DSAKeyValue dsaKeyValue = new DSAKeyValue(doc, p, q, g, y);
try {
pubKey = dsaKeyValue.getPublicKey();
} catch (Exception e) {
throw new XMLSignatureException(SAMLUtilsCommon.bundle.getString("errorObtainPK"));
}
}
} else {
Element rsaKey = (Element) reference.getElementsByTagNameNS(Constants.SignatureSpecNS, SAMLConstants.TAG_RSAKEYVALUE).item(0);
if (rsaKey != null) {
// It's RSAKey
NodeList nodes = rsaKey.getChildNodes();
int nodeCount = nodes.getLength();
BigInteger m = null, e = null;
if (nodeCount > 0) {
for (int i = 0; i < nodeCount; i++) {
Node currentNode = nodes.item(i);
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
String tagName = currentNode.getLocalName();
Node sub = currentNode.getChildNodes().item(0);
String value = sub.getNodeValue();
BigInteger v = new BigInteger(Base64.decode(SAMLUtilsCommon.removeNewLineChars(value)));
if (tagName.equals("Exponent")) {
e = v;
} else if (tagName.equals("Modulus")) {
m = v;
} else {
throw new XMLSignatureException(SAMLUtilsCommon.bundle.getString("errorObtainPK"));
}
}
}
}
RSAKeyValue rsaKeyValue = new RSAKeyValue(doc, m, e);
try {
pubKey = rsaKeyValue.getPublicKey();
} catch (Exception ex) {
throw new XMLSignatureException(SAMLUtilsCommon.bundle.getString("errorObtainPK"));
}
}
}
return pubKey;
}
use of org.apache.xml.security.keys.content.keyvalues.DSAKeyValue in project cxf by apache.
the class AbstractSTSClient method writeElementsForRSTPublicKey.
protected void writeElementsForRSTPublicKey(W3CDOMStreamWriter writer, X509Certificate cert) throws Exception {
writer.writeStartElement("wst", "UseKey", namespace);
writer.writeStartElement("ds", "KeyInfo", "http://www.w3.org/2000/09/xmldsig#");
writer.writeNamespace("ds", "http://www.w3.org/2000/09/xmldsig#");
boolean useCert = useCertificateForConfirmationKeyInfo;
String useCertStr = (String) getProperty(SecurityConstants.STS_TOKEN_USE_CERT_FOR_KEYINFO);
if (useCertStr != null) {
useCert = Boolean.parseBoolean(useCertStr);
}
if (useCert) {
X509Data certElem = new X509Data(writer.getDocument());
certElem.addCertificate(cert);
writer.getCurrentNode().appendChild(certElem.getElement());
} else {
writer.writeStartElement("ds", "KeyValue", "http://www.w3.org/2000/09/xmldsig#");
PublicKey key = cert.getPublicKey();
String pubKeyAlgo = key.getAlgorithm();
if ("DSA".equalsIgnoreCase(pubKeyAlgo)) {
DSAKeyValue dsaKeyValue = new DSAKeyValue(writer.getDocument(), key);
writer.getCurrentNode().appendChild(dsaKeyValue.getElement());
} else if ("RSA".equalsIgnoreCase(pubKeyAlgo)) {
RSAKeyValue rsaKeyValue = new RSAKeyValue(writer.getDocument(), key);
writer.getCurrentNode().appendChild(rsaKeyValue.getElement());
}
writer.writeEndElement();
}
writer.writeEndElement();
writer.writeEndElement();
}
use of org.apache.xml.security.keys.content.keyvalues.DSAKeyValue in project santuario-java by apache.
the class KeyValue method getPublicKey.
/**
* Method getPublicKey
*
* @return the public key
* @throws XMLSecurityException
*/
public PublicKey getPublicKey() throws XMLSecurityException {
Element rsa = XMLUtils.selectDsNode(getFirstChild(), Constants._TAG_RSAKEYVALUE, 0);
if (rsa != null) {
RSAKeyValue kv = new RSAKeyValue(rsa, this.baseURI);
return kv.getPublicKey();
}
Element dsa = XMLUtils.selectDsNode(getFirstChild(), Constants._TAG_DSAKEYVALUE, 0);
if (dsa != null) {
DSAKeyValue kv = new DSAKeyValue(dsa, this.baseURI);
return kv.getPublicKey();
}
return null;
}
use of org.apache.xml.security.keys.content.keyvalues.DSAKeyValue in project OpenAM by OpenRock.
the class SecurityUtils method getPublicKey.
/**
* Returns the <code>PublicKey</code>.
*/
private static PublicKey getPublicKey(Element reference) throws XMLSignatureException {
PublicKey pubKey = null;
Document doc = reference.getOwnerDocument();
Element dsaKey = (Element) reference.getElementsByTagNameNS(Constants.SignatureSpecNS, SAMLConstants.TAG_DSAKEYVALUE).item(0);
if (dsaKey != null) {
// It's DSAKey
NodeList nodes = dsaKey.getChildNodes();
int nodeCount = nodes.getLength();
if (nodeCount > 0) {
BigInteger p = null, q = null, g = null, y = null;
for (int i = 0; i < nodeCount; i++) {
Node currentNode = nodes.item(i);
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
String tagName = currentNode.getLocalName();
Node sub = currentNode.getChildNodes().item(0);
String value = sub.getNodeValue();
value = SAMLUtils.removeNewLineChars(value);
BigInteger v = new BigInteger(Base64.decode(value));
if (tagName.equals("P")) {
p = v;
} else if (tagName.equals("Q")) {
q = v;
} else if (tagName.equals("G")) {
g = v;
} else if (tagName.equals("Y")) {
y = v;
} else {
SAMLUtils.debug.error("Wrong tag name in DSA key.");
throw new XMLSignatureException(SAMLUtils.bundle.getString("errorObtainPK"));
}
}
}
DSAKeyValue dsaKeyValue = new DSAKeyValue(doc, p, q, g, y);
try {
pubKey = dsaKeyValue.getPublicKey();
} catch (XMLSecurityException xse) {
SAMLUtils.debug.error("Could not get Public Key from" + " DSA key value.");
throw new XMLSignatureException(SAMLUtils.bundle.getString("errorObtainPK"));
}
}
} else {
Element rsaKey = (Element) reference.getElementsByTagNameNS(Constants.SignatureSpecNS, SAMLConstants.TAG_RSAKEYVALUE).item(0);
if (rsaKey != null) {
// It's RSAKey
NodeList nodes = rsaKey.getChildNodes();
int nodeCount = nodes.getLength();
BigInteger m = null, e = null;
if (nodeCount > 0) {
for (int i = 0; i < nodeCount; i++) {
Node currentNode = nodes.item(i);
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
String tagName = currentNode.getLocalName();
Node sub = currentNode.getChildNodes().item(0);
String value = sub.getNodeValue();
value = SAMLUtils.removeNewLineChars(value);
BigInteger v = new BigInteger(Base64.decode(value));
if (tagName.equals("Exponent")) {
e = v;
} else if (tagName.equals("Modulus")) {
m = v;
} else {
SAMLUtils.debug.error("Wrong tag name from " + "RSA key element.");
throw new XMLSignatureException(SAMLUtils.bundle.getString("errorObtainPK"));
}
}
}
}
RSAKeyValue rsaKeyValue = new RSAKeyValue(doc, m, e);
try {
pubKey = rsaKeyValue.getPublicKey();
} catch (XMLSecurityException ex) {
SAMLUtils.debug.error("Could not get Public Key from" + " RSA key value.");
throw new XMLSignatureException(SAMLUtils.bundle.getString("errorObtainPK"));
}
}
}
return pubKey;
}
use of org.apache.xml.security.keys.content.keyvalues.DSAKeyValue in project cxf by apache.
the class SimpleBatchSTSClient method writeElementsForRSTPublicKey.
protected void writeElementsForRSTPublicKey(W3CDOMStreamWriter writer, X509Certificate cert) throws Exception {
writer.writeStartElement("wst", "UseKey", namespace);
writer.writeStartElement("dsig", "KeyInfo", "http://www.w3.org/2000/09/xmldsig#");
writer.writeNamespace("dsig", "http://www.w3.org/2000/09/xmldsig#");
boolean useCert = useCertificateForConfirmationKeyInfo;
String useCertStr = (String) getProperty(SecurityConstants.STS_TOKEN_USE_CERT_FOR_KEYINFO);
if (useCertStr != null) {
useCert = Boolean.parseBoolean(useCertStr);
}
if (useCert) {
X509Data certElem = new X509Data(writer.getDocument());
certElem.addCertificate(cert);
writer.getCurrentNode().appendChild(certElem.getElement());
} else {
writer.writeStartElement("dsig", "KeyValue", "http://www.w3.org/2000/09/xmldsig#");
PublicKey key = cert.getPublicKey();
String pubKeyAlgo = key.getAlgorithm();
if ("DSA".equalsIgnoreCase(pubKeyAlgo)) {
DSAKeyValue dsaKeyValue = new DSAKeyValue(writer.getDocument(), key);
writer.getCurrentNode().appendChild(dsaKeyValue.getElement());
} else if ("RSA".equalsIgnoreCase(pubKeyAlgo)) {
RSAKeyValue rsaKeyValue = new RSAKeyValue(writer.getDocument(), key);
writer.getCurrentNode().appendChild(rsaKeyValue.getElement());
}
writer.writeEndElement();
}
writer.writeEndElement();
writer.writeEndElement();
}
Aggregations