716
Effectiveness = SOAR Partial
Architecture or Design Review
According to SOAR, the following detection techniques may be useful: Highly cost effective:
Inspection (IEEE 1028 standard) (can apply to requirements, design, source code, etc.)
Effectiveness = High
Potential Mitigations
Phase: Architecture and Design
Phase: Implementation
Certificates should be carefully managed and checked to assure that data are encrypted with the
intended owner's public key.
Phase: Implementation
If certificate pinning is being used, ensure that all relevant properties of the certificate are fully
validated before the certificate is pinned, including the hostname.
Demonstrative Examples
Example 1:
This code checks the certificate of a connected peer.
Example Language: C (Bad)
if ((cert = SSL_get_peer_certificate(ssl)) && host)
foo=SSL_get_verify_result(ssl);
if ((X509_V_OK==foo) || X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN==foo))
// certificate looks good, host can be trusted
In this case, because the certificate is self-signed, there was no external authority that could
prove the identity of the host. The program could be communicating with a different system that is
spoofing the host, e.g. by poisoning the DNS cache or using an Adversary-in-the-Middle (AITM)
attack to modify the traffic from server to client.
Example 2:
The following OpenSSL code obtains a certificate and verifies it.
Example Language: C (Bad)
cert = SSL_get_peer_certificate(ssl);
if (cert && (SSL_get_verify_result(ssl)==X509_V_OK)) {
// do secret things
}
Even though the "verify" step returns X509_V_OK, this step does not include checking the
Common Name against the name of the host. That is, there is no guarantee that the certificate is
for the desired host. The SSL connection could have been established with a malicious host that
provided a valid certificate.
Example 3:
The following OpenSSL code ensures that there is a certificate and allows the use of expired
certificates.
Example Language: C (Bad)
if (cert = SSL_get_peer(certificate(ssl)) {
foo=SSL_get_verify_result(ssl);
if ((X509_V_OK==foo) || (X509_V_ERR_CERT_HAS_EXPIRED==foo))
//do stuff
CWE Version 4.14
CWE-295: Improper Certificate Validation
CWE-295: Improper Certificate Validation