You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by dr...@apache.org on 2015/06/11 15:31:07 UTC
[06/18] directory-kerby git commit: Remove not-yet-so-commons-ssl
library and pki-provider for now as PKINIT is still half-baked
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/324c4b45/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/HostnameVerifier.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/HostnameVerifier.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/HostnameVerifier.java
deleted file mode 100644
index e797abe..0000000
--- a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/HostnameVerifier.java
+++ /dev/null
@@ -1,481 +0,0 @@
-/*
- * $HeadURL: http://juliusdavies.ca/svn/not-yet-commons-ssl/tags/commons-ssl-0.3.16/src/java/org/apache/commons/ssl/HostnameVerifier.java $
- * $Revision: 121 $
- * $Date: 2007-11-13 21:26:57 -0800 (Tue, 13 Nov 2007) $
- *
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.commons.ssl;
-
-import javax.net.ssl.SSLException;
-import javax.net.ssl.SSLPeerUnverifiedException;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.SSLSocket;
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.cert.Certificate;
-import java.security.cert.X509Certificate;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.TreeSet;
-
-/**
- * Interface for checking if a hostname matches the names stored inside the
- * server's X.509 certificate. Correctly implements
- * javax.net.ssl.HostnameVerifier, but that interface is not recommended.
- * Instead we added several check() methods that take SSLSocket,
- * or X509Certificate, or ultimately (they all end up calling this one),
- * String. (It's easier to supply JUnit with Strings instead of mock
- * SSLSession objects!)
- * </p><p>Our check() methods throw exceptions if the name is
- * invalid, whereas javax.net.ssl.HostnameVerifier just returns true/false.
- * <p/>
- * We provide the HostnameVerifier.DEFAULT, HostnameVerifier.STRICT, and
- * HostnameVerifier.ALLOW_ALL implementations. We also provide the more
- * specialized HostnameVerifier.DEFAULT_AND_LOCALHOST, as well as
- * HostnameVerifier.STRICT_IE6. But feel free to define your own
- * implementations!
- * <p/>
- * Inspired by Sebastian Hauer's original StrictSSLProtocolSocketFactory in the
- * HttpClient "contrib" repository.
- *
- * @author Julius Davies
- * @author <a href="mailto:hauer@psicode.com">Sebastian Hauer</a>
- * @since 8-Dec-2006
- */
-public interface HostnameVerifier extends javax.net.ssl.HostnameVerifier {
-
- boolean verify(String host, SSLSession session);
-
- void check(String host, SSLSocket ssl) throws IOException;
-
- void check(String host, X509Certificate cert) throws SSLException;
-
- void check(String host, String[] cns, String[] subjectAlts)
- throws SSLException;
-
- void check(String[] hosts, SSLSocket ssl) throws IOException;
-
- void check(String[] hosts, X509Certificate cert) throws SSLException;
-
-
- /**
- * Checks to see if the supplied hostname matches any of the supplied CNs
- * or "DNS" Subject-Alts. Most implementations only look at the first CN,
- * and ignore any additional CNs. Most implementations do look at all of
- * the "DNS" Subject-Alts. The CNs or Subject-Alts may contain wildcards
- * according to RFC 2818.
- *
- * @param cns CN fields, in order, as extracted from the X.509
- * certificate.
- * @param subjectAlts Subject-Alt fields of type 2 ("DNS"), as extracted
- * from the X.509 certificate.
- * @param hosts The array of hostnames to verify.
- * @throws javax.net.ssl.SSLException If verification failed.
- */
- void check(String[] hosts, String[] cns, String[] subjectAlts)
- throws SSLException;
-
-
- /**
- * The DEFAULT HostnameVerifier works the same way as Curl and Firefox.
- * <p/>
- * The hostname must match either the first CN, or any of the subject-alts.
- * A wildcard can occur in the CN, and in any of the subject-alts.
- * <p/>
- * The only difference between DEFAULT and STRICT is that a wildcard (such
- * as "*.foo.com") with DEFAULT matches all subdomains, including
- * "a.b.foo.com".
- */
- public final static HostnameVerifier DEFAULT =
- new AbstractVerifier() {
- public final void check(final String[] hosts, final String[] cns,
- final String[] subjectAlts)
- throws SSLException {
- check(hosts, cns, subjectAlts, false, false);
- }
-
- public final String toString() { return "DEFAULT"; }
- };
-
-
- /**
- * The DEFAULT_AND_LOCALHOST HostnameVerifier works like the DEFAULT
- * one with one additional relaxation: a host of "localhost",
- * "localhost.localdomain", "127.0.0.1", "::1" will always pass, no matter
- * what is in the server's certificate.
- */
- public final static HostnameVerifier DEFAULT_AND_LOCALHOST =
- new AbstractVerifier() {
- public final void check(final String[] hosts, final String[] cns,
- final String[] subjectAlts)
- throws SSLException {
- if (isLocalhost(hosts[0])) {
- return;
- }
- check(hosts, cns, subjectAlts, false, false);
- }
-
- public final String toString() { return "DEFAULT_AND_LOCALHOST"; }
- };
-
- /**
- * The STRICT HostnameVerifier works the same way as java.net.URL in Sun
- * Java 1.4, Sun Java 5, Sun Java 6. It's also pretty close to IE6.
- * This implementation appears to be compliant with RFC 2818 for dealing
- * with wildcards.
- * <p/>
- * The hostname must match either the first CN, or any of the subject-alts.
- * A wildcard can occur in the CN, and in any of the subject-alts. The
- * one divergence from IE6 is how we only check the first CN. IE6 allows
- * a match against any of the CNs present. We decided to follow in
- * Sun Java 1.4's footsteps and only check the first CN.
- * <p/>
- * A wildcard such as "*.foo.com" matches only subdomains in the same
- * level, for example "a.foo.com". It does not match deeper subdomains
- * such as "a.b.foo.com".
- */
- public final static HostnameVerifier STRICT =
- new AbstractVerifier() {
- public final void check(final String[] host, final String[] cns,
- final String[] subjectAlts)
- throws SSLException {
- check(host, cns, subjectAlts, false, true);
- }
-
- public final String toString() { return "STRICT"; }
- };
-
- /**
- * The STRICT_IE6 HostnameVerifier works just like the STRICT one with one
- * minor variation: the hostname can match against any of the CN's in the
- * server's certificate, not just the first one. This behaviour is
- * identical to IE6's behaviour.
- */
- public final static HostnameVerifier STRICT_IE6 =
- new AbstractVerifier() {
- public final void check(final String[] host, final String[] cns,
- final String[] subjectAlts)
- throws SSLException {
- check(host, cns, subjectAlts, true, true);
- }
-
- public final String toString() { return "STRICT_IE6"; }
- };
-
- /**
- * The ALLOW_ALL HostnameVerifier essentially turns hostname verification
- * off. This implementation is a no-op, and never throws the SSLException.
- */
- public final static HostnameVerifier ALLOW_ALL =
- new AbstractVerifier() {
- public final void check(final String[] host, final String[] cns,
- final String[] subjectAlts) {
- // Allow everything - so never blowup.
- }
-
- public final String toString() { return "ALLOW_ALL"; }
- };
-
- abstract class AbstractVerifier implements HostnameVerifier {
-
- /**
- * This contains a list of 2nd-level domains that aren't allowed to
- * have wildcards when combined with country-codes.
- * For example: [*.co.uk].
- * <p/>
- * The [*.co.uk] problem is an interesting one. Should we just hope
- * that CA's would never foolishly allow such a certificate to happen?
- * Looks like we're the only implementation guarding against this.
- * Firefox, Curl, Sun Java 1.4, 5, 6 don't bother with this check.
- */
- private final static String[] BAD_COUNTRY_2LDS =
- {"ac", "co", "com", "ed", "edu", "go", "gouv", "gov", "info",
- "lg", "ne", "net", "or", "org"};
-
- private final static String[] LOCALHOSTS = {"::1", "127.0.0.1",
- "localhost",
- "localhost.localdomain"};
-
-
- static {
- // Just in case developer forgot to manually sort the array. :-)
- Arrays.sort(BAD_COUNTRY_2LDS);
- Arrays.sort(LOCALHOSTS);
- }
-
- protected AbstractVerifier() {}
-
- /**
- * The javax.net.ssl.HostnameVerifier contract.
- *
- * @param host 'hostname' we used to create our socket
- * @param session SSLSession with the remote server
- * @return true if the host matched the one in the certificate.
- */
- public boolean verify(String host, SSLSession session) {
- try {
- Certificate[] certs = session.getPeerCertificates();
- X509Certificate x509 = (X509Certificate) certs[0];
- check(new String[]{host}, x509);
- return true;
- }
- catch (SSLException e) {
- return false;
- }
- }
-
- public void check(String host, SSLSocket ssl) throws IOException {
- check(new String[]{host}, ssl);
- }
-
- public void check(String host, X509Certificate cert)
- throws SSLException {
- check(new String[]{host}, cert);
- }
-
- public void check(String host, String[] cns, String[] subjectAlts)
- throws SSLException {
- check(new String[]{host}, cns, subjectAlts);
- }
-
- public void check(String host[], SSLSocket ssl)
- throws IOException {
- if (host == null) {
- throw new NullPointerException("host to verify is null");
- }
-
- SSLSession session = ssl.getSession();
- if (session == null) {
- // In our experience this only happens under IBM 1.4.x when
- // spurious (unrelated) certificates show up in the server'
- // chain. Hopefully this will unearth the real problem:
- InputStream in = ssl.getInputStream();
- in.available();
- /*
- If you're looking at the 2 lines of code above because
- you're running into a problem, you probably have two
- options:
-
- #1. Clean up the certificate chain that your server
- is presenting (e.g. edit "/etc/apache2/server.crt"
- or wherever it is your server's certificate chain
- is defined).
-
- OR
-
- #2. Upgrade to an IBM 1.5.x or greater JVM, or switch
- to a non-IBM JVM.
- */
-
- // If ssl.getInputStream().available() didn't cause an
- // exception, maybe at least now the session is available?
- session = ssl.getSession();
- if (session == null) {
- // If it's still null, probably a startHandshake() will
- // unearth the real problem.
- ssl.startHandshake();
-
- // Okay, if we still haven't managed to cause an exception,
- // might as well go for the NPE. Or maybe we're okay now?
- session = ssl.getSession();
- }
- }
- Certificate[] certs;
- try {
- certs = session.getPeerCertificates();
- } catch (SSLPeerUnverifiedException spue) {
- InputStream in = ssl.getInputStream();
- in.available();
- // Didn't trigger anything interesting? Okay, just throw
- // original.
- throw spue;
- }
- X509Certificate x509 = (X509Certificate) certs[0];
- check(host, x509);
- }
-
- public void check(String[] host, X509Certificate cert)
- throws SSLException {
- String[] cns = Certificates.getCNs(cert);
- String[] subjectAlts = Certificates.getDNSSubjectAlts(cert);
- check(host, cns, subjectAlts);
- }
-
- public void check(final String[] hosts, final String[] cns,
- final String[] subjectAlts, final boolean ie6,
- final boolean strictWithSubDomains)
- throws SSLException {
- // Build up lists of allowed hosts For logging/debugging purposes.
- StringBuffer buf = new StringBuffer(32);
- buf.append('<');
- for (int i = 0; i < hosts.length; i++) {
- String h = hosts[i];
- h = h != null ? h.trim().toLowerCase() : "";
- hosts[i] = h;
- if (i > 0) {
- buf.append('/');
- }
- buf.append(h);
- }
- buf.append('>');
- String hostnames = buf.toString();
- // Build the list of names we're going to check. Our DEFAULT and
- // STRICT implementations of the HostnameVerifier only use the
- // first CN provided. All other CNs are ignored.
- // (Firefox, wget, curl, Sun Java 1.4, 5, 6 all work this way).
- TreeSet names = new TreeSet();
- if (cns != null && cns.length > 0 && cns[0] != null) {
- names.add(cns[0]);
- if (ie6) {
- for (int i = 1; i < cns.length; i++) {
- names.add(cns[i]);
- }
- }
- }
- if (subjectAlts != null) {
- for (int i = 0; i < subjectAlts.length; i++) {
- if (subjectAlts[i] != null) {
- names.add(subjectAlts[i]);
- }
- }
- }
- if (names.isEmpty()) {
- String msg = "Certificate for " + hosts[0] + " doesn't contain CN or DNS subjectAlt";
- throw new SSLException(msg);
- }
-
- // StringBuffer for building the error message.
- buf = new StringBuffer();
-
- boolean match = false;
- out:
- for (Iterator it = names.iterator(); it.hasNext();) {
- // Don't trim the CN, though!
- String cn = (String) it.next();
- cn = cn.toLowerCase();
- // Store CN in StringBuffer in case we need to report an error.
- buf.append(" <");
- buf.append(cn);
- buf.append('>');
- if (it.hasNext()) {
- buf.append(" OR");
- }
-
- // The CN better have at least two dots if it wants wildcard
- // action. It also can't be [*.co.uk] or [*.co.jp] or
- // [*.org.uk], etc...
- boolean doWildcard = cn.startsWith("*.") &&
- cn.lastIndexOf('.') >= 0 &&
- !isIP4Address(cn) &&
- acceptableCountryWildcard(cn);
-
- for (int i = 0; i < hosts.length; i++) {
- final String hostName = hosts[i].trim().toLowerCase();
- if (doWildcard) {
- match = hostName.endsWith(cn.substring(1));
- if (match && strictWithSubDomains) {
- // If we're in strict mode, then [*.foo.com] is not
- // allowed to match [a.b.foo.com]
- match = countDots(hostName) == countDots(cn);
- }
- } else {
- match = hostName.equals(cn);
- }
- if (match) {
- break out;
- }
- }
- }
- if (!match) {
- throw new SSLException("hostname in certificate didn't match: " + hostnames + " !=" + buf);
- }
- }
-
- public static boolean isIP4Address(final String cn) {
- boolean isIP4 = true;
- String tld = cn;
- int x = cn.lastIndexOf('.');
- // We only bother analyzing the characters after the final dot
- // in the name.
- if (x >= 0 && x + 1 < cn.length()) {
- tld = cn.substring(x + 1);
- }
- for (int i = 0; i < tld.length(); i++) {
- if (!Character.isDigit(tld.charAt(0))) {
- isIP4 = false;
- break;
- }
- }
- return isIP4;
- }
-
- public static boolean acceptableCountryWildcard(final String cn) {
- int cnLen = cn.length();
- if (cnLen >= 7 && cnLen <= 9) {
- // Look for the '.' in the 3rd-last position:
- if (cn.charAt(cnLen - 3) == '.') {
- // Trim off the [*.] and the [.XX].
- String s = cn.substring(2, cnLen - 3);
- // And test against the sorted array of bad 2lds:
- int x = Arrays.binarySearch(BAD_COUNTRY_2LDS, s);
- return x < 0;
- }
- }
- return true;
- }
-
- public static boolean isLocalhost(String host) {
- host = host != null ? host.trim().toLowerCase() : "";
- if (host.startsWith("::1")) {
- int x = host.lastIndexOf('%');
- if (x >= 0) {
- host = host.substring(0, x);
- }
- }
- int x = Arrays.binarySearch(LOCALHOSTS, host);
- return x >= 0;
- }
-
- /**
- * Counts the number of dots "." in a string.
- *
- * @param s string to count dots from
- * @return number of dots
- */
- public static int countDots(final String s) {
- int count = 0;
- for (int i = 0; i < s.length(); i++) {
- if (s.charAt(i) == '.') {
- count++;
- }
- }
- return count;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/324c4b45/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Java14.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Java14.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Java14.java
deleted file mode 100644
index 3e64e5d..0000000
--- a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Java14.java
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * $HeadURL: http://juliusdavies.ca/svn/not-yet-commons-ssl/tags/commons-ssl-0.3.16/src/java/org/apache/commons/ssl/Java14.java $
- * $Revision: 166 $
- * $Date: 2014-04-28 11:40:25 -0700 (Mon, 28 Apr 2014) $
- *
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.commons.ssl;
-
-import org.apache.commons.ssl.util.IPAddressParser;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.UnknownHostException;
-import java.security.KeyManagementException;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.Certificate;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
-import javax.net.SocketFactory;
-import javax.net.ssl.KeyManager;
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLPeerUnverifiedException;
-import javax.net.ssl.SSLServerSocket;
-import javax.net.ssl.SSLServerSocketFactory;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.SSLSocket;
-import javax.net.ssl.SSLSocketFactory;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.TrustManagerFactory;
-import javax.net.ssl.X509KeyManager;
-import javax.net.ssl.X509TrustManager;
-
-
-/**
- * @author Credit Union Central of British Columbia
- * @author <a href="http://www.cucbc.com/">www.cucbc.com</a>
- * @author <a href="mailto:juliusdavies@cucbc.com">juliusdavies@cucbc.com</a>
- * @since 30-Jun-2006
- */
-public final class Java14 extends JavaImpl {
- private static Java14 instance = new Java14();
-
- private Java14() {
- try {
- SSLSocketFactory.getDefault().createSocket();
- }
- catch (IOException ioe) {
- ioe.hashCode();
- }
- }
-
- public static Java14 getInstance() {
- return instance;
- }
-
- public final String getVersion() {
- return "Java14";
- }
-
- protected final String retrieveSubjectX500(X509Certificate cert) {
- return cert.getSubjectX500Principal().toString();
- }
-
- protected final String retrieveIssuerX500(X509Certificate cert) {
- return cert.getIssuerX500Principal().toString();
- }
-
- protected final Certificate[] retrievePeerCerts(SSLSession sslSession)
- throws SSLPeerUnverifiedException {
- return sslSession.getPeerCertificates();
- }
-
- protected final Object buildKeyManagerFactory(KeyStore ks, char[] password)
- throws NoSuchAlgorithmException, KeyStoreException,
- UnrecoverableKeyException {
- String alg = KeyManagerFactory.getDefaultAlgorithm();
- KeyManagerFactory kmf = KeyManagerFactory.getInstance(alg);
- kmf.init(ks, password);
- return kmf;
- }
-
- protected final Object buildTrustManagerFactory(KeyStore ks)
- throws NoSuchAlgorithmException, KeyStoreException {
- String alg = TrustManagerFactory.getDefaultAlgorithm();
- TrustManagerFactory tmf = TrustManagerFactory.getInstance(alg);
- tmf.init(ks);
- return tmf;
- }
-
- protected final Object[] retrieveKeyManagers(Object keyManagerFactory) {
- KeyManagerFactory kmf = (KeyManagerFactory) keyManagerFactory;
- return kmf.getKeyManagers();
- }
-
- protected final Object[] retrieveTrustManagers(Object trustManagerFactory) {
- TrustManagerFactory tmf = (TrustManagerFactory) trustManagerFactory;
- return tmf.getTrustManagers();
- }
-
- protected final SSLSocketFactory buildSSLSocketFactory(Object ssl) {
- return ((SSLContext) ssl).getSocketFactory();
- }
-
- protected final SSLServerSocketFactory buildSSLServerSocketFactory(Object ssl) {
- return ((SSLContext) ssl).getServerSocketFactory();
- }
-
- protected final RuntimeException buildRuntimeException(Exception cause) {
- return new RuntimeException(cause);
- }
-
- protected final SSLSocket buildSocket(SSL ssl) throws IOException {
- SSLSocketFactory sf = ssl.getSSLSocketFactory();
- SSLSocket s = (SSLSocket) sf.createSocket();
- ssl.doPreConnectSocketStuff(s);
- return s;
- }
-
- protected final SSLSocket buildSocket(SSL ssl, String remoteHost,
- int remotePort, InetAddress localHost,
- int localPort, int timeout)
- throws IOException {
- SSLSocket s = buildSocket(ssl);
- s = (SSLSocket) connectSocket(s, null, remoteHost, remotePort,
- localHost, localPort, timeout, ssl);
- ssl.doPostConnectSocketStuff(s, remoteHost);
- return s;
- }
-
-
- protected final Socket buildPlainSocket(
- SSL ssl, String remoteHost, int remotePort, InetAddress localHost, int localPort, int timeout
- ) throws IOException {
- Socket s = SocketFactory.getDefault().createSocket();
- ssl.doPreConnectSocketStuff(s);
- s = connectSocket(
- s, null, remoteHost, remotePort, localHost, localPort, timeout, ssl
- );
- ssl.doPostConnectSocketStuff(s, remoteHost);
- return s;
- }
-
- protected final Socket connectSocket(Socket s, SocketFactory sf,
- String host, int remotePort,
- InetAddress localHost, int localPort,
- int timeout, SSL ssl)
- throws IOException {
- if (s == null) {
- if (sf == null) {
- s = new Socket();
- } else {
- s = sf.createSocket();
- }
- }
- host = ssl.dnsOverride(host);
- InetAddress remoteHost = Util.toInetAddress(host);
- InetSocketAddress dest = new InetSocketAddress(remoteHost, remotePort);
- InetSocketAddress src = new InetSocketAddress(localHost, localPort);
- s.bind(src);
- s.connect(dest, timeout);
- return s;
- }
-
- protected final SSLServerSocket buildServerSocket(SSL ssl)
- throws IOException {
- ServerSocket s = ssl.getSSLServerSocketFactory().createServerSocket();
- SSLServerSocket ss = (SSLServerSocket) s;
- ssl.doPreConnectServerSocketStuff(ss);
- return ss;
- }
-
- protected final void wantClientAuth(Object o, boolean wantClientAuth) {
- SSLSocket s;
- SSLServerSocket ss;
- if (o instanceof SSLSocket) {
- s = (SSLSocket) o;
- s.setWantClientAuth(wantClientAuth);
- } else if (o instanceof SSLServerSocket) {
- ss = (SSLServerSocket) o;
- ss.setWantClientAuth(wantClientAuth);
- } else {
- throw new ClassCastException("need SSLSocket or SSLServerSocket");
- }
- }
-
- protected final void enabledProtocols(Object o, String[] enabledProtocols) {
- SSLSocket s;
- SSLServerSocket ss;
- if (o instanceof SSLSocket) {
- s = (SSLSocket) o;
- s.setEnabledProtocols(enabledProtocols);
- } else if (o instanceof SSLServerSocket) {
- ss = (SSLServerSocket) o;
- ss.setEnabledProtocols(enabledProtocols);
- } else {
- throw new ClassCastException("need SSLSocket or SSLServerSocket");
- }
- }
-
- protected void checkTrusted(Object trustManager, X509Certificate[] chain,
- String authType)
- throws CertificateException {
- X509TrustManager tm = (X509TrustManager) trustManager;
- tm.checkServerTrusted(chain, authType);
- }
-
- protected final Object initSSL(SSL ssl, TrustChain tc, KeyMaterial k)
- throws NoSuchAlgorithmException, KeyStoreException,
- CertificateException, KeyManagementException, IOException {
- SSLContext context = SSLContext.getInstance(ssl.getDefaultProtocol());
- TrustManager[] trustManagers = null;
- KeyManager[] keyManagers = null;
- if (tc != null) {
- trustManagers = (TrustManager[]) tc.getTrustManagers();
- }
- if (k != null) {
- keyManagers = (KeyManager[]) k.getKeyManagers();
- }
- if (keyManagers != null) {
- for (int i = 0; i < keyManagers.length; i++) {
- if (keyManagers[i] instanceof X509KeyManager) {
- X509KeyManager km = (X509KeyManager) keyManagers[i];
- keyManagers[i] = new Java14KeyManagerWrapper(km, k, ssl);
- }
- }
- }
- if (trustManagers != null) {
- for (int i = 0; i < trustManagers.length; i++) {
- if (trustManagers[i] instanceof X509TrustManager) {
- X509TrustManager tm = (X509TrustManager) trustManagers[i];
- trustManagers[i] = new Java14TrustManagerWrapper(tm, tc, ssl);
- }
- }
- }
- context.init(keyManagers, trustManagers, null);
- return context;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/324c4b45/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Java14KeyManagerWrapper.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Java14KeyManagerWrapper.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Java14KeyManagerWrapper.java
deleted file mode 100644
index baf7d1e..0000000
--- a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Java14KeyManagerWrapper.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * $HeadURL: http://juliusdavies.ca/svn/not-yet-commons-ssl/tags/commons-ssl-0.3.16/src/java/org/apache/commons/ssl/Java14KeyManagerWrapper.java $
- * $Revision: 121 $
- * $Date: 2007-11-13 21:26:57 -0800 (Tue, 13 Nov 2007) $
- *
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.commons.ssl;
-
-import javax.net.ssl.X509KeyManager;
-import java.net.Socket;
-import java.security.Principal;
-import java.security.PrivateKey;
-import java.security.cert.X509Certificate;
-
-/**
- * @author Credit Union Central of British Columbia
- * @author <a href="http://www.cucbc.com/">www.cucbc.com</a>
- * @author <a href="mailto:juliusdavies@cucbc.com">juliusdavies@cucbc.com</a>
- * @since 30-Mar-2006
- */
-public class Java14KeyManagerWrapper implements X509KeyManager {
- private final X509KeyManager keyManager;
- // private final KeyMaterial keyMaterial;
- // private final SSL ssl;
-
- public Java14KeyManagerWrapper(X509KeyManager m, KeyMaterial km, SSL h) {
- this.keyManager = m;
- // this.keyMaterial = km;
- // this.ssl = h;
- }
-
- public String chooseClientAlias(String[] keyType, Principal[] issuers,
- Socket socket) {
- return keyManager.chooseClientAlias(keyType, issuers, socket);
- }
-
- public String chooseServerAlias(String keyType, Principal[] issuers,
- Socket socket) {
- return keyManager.chooseServerAlias(keyType, issuers, socket);
- }
-
- public X509Certificate[] getCertificateChain(String alias) {
- return keyManager.getCertificateChain(alias);
- }
-
- public String[] getClientAliases(String keyType, Principal[] issuers) {
- return keyManager.getClientAliases(keyType, issuers);
- }
-
- public PrivateKey getPrivateKey(String alias) {
- return keyManager.getPrivateKey(alias);
- }
-
- public String[] getServerAliases(String keyType, Principal[] issuers) {
- return keyManager.getServerAliases(keyType, issuers);
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/324c4b45/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Java14TrustManagerWrapper.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Java14TrustManagerWrapper.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Java14TrustManagerWrapper.java
deleted file mode 100644
index 31b4df9..0000000
--- a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Java14TrustManagerWrapper.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * $HeadURL: http://juliusdavies.ca/svn/not-yet-commons-ssl/tags/commons-ssl-0.3.16/src/java/org/apache/commons/ssl/Java14TrustManagerWrapper.java $
- * $Revision: 138 $
- * $Date: 2008-03-03 23:50:07 -0800 (Mon, 03 Mar 2008) $
- *
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.commons.ssl;
-
-import javax.net.ssl.X509TrustManager;
-import java.security.cert.CertificateException;
-import java.security.cert.CertificateExpiredException;
-import java.security.cert.X509Certificate;
-
-/**
- * @author Credit Union Central of British Columbia
- * @author <a href="http://www.cucbc.com/">www.cucbc.com</a>
- * @author <a href="mailto:juliusdavies@cucbc.com">juliusdavies@cucbc.com</a>
- * @since 30-Mar-2006
- */
-public class Java14TrustManagerWrapper implements X509TrustManager {
- private final X509TrustManager trustManager;
- private final TrustChain trustChain;
- private final SSL ssl;
-
- public Java14TrustManagerWrapper(X509TrustManager m, TrustChain tc, SSL h) {
- this.trustManager = m;
- this.trustChain = tc;
- this.ssl = h;
- }
-
- public void checkClientTrusted(X509Certificate[] chain, String authType)
- throws CertificateException {
- ssl.setCurrentClientChain(chain);
- CertificateException ce = null;
- try {
- trustManager.checkClientTrusted(chain, authType);
- }
- catch (CertificateException e) {
- ce = e;
- }
- testShouldWeThrow(ce, chain);
- }
-
- public void checkServerTrusted(X509Certificate[] chain, String authType)
- throws CertificateException {
- ssl.setCurrentServerChain(chain);
- CertificateException ce = null;
- try {
- trustManager.checkServerTrusted(chain, authType);
- }
- catch (CertificateException e) {
- ce = e;
- }
- testShouldWeThrow(ce, chain);
- }
-
- public X509Certificate[] getAcceptedIssuers() {
- if (trustChain.containsTrustAll()) {
- // Counter-intuitively, this means we accept all issuers.
- return new X509Certificate[0];
- } else {
- return trustManager.getAcceptedIssuers();
- }
- }
-
- private void testShouldWeThrow(CertificateException checkException,
- X509Certificate[] chain)
- throws CertificateException {
- if (checkException != null) {
- Throwable root = getRootThrowable(checkException);
- boolean expiryProblem = root instanceof CertificateExpiredException;
- if (expiryProblem) {
- if (ssl.getCheckExpiry()) {
- // We're expired, and this factory cares.
- throw checkException;
- }
- } else {
- // Probably the cert isn't trusted. Only let it through if
- // this factory trusts everything.
- if (!trustChain.contains(TrustMaterial.TRUST_ALL)) {
- throw checkException;
- }
- }
- }
-
- for (int i = 0; i < chain.length; i++) {
- X509Certificate c = chain[i];
- if (ssl.getCheckExpiry()) {
- c.checkValidity();
- }
- if (ssl.getCheckCRL()) {
- Certificates.checkCRL(c);
- }
- }
- }
-
- private static Throwable getRootThrowable(Throwable t) {
- if (t == null) {
- return t;
- }
- Throwable cause = t.getCause();
- while (cause != null && !t.equals(cause)) {
- t = cause;
- cause = t.getCause();
- }
- return t;
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/324c4b45/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/JavaImpl.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/JavaImpl.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/JavaImpl.java
deleted file mode 100644
index bc222a8..0000000
--- a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/JavaImpl.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * $HeadURL: http://juliusdavies.ca/svn/not-yet-commons-ssl/tags/commons-ssl-0.3.16/src/java/org/apache/commons/ssl/JavaImpl.java $
- * $Revision: 155 $
- * $Date: 2009-09-17 14:00:58 -0700 (Thu, 17 Sep 2009) $
- *
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.commons.ssl;
-
-import javax.net.SocketFactory;
-import javax.net.ssl.SSLPeerUnverifiedException;
-import javax.net.ssl.SSLServerSocket;
-import javax.net.ssl.SSLServerSocketFactory;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.SSLSocket;
-import javax.net.ssl.SSLSocketFactory;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.security.KeyManagementException;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.Certificate;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
-
-/**
- * @author Credit Union Central of British Columbia
- * @author <a href="http://www.cucbc.com/">www.cucbc.com</a>
- * @author <a href="mailto:juliusdavies@cucbc.com">juliusdavies@cucbc.com</a>
- * @since 30-Jun-2006
- */
-public abstract class JavaImpl {
- private static JavaImpl HANDLER;
-
- static {
- JavaImpl h = null;
- h = Java14.getInstance();
- HANDLER = h;
- }
-
- public abstract String getVersion();
-
- protected abstract Object buildKeyManagerFactory(KeyStore ks, char[] pass)
- throws NoSuchAlgorithmException, KeyStoreException,
- UnrecoverableKeyException;
-
- protected abstract Object[] retrieveKeyManagers(Object keyManagerFactory);
-
- protected abstract Object buildTrustManagerFactory(KeyStore ks)
- throws NoSuchAlgorithmException, KeyStoreException;
-
- protected abstract Object[] retrieveTrustManagers(Object trustManagerFactory);
-
- protected abstract String retrieveSubjectX500(X509Certificate cert);
-
- protected abstract String retrieveIssuerX500(X509Certificate cert);
-
- protected abstract Certificate[] retrievePeerCerts(SSLSession sslSession)
- throws SSLPeerUnverifiedException;
-
- protected abstract SSLSocketFactory buildSSLSocketFactory(Object ssl);
-
- protected abstract SSLServerSocketFactory buildSSLServerSocketFactory(Object ssl);
-
- protected abstract SSLSocket buildSocket(SSL ssl)
- throws IOException;
-
- protected abstract SSLSocket buildSocket(
- SSL ssl, String remoteHost, int remotePort, InetAddress localHost, int localPort, int connectTimeout
- ) throws IOException;
-
- protected abstract Socket buildPlainSocket(
- SSL ssl, String remoteHost, int remotePort, InetAddress localHost, int localPort, int connectTimeout
- ) throws IOException;
-
- protected abstract Socket connectSocket(Socket s, SocketFactory sf,
- String remoteHost, int remotePort,
- InetAddress localHost, int localPort,
- int timeout, SSL ssl)
- throws IOException;
-
- protected abstract SSLServerSocket buildServerSocket(SSL ssl)
- throws IOException;
-
- protected abstract void wantClientAuth(Object o, boolean wantClientAuth);
-
- protected abstract void enabledProtocols(Object o, String[] enabledProtocols);
-
- protected abstract RuntimeException buildRuntimeException(Exception cause);
-
- protected abstract Object initSSL(SSL ssl, TrustChain tc, KeyMaterial km)
- throws NoSuchAlgorithmException, KeyStoreException,
- CertificateException, KeyManagementException, IOException;
-
- protected abstract void checkTrusted(Object trustManager,
- X509Certificate[] chain,
- String authType)
- throws CertificateException;
-
- public static Object init(SSL ssl, TrustChain trustChain, KeyMaterial keyMaterial)
- throws NoSuchAlgorithmException, KeyStoreException,
- CertificateException, KeyManagementException, IOException {
- return HANDLER.initSSL(ssl, trustChain, keyMaterial);
- }
-
- public static RuntimeException newRuntimeException(Exception cause) {
- return HANDLER.buildRuntimeException(cause);
- }
-
- public static SSLSocketFactory getSSLSocketFactory(Object sslContext) {
- return HANDLER.buildSSLSocketFactory(sslContext);
- }
-
- public static SSLServerSocketFactory getSSLServerSocketFactory(Object sslContext) {
- return HANDLER.buildSSLServerSocketFactory(sslContext);
- }
-
- public static String getSubjectX500(X509Certificate cert) {
- return HANDLER.retrieveSubjectX500(cert);
- }
-
- public static String getIssuerX500(X509Certificate cert) {
- return HANDLER.retrieveIssuerX500(cert);
- }
-
- public static Object newKeyManagerFactory(KeyStore ks, char[] password)
- throws NoSuchAlgorithmException, KeyStoreException,
- UnrecoverableKeyException {
- return HANDLER.buildKeyManagerFactory(ks, password);
- }
-
- public static Object[] getKeyManagers(Object keyManagerFactory) {
- return HANDLER.retrieveKeyManagers(keyManagerFactory);
- }
-
- public static Object newTrustManagerFactory(KeyStore ks)
- throws NoSuchAlgorithmException, KeyStoreException {
- return HANDLER.buildTrustManagerFactory(ks);
- }
-
- public static Object[] getTrustManagers(Object trustManagerFactory) {
- return HANDLER.retrieveTrustManagers(trustManagerFactory);
- }
-
- public static SSLSocket createSocket(SSL ssl)
- throws IOException {
- return HANDLER.buildSocket(ssl);
- }
-
- public static SSLSocket createSocket(SSL ssl, String remoteHost,
- int remotePort, InetAddress localHost,
- int localPort, int connectTimeout)
- throws IOException {
- return HANDLER.buildSocket(ssl, remoteHost, remotePort, localHost,
- localPort, connectTimeout);
- }
-
- public static Socket createPlainSocket(
- SSL ssl, String remoteHost, int remotePort, InetAddress localHost, int localPort,
- int connectTimeout
- ) throws IOException {
- return HANDLER.buildPlainSocket(
- ssl, remoteHost, remotePort, localHost, localPort, connectTimeout
- );
- }
-
- protected static Socket connect(Socket s, SocketFactory sf,
- String remoteHost, int remotePort,
- InetAddress localHost, int localPort,
- int timeout, SSL ssl)
- throws IOException {
- return HANDLER.connectSocket(s, sf, remoteHost, remotePort, localHost,
- localPort, timeout, ssl);
- }
-
- public static SSLServerSocket createServerSocket(SSL ssl)
- throws IOException {
- return HANDLER.buildServerSocket(ssl);
- }
-
- public static void setWantClientAuth(Object o, boolean wantClientAuth) {
- HANDLER.wantClientAuth(o, wantClientAuth);
- }
-
- public static void setEnabledProtocols(Object o, String[] enabledProtocols) {
- HANDLER.enabledProtocols(o, enabledProtocols);
- }
-
- public static Certificate[] getPeerCertificates(SSLSession session)
- throws SSLPeerUnverifiedException {
- return HANDLER.retrievePeerCerts(session);
- }
-
- public static void testTrust(Object trustManager, X509Certificate[] chain,
- String authType)
- throws CertificateException {
- HANDLER.checkTrusted(trustManager, chain, authType);
- }
-
- public static void load() {
- HANDLER.hashCode();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/324c4b45/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/KeyMaterial.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/KeyMaterial.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/KeyMaterial.java
deleted file mode 100644
index fdd7eee..0000000
--- a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/KeyMaterial.java
+++ /dev/null
@@ -1,289 +0,0 @@
-/*
- * $HeadURL: http://juliusdavies.ca/svn/not-yet-commons-ssl/tags/commons-ssl-0.3.16/src/java/org/apache/commons/ssl/KeyMaterial.java $
- * $Revision: 138 $
- * $Date: 2008-03-03 23:50:07 -0800 (Mon, 03 Mar 2008) $
- *
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.commons.ssl;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.security.GeneralSecurityException;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.cert.Certificate;
-import java.security.cert.CertificateEncodingException;
-import java.security.cert.X509Certificate;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * @author Credit Union Central of British Columbia
- * @author <a href="http://www.cucbc.com/">www.cucbc.com</a>
- * @author <a href="mailto:juliusdavies@cucbc.com">juliusdavies@cucbc.com</a>
- * @since 27-Feb-2006
- */
-public class KeyMaterial extends TrustMaterial {
- private final Object keyManagerFactory;
- private final List aliases;
- private final List associatedChains;
-
- public KeyMaterial(InputStream jks, char[] password)
- throws GeneralSecurityException, IOException {
- this(Util.streamToBytes(jks), password);
- }
-
- public KeyMaterial(InputStream jks, char[] jksPass, char[] keyPass)
- throws GeneralSecurityException, IOException {
- this(Util.streamToBytes(jks), jksPass, keyPass);
- }
-
- public KeyMaterial(InputStream jks, InputStream key, char[] password)
- throws GeneralSecurityException, IOException {
- this(jks != null ? Util.streamToBytes(jks) : null,
- key != null ? Util.streamToBytes(key) : null,
- password);
- }
-
- public KeyMaterial(InputStream jks, InputStream key, char[] jksPass,
- char[] keyPass)
- throws GeneralSecurityException, IOException {
- this(jks != null ? Util.streamToBytes(jks) : null,
- key != null ? Util.streamToBytes(key) : null,
- jksPass, keyPass);
- }
-
- public KeyMaterial(String pathToJksFile, char[] password)
- throws GeneralSecurityException, IOException {
- this(new File(pathToJksFile), password);
- }
-
- public KeyMaterial(String pathToJksFile, char[] jksPass, char[] keyPass)
- throws GeneralSecurityException, IOException {
- this(new File(pathToJksFile), jksPass, keyPass);
- }
-
- public KeyMaterial(String pathToCerts, String pathToKey, char[] password)
- throws GeneralSecurityException, IOException {
- this(pathToCerts != null ? new File(pathToCerts) : null,
- pathToKey != null ? new File(pathToKey) : null,
- password);
- }
-
- public KeyMaterial(String pathToCerts, String pathToKey, char[] jksPass,
- char[] keyPass)
- throws GeneralSecurityException, IOException {
- this(pathToCerts != null ? new File(pathToCerts) : null,
- pathToKey != null ? new File(pathToKey) : null,
- jksPass, keyPass);
- }
-
- public KeyMaterial(File jksFile, char[] password)
- throws GeneralSecurityException, IOException {
- this(new FileInputStream(jksFile), password);
- }
-
- public KeyMaterial(File jksFile, char[] jksPass, char[] keyPass)
- throws GeneralSecurityException, IOException {
- this(new FileInputStream(jksFile), jksPass, keyPass);
- }
-
- public KeyMaterial(File certsFile, File keyFile, char[] password)
- throws GeneralSecurityException, IOException {
- this(certsFile != null ? new FileInputStream(certsFile) : null,
- keyFile != null ? new FileInputStream(keyFile) : null,
- password);
- }
-
- public KeyMaterial(File certsFile, File keyFile, char[] jksPass,
- char[] keyPass)
- throws GeneralSecurityException, IOException {
- this(certsFile != null ? new FileInputStream(certsFile) : null,
- keyFile != null ? new FileInputStream(keyFile) : null,
- jksPass, keyPass);
- }
-
- public KeyMaterial(URL urlToJKS, char[] password)
- throws GeneralSecurityException, IOException {
- this(urlToJKS.openStream(), password);
- }
-
- public KeyMaterial(URL urlToJKS, char[] jksPass, char[] keyPass)
- throws GeneralSecurityException, IOException {
- this(urlToJKS.openStream(), jksPass, keyPass);
- }
-
- public KeyMaterial(URL urlToCerts, URL urlToKey, char[] password)
- throws GeneralSecurityException, IOException {
- this(urlToCerts.openStream(), urlToKey.openStream(), password);
- }
-
- public KeyMaterial(URL urlToCerts, URL urlToKey, char[] jksPass,
- char[] keyPass)
- throws GeneralSecurityException, IOException {
- this(urlToCerts.openStream(), urlToKey.openStream(), jksPass, keyPass);
- }
-
- public KeyMaterial(byte[] jks, char[] password)
- throws GeneralSecurityException, IOException {
- this(jks, (byte[]) null, password);
- }
-
- public KeyMaterial(byte[] jks, char[] jksPass, char[] keyPass)
- throws GeneralSecurityException, IOException {
- this(jks, null, jksPass, keyPass);
- }
-
- public KeyMaterial(byte[] jksOrCerts, byte[] key, char[] password)
- throws GeneralSecurityException, IOException {
- this(jksOrCerts, key, password, password);
- }
-
-
- public KeyMaterial(byte[] jksOrCerts, byte[] key, char[] jksPass,
- char[] keyPass)
- throws GeneralSecurityException, IOException {
- // We're not a simple trust type, so set "simpleTrustType" value to 0.
- // Only TRUST_ALL and TRUST_THIS_JVM are simple trust types.
- super(KeyStoreBuilder.build(jksOrCerts, key, jksPass, keyPass), 0);
- KeyStore ks = getKeyStore();
- Enumeration en = ks.aliases();
- List myAliases = new LinkedList();
- List myChains = new LinkedList();
- while (en.hasMoreElements()) {
- X509Certificate[] c; // chain
- String alias = (String) en.nextElement();
- if (ks.isKeyEntry(alias)) {
- try {
- ks.getKey(alias, keyPass);
- // No Exception thrown, so we're good!
- myAliases.add(alias);
- Certificate[] chain = ks.getCertificateChain(alias);
- if (chain != null) {
- c = Certificates.x509ifyChain(chain);
- // Cleanup chain to remove any spurious entries.
- if (c != null) {
- X509Certificate l = c[0]; // The leaf node.
- c = X509CertificateChainBuilder.buildPath(l, c);
- }
- myChains.add(c);
- } else {
- throw new KeyStoreException("Could not find KeyMaterial's associated certificate chain with alis=[" + alias + "]");
- }
-
- } catch (GeneralSecurityException gse) {
- // oh well, we can't use that KeyStore alias.
- }
- }
- }
- if (myAliases.isEmpty()) {
- throw new KeyStoreException("KeyMaterial provided does not contain any keys!");
- }
- this.aliases = Collections.unmodifiableList(myAliases);
- this.associatedChains = Collections.unmodifiableList(myChains);
- this.keyManagerFactory = JavaImpl.newKeyManagerFactory(ks, keyPass);
- }
-
- public Object[] getKeyManagers() {
- return JavaImpl.getKeyManagers(keyManagerFactory);
- }
-
- public List getAssociatedCertificateChains() {
- return associatedChains;
- }
-
- public KeyStore getKeyStore() {
- return super.getKeyStore();
- }
-
- public List getAliases() {
- return aliases;
- }
-
- public static void main(String[] args) throws Exception {
- if (args.length < 2) {
- System.out.println("Usage1: java org.apache.commons.ssl.KeyMaterial [password] [pkcs12 or jks]");
- System.out.println("Usage2: java org.apache.commons.ssl.KeyMaterial [password] [private-key] [cert-chain]");
- System.exit(1);
- }
- char[] jksPass = args[0].toCharArray();
- char[] keyPass = jksPass;
- String path1 = args[1];
- String path2 = null;
- if (args.length >= 3) {
- path2 = args[2];
- }
- if (args.length >= 4) {
- keyPass = args[3].toCharArray();
- } else if (path2 != null) {
- File f = new File(path2);
- if (!f.exists()) {
- // Hmmm... maybe it's a password.
- keyPass = path2.toCharArray();
- path2 = null;
- }
- }
-
- KeyMaterial km = new KeyMaterial(path1, path2, jksPass, keyPass);
- System.out.println(km);
- }
-
- public String toString() {
- List chains = getAssociatedCertificateChains();
- List aliases = getAliases();
- Iterator it = chains.iterator();
- Iterator aliasesIt = aliases.iterator();
- StringBuffer buf = new StringBuffer(8192);
- while (it.hasNext()) {
- X509Certificate[] certs = (X509Certificate[]) it.next();
- String alias = (String) aliasesIt.next();
- buf.append("Alias: ");
- buf.append(alias);
- buf.append('\n');
- if (certs != null) {
- for (int i = 0; i < certs.length; i++) {
- buf.append(Certificates.toString(certs[i]));
- try {
- buf.append(Certificates.toPEMString(certs[i]));
- }
- catch (CertificateEncodingException cee) {
- buf.append(cee.toString());
- buf.append('\n');
- }
- }
- }
- }
- return buf.toString();
- }
-}