mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-01 13:10:43 +00:00
Support mbedtls 3.x.x
This commit is contained in:
1 parent
f20ee1f305
commit
d9680df510
4 files changed
+52
-28
No files matched your search
@@ -16,6 +16,12 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
|
||||
#define RNG , rng_get, NULL
|
||||
#else
|
||||
#define RNG
|
||||
#endif
|
||||
|
||||
// Different versions have those in different files, so declare here
|
||||
EXTERN_C int mbedtls_net_recv(void *, unsigned char *, size_t);
|
||||
EXTERN_C int mbedtls_net_send(void *, const unsigned char *, size_t);
|
||||
@@ -60,6 +66,14 @@ static void debug_cb(void *c, int lev, const char *s, int n, const char *s2) {
|
||||
(void) lev;
|
||||
}
|
||||
|
||||
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
|
||||
static int rng_get(void *p_rng, unsigned char *buf, size_t len) {
|
||||
(void) p_rng;
|
||||
mg_random(buf, len);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void mg_tls_init(struct mg_connection *c, struct mg_tls_opts *opts) {
|
||||
struct mg_tls *tls = (struct mg_tls *) calloc(1, sizeof(*tls));
|
||||
int rc = 0;
|
||||
@@ -139,10 +153,9 @@ void mg_tls_init(struct mg_connection *c, struct mg_tls_opts *opts) {
|
||||
mg_error(c, "parse(%s) err %#x", cert, -rc);
|
||||
goto fail;
|
||||
}
|
||||
rc = key[0] == '-'
|
||||
? mbedtls_pk_parse_key(&tls->pk, (uint8_t *) key,
|
||||
strlen(key) + 1, NULL, 0)
|
||||
: mbedtls_pk_parse_keyfile(&tls->pk, key, NULL);
|
||||
rc = key[0] == '-' ? mbedtls_pk_parse_key(&tls->pk, (uint8_t *) key,
|
||||
strlen(key) + 1, NULL, 0 RNG)
|
||||
: mbedtls_pk_parse_keyfile(&tls->pk, key, NULL RNG);
|
||||
if (rc != 0) {
|
||||
mg_error(c, "tls key(%s) %#x", certkey, -rc);
|
||||
goto fail;
|
||||
|
||||
Reference in new issue
Block a user