thinh
thinh

Reputation: 1

how to use TLSv1.2 in java

I have a java chat app using TLS, but when I use Wireshark to capture data the protocol column display value "TCP", why does it not show as "TLS". What's happen with my code?

CertificateFactory cf = CertificateFactory.getInstance("X509");
X509Certificate cert = (X509Certificate) cf.generateCertificate(
    this.getClass().getResourceAsStream("/"+"lib/ca.crt")
);

InputStream is=this.getClass().getResourceAsStream("/"+"lib/plainclient.jks");
KeyStore clientKeys = KeyStore.getInstance("JKS");
clientKeys.load(is,"xuanthinh".toCharArray());
KeyManagerFactory clientKeyManager = KeyManagerFactory.getInstance("SunX509");
clientKeyManager.init(clientKeys,"xuanthinh".toCharArray());

KeyStore ks = KeyStore.getInstance("JKS");
is=this.getClass().getResourceAsStream("/"+"lib/serverpub.jks");
ks.load(is,"xuanthinh".toCharArray());
TrustManagerFactory trustManager = TrustManagerFactory.getInstance("SunX509");
trustManager.init(ks);
//use keys to create SSLSoket
ssl = SSLContext.getInstance("TLS");
ssl.init(
    clientKeyManager.getKeyManagers(), trustManager.getTrustManagers(), 
    SecureRandom.getInstance("SHA1PRNG")
);

Upvotes: 0

Views: 1040

Answers (2)

mkwyche
mkwyche

Reputation: 193

Not sure what client you're using from the snippet. But doing this with Jersey/CXF i usually just set the http.protocols value. This link has some helpful information: https://superuser.com/questions/747377/enable-tls-1-1-and-1-2-for-clients-on-java-7

Upvotes: 0

henrycarteruk
henrycarteruk

Reputation: 13227

They are different protocols, and both are used when transferring encrypted content.

Have a read on the OSI Model for network protocols as this explains where each protocol sits relative to each other.

TCP is part of the Layer 4 (Transport Layer), whilst TLS is part of Layer 6 (Presentation Layer).

Upvotes: 2

Related Questions