import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import javax.security.auth.x500.X500Principal;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import edu.internet2.middleware.shibboleth.serviceprovider.ServiceProviderContext;
import edu.internet2.middleware.shibboleth.serviceprovider.ServiceProviderConfig.ApplicationInfo;
-// TODO: Do the cert extraction methods belong here? Probably not...
-
// TODO: Suggest we implement a separation layer between the SP config pieces and the input needed
// for this class. As long as metadata/etc. are shared, this should work.
*/
public class ShibBrowserProfile implements SAMLBrowserProfile {
- private static Pattern regex = Pattern.compile(".*?CN=([^,/]+).*");
+
/** XML Signature algorithm to apply */
protected String algorithm = XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1;
}
}
- public static String getHostNameFromDN(X500Principal dn) {
- Matcher matches = regex.matcher(dn.getName(X500Principal.RFC2253));
- if (!matches.find() || matches.groupCount() > 1) {
- log.error("Unable to extract host name name from certificate subject DN.");
- return null;
- }
- return matches.group(1);
- }
+
/**
* @see org.opensaml.SAMLBrowserProfile#setVersion(int, int)
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashSet;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.security.auth.x500.X500Principal;
import org.apache.log4j.Logger;
import org.w3c.dom.Element;
private static Logger log = Logger.getLogger(BaseHandler.class.getName());
private HashSet locations = new HashSet();
+ private static Pattern regex = Pattern.compile(".*?CN=([^,/]+).*");
+
/**
* Required DOM-based constructor.
*/
return (URI[]) locations.toArray(new URI[0]);
}
-}
+ protected static String getHostNameFromDN(X500Principal dn) {
+
+ Matcher matches = regex.matcher(dn.getName(X500Principal.RFC2253));
+ if (!matches.find() || matches.groupCount() > 1) {
+ log.error("Unable to extract host name name from certificate subject DN.");
+ return null;
+ }
+ return matches.group(1);
+ }
+
+}
\ No newline at end of file
import org.apache.xml.security.keys.KeyInfo;
import org.w3c.dom.Element;
-import edu.internet2.middleware.shibboleth.common.ShibBrowserProfile;
import edu.internet2.middleware.shibboleth.common.ShibbolethConfigurationException;
import edu.internet2.middleware.shibboleth.idp.IdPProtocolHandler;
import edu.internet2.middleware.shibboleth.metadata.EntityDescriptor;
log.info("Inappropriate metadata for provider.");
return false;
}
- // TODO figure out what to do about this role business here
+
Iterator descriptors = sp.getKeyDescriptors();
while (descriptors.hasNext()) {
KeyInfo keyInfo = ((KeyDescriptor) descriptors.next()).getKeyInfo();
if (altNames != null) {
for (Iterator nameIterator = altNames.iterator(); nameIterator.hasNext();) {
List altName = (List) nameIterator.next();
- if (altName.get(0).equals(new Integer(2)) || altName.get(0).equals(new Integer(6))) { // 2 is
- // DNS,
- // 6 is
- // URI
+ if (altName.get(0).equals(new Integer(2)) || altName.get(0).equals(new Integer(6))) {
+ // 2 is DNS, 6 is URI
if (altName.get(1).equals(keyInfo.itemKeyName(l).getKeyName())) {
log.debug("Matched against SubjectAltName.");
return true;
}
}
} catch (CertificateParsingException e1) {
- log
- .error("Encountered an problem trying to extract Subject Alternate Name from supplied certificate: "
- + e1);
+ log.error("Encountered an problem trying to extract Subject Alternate "
+ + "Name from supplied certificate: " + e1);
}
// If that doesn't work, try to match using
// SSL-style hostname matching
-
- // TODO stop relying on this class
- if (ShibBrowserProfile.getHostNameFromDN(certificate.getSubjectX500Principal()).equals(
+ if (getHostNameFromDN(certificate.getSubjectX500Principal()).equals(
keyInfo.itemKeyName(l).getKeyName())) {
log.debug("Matched against hostname.");
return true;
import edu.internet2.middleware.shibboleth.common.InvalidNameIdentifierException;
import edu.internet2.middleware.shibboleth.common.NameIdentifierMappingException;
import edu.internet2.middleware.shibboleth.common.RelyingParty;
-import edu.internet2.middleware.shibboleth.common.ShibBrowserProfile;
import edu.internet2.middleware.shibboleth.common.ShibbolethConfigurationException;
import edu.internet2.middleware.shibboleth.idp.IdPProtocolHandler;
import edu.internet2.middleware.shibboleth.idp.IdPProtocolSupport;
+ credential.getSubjectX500Principal().getName(X500Principal.RFC2253) + ").");
// Mockup old requester name for requests from < 1.2 targets
if (fromLegacyProvider(req)) {
- String legacyName = ShibBrowserProfile.getHostNameFromDN(credential.getSubjectX500Principal());
+ String legacyName = getHostNameFromDN(credential.getSubjectX500Principal());
if (legacyName == null) {
log.error("Unable to extract legacy requester name from certificate subject.");
}
import edu.internet2.middleware.shibboleth.common.AuthNPrincipal;
import edu.internet2.middleware.shibboleth.common.NameIdentifierMappingException;
import edu.internet2.middleware.shibboleth.common.RelyingParty;
-import edu.internet2.middleware.shibboleth.common.ShibBrowserProfile;
import edu.internet2.middleware.shibboleth.common.ShibbolethConfigurationException;
import edu.internet2.middleware.shibboleth.idp.IdPProtocolHandler;
import edu.internet2.middleware.shibboleth.idp.IdPProtocolSupport;
if (relyingParty.getIdentityProvider().getSigningCredential() == null
|| relyingParty.getIdentityProvider().getSigningCredential().getX509Certificate() == null) { throw new SAMLException(
"Cannot serve legacy style assertions without an X509 certificate"); }
- issuer = ShibBrowserProfile.getHostNameFromDN(relyingParty.getIdentityProvider().getSigningCredential()
- .getX509Certificate().getSubjectX500Principal());
+ issuer = getHostNameFromDN(relyingParty.getIdentityProvider().getSigningCredential().getX509Certificate()
+ .getSubjectX500Principal());
if (issuer == null || issuer.equals("")) { throw new SAMLException(
"Error parsing certificate DN while determining legacy issuer name."); }
+++ /dev/null
-/*
- * The Shibboleth License, Version 1. Copyright (c) 2002 University Corporation for Advanced Internet Development, Inc.
- * All rights reserved Redistribution and use in source and binary forms, with or without modification, are permitted
- * provided that the following conditions are met: Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution, if any, must include the following acknowledgment: "This product includes
- * software developed by the University Corporation for Advanced Internet Development <http://www.ucaid.edu> Internet2
- * Project. Alternately, this acknowledegement may appear in the software itself, if and wherever such third-party
- * acknowledgments normally appear. Neither the name of Shibboleth nor the names of its contributors, nor Internet2,
- * nor the University Corporation for Advanced Internet Development, Inc., nor UCAID may be used to endorse or promote
- * products derived from this software without specific prior written permission. For written permission, please
- * contact shibboleth@shibboleth.org Products derived from this software may not be called Shibboleth, Internet2,
- * UCAID, or the University Corporation for Advanced Internet Development, nor may Shibboleth appear in their name,
- * without prior written permission of the University Corporation for Advanced Internet Development. THIS SOFTWARE IS
- * PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND WITH ALL FAULTS. ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
- * NON-INFRINGEMENT ARE DISCLAIMED AND THE ENTIRE RISK OF SATISFACTORY QUALITY, PERFORMANCE, ACCURACY, AND EFFORT IS
- * WITH LICENSEE. IN NO EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR THE UNIVERSITY CORPORATION FOR ADVANCED
- * INTERNET DEVELOPMENT, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package edu.internet2.middleware.shibboleth.aa;
-
-import javax.security.auth.x500.X500Principal;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.BasicConfigurator;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-
-import edu.internet2.middleware.shibboleth.common.ShibBrowserProfile;
-
-/**
- * Validation suite for hack to pull hostnames out of a subject DN.
- *
- * @author Walter Hoehn(wassa@columbia.edu)
- */
-public class DNHostNameExtractionTests extends TestCase {
-
- //Basic
- String dn1 = "CN=wayf.internet2.edu,OU=TSG,O=University Corporation for Advanced Internet Development,L=Ann Arbor,ST=Michigan,C=US";
-
- //lowercase CN
- String dn2 = "cn=wayf.internet2.edu,OU=TSG,O=University Corporation for Advanced Internet Development,L=Ann Arbor,ST=Michigan,C=US";
-
- //Multiple CNs
- String dn4 = "CN=wayf.internet2.edu,OU=TSG, CN=foo, O=University Corporation for Advanced Internet Development,L=Ann Arbor,ST=Michigan,C=US";
-
- public DNHostNameExtractionTests(String name) {
- super(name);
- BasicConfigurator.resetConfiguration();
- BasicConfigurator.configure();
- Logger.getRootLogger().setLevel(Level.OFF);
- }
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(DNHostNameExtractionTests.class);
- BasicConfigurator.configure();
- Logger.getRootLogger().setLevel(Level.OFF);
- }
-
- protected void setUp() throws Exception {
- super.setUp();
-
- }
-
- public void testBasicExtraction() {
-
- try {
- assertEquals("Round-trip handle validation failed on DN.", ShibBrowserProfile
- .getHostNameFromDN(new X500Principal(dn1)), "wayf.internet2.edu");
-
- } catch (Exception e) {
- fail("Error in test specification: " + e.getMessage());
- }
- }
-
- public void testExtractionWithLowerCaseAttrName() {
-
- try {
- assertEquals("Round-trip handle validation failed on DN.", ShibBrowserProfile
- .getHostNameFromDN(new X500Principal(dn2)), "wayf.internet2.edu");
-
- } catch (Exception e) {
- fail("Error in test specification: " + e.getMessage());
- }
- }
-
- public void testExtractionWithMultipleCNs() {
-
- try {
- assertEquals("Round-trip handle validation failed on DN.", ShibBrowserProfile
- .getHostNameFromDN(new X500Principal(dn4)), "wayf.internet2.edu");
-
- } catch (Exception e) {
- fail("Error in test specification: " + e.getMessage());
- }
- }
-
-}
import java.io.File;
import java.io.FileInputStream;
-import java.util.Arrays;
-import java.util.Iterator;
import junit.framework.TestCase;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
-
import org.opensaml.SAMLAttribute;
import org.opensaml.SAMLException;
import org.opensaml.XML;
--- /dev/null
+/*
+ * The Shibboleth License, Version 1. Copyright (c) 2002 University Corporation for Advanced Internet Development, Inc.
+ * All rights reserved Redistribution and use in source and binary forms, with or without modification, are permitted
+ * provided that the following conditions are met: Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution, if any, must include the following acknowledgment: "This product includes software
+ * developed by the University Corporation for Advanced Internet Development <http://www.ucaid.edu> Internet2 Project.
+ * Alternately, this acknowledegement may appear in the software itself, if and wherever such third-party
+ * acknowledgments normally appear. Neither the name of Shibboleth nor the names of its contributors, nor Internet2, nor
+ * the University Corporation for Advanced Internet Development, Inc., nor UCAID may be used to endorse or promote
+ * products derived from this software without specific prior written permission. For written permission, please contact
+ * shibboleth@shibboleth.org Products derived from this software may not be called Shibboleth, Internet2, UCAID, or the
+ * University Corporation for Advanced Internet Development, nor may Shibboleth appear in their name, without prior
+ * written permission of the University Corporation for Advanced Internet Development. THIS SOFTWARE IS PROVIDED BY THE
+ * COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND WITH ALL FAULTS. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE
+ * DISCLAIMED AND THE ENTIRE RISK OF SATISFACTORY QUALITY, PERFORMANCE, ACCURACY, AND EFFORT IS WITH LICENSEE. IN NO
+ * EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR THE UNIVERSITY CORPORATION FOR ADVANCED INTERNET DEVELOPMENT, INC.
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package edu.internet2.middleware.shibboleth.idp.provider;
+
+import javax.security.auth.x500.X500Principal;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+
+/**
+ * Validation suite for hack to pull hostnames out of a subject DN.
+ *
+ * @author Walter Hoehn(wassa@columbia.edu)
+ */
+public class DNHostNameExtractionTests extends TestCase {
+
+ //Basic
+ String dn1 = "CN=wayf.internet2.edu,OU=TSG,O=University Corporation for Advanced Internet Development,L=Ann Arbor,ST=Michigan,C=US";
+
+ //lowercase CN
+ String dn2 = "cn=wayf.internet2.edu,OU=TSG,O=University Corporation for Advanced Internet Development,L=Ann Arbor,ST=Michigan,C=US";
+
+ //Multiple CNs
+ String dn4 = "CN=wayf.internet2.edu,OU=TSG, CN=foo, O=University Corporation for Advanced Internet Development,L=Ann Arbor,ST=Michigan,C=US";
+
+ public DNHostNameExtractionTests(String name) {
+
+ super(name);
+ BasicConfigurator.resetConfiguration();
+ BasicConfigurator.configure();
+ Logger.getRootLogger().setLevel(Level.OFF);
+ }
+
+ public static void main(String[] args) {
+
+ junit.textui.TestRunner.run(DNHostNameExtractionTests.class);
+ BasicConfigurator.configure();
+ Logger.getRootLogger().setLevel(Level.OFF);
+ }
+
+ protected void setUp() throws Exception {
+
+ super.setUp();
+
+ }
+
+ public void testBasicExtraction() {
+
+ try {
+ assertEquals("Round-trip handle validation failed on DN.", BaseHandler.getHostNameFromDN(new X500Principal(
+ dn1)), "wayf.internet2.edu");
+
+ } catch (Exception e) {
+ fail("Error in test specification: " + e.getMessage());
+ }
+ }
+
+ public void testExtractionWithLowerCaseAttrName() {
+
+ try {
+ assertEquals("Round-trip handle validation failed on DN.", BaseHandler.getHostNameFromDN(new X500Principal(
+ dn2)), "wayf.internet2.edu");
+
+ } catch (Exception e) {
+ fail("Error in test specification: " + e.getMessage());
+ }
+ }
+
+ public void testExtractionWithMultipleCNs() {
+
+ try {
+ assertEquals("Round-trip handle validation failed on DN.", BaseHandler.getHostNameFromDN(new X500Principal(
+ dn4)), "wayf.internet2.edu");
+
+ } catch (Exception e) {
+ fail("Error in test specification: " + e.getMessage());
+ }
+ }
+
+}
\ No newline at end of file