From 44b601d7b88707683edadb618639df522bcb56d5 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Wed, 30 Mar 2016 15:02:18 -0400 Subject: [PATCH] Switched the sslopt enum to anonymous, and updated sslcRead(), as requested. Implemented sslcContextGetStrings. --- libctru/include/3ds/services/sslc.h | 18 ++++++++++++++---- libctru/source/services/sslc.c | 28 ++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/libctru/include/3ds/services/sslc.h b/libctru/include/3ds/services/sslc.h index 0b1d52c..2aa0705 100644 --- a/libctru/include/3ds/services/sslc.h +++ b/libctru/include/3ds/services/sslc.h @@ -29,11 +29,11 @@ typedef enum { } SSLC_DefaultClientCert; /// sslc options. https://www.3dbrew.org/wiki/SSL_Services#SSLOpt -typedef enum { +enum { SSLCOPT_Default = 0, SSLCOPT_DisableVerify = BIT(9), // "Disables server cert verification when set." SSLCOPT_TLSv10 = BIT(11) // "Use TLSv1.0." -} SSLC_SSLOpt; +}; /// Initializes SSLC. Normally session_handle should be 0. When non-zero this will use the specified handle for the main-service-session without using the Initialize command, instead of using srvGetServiceHandle. Result sslcInit(Handle session_handle); @@ -118,7 +118,7 @@ Result sslcGenerateRandomData(u8 *buf, u32 size); * @param input_opt Input sslc options bitmask. * @param hostname Server hostname. */ -Result sslcCreateContext(sslcContext *context, int sockfd, SSLC_SSLOpt input_opt, char *hostname); +Result sslcCreateContext(sslcContext *context, int sockfd, u32 input_opt, char *hostname); /* * @brief Destroys a sslc context. The associated sockfd must be closed manually. @@ -179,7 +179,17 @@ Result sslcContextSetHandle8(sslcContext *context, u32 handle); * @param context sslc context. * @param bitmask opt bitmask. */ -Result sslcContextClearOpt(sslcContext *context, SSLC_SSLOpt bitmask); +Result sslcContextClearOpt(sslcContext *context, u32 bitmask); + +/* + * @brief This copies two strings from context state to the specified output buffers. Each string is only copied if it was successfully loaded. The maxsizes include the nul-terminator. TODO: Update this with what these strings actually are. + * @param context sslc context. + * @param str0 Output buffer for str0. + * @param str0_maxsize Max size of the str0 output buffer. + * @param str0 Output buffer for str1. + * @param str0_maxsize Max size of the str1 output buffer. + */ +Result sslcContextGetStrings(sslcContext *context, char *str0, u32 str0_maxsize, char *str1, u32 str1_maxsize); /* * @brief This loads an u32 from the specified context state. This needs updated once it's known what this field is for. diff --git a/libctru/source/services/sslc.c b/libctru/source/services/sslc.c index 8e5c8d9..687952f 100644 --- a/libctru/source/services/sslc.c +++ b/libctru/source/services/sslc.c @@ -51,7 +51,7 @@ static Result sslcipc_Initialize(void) return cmdbuf[1]; } -static Result sslcipc_CreateContext(sslcContext *context, int sockfd, SSLC_SSLOpt input_opt, char *hostname) +static Result sslcipc_CreateContext(sslcContext *context, int sockfd, u32 input_opt, char *hostname) { u32* cmdbuf=getThreadCommandBuffer(); u32 size = strlen(hostname)+1; @@ -312,6 +312,26 @@ static Result sslcipc_ContextSetValue(sslcContext *context, u32 type, u32 value) return cmdbuf[1]; } +Result sslcContextGetStrings(sslcContext *context, char *str0, u32 str0_maxsize, char *str1, u32 str1_maxsize) +{ + u32* cmdbuf=getThreadCommandBuffer(); + + cmdbuf[0]=IPC_MakeHeader(0x1C,3,4); // 0x1C00C4 + cmdbuf[1]=context->sslchandle; + cmdbuf[2]=str0_maxsize; + cmdbuf[3]=str1_maxsize; + cmdbuf[4]=IPC_Desc_Buffer(str0_maxsize, IPC_BUFFER_W); + cmdbuf[5]=(u32)str0; + cmdbuf[6]=IPC_Desc_Buffer(str1_maxsize, IPC_BUFFER_W); + cmdbuf[7]=(u32)str1; + + Result ret=0; + if(R_FAILED(ret=svcSendSyncRequest(context->servhandle)))return ret; + ret = cmdbuf[1]; + + return ret; +} + Result sslcContextGetState(sslcContext *context, u32 *out) { u32* cmdbuf=getThreadCommandBuffer(); @@ -341,7 +361,7 @@ static Result sslcipc_DestroyContext(sslcContext *context) return cmdbuf[1]; } -Result sslcCreateContext(sslcContext *context, int sockfd, SSLC_SSLOpt input_opt, char *hostname) +Result sslcCreateContext(sslcContext *context, int sockfd, u32 input_opt, char *hostname) { Result ret=0; @@ -392,7 +412,7 @@ Result sslcRead(sslcContext *context, void *buf, size_t len, bool peek) { u32 type = 0; - if(peek==true)type = 1; + if(peek)type = 1; return sslcipc_DataTransfer(context, buf, len, type); } @@ -417,7 +437,7 @@ Result sslcContextSetHandle8(sslcContext *context, u32 handle) return sslcipc_ContextSetValue(context, 2, handle); } -Result sslcContextClearOpt(sslcContext *context, SSLC_SSLOpt bitmask) +Result sslcContextClearOpt(sslcContext *context, u32 bitmask) { return sslcipc_ContextSetValue(context, 3, bitmask); } -- 2.39.5