Skip to content

Commit a677887

Browse files
authored
Trust Any Certificate Docs (#1744)
* Added readme + change in sidebars.js
1 parent a505b14 commit a677887

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Trust Any Certificate
2+
3+
## Overview
4+
5+
Enabling “Trust Any Certificate” in an integration disables certificate validation and uses less-hardened SSL standards.
6+
7+
## Code usage
8+
9+
When constructing the `BaseClient` in your integrations, set `verify=False` to disable SSL checks and allow legacy ciphers:
10+
11+
```python
12+
from CommonServerPython import BaseClient
13+
14+
client = BaseClient(
15+
base_url="https://api.example.com",
16+
verify=False
17+
)
18+
response = client._http_request(...)
19+
```
20+
21+
## How it works
22+
23+
### _http_request()
24+
25+
In the implementation of `_http_request`, the verify parameter is passed to the underlying HTTP request from the `BaseClient`:
26+
27+
```python
28+
class BaseClient:
29+
...
30+
def _http_request():
31+
...
32+
res = self._session.request(..., verify=self._verify)
33+
```
34+
35+
When `self._verify` is set to False, SSL certificate verification is disabled. This means the client will accept insecure certificates.
36+
37+
### Skip Certificate Verification
38+
39+
When `verify=False` is set, the following function is triggered to delete certificate environment variables.
40+
This ensures that no extra CA bundles are loaded.
41+
For requests versions earlier than 2.28, this step is necessary to fully disable certificate validation in addition to passing the `self._verify` to the session.request.
42+
43+
```python
44+
def skip_cert_verification()
45+
for k in ('REQUESTS_CA_BUNDLE', 'CURL_CA_BUNDLE'):
46+
if k in os.environ:
47+
del os.environ[k]
48+
```
49+
50+
### Python 3.10+ & Custom SSLAdapter
51+
52+
Python 3.10 increased OpenSSL’s default security level to 2, which rejects many older cipher suites and breaks connections to legacy servers ([see CPython PR #25778](https://github.com/python/cpython/pull/25778)).
53+
To mitigate this, `BaseClient` mounts a custom SSL adapter when `verify=False`:
54+
55+
```python
56+
if IS_PY3 and PY_VER_MINOR >= 10 and not verify:
57+
self._session.mount('https://', SSLAdapter(verify=verify))
58+
```
59+
60+
### SSLAdapter
61+
62+
When `verify=False` on Python 3.10+, `SSLAdapter` creates a custom `ssl.SSLContext` that:
63+
64+
1. **Disables hostname checks:**
65+
66+
```python
67+
if not verify and IS_PY3:
68+
self.context.check_hostname = False
69+
```
70+
71+
2. **Enabling Legacy TLS Renegotiation:**
72+
73+
```python
74+
if not verify and ssl.OPENSSL_VERSION_INFO >= (3, 0, 0):
75+
self.context.options |= ssl.OP_LEGACY_SERVER_CONNECT
76+
```
77+
78+
The OP_LEGACY_SERVER_CONNECT flag tells OpenSSL to allow legacy TLS renegotiation. Relevant when a server doesn’t support the secure‐renegotiation extension (RFC 5746).
79+
80+
3. **Lowers OpenSSL security level to 1 & Enables a [cipher list](https://github.com/demisto/content/blob/e3807159cae86ac30ecbb3c51ec82dbac7512d3d/Packs/Base/Scripts/CommonServerPython/CommonServerPython.py#L9127)**
81+
82+
```python
83+
CIPHERS_STRING = (
84+
'@SECLEVEL=1:'
85+
'ECDHE+AESGCM:'
86+
'ECDHE+CHACHA20:'
87+
'DHE+AESGCM:'
88+
'DHE+CHACHA20:'
89+
'ECDH+AESGCM:'
90+
'DH+AESGCM:'
91+
'ECDH+AES:'
92+
'DH+AES:'
93+
'RSA+AESGCM:'
94+
'RSA+AES:'
95+
'!aNULL:'
96+
'!eNULL:'
97+
'!MD5:'
98+
'!DSS'
99+
)
100+
context = create_urllib3_context(ciphers=CIPHERS_STRING)
101+
```
102+
103+
This configuration restores legacy ciphers (excluding null, MD5, DSS).

sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ const sidebars = {
159159
"integrations/scheduled-commands",
160160
"integrations/yml-from-python-code-gen",
161161
"integrations/fetch-incidents-lookback",
162+
"integrations/Trust-any-certificate",
162163
]
163164
}
164165
]

0 commit comments

Comments
 (0)