| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
package org.apache.commons.httpclient.contrib.ssl; |
| 28 |
|
|
| 29 |
|
import java.security.KeyStore; |
| 30 |
|
import java.security.KeyStoreException; |
| 31 |
|
import java.security.NoSuchAlgorithmException; |
| 32 |
|
import java.security.cert.CertificateException; |
| 33 |
|
import java.security.cert.X509Certificate; |
| 34 |
|
|
| 35 |
|
import javax.net.ssl.TrustManagerFactory; |
| 36 |
|
import javax.net.ssl.TrustManager; |
| 37 |
|
import javax.net.ssl.X509TrustManager; |
| 38 |
|
import org.apache.commons.logging.Log; |
| 39 |
|
import org.apache.commons.logging.LogFactory; |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
@link |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
@author |
| 54 |
|
@author |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 10 |
Complexity Density: 0.62 |
|
| 63 |
|
public class EasyX509TrustManager implements X509TrustManager |
| 64 |
|
{ |
| 65 |
|
private X509TrustManager standardTrustManager = null; |
| 66 |
|
|
| 67 |
|
|
| 68 |
|
private static final Log LOG = LogFactory.getLog(EasyX509TrustManager.class); |
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 73 |
0
|
public EasyX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException {... |
| 74 |
0
|
super(); |
| 75 |
0
|
TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); |
| 76 |
0
|
factory.init(keystore); |
| 77 |
0
|
TrustManager[] trustmanagers = factory.getTrustManagers(); |
| 78 |
0
|
if (trustmanagers.length == 0) { |
| 79 |
0
|
throw new NoSuchAlgorithmException("no trust manager found"); |
| 80 |
|
} |
| 81 |
0
|
this.standardTrustManager = (X509TrustManager)trustmanagers[0]; |
| 82 |
|
} |
| 83 |
|
|
| 84 |
|
|
| 85 |
|
@see |
| 86 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 87 |
0
|
public void checkClientTrusted(X509Certificate[] certificates,String authType) throws CertificateException {... |
| 88 |
0
|
standardTrustManager.checkClientTrusted(certificates,authType); |
| 89 |
|
} |
| 90 |
|
|
| 91 |
|
|
| 92 |
|
@see |
| 93 |
|
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 6 |
Complexity Density: 0.86 |
|
| 94 |
0
|
public void checkServerTrusted(X509Certificate[] certificates,String authType) throws CertificateException {... |
| 95 |
0
|
if ((certificates != null) && LOG.isDebugEnabled()) { |
| 96 |
0
|
LOG.debug("Server certificate chain:"); |
| 97 |
0
|
for (int i = 0; i < certificates.length; i++) { |
| 98 |
0
|
LOG.debug("X509Certificate[" + i + "]=" + certificates[i]); |
| 99 |
|
} |
| 100 |
|
} |
| 101 |
0
|
if ((certificates != null) && (certificates.length == 1)) { |
| 102 |
0
|
certificates[0].checkValidity(); |
| 103 |
|
} else { |
| 104 |
0
|
standardTrustManager.checkServerTrusted(certificates,authType); |
| 105 |
|
} |
| 106 |
|
} |
| 107 |
|
|
| 108 |
|
|
| 109 |
|
@see |
| 110 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 111 |
0
|
public X509Certificate[] getAcceptedIssuers() {... |
| 112 |
0
|
return this.standardTrustManager.getAcceptedIssuers(); |
| 113 |
|
} |
| 114 |
|
} |