当前位置: 首页>>代码示例>>Java>>正文


Java X509Certificate.getInstance方法代码示例

本文整理汇总了Java中javax.security.cert.X509Certificate.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java X509Certificate.getInstance方法的具体用法?Java X509Certificate.getInstance怎么用?Java X509Certificate.getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.security.cert.X509Certificate的用法示例。


在下文中一共展示了X509Certificate.getInstance方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: BasicSSLSessionInfo

import javax.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 *
 * @param sessionId The SSL session ID
 * @param cypherSuite The cypher suite name
 * @param certificate A string representation of the client certificate
 * @throws java.security.cert.CertificateException If the client cert could not be decoded
 * @throws CertificateException If the client cert could not be decoded
 */
public BasicSSLSessionInfo(byte[] sessionId, String cypherSuite, String certificate) throws java.security.cert.CertificateException, CertificateException {
    this.sessionId = sessionId;
    this.cypherSuite = cypherSuite;

    if (certificate != null) {
        java.security.cert.CertificateFactory cf = java.security.cert.CertificateFactory.getInstance("X.509");
        byte[] certificateBytes = certificate.getBytes(US_ASCII);
        ByteArrayInputStream stream = new ByteArrayInputStream(certificateBytes);
        peerCertificate = cf.generateCertificate(stream);
        this.certificate = X509Certificate.getInstance(certificateBytes);
    } else {
        this.peerCertificate = null;
        this.certificate = null;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:BasicSSLSessionInfo.java

示例2: testHandleSuccessRequestMutualAuthHeader

import javax.security.cert.X509Certificate; //导入方法依赖的package包/类
@Test(description = "Handle request with device type URI with Mutual Auth Header",
        dependsOnMethods = "testHandleSuccessRequestProxyMutualAuthHeader")
public void testHandleSuccessRequestMutualAuthHeader() throws Exception {
    HashMap<String, String> transportHeaders = new HashMap<>();
    transportHeaders.put(AuthConstants.MUTUAL_AUTH_HEADER, "Test Header");
    setMockClient();
    this.mockClient.setResponse(getAccessTokenReponse());
    this.mockClient.setResponse(getValidationResponse());
    MessageContext messageContext = createSynapseMessageContext("<empty/>", this.synapseConfiguration,
            transportHeaders, "https://test.com/testservice/api/testdevice");
    org.apache.axis2.context.MessageContext axisMC = ((Axis2MessageContext) messageContext).getAxis2MessageContext();
    String certStr = getContent(TestUtils.getAbsolutePathOfConfig("ra_cert.pem"));
    X509Certificate cert = X509Certificate.getInstance(new ByteArrayInputStream(certStr.
            getBytes(StandardCharsets.UTF_8.name())));
    axisMC.setProperty(AuthConstants.CLIENT_CERTIFICATE, new X509Certificate[]{cert});
    boolean response = this.handler.handleRequest(messageContext);
    Assert.assertTrue(response);
    this.mockClient.reset();
}
 
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:20,代码来源:AuthenticationHandlerTest.java

示例3: checkCertificates

import javax.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * Checks whether any active users' certificates are beyond the expiration threshold.
 */
@TransactionAttribute
public void checkCertificates() {

    List<UserAuthentication> auths = userAuthDao.findAll();

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, configuration.getCertificateCheckThreshold());
    Date cutoff = cal.getTime();

    for (UserAuthentication auth : auths) {
        if (auth.getActive() && auth.getCertificate() != null) {
            try {
                X509Certificate certificate = X509Certificate
                        .getInstance(Base64.decodeBase64(auth.getCertificate()));
                if (cutoff.after(certificate.getNotAfter())) {
                    notifyExpirationCheckFail(auth.getUser().getUsername());
                }
            } catch (CertificateException e) {
                logger.warn("Certificate could not be read", e);
            }
        }
    }
}
 
开发者ID:psnc-dl,项目名称:darceo,代码行数:27,代码来源:CertificateChecker.java

示例4: getPeerCertificateChain

import javax.security.cert.X509Certificate; //导入方法依赖的package包/类
@Override
public X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException {
    // these are lazy created to reduce memory overhead
    X509Certificate[] c = x509PeerCerts;
    if (c == null) {
        if (SSL.isInInit(ssl) != 0) {
            throw new SSLPeerUnverifiedException("peer not verified");
        }
        byte[][] chain = SSL.getPeerCertChain(ssl);
        if (chain == null) {
            throw new SSLPeerUnverifiedException("peer not verified");
        }
        X509Certificate[] peerCerts = new X509Certificate[chain.length];
        for (int i = 0; i < peerCerts.length; i++) {
            try {
                peerCerts[i] = X509Certificate.getInstance(chain[i]);
            } catch (CertificateException e) {
                throw new IllegalStateException(e);
            }
        }
        c = x509PeerCerts = peerCerts;
    }
    return c;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:25,代码来源:OpenSslEngine.java

示例5: parse

import javax.security.cert.X509Certificate; //导入方法依赖的package包/类
public CertificateMeta parse() throws IOException, CertificateException {
  X509Certificate certificate = X509Certificate.getInstance(Utils.toByteArray(in));
  CertificateMeta.Builder builder = CertificateMeta.newCertificateMeta();
  byte[] bytes = certificate.getEncoded();
  String certMd5 = md5Digest(bytes);
  String publicKeyString = byteToHexString(bytes);
  String certBase64Md5 = md5Digest(publicKeyString);
  builder.data(bytes);
  builder.certBase64Md5(certBase64Md5);
  builder.certMd5(certMd5);
  builder.startDate(certificate.getNotBefore());
  builder.endDate(certificate.getNotAfter());
  builder.signAlgorithm(certificate.getSigAlgName());
  builder.signAlgorithmOID(certificate.getSigAlgOID());
  return builder.build();
}
 
开发者ID:jaredrummler,项目名称:APKParser,代码行数:17,代码来源:CertificateParser.java

示例6: mySSLSession

import javax.security.cert.X509Certificate; //导入方法依赖的package包/类
public mySSLSession(Certificate[] xc) throws CertificateEncodingException, CertificateException {
    certs = xc;
    xCerts = new X509Certificate[xc.length];
    int i = 0;
    for (Certificate cert : xc) {
        xCerts[i++] = X509Certificate.getInstance(cert.getEncoded());
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:9,代码来源:mySSLSession.java

示例7: getPeerCertificateChain

import javax.security.cert.X509Certificate; //导入方法依赖的package包/类
@Override
public X509Certificate[] getPeerCertificateChain() {
	if (peerCertificates == null) {
		return null;
	}
	X509Certificate[] chain = new X509Certificate[peerCertificates.length];
	try {
		for (int i = 0; i < peerCertificates.length; i ++) {
			chain[i] = X509Certificate.getInstance(peerCertificates[i].getEncoded());
		}
	} catch (CertificateException | GeneralSecurityException e) {
		Log.w(e.getMessage());
	}
	return chain;
}
 
开发者ID:xqbase,项目名称:tuna,代码行数:16,代码来源:MuxSSLSession.java

示例8: CertInfo

import javax.security.cert.X509Certificate; //导入方法依赖的package包/类
public CertInfo(String certPath) {
    try {
        FileInputStream file = new FileInputStream(certPath);
        X509Certificate cert = X509Certificate.getInstance(file);
        this.certs = new X509Certificate[]{cert};
    } catch(FileNotFoundException|CertificateException e) {
        logger.error(e.getMessage(), e);
    }
}
 
开发者ID:GruppoFilippetti,项目名称:vertx-mqtt-broker,代码行数:10,代码来源:CertInfo.java

示例9: shouldSucceedWhenValidKeyAlias

import javax.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * Scenario:
 *   - Select client key alias `gateway2`.
 *   - Mutual trust exists between gateway and API
 *   - We must use the `gateway2` cert NOT `gateway`.
 * @throws CertificateException the certificate exception
 * @throws IOException the IO exception
 */
@Test
public void shouldSucceedWhenValidKeyAlias() throws CertificateException, IOException  {
    config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/basic_mutual_auth_2/gateway_ts.jks"));
    config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "password");
    config.put(TLSOptions.TLS_KEYSTORE, getResourcePath("2waytest/basic_mutual_auth_2/gateway_ks.jks"));
    config.put(TLSOptions.TLS_KEYSTOREPASSWORD, "password");
    config.put(TLSOptions.TLS_KEYPASSWORD, "password");
    config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
    config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "false");

    config.put(TLSOptions.TLS_KEYALIASES, "gateway2");

    InputStream inStream = new FileInputStream(getResourcePath("2waytest/basic_mutual_auth_2/gateway2.cer"));
    final X509Certificate expectedCert = X509Certificate.getInstance(inStream);
    inStream.close();

    HttpConnectorFactory factory = new HttpConnectorFactory(config);
    IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.MTLS, false);
    IApiConnection connection = connector.connect(request,
            new IAsyncResultHandler<IApiConnectionResponse>() {

                @Override
                public void handle(IAsyncResult<IApiConnectionResponse> result) {
                    if (result.isError())
                        throw new RuntimeException(result.getError());

                    Assert.assertTrue(result.isSuccess());
                    // Assert that the expected certificate (associated with the private key by virtue)
                    // was the one used.
                    Assert.assertEquals(expectedCert.getSerialNumber(), clientSerial);
                }
            });

    connection.end();
}
 
开发者ID:apiman,项目名称:apiman,代码行数:44,代码来源:BasicMutualAuthTest.java

示例10: shouldFallbackWhenMultipleAliasesAvailable

import javax.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * Scenario:
 *   - First alias invalid, second valid.
 *   - Mutual trust exists between gateway and API.
 *   - We must fall back to the valid alias.
 * @throws CertificateException the certificate exception
 * @throws IOException the IO exception
 */
@Test
public void shouldFallbackWhenMultipleAliasesAvailable() throws CertificateException, IOException  {
    config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/basic_mutual_auth_2/gateway_ts.jks"));
    config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "password");
    config.put(TLSOptions.TLS_KEYSTORE, getResourcePath("2waytest/basic_mutual_auth_2/gateway_ks.jks"));
    config.put(TLSOptions.TLS_KEYSTOREPASSWORD, "password");
    config.put(TLSOptions.TLS_KEYPASSWORD, "password");
    config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
    config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "false");
    // Only gateway2 is valid. `unrelated` is real but not trusted by API. others don't exist.
    config.put(TLSOptions.TLS_KEYALIASES, "unrelated, owt, or, nowt, gateway2, sonorous, unrelated");

    InputStream inStream = new FileInputStream(getResourcePath("2waytest/basic_mutual_auth_2/gateway2.cer"));
    final X509Certificate expectedCert = X509Certificate.getInstance(inStream);
    inStream.close();

    HttpConnectorFactory factory = new HttpConnectorFactory(config);
    IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.MTLS, false);
    IApiConnection connection = connector.connect(request,
            new IAsyncResultHandler<IApiConnectionResponse>() {

                @Override
                public void handle(IAsyncResult<IApiConnectionResponse> result) {
                    if (result.isError())
                        throw new RuntimeException(result.getError());

                    Assert.assertTrue(result.isSuccess());
                    // Assert that the expected certificate (associated with the private key by virtue)
                    // was the one used.
                    Assert.assertEquals(expectedCert.getSerialNumber(), clientSerial);
                }
            });

    connection.end();
}
 
开发者ID:apiman,项目名称:apiman,代码行数:44,代码来源:BasicMutualAuthTest.java

示例11: getCertificate

import javax.security.cert.X509Certificate; //导入方法依赖的package包/类
private X509Certificate getCertificate(Client client) throws CertificateException, KeyStoreException, NoSuchProviderException, java.security.cert.CertificateException, NoSuchAlgorithmException, IOException {
	KeyStore keyStore = KeyStore.getInstance("pkcs12", "SunJSSE");
	keyStore.load(getClass().getResourceAsStream(client.path), client.password);

	return X509Certificate.getInstance(keyStore.getCertificate(keyStore.aliases().nextElement()).getEncoded());
}
 
开发者ID:AlnaSoftware,项目名称:eSaskaita,代码行数:7,代码来源:AbstractSignatureHelper.java

示例12: generateCertificate

import javax.security.cert.X509Certificate; //导入方法依赖的package包/类
private X509Certificate generateCertificate(String cert) throws CertificateException {
    return X509Certificate.getInstance(cert.getBytes(StandardCharsets.US_ASCII));
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:4,代码来源:SaslDelegatingLoginTest.java


注:本文中的javax.security.cert.X509Certificate.getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。