Skip to content

Commit

Permalink
fix: remove public key validation (#123)
Browse files Browse the repository at this point in the history
* fix: remove public key validation

* code review

---------

Co-authored-by: Avram Tudor <tudor.avram@8x8.com>
  • Loading branch information
quitrk and Avram Tudor authored Nov 18, 2024
1 parent 9879143 commit 67f708c
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions skynet/auth/jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,32 @@
log = get_logger(__name__)


def is_valid_key(key: str) -> bool:
return key.startswith('-----BEGIN PUBLIC KEY-----')


@alru_cache(maxsize=asap_pub_keys_max_cache_size)
async def get_public_key(kid: str) -> str:
encoded_pub_key_name = sha256(kid.encode('UTF-8')).hexdigest()
pub_key_remote_filename = f'{encoded_pub_key_name}.pem'

url = f'{asap_pub_keys_url}/{asap_pub_keys_folder}/{pub_key_remote_filename}'

log.info(f'Fetching public key {kid} from {url}')
key = await http_client.get(url, 'text')
response = await http_client.request('GET', url)

if response.status != 200:
error = f'Failed to retrieve public key {kid}'

if is_valid_key(key):
return key
if asap_pub_keys_fallback_folder:
url = f'{asap_pub_keys_url}/{asap_pub_keys_fallback_folder}/{pub_key_remote_filename}'

if asap_pub_keys_fallback_folder:
url = f'{asap_pub_keys_url}/{asap_pub_keys_fallback_folder}/{pub_key_remote_filename}'
log.info(f'Fetching public key {kid} from {url}')

log.info(f'Fetching public key {kid} from {url}')
key = await http_client.get(url, 'text')
response = await http_client.request('GET', url)

if is_valid_key(key):
return key
if response.status != 200:
raise Exception(error)
else:
raise Exception(error)

raise Exception(f'Failed to retrieve public key {kid}')
return await response.text()


async def authorize(jwt_incoming: str) -> dict:
Expand Down

0 comments on commit 67f708c

Please sign in to comment.