|
| 1 | +#ifndef JUB_GPC_APDU_SDK_H |
| 2 | +#define JUB_GPC_APDU_SDK_H |
| 3 | +// |
| 4 | +// Generic helper definitions for shared library support |
| 5 | +#if defined _MSC_VER || defined __CYGWIN__ |
| 6 | + #define JUB_COINCORE_DLL_IMPORT extern "C" __declspec(dllimport) |
| 7 | + #define JUB_COINCORE_DLL_EXPORT extern "C" __declspec(dllexport) |
| 8 | + #define JUB_COINCORE_DLL_LOCAL |
| 9 | +#else |
| 10 | + #if __GNUC__ >= 4 |
| 11 | + #define JUB_COINCORE_DLL_IMPORT __attribute__((visibility("default"))) |
| 12 | + #define JUB_COINCORE_DLL_EXPORT __attribute__((visibility("default"))) |
| 13 | + #define JUB_COINCORE_DLL_LOCAL __attribute__((visibility("internal"))) |
| 14 | + #else |
| 15 | + #define JUB_COINCORE_DLL_IMPORT |
| 16 | + #define JUB_COINCORE_DLL_EXPORT |
| 17 | + #define JUB_COINCORE_DLL_LOCAL |
| 18 | + #endif // #if __GNUC__ >= 4 |
| 19 | +#endif // #if defined _MSC_VER || defined __CYGWIN__ |
| 20 | + |
| 21 | +// Tag to deprecate functions and methods. |
| 22 | +// Gives a compiler warning when they are used. |
| 23 | +#if defined _MSC_VER || defined __CYGWIN__ |
| 24 | + #define BC_DEPRECATED __declspec(deprecated) |
| 25 | +#else |
| 26 | + #if __GNUC__ >= 4 |
| 27 | + #define JUB_DEPRECATED __attribute__((deprecated)) |
| 28 | + #else |
| 29 | + #define JUB_DEPRECATED |
| 30 | + #endif // #if __GNUC__ >= 4 |
| 31 | +#endif // #if defined _MSC_VER || defined __CYGWIN__ |
| 32 | + |
| 33 | +// Avoid namespace conflict between boost::placeholders and std::placeholders. |
| 34 | +#define BOOST_BIND_NO_PLACEHOLDERS |
| 35 | + |
| 36 | +// Define so we can have better visibility of lcov exclusion ranges. |
| 37 | +#define LCOV_EXCL_START(text) |
| 38 | +#define LCOV_EXCL_STOP() |
| 39 | + |
| 40 | +#if defined(_WIN32) |
| 41 | + #define HID_MODE |
| 42 | +#elif defined(__APPLE__) |
| 43 | +// see https://sourceforge.net/p/predef/mailman/message/34497133/ |
| 44 | + #include <TargetConditionals.h> |
| 45 | + #if TARGET_OS_OSX // mac osx |
| 46 | + #define HID_MODE |
| 47 | + #elif TARGET_OS_IOS // ios |
| 48 | + #define BLE_MODE |
| 49 | + #define NFC_MODE |
| 50 | + #endif // #if TARGET_OS_OSX |
| 51 | +#elif defined(__ANDROID__) |
| 52 | + #define BLE_MODE |
| 53 | + #define NFC_MODE |
| 54 | +#else //other |
| 55 | + #define HID_MODE |
| 56 | +#endif // #if defined(_WIN32) |
| 57 | + |
| 58 | +#define JUBR_OK 0x00000000UL |
| 59 | + |
| 60 | +#define JUBR_ERROR 0x00000001UL |
| 61 | +#define JUBR_HOST_MEMORY 0x00000002UL |
| 62 | +#define JUBR_ARGUMENTS_BAD 0x00000003UL |
| 63 | +#define JUBR_IMPL_NOT_SUPPORT 0x00000004UL |
| 64 | +#define JUBR_MEMORY_NULL_PTR 0x00000005UL |
| 65 | +#define JUBR_CONTEXT_NOT_SATISFIED 0x00000006UL |
| 66 | + |
| 67 | +#define JUBR_INVALID_MEMORY_PTR 0x00000008UL |
| 68 | +#define JUBR_REPEAT_MEMORY_PTR 0x00000009UL |
| 69 | +#define JUBR_BUFFER_TOO_SMALL 0x0000000AUL |
| 70 | + |
| 71 | + |
| 72 | +/* === Library typedef: === */ |
| 73 | +#ifndef IN |
| 74 | + #define IN |
| 75 | +#endif // #ifndef IN |
| 76 | + |
| 77 | +#ifndef OUT |
| 78 | + #define OUT |
| 79 | +#endif // #ifndef OUT |
| 80 | + |
| 81 | +#ifndef INOUT |
| 82 | + #define INOUT |
| 83 | +#endif // #ifndef INOUT |
| 84 | + |
| 85 | +#define JUB_TRUE 1 |
| 86 | +#define JUB_FALSE 0 |
| 87 | + |
| 88 | +#ifndef JUB_DISABLE_TRUE_FALSE |
| 89 | + #ifndef FALSE |
| 90 | + #define FALSE JUB_FALSE |
| 91 | + #endif // #ifndef FALSE |
| 92 | + |
| 93 | + #ifndef TRUE |
| 94 | + #define TRUE JUB_TRUE |
| 95 | + #endif // #ifndef TRUE |
| 96 | +#endif // #ifndef JUB_DISABLE_TRUE_FALSE |
| 97 | + |
| 98 | +/* an unsigned 8-bit value */ |
| 99 | +typedef unsigned char JUB_BYTE; |
| 100 | + |
| 101 | +/* an unsigned 8-bit character */ |
| 102 | +typedef JUB_BYTE JUB_UCHAR; |
| 103 | + |
| 104 | +/* an unsigned/signed 8-bit character, decide by complie*/ |
| 105 | +typedef char JUB_CHAR; |
| 106 | + |
| 107 | +/* an 8-bit UTF-8 character */ |
| 108 | +typedef JUB_BYTE JUB_UTF8UCHAR; |
| 109 | + |
| 110 | +/* a BYTE-sized Boolean flag */ |
| 111 | +typedef JUB_BYTE JUB_BBOOL; |
| 112 | + |
| 113 | +/* an unsigned value, at least 32 bits long */ |
| 114 | +typedef unsigned long int JUB_ULONG; |
| 115 | + |
| 116 | +/* a signed value, the same size as a JUB_ULONG */ |
| 117 | +typedef signed long int JUB_LONG; |
| 118 | + |
| 119 | +typedef JUB_BYTE JUB_UINT8; |
| 120 | + |
| 121 | +typedef unsigned int JUB_UINT32; |
| 122 | + |
| 123 | +typedef unsigned short JUB_UINT16; |
| 124 | + |
| 125 | +/* uint64 */ |
| 126 | +typedef unsigned long long JUB_UINT64; |
| 127 | + |
| 128 | +/* signed uint64 */ |
| 129 | +typedef signed long long JUB_INT64; |
| 130 | + |
| 131 | +#define JUB_PTR * |
| 132 | +typedef JUB_CHAR JUB_PTR JUB_CHAR_PTR; |
| 133 | +typedef JUB_CHAR_PTR JUB_PTR JUB_CHAR_PTR_PTR; |
| 134 | +typedef const JUB_CHAR JUB_PTR JUB_CHAR_CPTR; |
| 135 | +typedef const JUB_BYTE JUB_PTR JUB_BYTE_CPTR; |
| 136 | + |
| 137 | +typedef JUB_BYTE JUB_PTR JUB_BYTE_PTR; |
| 138 | +typedef const JUB_BYTE JUB_PTR JUB_BYTE_CPTR; |
| 139 | +typedef JUB_UCHAR JUB_PTR JUB_UCHAR_PTR; |
| 140 | +typedef JUB_UTF8UCHAR JUB_PTR JUB_UTF8UCHAR_PTR; |
| 141 | +typedef JUB_ULONG JUB_PTR JUB_ULONG_PTR; |
| 142 | +typedef JUB_UINT16 JUB_PTR JUB_UINT16_PTR; |
| 143 | +typedef JUB_UINT32 JUB_PTR JUB_UINT32_PTR; |
| 144 | +typedef JUB_UINT64 JUB_PTR JUB_UINT64_PTR; |
| 145 | +typedef void JUB_PTR JUB_VOID_PTR; |
| 146 | + |
| 147 | +/* Pointer to a JUB_VOID_PTR-- i.e., pointer to pointer to void */ |
| 148 | +typedef JUB_VOID_PTR JUB_PTR JUB_VOID_PTR_PTR; |
| 149 | + |
| 150 | +typedef JUB_ULONG JUB_RV; |
| 151 | + |
| 152 | +#ifdef __cplusplus |
| 153 | +extern "C" { |
| 154 | +#endif // #ifdef __cplusplus |
| 155 | + |
| 156 | + |
| 157 | +/** |
| 158 | + * SharedInfo. |
| 159 | +*/ |
| 160 | +typedef struct JUB_GPC_SCP11_SHAREDINFO { |
| 161 | + JUB_CHAR_PTR scpID; // SCP identifier and parameters in hex string |
| 162 | + JUB_CHAR_PTR keyUsage; // Key Usage Qualifier in hex string, for SCP11c, it's '3C' |
| 163 | + JUB_CHAR_PTR keyType; // Key Type in hex string, for SCP11c, it's '88' (AES) |
| 164 | + JUB_CHAR_PTR keyLength; // Key Length in hex string, it's '10' |
| 165 | + JUB_CHAR_PTR hostID; // hostID in hex string, eg, "8080808080808080" |
| 166 | + JUB_CHAR_PTR cardGroupID; // is the content of tag '5F20' (subject identifier) in CERT.SD.ECKA, eg, "6a75626974657277616c6c6574" |
| 167 | +} GPC_SCP11_SHAREDINFO; |
| 168 | + |
| 169 | + |
| 170 | +/***************************************************************************** |
| 171 | +* @function name : JUB_FreeMemory |
| 172 | +* @in param : memPtr |
| 173 | +* @out param : |
| 174 | +* @last change : |
| 175 | +*****************************************************************************/ |
| 176 | +JUB_RV JUB_FreeMemory(IN JUB_CHAR_CPTR memPtr); |
| 177 | + |
| 178 | + |
| 179 | +/***************************************************************************** |
| 180 | + * @function name : JUB_GPC_TLVDecode |
| 181 | + * @in param : tlv - TLV |
| 182 | + * tag - tag |
| 183 | + * @out param : value - value |
| 184 | + * @last change : |
| 185 | +*****************************************************************************/ |
| 186 | +JUB_COINCORE_DLL_EXPORT |
| 187 | +JUB_RV JUB_GPC_TLVDecode(IN JUB_CHAR_CPTR tlv, |
| 188 | + OUT JUB_ULONG_PTR tag, |
| 189 | + OUT JUB_CHAR_PTR_PTR value); |
| 190 | + |
| 191 | + |
| 192 | +/***************************************************************************** |
| 193 | + * @function name : JUB_GPC_Initialize |
| 194 | + * @in param : sharedInfo - SCP11 sharedInfo |
| 195 | + * oce_crt - OCE certificate in hex string |
| 196 | + * e_rk - Ephemeral private key of the OCE used for key agreement in hex string, ecdsa private key, length = 32 |
| 197 | + * @out param : |
| 198 | + * @last change : |
| 199 | +*****************************************************************************/ |
| 200 | +JUB_COINCORE_DLL_EXPORT |
| 201 | +JUB_RV JUB_GPC_Initialize(IN GPC_SCP11_SHAREDINFO &sharedInfo, |
| 202 | + IN JUB_CHAR_CPTR oce_crt, |
| 203 | + IN JUB_CHAR_CPTR oce_rk); |
| 204 | + |
| 205 | + |
| 206 | +/***************************************************************************** |
| 207 | + * @function name : JUB_GPC_Finalize |
| 208 | + * @in param : |
| 209 | + * @out param : |
| 210 | + * @last change : |
| 211 | +*****************************************************************************/ |
| 212 | +JUB_COINCORE_DLL_EXPORT |
| 213 | +JUB_RV JUB_GPC_Finalize(); |
| 214 | + |
| 215 | + |
| 216 | +/***************************************************************************** |
| 217 | + * @function name : JUB_GPC_BuildMutualAuthData |
| 218 | + * @in param : |
| 219 | + * @out param : apduData - APDU data for MutualAuth cmd in hex string |
| 220 | + * @last change : |
| 221 | + * @ condition: JUB_GPC_Initialize() has been called first. |
| 222 | +*****************************************************************************/ |
| 223 | +JUB_COINCORE_DLL_EXPORT |
| 224 | +JUB_RV JUB_GPC_BuildMutualAuthData(OUT JUB_CHAR_PTR_PTR apduData); |
| 225 | + |
| 226 | + |
| 227 | +/***************************************************************************** |
| 228 | + * @function name : JUB_GPC_OpenSecureChannel |
| 229 | + * @in param : response - response from Mutual Auth command in hex string |
| 230 | + * @out param : |
| 231 | + * @last change : |
| 232 | + * @ condition: JUB_GPC_Initialize() has been called first. |
| 233 | +*****************************************************************************/ |
| 234 | +JUB_COINCORE_DLL_EXPORT |
| 235 | +JUB_RV JUB_GPC_OpenSecureChannel(IN JUB_CHAR_CPTR response); |
| 236 | + |
| 237 | + |
| 238 | +/***************************************************************************** |
| 239 | + * @function name : JUB_GPC_BuildAPDU |
| 240 | + * @in param : cla - Class byte of the command message |
| 241 | + * ins - Instruction byte of the command message |
| 242 | + * p1 - Reference control parameter 1 |
| 243 | + * p2 - Reference control parameter 2 |
| 244 | + * data - APDU data in hex string |
| 245 | + * @out param : apdu - APDU in plain text |
| 246 | + * @last change : |
| 247 | +*****************************************************************************/ |
| 248 | +JUB_COINCORE_DLL_EXPORT |
| 249 | +JUB_RV JUB_GPC_BuildAPDU(IN JUB_ULONG cla, IN JUB_ULONG ins, |
| 250 | + IN JUB_ULONG p1, IN JUB_ULONG p2, |
| 251 | + IN JUB_CHAR_CPTR data, |
| 252 | + OUT JUB_CHAR_PTR_PTR apdu); |
| 253 | + |
| 254 | + |
| 255 | +/***************************************************************************** |
| 256 | + * @function name : JUB_GPC_ParseAPDUResponse |
| 257 | + * @in param : response - command response in hex string |
| 258 | + * @out param : pwRet - APDU response |
| 259 | + * resp - APDU response data |
| 260 | + * @last change : |
| 261 | +*****************************************************************************/ |
| 262 | +JUB_COINCORE_DLL_EXPORT |
| 263 | +JUB_RV JUB_GPC_ParseAPDUResponse(IN JUB_CHAR_CPTR response, |
| 264 | + OUT JUB_UINT16_PTR pwRet, |
| 265 | + OUT JUB_CHAR_PTR_PTR resp); |
| 266 | + |
| 267 | + |
| 268 | +/***************************************************************************** |
| 269 | + * @function name : JUB_GPC_BuildSafeAPDU |
| 270 | + * @in param : cla - Class byte of the command message |
| 271 | + * ins - Instruction byte of the command message |
| 272 | + * p1 - Reference control parameter 1 |
| 273 | + * p2 - Reference control parameter 2 |
| 274 | + * data - APDU data in hex string |
| 275 | + * @out param : safeApdu - APDU in cipher text |
| 276 | + * @last change : |
| 277 | + * @ condition: JUB_GPC_Initialize() has been called first. |
| 278 | +*****************************************************************************/ |
| 279 | +JUB_COINCORE_DLL_EXPORT |
| 280 | +JUB_RV JUB_GPC_BuildSafeAPDU(IN JUB_ULONG cla, IN JUB_ULONG ins, |
| 281 | + IN JUB_ULONG p1, IN JUB_ULONG p2, |
| 282 | + IN JUB_CHAR_CPTR data, |
| 283 | + OUT JUB_CHAR_PTR_PTR safeApdu); |
| 284 | + |
| 285 | + |
| 286 | +/***************************************************************************** |
| 287 | + * @function name : JUB_GPC_ParseSafeAPDUResponse |
| 288 | + * @in param : response - command response in hex string |
| 289 | + * @out param : pwRet - APDU response |
| 290 | + * decResp - APDU response data in plain text |
| 291 | + * @last change : |
| 292 | + * @ condition: JUB_GPC_Initialize() has been called first. |
| 293 | +*****************************************************************************/ |
| 294 | +JUB_COINCORE_DLL_EXPORT |
| 295 | +JUB_RV JUB_GPC_ParseSafeAPDUResponse(IN JUB_CHAR_CPTR response, |
| 296 | + OUT JUB_UINT16_PTR pwRet, |
| 297 | + OUT JUB_CHAR_PTR_PTR decResp); |
| 298 | + |
| 299 | + |
| 300 | +/***************************************************************************** |
| 301 | + * @function name : JUB_GPC_ParseCertificate |
| 302 | + * @in param : cert - certificate of a device |
| 303 | + * @out param : sn - Certificate Serial Number |
| 304 | + * : subjectID - Subject Identifier in hex |
| 305 | + * @last change : |
| 306 | + *****************************************************************************/ |
| 307 | +JUB_COINCORE_DLL_EXPORT |
| 308 | +JUB_RV JUB_GPC_ParseCertificate(IN JUB_CHAR_CPTR cert, |
| 309 | + OUT JUB_CHAR_PTR_PTR sn, |
| 310 | + OUT JUB_CHAR_PTR_PTR subjectID); |
| 311 | + |
| 312 | +#ifdef __cplusplus |
| 313 | +} |
| 314 | +#endif // #ifdef __cplusplus |
| 315 | +#endif /* JUB_GPC_APDU_SDK_H */ |
0 commit comments