mirror of
https://github.com/cesanta/mongoose.git
synced 2026-12-05 22:08:23 +00:00
allow no certs for client with (not enforced) two-way auth
This commit is contained in:
1 parent
03afe3aeb1
commit
05ef7ebad9
2 files changed
+8
-2
No files matched your search
+4
-1
@@ -16125,11 +16125,13 @@ static bool mg_tls_send_cert(struct mg_connection *c, bool is_client) {
|
|||||||
cert = (uint8_t *) mg_calloc(1, 13 + total_size);
|
cert = (uint8_t *) mg_calloc(1, 13 + total_size);
|
||||||
if (cert == NULL) return res;
|
if (cert == NULL) return res;
|
||||||
cert[0] = MG_TLS_CERTIFICATE; // handshake header
|
cert[0] = MG_TLS_CERTIFICATE; // handshake header
|
||||||
|
if (is_client && tls->cert_der.len == 0) total_size = 0; // empty list
|
||||||
MG_STORE_BE24(cert + 1, total_size + 4);
|
MG_STORE_BE24(cert + 1, total_size + 4);
|
||||||
cert[4] = 0; // request context
|
cert[4] = 0; // request context
|
||||||
MG_STORE_BE24(cert + 5, total_size); // 3 bytes: cert (s) length
|
MG_STORE_BE24(cert + 5, total_size); // 3 bytes: cert (s) length
|
||||||
offset = 8;
|
offset = 8;
|
||||||
MG_STORE_BE24(cert + offset, tls->cert_der.len); // 3 bytes: first cert len
|
if (total_size > 0) { // handle empty list, RFC-8446 4.4.2
|
||||||
|
MG_STORE_BE24(cert + offset, tls->cert_der.len); // 3 bytes: 1st cert len
|
||||||
offset += 3;
|
offset += 3;
|
||||||
// bytes 11+ are certificate in DER format
|
// bytes 11+ are certificate in DER format
|
||||||
memmove(cert + offset, tls->cert_der.buf, tls->cert_der.len);
|
memmove(cert + offset, tls->cert_der.buf, tls->cert_der.len);
|
||||||
@@ -16153,6 +16155,7 @@ static bool mg_tls_send_cert(struct mg_connection *c, bool is_client) {
|
|||||||
MG_STORE_BE16(cert + offset, 0); // certificate extensions (none)
|
MG_STORE_BE16(cert + offset, 0); // certificate extensions (none)
|
||||||
offset += 2;
|
offset += 2;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
mg_sha256_update(&tls->sha256, cert, offset);
|
mg_sha256_update(&tls->sha256, cert, offset);
|
||||||
res = mg_tls_encrypt(c, cert, offset, MG_TLS_HANDSHAKE);
|
res = mg_tls_encrypt(c, cert, offset, MG_TLS_HANDSHAKE);
|
||||||
mg_free(cert);
|
mg_free(cert);
|
||||||
|
|||||||
+4
-1
@@ -813,11 +813,13 @@ static bool mg_tls_send_cert(struct mg_connection *c, bool is_client) {
|
|||||||
cert = (uint8_t *) mg_calloc(1, 13 + total_size);
|
cert = (uint8_t *) mg_calloc(1, 13 + total_size);
|
||||||
if (cert == NULL) return res;
|
if (cert == NULL) return res;
|
||||||
cert[0] = MG_TLS_CERTIFICATE; // handshake header
|
cert[0] = MG_TLS_CERTIFICATE; // handshake header
|
||||||
|
if (is_client && tls->cert_der.len == 0) total_size = 0; // empty list
|
||||||
MG_STORE_BE24(cert + 1, total_size + 4);
|
MG_STORE_BE24(cert + 1, total_size + 4);
|
||||||
cert[4] = 0; // request context
|
cert[4] = 0; // request context
|
||||||
MG_STORE_BE24(cert + 5, total_size); // 3 bytes: cert (s) length
|
MG_STORE_BE24(cert + 5, total_size); // 3 bytes: cert (s) length
|
||||||
offset = 8;
|
offset = 8;
|
||||||
MG_STORE_BE24(cert + offset, tls->cert_der.len); // 3 bytes: first cert len
|
if (total_size > 0) { // handle empty list, RFC-8446 4.4.2
|
||||||
|
MG_STORE_BE24(cert + offset, tls->cert_der.len); // 3 bytes: 1st cert len
|
||||||
offset += 3;
|
offset += 3;
|
||||||
// bytes 11+ are certificate in DER format
|
// bytes 11+ are certificate in DER format
|
||||||
memmove(cert + offset, tls->cert_der.buf, tls->cert_der.len);
|
memmove(cert + offset, tls->cert_der.buf, tls->cert_der.len);
|
||||||
@@ -841,6 +843,7 @@ static bool mg_tls_send_cert(struct mg_connection *c, bool is_client) {
|
|||||||
MG_STORE_BE16(cert + offset, 0); // certificate extensions (none)
|
MG_STORE_BE16(cert + offset, 0); // certificate extensions (none)
|
||||||
offset += 2;
|
offset += 2;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
mg_sha256_update(&tls->sha256, cert, offset);
|
mg_sha256_update(&tls->sha256, cert, offset);
|
||||||
res = mg_tls_encrypt(c, cert, offset, MG_TLS_HANDSHAKE);
|
res = mg_tls_encrypt(c, cert, offset, MG_TLS_HANDSHAKE);
|
||||||
mg_free(cert);
|
mg_free(cert);
|
||||||
|
|||||||
Reference in new issue
Block a user