本文整理汇总了Java中com.squareup.okhttp.TlsVersion类的典型用法代码示例。如果您正苦于以下问题:Java TlsVersion类的具体用法?Java TlsVersion怎么用?Java TlsVersion使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TlsVersion类属于com.squareup.okhttp包,在下文中一共展示了TlsVersion类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enforceTls12
import com.squareup.okhttp.TlsVersion; //导入依赖的package包/类
/**
* Enable TLS 1.2 on the OkHttpClient on API 16-21, which is supported but not enabled by default.
* @link https://github.com/square/okhttp/issues/2372
* @see TLS12SocketFactory
*/
private void enforceTls12(OkHttpClient client) {
// No need to modify client as TLS 1.2 is enabled by default on API21+
// Lollipop is included because some Samsung devices face the same problem on API 21.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN
|| Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
return;
}
try {
SSLContext sc = SSLContext.getInstance("TLSv1.2");
sc.init(null, null, null);
client.setSslSocketFactory(new TLS12SocketFactory(sc.getSocketFactory()));
ConnectionSpec cs = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.tlsVersions(TlsVersion.TLS_1_2)
.build();
List<ConnectionSpec> specs = new ArrayList<>();
specs.add(cs);
specs.add(ConnectionSpec.COMPATIBLE_TLS);
specs.add(ConnectionSpec.CLEARTEXT);
client.setConnectionSpecs(specs);
} catch (NoSuchAlgorithmException | KeyManagementException e) {
Log.e(TAG, "Error while setting TLS 1.2", e);
}
}
示例2: verifyTLS12Enforced
import com.squareup.okhttp.TlsVersion; //导入依赖的package包/类
private static void verifyTLS12Enforced(OkHttpClient client) {
ArgumentCaptor<SSLSocketFactory> factoryCaptor = ArgumentCaptor.forClass(SSLSocketFactory.class);
verify(client).setSslSocketFactory(factoryCaptor.capture());
assertTrue(factoryCaptor.getValue() instanceof TLS12SocketFactory);
ArgumentCaptor<List> specCaptor = ArgumentCaptor.forClass(List.class);
verify(client).setConnectionSpecs(specCaptor.capture());
boolean hasTls12 = false;
for (Object item : specCaptor.getValue()) {
assertTrue(item instanceof ConnectionSpec);
ConnectionSpec spec = (ConnectionSpec) item;
if (!spec.isTls()) {
continue;
}
List<TlsVersion> versions = spec.tlsVersions();
for (TlsVersion version : versions) {
if ("TLSv1.2".equals(version.javaName())) {
hasTls12 = true;
break;
}
}
}
assertTrue(hasTls12);
}
示例3: createChannelBuilder
import com.squareup.okhttp.TlsVersion; //导入依赖的package包/类
private OkHttpChannelBuilder createChannelBuilder() {
OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("localhost", getPort())
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
.connectionSpec(new ConnectionSpec.Builder(OkHttpChannelBuilder.DEFAULT_CONNECTION_SPEC)
.cipherSuites(TestUtils.preferredTestCiphers().toArray(new String[0]))
.tlsVersions(ConnectionSpec.MODERN_TLS.tlsVersions().toArray(new TlsVersion[0]))
.build())
.overrideAuthority(GrpcUtil.authorityFromHostAndPort(
TestUtils.TEST_SERVER_HOST, getPort()));
io.grpc.internal.TestingAccessor.setStatsImplementation(
builder, createClientCensusStatsModule());
try {
builder.sslSocketFactory(TestUtils.newSslSocketFactoryForCa(Platform.get().getProvider(),
TestUtils.loadCert("ca.pem")));
} catch (Exception e) {
throw new RuntimeException(e);
}
return builder;
}