components/coolkey/patches/16-cky_factory.c.patch
author Stephen Gaul Jr <steve.gaul@oracle.com>
Tue, 12 Jul 2016 17:34:11 -0700
changeset 6401 8e624b116c1d
permissions -rw-r--r--
PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices 22017764 Add Coolkey v1.1.0 to Userland consolidation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6401
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
     1
Upstream fixes already included in the latest community updates to coolkey v1.1.0
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
     2
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
     3
Addresses APDU applet issues with card management.
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
     4
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
     5
--- ORIGINAL/./src/libckyapplet/cky_factory.c	2016-06-24 16:08:04.366910071 -0400
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
     6
+++ ././src/libckyapplet/cky_factory.c	2016-06-24 12:38:22.645520956 -0400
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
     7
@@ -25,12 +25,13 @@
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
     8
  * special commands can be issued at any time 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
     9
  */
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    10
 CKYStatus
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    11
-CKYAPDUFactory_SelectFile(CKYAPDU *apdu, const CKYBuffer *AID)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    12
+CKYAPDUFactory_SelectFile(CKYAPDU *apdu, CKYByte p1, CKYByte p2,
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    13
+			  const CKYBuffer *AID)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    14
 {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    15
     CKYAPDU_SetCLA(apdu, CKY_CLASS_ISO7816);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    16
     CKYAPDU_SetINS(apdu, CKY_INS_SELECT_FILE);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    17
-    CKYAPDU_SetP1(apdu, 0x04);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    18
-    CKYAPDU_SetP2(apdu, 0x00);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    19
+    CKYAPDU_SetP1(apdu, p1);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    20
+    CKYAPDU_SetP2(apdu, p2);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    21
     return CKYAPDU_SetSendDataBuffer(apdu, AID);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    22
 }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    23
 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    24
@@ -61,7 +62,6 @@
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    25
     CKYAPDU_SetP2(apdu, 0x7f);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    26
     return CKYAPDU_SetReceiveLen(apdu, CKY_SIZE_GET_CPLCDATA);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    27
 }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    28
-
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    29
 /*
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    30
  * applet commands must be issued with the appplet selected.
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    31
  */
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    32
@@ -131,6 +131,7 @@
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    33
     return ret;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    34
 }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    35
 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    36
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    37
 CKYStatus
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    38
 CKYAPDUFactory_ComputeCryptFinal(CKYAPDU *apdu, CKYByte keyNumber, 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    39
 		CKYByte location, const CKYBuffer *data, const CKYBuffer *sig)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    40
@@ -182,6 +183,49 @@
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    41
 }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    42
 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    43
 CKYStatus
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    44
+CKYAPDUFactory_ComputeECCKeyAgreementOneStep(CKYAPDU *apdu, CKYByte keyNumber,
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    45
+                             CKYByte location,
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    46
+                            const CKYBuffer *publicData, const CKYBuffer *secretKey)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    47
+{
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    48
+    CKYStatus ret      = CKYINVALIDARGS;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    49
+    CKYSize   len;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    50
+    CKYBuffer buf;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    51
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    52
+    if (!publicData)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    53
+        return ret;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    54
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    55
+    if (!(len = CKYBuffer_Size(publicData)))
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    56
+        return ret;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    57
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    58
+    CKYAPDU_SetCLA(apdu, CKY_CLASS_COOLKEY);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    59
+    CKYAPDU_SetINS(apdu, CKY_INS_COMPUTE_ECC_KEY_AGREEMENT);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    60
+    CKYAPDU_SetP1(apdu, keyNumber);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    61
+    CKYAPDU_SetP2(apdu, CKY_CIPHER_ONE_STEP);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    62
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    63
+    CKYBuffer_InitEmpty(&buf);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    64
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    65
+    ret = CKYBuffer_Reserve(&buf, 3);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    66
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    67
+    if (ret == CKYSUCCESS)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    68
+        ret = CKYBuffer_AppendChar(&buf, location);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    69
+    if (ret == CKYSUCCESS)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    70
+        ret = CKYBuffer_AppendShort(&buf, (unsigned short)len);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    71
+    if (ret == CKYSUCCESS)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    72
+        ret = CKYAPDU_SetSendDataBuffer(apdu, &buf);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    73
+    if (ret == CKYSUCCESS)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    74
+        ret = CKYAPDU_AppendSendDataBuffer(apdu, publicData);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    75
+    if (ret == CKYSUCCESS && secretKey && 0 < (len = CKYBuffer_Size(secretKey))) {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    76
+        CKYBuffer_Resize(&buf,2);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    77
+        CKYBuffer_SetShort(&buf, 0, (unsigned short)len);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    78
+        ret = CKYAPDU_AppendSendDataBuffer(apdu, &buf);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    79
+        if (ret == CKYSUCCESS)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    80
+            ret = CKYAPDU_AppendSendDataBuffer(apdu, secretKey);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    81
+    }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    82
+    CKYBuffer_FreeData(&buf);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    83
+    return ret;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    84
+}
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    85
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    86
+CKYStatus
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    87
 CKYAPDUFactory_ComputeCryptOneStep(CKYAPDU *apdu, CKYByte keyNumber, CKYByte mode,
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    88
 				CKYByte direction, CKYByte location,
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    89
 				const CKYBuffer *idata, const CKYBuffer *sig)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    90
@@ -190,8 +234,11 @@
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    91
     CKYSize   len;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    92
     CKYBuffer buf;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    93
 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    94
-    if (!idata || !(len = CKYBuffer_Size(idata)) || location != CKY_DL_APDU)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    95
-    	return ret;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    96
+    if (!idata)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    97
+        return ret;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    98
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
    99
+    if (!(len = CKYBuffer_Size(idata)) && location != CKY_DL_OBJECT)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   100
+        return ret;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   101
 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   102
     CKYAPDU_SetCLA(apdu, CKY_CLASS_COOLKEY);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   103
     CKYAPDU_SetINS(apdu, CKY_INS_COMPUTE_CRYPT);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   104
@@ -314,8 +361,6 @@
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   105
     return CKYSUCCESS;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   106
 }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   107
 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   108
-/* Future add WriteObject */
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   109
-
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   110
 CKYStatus
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   111
 CKYAPDUFactory_CreateObject(CKYAPDU *apdu, unsigned long objectID, CKYSize size,
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   112
     unsigned short readACL, unsigned short writeACL, unsigned short deleteACL)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   113
@@ -383,6 +428,49 @@
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   114
 }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   115
 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   116
 CKYStatus
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   117
+CKYAPDUFactory_ComputeECCSignatureOneStep(CKYAPDU *apdu, CKYByte keyNumber,
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   118
+                             CKYByte location,
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   119
+                            const CKYBuffer *idata, const CKYBuffer *sig)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   120
+{
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   121
+    CKYStatus ret      = CKYINVALIDARGS;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   122
+    CKYSize   len;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   123
+    CKYBuffer buf;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   124
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   125
+    if (!idata)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   126
+        return ret;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   127
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   128
+    if (!(len = CKYBuffer_Size(idata)) && location != CKY_DL_OBJECT)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   129
+        return ret;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   130
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   131
+    CKYAPDU_SetCLA(apdu, CKY_CLASS_COOLKEY);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   132
+    CKYAPDU_SetINS(apdu, CKY_INS_COMPUTE_ECC_SIGNATURE);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   133
+    CKYAPDU_SetP1(apdu, keyNumber);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   134
+    CKYAPDU_SetP2(apdu, CKY_CIPHER_ONE_STEP);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   135
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   136
+    CKYBuffer_InitEmpty(&buf);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   137
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   138
+    ret = CKYBuffer_Reserve(&buf, 3);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   139
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   140
+    if (ret == CKYSUCCESS)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   141
+        ret = CKYBuffer_AppendChar(&buf, location);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   142
+    if (ret == CKYSUCCESS)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   143
+        ret = CKYBuffer_AppendShort(&buf, (unsigned short)len);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   144
+    if (ret == CKYSUCCESS)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   145
+        ret = CKYAPDU_SetSendDataBuffer(apdu, &buf);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   146
+    if (ret == CKYSUCCESS)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   147
+        ret = CKYAPDU_AppendSendDataBuffer(apdu, idata);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   148
+    if (ret == CKYSUCCESS && sig && 0 < (len = CKYBuffer_Size(sig))) {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   149
+        CKYBuffer_Resize(&buf,2);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   150
+        CKYBuffer_SetShort(&buf, 0, (unsigned short)len);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   151
+        ret = CKYAPDU_AppendSendDataBuffer(apdu, &buf);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   152
+        if (ret == CKYSUCCESS)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   153
+            ret = CKYAPDU_AppendSendDataBuffer(apdu, sig);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   154
+    }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   155
+    CKYBuffer_FreeData(&buf);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   156
+    return ret;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   157
+}
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   158
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   159
+CKYStatus
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   160
 CKYAPDUFactory_ReadObject(CKYAPDU *apdu, unsigned long objectID, 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   161
 						CKYOffset offset, CKYByte size)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   162
 {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   163
@@ -419,6 +507,58 @@
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   164
 }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   165
 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   166
 CKYStatus
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   167
+CKYAPDUFactory_WriteObject(CKYAPDU *apdu, unsigned long objectID,
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   168
+                                    CKYOffset offset,CKYSize size,CKYBuffer *data)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   169
+{
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   170
+    CKYBuffer buf;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   171
+    CKYStatus ret = CKYSUCCESS;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   172
+    unsigned short dataSize = 0;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   173
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   174
+    CKYAPDU_SetCLA(apdu, CKY_CLASS_COOLKEY);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   175
+    CKYAPDU_SetINS(apdu, CKY_INS_WRITE_OBJ);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   176
+    CKYAPDU_SetP1(apdu, 0x00);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   177
+    CKYAPDU_SetP2(apdu, 0x00);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   178
+    CKYBuffer_InitEmpty(&buf);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   179
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   180
+    dataSize = (unsigned short) CKYBuffer_Size(data);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   181
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   182
+    if(!dataSize) {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   183
+        ret = CKYINVALIDARGS;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   184
+        goto fail;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   185
+    }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   186
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   187
+    ret = CKYBuffer_AppendLong(&buf,objectID);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   188
+    if (ret != CKYSUCCESS) {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   189
+        goto fail;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   190
+    }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   191
+    ret = CKYBuffer_AppendLong(&buf,offset);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   192
+    if (ret != CKYSUCCESS) {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   193
+        goto fail;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   194
+    }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   195
+    ret = CKYBuffer_AppendChar(&buf, size);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   196
+    if (ret != CKYSUCCESS) {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   197
+        goto fail;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   198
+    }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   199
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   200
+    ret = CKYAPDU_SetSendDataBuffer(apdu,&buf);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   201
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   202
+    if (ret != CKYSUCCESS) {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   203
+        goto fail;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   204
+    }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   205
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   206
+    ret = CKYAPDU_AppendSendDataBuffer(apdu, data);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   207
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   208
+    if (ret != CKYSUCCESS) {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   209
+        goto fail;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   210
+    }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   211
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   212
+fail:
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   213
+    CKYBuffer_FreeData(&buf);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   214
+    return ret;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   215
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   216
+}
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   217
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   218
+CKYStatus
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   219
 CKYAPDUFactory_ListObjects(CKYAPDU *apdu, CKYByte sequence)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   220
 {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   221
     CKYAPDU_SetCLA(apdu, CKY_CLASS_COOLKEY);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   222
@@ -519,11 +659,11 @@
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   223
 }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   224
 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   225
 CKYStatus
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   226
-CACAPDUFactory_SignDecrypt(CKYAPDU *apdu, const CKYBuffer *data)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   227
+CACAPDUFactory_SignDecrypt(CKYAPDU *apdu, CKYByte type, const CKYBuffer *data)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   228
 {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   229
     CKYAPDU_SetCLA(apdu, CKY_CLASS_ISO7816);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   230
     CKYAPDU_SetINS(apdu, CAC_INS_SIGN_DECRYPT);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   231
-    CKYAPDU_SetP1(apdu, 0x00);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   232
+    CKYAPDU_SetP1(apdu, type);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   233
     CKYAPDU_SetP2(apdu, 0x00);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   234
     return CKYAPDU_SetSendDataBuffer(apdu, data);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   235
 }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   236
@@ -539,6 +679,35 @@
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   237
 }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   238
 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   239
 CKYStatus
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   240
+CACAPDUFactory_ReadFile(CKYAPDU *apdu, unsigned short offset, 	
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   241
+					CKYByte type, CKYByte count)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   242
+{
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   243
+    CKYStatus ret;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   244
+    CKYBuffer buf;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   245
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   246
+    CKYBuffer_InitEmpty(&buf);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   247
+    CKYAPDU_SetCLA(apdu, CKY_CLASS_GLOBAL_PLATFORM);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   248
+    CKYAPDU_SetINS(apdu, CAC_INS_READ_FILE);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   249
+    CKYAPDU_SetP1(apdu, (offset >> 8) & 0xff);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   250
+    CKYAPDU_SetP2(apdu, offset & 0xff);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   251
+    ret = CKYBuffer_Reserve(&buf, 2);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   252
+    if (ret != CKYSUCCESS) {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   253
+	    goto fail;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   254
+    }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   255
+    ret = CKYBuffer_AppendChar(&buf, type);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   256
+    if (ret != CKYSUCCESS) {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   257
+	    goto fail;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   258
+    }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   259
+    ret = CKYBuffer_AppendChar(&buf, count);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   260
+    if (ret != CKYSUCCESS) {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   261
+	    goto fail;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   262
+    } 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   263
+    ret = CKYAPDU_SetSendDataBuffer(apdu, &buf);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   264
+fail:
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   265
+    CKYBuffer_FreeData(&buf);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   266
+    return ret;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   267
+}
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   268
+CKYStatus
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   269
 CACAPDUFactory_GetProperties(CKYAPDU *apdu)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   270
 {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   271
     CKYAPDU_SetCLA(apdu, CKY_CLASS_ISO7816);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   272
@@ -549,7 +718,7 @@
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   273
 }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   274
 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   275
 CKYStatus
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   276
-CACAPDUFactory_VerifyPIN(CKYAPDU *apdu, const char *pin)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   277
+CACAPDUFactory_VerifyPIN(CKYAPDU *apdu, CKYByte keyRef, const char *pin)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   278
 {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   279
     CKYStatus ret;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   280
     CKYSize size;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   281
@@ -557,7 +726,7 @@
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   282
     CKYAPDU_SetCLA(apdu, CKY_CLASS_ISO7816);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   283
     CKYAPDU_SetINS(apdu, CAC_INS_VERIFY_PIN);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   284
     CKYAPDU_SetP1(apdu, 0x00);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   285
-    CKYAPDU_SetP2(apdu, 0x00);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   286
+    CKYAPDU_SetP2(apdu, keyRef);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   287
     /* no pin, send an empty buffer */
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   288
     if (!pin) {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   289
     	return CKYAPDU_SetReceiveLen(apdu, 0);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   290
@@ -578,3 +747,63 @@
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   291
     return ret;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   292
 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   293
 }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   294
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   295
+CKYStatus
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   296
+PIVAPDUFactory_SignDecrypt(CKYAPDU *apdu, CKYByte chain, CKYByte alg, 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   297
+			   CKYByte key, int len, const CKYBuffer *data)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   298
+{
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   299
+    CKYStatus ret;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   300
+    CKYAPDU_SetCLA(apdu, chain ? CKY_CLASS_ISO7816_CHAIN :
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   301
+				  CKY_CLASS_ISO7816);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   302
+    CKYAPDU_SetINS(apdu, PIV_INS_GEN_AUTHENTICATE);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   303
+    CKYAPDU_SetP1(apdu, alg);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   304
+    CKYAPDU_SetP2(apdu, key);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   305
+    ret =  CKYAPDU_SetSendDataBuffer(apdu, data);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   306
+    if (ret == CKYSUCCESS && chain == 0 && len != 0) {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   307
+	if (len >= 256) len = 0;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   308
+	ret = CKYAPDU_AppendReceiveLen(apdu, len);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   309
+    }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   310
+    return ret;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   311
+}
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   312
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   313
+CKYStatus
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   314
+PIVAPDUFactory_GetData(CKYAPDU *apdu, const CKYBuffer *object, CKYByte count)
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   315
+{
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   316
+    CKYStatus ret;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   317
+    CKYBuffer buf;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   318
+    CKYByte objectSize;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   319
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   320
+    CKYBuffer_InitEmpty(&buf);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   321
+    CKYAPDU_SetCLA(apdu, CKY_CLASS_ISO7816);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   322
+    CKYAPDU_SetINS(apdu, 0xcb);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   323
+    CKYAPDU_SetP1(apdu, 0x3f);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   324
+    CKYAPDU_SetP2(apdu, 0xff);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   325
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   326
+    objectSize = CKYBuffer_Size(object);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   327
+
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   328
+    ret = CKYBuffer_Reserve(&buf, 2+objectSize);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   329
+    if (ret != CKYSUCCESS) {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   330
+	    goto fail;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   331
+    }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   332
+    ret = CKYBuffer_AppendChar(&buf, 0x5c);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   333
+    if (ret != CKYSUCCESS) {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   334
+	    goto fail;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   335
+    }
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   336
+    ret = CKYBuffer_AppendChar(&buf, objectSize);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   337
+    if (ret != CKYSUCCESS) {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   338
+	    goto fail;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   339
+    } 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   340
+    ret = CKYBuffer_AppendCopy(&buf, object);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   341
+    if (ret != CKYSUCCESS) {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   342
+	    goto fail;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   343
+    } 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   344
+    ret = CKYAPDU_SetSendDataBuffer(apdu, &buf);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   345
+    if (ret != CKYSUCCESS) {
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   346
+	    goto fail;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   347
+    } 
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   348
+    ret = CKYAPDU_AppendReceiveLen(apdu, count);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   349
+fail:
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   350
+    CKYBuffer_FreeData(&buf);
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   351
+    return ret;
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   352
+}
8e624b116c1d PSARC/2016/219 Coolkey PKCS#11 provider for smartcard devices
Stephen Gaul Jr <steve.gaul@oracle.com>
parents:
diff changeset
   353
+