lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /***************************************************************/
|
| 2 | //
|
| 3 | //²Î¼û LPA½Ó¿ÚÎĵµV0.1 SGP.22, ·µ»ØJSON
|
| 4 | //
|
| 5 | /***************************************************************/
|
| 6 |
|
| 7 | #include <stdio.h>
|
| 8 | #include <stdlib.h>
|
| 9 | #include <string.h>
|
| 10 | #include <ctype.h>
|
| 11 | #include <sys/time.h>
|
| 12 | #include <termios.h>
|
| 13 |
|
| 14 | #include "lpa_inner.h"
|
| 15 |
|
| 16 |
|
| 17 | #define LPA_AUTH_DATA_LEN 512
|
| 18 |
|
| 19 | /***************************************************************/
|
| 20 | //
|
| 21 | //euiccChallenge:¿¨·µ»ØµÄAPDU,²»º¬9000
|
| 22 | //euiccInfo1: ¿¨·µ»ØµÄAPDU,²»º¬9000
|
| 23 | //smdpAddress:¼¤»îÂëÖÐsdmpµØÖ·
|
| 24 | //·µ»Øjson
|
| 25 | //
|
| 26 | /***************************************************************/
|
| 27 | char *InitiateAuthentication(char *euiccChallenge, char *euiccInfo1, char *smdpAddress)
|
| 28 | {
|
| 29 | char *js_data = NULL;
|
| 30 | unsigned char clg_byte[APDU_BYTE_LEN] = {0};
|
| 31 | unsigned char info1_byte[APDU_BYTE_LEN] = {0};
|
| 32 | int clg_len = 0;
|
| 33 | int info1_len = 0;
|
| 34 | char *clg_b64 = NULL;
|
| 35 | char *info1_b64 = NULL;
|
| 36 |
|
| 37 | clg_len = string2bytes(euiccChallenge, clg_byte, strlen(euiccChallenge));
|
| 38 | clg_b64 = lpa_base64_encode(clg_byte, clg_len);
|
| 39 | if (clg_b64 == NULL)
|
| 40 | return NULL;
|
| 41 |
|
| 42 | info1_len = string2bytes(euiccInfo1, info1_byte, strlen(euiccInfo1));
|
| 43 | info1_b64 = lpa_base64_encode(info1_byte, info1_len);
|
| 44 | if (info1_b64 == NULL) {
|
| 45 | free(clg_b64);
|
| 46 | return NULL;
|
| 47 | }
|
| 48 |
|
| 49 | js_data = malloc(LPA_AUTH_DATA_LEN);
|
| 50 | if (js_data != NULL) {
|
| 51 | memset(js_data, 0, LPA_AUTH_DATA_LEN);
|
| 52 | snprintf(js_data, LPA_AUTH_DATA_LEN, "{\"euiccChallenge\":\"%s\",\"euiccInfo1\":\"%s\",\"smdpAddress\":\"%s\"}",
|
| 53 | clg_b64, info1_b64, smdpAddress);
|
| 54 | //printf("js_data:-%s-\n", js_data);
|
| 55 | }
|
| 56 |
|
| 57 | free(clg_b64);
|
| 58 | free(info1_b64);
|
| 59 | return js_data;
|
| 60 | }
|
| 61 |
|
| 62 | /***************************************************************/
|
| 63 | //
|
| 64 | //transactionId: smdp InitiateAuthentication½Ó¿Ú·µ»Ø
|
| 65 | //authSerRespHex:¿¨·µ»ØµÄAPDU,²»º¬9000
|
| 66 | //
|
| 67 | /***************************************************************/
|
| 68 | char *AuthenticateClient(
|
| 69 | char *transactionId,
|
| 70 | char *authSerRespHex)
|
| 71 | {
|
| 72 | char *ac_js = NULL;
|
| 73 | unsigned char *as_byte = NULL;
|
| 74 | int as_byte_len = 0;
|
| 75 | int ashex_len = strlen(authSerRespHex);
|
| 76 | char *as_b64 = NULL;
|
| 77 | int as_b64_len = 0;
|
| 78 |
|
| 79 | as_byte = malloc(ashex_len/2 + 1);
|
| 80 | if (as_byte == NULL) {
|
| 81 | return NULL;
|
| 82 | }
|
| 83 | memset(as_byte, 0, ashex_len/2 + 1);
|
| 84 |
|
| 85 | as_byte_len = string2bytes(authSerRespHex, as_byte, ashex_len);
|
| 86 | as_b64 = lpa_base64_encode(as_byte, as_byte_len);
|
| 87 | if (as_b64 == NULL) {
|
| 88 | free(as_byte);
|
| 89 | return NULL;
|
| 90 | }
|
| 91 | as_b64_len = strlen(as_b64);
|
| 92 |
|
| 93 | ac_js = malloc(as_b64_len + 100);
|
| 94 | if (ac_js != NULL) {
|
| 95 | memset(ac_js, 0, as_b64_len + 100);
|
| 96 | snprintf(ac_js, as_b64_len + 100, "{\"transactionId\":\"%s\",\"authenticateServerResponse\":\"%s\"}",
|
| 97 | transactionId, as_b64);
|
| 98 | //printf("js_data:-%s-\n", ac_js);
|
| 99 | }
|
| 100 |
|
| 101 | free(as_byte);
|
| 102 | free(as_b64);
|
| 103 | return ac_js;
|
| 104 | }
|
| 105 |
|
| 106 |
|
| 107 | /***************************************************************/
|
| 108 | //
|
| 109 | //transactionId: smdp AuthenticateClient½Ó¿Ú·µ»Ø
|
| 110 | //predlRespHex: prepareDownloadResponseHex ¿¨·µ»ØµÄAPDU,²»º¬9000
|
| 111 | //
|
| 112 | /***************************************************************/
|
| 113 | char *GetBoundProfilePackage (
|
| 114 | char *transactionId,
|
| 115 | char *predlRespHex)
|
| 116 | {
|
| 117 | char *bpp_js = NULL;
|
| 118 | unsigned char *pdl_byte = NULL;
|
| 119 | int pdl_byte_len = 0;
|
| 120 | int pdlhex_len = strlen(predlRespHex);
|
| 121 | char *pdl_b64 = NULL;
|
| 122 | int pdl_b64_len = 0;
|
| 123 |
|
| 124 | pdl_byte = malloc(pdlhex_len/2 + 1);
|
| 125 | if (pdl_byte == NULL) {
|
| 126 | return NULL;
|
| 127 | }
|
| 128 | memset(pdl_byte, 0, pdlhex_len/2 + 1);
|
| 129 |
|
| 130 | pdl_byte_len = string2bytes(predlRespHex, pdl_byte, pdlhex_len);
|
| 131 | pdl_b64 = lpa_base64_encode(pdl_byte, pdl_byte_len);
|
| 132 | if (pdl_b64 == NULL) {
|
| 133 | free(pdl_byte);
|
| 134 | return NULL;
|
| 135 | }
|
| 136 | pdl_b64_len = strlen(pdl_b64);
|
| 137 |
|
| 138 | bpp_js = malloc(pdl_b64_len + 100);
|
| 139 | if (bpp_js != NULL) {
|
| 140 | memset(bpp_js, 0, pdl_b64_len + 100);
|
| 141 | snprintf(bpp_js, pdl_b64_len + 100, "{\"transactionId\":\"%s\",\"prepareDownloadResponse\":\"%s\"}",
|
| 142 | transactionId, pdl_b64);
|
| 143 | //printf("js_data:-%s-\n", bpp_js);
|
| 144 | }
|
| 145 |
|
| 146 | free(pdl_byte);
|
| 147 | free(pdl_b64);
|
| 148 | return bpp_js;
|
| 149 | }
|
| 150 |
|
| 151 |
|
| 152 | /***************************************************************/
|
| 153 | //
|
| 154 | //pnfHex: pendingNotification ¿¨·µ»ØµÄAPDU,²»º¬9000
|
| 155 | //
|
| 156 | /***************************************************************/
|
| 157 | char *HandleNotification(char *pnfHex)
|
| 158 | {
|
| 159 | char *bpp_js = NULL;
|
| 160 | unsigned char *pdl_byte = NULL;
|
| 161 | int pdl_byte_len = 0;
|
| 162 | int pdlhex_len = strlen(pnfHex);
|
| 163 | char *pdl_b64 = NULL;
|
| 164 | int pdl_b64_len = 0;
|
| 165 |
|
| 166 | pdl_byte = malloc(pdlhex_len/2 + 1);
|
| 167 | if (pdl_byte == NULL) {
|
| 168 | return NULL;
|
| 169 | }
|
| 170 | memset(pdl_byte, 0, pdlhex_len/2 + 1);
|
| 171 |
|
| 172 | pdl_byte_len = string2bytes(pnfHex, pdl_byte, pdlhex_len);
|
| 173 | pdl_b64 = lpa_base64_encode(pdl_byte, pdl_byte_len);
|
| 174 | if (pdl_b64 == NULL) {
|
| 175 | free(pdl_byte);
|
| 176 | return NULL;
|
| 177 | }
|
| 178 | pdl_b64_len = strlen(pdl_b64);
|
| 179 |
|
| 180 | bpp_js = malloc(pdl_b64_len + 100);
|
| 181 | if (bpp_js != NULL) {
|
| 182 | memset(bpp_js, 0, pdl_b64_len + 100);
|
| 183 | snprintf(bpp_js, pdl_b64_len + 100,
|
| 184 | "{\"header\":{\"functionExecutionStatus\":{\"status\":\"Executed-Success\"}},\"pendingNotification\":\"%s\"}", pdl_b64);
|
| 185 | //printf("js_data:-%s-\n", bpp_js);
|
| 186 | }
|
| 187 |
|
| 188 | free(pdl_byte);
|
| 189 | free(pdl_b64);
|
| 190 | return bpp_js;
|
| 191 | }
|
| 192 |
|
| 193 |
|