mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-16 20:08:09 +00:00
initial public release
This commit is contained in:
37
src/api-service/__app__/onefuzzlib/azure/auth.py
Normal file
37
src/api-service/__app__/onefuzzlib/azure/auth.py
Normal file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
import os
|
||||
import subprocess # nosec - used for ssh key generation
|
||||
import tempfile
|
||||
from typing import Tuple
|
||||
from uuid import uuid4
|
||||
|
||||
from onefuzztypes.models import Authentication
|
||||
|
||||
|
||||
def generate_keypair() -> Tuple[str, str]:
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
filename = os.path.join(tmpdir, "key")
|
||||
|
||||
cmd = ["ssh-keygen", "-t", "rsa", "-f", filename, "-P", "", "-b", "2048"]
|
||||
subprocess.check_output(cmd) # nosec - all arguments are under our control
|
||||
|
||||
with open(filename, "r") as handle:
|
||||
private = handle.read()
|
||||
|
||||
with open(filename + ".pub", "r") as handle:
|
||||
public = handle.read().strip()
|
||||
|
||||
return (public, private)
|
||||
|
||||
|
||||
def build_auth() -> Authentication:
|
||||
public_key, private_key = generate_keypair()
|
||||
auth = Authentication(
|
||||
password=str(uuid4()), public_key=public_key, private_key=private_key
|
||||
)
|
||||
return auth
|
Reference in New Issue
Block a user