http://javapapers.com/core-java/java-vs-javaw-vs-javaws/
1. Introduction
Who of us didn’t visit ebay, amazon to buy anything or his personal bank account to check it. Do you think that those sites are secure enough to put your personal data like (credit card number or bank account number, etc.,)?
Most of those sites use the Socket Layer (SSL) protocol to secure their Internet applications. SSL allows the data from a client, such as a Web browser, to be encrypted prior to transmission so that someone trying to sniff the data is unable to decipher it.
Many Java application servers and Web servers support the use of keystores for SSL configuration. If you’re building secure Java programs, learning to build a keystore is the first step.
2. SSL and how it works
A HTTP-based SSL connection is always initiated by the client using a URL starting with https:// instead of with http://. At the beginning of an SSL session, an SSL handshake is performed. This handshake produces the cryptographic parameters of the session. A simplified overview of how the SSL handshake is processed is shown in the diagram below.
This is in short how it works:
- A browser requests a secure page (usually https://).
- The web server sends its public key with its certificate.
- The browser checks that the certificate was issued by a trusted party (usually a trusted root CA), that the certificate is still valid and that the certificate is related to the site contacted.
- The browser then uses the public key, to encrypt a random symmetric encryption key and sends it to the server with the encrypted URL required as well as other encrypted http data.
- The web server decrypts the symmetric encryption key using its private key and uses the symmetric key to decrypt the URL and http data.
- The web server sends back the requested html document and http data encrypted with the symmetric key.
- The browser decrypts the http data and html document using the symmetric key and displays the information.
The world of SSL has, essentially, three types of certificates: private keys, public keys (also called public certificates or site certificates), and root certificates.
3. Private Keys
The private key contains the identity information of the server, along with a key value. It should keep this key safe and protected by password because it’s used to negotiate the hash during the handshake. It can be used by someone to decrypt the traffic and get your personal information. It like leaving your house key in the door lock.
4. Public Certificates
The public certificate (public key) is the portion that is presented to a client, it likes your personal passport when you show in the Airport. The public certificate, tightly associated to the private key, is created from the private key using a Certificate Signing Request (CSR). After you create a private key, you create a CSR, which is sent to your Certificate Authority (CA). The CA returns a signed certificate, which has information about the server identity and about the CA.
5. Root Certificates
Root CA Certificate is a CA Certificate which is simply a Self-signed Certificate. This certificate represents a entity which issues certificate and is known as Certificate Authority or the CA such as VeriSign, Thawte, etc.
6. Certificate Authorities
Companies who will sign certificates for you such as VeriSign, Thawte, Commodo, GetTrust. Also, many companies and institutions act as their own CA, either by building a complete implementation from scratch, or by using an open source option, such as OpenSSL.
7. Certificate Chain
When a server and client establish an SSL connection, a certificate is presented to the client; the client should determine whether to trust this certificate, a process called the certificate chain. The client examines the issuer of a certificate, searches its list of trusted root certificates, and compares the issuer on the presented certificate to the subjects of the trusted certificates.
If a match is found, the connection proceeds. If not, the Web browsers may pop up a dialog box, warning you that it cannot trust the certificate and offering the option to trust the certificate.
8. Keystore using Java keytool
Java Keytool is a key and certificate management utility. It allows users to manage their own public/private key pairs and certificates. Java Keytool stores the keys and certificates in what is called a keystore. It protects private keys with a password.
Each certificate in a Java keystore is associated with a unique alias. When creating a Java keystore you will first create the .jks file that will initially only contain the private key, then generate a CSR. Then you will import the certificate to the keystore including any root certificates.
9. Keystore Commands
Create Keystore, Keys and Certificate Requests
- Generate a Java keystore and key pair
- Generate a certificate signing request (CSR) for an existing Java keystore
- Generate a keystore and self-signed certificate
- Import a root or intermediate CA certificate to an existing Java keystore
- Import a signed primary certificate to an existing Java keystore
Export Certificates
- Export a certificate from a keystore
Check/List/View Certificates
- Check a stand-alone certificate
- Check which certificates are in a Java keystore
- Check a particular keystore entry using an alias
Delete Certificates
- Delete a certificate from a Java Keytool keystore
Change Passwords
- Change a Java keystore password
- Change a private key password
10. Configure SSL using Keystores and Self Signed Certificates on Apache Tomcat
- Generate new keystore and self-signed certificateusing this command, you will prompt to enter specific information such as user name, organization unit, company and location.
- You can list the certificate details you just created using this command
- Download Tomcat 7
- Configure Tomcat’s server to support for SSL or https connection. Adding a connector element in Tomcat\conf\server.xml
- Start Tomcat and go tohttps://localhost:8443/, you will find the following security issue where the browser will present untrusted error messages. In the case of e-commerce, such error messages result in immediate lack of confidence in the website and organizations risk losing confidence and business from the majority of consumers, that's normal as your certificate isn't signed yet by CA such as Thawte or Verisign who will verify the identity of the requester and issue a signed certificate.
- You can click Proceed anyway till you receive you signed certificate.
Nothing wrong with command line , I use myself everyday and should be the preferred way in a production server, but a GUI helps while one is not familiar with the concepts.
Whats up with that spy at the browser window? is some theme, plugin, or something, hummm…, else ? :)
The browser then uses the public key, to encrypt a random symmetric encryption key and sends it to the server with the encrypted URL required as well as other encrypted http data
==
I am created my own keystone using RSA algorithm,
I am encryption and decryption small data is fine, but I try to encrypt long data(my data having a 5725 characters), I am getting “java.lang.ArrayIndexOutOfBoundsException: too much data for RSA block” exception in java. please help me how to solve this problem.
I am trying to create sso login using cas for some of the applications in Tomcat.
I have built cas and have deployed the cas on Tomcat 7.0
Can you please tell me about the configurations to be made for the applications in Tomcat to get SSO Login through cas.
Chethan SK