| Server IP : 162.144.4.212 / Your IP : 216.73.216.108 Web Server : Apache System : Linux gator2125.hostgator.com 5.14.0-162.23.1.9991722448259.nf.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 31 18:11:45 UTC 2024 x86_64 User : cozeellc ( 2980) PHP Version : 8.3.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/lib/python3.9/site-packages/oci/auth/ |
Upload File : |
# coding: utf-8
# Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
# This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa
import threading
class SessionKeySupplier(object):
# Magic number recommended by cryptography.io docs. Also see: http://www.daemonology.net/blog/2009-06-11-cryptographic-right-answers.html
PUBLIC_EXPONENT = 65537
def __init__(self, key_size=2048):
"""
A supplier which vends public and private keys, and can refresh the keys it uses.
:param int key_size (optional):
The key size to use when generating private keys. Defaults to 2048 if not provided.
"""
self.key_size = key_size
self.private_key = rsa.generate_private_key(
public_exponent=self.PUBLIC_EXPONENT,
key_size=self.key_size,
backend=default_backend()
)
self._refresh_lock = threading.Lock()
def get_key_pair(self):
self._refresh_lock.acquire()
private_key = self.private_key
self._refresh_lock.release()
return {'private': private_key, 'public': private_key.public_key()}
def refresh(self):
self._refresh_lock.acquire()
try:
self.private_key = rsa.generate_private_key(
public_exponent=self.PUBLIC_EXPONENT,
key_size=self.key_size,
backend=default_backend()
)
finally:
self._refresh_lock.release()