java reflect

static List<ConnectionSpec> GmTlsSpecs(){
final ConnectionSpec tls = ConnectionSpec.MODERN_TLS;
List<CipherSuite> cs = tls.cipherSuites();
List<TlsVersion> versions = tls.tlsVersions();
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")*/);
Constructor tc = TlsVersion.class.getDeclaredConstructors()[0];
tc.setAccessible(true);
TlsVersion ver = (TlsVersion)tc.newInstance("GMTLS");
versions = new ArrayList<>(versions);
versions.add(ver /*new TlsVersion("GMTLS")*/);
} catch (Exception e){
e.printStackTrace();
}
ConnectionSpec gmtls = (new ConnectionSpec.Builder(tls)).cipherSuites(cs.toArray(new CipherSuite[cs.size()])).
tlsVersions(versions.toArray(new TlsVersion[versions.size()])).build();
return Util.immutableList(new ConnectionSpec[]{gmtls, ConnectionSpec.CLEARTEXT});
}
posted @ 2020-12-28 14:49  zJanly  阅读(98)  评论(0编辑  收藏  举报