gnutls psk is working!

FossilOrigin-Name: b62107a4ffcdb33ce511826b20dd85209ed22f56781b43828c1e9b984bb86dd7
This commit is contained in:
7u83@mail.ru
2018-04-04 08:59:07 +00:00
parent debcfd6f3e
commit b21845d3c0
17 changed files with 219 additions and 79 deletions

View File

@ -1,4 +1,30 @@
#include "cw.h"
static int get_psk(struct conn * conn,const char * username, uint8_t **psk, unsigned int *len)
{
char key[CW_KTV_MAX_KEY_LEN];
cw_KTV_t * result;
sprintf(key,"%s/%s","psk",username);
result = cw_ktv_get(conn->local_cfg,key,CW_TYPE_BSTR16);
if (result == NULL){
if (conn->dtls_psk != NULL){
*psk = bstr16_data(conn->dtls_psk);
*len = bstr16_len(conn->dtls_psk);
return 1;
}
return 0;
}
if (result == NULL)
return 0;
*psk = result->type->data(result);
*len = result->type->len(result);
return 1;
}
/**
* @brief Setup DTLS parameters from config
* @param conn
@ -10,7 +36,7 @@
int cw_setup_dtls(struct conn * conn, mavl_t cfg, const char *prefix, char * default_cipher)
{
char key[CW_KTV_MAX_KEY_LEN];
char *ssl_psk,*ssl_cert,*ssl_key;
char *ssl_cert,*ssl_key;
uint8_t security;
security = 0;
@ -18,13 +44,18 @@ int cw_setup_dtls(struct conn * conn, mavl_t cfg, const char *prefix, char * de
sprintf(key,"%s/%s",prefix,"ssl-cipher");
conn->dtls_cipher = cw_ktv_get_str(cfg,key, default_cipher);
sprintf(key,"%s/%s",prefix,"ssl-psk");
ssl_psk = cw_ktv_get_str(cfg,key,NULL);
if (ssl_psk != NULL){
conn->dtls_psk=ssl_psk;
conn->dtls_psk_len=strlen(ssl_psk);
conn->dtls_psk = cw_ktv_get_bstr16(cfg,key,NULL);
sprintf(key,"%s/%s",prefix,"ssl-psk-enable");
conn->dtls_psk_enable = cw_ktv_get_bool(cfg,key,0);
if (conn->dtls_psk_enable ){
security |= CAPWAP_FLAG_AC_SECURITY_S;
}
sprintf(key,"%s/%s",prefix,"ssl-certfile");
ssl_cert = cw_ktv_get_str(conn->local_cfg,key,NULL);
@ -41,6 +72,8 @@ int cw_setup_dtls(struct conn * conn, mavl_t cfg, const char *prefix, char * de
sprintf(key,"%s/%s",prefix,"ssl-dhbits");
conn->dtls_dhbits = cw_ktv_get_word(cfg,key,1024);
conn->dtls_get_psk = get_psk;
return security;
}