1 (edited by kjjy7 2018-08-02 19:32:01)

Topic: How to import pre-shared key in client ....

To Setup pre-shared key, mbedtls_ssl_conf_psk function is used in mbedtls.

is there any method to Setup pre-shared key?

I have Not to use callback function.
   such as (wolfSSL_CTX_set_psk_client_callback function(ctx, My_Psk_Client_cb))

Regards

Share

Re: How to import pre-shared key in client ....

Hi kjjy7,

We provide an example for a psk client callback function in <wolfssl-root>/wolfssl/test.h

1115 static WC_INLINE unsigned int my_psk_client_cb(WOLFSSL* ssl, const char* hint,   
1116         char* identity, unsigned int id_max_len, unsigned char* key,             
1117         unsigned int key_max_len)                                                
1118 {                                                                                
1119     (void)ssl;                                                                   
1120     (void)hint;                                                                  
1121     (void)key_max_len;                                                           
1122                                                                                  
1123     /* see internal.h MAX_PSK_ID_LEN for PSK identity limit */                   
1124     strncpy(identity, kIdentityStr, id_max_len);                                 
1125                                                                                  
1126     if (wolfSSL_GetVersion(ssl) < WOLFSSL_TLSV1_3) {                             
1127         /* test key in hex is 0x1a2b3c4d , in decimal 439,041,101 , we're using  
1128            unsigned binary */                                                    
1129         key[0] = 0x1a;                                                           
1130         key[1] = 0x2b;                                                           
1131         key[2] = 0x3c;                                                           
1132         key[3] = 0x4d;                                                           
1133                                                                                  
1134                                                                                  
1135         return 4;   /* length of key in octets or 0 for error */                 
1136     }                                                                            
1137     else {                                                                       
1138         int i;                                                                   
1139         int b = 0x01;                                                            
1140                                                                                  
1141         for (i = 0; i < 32; i++, b += 0x22) {                                    
1142             if (b >= 0x100)                                                      
1143                 b = 0x01;                                                        
1144             key[i] = b;                                                          
1145         }                                                                        
1146                                                                                  
1147         return 32;   /* length of key in octets or 0 for error */                
1148     }                                                                            
1149 }

You would then register your callback with:

wolfSSL_CTX_set_psk_client_callback(ctx, my_psk_client_cb);

Warm Regards,

Kaleb

Re: How to import pre-shared key in client ....

thanks

Share