[java-opensaml COMMIT] in /trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec: encryption/support/SimpleKeyI...
noreply at shibboleth.net
noreply at shibboleth.net
Wed Jan 30 21:31:11 EST 2013
Author: scantor
Date: Wed Jan 30 21:31:10 2013
New Revision: 3197
URL: http://svn.shibboleth.net/view/java-opensaml?rev=3197&view=rev
Log:
Port java-xmltooling r774
Added:
trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/encryption/support/SimpleKeyInfoReferenceEncryptedKeyResolver.java (with props)
trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/signature/DEREncodedKeyValue.java (with props)
trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/signature/ECKeyValue.java (with props)
trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/signature/ECPointType.java (with props)
trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/signature/KeyInfoReference.java (with props)
trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/signature/NamedCurve.java (with props)
trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/signature/PublicKey.java (with props)
trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/signature/X509Digest.java (with props)
Modified:
trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/keyinfo/KeyInfoSupport.java
Modified: trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/keyinfo/KeyInfoSupport.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/keyinfo/KeyInfoSupport.java?rev=3197&r1=3196&r2=3197&view=diff
==============================================================================
--- trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/keyinfo/KeyInfoSupport.java (original)
+++ trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/keyinfo/KeyInfoSupport.java Wed Jan 30 21:31:10 2013
@@ -20,6 +20,7 @@
import java.math.BigInteger;
import java.security.KeyException;
import java.security.KeyFactory;
+import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.cert.CRLException;
@@ -36,6 +37,7 @@
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
import java.security.spec.RSAPublicKeySpec;
+import java.security.spec.X509EncodedKeySpec;
import java.util.LinkedList;
import java.util.List;
@@ -45,6 +47,7 @@
import net.shibboleth.utilities.java.support.codec.Base64Support;
import net.shibboleth.utilities.java.support.logic.Constraint;
+import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.XMLObjectBuilder;
import org.opensaml.core.xml.XMLObjectBuilderFactory;
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
@@ -52,6 +55,8 @@
import org.opensaml.security.x509.X509Support;
import org.opensaml.xmlsec.SecurityConfiguration;
import org.opensaml.xmlsec.SecurityConfigurationSupport;
+import org.opensaml.xmlsec.crypto.AlgorithmSupport;
+import org.opensaml.xmlsec.signature.DEREncodedKeyValue;
import org.opensaml.xmlsec.signature.DSAKeyValue;
import org.opensaml.xmlsec.signature.Exponent;
import org.opensaml.xmlsec.signature.G;
@@ -63,6 +68,7 @@
import org.opensaml.xmlsec.signature.Q;
import org.opensaml.xmlsec.signature.RSAKeyValue;
import org.opensaml.xmlsec.signature.X509Data;
+import org.opensaml.xmlsec.signature.X509Digest;
import org.opensaml.xmlsec.signature.X509IssuerName;
import org.opensaml.xmlsec.signature.X509IssuerSerial;
import org.opensaml.xmlsec.signature.X509SKI;
@@ -454,6 +460,36 @@
}
/**
+ * Build an {@link X509Digest} containing the digest of the specified certificate.
+ *
+ * @param javaCert the Java X509Certificate to digest
+ * @param algorithmURI digest algorithm URI
+ * @return a new X509Digest object
+ * @throws NoSuchAlgorithmException if the algorithm specified cannot be used
+ * @throws CertificateEncodingException if the certificate cannot be encoded
+ */
+ @Nonnull public static X509Digest buildX509Digest(@Nonnull final X509Certificate javaCert,
+ @Nonnull final String algorithmURI) throws NoSuchAlgorithmException, CertificateEncodingException {
+ Constraint.isNotNull(javaCert, "Certificate cannot be null");
+
+ String jceAlg = AlgorithmSupport.getAlgorithmID(algorithmURI);
+ if (jceAlg == null) {
+ throw new NoSuchAlgorithmException("No JCE algorithm found for " + algorithmURI);
+ }
+ MessageDigest md = MessageDigest.getInstance(jceAlg);
+ byte[] hash = md.digest(javaCert.getEncoded());
+
+ XMLObjectBuilder<X509Digest> builder = XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder(
+ X509Digest.DEFAULT_ELEMENT_NAME);
+ X509Digest xmlDigest = Constraint.isNotNull(builder, "X509Digest builder not available").buildObject(
+ X509Digest.DEFAULT_ELEMENT_NAME);
+ xmlDigest.setAlgorithm(algorithmURI);
+ xmlDigest.setValue(Base64Support.encode(hash, Base64Support.CHUNKED));
+
+ return xmlDigest;
+ }
+
+ /**
[... 105 lines stripped ...]
More information about the commits
mailing list