Tuesday, 5 November 2019

SSL Handshake Overview

Reference : https://support.f5.com/csp/article/K15292

SSL Handshake Overview


SSL communication consists of a series of messages exchanged between two parties (client and server). The SSL handshake between a client and server consists of nine steps, and appears as follows.


The SSL messages determine the parameters of the encrypted communication channel that the two parties will use. It is important that the client and server agree on the message details, such as the protocol version, cipher suites, secure renegotiation, or client certificate requests. Otherwise the handshake will fail. The SSL handshake has the following messaging components:

ClientHello


When a client first attempts to connect to an SSL server, it initiates the session by sending a ClientHello message to the server. The ClientHello message starts the SSL communication between the two systems. The ClientHello message contains some of the following components:
  • Version: The version field contains the highest SSL version that the client supports.
  • Random: A random number generated by the client.
  • Session ID: An arbitrary sequence of bytes chosen by the server; it identifies a particular SSL session. The client may attempt to resume a previously established session by sending a non-zero session ID.
  • Cipher suites: Identifies the list of ciphers suites that the client supports.
  • Compression: Identifies the list of compression methods that the client supports.

ServerHello


If the server is able to find an acceptable set of algorithms, it responds to the ClientHello message with a ServerHello message. The server may use the ServerHello message to allow a resumed session. The ServerHello message contains some of the following components:
  • Version: The version field contains the highest SSL version supported by both the client and server.
  • Random: A random number generated by the server.
  • Session ID: Identifies a particular SSL session. If the client sends a non-zero session ID and the server locates a match in its cache, the server will attempt to respond with the same value as was supplied by the client, and resume the session using the same cipher suite.
  • Cipher suites: Identifies the cipher suite chosen by the server from the list of ciphers that the client supports.
  • Compression: Identifies the compression method chosen by the server from the list that the client supports.

Certificate


The server sends its Certificate message containing the server's certificate or list of (chain) certificates, depending on the selected cipher suite.

Note: The server may send a ServerKeyExchange message when the server Certificate message does not contain enough data to allow the client to exchange a premaster secret. This is true of some ciphers such as DHE-DSS.

ServerHelloDone


After sending its certificate, the server sends a ServerHelloDone message, indicating it is done with handshake negotiation.

ClientKeyExchange


The client sends the ClientKeyExchange message containing the PreMasterSecret. The PreMasterSecret is sent encrypted using the public key of the server.

ChangeCipherSpec


Both the client and server send the ChangeCipherSpec message after the security parameters have been determined. The ChangeCipherSpec message activates the negotiated SSL options for the session. From this point forward, all messages are authenticated and encrypted. This stage is significant as it indicates that subsequent records will be protected under the newly negotiated CipherSpec and keys.

Finished


Each party sends a Finished message under the new algorithm, keys and secrets. The Finished message indicates that the handshake is complete, and the parties may begin to exchange application layer data.


Resumed SSL sessions


A resumed SSL session implements session identifier (session ID) to re-establish a previously negotiated session. When an SSL handshake is resumed, the client presents the session ID from the previously negotiated session. If the server finds the session ID in its cache and accepts the resumed session, it sends back the same session ID and the parties skip the public key operation. If the server does not accept the resumed session, it issues a new session ID and implements the full SSL handshake. The resumed SSL handshake between a client and server consists of the following steps.

  


Testing SSL connections (using s_client)

After you enable SSL debug logging on the BIG-IP system, you should test SSL connections for the virtual server using a web browser or other utility, such as the OpenSSL utility, s_client, or cURL. Using the s_client utility may provide additional debugging information that you can use to troubleshoot the issue. After making several requests to the virtual server, you can review and analyze the debug log files on the BIG-IP system.
Impact of procedure: Performing the following procedure should not have a negative impact on your system.
  1. Log in to the command line of a Linux host (with a current version of OpenSSL) that can access the SSL virtual server.
  2. To test SSL connections for the virtual server, use the following command syntax:
    openssl s_client -connect <virtual_server>:<port> -msg
    For example:
    openssl s_client -connect 10.12.23.115:443 -msg
    openssl s_client -connect https://<url_of_website> -msg
  3. If the handshake attempt fails, take note of SSL errors returned by the s_client utility.
  4. If the handshake succeeds, type the following at the prompt:
    GET / HTTP/1.0
  5. Press Enter twice.
    The HTML page should display.


Thursday, 16 May 2019

SoapUI : Websphere MQ Test Integration with Groovy

MQ Injection and reception of messages using groovy is rather easy than setting up with HermesJMS and far more stable.

Below is a simple example :



While integrating with maven, you will have to ensure that you have included the following dependencies in your pom file.




Saturday, 28 July 2018

Creating Multi-Module Pom Project

In one of my previous posts, I've written about creating maven project for simple purpose. Of course maven can be used for more complex projects as well and the structure defined by maven becomes really useful.
While working on a project you'd realize it has more complex needs, you would need a system where you can develop different independent components and that leads to the scenario we are going to cover in this post. We will be creating a project with maven which will serve as parent, or you can say binding element for the build of the other sub-projects or modules. Maven has a feature which allows you to create multi module project. We are going to see how.
To create a multi module project, we will have to start with a simple project about which you can learn from my previous post Creating a simple Maven Project.

# mvn archetype:generate -DgroupId=myProject.myCompany.com -DartifactId=myProject -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Once done, you  would see that a directory with name "myProject" as per the artifactId defined earlier is created. Now move into this directory where you would see the pom.xml file created by maven the pom file may appear as below :



Before we move to creation of the modules, we need to do some changes in the parent pom file which was stated above. Locate and modify the lines as given below.

Modify the parameter packaging from "jar" to "pom". Now using the below command, you can create the modules.

# mvn archetype:generate -DgroupId=myProject.myCompany.com -DartifactId=myModule1 -DinteractiveMode=false
You will notice that a new directory is created in the parent directory, open the pom file inside which would appear as below


You will also notice that there are few extra lines added in the main project pom file as below Every new module created will have similar to above line added to the main pom.xml file. So that was quick update about creating a multi module pom project, hope you enjoyed and it was helpful.

Update
If you are running a latest version of maven, you would realize that the build is failing with rather strange error as below
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project myModule1: Compilation failure: Compilation failure:
[ERROR] Source option 5 is no longer supported. Use 6 or later.
[ERROR] Target option 1.5 is no longer supported. Use 1.6 or later.
If you have the above error while build, you might need to  add below lines in the main project's (parent) pom file under "project" head.


With above changes, you should be able to build your project successfully using the command
# mvn clean install

Thursday, 6 April 2017

SoapUI, HermesJMS, IBM Websphere MQ automation with Maven

I was working on the project where I need to automate tests with interact with IBM websphere MQ queues. I have been able to achieve it from SoapUI and HermesJMS (I have already talked about the steps in my old post here) soon to face the next challenge to integrate with Jenkins and run the tests with scheduled builds. 
In my hope to find an existing solution on net, I looked for it on google. Unfortunately it didn't help that much as the solutions available did not help me but they gave me an idea about how to achieve the same. I am using maven for integration of my solution here.


Step 1 : HeremesJMS Configuration File

I would suggest to simplify the HermesJMS configuration file which was created in the steps performed in exercise earlier. Remove all the unnecessary elements and keep only those that you would need for your test.  Here below is my configuration file which I've used



You would notice that I've used a keyword "MQ_LIB_LOCATION" while providing the path of the IBM websphere MQ dependency jar files which are used by HermesJMS in order to create connection. While my experiment I realized that in order to be able to run my build I'll have to keep my hermes configuration file autonomous. Hence, I needed to update the file dynamically with help of "com.google.code.maven-replacer-plugin" of maven. With help of this plugin I change the path of the libraries used by HermesJMS.


Step 2 : Create Maven Project skeleton

As explained above we will have to update the Hermes configuration files dynamically, hence a separate maven project module would be needed for achieving this and another module will be used to execute the SoapUI project.

Create the master project using below command and then the modules under the master project
mvn archetype:generate -DgroupId=myorg.com -DartifactId=myapp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
This command will create a directory "myapp" with the master project, now edit the pom file and change "packaging" parameter from "jar" to "pom" and remove the directory "src" from the master project as you will not be using it.
Once done, you can create the modules. Go to the master project directory and create the two modules with below commands
mvn archetype:generate -DgroupId=myorg.com -DartifactId=SoapProject -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
mvn archetype:generate -DgroupId=myorg.com -DartifactId=UpdateHermesJMS -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Now the two projects are ready, you can update the pom file to meet your need. We will start with the project to update the Hermes configuration.


Step 3 : Module UpdateHermesJMS

Now is the time to setup your module to update the hermesJMS configuration to be able to run in any environment. For this add a "com.google.code.maven-replacer-plugin" plugin to the project. I have created a folder "resources" under "src/main/" where I have put the folder for hermes configuration "hermes", the package of hermes "HermesJMS" and the library files for IBM Websphere MQ which is needed by HermesJMS for connecting to websphere MQ.
Below is example from my project : 


Step 4 : Module SoapProject

You are now set to work on the final module which is going to execute the SoapUI tests. There are few elements you should focus on and we will discuss about them one by one. 

Dependencies : Since the module UpdateHermesJMS should be executed before the SoapProject in order to have your configuration ready, this project needs to be prioritized. For that we need to define this module as dependency in the SoapProject module

Another level of dependencies has to be defined at plugin level for HermesJMS and websphere MQ library. 


I hope you are already aware of the SoapUI project execution and related plugin. The only thing extra you may have to do is to define two additional global variable for your project that will be used by SoapUI to configure HermesJMS
<globalProperties>
    <value>HERMES_JMS=${basedir}/../updateHermesConf/src/main/resources/HermesJMS</value>
    <value>hermesConfig=${basedir}/../updateHermesConf/src/main/resources/hermes</value>
</globalProperties>

Step 5 : Project LoadScript

Your maven project should be ready, however your project still needs one more tweeks in order to be able to use the right HermesJMS and corresponding configuration file.
Open your SoapUI workspace, right click on the project click on "Show Project View" and go on "Load Script" on the window of the project and insert the below script to configure HermesJMS and its configuration from the variables we have defined in previous step.



Now you are all set with the project and you can integrate your maven project on Jenkins with a simple maven build.

Monday, 27 March 2017

Creating a simple Maven Project

When I was first introduced to maven, I was introduced as a build tool, an alternative to ant build which I was using for my SoapUI project builds. However, once I dwell deeper into maven and built my interest because of the wide range of features supported by Maven, only then I realized that maven is much more than just a build tool. It is a complete project management tool which allows the developers to have synergy in the project structure. It provides a defined structure to the project which allows developers to easily understand and help in case there is any transition on the project. The new developers who are familiar with maven structure can easily determine the class file, resources etc on the project.

In this post I am going to start with creating a simple maven project and then in later part I will explain how you can create a complex project in maven with multiple modules.

You can create a simple project with below command (here I am assuming that you already have configured JDK and Maven).
mvn archetype:generate -DgroupId=myProject.myCompany.com
                       -DartifactId=myProject
                       -DarchetypeArtifactId=maven-archetype-quickstart
                       -DinteractiveMode=false
 the above command will create a maven project structure where you will have
  • pom.xml : This is the main and single configuration file that contains majority of the information used by maven to build the project. 
  • Directory structure as :
    • src -
      • main - 
        • java - 
          • myProject -
            • myCompany -
              • com -
                • App.java : It is the class file
      • test -
        • java - 
          • myProject -
            • myCompany -
              • com -
                • App.java : It is the JUnit test class file for testing the class created by maven automatically.
To run this maven project file you need to run a simple command as below :
mvn install
Above command will compile your source code, perform test and then create a jar package in the directory as below :
  • target
    • myProject-1.0-SNAPSHOT.jar
    • classes
      • myProject
        • myCompany
          • com
            • App.class
    • maven-archiver
      • pom.properties
    • maven-status
      • maven-compiler-plugin
        • compile
          • default-compile
            • createdFiles.lst
            • inputFiles.lst
        • testCompile 
          • default-testCompile
            • createdFiles.lst
            • inputFiles.lst
    • surefire-reports
      • myProject.myCompany.com.AppTest.txt
      • TEST-myProject.myCompany.com.AppTest.xml
    • test-classes
      • myProject
        • myCompany
          • com
            • AppTest.class

As you can see that maven has compiled and packaged the project into a jar file (if it is web project then a war will be generated). You can run your package with following command from your project directory
java -cp target/myProject-1.0-SNAPSHOT.jar myProject.myCompany.com.App
Hello world!
So, as you can see in the above example that it is very easy to create a maven project. Now we look into the pom.xml file that has been generated by maven




Following element in the pom file together are known as co-ordinates of the projct
  • groupId
  • artifactId
  • packaging
  • version
Creating a complex project with multiple child elements or modules is even easier. Use the same command as above to create the maven master project. Now go to the project directory and remove the "src" directory created inside and edit the "pom.xml" and change the value of element "packaging" to "pom"
<packaging>pom</packaging>
Now your master project is almost ready and you can create the modules inside using the similar command as you used for creating the master project file.
mvn archetype:generate -DgroupId=myProject.myCompany.com
                       -DartifactId=module1
                       -DarchetypeArtifactId=maven-archetype-quickstart
                       -DinteractiveMode=false
mvn archetype:generate -DgroupId=myProject.myCompany.com
                       -DartifactId=module2
                       -DarchetypeArtifactId=maven-archetype-quickstart
                       -DinteractiveMode=false
The above two commands will create two modules or child projects within the master project and you will realize that the pom file inside the master project is updated to have below elements

And the child project will have reference to the master project as below



For a complex project you only need to compile the master project and child projects will be launched on their own.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] myProject .......................................... SUCCESS [  0.757 s]
[INFO] module1 ............................................ SUCCESS [  5.211 s]
[INFO] module2 ............................................ SUCCESS [  0.748 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.909 s
[INFO] Finished at: 2017-03-26T19:26:54+05:30
[INFO] Final Memory: 15M/37M
[INFO] -----------------------------------------------------------------------

Thursday, 23 March 2017

Maven : Compilation of Groovy Class files

There are various ways to build and use your groovy class files, you can use Gradle, or Goovyc Ant or using maven. In maven we have two main possibilities, one with GMaven and the other with Groovy eclipse.

I will elaborate an example with GMaven. GMaven Plugin definition requires the groovy dependency (groovy-all).

Below is an example of a pom file which compiles all the groovy class files located in a specific location.



In this example, my scripts are making connection to an oracle 12g database, hence I had to add dependency for ojdbc and since the DB is in 12G I was facing further errors related to xdb.war. So I downloaded the war file and installed it on maven using command below.

mvn install:install-file -Dfile=xdb6.jar -DgroupId=com.oracle -DartifactId=xmlparserv2 -Dversion=12.1.0.2 -Dpackaging=jar

After installing the war to my maven repository and added the same to dependencies as shown in example above.

Now I can use the above maven pom in my master file and other child pom build can use the classes compiled from it.

Dependency Error : SoapUI 5.2.1

In our project we observed a strange error because of which the maven build was failing. Further analysis led to a conclusion that the problem was specific to the version of Soap-UI plugin we were using in our project.

Here below is the error that we observed while executing the build


There are two possible ways to manage this error, one is to degrade the plugin version for Soap-UI. We saw that this error did not exist with Soap-UI plugin 4.6.? however with 5.?.? we have the problem.

Another way to fix the problem was to add "com.jgoodies:forms:1.0.7"  dependency to your pom file.