Monday, August 13, 2018

Debug SSL Handshaking ot Debug HTTPS webservice call

Good Document on oracle site

*I am sharing this link for just knowledge sharing purpose,Oracle owns all data provided on this link.

http://docs.oracle.com/javase/7/docs/technotes/guides/security/jsse/ReadDebug.html

Add below argument in your server launch configuration or java application while running application
-Djavax.net.debug=all

On start up it will first check keystore and truststore present on your machine ot you are giving to programme in argument
Note:You can setup these parameters using below method
java -Djavax.net.ssl.keyStore=serverKeys
-Djavax.net.ssl.keyStorePassword=password
-Djavax.net.ssl.trustStore=serverTrust
-Djavax.net.ssl.trustStorePassword=password

or
System.setProperty("javax.net.ssl.keyStore","serverKeys")

It will show you below output
keyStore is : C:\Program Files\Java\jdk1.7.0_03\jre\lib\security\key12_tcvm.jks
keyStore type is : jks
keyStore provider is :
init keystore
init keymanager of type SunX509
***
found key for :abcclient
chain [0] = [
[
Version: V3
Subject: CN=ABCD, OU=CIO, O=ABCD Firm PLC, C=AB
Signature Algorithm: SHA1withRSA, OID = 1.2.840.113549.1.1.5

Key: Sun RSA public key, 1024 bits
modulus: 1306071364996419254586849286965299189
public exponent: 65537
Validity: [From: Tue Jan 17 23:17:12 IST 2012,
To: Sat Aug 26 23:17:12 IST 2017]
Issuer: CN=WEBROOT CA (2016), OU=WEBROOT CA (2016), O=ABCD Firm PLC
SerialNumber: [ f8dc3b4d 6aeaef41 37609aef a0800884]

Certificate Extensions: 6
[1]: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: 4A 3E C4 CF 17 67 FB B3 BA 11 29 79 90 46 B7 3B J>...g....)y.F.;
0010: E9 61 1F 5C .a.\
]
]
***
trustStore is: C:\Program Files\Java\jdk1.7.0_03\jre\lib\security\cacerts
trustStore type is : jks
trustStore provider is :
init truststore
adding as trusted cert:
Subject: CN=XYZ - G2, O=SwissSign AG, C=CH
Issuer: CN=XYZ - G2, O=SwissSign AG, C=CH
Algorithm: RSA; Serial number: 0x4eb200670c035d4f
Valid from Wed Oct 25 14:06:00 IST 2006 until Sat Oct 25 14:06:00 IST 2036

adding as trusted cert:
Subject: EMAILADDRESS=info@mysite.com, CN=http://www.mysite.com/, OU=mysite Class 1 Policy Validation Authority, O="mysite, Inc.", L=mysite Validation Network
Issuer: EMAILADDRESS=info@mysite.com, CN=http://www.mysite.com/, OU=mysite Class 1 Policy Validation Authority, O="mysite, Inc.", L=mysite Validation Network
Algorithm: RSA; Serial number: 0x1
Valid from Sat Jun 26 03:53:48 IST 1999 until Wed Jun 26 03:53:48 IST 2019

The following steps are how a SSL handshake is performed. The messages that compose
this handshake are: ClientHello, ServerHello, ServerKeyExchange, ServerHelloDone,
ClientKeyExchange, ChangeCipherSpec, Finished, ChangeCipherSpec, Finished.

Now our SSL communication will start with below message and will get this in log

1)Client Hello
The first message is the ClientHello. Since the client machine is requesting the
secure communication session, this message involves a set of options that the client is
willing to use in order to communicate with the server. The option categories are:
Version of SSL to be used, CipherSuites supported by the client, and
CompressionMethods used by the client. Other information that is included in this
message is a 32-byte RandomNumber that assists the client in establishing encrypted
communications, and a SessionID field that is blank.
*** ClientHello, TLSv1
The client sends the server the client’s SSL version number, cipher settings, randomly generated data, and other information the server needs to communicate with the client using SSL.

2)Server Hello:
Server sends the client the server’s SSL version number, cipher settings, randomly generated data, and other information the client needs to communicate with the server over SSL. The server also sends its own certificate

3)Authentication and Pre-Master Secret
- Client authenticates the server certificate. (e.g. Common Name / Date / Issuer)
- Client creates premaster key
- Encrypts with the server's public key and sends the encrypted pre-master secret to the server.

4)Decryption and Creation of Master Secret
- server decripts pre-master key using his own private key.
- Server and Client Creates master secret with the agreed cipher.

5)Generate Session Keys
client and the server use the master secret to generate the session keys, which are symmetric keys used to encrypt and decrypt information exchanged during the SSL session

6)Encryption with Session Key
client and server exchange messages to inform that future messages will be encrypted.

No comments:

Post a Comment

How to check whether operating system is 64 bit or 32bit?

What is 32 and 64 bit operating system? The terms 32-bit and 64-bit refer to the way a computer's processor that is CPU, handles info...