Skip to content

Commit 2eae6a3

Browse files
committed
C++: Add qhelp for result conflation query.
1 parent 6afcbce commit 2eae6a3

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
<overview>
6+
<p>When checking the result of SSL certificate verification, accepting any error code may allow an attacker to impersonate someone who is trusted.</p>
7+
8+
</overview>
9+
<recommendation>
10+
11+
<p>When checking an SSL certificate with <code>SSL_get_verify_result</code>, only <code>X509_V_OK</code> is a success code. If there is any other result the certificate should not be accepted.</p>
12+
13+
</recommendation>
14+
<example>
15+
16+
<p>In this example the error code <code>X509_V_ERR_CERT_HAS_EXPIRED</code> is treated the same as an OK result. An expired certificate should not be accepted as it is more likely to be compromised than a valid certificate.</p>
17+
18+
<sample src="SSLResultConflationBad.cpp" />
19+
20+
<p>In the corrected example, only a result of <code>X509_V_OK</code> is accepted.</p>
21+
22+
<sample src="SSLResultConflationGood.cpp" />
23+
24+
</example>
25+
<references>
26+
27+
</references>
28+
</qhelp>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// ...
2+
3+
if (cert = SSL_get_peer_certificate(ssl))
4+
{
5+
result = SSL_get_verify_result(ssl);
6+
7+
if ((result == X509_V_OK) || (result == X509_V_ERR_CERT_HAS_EXPIRED)) // BAD (conflates OK and a non-OK codes)
8+
{
9+
do_ok();
10+
} else {
11+
do_error();
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// ...
2+
3+
if (cert = SSL_get_peer_certificate(ssl))
4+
{
5+
result = SSL_get_verify_result(ssl);
6+
7+
if (result == X509_V_OK) // GOOD
8+
{
9+
do_ok();
10+
} else {
11+
do_error();
12+
}
13+
}

0 commit comments

Comments
 (0)