本文整理汇总了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());
}