From e07d96a0b6024ce67d50e42ed5e885f1117a21cf Mon Sep 17 00:00:00 2001
From: Jack Magne <jmagne@dhcp-16-213.sjc.redhat.com>
Date: Tue, 4 Mar 2014 13:40:05 -0800
Subject: [PATCH] Further TPS Rewrite Requested Review Changes:

    1. Change the location of some more of the classes.
    2. Change the file names to reflect naming convention.
    3. Change leftover method names to reflect convention.
    4. Resolved some script building ommissions and build dependencies.
---
 base/common/src/CMakeLists.txt                     |   4 +-
 .../src/org/dogtagpki/server/tps/TPSServlet.java   |  62 -----
 .../src/org/dogtagpki/server/tps/TPSSession.java   | 139 ----------
 base/common/src/org/dogtagpki/tps/apdu/APDU.java   |  34 +--
 .../src/org/dogtagpki/tps/apdu/APDUResponse.java   |   4 +-
 .../src/org/dogtagpki/tps/apdu/CreateObject.java   |   8 +-
 .../src/org/dogtagpki/tps/apdu/CreatePin.java      |   6 +-
 .../src/org/dogtagpki/tps/apdu/DeleteFile.java     |  10 +-
 .../dogtagpki/tps/apdu/ExternalAuthenticate.java   |  22 +-
 .../org/dogtagpki/tps/apdu/FormatMuscleApplet.java |   8 +-
 .../src/org/dogtagpki/tps/apdu/GenerateKey.java    |   8 +-
 .../src/org/dogtagpki/tps/apdu/GenerateKeyECC.java |  10 +-
 .../common/src/org/dogtagpki/tps/apdu/GetData.java |   8 +-
 .../src/org/dogtagpki/tps/apdu/GetIssuerInfo.java  |   8 +-
 .../src/org/dogtagpki/tps/apdu/GetStatus.java      |   8 +-
 .../src/org/dogtagpki/tps/apdu/GetVersion.java     |   8 +-
 .../src/org/dogtagpki/tps/apdu/ImportKey.java      |   8 +-
 .../src/org/dogtagpki/tps/apdu/ImportKeyEnc.java   |  10 +-
 .../org/dogtagpki/tps/apdu/InitializeUpdate.java   |  10 +-
 .../src/org/dogtagpki/tps/apdu/InstallApplet.java  |  18 +-
 .../src/org/dogtagpki/tps/apdu/InstallLoad.java    |  20 +-
 .../src/org/dogtagpki/tps/apdu/Lifecycle.java      |   8 +-
 .../src/org/dogtagpki/tps/apdu/ListObjects.java    |   8 +-
 .../src/org/dogtagpki/tps/apdu/ListPins.java       |  12 +-
 .../src/org/dogtagpki/tps/apdu/LoadFile.java       |  10 +-
 base/common/src/org/dogtagpki/tps/apdu/PutKey.java |  10 +-
 .../src/org/dogtagpki/tps/apdu/ReadBuffer.java     |  10 +-
 .../src/org/dogtagpki/tps/apdu/ReadObject.java     |   8 +-
 base/common/src/org/dogtagpki/tps/apdu/Select.java |  10 +-
 .../src/org/dogtagpki/tps/apdu/SetIssuerInfo.java  |  10 +-
 base/common/src/org/dogtagpki/tps/apdu/SetPin.java |  10 +-
 .../src/org/dogtagpki/tps/apdu/UnblockPin.java     |   8 +-
 .../src/org/dogtagpki/tps/apdu/WriteObject.java    |  10 +-
 .../src/org/dogtagpki/tps/main/TPSBuffer.java      |   2 +-
 base/common/src/org/dogtagpki/tps/main/Util.java   |  10 +-
 base/common/src/org/dogtagpki/tps/msg/BeginOp.java |  13 +-
 base/common/src/org/dogtagpki/tps/msg/EndOp.java   | 208 ++++++++++++++-
 .../dogtagpki/tps/msg/ExtendedLoginRequest.java    |   6 +-
 .../dogtagpki/tps/msg/ExtendedLoginResponse.java   |   3 +-
 .../src/org/dogtagpki/tps/msg/TPSMessage.java      |   2 +-
 .../src/org/dogtagpki/tps/msg/TokenPDURequest.java |   2 +-
 .../org/dogtagpki/tps/msg/TokenPDUResponse.java    |   7 +-
 .../src/org/dogtagpki/server/tps/TPSServlet.java   |  62 +++++
 .../src/org/dogtagpki/server/tps/TPSSession.java   | 137 ++++++++++
 .../src/org/dogtagpki/server/tps/engine/TPS.java   | 106 --------
 .../org/dogtagpki/server/tps/engine/TPSEngine.java | 106 ++++++++
 .../server/tps/processor/TPSFormatProcessor.java   |   5 +-
 .../server/tps/processor/TPSProcessor.java         | 280 +++------------------
 48 files changed, 735 insertions(+), 741 deletions(-)
 delete mode 100644 base/common/src/org/dogtagpki/server/tps/TPSServlet.java
 delete mode 100644 base/common/src/org/dogtagpki/server/tps/TPSSession.java
 create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/TPSServlet.java
 create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/TPSSession.java
 delete mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/engine/TPS.java
 create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/engine/TPSEngine.java

diff --git a/base/common/src/CMakeLists.txt b/base/common/src/CMakeLists.txt
index f48ef87..472740d 100644
--- a/base/common/src/CMakeLists.txt
+++ b/base/common/src/CMakeLists.txt
@@ -128,7 +128,7 @@ find_file(HTTPCORE_JAR
 # build pki-certsrv
 javac(pki-certsrv-classes
     SOURCES
-        com/netscape/certsrv/*.java
+        *.java
     CLASSPATH
         ${PKI_NSUTIL_JAR} ${PKI_CMSUTIL_JAR}
         ${LDAPJDK_JAR} ${SERVLET_JAR} ${VELOCITY_JAR} ${XALAN_JAR} ${XERCES_JAR}
@@ -158,7 +158,7 @@ jar(pki-certsrv-jar
     INPUT_DIR
         ${CMAKE_BINARY_DIR}/classes
     FILES
-        com/netscape/certsrv/*.class
+        *.class
     DEPENDS
         pki-certsrv-classes
 )
diff --git a/base/common/src/org/dogtagpki/server/tps/TPSServlet.java b/base/common/src/org/dogtagpki/server/tps/TPSServlet.java
deleted file mode 100644
index d5c3983..0000000
--- a/base/common/src/org/dogtagpki/server/tps/TPSServlet.java
+++ /dev/null
@@ -1,62 +0,0 @@
-// --- BEGIN COPYRIGHT BLOCK ---
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; version 2 of the License.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-//
-// (C) 2013 Red Hat, Inc.
-// All rights reserved.
-// --- END COPYRIGHT BLOCK ---
-package org.dogtagpki.server.tps;
-
-import java.io.IOException;
-
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.dogtagpki.tps.TPSConnection;
-
-import com.netscape.certsrv.apps.CMS;
-
-/**
- * @author Endi S. Dewata <edewata@redhat.com>
- */
-public class TPSServlet extends HttpServlet {
-
-    private static final long serialVersionUID = -1092227495262381074L;
-
-    public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
-
-        CMS.debug("Hello from tps.service " + request);
-        response.setHeader("Transfer-Encoding", "chunked");
-
-        TPSConnection con = new TPSConnection(
-                request.getInputStream(), response.getOutputStream(), true);
-
-        CMS.debug("TPSConnection created: " + con);
-
-        TPSSession session = new TPSSession(con);
-
-        CMS.debug("TPSSession created: " + session);
-
-        if (session != null) {
-            try {
-                session.process();
-            } catch (Exception e) {
-                CMS.debug("TPSServlet.service: Can't process incoming message exception occured: " + e);
-            }
-        }
-
-        CMS.debug("After session.process() exiting ...");
-
-    }
-}
diff --git a/base/common/src/org/dogtagpki/server/tps/TPSSession.java b/base/common/src/org/dogtagpki/server/tps/TPSSession.java
deleted file mode 100644
index 7094928..0000000
--- a/base/common/src/org/dogtagpki/server/tps/TPSSession.java
+++ /dev/null
@@ -1,139 +0,0 @@
-// --- BEGIN COPYRIGHT BLOCK ---
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; version 2 of the License.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-//
-// (C) 2013 Red Hat, Inc.
-// All rights reserved.
-// --- END COPYRIGHT BLOCK ---
-package org.dogtagpki.server.tps;
-
-import java.io.IOException;
-
-import org.dogtagpki.server.tps.processor.TPSFormatProcessor;
-import org.dogtagpki.server.tps.processor.TPSProcessor;
-import org.dogtagpki.server.tps.processor.TPSProcessor.TPS_Status;
-import org.dogtagpki.tps.TPSConnection;
-import org.dogtagpki.tps.msg.BeginOp;
-import org.dogtagpki.tps.msg.EndOp;
-import org.dogtagpki.tps.msg.TPSMessage;
-
-import com.netscape.certsrv.apps.CMS;
-import com.netscape.certsrv.base.EBaseException;
-
-public class TPSSession {
-
-    public TPSSession(TPSConnection conn) {
-
-        CMS.debug("TPSSession constructor conn: " + conn);
-        connection = conn;
-    }
-
-    public TPSConnection getConnection() {
-        return connection;
-    }
-
-    public TPSMessage read() throws IOException {
-        TPSMessage message = null;
-
-        if (connection != null) {
-            CMS.debug("TPSSession.process() about to call read on connection : " + connection);
-
-            try {
-                message = connection.read();
-                CMS.debug("TPSSession.process() created message " + message);
-
-            } catch (Exception e) {
-                //Catch here so we can log
-                CMS.debug("Exception reading from the client: " + e.toString());
-                throw new IOException(e.toString());
-            }
-        } else {
-            throw new IOException("No connection available in TPSSession instance!");
-        }
-
-        return message;
-    }
-
-    public void write(TPSMessage msg) throws IOException {
-
-        if (connection != null) {
-
-            try {
-                connection.write(msg);
-            } catch (Exception e) {
-                //Catch here so we can log
-                CMS.debug("Exception reading from the client: " + e.toString());
-                throw new IOException(e.toString());
-            }
-
-        } else {
-            throw new IOException("No conneciton available in TPSSession instance!");
-        }
-    }
-
-    public void process() throws IOException, EBaseException {
-        TPSProcessor.TPS_Status status = TPS_Status.STATUS_ERROR_BAD_STATUS;
-        CMS.debug("In TPSSession.process()");
-
-        TPSMessage firstMsg = read();
-
-        if (firstMsg == null) {
-            throw new IOException("Can't create first TPSMessage!");
-        }
-
-        TPSMessage.MsgType msg_type = firstMsg.getType();
-        TPSMessage.OpType op_type = firstMsg.getOpType();
-
-        if (msg_type != TPSMessage.MsgType.MSG_BEGIN_OP) {
-            throw new IOException("Wong first message type read in TPSSession.process!");
-        }
-
-        switch (op_type) {
-        case OP_FORMAT:
-
-            TPSFormatProcessor processor = new TPSFormatProcessor();
-            BeginOp beginOp = (BeginOp) firstMsg;
-            status = processor.Process(this, beginOp);
-
-        case OP_ENROLL:
-            break;
-        case OP_RENEW:
-            break;
-        case OP_RESET_PIN:
-            break;
-        case OP_UNBLOCK:
-            break;
-        case OP_UNDEFINED:
-            break;
-        default:
-            break;
-
-        }
-
-        int result = EndOp.RESULT_ERROR;
-
-        if (status == TPSProcessor.TPS_Status.STATUS_NO_ERROR) {
-            result = EndOp.RESULT_GOOD;
-        }
-
-        EndOp endOp = new EndOp(firstMsg.getOpType(), result, status);
-
-        write(endOp);
-
-        CMS.debug("TPSSession.process: leaving: result: " + result + " status: " + status);
-
-    }
-
-    private TPSConnection connection;
-
-}
diff --git a/base/common/src/org/dogtagpki/tps/apdu/APDU.java b/base/common/src/org/dogtagpki/tps/apdu/APDU.java
index c880ba4..c4f2c17 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/APDU.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/APDU.java
@@ -56,6 +56,15 @@ public abstract class APDU {
         APDU_GENERATE_KEY_ECC
     }
 
+    protected byte cla;
+    protected byte ins;
+    protected byte p1;
+    protected byte p2;
+
+    protected TPSBuffer data = null;
+    protected TPSBuffer plainText = null;
+    protected TPSBuffer mac = null;
+
     public APDU() {
         data = new TPSBuffer();
     }
@@ -64,28 +73,28 @@ public abstract class APDU {
         data = new TPSBuffer(otherAPDU.getData());
     }
 
-    void SetCLA(byte theCla) {
+    void setCLA(byte theCla) {
         cla = theCla;
     }
 
-    void SetINS(byte theIns) {
+    void setINS(byte theIns) {
         ins = theIns;
     }
 
-    void SetP1(byte theP1) {
+    void setP1(byte theP1) {
         p1 = theP1;
     }
 
-    void SetP2(byte theP2) {
+    void setP2(byte theP2) {
         p2 = theP2;
     }
 
-    void SetData(TPSBuffer theData) {
+    void setData(TPSBuffer theData) {
         data = new TPSBuffer(theData);
 
     }
 
-    public void SetMAC(TPSBuffer theMac) {
+    public void setMAC(TPSBuffer theMac) {
         mac = theMac;
     }
 
@@ -168,8 +177,8 @@ public abstract class APDU {
 
         int claInt = cla & 0xff;
         int insInt = ins & 0xff;
-        int p1Int =  p1 & 0xff;
-        int p2Int =  p2 & 0xff;
+        int p1Int = p1 & 0xff;
+        int p2Int = p2 & 0xff;
 
         System.out.println("APDU: ");
         System.out.println("CLA: " + Util.intToHex(claInt));
@@ -180,13 +189,4 @@ public abstract class APDU {
         data.dump();
     }
 
-    protected byte cla;
-    protected byte ins;
-    protected byte p1;
-    protected byte p2;
-
-    protected TPSBuffer data = null;
-    protected TPSBuffer plainText = null;
-    protected TPSBuffer mac = null;
-
 };
diff --git a/base/common/src/org/dogtagpki/tps/apdu/APDUResponse.java b/base/common/src/org/dogtagpki/tps/apdu/APDUResponse.java
index 9cfc645..d0fc64b 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/APDUResponse.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/APDUResponse.java
@@ -31,7 +31,7 @@ public class APDUResponse extends APDU {
     }
 
     public APDUResponse(TPSBuffer theData) {
-        SetData(theData);
+        setData(theData);
 
     }
 
@@ -52,7 +52,7 @@ public class APDUResponse extends APDU {
 
     }
 
-    public byte GetSW2() {
+    public byte getSW2() {
         if (data == null) {
             return 0x0;
         } else {
diff --git a/base/common/src/org/dogtagpki/tps/apdu/CreateObject.java b/base/common/src/org/dogtagpki/tps/apdu/CreateObject.java
index d7b7f90..04208aa 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/CreateObject.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/CreateObject.java
@@ -71,10 +71,10 @@ public class CreateObject extends APDU {
         if (permissions.length != 6)
             return;
 
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0x5a);
-        SetP1((byte) 0x00);
-        SetP2((byte) 0x00);
+        setCLA((byte) 0x84);
+        setINS((byte) 0x5a);
+        setP1((byte) 0x00);
+        setP2((byte) 0x00);
 
         data = new TPSBuffer();
 
diff --git a/base/common/src/org/dogtagpki/tps/apdu/CreatePin.java b/base/common/src/org/dogtagpki/tps/apdu/CreatePin.java
index 078ee66..3d7b927 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/CreatePin.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/CreatePin.java
@@ -26,9 +26,9 @@ public class CreatePin extends APDU {
 
     public CreatePin(byte theP1, byte theP2, TPSBuffer theData) {
 
-        SetP1(theP1);
-        SetP2(theP2);
-        SetData(theData);
+        setP1(theP1);
+        setP2(theP2);
+        setData(theData);
 
     }
 
diff --git a/base/common/src/org/dogtagpki/tps/apdu/DeleteFile.java b/base/common/src/org/dogtagpki/tps/apdu/DeleteFile.java
index e47b91d..475207d 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/DeleteFile.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/DeleteFile.java
@@ -22,10 +22,10 @@ import org.dogtagpki.tps.main.TPSBuffer;
 public class DeleteFile extends APDU {
 
     public DeleteFile( TPSBuffer aid) {
-        SetCLA((byte) 0x84);
-        SetINS((byte)0xE4);
-        SetP1((byte)0x00);
-        SetP2((byte)0x00);
+        setCLA((byte) 0x84);
+        setINS((byte)0xE4);
+        setP1((byte)0x00);
+        setP2((byte)0x00);
 
 
         TPSBuffer AIDTLV = new TPSBuffer();
@@ -35,7 +35,7 @@ public class DeleteFile extends APDU {
 
         AIDTLV.add(aid);
 
-        SetData(AIDTLV);
+        setData(AIDTLV);
 
     }
 
diff --git a/base/common/src/org/dogtagpki/tps/apdu/ExternalAuthenticate.java b/base/common/src/org/dogtagpki/tps/apdu/ExternalAuthenticate.java
index 6204bb2..d1337b8 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/ExternalAuthenticate.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/ExternalAuthenticate.java
@@ -17,30 +17,22 @@
 // --- END COPYRIGHT BLOCK ---
 package org.dogtagpki.tps.apdu;
 
-import org.dogtagpki.server.tps.channel.SecureChannel;
 import org.dogtagpki.tps.main.TPSBuffer;
 
 public class ExternalAuthenticate extends APDU {
 
-    public ExternalAuthenticate(TPSBuffer theData, SecureChannel.SecurityLevel sl) {
+    public ExternalAuthenticate(TPSBuffer theData, byte securityLevel) {
 
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0x82);
-        SetP1((byte) 0x01);
+        setCLA((byte) 0x84);
+        setINS((byte) 0x82);
 
-        if (sl == SecureChannel.SecurityLevel.SECURE_MSG_MAC_ENC) {
-            SetP1((byte) 0x03);
-        } else if (sl == SecureChannel.SecurityLevel.SECURE_MSG_NONE) {
-            SetP1((byte) 0x00);
-        } else { // default
-            SetP1((byte) 0x01);
-        }
+        setP1(securityLevel);
 
-        SetP2((byte) 0x00);
-        SetData(theData);
+        setP2((byte) 0x00);
+        setData(theData);
     }
 
-    public TPSBuffer GetHostCryptogram()
+    public TPSBuffer getHostCryptogram()
     {
         return getData();
     }
diff --git a/base/common/src/org/dogtagpki/tps/apdu/FormatMuscleApplet.java b/base/common/src/org/dogtagpki/tps/apdu/FormatMuscleApplet.java
index 2ef508e..af4cec1 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/FormatMuscleApplet.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/FormatMuscleApplet.java
@@ -35,10 +35,10 @@ public class FormatMuscleApplet extends APDU {
             short keyCreationPermissions,
             short pinCreationPermissions) {
 
-        SetCLA((byte) 0xB0);
-        SetINS((byte) 0x2A);
-        SetP1((byte) 0x00);
-        SetP2((byte) 0x00);
+        setCLA((byte) 0xB0);
+        setINS((byte) 0x2A);
+        setP1((byte) 0x00);
+        setP2((byte) 0x00);
 
     }
 
diff --git a/base/common/src/org/dogtagpki/tps/apdu/GenerateKey.java b/base/common/src/org/dogtagpki/tps/apdu/GenerateKey.java
index da9d3d1..47f45bb 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/GenerateKey.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/GenerateKey.java
@@ -29,10 +29,10 @@ public class GenerateKey extends APDU {
             int keysize, byte option,
             byte type, TPSBuffer wrapped_challenge, TPSBuffer key_check) {
 
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0x0C);
-        SetP1(theP1);
-        SetP2(theP2);
+        setCLA((byte) 0x84);
+        setINS((byte) 0x0C);
+        setP1(theP1);
+        setP2(theP2);
         data = new TPSBuffer();
 
         data.add(alg);
diff --git a/base/common/src/org/dogtagpki/tps/apdu/GenerateKeyECC.java b/base/common/src/org/dogtagpki/tps/apdu/GenerateKeyECC.java
index 03dca7b..3f91067 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/GenerateKeyECC.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/GenerateKeyECC.java
@@ -29,10 +29,10 @@ public class GenerateKeyECC extends APDU {
             int keysize, byte option,
             byte type, TPSBuffer wrapped_challenge, TPSBuffer key_check) {
 
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0x0D);
-        SetP1(theP1);
-        SetP2(theP2);
+        setCLA((byte) 0x84);
+        setINS((byte) 0x0D);
+        setP1(theP1);
+        setP2(theP2);
 
         TPSBuffer data1 = new TPSBuffer();
 
@@ -55,7 +55,7 @@ public class GenerateKeyECC extends APDU {
             data1.add(key_check);
         }
 
-        SetData(data1);
+        setData(data1);
     }
 
     @Override
diff --git a/base/common/src/org/dogtagpki/tps/apdu/GetData.java b/base/common/src/org/dogtagpki/tps/apdu/GetData.java
index 344bae6..b7b8be0 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/GetData.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/GetData.java
@@ -26,10 +26,10 @@ public class GetData extends APDU {
 
     public GetData()
     {
-        SetCLA((byte) 0x80);
-        SetINS((byte) 0xCA);
-        SetP1((byte) 0x9F);
-        SetP2((byte) 0x7F);
+        setCLA((byte) 0x80);
+        setINS((byte) 0xCA);
+        setP1((byte) 0x9F);
+        setP2((byte) 0x7F);
     }
 
     @Override
diff --git a/base/common/src/org/dogtagpki/tps/apdu/GetIssuerInfo.java b/base/common/src/org/dogtagpki/tps/apdu/GetIssuerInfo.java
index f8eac6e..21fe1a7 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/GetIssuerInfo.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/GetIssuerInfo.java
@@ -47,10 +47,10 @@ public class GetIssuerInfo extends APDU {
      */
     public GetIssuerInfo()
     {
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0xF6);
-        SetP1((byte) 0x00);
-        SetP2((byte) 0x00);
+        setCLA((byte) 0x84);
+        setINS((byte) 0xF6);
+        setP1((byte) 0x00);
+        setP2((byte) 0x00);
     }
 
     @Override
diff --git a/base/common/src/org/dogtagpki/tps/apdu/GetStatus.java b/base/common/src/org/dogtagpki/tps/apdu/GetStatus.java
index ec7109d..3b8c68f 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/GetStatus.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/GetStatus.java
@@ -25,10 +25,10 @@ import org.dogtagpki.tps.main.TPSBuffer;
 public class GetStatus extends APDU {
     public GetStatus()
     {
-        SetCLA((byte) 0xB0);
-        SetINS((byte) 0x3C);
-        SetP1((byte) 0x00);
-        SetP2((byte) 0x00);
+        setCLA((byte) 0xB0);
+        setINS((byte) 0x3C);
+        setP1((byte) 0x00);
+        setP2((byte) 0x00);
     }
 
     @Override
diff --git a/base/common/src/org/dogtagpki/tps/apdu/GetVersion.java b/base/common/src/org/dogtagpki/tps/apdu/GetVersion.java
index f9a2316..9bdc27f 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/GetVersion.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/GetVersion.java
@@ -25,10 +25,10 @@ import org.dogtagpki.tps.main.TPSBuffer;
 public class GetVersion extends APDU {
     public GetVersion()
     {
-        SetCLA((byte) 0xB0);
-        SetINS((byte) 0x70);
-        SetP1((byte) 0x00);
-        SetP2((byte) 0x00);
+        setCLA((byte) 0xB0);
+        setINS((byte) 0x70);
+        setP1((byte) 0x00);
+        setP2((byte) 0x00);
     }
 
     @Override
diff --git a/base/common/src/org/dogtagpki/tps/apdu/ImportKey.java b/base/common/src/org/dogtagpki/tps/apdu/ImportKey.java
index 898960d..c17bfb8 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/ImportKey.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/ImportKey.java
@@ -48,10 +48,10 @@ public class ImportKey extends APDU {
      */
     public ImportKey(byte p1)
     {
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0x32);
-        SetP1(p1);
-        SetP2((byte) 0x00);
+        setCLA((byte) 0x84);
+        setINS((byte) 0x32);
+        setP1(p1);
+        setP2((byte) 0x00);
 
         data = new TPSBuffer();
         data.add((byte) 0xFF);
diff --git a/base/common/src/org/dogtagpki/tps/apdu/ImportKeyEnc.java b/base/common/src/org/dogtagpki/tps/apdu/ImportKeyEnc.java
index f754f83..c87a76a 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/ImportKeyEnc.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/ImportKeyEnc.java
@@ -49,12 +49,12 @@ public class ImportKeyEnc extends APDU {
      */
     public ImportKeyEnc(byte p1, byte p2, TPSBuffer theData)
     {
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0x0A);
-        SetP1(p1);
-        SetP2(p2);
+        setCLA((byte) 0x84);
+        setINS((byte) 0x0A);
+        setP1(p1);
+        setP2(p2);
 
-        SetData(theData);
+        setData(theData);
     }
 
     public Type getType()
diff --git a/base/common/src/org/dogtagpki/tps/apdu/InitializeUpdate.java b/base/common/src/org/dogtagpki/tps/apdu/InitializeUpdate.java
index 1de8ae0..4016b96 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/InitializeUpdate.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/InitializeUpdate.java
@@ -29,13 +29,13 @@ public class InitializeUpdate extends APDU {
      * Constructs Initialize Update APDU.
      */
     public InitializeUpdate(byte key_version, byte key_index, TPSBuffer theData) {
-        SetINS((byte) 0x50);
-        SetP1(key_version);
-        SetP2(key_index);
-        SetData(theData);
+        setINS((byte) 0x50);
+        setP1(key_version);
+        setP2(key_index);
+        setData(theData);
     }
 
-    public TPSBuffer GetHostChallenge()
+    public TPSBuffer getHostChallenge()
     {
         return getData();
     }
diff --git a/base/common/src/org/dogtagpki/tps/apdu/InstallApplet.java b/base/common/src/org/dogtagpki/tps/apdu/InstallApplet.java
index 5b644a5..9e6206a 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/InstallApplet.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/InstallApplet.java
@@ -28,10 +28,10 @@ public class InstallApplet extends APDU {
     public InstallApplet(TPSBuffer packageAID, TPSBuffer appletAID,
             byte appPrivileges, int instanceSize, int appletMemorySize)
     {
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0xE6);
-        SetP1((byte) 0x0C);
-        SetP2((byte) 0x00);
+        setCLA((byte) 0x84);
+        setINS((byte) 0xE6);
+        setP1((byte) 0x0C);
+        setP2((byte) 0x00);
 
         data = new TPSBuffer();
         data.add((byte) packageAID.size());
@@ -81,11 +81,11 @@ public class InstallApplet extends APDU {
      */
     public InstallApplet(TPSBuffer theData)
     {
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0xE6);
-        SetP1((byte) 0x0C);
-        SetP2((byte) 0x00);
-        SetData(theData);
+        setCLA((byte) 0x84);
+        setINS((byte) 0xE6);
+        setP1((byte) 0x0C);
+        setP2((byte) 0x00);
+        setData(theData);
     }
 
     @Override
diff --git a/base/common/src/org/dogtagpki/tps/apdu/InstallLoad.java b/base/common/src/org/dogtagpki/tps/apdu/InstallLoad.java
index 2fb9fc0..dc6d2b0 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/InstallLoad.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/InstallLoad.java
@@ -29,10 +29,10 @@ public class InstallLoad extends APDU {
             int fileLen)
     {
 
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0xE6);
-        SetP1((byte) 0x02);
-        SetP2((byte) 0x00);
+        setCLA((byte) 0x84);
+        setINS((byte) 0xE6);
+        setP1((byte) 0x02);
+        setP2((byte) 0x00);
 
         TPSBuffer inputData = new TPSBuffer();
         inputData.add((byte) packageAID.size());
@@ -49,7 +49,7 @@ public class InstallLoad extends APDU {
         inputData.add((byte) ((fileLen >> 8) & 0xff));
         inputData.add((byte) (fileLen & 0xff));
 
-        SetData(inputData);
+        setData(inputData);
     }
 
     /**
@@ -57,11 +57,11 @@ public class InstallLoad extends APDU {
      */
     public InstallLoad(TPSBuffer theData)
     {
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0xE6);
-        SetP1((byte) 0x02);
-        SetP2((byte) 0x00);
-        SetData(theData);
+        setCLA((byte) 0x84);
+        setINS((byte) 0xE6);
+        setP1((byte) 0x02);
+        setP2((byte) 0x00);
+        setData(theData);
     }
 
     @Override
diff --git a/base/common/src/org/dogtagpki/tps/apdu/Lifecycle.java b/base/common/src/org/dogtagpki/tps/apdu/Lifecycle.java
index c6e48b3..e26a39e 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/Lifecycle.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/Lifecycle.java
@@ -27,10 +27,10 @@ public class Lifecycle extends APDU {
      */
     public Lifecycle(byte lifecycle)
     {
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0xf0);
-        SetP1(lifecycle);
-        SetP2((byte) 0x00);
+        setCLA((byte) 0x84);
+        setINS((byte) 0xf0);
+        setP1(lifecycle);
+        setP2((byte) 0x00);
     }
 
     @Override
diff --git a/base/common/src/org/dogtagpki/tps/apdu/ListObjects.java b/base/common/src/org/dogtagpki/tps/apdu/ListObjects.java
index d44f984..b21cd11 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/ListObjects.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/ListObjects.java
@@ -26,10 +26,10 @@ import org.dogtagpki.tps.main.TPSBuffer;
 public class ListObjects extends APDU {
     public ListObjects(byte seq)
     {
-        SetCLA((byte) 0xB0);
-        SetINS((byte) 0x58);
-        SetP1(seq);
-        SetP2((byte) 0x00);
+        setCLA((byte) 0xB0);
+        setINS((byte) 0x58);
+        setP1(seq);
+        setP2((byte) 0x00);
     }
 
     @Override
diff --git a/base/common/src/org/dogtagpki/tps/apdu/ListPins.java b/base/common/src/org/dogtagpki/tps/apdu/ListPins.java
index 066fa30..7ced5a2 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/ListPins.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/ListPins.java
@@ -25,12 +25,14 @@ import org.dogtagpki.tps.main.TPSBuffer;
 
 public class ListPins extends APDU {
 
+    private byte ret_size = 0;
+
     public ListPins(byte theRet_size)
     {
-        SetCLA((byte) 0xB0);
-        SetINS((byte) 0x48);
-        SetP1((byte) 0x00);
-        SetP2((byte) 0x00);
+        setCLA((byte) 0xB0);
+        setINS((byte) 0x48);
+        setP1((byte) 0x00);
+        setP2((byte) 0x00);
         ret_size = theRet_size;
     }
 
@@ -53,6 +55,4 @@ public class ListPins extends APDU {
         return encoding;
     } /* Encode */
 
-    private byte ret_size = 0;
-
 }
diff --git a/base/common/src/org/dogtagpki/tps/apdu/LoadFile.java b/base/common/src/org/dogtagpki/tps/apdu/LoadFile.java
index 99af6fc..2b3f7e3 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/LoadFile.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/LoadFile.java
@@ -28,12 +28,12 @@ public class LoadFile extends APDU {
      */
     public LoadFile(byte refControl, byte blockNum, TPSBuffer theData)
     {
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0xE8);
-        SetP1(refControl);
-        SetP2(blockNum);
+        setCLA((byte) 0x84);
+        setINS((byte) 0xE8);
+        setP1(refControl);
+        setP2(blockNum);
 
-        SetData(theData);
+        setData(theData);
     }
 
     @Override
diff --git a/base/common/src/org/dogtagpki/tps/apdu/PutKey.java b/base/common/src/org/dogtagpki/tps/apdu/PutKey.java
index acd2782..3d6f2a0 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/PutKey.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/PutKey.java
@@ -28,11 +28,11 @@ public class PutKey extends APDU {
      */
     public PutKey(byte p1, byte p2, TPSBuffer theData)
     {
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0xd8);
-        SetP1(p1);
-        SetP2(p2);
-        SetData(theData);
+        setCLA((byte) 0x84);
+        setINS((byte) 0xd8);
+        setP1(p1);
+        setP2(p2);
+        setData(theData);
     }
 
     public Type getType()
diff --git a/base/common/src/org/dogtagpki/tps/apdu/ReadBuffer.java b/base/common/src/org/dogtagpki/tps/apdu/ReadBuffer.java
index 63d832b..7e1ab00 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/ReadBuffer.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/ReadBuffer.java
@@ -28,10 +28,10 @@ public class ReadBuffer extends APDU {
      */
     public ReadBuffer(int len, int offset)
     {
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0x08);
-        SetP1((byte) len);
-        SetP2((byte) 0x00);
+        setCLA((byte) 0x84);
+        setINS((byte) 0x08);
+        setP1((byte) len);
+        setP2((byte) 0x00);
         data = new TPSBuffer();
 
         data.add((byte) (offset / 256));
@@ -48,7 +48,7 @@ public class ReadBuffer extends APDU {
         return p1;
     }
 
-    public int GetOffset()
+    public int getOffset()
     {
         byte a = data.at(0);
         byte b = data.at(1);
diff --git a/base/common/src/org/dogtagpki/tps/apdu/ReadObject.java b/base/common/src/org/dogtagpki/tps/apdu/ReadObject.java
index 8550a41..b780983 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/ReadObject.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/ReadObject.java
@@ -54,10 +54,10 @@ public class ReadObject extends APDU {
 
     public ReadObject(byte[] object_id, int offset, int len)
     {
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0x56);
-        SetP1((byte) 0x00);
-        SetP2((byte) 0x00);
+        setCLA((byte) 0x84);
+        setINS((byte) 0x56);
+        setP1((byte) 0x00);
+        setP2((byte) 0x00);
         data = new TPSBuffer();
 
         data.add(object_id[0]);
diff --git a/base/common/src/org/dogtagpki/tps/apdu/Select.java b/base/common/src/org/dogtagpki/tps/apdu/Select.java
index 0a95c67..f01c001 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/Select.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/Select.java
@@ -25,11 +25,11 @@ import org.dogtagpki.tps.main.TPSBuffer;
 public class Select extends APDU {
     public Select(byte p1, byte p2, TPSBuffer theData)
     {
-        SetCLA((byte) 0x00);
-        SetINS((byte) 0xa4);
-        SetP1(p1);
-        SetP2(p2);
-        SetData(theData);
+        setCLA((byte) 0x00);
+        setINS((byte) 0xa4);
+        setP1(p1);
+        setP2(p2);
+        setData(theData);
     }
 
     public Type getType()
diff --git a/base/common/src/org/dogtagpki/tps/apdu/SetIssuerInfo.java b/base/common/src/org/dogtagpki/tps/apdu/SetIssuerInfo.java
index 563bcc6..316a0fd 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/SetIssuerInfo.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/SetIssuerInfo.java
@@ -47,11 +47,11 @@ public class SetIssuerInfo extends APDU {
      */
     public SetIssuerInfo(byte p1, byte p2, TPSBuffer theData)
     {
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0xF4);
-        SetP1(p1);
-        SetP2(p2);
-        SetData(theData);
+        setCLA((byte) 0x84);
+        setINS((byte) 0xF4);
+        setP1(p1);
+        setP2(p2);
+        setData(theData);
     }
 
     public TPSBuffer getIssuerInfo()
diff --git a/base/common/src/org/dogtagpki/tps/apdu/SetPin.java b/base/common/src/org/dogtagpki/tps/apdu/SetPin.java
index 7da0e07..8911c40 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/SetPin.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/SetPin.java
@@ -47,11 +47,11 @@ public class SetPin extends APDU {
      */
     public SetPin(byte p1, byte p2, TPSBuffer theData)
     {
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0x04);
-        SetP1(p1);
-        SetP2(p2);
-        SetData(theData);
+        setCLA((byte) 0x84);
+        setINS((byte) 0x04);
+        setP1(p1);
+        setP2(p2);
+        setData(theData);
     }
 
     public TPSBuffer getNewPIN()
diff --git a/base/common/src/org/dogtagpki/tps/apdu/UnblockPin.java b/base/common/src/org/dogtagpki/tps/apdu/UnblockPin.java
index 5c66bfc..620698c 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/UnblockPin.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/UnblockPin.java
@@ -26,10 +26,10 @@ public class UnblockPin extends APDU {
      */
     public UnblockPin()
     {
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0x02);
-        SetP1((byte) 0x00);
-        SetP2((byte) 0x00);
+        setCLA((byte) 0x84);
+        setINS((byte) 0x02);
+        setP1((byte) 0x00);
+        setP2((byte) 0x00);
     }
 
     public Type getType()
diff --git a/base/common/src/org/dogtagpki/tps/apdu/WriteObject.java b/base/common/src/org/dogtagpki/tps/apdu/WriteObject.java
index b761dca..bf64949 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/WriteObject.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/WriteObject.java
@@ -66,10 +66,10 @@ public class WriteObject extends APDU {
             return;
         }
 
-        SetCLA((byte) 0x84);
-        SetINS((byte) 0x54);
-        SetP1((byte) 0x00);
-        SetP2((byte) 0x00);
+        setCLA((byte) 0x84);
+        setINS((byte) 0x54);
+        setP1((byte) 0x00);
+        setP2((byte) 0x00);
 
         TPSBuffer data1 = new TPSBuffer();
 
@@ -85,7 +85,7 @@ public class WriteObject extends APDU {
         data1.add((byte) (offset & 0xff));
         data1.add((byte) data.size());
         data1.add(data);
-        SetData(data1);
+        setData(data1);
     }
 
     public Type getType()
diff --git a/base/common/src/org/dogtagpki/tps/main/TPSBuffer.java b/base/common/src/org/dogtagpki/tps/main/TPSBuffer.java
index a0a71a6..1df8716 100644
--- a/base/common/src/org/dogtagpki/tps/main/TPSBuffer.java
+++ b/base/common/src/org/dogtagpki/tps/main/TPSBuffer.java
@@ -39,7 +39,7 @@ public class TPSBuffer {
     public TPSBuffer(String str) {
 
         if (str != null) {
-            buf = Util.Str2ByteArray(str);
+            buf = Util.str2ByteArray(str);
         } else {
             buf = new byte[0];
         }
diff --git a/base/common/src/org/dogtagpki/tps/main/Util.java b/base/common/src/org/dogtagpki/tps/main/Util.java
index deecd5a..a493dd6 100644
--- a/base/common/src/org/dogtagpki/tps/main/Util.java
+++ b/base/common/src/org/dogtagpki/tps/main/Util.java
@@ -30,7 +30,7 @@ public class Util {
     public Util() {
     }
 
-    public static byte[]  Str2ByteArray (String s)  {
+    public static byte[]  str2ByteArray (String s)  {
         int len = s.length() / 2;
 
 
@@ -63,17 +63,17 @@ public class Util {
 
     }
 
-    public static String URIDecode(String encoded) throws UnsupportedEncodingException {
+    public static String uriDecode(String encoded) throws UnsupportedEncodingException {
 
         return URLDecoder.decode(encoded, "UTF-8");
     }
 
-    public static String URIEncode(String decoded) throws UnsupportedEncodingException {
+    public static String uriEncode(String decoded) throws UnsupportedEncodingException {
 
         return URLEncoder.encode(decoded, "UTF-8");
     }
 
-    public static byte[] URIDecodeFromHex(String buff) {
+    public static byte[] uriDecodeFromHex(String buff) {
 
         byte[] result = null;
         byte[] tmp = null;
@@ -106,7 +106,7 @@ public class Util {
         return result;
     }
 
-    public static String URIEncodeInHex(byte[] buff) {
+    public static String uriEncodeInHex(byte[] buff) {
 
         final String HEX_DIGITS = "0123456789ABCDEF";
 
diff --git a/base/common/src/org/dogtagpki/tps/msg/BeginOp.java b/base/common/src/org/dogtagpki/tps/msg/BeginOp.java
index 0b6ab9f..2d2586c 100644
--- a/base/common/src/org/dogtagpki/tps/msg/BeginOp.java
+++ b/base/common/src/org/dogtagpki/tps/msg/BeginOp.java
@@ -22,7 +22,10 @@ import java.util.Map;
 import com.netscape.certsrv.apps.CMS;
 
 public class BeginOp extends TPSMessage {
-    public BeginOp(OpType theOp, Map<String,String> theExtensions) {
+
+    private Map<String, String> extensions;
+
+    public BeginOp(OpType theOp, Map<String, String> theExtensions) {
 
         CMS.debug("BeingOp op: " + theOp + " extensions: " + theExtensions);
         put(OPERATION_TYPE_NAME, opTypeToInt(theOp));
@@ -33,12 +36,11 @@ public class BeginOp extends TPSMessage {
 
     public OpType getOpType() {
 
-        int opTypeInt =  getInt(OPERATION_TYPE_NAME);
+        int opTypeInt = getInt(OPERATION_TYPE_NAME);
         return intToOpType(opTypeInt);
     }
 
-
-    public Map<String,String> GetExtensions() {
+    public Map<String, String> GetExtensions() {
         return extensions;
     }
 
@@ -46,12 +48,11 @@ public class BeginOp extends TPSMessage {
 
         String result = null;
 
-        if(extName == null)
+        if (extName == null)
             return result;
 
         return extensions.get(extName);
 
     }
 
-    private    Map<String, String> extensions;
 }
diff --git a/base/common/src/org/dogtagpki/tps/msg/EndOp.java b/base/common/src/org/dogtagpki/tps/msg/EndOp.java
index 40179c5..fbb2f93 100644
--- a/base/common/src/org/dogtagpki/tps/msg/EndOp.java
+++ b/base/common/src/org/dogtagpki/tps/msg/EndOp.java
@@ -17,25 +17,225 @@
 // --- END COPYRIGHT BLOCK ---
 package org.dogtagpki.tps.msg;
 
-import org.dogtagpki.server.tps.processor.TPSProcessor;
 
 
 public class EndOp extends TPSMessage {
 
+    public enum TPSStatus {
+        STATUS_NO_ERROR,
+        STATUS_ERROR_SNAC,
+        STATUS_ERROR_SEC_INIT_UPDATE,
+        STATUS_ERROR_CREATE_CARDMGR,
+        STATUS_ERROR_MAC_RESET_PIN_PDU,
+        STATUS_ERROR_MAC_CERT_PDU,
+        STATUS_ERROR_MAC_LIFESTYLE_PDU,
+        STATUS_ERROR_MAC_ENROLL_PDU,
+        STATUS_ERROR_READ_OBJECT_PDU,
+        STATUS_ERROR_BAD_STATUS,
+        STATUS_ERROR_CA_RESPONSE,
+        STATUS_ERROR_READ_BUFFER_OVERFLOW,
+        STATUS_ERROR_TOKEN_RESET_PIN_FAILED,
+        STATUS_ERROR_CONNECTION,
+        STATUS_ERROR_LOGIN,
+        STATUS_ERROR_DB,
+        STATUS_ERROR_TOKEN_DISABLED,
+        STATUS_ERROR_SECURE_CHANNEL,
+        STATUS_ERROR_MISCONFIGURATION,
+        STATUS_ERROR_UPGRADE_APPLET,
+        STATUS_ERROR_KEY_CHANGE_OVER,
+        STATUS_ERROR_EXTERNAL_AUTH,
+        STATUS_ERROR_DEFAULT_TOKENTYPE_NOT_FOUND,
+        STATUS_ERROR_DEFAULT_TOKENTYPE_PARAMS_NOT_FOUND,
+        STATUS_ERROR_PUBLISH,
+        STATUS_ERROR_LDAP_CONN,
+        STATUS_ERROR_DISABLED_TOKEN,
+        STATUS_ERROR_NOT_PIN_RESETABLE,
+        STATUS_ERROR_CONN_LOST,
+        STATUS_ERROR_CREATE_TUS_TOKEN_ENTRY,
+        STATUS_ERROR_NO_SUCH_TOKEN_STATE,
+        STATUS_ERROR_NO_SUCH_LOST_REASON,
+        STATUS_ERROR_UNUSABLE_TOKEN_KEYCOMPROMISE,
+        STATUS_ERROR_INACTIVE_TOKEN_NOT_FOUND,
+        STATUS_ERROR_HAS_AT_LEAST_ONE_ACTIVE_TOKEN,
+        STATUS_ERROR_CONTACT_ADMIN,
+        STATUS_ERROR_RECOVERY_IS_PROCESSED,
+        STATUS_ERROR_RECOVERY_FAILED,
+        STATUS_ERROR_NO_OPERATION_ON_LOST_TOKEN,
+        STATUS_ERROR_KEY_ARCHIVE_OFF,
+        STATUS_ERROR_NO_TKS_CONNID,
+        STATUS_ERROR_UPDATE_TOKENDB_FAILED,
+        STATUS_ERROR_REVOKE_CERTIFICATES_FAILED,
+        STATUS_ERROR_NOT_TOKEN_OWNER,
+        STATUS_ERROR_RENEWAL_IS_PROCESSED,
+        STATUS_ERROR_RENEWAL_FAILED
+    };
+
+
     public static final int  RESULT_GOOD = 0;
     public static final int  RESULT_ERROR = 1;
 
 
-    public EndOp(OpType theOp, int result, TPSProcessor.TPS_Status message) {
+    public EndOp(OpType theOp, int result, TPSStatus message) {
         put(MSG_TYPE_NAME, msgTypeToInt(MsgType.MSG_END_OP));
         put(OPERATION_TYPE_NAME, opTypeToInt(theOp));
         put(RESULT_NAME, result);
-        put(MESSAGE_NAME, TPSProcessor.statusToInt(message));
+        put(MESSAGE_NAME, statusToInt(message));
+    }
+
+    public static int statusToInt(TPSStatus status) {
+
+        int result = 0;
+
+        switch (status) {
+        case STATUS_NO_ERROR:
+            result = 0;
+            break;
+        case STATUS_ERROR_SNAC:
+            result = 1;
+            break;
+        case STATUS_ERROR_SEC_INIT_UPDATE:
+            result = 2;
+            break;
+        case STATUS_ERROR_CREATE_CARDMGR:
+            result = 3;
+            break;
+        case STATUS_ERROR_MAC_RESET_PIN_PDU:
+            result = 4;
+            break;
+        case STATUS_ERROR_MAC_CERT_PDU:
+            result = 5;
+            break;
+        case STATUS_ERROR_MAC_LIFESTYLE_PDU:
+            result = 6;
+            break;
+        case STATUS_ERROR_MAC_ENROLL_PDU:
+            result = 7;
+            break;
+        case STATUS_ERROR_READ_OBJECT_PDU:
+            result = 8;
+            break;
+        case STATUS_ERROR_BAD_STATUS:
+            result = 9;
+            break;
+        case STATUS_ERROR_CA_RESPONSE:
+            result = 10;
+            break;
+        case STATUS_ERROR_READ_BUFFER_OVERFLOW:
+            result = 11;
+            break;
+        case STATUS_ERROR_TOKEN_RESET_PIN_FAILED:
+            result = 12;
+            break;
+        case STATUS_ERROR_CONNECTION:
+            result = 13;
+            break;
+        case STATUS_ERROR_LOGIN:
+            result = 14;
+            break;
+        case STATUS_ERROR_DB:
+            result = 15;
+            break;
+        case STATUS_ERROR_TOKEN_DISABLED:
+            result = 16;
+            break;
+        case STATUS_ERROR_SECURE_CHANNEL:
+            result = 17;
+            break;
+        case STATUS_ERROR_MISCONFIGURATION:
+            result = 18;
+            break;
+        case STATUS_ERROR_UPGRADE_APPLET:
+            result = 19;
+            break;
+        case STATUS_ERROR_KEY_CHANGE_OVER:
+            result = 20;
+            break;
+        case STATUS_ERROR_EXTERNAL_AUTH:
+            result = 21;
+            break;
+        case STATUS_ERROR_DEFAULT_TOKENTYPE_NOT_FOUND:
+            result = 22;
+            break;
+        case STATUS_ERROR_DEFAULT_TOKENTYPE_PARAMS_NOT_FOUND:
+            result = 23;
+            break;
+        case STATUS_ERROR_PUBLISH:
+            result = 24;
+            break;
+        case STATUS_ERROR_LDAP_CONN:
+            result = 25;
+            break;
+        case STATUS_ERROR_DISABLED_TOKEN:
+            result = 26;
+            break;
+        case STATUS_ERROR_NOT_PIN_RESETABLE:
+            result = 27;
+            break;
+        case STATUS_ERROR_CONN_LOST:
+            result = 28;
+            break;
+        case STATUS_ERROR_CREATE_TUS_TOKEN_ENTRY:
+            result = 29;
+            break;
+        case STATUS_ERROR_NO_SUCH_TOKEN_STATE:
+            result = 30;
+            break;
+        case STATUS_ERROR_NO_SUCH_LOST_REASON:
+            result = 31;
+            break;
+        case STATUS_ERROR_UNUSABLE_TOKEN_KEYCOMPROMISE:
+            result = 32;
+            break;
+        case STATUS_ERROR_INACTIVE_TOKEN_NOT_FOUND:
+            result = 33;
+            break;
+        case STATUS_ERROR_HAS_AT_LEAST_ONE_ACTIVE_TOKEN:
+            result = 34;
+            break;
+        case STATUS_ERROR_CONTACT_ADMIN:
+            result = 35;
+            break;
+        case STATUS_ERROR_RECOVERY_IS_PROCESSED:
+            result = 36;
+            break;
+        case STATUS_ERROR_RECOVERY_FAILED:
+            result = 37;
+            break;
+        case STATUS_ERROR_NO_OPERATION_ON_LOST_TOKEN:
+            result = 38;
+            break;
+        case STATUS_ERROR_KEY_ARCHIVE_OFF:
+            result = 39;
+            break;
+        case STATUS_ERROR_NO_TKS_CONNID:
+            result = 40;
+            break;
+        case STATUS_ERROR_UPDATE_TOKENDB_FAILED:
+            result = 41;
+            break;
+        case STATUS_ERROR_REVOKE_CERTIFICATES_FAILED:
+            result = 42;
+            break;
+        case STATUS_ERROR_NOT_TOKEN_OWNER:
+            result = 43;
+            break;
+        case STATUS_ERROR_RENEWAL_IS_PROCESSED:
+            result = 44;
+            break;
+        case STATUS_ERROR_RENEWAL_FAILED:
+            result = 45;
+            break;
+        default:
+            break;
+        }
+
+        return result;
+
     }
 
     public static void main(String[] args) {
 
-        EndOp end_msg = new EndOp(OpType.OP_FORMAT,0,TPSProcessor.TPS_Status.STATUS_NO_ERROR);
+        EndOp end_msg = new EndOp(OpType.OP_FORMAT,0,TPSStatus.STATUS_NO_ERROR);
         System.out.println(end_msg.encode());
 
 
diff --git a/base/common/src/org/dogtagpki/tps/msg/ExtendedLoginRequest.java b/base/common/src/org/dogtagpki/tps/msg/ExtendedLoginRequest.java
index ee979ff..dbc4816 100644
--- a/base/common/src/org/dogtagpki/tps/msg/ExtendedLoginRequest.java
+++ b/base/common/src/org/dogtagpki/tps/msg/ExtendedLoginRequest.java
@@ -26,6 +26,8 @@ import org.dogtagpki.tps.main.Util;
 
 public class ExtendedLoginRequest extends TPSMessage {
 
+    private Set<String> params;
+
     public ExtendedLoginRequest(int invalid_pw, int blocked, Set<String> params, String title, String description) {
 
         put(INVALID_PWD_NAME, invalid_pw);
@@ -46,7 +48,7 @@ public class ExtendedLoginRequest extends TPSMessage {
                 String curParam = null;
 
                 try {
-                    curParam = Util.URIEncode(iter.next());
+                    curParam = Util.uriEncode(iter.next());
                 } catch (UnsupportedEncodingException e) {
                     curParam = null;
                 }
@@ -68,8 +70,6 @@ public class ExtendedLoginRequest extends TPSMessage {
 
     }
 
-    private Set<String> params;
-
     public static void main(String[] args) {
 
         final String title = "LDAP Authentication";
diff --git a/base/common/src/org/dogtagpki/tps/msg/ExtendedLoginResponse.java b/base/common/src/org/dogtagpki/tps/msg/ExtendedLoginResponse.java
index 557c2eb..8ae7ad6 100644
--- a/base/common/src/org/dogtagpki/tps/msg/ExtendedLoginResponse.java
+++ b/base/common/src/org/dogtagpki/tps/msg/ExtendedLoginResponse.java
@@ -22,6 +22,8 @@ import java.util.Map;
 
 public class ExtendedLoginResponse extends TPSMessage {
 
+    private Map<String, String> authParams;
+
     public ExtendedLoginResponse(String msg) {
 
         super(msg);
@@ -38,5 +40,4 @@ public class ExtendedLoginResponse extends TPSMessage {
         return authParams;
     }
 
-    private Map<String, String> authParams;
 }
diff --git a/base/common/src/org/dogtagpki/tps/msg/TPSMessage.java b/base/common/src/org/dogtagpki/tps/msg/TPSMessage.java
index f656db8..f6939d3 100644
--- a/base/common/src/org/dogtagpki/tps/msg/TPSMessage.java
+++ b/base/common/src/org/dogtagpki/tps/msg/TPSMessage.java
@@ -417,7 +417,7 @@ public class TPSMessage {
         Map<String, String> extsMap = null;
         if (extensions != null) {
             try {
-                decoded = Util.URIDecode(extensions);
+                decoded = Util.uriDecode(extensions);
             } catch (Exception e) {
                 CMS.debug("TPSMessage.createMessage: Util.URIDecode failed: " + e);
                 return null;
diff --git a/base/common/src/org/dogtagpki/tps/msg/TokenPDURequest.java b/base/common/src/org/dogtagpki/tps/msg/TokenPDURequest.java
index 02f2699..433338b 100644
--- a/base/common/src/org/dogtagpki/tps/msg/TokenPDURequest.java
+++ b/base/common/src/org/dogtagpki/tps/msg/TokenPDURequest.java
@@ -33,7 +33,7 @@ public class TokenPDURequest extends TPSMessage {
             TPSBuffer encoding = apdu.getEncoding();
             int apduSize = encoding.size();
 
-            String apdu_value = Util.URIEncodeInHex(encoding.toBytesArray());
+            String apdu_value = Util.uriEncodeInHex(encoding.toBytesArray());
 
             put(PDU_SIZE_NAME, apduSize);
             put(PDU_DATA_NAME, apdu_value);
diff --git a/base/common/src/org/dogtagpki/tps/msg/TokenPDUResponse.java b/base/common/src/org/dogtagpki/tps/msg/TokenPDUResponse.java
index 4059c1b..b654e80 100644
--- a/base/common/src/org/dogtagpki/tps/msg/TokenPDUResponse.java
+++ b/base/common/src/org/dogtagpki/tps/msg/TokenPDUResponse.java
@@ -22,6 +22,9 @@ import org.dogtagpki.tps.main.TPSBuffer;
 import org.dogtagpki.tps.main.Util;
 
 public class TokenPDUResponse extends TPSMessage {
+
+    private APDUResponse response;
+
     public TokenPDUResponse(String message) {
 
         super(message);
@@ -32,7 +35,7 @@ public class TokenPDUResponse extends TPSMessage {
 
         int sizeI = Integer.parseInt(size);
 
-        byte[] decoded_pdu_data = Util.URIDecodeFromHex(apduData);
+        byte[] decoded_pdu_data = Util.uriDecodeFromHex(apduData);
 
         if (decoded_pdu_data.length == sizeI) {
 
@@ -44,8 +47,6 @@ public class TokenPDUResponse extends TPSMessage {
 
     }
 
-    private APDUResponse response;
-
     public APDUResponse getResponseAPDU() {
         return response;
     }
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSServlet.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSServlet.java
new file mode 100644
index 0000000..d5c3983
--- /dev/null
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSServlet.java
@@ -0,0 +1,62 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package org.dogtagpki.server.tps;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.dogtagpki.tps.TPSConnection;
+
+import com.netscape.certsrv.apps.CMS;
+
+/**
+ * @author Endi S. Dewata <edewata@redhat.com>
+ */
+public class TPSServlet extends HttpServlet {
+
+    private static final long serialVersionUID = -1092227495262381074L;
+
+    public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
+
+        CMS.debug("Hello from tps.service " + request);
+        response.setHeader("Transfer-Encoding", "chunked");
+
+        TPSConnection con = new TPSConnection(
+                request.getInputStream(), response.getOutputStream(), true);
+
+        CMS.debug("TPSConnection created: " + con);
+
+        TPSSession session = new TPSSession(con);
+
+        CMS.debug("TPSSession created: " + session);
+
+        if (session != null) {
+            try {
+                session.process();
+            } catch (Exception e) {
+                CMS.debug("TPSServlet.service: Can't process incoming message exception occured: " + e);
+            }
+        }
+
+        CMS.debug("After session.process() exiting ...");
+
+    }
+}
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSSession.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSSession.java
new file mode 100644
index 0000000..afc1f60
--- /dev/null
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSSession.java
@@ -0,0 +1,137 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package org.dogtagpki.server.tps;
+
+import java.io.IOException;
+
+import org.dogtagpki.server.tps.processor.TPSFormatProcessor;
+import org.dogtagpki.tps.TPSConnection;
+import org.dogtagpki.tps.msg.BeginOp;
+import org.dogtagpki.tps.msg.EndOp;
+import org.dogtagpki.tps.msg.TPSMessage;
+
+import com.netscape.certsrv.apps.CMS;
+import com.netscape.certsrv.base.EBaseException;
+
+public class TPSSession {
+
+    private TPSConnection connection;
+
+    public TPSSession(TPSConnection conn) {
+
+        CMS.debug("TPSSession constructor conn: " + conn);
+        connection = conn;
+    }
+
+    public TPSConnection getConnection() {
+        return connection;
+    }
+
+    public TPSMessage read() throws IOException {
+        TPSMessage message = null;
+
+        if (connection != null) {
+            CMS.debug("TPSSession.process() about to call read on connection : " + connection);
+
+            try {
+                message = connection.read();
+                CMS.debug("TPSSession.process() created message " + message);
+
+            } catch (Exception e) {
+                //Catch here so we can log
+                CMS.debug("Exception reading from the client: " + e.toString());
+                throw new IOException(e.toString());
+            }
+        } else {
+            throw new IOException("No connection available in TPSSession instance!");
+        }
+
+        return message;
+    }
+
+    public void write(TPSMessage msg) throws IOException {
+
+        if (connection != null) {
+
+            try {
+                connection.write(msg);
+            } catch (Exception e) {
+                //Catch here so we can log
+                CMS.debug("Exception reading from the client: " + e.toString());
+                throw new IOException(e.toString());
+            }
+
+        } else {
+            throw new IOException("No conneciton available in TPSSession instance!");
+        }
+    }
+
+    public void process() throws IOException, EBaseException {
+        EndOp.TPSStatus status = EndOp.TPSStatus.STATUS_ERROR_BAD_STATUS;
+        CMS.debug("In TPSSession.process()");
+
+        TPSMessage firstMsg = read();
+
+        if (firstMsg == null) {
+            throw new IOException("Can't create first TPSMessage!");
+        }
+
+        TPSMessage.MsgType msg_type = firstMsg.getType();
+        TPSMessage.OpType op_type = firstMsg.getOpType();
+
+        if (msg_type != TPSMessage.MsgType.MSG_BEGIN_OP) {
+            throw new IOException("Wong first message type read in TPSSession.process!");
+        }
+
+        switch (op_type) {
+        case OP_FORMAT:
+
+            TPSFormatProcessor processor = new TPSFormatProcessor();
+            BeginOp beginOp = (BeginOp) firstMsg;
+            status = processor.process(this, beginOp);
+
+        case OP_ENROLL:
+            break;
+        case OP_RENEW:
+            break;
+        case OP_RESET_PIN:
+            break;
+        case OP_UNBLOCK:
+            break;
+        case OP_UNDEFINED:
+            break;
+        default:
+            break;
+
+        }
+
+        int result = EndOp.RESULT_ERROR;
+
+        if (status == EndOp.TPSStatus.STATUS_NO_ERROR) {
+            result = EndOp.RESULT_GOOD;
+        }
+
+        EndOp endOp = new EndOp(firstMsg.getOpType(), result, status);
+
+        write(endOp);
+
+        CMS.debug("TPSSession.process: leaving: result: " + result + " status: " + status);
+
+    }
+
+}
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/engine/TPS.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/engine/TPS.java
deleted file mode 100644
index b1c2fb4..0000000
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/engine/TPS.java
+++ /dev/null
@@ -1,106 +0,0 @@
-// --- BEGIN COPYRIGHT BLOCK ---
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; version 2 of the License.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-//
-// (C) 2013 Red Hat, Inc.
-// All rights reserved.
-// --- END COPYRIGHT BLOCK ---
-package org.dogtagpki.server.tps.engine;
-
-public class TPS {
-
-    public static final String TKS_RESPONSE_STATUS = "status";
-    public static final String TKS_RESPONSE_SessionKey = "sessionKey";
-    public static final String TKS_RESPONSE_EncSessionKey = "encSessionKey";
-    public static final String TKS_RESPONSE_KEK_DesKey = "kek_wrapped_desKey";
-    public static final String TKS_RESPONSE_DRM_Trans_DesKey = "drm_trans_wrapped_desKey";
-    public static final String TKS_RESPONSE_HostCryptogram = "hostCryptogram";
-
-    public static final String CFG_DEBUG_ENABLE = "logging.debug.enable";
-    public static final String CFG_DEBUG_FILENAME = "logging.debug.filename";
-    public static final String CFG_DEBUG_LEVEL = "logging.debug.level";
-    public static final String CFG_AUDIT_ENABLE = "logging.audit.enable";
-    public static final String CFG_AUDIT_FILENAME = "logging.audit.filename";
-    public static final String CFG_SIGNED_AUDIT_FILENAME = "logging.audit.signedAuditFilename";
-    public static final String CFG_AUDIT_LEVEL = "logging.audit.level";
-    public static final String CFG_AUDIT_SIGNED = "logging.audit.logSigning";
-    public static final String CFG_AUDIT_SIGNING_CERT_NICK = "logging.audit.signedAuditCertNickname";
-    public static final String CFG_ERROR_ENABLE = "logging.error.enable";
-    public static final String CFG_ERROR_FILENAME = "logging.error.filename";
-    public static final String CFG_ERROR_LEVEL = "logging.error.level";
-    public static final String CFG_SELFTEST_ENABLE = "selftests.container.logger.enable";
-    public static final String CFG_SELFTEST_FILENAME = "selftests.container.logger.fileName";
-    public static final String CFG_SELFTEST_LEVEL = "selftests.container.logger.level";
-    public static final String CFG_CHANNEL_SEC_LEVEL = "channel.securityLevel";
-    public static final String CFG_CHANNEL_ENCRYPTION = "channel.encryption";
-    public static final String CFG_APPLET_CARDMGR_INSTANCE_AID = "applet.aid.cardmgr_instance";
-    public static final String CFG_APPLET_NETKEY_INSTANCE_AID = "applet.aid.netkey_instance";
-    public static final String CFG_APPLET_NETKEY_FILE_AID = "applet.aid.netkey_file";
-    public static final String CFG_APPLET_NETKEY_OLD_INSTANCE_AID = "applet.aid.netkey_old_instance";
-    public static final String CFG_APPLET_NETKEY_OLD_FILE_AID = "applet.aid.netkey_old_file";
-    public static final String CFG_APPLET_SO_PIN = "applet.so_pin";
-    public static final String CFG_APPLET_DELETE_NETKEY_OLD = "applet.delete_old";
-    public static final String CFG_AUDIT_SELECTED_EVENTS="logging.audit.selected.events";
-    public static final String CFG_AUDIT_NONSELECTABLE_EVENTS="logging.audit.nonselectable.events";
-    public static final String CFG_AUDIT_SELECTABLE_EVENTS="logging.audit.selectable.events";
-    public static final String CFG_AUDIT_BUFFER_SIZE = "logging.audit.buffer.size";
-    public static final String CFG_AUDIT_FLUSH_INTERVAL = "logging.audit.flush.interval";
-    public static final String CFG_AUDIT_FILE_TYPE = "logging.audit.file.type";
-    public static final String CFG_DEBUG_FILE_TYPE = "logging.debug.file.type";
-    public static final String CFG_ERROR_FILE_TYPE = "logging.error.file.type";
-    public static final String CFG_SELFTEST_FILE_TYPE = "selftests.container.logger.file.type";
-    public static final String CFG_AUDIT_PREFIX = "logging.audit";
-    public static final String CFG_ERROR_PREFIX = "logging.error";
-    public static final String CFG_DEBUG_PREFIX = "logging.debug";
-    public static final String CFG_SELFTEST_PREFIX = "selftests.container.logger";
-    public static final String CFG_TOKENDB_ALLOWED_TRANSITIONS = "tokendb.allowedTransitions";
-    public static final String CFG_OPERATIONS_ALLOWED_TRANSITIONS = "tps.operations.allowedTransitions";
-
-    public static final String CFG_PRINTBUF_FULL = "tps.printBufFull";
-    public static final String CFG_RECV_BUF_SIZE = "tps.recvBufSize";
-    public static final String CFG_AUTHS_ENABLE="auth.enable";
-    public static final String CFG_PROFILE_MAPPING_ORDER="mapping.order";
-
-    /* default values */
-    public static final String CFG_DEF_CARDMGR_INSTANCE_AID = "A0000000030000";
-    public static final String CFG_DEF_NETKEY_INSTANCE_AID = "627601FF000000";
-    public static final String CFG_DEF_NETKEY_FILE_AID = "627601FF0000";
-    public static final String CFG_DEF_NETKEY_OLD_INSTANCE_AID = "A00000000101";
-    public static final String CFG_DEF_NETKEY_OLD_FILE_AID = "A000000001";
-    public static final String CFG_DEF_APPLET_SO_PIN = "000000000000";
-
-    /* External reg values */
-
-    public static final String CFG_EXTERNAL_REG = "externalReg";
-
-    /* misc values */
-
-    public static final String OP_FORMAT_PREFEX = "op.format";
-
-
-
-    public TPS() {
-    }
-
-    public int initialize(String cfg_path) {
-
-        int rc = -1;
-
-        return rc;
-    }
-
-    public static void main(String[] args) {
-
-    }
-
-}
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/engine/TPSEngine.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/engine/TPSEngine.java
new file mode 100644
index 0000000..d3bf546
--- /dev/null
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/engine/TPSEngine.java
@@ -0,0 +1,106 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package org.dogtagpki.server.tps.engine;
+
+public class TPSEngine {
+
+    public static final String TKS_RESPONSE_STATUS = "status";
+    public static final String TKS_RESPONSE_SessionKey = "sessionKey";
+    public static final String TKS_RESPONSE_EncSessionKey = "encSessionKey";
+    public static final String TKS_RESPONSE_KEK_DesKey = "kek_wrapped_desKey";
+    public static final String TKS_RESPONSE_DRM_Trans_DesKey = "drm_trans_wrapped_desKey";
+    public static final String TKS_RESPONSE_HostCryptogram = "hostCryptogram";
+
+    public static final String CFG_DEBUG_ENABLE = "logging.debug.enable";
+    public static final String CFG_DEBUG_FILENAME = "logging.debug.filename";
+    public static final String CFG_DEBUG_LEVEL = "logging.debug.level";
+    public static final String CFG_AUDIT_ENABLE = "logging.audit.enable";
+    public static final String CFG_AUDIT_FILENAME = "logging.audit.filename";
+    public static final String CFG_SIGNED_AUDIT_FILENAME = "logging.audit.signedAuditFilename";
+    public static final String CFG_AUDIT_LEVEL = "logging.audit.level";
+    public static final String CFG_AUDIT_SIGNED = "logging.audit.logSigning";
+    public static final String CFG_AUDIT_SIGNING_CERT_NICK = "logging.audit.signedAuditCertNickname";
+    public static final String CFG_ERROR_ENABLE = "logging.error.enable";
+    public static final String CFG_ERROR_FILENAME = "logging.error.filename";
+    public static final String CFG_ERROR_LEVEL = "logging.error.level";
+    public static final String CFG_SELFTEST_ENABLE = "selftests.container.logger.enable";
+    public static final String CFG_SELFTEST_FILENAME = "selftests.container.logger.fileName";
+    public static final String CFG_SELFTEST_LEVEL = "selftests.container.logger.level";
+    public static final String CFG_CHANNEL_SEC_LEVEL = "channel.securityLevel";
+    public static final String CFG_CHANNEL_ENCRYPTION = "channel.encryption";
+    public static final String CFG_APPLET_CARDMGR_INSTANCE_AID = "applet.aid.cardmgr_instance";
+    public static final String CFG_APPLET_NETKEY_INSTANCE_AID = "applet.aid.netkey_instance";
+    public static final String CFG_APPLET_NETKEY_FILE_AID = "applet.aid.netkey_file";
+    public static final String CFG_APPLET_NETKEY_OLD_INSTANCE_AID = "applet.aid.netkey_old_instance";
+    public static final String CFG_APPLET_NETKEY_OLD_FILE_AID = "applet.aid.netkey_old_file";
+    public static final String CFG_APPLET_SO_PIN = "applet.so_pin";
+    public static final String CFG_APPLET_DELETE_NETKEY_OLD = "applet.delete_old";
+    public static final String CFG_AUDIT_SELECTED_EVENTS="logging.audit.selected.events";
+    public static final String CFG_AUDIT_NONSELECTABLE_EVENTS="logging.audit.nonselectable.events";
+    public static final String CFG_AUDIT_SELECTABLE_EVENTS="logging.audit.selectable.events";
+    public static final String CFG_AUDIT_BUFFER_SIZE = "logging.audit.buffer.size";
+    public static final String CFG_AUDIT_FLUSH_INTERVAL = "logging.audit.flush.interval";
+    public static final String CFG_AUDIT_FILE_TYPE = "logging.audit.file.type";
+    public static final String CFG_DEBUG_FILE_TYPE = "logging.debug.file.type";
+    public static final String CFG_ERROR_FILE_TYPE = "logging.error.file.type";
+    public static final String CFG_SELFTEST_FILE_TYPE = "selftests.container.logger.file.type";
+    public static final String CFG_AUDIT_PREFIX = "logging.audit";
+    public static final String CFG_ERROR_PREFIX = "logging.error";
+    public static final String CFG_DEBUG_PREFIX = "logging.debug";
+    public static final String CFG_SELFTEST_PREFIX = "selftests.container.logger";
+    public static final String CFG_TOKENDB_ALLOWED_TRANSITIONS = "tokendb.allowedTransitions";
+    public static final String CFG_OPERATIONS_ALLOWED_TRANSITIONS = "tps.operations.allowedTransitions";
+
+    public static final String CFG_PRINTBUF_FULL = "tps.printBufFull";
+    public static final String CFG_RECV_BUF_SIZE = "tps.recvBufSize";
+    public static final String CFG_AUTHS_ENABLE="auth.enable";
+    public static final String CFG_PROFILE_MAPPING_ORDER="mapping.order";
+
+    /* default values */
+    public static final String CFG_DEF_CARDMGR_INSTANCE_AID = "A0000000030000";
+    public static final String CFG_DEF_NETKEY_INSTANCE_AID = "627601FF000000";
+    public static final String CFG_DEF_NETKEY_FILE_AID = "627601FF0000";
+    public static final String CFG_DEF_NETKEY_OLD_INSTANCE_AID = "A00000000101";
+    public static final String CFG_DEF_NETKEY_OLD_FILE_AID = "A000000001";
+    public static final String CFG_DEF_APPLET_SO_PIN = "000000000000";
+
+    /* External reg values */
+
+    public static final String CFG_EXTERNAL_REG = "externalReg";
+
+    /* misc values */
+
+    public static final String OP_FORMAT_PREFEX = "op.format";
+
+
+
+    public TPSEngine() {
+    }
+
+    public int initialize(String cfg_path) {
+
+        int rc = -1;
+
+        return rc;
+    }
+
+    public static void main(String[] args) {
+
+    }
+
+}
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/processor/TPSFormatProcessor.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/processor/TPSFormatProcessor.java
index 031b55d..11688a4 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/processor/TPSFormatProcessor.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/processor/TPSFormatProcessor.java
@@ -19,6 +19,7 @@ package org.dogtagpki.server.tps.processor;
 
 import org.dogtagpki.server.tps.TPSSession;
 import org.dogtagpki.tps.msg.BeginOp;
+import org.dogtagpki.tps.msg.EndOp.TPSStatus;
 
 import com.netscape.certsrv.apps.CMS;
 import com.netscape.certsrv.base.EBaseException;
@@ -29,9 +30,9 @@ public class TPSFormatProcessor extends TPSProcessor {
     }
 
 
-    public TPS_Status Process(TPSSession session, BeginOp beginMsg) throws EBaseException {
+    public TPSStatus process(TPSSession session, BeginOp beginMsg) throws EBaseException {
         CMS.debug("In TPS_Format_Processor.Process.");
-        return super.Format(session,beginMsg);
+        return super.format(session,beginMsg);
     }
 
     public static void main(String[] args) {
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/processor/TPSProcessor.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/processor/TPSProcessor.java
index d7a571f..634cae0 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/processor/TPSProcessor.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/processor/TPSProcessor.java
@@ -18,7 +18,7 @@
 package org.dogtagpki.server.tps.processor;
 
 import org.dogtagpki.server.tps.TPSSession;
-import org.dogtagpki.server.tps.engine.TPS;
+import org.dogtagpki.server.tps.engine.TPSEngine;
 import org.dogtagpki.tps.apdu.APDU;
 import org.dogtagpki.tps.apdu.APDUResponse;
 import org.dogtagpki.tps.apdu.GetData;
@@ -27,6 +27,7 @@ import org.dogtagpki.tps.apdu.Select;
 import org.dogtagpki.tps.main.TPSBuffer;
 import org.dogtagpki.tps.main.Util;
 import org.dogtagpki.tps.msg.BeginOp;
+import org.dogtagpki.tps.msg.EndOp.TPSStatus;
 import org.dogtagpki.tps.msg.TokenPDURequest;
 import org.dogtagpki.tps.msg.TokenPDUResponse;
 
@@ -36,61 +37,14 @@ import com.netscape.certsrv.base.IConfigStore;
 
 public abstract class TPSProcessor {
 
-    public enum TPS_Status {
-        STATUS_NO_ERROR,
-        STATUS_ERROR_SNAC,
-        STATUS_ERROR_SEC_INIT_UPDATE,
-        STATUS_ERROR_CREATE_CARDMGR,
-        STATUS_ERROR_MAC_RESET_PIN_PDU,
-        STATUS_ERROR_MAC_CERT_PDU,
-        STATUS_ERROR_MAC_LIFESTYLE_PDU,
-        STATUS_ERROR_MAC_ENROLL_PDU,
-        STATUS_ERROR_READ_OBJECT_PDU,
-        STATUS_ERROR_BAD_STATUS,
-        STATUS_ERROR_CA_RESPONSE,
-        STATUS_ERROR_READ_BUFFER_OVERFLOW,
-        STATUS_ERROR_TOKEN_RESET_PIN_FAILED,
-        STATUS_ERROR_CONNECTION,
-        STATUS_ERROR_LOGIN,
-        STATUS_ERROR_DB,
-        STATUS_ERROR_TOKEN_DISABLED,
-        STATUS_ERROR_SECURE_CHANNEL,
-        STATUS_ERROR_MISCONFIGURATION,
-        STATUS_ERROR_UPGRADE_APPLET,
-        STATUS_ERROR_KEY_CHANGE_OVER,
-        STATUS_ERROR_EXTERNAL_AUTH,
-        STATUS_ERROR_DEFAULT_TOKENTYPE_NOT_FOUND,
-        STATUS_ERROR_DEFAULT_TOKENTYPE_PARAMS_NOT_FOUND,
-        STATUS_ERROR_PUBLISH,
-        STATUS_ERROR_LDAP_CONN,
-        STATUS_ERROR_DISABLED_TOKEN,
-        STATUS_ERROR_NOT_PIN_RESETABLE,
-        STATUS_ERROR_CONN_LOST,
-        STATUS_ERROR_CREATE_TUS_TOKEN_ENTRY,
-        STATUS_ERROR_NO_SUCH_TOKEN_STATE,
-        STATUS_ERROR_NO_SUCH_LOST_REASON,
-        STATUS_ERROR_UNUSABLE_TOKEN_KEYCOMPROMISE,
-        STATUS_ERROR_INACTIVE_TOKEN_NOT_FOUND,
-        STATUS_ERROR_HAS_AT_LEAST_ONE_ACTIVE_TOKEN,
-        STATUS_ERROR_CONTACT_ADMIN,
-        STATUS_ERROR_RECOVERY_IS_PROCESSED,
-        STATUS_ERROR_RECOVERY_FAILED,
-        STATUS_ERROR_NO_OPERATION_ON_LOST_TOKEN,
-        STATUS_ERROR_KEY_ARCHIVE_OFF,
-        STATUS_ERROR_NO_TKS_CONNID,
-        STATUS_ERROR_UPDATE_TOKENDB_FAILED,
-        STATUS_ERROR_REVOKE_CERTIFICATES_FAILED,
-        STATUS_ERROR_NOT_TOKEN_OWNER,
-        STATUS_ERROR_RENEWAL_IS_PROCESSED,
-        STATUS_ERROR_RENEWAL_FAILED
-    };
-
     public static final int RESULT_NO_ERROR = 0;
     public static final int RESULT_ERROR = -1;
 
     public static final int CPLC_DATA_SIZE = 47;
     public static final int CPLC_MSN_INDEX = 41;
-    public static final int CPLC_MSN_SIZE  = 4;
+    public static final int CPLC_MSN_SIZE = 4;
+
+    private boolean isExternalReg = false;
 
     public TPSProcessor() {
     }
@@ -128,7 +82,7 @@ public abstract class TPSProcessor {
 
     }
 
-    protected int SelectCardManager(TPSSession session, String prefix, String tokenType) {
+    protected int selectCardManager(TPSSession session, String prefix, String tokenType) {
         //ToDo
         return 0;
     }
@@ -152,7 +106,7 @@ public abstract class TPSProcessor {
      *
      */
 
-    protected int SelectApplet(TPSSession session, byte p1, byte p2, TPSBuffer aid)  {
+    protected int selectApplet(TPSSession session, byte p1, byte p2, TPSBuffer aid) {
 
         CMS.debug("In TPS_Processor.SelectApplet.");
         int rc = RESULT_ERROR;
@@ -165,9 +119,9 @@ public abstract class TPSProcessor {
 
         Select select_apdu = new Select(p1, p2, aid);
 
-        APDUResponse respApdu = HandleAPDURequest(session, select_apdu);
+        APDUResponse respApdu = handleAPDURequest(session, select_apdu);
 
-        if(checkTokenPDUResponse(respApdu) == true) {
+        if (checkTokenPDUResponse(respApdu) == true) {
             rc = RESULT_NO_ERROR;
         }
 
@@ -175,7 +129,7 @@ public abstract class TPSProcessor {
 
     }
 
-    protected TPSBuffer GetStatus(TPSSession session) {
+    protected TPSBuffer getStatus(TPSSession session) {
 
         CMS.debug("In TPS_Processor.GetStatus.");
 
@@ -183,19 +137,19 @@ public abstract class TPSProcessor {
 
         GetStatus get_status_apdu = new GetStatus();
 
-        APDUResponse respApdu = HandleAPDURequest(session, get_status_apdu);
+        APDUResponse respApdu = handleAPDURequest(session, get_status_apdu);
 
-        if( respApdu != null) {
+        if (respApdu != null) {
             result = respApdu.getData();
         }
 
         return result;
     }
 
-    protected APDUResponse HandleAPDURequest(TPSSession session, APDU apdu) {
+    protected APDUResponse handleAPDURequest(TPSSession session, APDU apdu) {
         APDUResponse response = null;
 
-        if(session == null || apdu == null) {
+        if (session == null || apdu == null) {
             return response;
         }
 
@@ -231,13 +185,13 @@ public abstract class TPSProcessor {
 
     }
 
-    protected TPSBuffer GetCplcData(TPSSession session) {
+    protected TPSBuffer getCplcData(TPSSession session) {
         CMS.debug("In TPS_Processor.GetData");
         TPSBuffer result = null;
 
         GetData get_data_apdu = new GetData();
 
-        APDUResponse respApdu = HandleAPDURequest(session, get_data_apdu);
+        APDUResponse respApdu = handleAPDURequest(session, get_data_apdu);
 
         result = respApdu.getData();
 
@@ -245,22 +199,23 @@ public abstract class TPSProcessor {
 
     }
 
-    protected TPS_Status Format(TPSSession session, BeginOp message) throws EBaseException {
+    protected TPSStatus format(TPSSession session, BeginOp message) throws EBaseException {
 
         IConfigStore configStore = CMS.getConfigStore();
 
         String CardManagerAID = null;
         String NetKeyAID = null;
 
-        String External_Reg_Cfg = TPS.CFG_EXTERNAL_REG + "." + "enable";
+        String External_Reg_Cfg = TPSEngine.CFG_EXTERNAL_REG + "." + "enable";
         boolean isExternalReg = false;
 
         try {
-            CardManagerAID = configStore.getString(TPS.CFG_APPLET_CARDMGR_INSTANCE_AID,
-                    TPS.CFG_DEF_CARDMGR_INSTANCE_AID);
-            NetKeyAID = configStore.getString(TPS.CFG_APPLET_NETKEY_INSTANCE_AID, TPS.CFG_DEF_NETKEY_INSTANCE_AID);
+            CardManagerAID = configStore.getString(TPSEngine.CFG_APPLET_CARDMGR_INSTANCE_AID,
+                    TPSEngine.CFG_DEF_CARDMGR_INSTANCE_AID);
+            NetKeyAID = configStore.getString(TPSEngine.CFG_APPLET_NETKEY_INSTANCE_AID,
+                    TPSEngine.CFG_DEF_NETKEY_INSTANCE_AID);
             CMS.debug("In TPS_Processor.Format. CardManagerAID: " + CardManagerAID + " NetKeyAID: " + NetKeyAID);
-            this.isExternalReg = configStore.getBoolean(External_Reg_Cfg,false);
+            this.isExternalReg = configStore.getBoolean(External_Reg_Cfg, false);
             CMS.debug("In TPS_Processor.Format isExternalReg: " + isExternalReg);
         } catch (EBaseException e1) {
             CMS.debug("In TPS_Processor.Format: Error obtaining config values.");
@@ -268,23 +223,23 @@ public abstract class TPSProcessor {
             throw new EBaseException("TPS error getting config values from config store.");
         }
 
-        TPS_Status ret = TPS_Status.STATUS_NO_ERROR;
+        TPSStatus ret = TPSStatus.STATUS_NO_ERROR;
 
         TPSBuffer aidBuf = new TPSBuffer(CardManagerAID);
 
         int select_rc = RESULT_NO_ERROR;
 
-        select_rc = SelectApplet(session, (byte) 0x04, (byte) 0x00, aidBuf);
+        select_rc = selectApplet(session, (byte) 0x04, (byte) 0x00, aidBuf);
 
-        if (select_rc ==  RESULT_ERROR) {
-            ret = TPS_Status.STATUS_ERROR_SECURE_CHANNEL;
+        if (select_rc == RESULT_ERROR) {
+            ret = TPSStatus.STATUS_ERROR_SECURE_CHANNEL;
             return ret;
         }
 
-        TPSBuffer cplc_data = GetCplcData(session);
+        TPSBuffer cplc_data = getCplcData(session);
 
         if (cplc_data == null) {
-            ret = TPS_Status.STATUS_ERROR_SECURE_CHANNEL;
+            ret = TPSStatus.STATUS_ERROR_SECURE_CHANNEL;
             return ret;
         } else {
             CMS.debug("cplc_data: " + cplc_data.toString());
@@ -298,7 +253,7 @@ public abstract class TPSProcessor {
             cuid = token_cuid.toHexString();
             CMS.debug("TPS_Processor.Format: token_cuid str: " + cuid);
         } else {
-            ret = TPS_Status.STATUS_ERROR_SECURE_CHANNEL;
+            ret = TPSStatus.STATUS_ERROR_SECURE_CHANNEL;
             return ret;
         }
 
@@ -319,14 +274,14 @@ public abstract class TPSProcessor {
 
         select_rc = RESULT_NO_ERROR;
 
-        select_rc = SelectApplet(session, (byte) 0x04, (byte) 0x00, netkeyAid);
+        select_rc = selectApplet(session, (byte) 0x04, (byte) 0x00, netkeyAid);
 
         if (select_rc == RESULT_ERROR) {
-            ret = TPS_Status.STATUS_ERROR_SECURE_CHANNEL;
+            ret = TPSStatus.STATUS_ERROR_SECURE_CHANNEL;
             return ret;
         }
 
-        TPSBuffer status = GetStatus(session);
+        TPSBuffer status = getStatus(session);
 
         byte major_version = 0x0;
         byte minor_version = 0x0;
@@ -343,10 +298,10 @@ public abstract class TPSProcessor {
                     + " app_major_version: " + app_major_version + " app_minor_version: " + app_minor_version);
 
         } else {
-            ret = TPS_Status.STATUS_ERROR_SECURE_CHANNEL;
+            ret = TPSStatus.STATUS_ERROR_SECURE_CHANNEL;
         }
 
-        if(isExternalReg) {
+        if (isExternalReg) {
             //ToDo, do some external Reg stuff along with authentication
         } else {
             //ToDo, Do some authentication
@@ -355,157 +310,6 @@ public abstract class TPSProcessor {
         return ret;
     }
 
-    public static int statusToInt(TPS_Status status) {
-
-        int result = 0;
-
-        switch (status) {
-        case STATUS_NO_ERROR:
-            result = 0;
-            break;
-        case STATUS_ERROR_SNAC:
-            result = 1;
-            break;
-        case STATUS_ERROR_SEC_INIT_UPDATE:
-            result = 2;
-            break;
-        case STATUS_ERROR_CREATE_CARDMGR:
-            result = 3;
-            break;
-        case STATUS_ERROR_MAC_RESET_PIN_PDU:
-            result = 4;
-            break;
-        case STATUS_ERROR_MAC_CERT_PDU:
-            result = 5;
-            break;
-        case STATUS_ERROR_MAC_LIFESTYLE_PDU:
-            result = 6;
-            break;
-        case STATUS_ERROR_MAC_ENROLL_PDU:
-            result = 7;
-            break;
-        case STATUS_ERROR_READ_OBJECT_PDU:
-            result = 8;
-            break;
-        case STATUS_ERROR_BAD_STATUS:
-            result = 9;
-            break;
-        case STATUS_ERROR_CA_RESPONSE:
-            result = 10;
-            break;
-        case STATUS_ERROR_READ_BUFFER_OVERFLOW:
-            result = 11;
-            break;
-        case STATUS_ERROR_TOKEN_RESET_PIN_FAILED:
-            result = 12;
-            break;
-        case STATUS_ERROR_CONNECTION:
-            result = 13;
-            break;
-        case STATUS_ERROR_LOGIN:
-            result = 14;
-            break;
-        case STATUS_ERROR_DB:
-            result = 15;
-            break;
-        case STATUS_ERROR_TOKEN_DISABLED:
-            result = 16;
-            break;
-        case STATUS_ERROR_SECURE_CHANNEL:
-            result = 17;
-            break;
-        case STATUS_ERROR_MISCONFIGURATION:
-            result = 18;
-            break;
-        case STATUS_ERROR_UPGRADE_APPLET:
-            result = 19;
-            break;
-        case STATUS_ERROR_KEY_CHANGE_OVER:
-            result = 20;
-            break;
-        case STATUS_ERROR_EXTERNAL_AUTH:
-            result = 21;
-            break;
-        case STATUS_ERROR_DEFAULT_TOKENTYPE_NOT_FOUND:
-            result = 22;
-            break;
-        case STATUS_ERROR_DEFAULT_TOKENTYPE_PARAMS_NOT_FOUND:
-            result = 23;
-            break;
-        case STATUS_ERROR_PUBLISH:
-            result = 24;
-            break;
-        case STATUS_ERROR_LDAP_CONN:
-            result = 25;
-            break;
-        case STATUS_ERROR_DISABLED_TOKEN:
-            result = 26;
-            break;
-        case STATUS_ERROR_NOT_PIN_RESETABLE:
-            result = 27;
-            break;
-        case STATUS_ERROR_CONN_LOST:
-            result = 28;
-            break;
-        case STATUS_ERROR_CREATE_TUS_TOKEN_ENTRY:
-            result = 29;
-            break;
-        case STATUS_ERROR_NO_SUCH_TOKEN_STATE:
-            result = 30;
-            break;
-        case STATUS_ERROR_NO_SUCH_LOST_REASON:
-            result = 31;
-            break;
-        case STATUS_ERROR_UNUSABLE_TOKEN_KEYCOMPROMISE:
-            result = 32;
-            break;
-        case STATUS_ERROR_INACTIVE_TOKEN_NOT_FOUND:
-            result = 33;
-            break;
-        case STATUS_ERROR_HAS_AT_LEAST_ONE_ACTIVE_TOKEN:
-            result = 34;
-            break;
-        case STATUS_ERROR_CONTACT_ADMIN:
-            result = 35;
-            break;
-        case STATUS_ERROR_RECOVERY_IS_PROCESSED:
-            result = 36;
-            break;
-        case STATUS_ERROR_RECOVERY_FAILED:
-            result = 37;
-            break;
-        case STATUS_ERROR_NO_OPERATION_ON_LOST_TOKEN:
-            result = 38;
-            break;
-        case STATUS_ERROR_KEY_ARCHIVE_OFF:
-            result = 39;
-            break;
-        case STATUS_ERROR_NO_TKS_CONNID:
-            result = 40;
-            break;
-        case STATUS_ERROR_UPDATE_TOKENDB_FAILED:
-            result = 41;
-            break;
-        case STATUS_ERROR_REVOKE_CERTIFICATES_FAILED:
-            result = 42;
-            break;
-        case STATUS_ERROR_NOT_TOKEN_OWNER:
-            result = 43;
-            break;
-        case STATUS_ERROR_RENEWAL_IS_PROCESSED:
-            result = 44;
-            break;
-        case STATUS_ERROR_RENEWAL_FAILED:
-            result = 45;
-            break;
-        default:
-            break;
-        }
-
-        return result;
-
-    }
-
     protected boolean checkTokenPDUResponse(APDUResponse response) {
 
         boolean result = false;
@@ -514,12 +318,12 @@ public abstract class TPSProcessor {
             return result;
 
         byte sw1 = response.getSW1();
-        byte sw2 = response.GetSW2();
+        byte sw2 = response.getSW2();
 
         int int1 = sw1 & 0xff;
         int int2 = sw2 & 0xff;
 
-        CMS.debug("checkTokenPDUResponse: sw1: " +  "0x" + Util.intToHex(int1) + " sw2: " + "0x" + Util.intToHex(int2));
+        CMS.debug("checkTokenPDUResponse: sw1: " + "0x" + Util.intToHex(int1) + " sw2: " + "0x" + Util.intToHex(int2));
 
         if (sw1 == (byte) 0x90 && sw2 == 0x0)
             result = true;
@@ -527,19 +331,15 @@ public abstract class TPSProcessor {
         return result;
     }
 
-
-    private boolean isExternalReg = false;
-
     public boolean getIsExternalReg() {
         return isExternalReg;
     }
 
-    public static void main(String[] args) {
+    public TPSStatus process(TPSSession session, BeginOp beginMsg) throws EBaseException {
+        return TPSStatus.STATUS_NO_ERROR;
     }
 
-    public TPS_Status Process(TPSSession session, BeginOp beginMsg) throws EBaseException {
-        return TPS_Status.STATUS_NO_ERROR;
+    public static void main(String[] args) {
     }
 
-
 }
-- 
1.8.3.1

