CWE Rule 693
Description
Rule Description
The product does not use or incorrectly uses a protection mechanism that provides sufficient defense against directed attacks against the product.
Polyspace Implementation
The rule checker checks for Nonsecure SSL/TLS protocol.
Examples
This issue occurs when you do not
disable nonsecure protocols in an SSL_CTX
or SSL
context object before using the object for handling SSL/TLS connections.
For instance, you disable the protocols SSL2.0 and TLS1.0 but forget to disable the protocol SSL3.0, which is also considered weak.
/* Create and configure context */
ctx = SSL_CTX_new(SSLv23_method());
SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_TLSv1);
/* Use context to handle connection */
ssl = SSL_new(ctx);
SSL_set_fd(ssl, NULL);
ret = SSL_connect(ssl);
The protocols SSL2.0, SSL3.0, and TLS1.0 are considered weak in the cryptographic community. Using one of these protocols can expose your connections to cross-protocol attacks. The attacker can decrypt an RSA ciphertext without knowing the RSA private key.
Disable the nonsecure protocols in the context object before using the object to handle connections.
/* Create and configure context */
ctx = SSL_CTX_new(SSLv23_method());
SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#define fatal_error() exit(-1)
int ret;
int func(){
SSL_CTX *ctx;
SSL *ssl;
SSL_library_init();
/* context configuration */
ctx = SSL_CTX_new(SSLv23_client_method());
if (ctx==NULL) fatal_error();
ret = SSL_CTX_use_certificate_file(ctx, "cert.pem", SSL_FILETYPE_PEM);
if (ret <= 0) fatal_error();
ret = SSL_CTX_load_verify_locations(ctx, NULL, "ca/path");
if (ret <= 0) fatal_error();
/* Handle connection */
ssl = SSL_new(ctx);
if (ssl==NULL) fatal_error();
SSL_set_fd(ssl, NULL);
return SSL_connect(ssl); //Noncompliant
}
In this example, the protocols SSL2.0, SSL3.0, and TLS1.0 are not disabled in the context object before the object is used for a new connection.
Disable nonsecure protocols before using the objects for a new connection. Use
the function SSL_CTX_set_options
to disable the protocols
SSL2.0, SSL3.0, and TLS1.0.
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#define fatal_error() exit(-1)
int ret;
int func(){
SSL_CTX *ctx;
SSL *ssl;
SSL_library_init();
/* context configuration */
ctx = SSL_CTX_new(SSLv23_client_method());
if (ctx==NULL) fatal_error();
SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
ret = SSL_CTX_use_certificate_file(ctx, "cert.pem", SSL_FILETYPE_PEM);
if (ret <= 0) fatal_error();
ret = SSL_CTX_load_verify_locations(ctx, NULL, "ca/path");
if (ret <= 0) fatal_error();
/* Handle connection */
ssl = SSL_new(ctx);
if (ssl==NULL) fatal_error();
SSL_set_fd(ssl, NULL);
return SSL_connect(ssl);
}
Check Information
Category: Others |
Version History
Introduced in R2024a
See Also
External Websites
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)