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

Allow certificate login #21

Open
wants to merge 1 commit into
base: master
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
26 changes: 18 additions & 8 deletions tpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
# set logger
log = logging.getLogger(__name__)
# disable unsecure SSL warning
requests.packages.urllib3.disable_warnings()
###requests.packages.urllib3.disable_warnings()


class TPMException(Exception):
Expand Down Expand Up @@ -101,6 +101,8 @@ def __init__(self, api, base_url, kwargs):
self.username = False
self.password = False
self.unlock_reason = False
self.certificate = False
self.certificate_key = False
for key in kwargs:
if key == 'private_key':
self.private_key = kwargs[key]
Expand All @@ -112,6 +114,10 @@ def __init__(self, api, base_url, kwargs):
self.password = kwargs[key]
elif key == 'unlock_reason':
self.unlock_reason = kwargs[key]
elif key == 'certificate':
self.certificate = kwargs[key]
elif key == 'certificate_key':
self.certificate_key = kwargs[key]
if self.private_key is not False and self.public_key is not False and\
self.username is False and self.password is False:
log.debug('Using Private/Public Key authentication.')
Expand Down Expand Up @@ -164,21 +170,25 @@ def request(self, path, action, data=''):
try:
if action == 'get':
log.debug('GET request %s' % url)
self.req = requests.get(url, headers=self.headers, auth=auth,
verify=False)

self.req = requests.get(url, headers=self.headers,
auth=auth, verify=True,
cert=(self.certificate, self.certificate_key))
elif action == 'post':
log.debug('POST request %s' % url)
self.req = requests.post(url, headers=self.headers, auth=auth,
verify=False, data=data)
self.req = requests.post(url, headers=self.headers,
auth=auth, verify=True, data=data,
cert=(self.certificate, self.certificate_key))
elif action == 'put':
log.debug('PUT request %s' % url)
self.req = requests.put(url, headers=self.headers,
auth=auth, verify=False,
data=data)
auth=auth, verify=True, data=data,
cert=(self.certificate, self.certificate_key))
elif action == 'delete':
log.debug('DELETE request %s' % url)
self.req = requests.delete(url, headers=self.headers,
verify=False, auth=auth)
verify=True, auth=auth,
cert=(self.certificate, self.certificate_key))

if self.req.content == b'':
result = None
Expand Down