From d769879933b5e672e817e6082e6edb20f5924a96 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 8 Mar 2016 18:19:51 -0500 Subject: [PATCH] Added httpc AddTrustedRootCA. --- libctru/include/3ds/services/httpc.h | 17 +++++++++++++++++ libctru/source/services/httpc.c | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/libctru/include/3ds/services/httpc.h b/libctru/include/3ds/services/httpc.h index a0009fd..b169616 100644 --- a/libctru/include/3ds/services/httpc.h +++ b/libctru/include/3ds/services/httpc.h @@ -121,6 +121,14 @@ Result httpcGetResponseStatusCode(httpcContext *context, u32* out, u64 delay); */ Result httpcGetResponseHeader(httpcContext *context, char* name, char* value, u32 valuebuf_maxsize); +/** + * @brief Adds a trusted RootCA cert to a HTTP context. + * @param context Context to use. + * @param cert Pointer to DER cert. + * @param certsize Size of the DER cert. + */ +Result httpcAddTrustedRootCA(httpcContext *context, u8 *cert, u32 certsize); + /** * @brief Downloads data from the HTTP context into a buffer. * The *entire* content must be downloaded before using httpcCloseContext(), otherwise httpcCloseContext() will hang. @@ -252,3 +260,12 @@ Result HTTPC_GetResponseHeader(Handle handle, Handle contextHandle, char* name, */ Result HTTPC_GetResponseStatusCode(Handle handle, Handle contextHandle, u32* out); +/** + * @brief Adds a trusted RootCA cert to a HTTP context. + * @param handle HTTPC service handle to use. + * @param contextHandle HTTP context handle to use. + * @param cert Pointer to DER cert. + * @param certsize Size of the DER cert. + */ +Result HTTPC_AddTrustedRootCA(Handle handle, Handle contextHandle, u8 *cert, u32 certsize); + diff --git a/libctru/source/services/httpc.c b/libctru/source/services/httpc.c index 25e1ff1..6b3f03e 100644 --- a/libctru/source/services/httpc.c +++ b/libctru/source/services/httpc.c @@ -164,6 +164,11 @@ Result httpcGetResponseStatusCode(httpcContext *context, u32* out, u64 delay) return HTTPC_GetResponseStatusCode(context->servhandle, context->httphandle, out); } +Result httpcAddTrustedRootCA(httpcContext *context, u8 *cert, u32 certsize) +{ + return HTTPC_AddTrustedRootCA(context->servhandle, context->httphandle, cert, certsize); +} + Result httpcDownloadData(httpcContext *context, u8* buffer, u32 size, u32 *downloadedsize) { Result ret=0; @@ -439,3 +444,19 @@ Result HTTPC_GetResponseStatusCode(Handle handle, Handle contextHandle, u32* out return cmdbuf[1]; } +Result HTTPC_AddTrustedRootCA(Handle handle, Handle contextHandle, u8 *cert, u32 certsize) +{ + u32* cmdbuf=getThreadCommandBuffer(); + + cmdbuf[0]=IPC_MakeHeader(0x24,2,2); // 0x240082 + cmdbuf[1]=contextHandle; + cmdbuf[2]=certsize; + cmdbuf[3]=IPC_Desc_Buffer(certsize, IPC_BUFFER_R); + cmdbuf[4]=(u32)cert; + + Result ret=0; + if(R_FAILED(ret=svcSendSyncRequest(handle)))return ret; + + return cmdbuf[1]; +} +