Skip to content

Passing ssh passphrase securely when calling the signing script #323

@ocaisa

Description

@ocaisa

If the ssh key used for signing was passphrased, the signing script has an option to pass that via an environment variable. This is not secure and there is a better way which carries less risk of exposing the passphrase. General proof of concept:

import pexpect
import sys

passphrase = "Rudolf"
key_path = "id_rsa"

cmd = f"ssh-keygen -p -f {key_path} -N ''"

child = pexpect.spawn('/bin/bash', ['-c', cmd])

try:
    index = child.expect([
        "Enter old passphrase:",
        "Your identification has been saved",
        pexpect.EOF,
        pexpect.TIMEOUT
    ], timeout=5)

    if index == 0:
        child.sendline(passphrase)
        child.expect("Your identification has been saved", timeout=5)

    child.expect(pexpect.EOF)
    print("Key conversion succeeded.")

except pexpect.exceptions.ExceptionPexpect as e:
    print("Error during key conversion:", e)

finally:
    child.close()
    if child.exitstatus != 0:
        print("ssh-keygen exited with error.")

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions