Skip to content

Commit

Permalink
Simplify, fix CS, and fix variable name on GPG 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Nov 17, 2022
1 parent 4ddf479 commit 048fed1
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions lib/Horde/Crypt/Pgp/Backend/Binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ public function generateKey($opts)

$input = array();

/* Create the config file necessary for GnuPG to run in batch mode. */
/* TODO: Sanitize input, More user customizable? */
$input = array(
'Key-Type: ' . $opts['key_type'],
'Key-Length: ' . $opts['keylength'],
'Subkey-Type: ' . $opts['subkey_type'],
'Subkey-Length: ' . $opts['keylength'],
'Name-Real: ' . $opts['name'],
'Name-Email: ' . $opts['email'],
'Expire-Date: ' . $expire,
'Passphrase: ' . $opts['passphrase'],
'Preferences: AES256 AES192 AES CAST5 3DES SHA256 SHA512 SHA384 SHA224 SHA1 ZLIB BZIP2 ZIP Uncompressed'
);

if (!$this->_gnupg21) {
/*
* %secring and %pubring have been deprecated since GnuPG 2.1 and %secring% is not available
Expand All @@ -132,29 +146,12 @@ public function generateKey($opts)
$input = array_merge(
$input,
array(
'%secring '. $sec_file,
'%secring '. $secret_file,
'%pubring ' . $pub_file,
)
);
}

/* Create the config file necessary for GnuPG to run in batch mode. */
/* TODO: Sanitize input, More user customizable? */
$input = array_merge (
$input,
array(
'Key-Type: ' . $opts['key_type'],
'Key-Length: ' . $opts['keylength'],
'Subkey-Type: ' . $opts['subkey_type'],
'Subkey-Length: ' . $opts['keylength'],
'Name-Real: ' . $opts['name'],
'Name-Email: ' . $opts['email'],
'Expire-Date: ' . $expire,
'Passphrase: ' . $opts['passphrase'],
'Preferences: AES256 AES192 AES CAST5 3DES SHA256 SHA512 SHA384 SHA224 SHA1 ZLIB BZIP2 ZIP Uncompressed'
)
);

if (!empty($opts['comment'])) {
$input[] = 'Name-Comment: ' . $opts['comment'];
}
Expand All @@ -174,9 +171,7 @@ public function generateKey($opts)
);

if ($this->_gnupg21) {

/* Export public key from the ephemeral home dir (see comment above for details). */

$result = $this->_callGpg(
array(
'--export',
Expand All @@ -191,7 +186,6 @@ public function generateKey($opts)
$public_key = $result->output;

/* Export secret key from the ephemeral home dir (see comment above for details). */

$result = $this->_callGpg(
array(
'--export-secret-key',
Expand All @@ -205,13 +199,10 @@ public function generateKey($opts)
);
$this->_ensureResult($result);
$secret_key = $result->output;

} else {

/* Get the keys from the temp files. */
$public_key = file_get_contents($pub_file);
$secret_key = file_get_contents($secret_file);

}

/* If either key is empty, something went wrong. */
Expand Down

0 comments on commit 048fed1

Please sign in to comment.