add es9p_base64_trim for some dp+ return \n in base64 message

This commit is contained in:
estkme 2024-05-09 13:47:07 +08:00
parent 3a32229c1c
commit 2eb3e45e0b
2 changed files with 62 additions and 13 deletions

View file

@ -13,6 +13,23 @@ static const char *lpa_header[] = {
NULL,
};
static void es9p_base64_trim(char *str)
{
char *p = str;
while (*p)
{
if (*p == '\n' || *p == '\r' || *p == ' ' || *p == '\t')
{
memmove(p, p + 1, strlen(p));
}
else
{
p++;
}
}
}
static int es9p_trans_ex(struct euicc_ctx *ctx, const char *url, const char *url_postfix, uint32_t *rcode, char **str_rx, const char *str_tx)
{
int fret = 0;
@ -260,7 +277,17 @@ int es9p_initiate_authentication_r(struct euicc_ctx *ctx, char **transaction_id,
const char oobj[] = {0, 0, 0, 0, 0};
void **optr[] = {(void **)&ctx->http._internal.transaction_id, (void **)&resp->b64_serverSigned1, (void **)&resp->b64_serverSignature1, (void **)&resp->b64_euiccCiPKIdToBeUsed, (void **)&resp->b64_serverCertificate, NULL};
return es9p_trans_json(ctx, ctx->http.server_address, "/gsma/rsp2/es9plus/initiateAuthentication", ikey, idata, okey, oobj, optr);
if (es9p_trans_json(ctx, ctx->http.server_address, "/gsma/rsp2/es9plus/initiateAuthentication", ikey, idata, okey, oobj, optr))
{
return -1;
}
es9p_base64_trim(resp->b64_serverSigned1);
es9p_base64_trim(resp->b64_serverSignature1);
es9p_base64_trim(resp->b64_euiccCiPKIdToBeUsed);
es9p_base64_trim(resp->b64_serverCertificate);
return 0;
}
int es9p_get_bound_profile_package_r(struct euicc_ctx *ctx, char **b64_bound_profile_package, const char *server_address, const char *transaction_id, const char *b64_prepare_download_response)
@ -271,7 +298,14 @@ int es9p_get_bound_profile_package_r(struct euicc_ctx *ctx, char **b64_bound_pro
const char oobj[] = {0};
void **optr[] = {(void **)b64_bound_profile_package, NULL};
return es9p_trans_json(ctx, ctx->http.server_address, "/gsma/rsp2/es9plus/getBoundProfilePackage", ikey, idata, okey, oobj, optr);
if (es9p_trans_json(ctx, ctx->http.server_address, "/gsma/rsp2/es9plus/getBoundProfilePackage", ikey, idata, okey, oobj, optr))
{
return -1;
}
es9p_base64_trim(*b64_bound_profile_package);
return 0;
}
int es9p_authenticate_client_r(struct euicc_ctx *ctx, struct es10b_prepare_download_param *resp, const char *server_address, const char *transaction_id, const char *b64_authenticate_server_response)
@ -282,7 +316,17 @@ int es9p_authenticate_client_r(struct euicc_ctx *ctx, struct es10b_prepare_downl
const char oobj[] = {0, 0, 0, 0};
void **optr[] = {(void **)&resp->b64_profileMetadata, (void **)&resp->b64_smdpSigned2, (void **)&resp->b64_smdpSignature2, (void **)&resp->b64_smdpCertificate, NULL};
return es9p_trans_json(ctx, ctx->http.server_address, "/gsma/rsp2/es9plus/authenticateClient", ikey, idata, okey, oobj, optr);
if (es9p_trans_json(ctx, ctx->http.server_address, "/gsma/rsp2/es9plus/authenticateClient", ikey, idata, okey, oobj, optr))
{
return -1;
}
es9p_base64_trim(resp->b64_profileMetadata);
es9p_base64_trim(resp->b64_smdpSigned2);
es9p_base64_trim(resp->b64_smdpSignature2);
es9p_base64_trim(resp->b64_smdpCertificate);
return 0;
}
int es9p_cancel_session_r(struct euicc_ctx *ctx, const char *server_address, const char *transaction_id, const char *b64_cancel_session_response)
@ -290,7 +334,12 @@ int es9p_cancel_session_r(struct euicc_ctx *ctx, const char *server_address, con
const char *ikey[] = {"transactionId", "cancelSessionResponse", NULL};
const char *idata[] = {ctx->http._internal.transaction_id, b64_cancel_session_response, NULL};
return es9p_trans_json(ctx, ctx->http.server_address, "/gsma/rsp2/es9plus/cancelSession", ikey, idata, NULL, NULL, NULL);
if (es9p_trans_json(ctx, ctx->http.server_address, "/gsma/rsp2/es9plus/cancelSession", ikey, idata, NULL, NULL, NULL))
{
return -1;
}
return 0;
}
int es11_authenticate_client_r(struct euicc_ctx *ctx, char ***smdp_list, const char *server_address, const char *transaction_id, const char *b64_authenticate_server_response)

View file

@ -77,7 +77,7 @@ void main_fini_euicc()
}
#ifdef WIN32
char** warg_to_arg(const int wargc, wchar_t **wargv)
static char **warg_to_arg(const int wargc, wchar_t **wargv)
{
char **argv = malloc(wargc * sizeof(char *));
if (argv == NULL)
@ -105,14 +105,6 @@ char** warg_to_arg(const int wargc, wchar_t **wargv)
int main(int argc, char **argv)
{
#ifdef WIN32
argv = warg_to_arg(argc, CommandLineToArgvW(GetCommandLineW(), &argc));
if (argv == NULL)
{
return -1;
}
#endif
int ret = 0;
memset(&euicc_ctx, 0, sizeof(euicc_ctx));
@ -125,6 +117,14 @@ int main(int argc, char **argv)
euicc_ctx.apdu.interface = &euicc_driver_interface_apdu;
euicc_ctx.http.interface = &euicc_driver_interface_http;
#ifdef WIN32
argv = warg_to_arg(argc, CommandLineToArgvW(GetCommandLineW(), &argc));
if (argv == NULL)
{
return -1;
}
#endif
ret = applet_entry(argc, argv, applets);
main_fini_euicc();