use of java.security.cert.CertificateException in project hadoop by apache.
the class AbstractJavaKeyStoreProvider method flush.
@Override
public void flush() throws IOException {
writeLock.lock();
try {
if (!changed) {
LOG.debug("Keystore hasn't changed, returning.");
return;
}
LOG.debug("Writing out keystore.");
try (OutputStream out = getOutputStreamForKeystore()) {
keyStore.store(out, password);
} catch (KeyStoreException e) {
throw new IOException("Can't store keystore " + this, e);
} catch (NoSuchAlgorithmException e) {
throw new IOException("No such algorithm storing keystore " + this, e);
} catch (CertificateException e) {
throw new IOException("Certificate exception storing keystore " + this, e);
}
changed = false;
} finally {
writeLock.unlock();
}
}
use of java.security.cert.CertificateException in project hbase by apache.
the class KeyStoreKeyProvider method load.
protected void load(URI uri) throws IOException {
String path = uri.getPath();
if (path == null || path.isEmpty()) {
throw new RuntimeException("KeyProvider parameters should specify a path");
}
InputStream is = new FileInputStream(new File(path));
try {
store.load(is, password);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (CertificateException e) {
throw new RuntimeException(e);
} finally {
is.close();
}
}
use of java.security.cert.CertificateException in project kafka by apache.
the class TestSslUtils method generateCertificate.
/**
* Create a self-signed X.509 Certificate.
* From http://bfo.com/blog/2011/03/08/odds_and_ends_creating_a_new_x_509_certificate.html.
*
* @param dn the X.509 Distinguished Name, eg "CN=Test, L=London, C=GB"
* @param pair the KeyPair
* @param days how many days from now the Certificate is valid for
* @param algorithm the signing algorithm, eg "SHA1withRSA"
* @return the self-signed certificate
* @throws CertificateException thrown if a security error or an IO error occurred.
*/
public static X509Certificate generateCertificate(String dn, KeyPair pair, int days, String algorithm) throws CertificateException {
try {
Security.addProvider(new BouncyCastleProvider());
AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find(algorithm);
AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);
AsymmetricKeyParameter privateKeyAsymKeyParam = PrivateKeyFactory.createKey(pair.getPrivate().getEncoded());
SubjectPublicKeyInfo subPubKeyInfo = SubjectPublicKeyInfo.getInstance(pair.getPublic().getEncoded());
ContentSigner sigGen = new BcRSAContentSignerBuilder(sigAlgId, digAlgId).build(privateKeyAsymKeyParam);
X500Name name = new X500Name(dn);
Date from = new Date();
Date to = new Date(from.getTime() + days * 86400000L);
BigInteger sn = new BigInteger(64, new SecureRandom());
X509v1CertificateBuilder v1CertGen = new X509v1CertificateBuilder(name, sn, from, to, name, subPubKeyInfo);
X509CertificateHolder certificateHolder = v1CertGen.build(sigGen);
return new JcaX509CertificateConverter().setProvider("BC").getCertificate(certificateHolder);
} catch (CertificateException ce) {
throw ce;
} catch (Exception e) {
throw new CertificateException(e);
}
}
use of java.security.cert.CertificateException in project cw-omnibus by commonsguy.
the class SignatureFragment method show.
void show(byte[] raw) {
CertificateFactory cf = null;
try {
cf = CertificateFactory.getInstance("X509");
} catch (CertificateException e) {
Log.e(getClass().getSimpleName(), "Exception getting CertificateFactory", e);
return;
}
X509Certificate c = null;
ByteArrayInputStream bin = new ByteArrayInputStream(raw);
try {
c = (X509Certificate) cf.generateCertificate(bin);
} catch (CertificateException e) {
Log.e(getClass().getSimpleName(), "Exception getting X509Certificate", e);
return;
}
TextView tv = (TextView) getView().findViewById(R.id.subject);
tv.setText(c.getSubjectDN().toString());
tv = (TextView) getView().findViewById(R.id.issuer);
tv.setText(c.getIssuerDN().toString());
tv = (TextView) getView().findViewById(R.id.valid);
tv.setText(fmt.format(c.getNotBefore()) + " to " + fmt.format(c.getNotAfter()));
}
use of java.security.cert.CertificateException in project AndroidNetworkDemo by dodocat.
the class RequestManager method newRequestQueue.
private RequestQueue newRequestQueue(Context context) {
RequestQueue requestQueue;
try {
String[] hosts = { "kyfw.12306.cn" };
int[] certRes = { R.raw.kyfw };
String[] certPass = { "asdfqaz" };
socketFactoryMap = new Hashtable<>(hosts.length);
for (int i = 0; i < certRes.length; i++) {
int res = certRes[i];
String password = certPass[i];
SSLSocketFactory sslSocketFactory = createSSLSocketFactory(context, res, password);
socketFactoryMap.put(hosts[i], sslSocketFactory);
}
HurlStack stack = new SelfSignSslOkHttpStack(socketFactoryMap);
requestQueue = Volley.newRequestQueue(context, stack);
requestQueue.start();
} catch (KeyStoreException | CertificateException | NoSuchAlgorithmException | KeyManagementException | IOException e) {
throw new RuntimeException(e);
}
return requestQueue;
}
Aggregations