Skip to content
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

PM-11586: Bitwarden API self-signed certificate fix #66

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/bitwarden_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from typing import Optional, Dict, Any

import requests
Expand Down Expand Up @@ -37,6 +38,18 @@ def _join_urls(base: str, *paths: str):
return url


def _get_custom_ca_certificate_location() -> Optional[str]:
if 'SPLUNK_HOME' not in os.environ:
return None

app_cacerts_file = os.path.join(os.environ.get('SPLUNK_HOME'), 'etc', 'auth',
'bitwarden_event_logs_cacerts.pem')
if not os.path.isfile(app_cacerts_file):
return None

return app_cacerts_file


class BitwardenApi:
def __init__(self, api_config: BitwardenApiConfig):
self.logger = get_logger()
Expand All @@ -61,7 +74,8 @@ def get_access_token(self) -> str:
response = requests.post(url,
headers=headers,
data=data,
timeout=REQUESTS_TIMEOUT)
timeout=REQUESTS_TIMEOUT,
verify=_get_custom_ca_certificate_location())

response_dict = self.__get_response_json(response)

Expand Down Expand Up @@ -117,7 +131,8 @@ def __send_get_request(self, url: str, query_params: Optional[Dict[str, Any]]) -
response = requests.get(url,
headers=headers,
params=query_params,
timeout=REQUESTS_TIMEOUT)
timeout=REQUESTS_TIMEOUT,
verify=_get_custom_ca_certificate_location())

return self.__get_response_json(response)

Expand Down
Loading