Skip to content

Commit 3226ef7

Browse files
committed
verify_peer_identity: Check for missing application specific data.
This should not be possible in practice since we always store the data point when peer verification is enabled. Found by the ZeroPath AI Security Engineer <https://zeropath.com>
1 parent a8546ab commit 3226ef7

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

logsrvd/tls_client.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ verify_peer_identity(int preverify_ok, X509_STORE_CTX *ctx)
6464

6565
current_cert = X509_STORE_CTX_get_current_cert(ctx);
6666

67-
/* if pre-verification of the cert failed, just propagate that result back */
67+
/* If pre-verification of the cert failed, just propagate that result back */
6868
if (preverify_ok != 1) {
6969
int err = X509_STORE_CTX_get_error(ctx);
7070
char current_cert_name[256] = "";
@@ -79,7 +79,7 @@ verify_peer_identity(int preverify_ok, X509_STORE_CTX *ctx)
7979

8080
/*
8181
* Since this callback is called for each cert in the chain,
82-
* check that current cert is the peer's certificate
82+
* check that current cert is the peer's certificate.
8383
*/
8484
peer_cert = X509_STORE_CTX_get0_cert(ctx);
8585
if (current_cert != peer_cert) {
@@ -88,7 +88,13 @@ verify_peer_identity(int preverify_ok, X509_STORE_CTX *ctx)
8888

8989
/* Fetch the attached peer_info from the ssl connection object. */
9090
ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
91+
if (ssl == NULL) {
92+
debug_return_int(0);
93+
}
9194
peer_info = SSL_get_ex_data(ssl, 1);
95+
if (peer_info == NULL) {
96+
debug_return_int(0);
97+
}
9298

9399
/* Validate the cert based on the host name and IP address. */
94100
result = validate_hostname(peer_cert, peer_info->name, peer_info->ipaddr);

plugins/sudoers/log_client.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ verify_peer_identity(int preverify_ok, X509_STORE_CTX *ctx)
146146

147147
current_cert = X509_STORE_CTX_get_current_cert(ctx);
148148

149-
/* if pre-verification of the cert failed, just propagate that result back */
149+
/* If pre-verification of the cert failed, just propagate that result back */
150150
if (preverify_ok != 1) {
151151
int err = X509_STORE_CTX_get_error(ctx);
152152
char current_cert_name[256] = "";
@@ -159,29 +159,29 @@ verify_peer_identity(int preverify_ok, X509_STORE_CTX *ctx)
159159
debug_return_int(0);
160160
}
161161

162-
/* since this callback is called for each cert in the chain,
163-
* check that current cert is the peer's certificate
162+
/*
163+
* Since this callback is called for each cert in the chain,
164+
* check that current cert is the peer's certificate.
164165
*/
165166
peer_cert = X509_STORE_CTX_get0_cert(ctx);
166-
167167
if (current_cert != peer_cert) {
168168
debug_return_int(1);
169169
}
170170

171-
/* read out the attached object (closure) from the ssl connection object */
171+
/* Fetch the attached closure from the ssl connection object. */
172172
ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
173+
if (ssl == NULL) {
174+
debug_return_int(0);
175+
}
173176
closure = SSL_get_ex_data(ssl, 1);
177+
if (closure == NULL) {
178+
debug_return_int(0);
179+
}
174180

175181
result = validate_hostname(peer_cert, closure->server_name,
176182
closure->server_ip);
177183

178-
switch(result)
179-
{
180-
case MatchFound:
181-
debug_return_int(1);
182-
default:
183-
debug_return_int(0);
184-
}
184+
debug_return_int(result == MatchFound);
185185
}
186186

187187
static bool

0 commit comments

Comments
 (0)