Skip to content
Open
Show file tree
Hide file tree
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
29 changes: 17 additions & 12 deletions PccsAdminTool/lib/intelsgx/credential.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import keyring
try:
import keyring
except:
keyring = None
import getpass

class Credentials:
Expand All @@ -7,11 +10,12 @@ class Credentials:

def get_admin_token(self):
admin_token = ""
try:
print("Please note: A prompt may appear asking for your keyring password to access stored credentials.")
admin_token = keyring.get_password(self.APPNAME, self.KEY_ADMINTOKEN)
except keyring.errors.KeyringError as ke:
admin_token = ""
if keyring is not None:
try:
print("Please note: A prompt may appear asking for your keyring password to access stored credentials.")
admin_token = keyring.get_password(self.APPNAME, self.KEY_ADMINTOKEN)
except keyring.errors.KeyringError as ke:
admin_token = ""

while admin_token is None or admin_token == '':
admin_token = getpass.getpass(prompt="Please input your administrator password for PCCS service:")
Expand All @@ -24,10 +28,11 @@ def get_admin_token(self):
return admin_token

def set_admin_token(self, token):
try:
print("Please note: A prompt may appear asking for your keyring password to access stored credentials.")
keyring.set_password(self.APPNAME, self.KEY_ADMINTOKEN, token)
except keyring.errors.PasswordSetError as ke:
print("Failed to store admin token.")
return False
if keyring is not None:
try:
print("Please note: A prompt may appear asking for your keyring password to access stored credentials.")
keyring.set_password(self.APPNAME, self.KEY_ADMINTOKEN, token)
except keyring.errors.PasswordSetError as ke:
print("Failed to store admin token.")
return False
return True
32 changes: 28 additions & 4 deletions PccsAdminTool/pccsadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ def get_platforms(self):
if response.status_code == 200:
self._write_output_file(output_file, response)
elif response.status_code == 401: # Authentication error
self.credentials.set_admin_token('')
try:
self.credentials.set_admin_token('')
except:
# If keyring is unavailable, we don't want to trigger
# traceback, as the user may have declined to save
# the key in the keyring earlier
pass
print("Authentication failed.")
else:
self._handle_error(response)
Expand Down Expand Up @@ -150,7 +156,13 @@ def upload_collaterals(self):
if response.status_code == 200:
print("Collaterals uploaded successfully.")
elif response.status_code == 401: # Authentication error
self.credentials.set_admin_token('')
try:
self.credentials.set_admin_token('')
except:
# If keyring is unavailable, we don't want to trigger
# traceback, as the user may have declined to save
# the key in the keyring earlier
pass
print("Authentication failed.")
else:
self._handle_error(response)
Expand All @@ -166,7 +178,13 @@ def upload_collaterals(self):
if response.status_code == 200:
print("Policy uploaded successfully with policy ID :" + response.text)
elif response.status_code == 401: # Authentication error
self.credentials.set_admin_token('')
try:
self.credentials.set_admin_token('')
except:
# If keyring is unavailable, we don't want to trigger
# traceback, as the user may have declined to save
# the key in the keyring earlier
pass
print("Authentication failed.")
else:
self._handle_error(response)
Expand Down Expand Up @@ -199,7 +217,13 @@ def refresh_cache_database(self):
if response.status_code == 200:
print("The cache database was refreshed successfully.")
elif response.status_code == 401: # Authentication error
self.credentials.set_admin_token('')
try:
self.credentials.set_admin_token('')
except:
# If keyring is unavailable, we don't want to trigger
# traceback, as the user may have declined to save
# the key in the keyring earlier
pass
print("Authentication failed.")
else:
self._handle_error(response)
Expand Down