-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Florian Agbuya <[email protected]>
- Loading branch information
Showing
5 changed files
with
141 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
import atexit | ||
import tempfile | ||
import subprocess | ||
from pathlib import Path | ||
|
||
|
||
def create_ssl_certs(): | ||
"""Generate temporary SSL certificates for testing. | ||
Returns dict with cert paths or None if certs exist in env.""" | ||
if all(x in os.environ for x in ['SERVER_KEY', 'SERVER_CERT', 'CLIENT_KEY', 'CLIENT_CERT']): | ||
return None | ||
|
||
cert_dir = tempfile.mkdtemp() | ||
for cert_name in ["server", "client"]: | ||
subprocess.run([ | ||
"openssl", "req", "-x509", "-newkey", "rsa:2048", | ||
"-keyout", os.path.join(cert_dir, f"{cert_name}.key"), | ||
"-nodes", | ||
"-out", os.path.join(cert_dir, f"{cert_name}.pem"), | ||
"-sha256", "-days", "1", | ||
"-subj", "/" | ||
], check=True) | ||
|
||
certs = { | ||
"SERVER_KEY": os.path.join(cert_dir, "server.key"), | ||
"SERVER_CERT": os.path.join(cert_dir, "server.pem"), | ||
"CLIENT_KEY": os.path.join(cert_dir, "client.key"), | ||
"CLIENT_CERT": os.path.join(cert_dir, "client.pem") | ||
} | ||
|
||
def cleanup(): | ||
if os.path.exists(cert_dir): | ||
for file in Path(cert_dir).glob("*"): | ||
file.unlink() | ||
os.rmdir(cert_dir) | ||
|
||
atexit.register(cleanup) | ||
return certs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters