Saturday 18 July 2015

X.509 Certificate Encoding and Extensions


An X.509 certificate is a digital certificate which uses international X.509 public key infrastructure (PKI) standard to verify a public key. X.509 certificate is defined using ASN.1
Understanding different encodings:

 1. PEM:
  •   ASCII(Base64) encoded data
  •   File extension is .cer
 2. DER:
  •   Binary form of ASCII PEM format certificate
  •   File extension can be .cer or .der

3. P7b/PKCS#7 :
  •  This are base64 encoded . Contains “—–BEGIN PKCS—–” & “—–END PKCS7—–” statements.
  •  They have extensions .p7b, .p7c

4. PFX/PKCS#12:
  •   They are Binary format files  storing the Server certificate.
  •   They have extensions .pfx, .p12

 

Understanding different files/extensions:

  • .Pem -   Includes private and public key in ASCII PEM format
  • .p12 - An archive file format for storing many cryptography objects as a single file.
  • .key- Contains private key.  The KEY extension is used both for public and private PKCS#8 keys. The keys may be encoded as binary DER or as ASCII PEM.
  •  .csr - Stands for certificate signing request. A certificate authority will use a CSR to create your SSL certificate
  •  .cer & .crt -  This can be interchangeable format .cer is Microsoft extension
  •  .config - Contains the configuration for creating certificate

Monday 28 July 2014

Java 7 : Exception handling

Highlights:

- Performs more precise and intelligent analysis while re-throwing the exception
- Improved type checking while throwing exception
- Simpler handling for more then one type of exceptions


Examples:

Please find below examples for exception handling for more clarification:

    /* Very generic exception handling in catch block , but precise handling in throws statement*/
     public void rethrowException(boolean flag) throws IOException,
    FileNotFoundException {
        try {
            if (flag) {
                throw new IOException();
            } else {
                throw new FileNotFoundException();
            }
        } catch (Exception e) {
            throw e;
        }
    }

/* No throw required for method , because it can analyze no exception thrown*/
    public void rethrowException() {
        try {
            try {
                throw new Exception();
            } catch (Exception e) {
            }
        } catch (Exception e1) {
            throw e1;
        }
    }
  

    /* Very generic exception handling in catch block , but precise handling in throws statement*/
    public static void rethrow() throws ParseException{
        try {
            new SimpleDateFormat("yyyyMMdd").parse("1");
        } catch (Exception e) {
            throw e;
        }
    }

Tuesday 7 January 2014

Minimize EXT framework download time on browser


EXT framework library(ext-all.js) was around 1.5MB and was taking around 30 seconds for first browser request to download the file which was freezing screen.

Even after enabling the gzip on tomcat server it was not making any effect.
The workaround is to create minimal footprint build using sencha commands.

Example:
sencha compile -classpath=my.js,../src concat -yui ext.js


More details on sencha command @ http://docs.sencha.com/extjs/4.2.2/#!/guide/command

Thursday 26 December 2013

Integrating Bryntum charts in Vaadin framework.


Ext Gantt is a very interactive Gantt chart built on the fantastic Ext JS framework and Vaadin is java based framework for rich and interactive UI development.

Ext framework is build on top of java-scrip. So for Vaadin and Ext framework integration you will need to create Vaadin java-script component.

First a server-side component is required which extend AbstractJavaScriptComponent. The class should also have a @JavaScript annotation that defines the required Ext libraries (For more details check Integrating Java Script Component )

          package com.ext
@JavaScript({"vaadin://js/ext-all.js", "vaadin://js/gnt-all.js", "vaadin://js/gantt.js"})
@StyleSheet({ "vaadin://themes/justransform/ext-all.css", "vaadin://themes/justransform/sch-gantt-all.css"})
public class GanttChartComponent extends AbstractJavaScriptComponent {
//Required API's
}
In above source code ext-all.js is minified version of ext framework, gnt-all.js is the bryntum  gantt chart library, ganttt.js is the connector script which creates gantt chaart.

Second step is to have shared state class that extend JavaScriptComponentStat. This shared state class can be used to communicate data or any changes to client side javascript.
 public class GanttChartState extends JavaScriptComponentState {
    public String divId;
//Other required data which should be part of state
}


 In above code please note the important element divId which will be used by javascript.In next step we will get in to more details.

Last step is client-side JavaScript connector (gantt.js). The connector javascript should define a global initializer function named based on the fully qualified name of the server-side Component class . In this example the server-side Component is com.ext.GanttChartComponent  so the function name should be com_ext_GanttChartComponent
com_ext_GanttChartComponent = function() {

     Ext.require('Gnt.panel.Gantt');

    //Get  domId from state
    var domId = this.getState().divId;

   // Create and div using domId
    var ganttElement = document.createElement('div');
    ganttElement.setAttribute('id', domId);
    e.appendChild(ganttElement);

   //Create bryntum charts
   var ganttPanel = Ext .create( 'Gnt.panel.Gantt',  {
                        height : 400,
                        width : 1000,
                        viewPreset : 'weekAndDayLetter',
                        startDate : startDt,
                        endDate : endDate...}

//Listen for state changes
this.onStateChange = function() {
..}

//Render chart
ganttPanel.render(domId);

 Important point to note here is the divId which was passed using shared state is used to create an div element and gantt charts are render inside this div. This will attach the gantt chart element to Vaadin component and get renders on the UI.

Also onStateChange function can be used to handle data changes and update the task and dependency store as required.