summaryrefslogtreecommitdiffstats
path: root/base/common/src/org
diff options
context:
space:
mode:
authorJack Magne <jmagne@dhcp-16-213.sjc.redhat.com>2014-03-06 11:29:10 -0800
committerJack Magne <jmagne@dhcp-16-213.sjc.redhat.com>2014-03-20 10:56:58 -0700
commit905b83fe6359a64029e697989312d49c33dd6f88 (patch)
treea3b026658d610cf40133872609aabc8369f566ce /base/common/src/org
parenta79a66e826b150d92f407af2111b564201a8b05f (diff)
downloadpki-905b83fe6359a64029e697989312d49c33dd6f88.tar.gz
pki-905b83fe6359a64029e697989312d49c33dd6f88.tar.xz
pki-905b83fe6359a64029e697989312d49c33dd6f88.zip
Further work on TPS Processor, format operation.
1. Method to calculate the token type. 2. Some added convenience methods to get various config params for the Format operation. 3. More progress for the format operation up until we attempt to upgrade the applet. 4. Added TPSException that holds a message and end op return code. Can be used to throw from anywhere and the return code makes it back to the client. 5. Error handling. 6. Get rid of TPSFormatProcessor class, for now. 7. More error handling. 8. Moving around some constants.
Diffstat (limited to 'base/common/src/org')
-rw-r--r--base/common/src/org/dogtagpki/tps/apdu/APDUResponse.java31
-rw-r--r--base/common/src/org/dogtagpki/tps/main/TPSException.java50
-rw-r--r--base/common/src/org/dogtagpki/tps/msg/BeginOp.java2
-rw-r--r--base/common/src/org/dogtagpki/tps/msg/TPSMessage.java46
4 files changed, 97 insertions, 32 deletions
diff --git a/base/common/src/org/dogtagpki/tps/apdu/APDUResponse.java b/base/common/src/org/dogtagpki/tps/apdu/APDUResponse.java
index d0fc64b33..ef25cd204 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/APDUResponse.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/APDUResponse.java
@@ -22,6 +22,9 @@
package org.dogtagpki.tps.apdu;
import org.dogtagpki.tps.main.TPSBuffer;
+import org.dogtagpki.tps.main.Util;
+
+import com.netscape.certsrv.apps.CMS;
public class APDUResponse extends APDU {
@@ -65,6 +68,34 @@ public class APDUResponse extends APDU {
}
+ //Not every non 0x90 0x00 is considered fatal, return result
+ public boolean checkResult() {
+ boolean result = false;
+
+ byte sw1 = getSW1();
+ byte sw2 = getSW2();
+
+ int int1 = sw1 & 0xff;
+ int int2 = sw2 & 0xff;
+
+ CMS.debug("APDUResponse.checkResult : sw1: " + "0x" + Util.intToHex(int1) + " sw2: " + "0x"
+ + Util.intToHex(int2));
+
+ if (sw1 == (byte) 0x90 && sw2 == 0x0)
+ result = true;
+
+ return result;
+ }
+
+ //Get the two byte apdu return code
+ byte[] getResultBytes() {
+ byte[] result = new byte[2];
+
+ result[0] = getSW1();
+ result[1] = getSW2();
+ return result;
+ }
+
public static void main(String args[]) {
APDUResponse resp = new APDUResponse();
diff --git a/base/common/src/org/dogtagpki/tps/main/TPSException.java b/base/common/src/org/dogtagpki/tps/main/TPSException.java
new file mode 100644
index 000000000..ee3ef5793
--- /dev/null
+++ b/base/common/src/org/dogtagpki/tps/main/TPSException.java
@@ -0,0 +1,50 @@
+// --- 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.tps.main;
+
+import org.dogtagpki.tps.msg.EndOp.TPSStatus;
+
+import com.netscape.certsrv.base.EBaseException;
+
+public class TPSException extends EBaseException {
+
+ private static final long serialVersionUID = -678878301521643436L;
+ private TPSStatus status;
+
+ public TPSException(String msg) {
+ super(msg);
+ status = TPSStatus.STATUS_ERROR_CONTACT_ADMIN;
+ }
+
+ public TPSException(String msg, TPSStatus theStatus) {
+
+ super(msg);
+ status = theStatus;
+
+ }
+
+ public TPSStatus getStatus() {
+ return status;
+ }
+
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/base/common/src/org/dogtagpki/tps/msg/BeginOp.java b/base/common/src/org/dogtagpki/tps/msg/BeginOp.java
index 2d2586c30..de12660f2 100644
--- a/base/common/src/org/dogtagpki/tps/msg/BeginOp.java
+++ b/base/common/src/org/dogtagpki/tps/msg/BeginOp.java
@@ -40,7 +40,7 @@ public class BeginOp extends TPSMessage {
return intToOpType(opTypeInt);
}
- public Map<String, String> GetExtensions() {
+ public Map<String, String> getExtensions() {
return extensions;
}
diff --git a/base/common/src/org/dogtagpki/tps/msg/TPSMessage.java b/base/common/src/org/dogtagpki/tps/msg/TPSMessage.java
index f6939d374..036c44c36 100644
--- a/base/common/src/org/dogtagpki/tps/msg/TPSMessage.java
+++ b/base/common/src/org/dogtagpki/tps/msg/TPSMessage.java
@@ -17,6 +17,7 @@
// --- END COPYRIGHT BLOCK ---
package org.dogtagpki.tps.msg;
+import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -401,7 +402,7 @@ public class TPSMessage {
return result;
}
- private TPSMessage createMessage() {
+ private TPSMessage createMessage() throws IOException {
TPSMessage result = null;
@@ -416,13 +417,7 @@ public class TPSMessage {
String decoded = null;
Map<String, String> extsMap = null;
if (extensions != null) {
- try {
- decoded = Util.uriDecode(extensions);
- } catch (Exception e) {
- CMS.debug("TPSMessage.createMessage: Util.URIDecode failed: " + e);
- return null;
- }
-
+ decoded = Util.uriDecode(extensions);
System.out.println("decoded extensions : " + decoded);
extsMap = decodeToMap(decoded);
@@ -431,15 +426,11 @@ public class TPSMessage {
int msg_type_int = 0;
int op_type_int = 0;
- try {
- if (msg_type != null) {
- msg_type_int = Integer.parseInt(msg_type);
- }
- if (op_type != null) {
- op_type_int = Integer.parseInt(op_type);
- }
- } catch (NumberFormatException e) {
- CMS.debug("TPSMessage.createMessage: Error obtaining msg_type or op_type from incoming message.");
+ if (msg_type != null) {
+ msg_type_int = Integer.parseInt(msg_type);
+ }
+ if (op_type != null) {
+ op_type_int = Integer.parseInt(op_type);
}
MsgType val = intToMsgType(msg_type_int);
@@ -481,29 +472,22 @@ public class TPSMessage {
case MSG_TOKEN_PDU_RESPONSE:
result = new TokenPDUResponse(encode());
break;
- case MSG_UNDEFINED:
- return result;
default:
- return result;
-
+ //Something was garbled with the message coming in
+ throw new IOException("TPSMessage.createMessage: Can't create incoming TPS message!");
}
return result;
}
- public static TPSMessage createMessage(String message) {
+ public static TPSMessage createMessage(String message) throws IOException {
CMS.debug("TPSMessage.createMessage: message: " + message);
- TPSMessage new_msg = null;
- TPSMessage returnMsg = null;
-
- new_msg = new TPSMessage(message);
-
- returnMsg = new_msg.createMessage();
+ TPSMessage new_msg = new TPSMessage(message);
- return returnMsg;
+ return new_msg.createMessage();
}
public MsgType getType() {
@@ -512,11 +496,11 @@ public class TPSMessage {
return intToMsgType(res);
}
- public static void main(String[] args) {
+ public static void main(String[] args) throws IOException {
String encoded = "s=204&msg_type=2&operation=5&extensions=tokenType%3DuserKey%26clientVersion%3DESC+1%2E0%2E1%26tokenATR%3D3BFF1400FF8131FE458025A00000005657534336353003003B%26statusUpdate%3Dtrue%26extendedLoginRequest%3Dtrue%26";
BeginOp testMessage = (BeginOp) TPSMessage.createMessage(encoded);
System.out.println("Encoded msg: " + testMessage.encode());
- System.out.println("msg Extensions: " + testMessage.GetExtensions());
+ System.out.println("msg Extensions: " + testMessage.getExtensions());
}