Blob Blame History Raw
From 618a17ad33363633c6589c4ce7170c34f21bf459 Mon Sep 17 00:00:00 2001
From: Jack Magne <jmagne@dhcp-16-206.sjc.redhat.com>
Date: Tue, 15 Nov 2016 17:37:07 -0800
Subject: [PATCH] Change lifecycle at end of enrollment if it is not already
 set.

TPS throws "err=6" when attempting to format and enroll G&D Cards.
https://bugzilla.redhat.com/show_bug.cgi?id=1320283

This fix addresses this bug , but also:
Fixes this issue:

Applet upgrade during rekey operation results in formatted token.

 Also, it takes care of a related issue where the new apdu needed for the
lifecycle state causes the testing tool "tpslcient" to seg fault.
The fix here is a minimal fix to have tpsclient return an error when it gets
this apdu it can't handle, instead of crashing.

(cherry picked from commit 4027d3caa872f2950dae0b3d2208c0c54ceb4a4c)
(cherry picked from commit fbb7cf7d70263aa63274a41ecba235bc87c961f0)
---
 base/common/src/org/dogtagpki/tps/apdu/APDU.java   |  3 +-
 .../org/dogtagpki/tps/apdu/GetLifecycleAPDU.java   | 35 +++++++++++++
 2 files changed, 37 insertions(+), 1 deletions(-)
 create mode 100644 base/common/src/org/dogtagpki/tps/apdu/GetLifecycleAPDU.java

diff --git a/base/common/src/org/dogtagpki/tps/apdu/APDU.java b/base/common/src/org/dogtagpki/tps/apdu/APDU.java
index 86f07ee..390252f 100644
--- a/base/common/src/org/dogtagpki/tps/apdu/APDU.java
+++ b/base/common/src/org/dogtagpki/tps/apdu/APDU.java
@@ -56,7 +56,8 @@ public abstract class APDU {
         APDU_IMPORT_KEY_ENC,
         APDU_SET_ISSUERINFO,
         APDU_GET_ISSUERINFO,
-        APDU_GENERATE_KEY_ECC
+        APDU_GENERATE_KEY_ECC,
+        APDU_GET_LIFECYCLE
     }
 
     protected byte cla;
diff --git a/base/common/src/org/dogtagpki/tps/apdu/GetLifecycleAPDU.java b/base/common/src/org/dogtagpki/tps/apdu/GetLifecycleAPDU.java
new file mode 100644
index 0000000..6f55b01
--- /dev/null
+++ b/base/common/src/org/dogtagpki/tps/apdu/GetLifecycleAPDU.java
@@ -0,0 +1,35 @@
+package org.dogtagpki.tps.apdu;
+
+import org.dogtagpki.tps.main.TPSBuffer;
+
+
+public class GetLifecycleAPDU extends APDU {
+    public GetLifecycleAPDU() {
+        setCLA((byte) 0xB0);
+        setINS((byte) 0xf2);
+        setP1((byte) 0x0);
+        setP2((byte) 0x0);
+    }
+
+    @Override
+    public Type getType()
+    {
+        return Type.APDU_GET_LIFECYCLE;
+    }
+
+    @Override
+    public TPSBuffer getEncoding()
+    {
+        TPSBuffer encoding = new TPSBuffer();
+
+        encoding.add(cla);
+        encoding.add(ins);
+        encoding.add(p1);
+        encoding.add(p2);
+        encoding.add((byte) 0x01);
+
+        return encoding;
+    } /* Encode */
+
+
+}
-- 
1.8.3.1