bc
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null);
int index = 0;
for (InputStream certificate : certificates) {
String certificateAlias = Integer.toString(index++);
keyStore.setCertificateEntry(certificateAlias, certificateFactory.generateCertificate(certificate));
try {
if (certificate != null) {
certificate.close();
}
} catch (IOException e) {
logger.error(e);
}
}
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
return trustManagerFactory.getTrustManagers();
PEMParser(new BufferedReader(new InputStreamReader(res)))
while (true){
Object object = pemRd.readObject();
if (object == null){
break;
}
if (object instanceof PEMKeyPair){
priv.add(((PEMKeyPair)object).getPrivateKeyInfo());
} else if (object instanceof PrivateKeyInfo){
priv.add((PrivateKeyInfo)object);
}
}
PrivateKey priv = new JcaPEMKeyConverter().getPrivateKey(pemPair[i]);
//DEK-Info
PEMParser pemParser = new PEMParser(pemReader);
Object object = pemParser.readObject();
if (object instanceof PEMEncryptedKeyPair) {
PEMEncryptedKeyPair pemEncryptedKeyPair = (PEMEncryptedKeyPair) object;
PEMDecryptorProvider decProv = (new JcePEMDecryptorProviderBuilder())
.build(this.password.toCharArray());
PEMKeyPair pemkp = pemEncryptedKeyPair.decryptKeyPair(decProv);
KeyPair kp =
new JcaPEMKeyConverter().getKeyPair(pemkp);
return kp.getPrivate();
}
static {
final ConnectionSpec tls = ConnectionSpec.COMPATIBLE_TLS;
List<CipherSuite> cs = tls.cipherSuites();
List<TlsVersion> versions = tls.tlsVersions();
TlsVersion[] vers = new TlsVersion[versions.size() + 1];
try {
Constructor[] ccs = CipherSuite.class.getConstructors();
Constructor cc = CipherSuite.class.getDeclaredConstructors()[0];
cc.setAccessible(true);
CipherSuite suite = (CipherSuite)cc.newInstance("TLS_ECC_SM4_SM3");
cs = new ArrayList<>(cs);
cs.add(suite /*new CipherSuite("TLS_ECC_SM4_SM3")*/);
versions.toArray(vers);
vers[vers.length - 1] = TlsVersion.GMTLS;
} catch (Exception e){
e.printStackTrace();
}
ConnectionSpec gmtls = (new ConnectionSpec.Builder(tls)).cipherSuites(cs.toArray(new CipherSuite[cs.size()])).
tlsVersions(vers).build();
GmTlsSpecs = Util.immutableList(new ConnectionSpec[]{gmtls, ConnectionSpec.CLEARTEXT});
}