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

change pkey generate function #205

Closed
wants to merge 2 commits into from
Closed
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: 22 additions & 4 deletions accesser/utils/certmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,28 @@ def create_root_ca():
))


pkey = rsa.generate_private_key(
public_exponent=65537,
key_size=4096,
)
def create_private_key():
pkey = rsa.generate_private_key(
public_exponent=65537,
key_size=4096,
)
# save private key
(Path(certpath) / "private.key").write_bytes(
pkey.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.NoEncryption(),
)
)
return pkey

def generate_private_key():
if not os.path.exists(os.path.join(certpath, "private.key")):
return create_private_key()
else:
return serialization.load_pem_private_key((Path(certpath) / "private.key").read_bytes(), password=None)

pkey = generate_private_key()

def create_certificate(server_name):
rootpem = (Path(certpath) / "root.crt").read_bytes()
Expand Down