@@ -103,7 +103,7 @@ void wolfSSL_TLS_client_init(const char* cipherlist)
103103 char * cert = "./certs/ca-cert.pem" ;
104104 #endif
105105 #else
106- #if defined(USE_ECC_CERT ) && defined(USE_CERT_BUFFERS_256 )
106+ #if defined(USE_ECC_CERT ) && defined(USE_CERT_BUFFERS_256 )
107107 const unsigned char * cert = ca_ecc_cert_der_256 ;
108108 #define SIZEOF_CERT sizeof_ca_ecc_cert_der_256
109109 #else
@@ -118,7 +118,7 @@ void wolfSSL_TLS_client_init(const char* cipherlist)
118118 #endif
119119
120120 /* Create and initialize WOLFSSL_CTX */
121- if ((client_ctx =
121+ if ((client_ctx =
122122 wolfSSL_CTX_new (wolfSSLv23_client_method_ex ((void * )NULL ))) == NULL ) {
123123 printf ("ERROR: failed to create WOLFSSL_CTX\n" );
124124 return ;
@@ -134,7 +134,7 @@ void wolfSSL_TLS_client_init(const char* cipherlist)
134134 return ;
135135 }
136136 #else
137- if (wolfSSL_CTX_load_verify_buffer (client_ctx , cert , SIZEOF_CERT ,
137+ if (wolfSSL_CTX_load_verify_buffer (client_ctx , cert , SIZEOF_CERT ,
138138 SSL_FILETYPE_ASN1 ) != SSL_SUCCESS ){
139139 printf ("ERROR: can't load certificate data\n" );
140140 return ;
@@ -151,24 +151,6 @@ void wolfSSL_TLS_client_init(const char* cipherlist)
151151 return ;
152152 }
153153
154- /* set client private key data */
155- #if defined(WOLFSSL_TLS13 ) && defined(SIMPLE_TLS_TSIP_CLIENT )
156- if (tsip_set_clientPrivateKeyEnc (
157- g_key_block_data .encrypted_user_ecc256_private_key ,
158- TSIP_ECCP256 ) != 0 ) {
159- printf ("ERROR: can't load client-private key\n" );
160- return ;
161- }
162- #else
163- if (wolfSSL_CTX_use_PrivateKey_buffer (client_ctx ,
164- ecc_clikey_der_256 ,
165- sizeof_ecc_clikey_der_256 ,
166- SSL_FILETYPE_ASN1 ) != WOLFSSL_SUCCESS ) {
167- printf ("ERROR: can't load private-key data.\n" );
168- return ;
169- }
170- #endif /* WOLFSSL_TLS13 */
171-
172154#else
173155 if (wolfSSL_CTX_use_certificate_chain_buffer_format (client_ctx ,
174156 client_cert_der_2048 ,
@@ -195,15 +177,15 @@ void wolfSSL_TLS_client_init(const char* cipherlist)
195177 wolfSSL_SetIOSend (client_ctx , my_IOSend );
196178
197179 /* use specific cipher */
198- if (cipherlist != NULL &&
180+ if (cipherlist != NULL &&
199181 wolfSSL_CTX_set_cipher_list (client_ctx , cipherlist ) != WOLFSSL_SUCCESS ) {
200182 wolfSSL_CTX_free (client_ctx ); client_ctx = NULL ;
201183 printf ("client can't set cipher list" );
202184 return ;
203185 }
204-
186+
205187#if defined(WOLFSSL_TLS13 )
206- if (wolfSSL_CTX_UseSupportedCurve (client_ctx , WOLFSSL_ECC_SECP256R1 )
188+ if (wolfSSL_CTX_UseSupportedCurve (client_ctx , WOLFSSL_ECC_SECP256R1 )
207189 != WOLFSSL_SUCCESS ) {
208190 wolfSSL_CTX_free (client_ctx ); client_ctx = NULL ;
209191 printf ("client can't set use supported curves\n" );
@@ -222,11 +204,11 @@ void wolfSSL_TLS_client( )
222204
223205 #define BUFF_SIZE 256
224206 static const char sendBuff []= "Hello Server\n" ;
225-
207+
226208 char rcvBuff [BUFF_SIZE ] = {0 };
227-
209+
228210 static T_IPV4EP my_addr = { 0 , 0 };
229-
211+
230212 T_IPV4EP dst_addr ;
231213
232214 if ((dst_addr .ipaddr = getIPaddr (SIMPLE_TLSSEVER_IP )) == 0 ){
@@ -248,9 +230,45 @@ void wolfSSL_TLS_client( )
248230 goto out ;
249231 }
250232
251- #ifdef SIMPLE_TLS_TSIP_CLIENT
233+ #ifdef SIMPLE_TLS_TSIP_CLIENT
252234 tsip_set_callback_ctx (ssl , & userContext );
235+ #endif
236+
237+ /* set client private key data */
238+ #if defined(WOLFSSL_TLS13 ) && defined(SIMPLE_TLS_TSIP_CLIENT )
239+ #if defined(USE_ECC_CERT )
240+ if (tsip_use_PrivateKey_buffer_TLS (ssl ,
241+ (const char * )g_key_block_data .encrypted_user_ecc256_private_key ,
242+ sizeof (g_key_block_data .encrypted_user_ecc256_private_key ),
243+ TSIP_ECCP256 ) != 0 ) {
244+ printf ("ERROR: can't load client-private key\n" );
245+ return ;
246+ }
247+ #else
248+ if (tsip_use_PrivateKey_buffer_TLS (ssl ,
249+ (const char * )g_key_block_data .encrypted_user_rsa2048_private_key ,
250+ sizeof (g_key_block_data .encrypted_user_rsa2048_private_key ),
251+ TSIP_RSA2048 ) != 0 ) {
252+ printf ("ERROR: can't load client-private key\n" );
253+ return ;
254+ }
255+ ret = tsip_use_PublicKey_buffer_TLS (ssl ,
256+ (const char * )g_key_block_data .encrypted_user_rsa2048_public_key ,
257+ sizeof (g_key_block_data .encrypted_user_rsa2048_public_key ), TSIP_RSA2048 );
258+ if (ret != 0 ) {
259+ printf ("ERROR tsip_use_PublicKey_buffer: %d\n" , ret );
260+ return ;
261+ }
253262 #endif
263+ #else
264+ if (wolfSSL_use_PrivateKey_buffer (ssl ,
265+ ecc_clikey_der_256 ,
266+ sizeof_ecc_clikey_der_256 ,
267+ SSL_FILETYPE_ASN1 ) != WOLFSSL_SUCCESS ) {
268+ printf ("ERROR: can't load private-key data.\n" );
269+ return ;
270+ }
271+ #endif /* WOLFSSL_TLS13 */
254272
255273 /* set callback context */
256274 wolfSSL_SetIOReadCtx (ssl , (void * )& cepid );
0 commit comments