CWE-593 is titled Authentication Bypass: OpenSSL CTX Object Modified after SSL Objects are Created. The product changes the SSL_CTX after connection creation has begun, and older SSL objects created from the original context may be affected by the change.
It is a configuration-ordering bug in code that uses OpenSSL directly.
How it happens
An SSL_CTX holds shared settings: certificates, verification mode, ciphers. Each SSL object is created from it. The trouble starts when a program creates connections and then keeps adjusting the context, perhaps to toggle verification or load another certificate.
SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
SSL *ssl = SSL_new(ctx); /* connection created */
SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL); /* context changed afterwards */
Code that assumed existing connections were frozen at their original settings may find they are not.
What an attacker gains
The record lists an access control bypass: no authentication takes place in the process, bypassing an assumed protection of encryption. It also notes a confidentiality risk, since encrypted communication between a user and a trusted host may be open to sniffing.
How to find it
Static analysis is the practical route. Trace each SSL_CTX from creation to its last use and flag any setter that can run after an SSL_new() from the same context.
How to fix it
MITRE's mitigations are short.
- Set up an
SSL_CTXcompletely before creating SSL objects from it. - Most
SSL_CTXfunctions haveSSLcounterparts that act on SSL-type objects. Use those for per-connection changes. - More broadly, prefer a language or library that provides a cryptography framework at a higher level of abstraction.
SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL); /* finish configuration */
SSL *ssl = SSL_new(ctx); /* then create connections */
SSL_set_verify(ssl, SSL_VERIFY_PEER, NULL); /* per-connection change */
Quick check
What should you use for a change that applies to one connection only?
The SSL counterpart of the SSL_CTX function, which acts on the SSL object rather than the shared context.