added keystore security stuff:q
authorblk <blk@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 12 Jun 2002 05:10:54 +0000 (05:10 +0000)
committerblk <blk@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 12 Jun 2002 05:10:54 +0000 (05:10 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@75 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/hs/HandleServiceSAML.java
src/edu/internet2/middleware/shibboleth/hs/HandleServlet.java

index 084dee1..9341bbf 100755 (executable)
@@ -2,25 +2,37 @@ package edu.internet2.middleware.shibboleth.hs;
 
 import java.io.*;
 import java.util.*;
+import java.security.*;
+import java.security.cert.*;
 import edu.internet2.middleware.shibboleth.*;
 import edu.internet2.middleware.shibboleth.common.*;
 import org.opensaml.*;
 
-
 public class HandleServiceSAML {
 
     protected String domain;
     protected String AAurl;
     public String[] policies = { Constants.POLICY_CLUBSHIB };
     private ShibPOSTProfile spp;
+    PrivateKey privateKey;
+    X509Certificate cert;
 
-    public HandleServiceSAML( String domain, String AAurl, String issuer) 
-       throws SAMLException 
+    public HandleServiceSAML( String domain, String AAurl, String HSname,
+                             String KSpath, String KSpass, String KSkeyalias,
+                             String KSkeypass, String certalias ) 
+       throws SAMLException, KeyStoreException, Exception
     {
        this.domain = domain;
        this.AAurl = AAurl;
        
-       spp = ShibPOSTProfileFactory.getInstance( policies, issuer );
+       KeyStore ks = KeyStore.getInstance("JKS");
+       FileInputStream fis = new FileInputStream(KSpath);
+       ks.load( fis, KSpass.toCharArray());
+       privateKey = (PrivateKey)ks.getKey(KSkeyalias, KSkeypass.toCharArray());
+       cert =(X509Certificate)ks.getCertificate(certalias);
+
+       
+       spp = ShibPOSTProfileFactory.getInstance( policies, HSname );
     }
     
     public byte[] prepare ( String handle, String shireURL, 
index fbdcaba..67f5edc 100644 (file)
@@ -24,16 +24,28 @@ public class HandleServlet extends HttpServlet {
        try {
            hsSAML = new HandleServiceSAML( getInitParameter("domain"), 
                                            getInitParameter("AAurl"),
-                                           getInitParameter("issuer") );
+                                           getInitParameter("HSname"),
+                                           getInitParameter("KSpath"),
+                                           getInitParameter("KSpass"),
+                                           getInitParameter("KSkeyalias"),
+                                           getInitParameter("KSkeypass"),
+                                           getInitParameter("certalias") );
            hrf = HandleRepositoryFactory.getInstance
                ( Constants.POLICY_CLUBSHIB, this );
        }
        catch (SAMLException ex) {
            throw new ServletException( "Error initializing SAML libraries: " + ex );
        }
+       catch (java.security.KeyStoreException ex) {
+           throw new ServletException( "Error initializing private KeyStore: " + ex );
+       }
+       
        catch (HandleException ex) {
            throw new ServletException( "Error initializing Handle Service: " +ex );
        }
+       catch (Exception ex) {
+           throw new ServletException( "Error initializing private KeyStore: " +ex );
+       }
        if (hsSAML == null) {
            throw new ServletException( "Error initializing SAML libraries: No Profile created." );
        }  
@@ -54,7 +66,31 @@ public class HandleServlet extends HttpServlet {
             getInitParameter("AAurl").equals("")) {
            throw new ServletException("Cannot find host Attribute Authority location in init parameters");
        }
-       
+       if ( getInitParameter("HSname") == null || 
+            getInitParameter("HSname").equals("")) {
+           throw new ServletException("Cannot find Handle Service name in init parameters");
+       }
+       if ( getInitParameter("KSpath") == null || 
+            getInitParameter("AAurl").equals("")) {
+           throw new ServletException("Cannot find path to KeyStore file in init parameters");
+       }
+       if ( getInitParameter("KSpass") == null || 
+            getInitParameter("KSpass").equals("")) {
+           throw new ServletException("Cannot find password to KeyStore in init parameters");
+       }
+       if ( getInitParameter("KSkeyalias") == null || 
+            getInitParameter("AAurl").equals("")) {
+           throw new ServletException("Cannot find private key alias to KeyStore in init parameters");
+       }
+       if ( getInitParameter("KSkeypass") == null || 
+            getInitParameter("KSkeypass").equals("")) {
+           throw new ServletException("Cannot find private key password to Keystore in init parameters");
+       }
+       if ( getInitParameter("certalias") == null || 
+            getInitParameter("certalias").equals("")) {
+           throw new ServletException("Cannot find certificate alias in init parameters");
+       }
+
 
     }
 
@@ -110,7 +146,8 @@ public class HandleServlet extends HttpServlet {
            out.println("</form>");
            
            /**
-            * soon to implement forwarding to hs.jsp for submission
+            * uncomment the following to implement 
+            * forwarding to hs.jsp for submission
              * 
            //Hardcoded to ASCII to ensure Base64 encoding compatibility
            req.setAttribute("assertion", new String(buf, "ASCII"));
@@ -135,7 +172,7 @@ public class HandleServlet extends HttpServlet {
        throws ServletException, IOException {
 
        req.setAttribute("errorText", e.toString());
-       //      req.setAttribute("requestURL", req.getRequestURL().toString());
+       req.setAttribute("requestURL", req.getRequestURI().toString());
        RequestDispatcher rd = req.getRequestDispatcher("/hserror.jsp");
        
        rd.forward(req, res);