本文整理匯總了Java中javax.net.ssl.X509TrustManager.getAcceptedIssuers方法的典型用法代碼示例。如果您正苦於以下問題:Java X509TrustManager.getAcceptedIssuers方法的具體用法?Java X509TrustManager.getAcceptedIssuers怎麽用?Java X509TrustManager.getAcceptedIssuers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.net.ssl.X509TrustManager
的用法示例。
在下文中一共展示了X509TrustManager.getAcceptedIssuers方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: create
import javax.net.ssl.X509TrustManager; //導入方法依賴的package包/類
private void create(Path path)
throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException,
KeyManagementException {
TrustManager[] trustManagers;
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null, null);
installCertificates(path, keyStore);
String defaultAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(defaultAlgorithm);
trustManagerFactory.init(keyStore);
trustManagers = trustManagerFactory.getTrustManagers();
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagers, null);
trustManager = (X509TrustManager) trustManagers[0];
X509Certificate[] acceptedIssuers = trustManager.getAcceptedIssuers();
for (X509Certificate acceptedIssuer : acceptedIssuers) {
logger.info("installed cert details: subject={} issuer={}",
acceptedIssuer.getSubjectX500Principal(), acceptedIssuer.getIssuerX500Principal());
}
}
示例2: X509TrustManagerWrapper
import javax.net.ssl.X509TrustManager; //導入方法依賴的package包/類
public X509TrustManagerWrapper(X509TrustManager tm, boolean verifyServerCertificate) throws CertificateException {
this.origTm = tm;
this.verifyServerCert = verifyServerCertificate;
if (verifyServerCertificate) {
try {
Set<TrustAnchor> anch = new HashSet<TrustAnchor>();
for (X509Certificate cert : tm.getAcceptedIssuers()) {
anch.add(new TrustAnchor(cert, null));
}
this.validatorParams = new PKIXParameters(anch);
this.validatorParams.setRevocationEnabled(false);
this.validator = CertPathValidator.getInstance("PKIX");
this.certFactory = CertificateFactory.getInstance("X.509");
} catch (Exception e) {
throw new CertificateException(e);
}
}
}
示例3: dumpTrustedCerts
import javax.net.ssl.X509TrustManager; //導入方法依賴的package包/類
public void dumpTrustedCerts() {
try {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory
.getDefaultAlgorithm());
tmf.init((KeyStore) null);
X509TrustManager xtm = (X509TrustManager) tmf.getTrustManagers()[0];
StringBuffer buff = new StringBuffer();
for (X509Certificate cert : xtm.getAcceptedIssuers()) {
String certStr = "S:" + cert.getSubjectDN().getName() + "\nI:"
+ cert.getIssuerDN().getName();
Log.d(TAG, certStr);
buff.append(certStr + "\n\n");
}
} catch (GeneralSecurityException e) {
throw new RuntimeException(e);
}
}
示例4: KeyStoresTrustManager
import javax.net.ssl.X509TrustManager; //導入方法依賴的package包/類
public KeyStoresTrustManager(KeyStore... keyStores) throws NoSuchAlgorithmException, KeyStoreException {
super();
for (KeyStore keystore : keyStores) {
TrustManagerFactory factory = TrustManagerFactory.getInstance("JKS");
factory.init(keystore);
TrustManager[] tms = factory.getTrustManagers();
if (tms.length == 0) {
throw new NoSuchAlgorithmException("Unable to load keystore");
}
trustManagers.add((X509TrustManager) tms[0]);
}
//Build accepted issuers list
Set<X509Certificate> issuers = new HashSet<X509Certificate>();
for (X509TrustManager tm : trustManagers) {
for (X509Certificate issuer : tm.getAcceptedIssuers()) {
issuers.add(issuer);
}
}
acceptedIssuers = issuers.toArray(new X509Certificate[issuers.size()]);
}
示例5: getAcceptedIssuers
import javax.net.ssl.X509TrustManager; //導入方法依賴的package包/類
@Override
public X509Certificate[] getAcceptedIssuers() {
X509Certificate[] issuers = EMPTY;
X509TrustManager tm = trustManagerRef.get();
if (tm != null) {
issuers = tm.getAcceptedIssuers();
}
return issuers;
}
示例6: createSome
import javax.net.ssl.X509TrustManager; //導入方法依賴的package包/類
@Test
public void createSome() throws IOException {
CertificateLoader securitySupport =
new CertificateLoader("classpath:certs");
X509TrustManager x509TrustManager = securitySupport.trustManager();
SSLContext sslContext = securitySupport.sslContext();
assertNotNull(x509TrustManager);
assertNotNull(sslContext);
X509Certificate[] acceptedIssuers = x509TrustManager.getAcceptedIssuers();
assertEquals(3, acceptedIssuers.length);
String issuer1 = "CN=Let's Encrypt Authority X1, O=Let's Encrypt, C=US";
String issuer2 = "CN=Let's Encrypt Authority X2, O=Let's Encrypt, C=US";
String issuer3 = "CN=Let's Encrypt Authority X3, O=Let's Encrypt, C=US";
Set<String> seen = Sets.newHashSet();
for (X509Certificate acceptedIssuer : acceptedIssuers) {
String name = acceptedIssuer.getSubjectDN().getName();
System.out.println(name);
if (issuer1.equals(name)) {
seen.add(name);
}
if (issuer2.equals(name)) {
seen.add(name);
}
if (issuer3.equals(name)) {
seen.add(name);
}
}
assertEquals(3, seen.size());
assertTrue(seen.contains(issuer1));
assertTrue(seen.contains(issuer2));
assertTrue(seen.contains(issuer3));
}
示例7: createNone
import javax.net.ssl.X509TrustManager; //導入方法依賴的package包/類
@Test
public void createNone() throws IOException {
String fPath = "file://" + folder.newFolder().getAbsolutePath();
CertificateLoader securitySupport = new CertificateLoader(fPath);
X509TrustManager x509TrustManager = securitySupport.trustManager();
SSLContext sslContext = securitySupport.sslContext();
assertNotNull(x509TrustManager);
assertNotNull(sslContext);
X509Certificate[] acceptedIssuers = x509TrustManager.getAcceptedIssuers();
assertEquals(0, acceptedIssuers.length);
}
示例8: buildTrustRootIndex
import javax.net.ssl.X509TrustManager; //導入方法依賴的package包/類
public TrustRootIndex buildTrustRootIndex(X509TrustManager trustManager) {
return new BasicTrustRootIndex(trustManager.getAcceptedIssuers());
}
示例9: trustRootIndex
import javax.net.ssl.X509TrustManager; //導入方法依賴的package包/類
public TrustRootIndex trustRootIndex(X509TrustManager trustManager) {
return new RealTrustRootIndex(trustManager.getAcceptedIssuers());
}