mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-17 19:30:36 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
63aaad829a |
No files matched your search
+13
-13
@@ -16400,9 +16400,9 @@ static long recv_raw(struct mg_connection *c, void *buf, size_t len) {
|
|||||||
long n = 0;
|
long n = 0;
|
||||||
if (c->is_udp) {
|
if (c->is_udp) {
|
||||||
union usa usa;
|
union usa usa;
|
||||||
socklen_t slen = sizeof(usa);
|
socklen_t slen = tousa(&c->rem, &usa);
|
||||||
n = recvfrom(FD(c), (char *) buf, len, 0, &usa.sa, &slen);
|
n = recvfrom(FD(c), (char *) buf, len, 0, &usa.sa, &slen);
|
||||||
if (n > 0) tomgaddr(&usa, &c->rem, usa.sa.sa_family == AF_INET6);
|
if (n > 0) tomgaddr(&usa, &c->rem, slen != sizeof(usa.sin));
|
||||||
} else {
|
} else {
|
||||||
n = recv(FD(c), (char *) buf, len, MSG_NONBLOCKING);
|
n = recv(FD(c), (char *) buf, len, MSG_NONBLOCKING);
|
||||||
}
|
}
|
||||||
@@ -19166,8 +19166,8 @@ static bool mg_tls_server_send_hello(struct mg_connection *c) {
|
|||||||
|
|
||||||
// calculate P-256 keyshare and the shared secret
|
// calculate P-256 keyshare and the shared secret
|
||||||
pub[0] = 0x04; // uncompressed point 0x04 || X || Y
|
pub[0] = 0x04; // uncompressed point 0x04 || X || Y
|
||||||
if (!mg_p256_make_key(pub + 1, prv) ||
|
if (mg_p256_make_key(pub + 1, prv) == 0 ||
|
||||||
!mg_p256_shared_secret(tls->p256_peer, prv, tls->ecdhe_sec)) {
|
mg_p256_shared_secret(tls->p256_peer, prv, tls->ecdhe_sec) == 0) {
|
||||||
mg_bzero(prv, sizeof(prv));
|
mg_bzero(prv, sizeof(prv));
|
||||||
mg_error(c, "bad key");
|
mg_error(c, "bad key");
|
||||||
return false;
|
return false;
|
||||||
@@ -19582,7 +19582,7 @@ static bool mg_tls_send_cert_verify(struct mg_connection *c, bool is_client) {
|
|||||||
size_t sigsz, verifysz = 0;
|
size_t sigsz, verifysz = 0;
|
||||||
int adj1, adj2;
|
int adj1, adj2;
|
||||||
uint8_t sig[64] = {0};
|
uint8_t sig[64] = {0};
|
||||||
if (!mg_p256_sign(tls->ec_key, hash, sizeof(hash), sig)) {
|
if (mg_p256_sign(tls->ec_key, hash, sizeof(hash), sig) != 1) {
|
||||||
mg_error(c, "P-256 sign");
|
mg_error(c, "P-256 sign");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -19714,7 +19714,7 @@ static bool mg_tls_client_send_hello(struct mg_connection *c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// calc+fill keyshare; X || Y, sent as an uncompressed point 0x04 || X || Y
|
// calc+fill keyshare; X || Y, sent as an uncompressed point 0x04 || X || Y
|
||||||
if (!mg_p256_make_key(msg_client_hello + 95, tls->p256_cli)) {
|
if (mg_p256_make_key(msg_client_hello + 95, tls->p256_cli) == 0) {
|
||||||
mg_error(c, "P-256 key");
|
mg_error(c, "P-256 key");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -19804,8 +19804,8 @@ static int mg_tls_client_recv_hello(struct mg_connection *c) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (key_exchange_len != 65 || key_exchange[0] != 0x04 ||
|
if (key_exchange_len != 65 || key_exchange[0] != 0x04 ||
|
||||||
!mg_p256_shared_secret(key_exchange + 1, tls->p256_cli,
|
mg_p256_shared_secret(key_exchange + 1, tls->p256_cli,
|
||||||
tls->ecdhe_sec)) { // Validates the point
|
tls->ecdhe_sec) == 0) { // Validates the point
|
||||||
mg_error(c, "bad key");
|
mg_error(c, "bad key");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -20186,14 +20186,14 @@ static bool mg_tls_verify_cert_signature(const struct mg_tls_cert *cert,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mg_tls_verify_cert_cn(struct mg_der_tlv *subj, const char *host) {
|
static bool mg_tls_verify_cert_cn(struct mg_der_tlv *subj, const char *host) {
|
||||||
struct mg_der_tlv v;
|
struct mg_der_tlv v;
|
||||||
int matched = 0;
|
bool matched = false;
|
||||||
if (mg_der_find_oid(subj, (uint8_t *) "\x55\x04\x03", 3, &v) > 0) {
|
if (mg_der_find_oid(subj, (uint8_t *) "\x55\x04\x03", 3, &v) > 0) {
|
||||||
struct mg_str hn, cn;
|
struct mg_str hn, cn;
|
||||||
MG_VERBOSE(("using CN: %.*s <-> %s", v.len, v.value, host));
|
MG_VERBOSE(("using CN: %.*s <-> %s", v.len, v.value, host));
|
||||||
hn = mg_str(host), cn = mg_str_n((char *) v.value, v.len);
|
hn = mg_str(host), cn = mg_str_n((char *) v.value, v.len);
|
||||||
matched = (int) (countdots(hn) == countdots(cn) && mg_match(hn, cn, NULL));
|
matched = (countdots(hn) == countdots(cn) && mg_match(hn, cn, NULL));
|
||||||
}
|
}
|
||||||
return matched;
|
return matched;
|
||||||
}
|
}
|
||||||
@@ -20316,8 +20316,8 @@ static int mg_tls_recv_cert(struct mg_connection *c, bool is_client) {
|
|||||||
san = mg_tls_verify_cert_san(cert, certsz, tls->hostname,
|
san = mg_tls_verify_cert_san(cert, certsz, tls->hostname,
|
||||||
is_addr ? &addr : NULL);
|
is_addr ? &addr : NULL);
|
||||||
if (san < 0 || // RFC 6125 6.4.4 allow legacy fallback to CN
|
if (san < 0 || // RFC 6125 6.4.4 allow legacy fallback to CN
|
||||||
(san == 0 && (is_addr || mg_tls_verify_cert_cn(
|
(san == 0 &&
|
||||||
&ci->subj, tls->hostname) <= 0))) {
|
(is_addr || !mg_tls_verify_cert_cn(&ci->subj, tls->hostname)))) {
|
||||||
mg_error(c, "failed to verify host");
|
mg_error(c, "failed to verify host");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -297,9 +297,9 @@ static long recv_raw(struct mg_connection *c, void *buf, size_t len) {
|
|||||||
long n = 0;
|
long n = 0;
|
||||||
if (c->is_udp) {
|
if (c->is_udp) {
|
||||||
union usa usa;
|
union usa usa;
|
||||||
socklen_t slen = sizeof(usa);
|
socklen_t slen = tousa(&c->rem, &usa);
|
||||||
n = recvfrom(FD(c), (char *) buf, len, 0, &usa.sa, &slen);
|
n = recvfrom(FD(c), (char *) buf, len, 0, &usa.sa, &slen);
|
||||||
if (n > 0) tomgaddr(&usa, &c->rem, usa.sa.sa_family == AF_INET6);
|
if (n > 0) tomgaddr(&usa, &c->rem, slen != sizeof(usa.sin));
|
||||||
} else {
|
} else {
|
||||||
n = recv(FD(c), (char *) buf, len, MSG_NONBLOCKING);
|
n = recv(FD(c), (char *) buf, len, MSG_NONBLOCKING);
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-11
@@ -761,8 +761,8 @@ static bool mg_tls_server_send_hello(struct mg_connection *c) {
|
|||||||
|
|
||||||
// calculate P-256 keyshare and the shared secret
|
// calculate P-256 keyshare and the shared secret
|
||||||
pub[0] = 0x04; // uncompressed point 0x04 || X || Y
|
pub[0] = 0x04; // uncompressed point 0x04 || X || Y
|
||||||
if (!mg_p256_make_key(pub + 1, prv) ||
|
if (mg_p256_make_key(pub + 1, prv) == 0 ||
|
||||||
!mg_p256_shared_secret(tls->p256_peer, prv, tls->ecdhe_sec)) {
|
mg_p256_shared_secret(tls->p256_peer, prv, tls->ecdhe_sec) == 0) {
|
||||||
mg_bzero(prv, sizeof(prv));
|
mg_bzero(prv, sizeof(prv));
|
||||||
mg_error(c, "bad key");
|
mg_error(c, "bad key");
|
||||||
return false;
|
return false;
|
||||||
@@ -1177,7 +1177,7 @@ static bool mg_tls_send_cert_verify(struct mg_connection *c, bool is_client) {
|
|||||||
size_t sigsz, verifysz = 0;
|
size_t sigsz, verifysz = 0;
|
||||||
int adj1, adj2;
|
int adj1, adj2;
|
||||||
uint8_t sig[64] = {0};
|
uint8_t sig[64] = {0};
|
||||||
if (!mg_p256_sign(tls->ec_key, hash, sizeof(hash), sig)) {
|
if (mg_p256_sign(tls->ec_key, hash, sizeof(hash), sig) != 1) {
|
||||||
mg_error(c, "P-256 sign");
|
mg_error(c, "P-256 sign");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1309,7 +1309,7 @@ static bool mg_tls_client_send_hello(struct mg_connection *c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// calc+fill keyshare; X || Y, sent as an uncompressed point 0x04 || X || Y
|
// calc+fill keyshare; X || Y, sent as an uncompressed point 0x04 || X || Y
|
||||||
if (!mg_p256_make_key(msg_client_hello + 95, tls->p256_cli)) {
|
if (mg_p256_make_key(msg_client_hello + 95, tls->p256_cli) == 0) {
|
||||||
mg_error(c, "P-256 key");
|
mg_error(c, "P-256 key");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1399,8 +1399,8 @@ static int mg_tls_client_recv_hello(struct mg_connection *c) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (key_exchange_len != 65 || key_exchange[0] != 0x04 ||
|
if (key_exchange_len != 65 || key_exchange[0] != 0x04 ||
|
||||||
!mg_p256_shared_secret(key_exchange + 1, tls->p256_cli,
|
mg_p256_shared_secret(key_exchange + 1, tls->p256_cli,
|
||||||
tls->ecdhe_sec)) { // Validates the point
|
tls->ecdhe_sec) == 0) { // Validates the point
|
||||||
mg_error(c, "bad key");
|
mg_error(c, "bad key");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -1781,14 +1781,14 @@ static bool mg_tls_verify_cert_signature(const struct mg_tls_cert *cert,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mg_tls_verify_cert_cn(struct mg_der_tlv *subj, const char *host) {
|
static bool mg_tls_verify_cert_cn(struct mg_der_tlv *subj, const char *host) {
|
||||||
struct mg_der_tlv v;
|
struct mg_der_tlv v;
|
||||||
int matched = 0;
|
bool matched = false;
|
||||||
if (mg_der_find_oid(subj, (uint8_t *) "\x55\x04\x03", 3, &v) > 0) {
|
if (mg_der_find_oid(subj, (uint8_t *) "\x55\x04\x03", 3, &v) > 0) {
|
||||||
struct mg_str hn, cn;
|
struct mg_str hn, cn;
|
||||||
MG_VERBOSE(("using CN: %.*s <-> %s", v.len, v.value, host));
|
MG_VERBOSE(("using CN: %.*s <-> %s", v.len, v.value, host));
|
||||||
hn = mg_str(host), cn = mg_str_n((char *) v.value, v.len);
|
hn = mg_str(host), cn = mg_str_n((char *) v.value, v.len);
|
||||||
matched = (int) (countdots(hn) == countdots(cn) && mg_match(hn, cn, NULL));
|
matched = (countdots(hn) == countdots(cn) && mg_match(hn, cn, NULL));
|
||||||
}
|
}
|
||||||
return matched;
|
return matched;
|
||||||
}
|
}
|
||||||
@@ -1911,8 +1911,8 @@ static int mg_tls_recv_cert(struct mg_connection *c, bool is_client) {
|
|||||||
san = mg_tls_verify_cert_san(cert, certsz, tls->hostname,
|
san = mg_tls_verify_cert_san(cert, certsz, tls->hostname,
|
||||||
is_addr ? &addr : NULL);
|
is_addr ? &addr : NULL);
|
||||||
if (san < 0 || // RFC 6125 6.4.4 allow legacy fallback to CN
|
if (san < 0 || // RFC 6125 6.4.4 allow legacy fallback to CN
|
||||||
(san == 0 && (is_addr || mg_tls_verify_cert_cn(
|
(san == 0 &&
|
||||||
&ci->subj, tls->hostname) <= 0))) {
|
(is_addr || !mg_tls_verify_cert_cn(&ci->subj, tls->hostname)))) {
|
||||||
mg_error(c, "failed to verify host");
|
mg_error(c, "failed to verify host");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user