當前位置: 首頁>>代碼示例>>Java>>正文


Java X509KeyManager.getCertificateChain方法代碼示例

本文整理匯總了Java中javax.net.ssl.X509KeyManager.getCertificateChain方法的典型用法代碼示例。如果您正苦於以下問題:Java X509KeyManager.getCertificateChain方法的具體用法?Java X509KeyManager.getCertificateChain怎麽用?Java X509KeyManager.getCertificateChain使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.net.ssl.X509KeyManager的用法示例。


在下文中一共展示了X509KeyManager.getCertificateChain方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: test_X509KeyManager_alias

import javax.net.ssl.X509KeyManager; //導入方法依賴的package包/類
private void test_X509KeyManager_alias(X509KeyManager km, String alias, String keyType) {
    if (alias == null) {
        assertNull(km.getCertificateChain(alias));
        assertNull(km.getPrivateKey(alias));
        return;
    }

    X509Certificate[] certificateChain = km.getCertificateChain(alias);
    PrivateKey privateKey = km.getPrivateKey(alias);

    if (keyType == null) {
        keyType = privateKey.getAlgorithm();
    } else {
        assertEquals(keyType, certificateChain[0].getPublicKey().getAlgorithm());
        assertEquals(keyType, privateKey.getAlgorithm());
    }

    PrivateKeyEntry privateKeyEntry
            = TestKeyStore.privateKey(TEST_KEY_STORE.keyStore,
                                      TEST_KEY_STORE.storePassword,
                                      keyType);
    assertEquals(Arrays.asList(privateKeyEntry.getCertificateChain()),
                 Arrays.asList(certificateChain));
    assertEquals(privateKeyEntry.getPrivateKey(), privateKey);
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:26,代碼來源:KeyManagerFactoryTest.java

示例2: createSingleKeyManager

import javax.net.ssl.X509KeyManager; //導入方法依賴的package包/類
/** 
 * Create a key manager which manages one single key.  
 */ 
private KeyManager createSingleKeyManager(KeyStore keyStore,String alias,Secret privKeyPasswd) throws Exception
{
    KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");

    keyManagerFactory.init(keyStore, privKeyPasswd.getChars());
    X509KeyManager managerImpl = (X509KeyManager)keyManagerFactory.getKeyManagers()[0];
    X509Certificate[] chain = managerImpl.getCertificateChain(alias); 

    // === //
    
    PrivateKey privKey ;
    privKey=(PrivateKey)keyStore.getKey(alias,privKeyPasswd.getChars());
    
    PrivateX509KeyManager manager=new PrivateX509KeyManager(chain,privKey); 
   
    for (X509Certificate cert:chain)
    {
        logger.debugPrintf("--- my cert chain ---\n"); 
        logger.debugPrintf(" - subject %s\n",cert.getSubjectDN()); 
    }

    return manager;
}
 
開發者ID:NLeSC,項目名稱:vbrowser,代碼行數:27,代碼來源:SSLContextManager.java

示例3: getCertificateChain

import javax.net.ssl.X509KeyManager; //導入方法依賴的package包/類
@Override
public X509Certificate[] getCertificateChain(final String alias) {
    for (final X509KeyManager keyManager : keyManagers) {
        final X509Certificate[] chain = keyManager.getCertificateChain(alias);
        if (chain != null && chain.length > 0) {
            return chain;
        }
    }
    return null;
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:11,代碼來源:FileTrustStoreSslSocketFactory.java

示例4: setCertificate

import javax.net.ssl.X509KeyManager; //導入方法依賴的package包/類
void setCertificate(String alias) throws CertificateEncodingException, SSLException {
    if (alias == null) {
        return;
    }
    X509KeyManager keyManager = parameters.getX509KeyManager();
    if (keyManager == null) {
        return;
    }
    PrivateKey privateKey = keyManager.getPrivateKey(alias);
    if (privateKey == null) {
        return;
    }
    localCertificates = keyManager.getCertificateChain(alias);
    if (localCertificates == null) {
        return;
    }
    int numLocalCerts = localCertificates.length;
    PublicKey publicKey = (numLocalCerts > 0) ? localCertificates[0].getPublicKey() : null;

    // Encode the local certificates.
    byte[][] encodedLocalCerts = new byte[numLocalCerts][];
    for (int i = 0; i < numLocalCerts; ++i) {
        encodedLocalCerts[i] = localCertificates[i].getEncoded();
    }

    // Convert the key so we can access a native reference.
    final OpenSSLKey key;
    try {
        key = OpenSSLKey.fromPrivateKeyForTLSStackOnly(privateKey, publicKey);
    } catch (InvalidKeyException e) {
        throw new SSLException(e);
    }

    // Set the local certs and private key.
    NativeCrypto.setLocalCertsAndPrivateKey(ssl, encodedLocalCerts, key.getNativeRef());
}
 
開發者ID:google,項目名稱:conscrypt,代碼行數:37,代碼來源:NativeSsl.java

示例5: test_X509KeyManager_alias

import javax.net.ssl.X509KeyManager; //導入方法依賴的package包/類
private void test_X509KeyManager_alias(X509KeyManager km, String alias, String keyType,
        boolean many, boolean empty) throws Exception {
    if (empty || (!many && (keyType == null || keyType.isEmpty()))) {
        assertNull(keyType, alias);
        assertNull(keyType, km.getCertificateChain(alias));
        assertNull(keyType, km.getPrivateKey(alias));
        return;
    }
    assertNotNull(keyType, alias);

    X509Certificate[] certificateChain = km.getCertificateChain(alias);
    PrivateKey privateKey = km.getPrivateKey(alias);

    String keyAlgName = privateKey.getAlgorithm();

    X509Certificate certificate = certificateChain[0];
    assertEquals(keyType, keyAlgName, certificate.getPublicKey().getAlgorithm());

    String sigAlgName = certificate.getSigAlgName();

    PrivateKeyEntry privateKeyEntry = getTestKeyStore().getPrivateKey(keyAlgName, sigAlgName);

    assertEquals(keyType, Arrays.asList(privateKeyEntry.getCertificateChain()),
            Arrays.<Certificate>asList(certificateChain));
    assertEquals(keyType, privateKeyEntry.getPrivateKey(), privateKey);

    if (keyType != null) {
        assertEquals(TestKeyStore.keyAlgorithm(keyType), keyAlgName);

        // Skip this when we're given only "DH" or "EC" instead of "DH_DSA",
        // "EC_RSA", etc. since we don't know what the expected
        // algorithm was.
        if (!keyType.equals("DH") && !keyType.equals("EC")) {
            assertTrue(sigAlgName.contains(TestKeyStore.signatureAlgorithm(keyType)));
        }
    }
}
 
開發者ID:google,項目名稱:conscrypt,代碼行數:38,代碼來源:KeyManagerFactoryTest.java

示例6: getCertificateChain

import javax.net.ssl.X509KeyManager; //導入方法依賴的package包/類
public synchronized X509Certificate[] getCertificateChain(String alias) {
    String[] parts = alias.split(SEP, 2);
    String description = parts[0];
    alias = parts[1];
    X509KeyManager km = (X509KeyManager) _managers.get(description);
    return km.getCertificateChain(alias);
}
 
開發者ID:Neraud,項目名稱:PADListener,代碼行數:8,代碼來源:SSLKeyManager.java

示例7: getCertificateChain

import javax.net.ssl.X509KeyManager; //導入方法依賴的package包/類
/**
 * Returns the first non-null certificate chain associated with the given alias, or {@code null}
 * if the alias can't be found.
 */
@Override
public @Nullable X509Certificate[] getCertificateChain(String alias){
	for (List<X509KeyManager> keyManagers : keyManagers.values()) {
		for (X509KeyManager x509KeyManager : keyManagers) {
			X509Certificate[] chain = x509KeyManager.getCertificateChain(alias);
			if (chain != null && chain.length > 0) {
				return chain;
			}
		}
	}
	return null;
}
 
開發者ID:elexis,項目名稱:elexis-3-core,代碼行數:17,代碼來源:CompositeX509KeyManager.java


注:本文中的javax.net.ssl.X509KeyManager.getCertificateChain方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。