-
Notifications
You must be signed in to change notification settings - Fork 15
Set SSL certificate verification to enabled by default with possible override from configuration #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,7 +73,6 @@ def __init__( | |
| self.loggingEnabled = loggingEnabled | ||
| self.logger = logger | ||
| self.retry = retry | ||
| requests.packages.urllib3.disable_warnings() | ||
| if self.config["token"] == "" or time.time() > self.config["date_limit"]: | ||
| if self.config["private_key"] is not None or self.config["pathToKey"] is not None: | ||
| token_info = self.get_jwt_token_and_expiry_for_config( | ||
|
|
@@ -139,7 +138,7 @@ def get_oauth_token_and_expiry_for_config( | |
| "code": config["auth_code"] | ||
| } | ||
| response = requests.post( | ||
| config["oauthTokenEndpoint"], data=oauth_payload, verify=False | ||
| config["oauthTokenEndpoint"], data=oauth_payload, verify=self.config["sslVerification"] | ||
| ) | ||
| return self._token_postprocess(response=response, verbose=verbose, save=save) | ||
|
|
||
|
|
@@ -186,7 +185,10 @@ def get_jwt_token_and_expiry_for_config( | |
| "jwt_token": encoded_jwt, | ||
| } | ||
| response = requests.post( | ||
| config["jwtTokenEndpoint"], headers=header_jwt, data=payload, verify=False | ||
| config["jwtTokenEndpoint"], | ||
| headers=header_jwt, | ||
| data=payload, | ||
| verify=self.config["sslVerification"] | ||
| ) | ||
| return self._token_postprocess(response=response, verbose=verbose, save=save) | ||
|
|
||
|
|
@@ -298,20 +300,20 @@ def getData( | |
| f"Start GET request to {endpoint} with header: {json.dumps(headers)}" | ||
| ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we just set verify up top once and just use it in the requests.get workflow, feels cleaner
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't clear what you meant - the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The latter |
||
| if params is None and data is None: | ||
| res = requests.get(endpoint, headers=headers, verify=False) | ||
| res = requests.get(endpoint, headers=headers, verify=self.config["sslVerification"]) | ||
| elif params is not None and data is None: | ||
| if self.loggingEnabled: | ||
| self.logger.debug(f"params: {json.dumps(params)}") | ||
| res = requests.get(endpoint, headers=headers, params=params, verify=False) | ||
| res = requests.get(endpoint, headers=headers, params=params, verify=self.config["sslVerification"]) | ||
| elif params is None and data is not None: | ||
| if self.loggingEnabled: | ||
| self.logger.debug(f"data: {json.dumps(data)}") | ||
| res = requests.get(endpoint, headers=headers, data=data, verify=False) | ||
| res = requests.get(endpoint, headers=headers, data=data, verify=self.config["sslVerification"]) | ||
| elif params is not None and data is not None: | ||
| if self.loggingEnabled: | ||
| self.logger.debug(f"params: {json.dumps(params)}") | ||
| self.logger.debug(f"data: {json.dumps(data)}") | ||
| res = requests.get(endpoint, headers=headers, params=params, data=data, verify=False) | ||
| res = requests.get(endpoint, headers=headers, params=params, data=data, verify=self.config["sslVerification"]) | ||
| if self.loggingEnabled: | ||
| self.logger.debug(f"endpoint used: {res.request.url}") | ||
| self.logger.debug(f"params used: {params}") | ||
|
|
@@ -370,9 +372,9 @@ def headData( | |
| f"Start GET request to {endpoint} with header: {json.dumps(headers)}" | ||
| ) | ||
| if params is None: | ||
| res = requests.head(endpoint, headers=headers, verify=False) | ||
| res = requests.head(endpoint, headers=headers, verify=self.config["sslVerification"]) | ||
| if params is not None: | ||
| res = requests.head(endpoint, headers=headers, params=params, verify=False) | ||
| res = requests.head(endpoint, headers=headers, params=params, verify=self.config["sslVerification"]) | ||
| try: | ||
| res_header = res.headers() | ||
| except: | ||
|
|
@@ -407,27 +409,27 @@ def postData( | |
| f"Start POST request to {endpoint} with header: {json.dumps(headers)}" | ||
| ) | ||
| if params is None and data is None: | ||
| res = requests.post(endpoint, headers=headers, verify=False) | ||
| res = requests.post(endpoint, headers=headers, verify=self.config["sslVerification"]) | ||
| elif params is not None and data is None: | ||
| if self.loggingEnabled: | ||
| self.logger.debug(f"params: {json.dumps(params)}") | ||
| res = requests.post(endpoint, headers=headers, params=params, verify=False) | ||
| res = requests.post(endpoint, headers=headers, params=params, verify=self.config["sslVerification"]) | ||
| elif params is None and data is not None: | ||
| if self.loggingEnabled: | ||
| self.logger.debug(f"data: {json.dumps(data)}") | ||
| res = requests.post(endpoint, headers=headers, data=json.dumps(data), verify=False) | ||
| res = requests.post(endpoint, headers=headers, data=json.dumps(data), verify=self.config["sslVerification"]) | ||
| elif params is not None and data is not None: | ||
| if self.loggingEnabled: | ||
| self.logger.debug(f"params: {json.dumps(params)}") | ||
| self.logger.debug(f"data: {json.dumps(data)}") | ||
| res = requests.post( | ||
| endpoint, headers=headers, params=params, data=json.dumps(data), verify=False | ||
| endpoint, headers=headers, params=params, data=json.dumps(data), verify=self.config["sslVerification"] | ||
| ) | ||
| elif bytesData is not None: | ||
| if self.loggingEnabled: | ||
| self.logger.debug(f"bytes data used") | ||
| res = requests.post( | ||
| endpoint, headers=headers, params=params, data=bytesData, verify=False | ||
| endpoint, headers=headers, params=params, data=bytesData, verify=self.config["sslVerification"] | ||
| ) | ||
| try: | ||
| formatUse = kwargs.get("format", "json") | ||
|
|
@@ -482,17 +484,17 @@ def patchData( | |
| if params is not None and data is None: | ||
| if self.loggingEnabled: | ||
| self.logger.debug(f"params: {json.dumps(params)}") | ||
| res = requests.patch(endpoint, headers=headers, params=params, verify=False) | ||
| res = requests.patch(endpoint, headers=headers, params=params, verify=self.config["sslVerification"]) | ||
| elif params is None and data is not None: | ||
| if self.loggingEnabled: | ||
| self.logger.debug(f"data: {json.dumps(data)}") | ||
| res = requests.patch(endpoint, headers=headers, data=json.dumps(data), verify=False) | ||
| res = requests.patch(endpoint, headers=headers, data=json.dumps(data), verify=self.config["sslVerification"]) | ||
| elif params is not None and data is not None: | ||
| if self.loggingEnabled: | ||
| self.logger.debug(f"params: {json.dumps(params)}") | ||
| self.logger.debug(f"data: {json.dumps(data)}") | ||
| res = requests.patch( | ||
| endpoint, headers=headers, params=params, data=json.dumps(data), verify=False | ||
| endpoint, headers=headers, params=params, data=json.dumps(data), verify=self.config["sslVerification"] | ||
| ) | ||
| try: | ||
| res_json = res.json() | ||
|
|
@@ -536,17 +538,17 @@ def putData( | |
| if params is not None and data is None: | ||
| if self.loggingEnabled: | ||
| self.logger.debug(f"params: {json.dumps(params)}") | ||
| res = requests.put(endpoint, headers=headers, params=params, verify=False) | ||
| res = requests.put(endpoint, headers=headers, params=params, verify=self.config["sslVerification"]) | ||
| elif params is None and data is not None: | ||
| if self.loggingEnabled: | ||
| self.logger.debug(f"data: {json.dumps(data)}") | ||
| res = requests.put(endpoint, headers=headers, data=json.dumps(data), verify=False) | ||
| res = requests.put(endpoint, headers=headers, data=json.dumps(data), verify=self.config["sslVerification"]) | ||
| elif params is not None and data is not None: | ||
| if self.loggingEnabled: | ||
| self.logger.debug(f"params: {json.dumps(params)}") | ||
| self.logger.debug(f"data: {json.dumps(data)}") | ||
| res = requests.put( | ||
| endpoint, headers=headers, params=params, data=json.dumps(data), verify=False | ||
| endpoint, headers=headers, params=params, data=json.dumps(data), verify=self.config["sslVerification"] | ||
| ) | ||
| try: | ||
| res_json = res.json() | ||
|
|
@@ -579,9 +581,9 @@ def deleteData( | |
| f"Start PUT request to {endpoint} with header: {json.dumps(headers)}" | ||
| ) | ||
| if params is None: | ||
| res = requests.delete(endpoint, headers=headers, verify=False) | ||
| res = requests.delete(endpoint, headers=headers, verify=self.config["sslVerification"]) | ||
| elif params is not None: | ||
| res = requests.delete(endpoint, headers=headers, params=params, verify=False) | ||
| res = requests.delete(endpoint, headers=headers, params=params, verify=self.config["sslVerification"]) | ||
| try: | ||
| status_code = res.status_code | ||
| if status_code >= 400: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,7 +61,8 @@ Normally your config file will look like this: | |
| "secret": "<YourSecret>", | ||
| "pathToKey": "<path/to/your/privatekey.key>", | ||
| "sandbox-name": "prod", | ||
| "environment": "prod" | ||
| "environment": "prod", | ||
| "ssl_verification": true | ||
| } | ||
| ``` | ||
|
|
||
|
|
@@ -172,6 +173,34 @@ aepp.configure( | |
|
|
||
| **NOTE** The `environment` parameter is optional and defaults to "prod". | ||
|
|
||
| ### SSL certificate verification | ||
|
|
||
| By default `aepp` will enforce SSL certificate verification on any outgoing HTTP requests. | ||
|
|
||
| There can be cases where you might want to disable this verification. This includes, but not limited to: | ||
| - Development workloads might not need the same strong guarantees you would want in production workloads. | ||
| - If you are behind a proxy / VPN you might under certain scenarios get a `SSLCertVerificationError` when trying to connect to AEP APIs. | ||
|
|
||
| If you are in one of these situation where disabling SSL certificate verification is appropriate, you can tell `aepp` to do that by using: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: replace situation with situations, also one thought/question, how would the customer know if they have to do this or not?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a good question, but I would expect in most cases if someone is behind a proxy or on a VPN with special rules they will be aware of it. From what I could see there's only very few situations where SSL certificate verification can fail. If you know other cases let me know I can add more, otherwise we can stick to that for now.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I heard for other packages that I developed that it prevented network operation (so the package cannot be used). That would be one possible scenario to test if that is the case. Maybe we can ask the customer to provide a screenshot of the error and place it in a FAQ page.
|
||
|
|
||
| ```python | ||
| import aepp | ||
| aepp.configure( | ||
| org_id=my_org_id, | ||
| tech_id=my_tech_id, | ||
| secret=my_secret, | ||
| private_key=my_key_as_string, | ||
| client_id=my_client_id, | ||
| environment="prod", | ||
| sandbox=my_sandbox_id, | ||
| ssl_verification=False | ||
| ) | ||
| ``` | ||
|
|
||
| Or simply update the JSON configuration generated earlier if you have one and set `ssl_verification` parameter to `false`. | ||
|
|
||
| Please note disabling SSL certificate verification is not recommended overall, but we provide this facility in `aepp` for the few situations that do warrant it if you know what you are doing. | ||
|
|
||
| ### Tip for multi sandbox work | ||
|
|
||
| The `aepp` module contains a parameter named `connectInstance` for `importConfig` and `configure` methods that provide a way to store the configuration setup.\ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add that in the
connectInstanceclass.It is used to save the configuration loaded into an instance in order to re-use it later on with all the sub module.
I would imagine we need to add it in 3 places:
self.__configObject__(starting line 320)