Skip to content

Commit 72a0325

Browse files
committed
C++: Add qhelp for result not checked query.
1 parent 5eb814f commit 72a0325

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-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>After fetching an SSL certificate, always check the result of certificate verification.</p>
7+
8+
</overview>
9+
<recommendation>
10+
11+
<p>Always check the result of SSL certificate verification. A certificate that has been revoked may indicate that data is coming from an attacker, whereas a certificate that has expired or was self-signed may indicate an increased likelihood that the data is malicious.</p>
12+
13+
</recommendation>
14+
<example>
15+
16+
<p>In this example, the <code>SSL_get_peer_certificate</code> function is used to get the certificate of a peer. However it is unsafe to use that information wihtout checking the certificate is valid.</p>
17+
18+
<sample src="SSLResultNotCheckedBad.cpp" />
19+
20+
<p>In the corrected example, we use <code>SSL_get_verify_result</code> to check that certificate verification was successful.</p>
21+
22+
<sample src="SSLResultNotCheckedGood.cpp" />
23+
24+
</example>
25+
<references>
26+
27+
</references>
28+
</qhelp>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// ...
2+
3+
int cert = SSL_get_peer_certificate(ssl); // BAD (SSL_get_verify_result is never called)
4+
5+
// ...
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// ...
2+
3+
int cert = SSL_get_peer_certificate(ssl); // GOOD
4+
if (cert)
5+
{
6+
result = SSL_get_verify_result(ssl);
7+
if (result == X509_V_OK)
8+
{
9+
// ...

0 commit comments

Comments
 (0)