From 1d8f51ba16c681ed82f55609c918acc2553d21da Mon Sep 17 00:00:00 2001 From: rudolf Date: Fri, 21 Jan 2005 18:28:42 +0000 Subject: added ECDSA Key handling git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@241 d688527b-c9ab-4aba-bd8d-4036d912da1d --- .../auth/parser/IdentityLinkAssertionParser.java | 40 +++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'id.server/src/at/gv/egovernment/moa/id/auth') diff --git a/id.server/src/at/gv/egovernment/moa/id/auth/parser/IdentityLinkAssertionParser.java b/id.server/src/at/gv/egovernment/moa/id/auth/parser/IdentityLinkAssertionParser.java index 49baf1bf5..dd44419da 100644 --- a/id.server/src/at/gv/egovernment/moa/id/auth/parser/IdentityLinkAssertionParser.java +++ b/id.server/src/at/gv/egovernment/moa/id/auth/parser/IdentityLinkAssertionParser.java @@ -19,6 +19,7 @@ import at.gv.egovernment.moa.util.Base64Utils; import at.gv.egovernment.moa.util.Constants; import at.gv.egovernment.moa.util.DOMUtils; import at.gv.egovernment.moa.util.XPathUtils; +import at.gv.egovernment.moa.id.util.ECDSAKeyValueConverter; /** * Parses an identity link <saml:Assertion> @@ -118,6 +119,20 @@ public class IdentityLinkAssertionParser { + "AttributeValue/" + DSIG + "RSAKeyValue"; + + /** Xpath expression to the ECKeyValue element */ + private static final String ECDSA_KEY_VALUE_XPATH = + ROOT + + SAML + + "AttributeStatement/" + + SAML + + "Attribute/" + + SAML + + "AttributeValue/" + + ECDSA + + "ECDSAKeyValue"; + + /** Xpath expression to the RSA Modulus element */ private static final String RSA_KEY_MODULUS_XPATH = DSIG + "Modulus"; /** Xpath expression to the RSA Exponent element */ @@ -228,14 +243,15 @@ public class IdentityLinkAssertionParser { * @return RSAPublicKey[] * @throws IOException can occur when decoding the base64 values of the modulus and exponent */ - public PublicKey[] getPublicKeys() throws IOException{ + public PublicKey[] getPublicKeys() throws IOException, ECDSAConverterException{ List pubKeys = new ArrayList(); //Try to get RSA-Keys NodeIterator rsaIter = - XPathUtils.selectNodeIterator(assertionElem, RSA_KEY_VALUE_XPATH); + XPathUtils.selectNodeIterator(assertionElem, Constants.nSMap, RSA_KEY_VALUE_XPATH); Element rsaElem; + while ((rsaElem = (Element) rsaIter.nextNode()) != null) { String modulus = XPathUtils.getElementValue(rsaElem, RSA_KEY_MODULUS_XPATH, ""); @@ -246,10 +262,26 @@ public class IdentityLinkAssertionParser { new iaik.security.rsa.RSAPublicKey( new BigInteger(1, Base64Utils.decode(modulus, true)), new BigInteger(1, Base64Utils.decode(exponent, true))); - pubKeys.add(resPub);} + pubKeys.add(resPub); + } + + //Try to get ECDSA-Keys + NodeIterator ecdsaIter = + XPathUtils.selectNodeIterator(assertionElem, Constants.nSMap, ECDSA_KEY_VALUE_XPATH); + Element ecdsaElem; + PublicKey ecPubKey = null; + while ((ecdsaElem = (Element) ecdsaIter.nextNode()) != null) { + try { + ecPubKey = ECDSAKeyValueConverter.element2ECDSAPublicKey(ecdsaElem); + pubKeys.add(ecPubKey); + } + catch(Exception e) { + //TODO test + throw new ECDSAConverterException("parser.03", new Object[] { e.toString() }, e); + } + } PublicKey[] result = new PublicKey[pubKeys.size()]; - pubKeys.toArray(result); return result; -- cgit v1.2.3