本文整理汇总了Java中javax.security.cert.CertificateException类的典型用法代码示例。如果您正苦于以下问题:Java CertificateException类的具体用法?Java CertificateException怎么用?Java CertificateException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CertificateException类属于javax.security.cert包,在下文中一共展示了CertificateException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: signRequest
import javax.security.cert.CertificateException; //导入依赖的package包/类
@Test
public void signRequest() throws JAXBException, ParserConfigurationException, CertificateException, KeyException, MarshalException, NoSuchAlgorithmException, SOAPException, XPathExpressionException, XMLSignatureException, InvalidAlgorithmParameterException, java.security.cert.CertificateException, NoSuchProviderException, KeyStoreException, IOException, UnrecoverableKeyException {
Serializable payload = createRequest();
SOAPMessage signedRequest = sign(
marshall(
payload,
getMarshaller(payload.getClass())
),
getClient()
);
System.out.println("============ SIGNED SOAP MESSAGE ================");
signedRequest.writeTo(System.out);
System.out.println("\n=================================================");
}
示例2: BasicSSLSessionInfo
import javax.security.cert.CertificateException; //导入依赖的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;
}
}
示例3: checkCertificates
import javax.security.cert.CertificateException; //导入依赖的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);
}
}
}
}
示例4: getPeerCertificateChain
import javax.security.cert.CertificateException; //导入依赖的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;
}
示例5: confirmRegister
import javax.security.cert.CertificateException; //导入依赖的package包/类
@GET
@Path("register/confirm/{validationKey}")
public Response confirmRegister(@PathParam("validationKey") String validationKey, @Context HttpServletRequest req) {
JsonResponse res = new JsonResponse();
try {
clusterController.validateRequest(validationKey, req, ClusterController.OP_TYPE.REGISTER);
} catch (IOException | InterruptedException | CertificateException ex) {
LOGGER.log(Level.SEVERE, null, ex);
res.setStatusCode(Response.Status.BAD_REQUEST.getStatusCode());
res.setSuccessMessage("Could not validate registration.");
return Response.ok().entity(res).build();
}
res.setStatusCode(Response.Status.OK.getStatusCode());
res.setSuccessMessage("Cluster registration validated.");
return Response.ok().entity(res).build();
}
示例6: confirmUnregister
import javax.security.cert.CertificateException; //导入依赖的package包/类
@GET
@Path("unregister/confirm/{validationKey}")
public Response confirmUnregister(@PathParam("validationKey") String validationKey, @Context HttpServletRequest req) {
JsonResponse res = new JsonResponse();
try {
clusterController.validateRequest(validationKey, req, ClusterController.OP_TYPE.UNREGISTER);
} catch (IOException | InterruptedException | CertificateException ex) {
LOGGER.log(Level.SEVERE, null, ex);
res.setStatusCode(Response.Status.BAD_REQUEST.getStatusCode());
res.setSuccessMessage("Could not validate unregistration.");
return Response.ok().entity(res).build();
}
res.setStatusCode(Response.Status.OK.getStatusCode());
res.setSuccessMessage("Cluster unregistration validated.");
return Response.ok().entity(res).build();
}
示例7: parse
import javax.security.cert.CertificateException; //导入依赖的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();
}
示例8: parseCertificate
import javax.security.cert.CertificateException; //导入依赖的package包/类
private void parseCertificate() throws IOException, CertificateException {
ZipEntry entry = null;
Enumeration<? extends ZipEntry> enu = zipFile.entries();
while (enu.hasMoreElements()) {
ZipEntry ne = enu.nextElement();
if (ne.isDirectory()) {
continue;
}
if (ne.getName().toUpperCase().endsWith(".RSA") ||
ne.getName().toUpperCase().endsWith(".DSA")) {
entry = ne;
break;
}
}
if (entry == null) {
throw new ParserException("ApkParser certificate not found");
}
InputStream in = zipFile.getInputStream(entry);
CertificateParser parser = new CertificateParser(in);
certificate = parser.parse();
in.close();
}
示例9: shouldFailWithInValidKeyAlias
import javax.security.cert.CertificateException; //导入依赖的package包/类
/**
* Scenario:
* - Select invalid key alias (no such key).
* - Negotiation will fail
* @throws CertificateException the certificate exception
* @throws IOException the IO exception
*/
@Test
public void shouldFailWithInValidKeyAlias() 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");
// No such key exists in the keystore
config.put(TLSOptions.TLS_KEYALIASES, "xxx");
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) {
Assert.assertTrue(result.isError());
}
});
connection.end();
}
示例10: encryptAssertion
import javax.security.cert.CertificateException; //导入依赖的package包/类
private EncryptedAssertion encryptAssertion(final Assertion assertion) throws KeyStoreException, NoSuchAlgorithmException, CertificateException,
IOException, SecurityException, EncryptionException, java.security.cert.CertificateException, NoSuchProviderException {
Credential keyEncryptionCredential = MockIDPSPMetadata.getSpCredentials();
EncryptionParameters encParams = new EncryptionParameters();
encParams.setAlgorithm(EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES128);
KeyEncryptionParameters kekParams = new KeyEncryptionParameters();
kekParams.setEncryptionCredential(keyEncryptionCredential);
kekParams.setAlgorithm(EncryptionConstants.ALGO_ID_KEYTRANSPORT_RSA15);
/*KeyInfoGeneratorFactory kigf = Configuration.getGlobalSecurityConfiguration().getKeyInfoGeneratorManager().getDefaultManager()
.getFactory(keyEncryptionCredential);
kekParams.setKeyInfoGenerator(kigf.newInstance());*/
Encrypter samlEncrypter = new Encrypter(encParams, kekParams);
samlEncrypter.setKeyPlacement(KeyPlacement.INLINE);
return samlEncrypter.encrypt(assertion);
}
示例11: getIDPKeyFromKeystore
import javax.security.cert.CertificateException; //导入依赖的package包/类
private X509Credential getIDPKeyFromKeystore() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, SecurityException,
java.security.cert.CertificateException {
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
InputStream inputStream = MockIDPArtifactResolve.class.getResourceAsStream("/keystore-idp.jks");
keystore.load(inputStream, "changeit".toCharArray());
inputStream.close();
Map<String, String> passwordMap = new HashMap<String, String>();
passwordMap.put("test", "changeit");
KeyStoreCredentialResolver resolver = new KeyStoreCredentialResolver(keystore, passwordMap);
Criteria criteria = new EntityIDCriteria("test");
CriteriaSet criteriaSet = new CriteriaSet(criteria);
return (X509Credential)resolver.resolveSingle(criteriaSet);
}
示例12: getSSLContext
import javax.security.cert.CertificateException; //导入依赖的package包/类
private static SSLContext getSSLContext(File truststoreFile, String truststorePass) throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException, UnrecoverableKeyException, KeyManagementException {
SSLContext ctx;
FileInputStream tsf = null;
ctx = null;
try {
try {
ctx = SSLContext.getInstance("SSL");
tsf = new FileInputStream(truststoreFile);
KeyStore ts = KeyStore.getInstance("JKS");
ts.load(tsf, truststorePass.toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ts);
ctx.init(null, tmf.getTrustManagers(), new SecureRandom());
}
catch (Exception e) {
logger.error("Problem encountered getting SSL Context " + e.getMessage(), e);
if (tsf != null) {
tsf.close();
}
}
}
finally {
if (tsf != null) {
tsf.close();
}
}
return ctx;
}
示例13: decodeX509CertificateChain
import javax.security.cert.CertificateException; //导入依赖的package包/类
static X509Certificate[] decodeX509CertificateChain(byte[][] certChain)
throws java.security.cert.CertificateException {
CertificateFactory certificateFactory = getCertificateFactory();
int numCerts = certChain.length;
X509Certificate[] decodedCerts = new X509Certificate[numCerts];
for (int i = 0; i < numCerts; i++) {
decodedCerts[i] = decodeX509Certificate(certificateFactory, certChain[i]);
}
return decodedCerts;
}
示例14: getCertificateFactory
import javax.security.cert.CertificateException; //导入依赖的package包/类
private static CertificateFactory getCertificateFactory() {
try {
return CertificateFactory.getInstance("X.509");
} catch (java.security.cert.CertificateException e) {
return null;
}
}
示例15: decodeX509Certificate
import javax.security.cert.CertificateException; //导入依赖的package包/类
private static X509Certificate decodeX509Certificate(CertificateFactory certificateFactory,
byte[] bytes) throws java.security.cert.CertificateException {
if (certificateFactory != null) {
return (X509Certificate) certificateFactory.generateCertificate(
new ByteArrayInputStream(bytes));
}
return OpenSSLX509Certificate.fromX509Der(bytes);
}