Skip to content

Commit 00bc4c0

Browse files
gcondraAndroid (Google) Code Review
authored andcommitted
Merge "Initial commit for X509TrustManagerExtensions." into jb-mr1-dev
2 parents 465d720 + ed41a4e commit 00bc4c0

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

api/current.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13024,6 +13024,11 @@ package android.net.http {
1302413024
field public static final int SSL_UNTRUSTED = 3; // 0x3
1302513025
}
1302613026

13027+
public class X509TrustManagerExtensions {
13028+
ctor public X509TrustManagerExtensions(javax.net.ssl.X509TrustManager) throws java.lang.IllegalArgumentException;
13029+
method public java.util.List<java.security.cert.X509Certificate> checkServerTrusted(java.security.cert.X509Certificate[], java.lang.String, java.lang.String) throws java.security.cert.CertificateException;
13030+
}
13031+
1302713032
}
1302813033

1302913034
package android.net.nsd {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (C) 2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.net.http;
18+
19+
import java.security.cert.CertificateException;
20+
import java.security.cert.X509Certificate;
21+
import java.security.KeyManagementException;
22+
import java.util.List;
23+
24+
import javax.net.ssl.X509TrustManager;
25+
26+
import org.apache.harmony.xnet.provider.jsse.TrustManagerImpl;
27+
28+
/**
29+
* X509TrustManager wrapper exposing Android-added features.
30+
*
31+
* <p> The checkServerTrusted method allows callers to perform additional
32+
* verification of certificate chains after they have been successfully
33+
* verified by the platform.</p>
34+
*/
35+
public class X509TrustManagerExtensions {
36+
37+
TrustManagerImpl mDelegate;
38+
39+
/**
40+
* Constructs a new X509TrustManagerExtensions wrapper.
41+
*
42+
* @param tm A {@link X509TrustManager} as returned by TrustManagerFactory.getInstance();
43+
* @throws IllegalArgumentException If tm is an unsupported TrustManager type.
44+
*/
45+
public X509TrustManagerExtensions(X509TrustManager tm) throws IllegalArgumentException {
46+
if (mDelegate instanceof TrustManagerImpl) {
47+
mDelegate = (TrustManagerImpl) tm;
48+
} else {
49+
throw new IllegalArgumentException("tm is not a supported type of X509TrustManager");
50+
}
51+
}
52+
53+
/**
54+
* Verifies the given certificate chain.
55+
*
56+
* <p>See {@link X509TrustManager#checkServerTrusted(X509Certificate[], String)} for a
57+
* description of the chain and authType parameters. The final parameter, host, should be the
58+
* hostname of the server.</p>
59+
*
60+
* @throws CertificateException if the chain does not verify correctly.
61+
* @return the properly ordered chain used for verification as a list of X509Certificates.
62+
*/
63+
public List<X509Certificate> checkServerTrusted(X509Certificate[] chain, String authType,
64+
String host) throws CertificateException {
65+
return mDelegate.checkServerTrusted(chain, authType, host);
66+
}
67+
}

0 commit comments

Comments
 (0)