summaryrefslogtreecommitdiffstats
path: root/base/common/src/com
diff options
context:
space:
mode:
authorJack Magne <jmagne@dhcp-16-213.sjc.redhat.com>2013-09-10 12:00:41 -0700
committerJack Magne <jmagne@dhcp-16-213.sjc.redhat.com>2014-03-05 10:03:52 -0800
commit1d0f670f02c6e8bbbf8dcd432d7fb37dd1a30731 (patch)
tree571ac81f4834551ebaa2fca46bf2b63f724c76f1 /base/common/src/com
parent2adf17fbcd106bbf09513a30bd320505afc85c01 (diff)
First cut at Java TPS Buffer class and APDU class.
1. Also simple framework for working with APDU command. 2. Implemented a few APDU commands in TPS_Processor class. 3. Can now attempt a format operation with TPS client. The code can performa a few apdu's talking to the client and return a success "EndOp" apdu to terminate the conversation. 4. APDU are being encoded/decoded properly to appease tpsclient. More info. 1. Patch is large but most of it consists of many similar apdu and msg classes. 2. APDU and msg classes are now bare bones and may need more work. Will address when class is needed. 3. A test tpsclient script call it (format.tst) to test this out is as follows: op=var_set name=ra_host value=localhost op=var_set name=ra_port value=8080 op=var_set name=ra_uri value=/tps/tps op=token_set cuid=40906145C76224192D2B msn=0120304 app_ver=6FBBC105 key_info=0101 major_ver=1 minor_ver=1 op=token_set auth_key=404142434445464748494a4b4c4d4e4f op=token_set mac_key=404142434445464748494a4b4c4d4e4f op=token_set kek_key=404142434445464748494a4b4c4d4e4f op=ra_format uid=jmagne pwd=redhat new_pin=rehat num_threads=1 op=exit 4: Execute as follows: tpsclient < format.tst
Diffstat (limited to 'base/common/src/com')
-rw-r--r--base/common/src/com/netscape/certsrv/tps/TPSConnection.java98
-rw-r--r--base/common/src/com/netscape/certsrv/tps/TPSMessage.java101
2 files changed, 0 insertions, 199 deletions
diff --git a/base/common/src/com/netscape/certsrv/tps/TPSConnection.java b/base/common/src/com/netscape/certsrv/tps/TPSConnection.java
deleted file mode 100644
index 00e201c25..000000000
--- a/base/common/src/com/netscape/certsrv/tps/TPSConnection.java
+++ /dev/null
@@ -1,98 +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 com.netscape.certsrv.tps;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintStream;
-
-/**
- * @author Endi S. Dewata <edewata@redhat.com>
- */
-public class TPSConnection {
-
- public InputStream in;
- public PrintStream out;
- public boolean chunked;
-
- public TPSConnection(InputStream in, OutputStream out) {
- this(in, out, false);
- }
-
- public TPSConnection(InputStream in, OutputStream out, boolean chunked) {
- this.in = in;
- this.out = new PrintStream(out);
- this.chunked = chunked;
- }
-
- public TPSMessage read() throws IOException {
-
- StringBuilder sb = new StringBuilder();
- int b;
-
- // read the first parameter
- while ((b = in.read()) >= 0) {
- char c = (char)b;
- if (c == '&') break;
- sb.append(c);
- }
-
- if (b < 0) throw new IOException("Unexpected end of stream");
-
- // parse message size
- String nvp = sb.toString();
- String[] s = nvp.split("=");
- int size = Integer.parseInt(s[1]);
-
- sb.append('&');
-
- // read the rest of message
- for (int i=0; i<size; i++) {
-
- b = in.read();
- if (b < 0) throw new IOException("Unexpected end of stream");
-
- char c = (char)b;
- sb.append(c);
- }
-
- // parse the entire message
- return new TPSMessage(sb.toString());
- }
-
- public void write(TPSMessage message) throws IOException {
- String s = message.encode();
-
- if (chunked) {
- // send message length + EOL
- out.print(Integer.toHexString(s.length()));
- out.print("\r\n");
- }
-
- // send message
- out.print(s);
-
- if (chunked) {
- // send EOL
- out.print("\r\n");
- }
-
- out.flush();
- }
-}
diff --git a/base/common/src/com/netscape/certsrv/tps/TPSMessage.java b/base/common/src/com/netscape/certsrv/tps/TPSMessage.java
deleted file mode 100644
index c25459b2a..000000000
--- a/base/common/src/com/netscape/certsrv/tps/TPSMessage.java
+++ /dev/null
@@ -1,101 +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 com.netscape.certsrv.tps;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-/**
- * @author Endi S. Dewata <edewata@redhat.com>
- */
-public class TPSMessage {
-
- Map<String, String> map = new LinkedHashMap<String, String>();
-
- public TPSMessage() {
- }
-
- public TPSMessage(String message) {
- decode(message);
- }
-
- public TPSMessage(Map<String, String> map) {
- this.map.putAll(map);
- }
-
- public void put(String key, String value) {
- map.put(key, value);
- }
-
- public void put(String key, Integer value) {
- map.put(key, value.toString());
- }
-
- public void put(String key, byte[] bytes) {
- StringBuilder sb = new StringBuilder();
-
- for (byte b : bytes) {
- sb.append("%");
- sb.append(String.format("%02X", b));
- }
-
- map.put(key, sb.toString());
- }
-
- public void decode(String message) {
-
- for (String nvp : message.split("&")) {
- String[] s = nvp.split("=");
-
- String key = s[0];
- String value = s[1];
-
- // skip message size
- if (key.equals("s")) continue;
-
- map.put(key, value);
- }
- }
-
- public String encode() {
-
- StringBuilder sb = new StringBuilder();
-
- // encode message type
- String type = map.get("msg_type");
- sb.append("msg_type=" + type);
-
- // encode other parameters
- for (String key : map.keySet()) {
-
- if (key.equals("msg_type")) continue;
-
- String value = map.get(key);
- sb.append("&" + key + "=" + value);
- }
-
- String message = sb.toString();
-
- // encode message_size
- return "s=" + message.length() + "&" + message;
- }
-
- public String toString() {
- return map.toString();
- }
-}