From: Charles McGarvey Date: Fri, 1 Dec 2017 03:13:27 +0000 (-0700) Subject: make crypt programs package variables X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fgroupsecret;a=commitdiff_plain;h=3bc3c5b0b3648ae001e38ee72e65dc7880dec9bd;hp=cdfc47a7e1357f76047015704ee61fe25d3c8f01 make crypt programs package variables --- diff --git a/lib/App/GroupSecret/Crypt.pm b/lib/App/GroupSecret/Crypt.pm index a7110f7..e64fa40 100644 --- a/lib/App/GroupSecret/Crypt.pm +++ b/lib/App/GroupSecret/Crypt.pm @@ -21,6 +21,9 @@ our @EXPORT_OK = qw( encrypt_aes_256_cbc ); +our $OPENSSL = 'openssl'; +our $SSH_KEYGEN = 'ssh-keygen'; + sub _croak { require Carp; Carp::croak(@_) } sub _usage { _croak("Usage: @_\n") } @@ -35,7 +38,7 @@ Get a certain number of secure random bytes. sub generate_secure_random_bytes { my $size = shift or _usage(q{generate_secure_random_bytes($num_bytes)}); - my @cmd = (qw{openssl rand}, $size); + my @cmd = ($OPENSSL, 'rand', $size); my $out; my $pid = open2($out, undef, @cmd); @@ -60,7 +63,7 @@ Read a RFC4716 (SSH2) public key from a file, converting it to PKCS8 (PEM). sub read_openssh_public_key { my $filepath = shift or _usage(q{read_openssh_public_key($filepath)}); - my @cmd = (qw{ssh-keygen -e -m PKCS8 -f}, $filepath); + my @cmd = ($SSH_KEYGEN, qw{-e -m PKCS8 -f}, $filepath); my $out; my $pid = open2($out, undef, @cmd); @@ -85,7 +88,7 @@ Get the fingerprint of an OpenSSH private or public key. sub read_openssh_key_fingerprint { my $filepath = shift or _usage(q{read_openssh_key_fingerprint($filepath)}); - my @cmd = (qw{ssh-keygen -l -E md5 -f}, $filepath); + my @cmd = ($SSH_KEYGEN, qw{-l -E md5 -f}, $filepath); my $out; my $pid = open2($out, undef, @cmd); @@ -135,7 +138,7 @@ sub decrypt_rsa { $filepath = $temp->filename; } - my @cmd = (qw{openssl rsautl -decrypt -oaep -in}, $filepath, '-inkey', $privkey); + my @cmd = ($OPENSSL, qw{rsautl -decrypt -oaep -in}, $filepath, '-inkey', $privkey); push @cmd, ('-out', $outfile) if $outfile; my $out; @@ -181,7 +184,7 @@ sub encrypt_rsa { close $temp2; my $keypath = $temp2->filename; - my @cmd = (qw{openssl rsautl -encrypt -oaep -pubin -inkey}, $keypath, '-in', $filepath); + my @cmd = ($OPENSSL, qw{rsautl -encrypt -oaep -pubin -inkey}, $keypath, '-in', $filepath); push @cmd, ('-out', $outfile) if $outfile; my $out; @@ -220,7 +223,7 @@ sub decrypt_aes_256_cbc { $filepath = $temp->filename; } - my @cmd = (qw{openssl aes-256-cbc -d -pass stdin -md sha256 -in}, $filepath); + my @cmd = ($OPENSSL, qw{aes-256-cbc -d -pass stdin -md sha256 -in}, $filepath); push @cmd, ('-out', $outfile) if $outfile; my ($in, $out); @@ -262,7 +265,7 @@ sub encrypt_aes_256_cbc { $filepath = $temp->filename; } - my @cmd = (qw{openssl aes-256-cbc -pass stdin -md sha256 -in}, $filepath); + my @cmd = ($OPENSSL, qw{aes-256-cbc -pass stdin -md sha256 -in}, $filepath); push @cmd, ('-out', $outfile) if $outfile; my ($in, $out);