Category Archives: Security

SSL Overview | OpenSSL – Cryptography & SSL/TLS Toolkit | Keytool

SSL Overview

SSL is a commonly-used protocol for managing the security of message transmission on the Internet.

SSL makes use of what is known as asymmetric cryptography, commonly referred to as public key cryptography (PKI). With public key encryption, a public key and a private key are generated for a server. Data encrypted with the public key can only be decrypted using the corresponding private key and data encrypted with the private key can only be decrypted using the corresponding public key. The private key is carefully protected so that only the owner can decrypt messages that were encrypted using the public key.

The public key is embedded in a digital certificate with additional information describing the owner of the public key, such as name, street address, and e-mail address. A private key and digital certificate provide identity for the server.

The data embedded in a digital certificate is verified by a certificate authority (CA) and digitally signed with the CA’s digital certificate. Well-known certificate authorities include Entrust and VeriSign. The trusted CA certificate establishes trust for a certificate.

An application participating in an SSL connection is authenticated when the other party evaluates and accepts the application’s digital certificate. Web browsers, servers, and other SSL-enabled applications generally accept as genuine any digital certificate that is signed by a trusted CA and is otherwise valid. For example, a digital certificate can be invalidated because it has expired or the digital certificate of the CA used to sign it expired. A server certificate can be invalidated if the host name in the digital certificate of the server does not match the URL specified by the client.

OpenSSL

Open Source toolkit implementing the Secure Sockets Layer (SSL) and Transport Layer Security (TLS) protocols as well as a full-strength general purpose cryptography library. OpenSSl Command Line Tool Document

OpenSSL provides:

  • A command line application to perform a wide variety of cryptography tasks, such as creating and handling certificates and related files. OpenSSL commands
  • A comprehensive and extensive cryptographic library libcrypto.
  • A library for enabling SSL/TLS communications libssl.

Generate self signed SSL certificate using OpenSSL toolkit

Terminology:

Public Keys 

These are keys that are intended to be known to everyone who needs to have trusted interactions with the entity. Public keys are used to verify signatures.

Private Keys 

These are keys, each of which is supposed to be known only to the particular entity who owns it (it’s supposed to be kept secret). Private and public keys exist in pairs in all public key cryptography systems. Private keys are used to compute signatures.

Signature 

A signature is computed over some data using the private key of an entity (the signer).

Certificate 

A certificate is a digitally signed statement from Certificate Authority that certifies the ownership of a public key by the named subject of the certificate.

Certificate Authority 

Certificate Authority(CA) is a trusted third party that agrees to vouch for the identity of a site, usually for a fee. Most web browsers automatically trust Commercial CAs. Aside from commercial CAs, some organizations entities may have their own CAs for internal signing.

keytool

keytool is a Java Key and Certificate Management Tool comes with JDK. It is an utility to manage the keystore of public/private keys, trusted certificates and certificates chains. JDK keytool

KeyStore

A keystore is a storage facility for cryptographic keys and certificates. In Java, you may encounter these two types of keystores:

  • Identity KeyStore: contains private key and accompanied by the certificate chain for the corresponding public key.

For example, if application server itself needs to provide SSL connections, the private key and SSL certificate should be saved in this keystore.

  • Trust KeyStore: contains certificates from other parties that you expect to communicate with, or from Certificate Authorities that you trust to identify other parties. If the application needs to connect to remote SSL server, the certificate from the remote server should be saved in this keystore.

Although one keystore can be used for both identity and trust, it is recommended using separate keystores for identity and trust because the identity keystore (private key/digital certificate pairs) and the trust keystore (trusted CA certificates) may have different security requirements. For example:

  • For trust, you only need the certificates (non-sensitive data) in the keystore. However, for identity, you add the certificate and the private key (sensitive data) in the keystore.
  • The identity keystore may be prohibited by company policy from ever being put on the corporate network, while the trust keystore can be distributed over the network.
  • The identity keystore may be protected by the operating system for both reading and writing by non-authorized users, while the trust keystore only needs to be write protected.
  • The identity keystore password is generally known to fewer people than the password for the trust keystore.

In general, systems within a domain have the same trust rules — they use the same set of trusted CAs — but they tend to have per-server identity. Identity requires a private key, and private keys should not be copied from one system to another. Therefore, you should maintain separate identity keystores for each system, each keystore containing only the server identity needed for that system. However, trust keystores can be copied from system to system, thus making it easier to standardize trust conventions.

Common keytool Commands

#generate keystore and public/private keys
keytool -genkeypair -alias *.manvirbasra.com -keyalg RSA -keysize 2048 -dname “CN=Manvir Singh, OU=Singh, O=Khalsa, L=Toronto, S=Ontario, C=CA” -keystore server.keystore -storepass password123 -keypass password123

#create csr for certificate signing
keytool -certreq -alias *.manvirbasra.com -file cert.csr -keystore server.keystore -ext san=dns:manvirbasra.com

#import root cert to keystore
keytool -importcert -alias root_cert -trustcacerts -file cacert.cer -keystore server.keystore

#import signed cert to keystore
keytool -importcert -alias *.manvirbasra.com -file cert.cer -keystore server.keystore

Resources:

OpenLDAP – Implementation of LDAP – Light Weight Directory Access Protocol

OpenLDAP:

  • Open Source Implementation of LDAP – Light Weight Directory Access Protocol
  • LDAP Protocol is used to access information stored in LDAP directory

Resources:

FindBugs Static Analysis Tool | Java Bytecode

FindBugs Static Analysis Tool is:

– Opensource
– Looks for bugs in Java
– Operates on Java bytecode
– Can run in NetBeans, Swing, Eclipse, Ant…
– Generates XML or text output

More information about FindBugs:

  1. Plug-ins available for Eclipse, NetBeans, IntelliJ IDEA, Gradle, Hudson and Jenkins
  2. Potential errors are classified in four ranks: (i) scariest, (ii) scary, (iii) troubling and (iv) of concern
  3. Additional rules sets can be plugged in FindBugs to increase the set of checks performed

Find Bugs Ant Usage Example:

<project name=”analyze_asm_util” default=”findbugs”>
<!– findbugs task definition –>
<property name=”findbugs.home” value=”/Users/ben/Documents/workspace/findbugs/findbugs” />
<property name=”jvmargs” value=”-server -Xss1m -Xmx800m -Duser.language=en -Duser.region=EN -Dfindbugs.home=${findbugs.home}” />

<path id=”findbugs.lib”>
<fileset dir=”${findbugs.home}/lib”>
<include name=”findbugs-ant.jar”/>
</fileset>
</path>

<taskdef name=”findbugs” classname=”edu.umd.cs.findbugs.anttask.FindBugsTask”>
<classpath refid=”findbugs.lib” />
</taskdef>

<taskdef name=”computeBugHistory” classname=”edu.umd.cs.findbugs.anttask.ComputeBugHistoryTask”>
<classpath refid=”findbugs.lib” />
</taskdef>

<taskdef name=”setBugDatabaseInfo” classname=”edu.umd.cs.findbugs.anttask.SetBugDatabaseInfoTask”>
<classpath refid=”findbugs.lib” />
</taskdef>

<taskdef name=”mineBugHistory” classname=”edu.umd.cs.findbugs.anttask.MineBugHistoryTask”>
<classpath refid=”findbugs.lib” />
</taskdef>

<!– findbugs task definition –>
<target name=”findbugs”>
<antcall target=”analyze” />
<antcall target=”mine” />
</target>

<!– analyze task –>
<target name=”analyze”>
<!– run findbugs against asm-util –>
<findbugs home=”${findbugs.home}”
output=”xml:withMessages”
timeout=”90000000″
reportLevel=”experimental”
workHard=”true”
effort=”max”
adjustExperimental=”true”
jvmargs=”${jvmargs}”
failOnError=”true”
outputFile=”out.xml”
projectName=”Findbugs”
debug=”false”>
<class location=”asm-util-3.0.jar” />
</findbugs>
</target>

<target name=”mine”>

<!– Set info to the latest analysis –>
<setBugDatabaseInfo home=”${findbugs.home}”
withMessages=”true”
name=”asm-util-3.0.jar”
input=”out.xml”
output=”out-rel.xml”/>

<!– Checking if history file already exists (out-hist.xml) –>
<condition property=”mining.historyfile.available”>
<available file=”out-hist.xml”/>
</condition>
<condition property=”mining.historyfile.notavailable”>
<not>
<available file=”out-hist.xml”/>
</not>
</condition>

<!– this target is executed if the history file do not exist (first run) –>
<antcall target=”history-init”>
<param name=”data.file” value=”out-rel.xml” />
<param name=”hist.file” value=”out-hist.xml” />
</antcall>
<!– else this one is executed –>
<antcall target=”history”>
<param name=”data.file” value=”out-rel.xml” />
<param name=”hist.file” value=”out-hist.xml” />
<param name=”hist.summary.file” value=”out-hist.txt” />
</antcall>
</target>

<!– Initializing history file –>
<target name=”history-init” if=”mining.historyfile.notavailable”>
<copy file=”${data.file}” tofile=”${hist.file}” />
</target>

<!– Computing bug history –>
<target name=”history” if=”mining.historyfile.available”>
<!– Merging ${data.file} into ${hist.file} –>
<computeBugHistory home=”${findbugs.home}”
withMessages=”true”
output=”${hist.file}”>
<dataFile name=”${hist.file}”/>
<dataFile name=”${data.file}”/>
</computeBugHistory>

<!– Compute history into ${hist.summary.file} –>
<mineBugHistory home=”${findbugs.home}”
formatDates=”true”
noTabs=”true”
input=”${hist.file}”
output=”${hist.summary.file}”/>
</target>

</project>

Resources: