feat: ssh私钥支持设置密码 (#346)
This commit is contained in:
@@ -2273,6 +2273,12 @@ ctrl+x 保存退出',
|
|||||||
'required' => true,
|
'required' => true,
|
||||||
'show' => 'auth==1',
|
'show' => 'auth==1',
|
||||||
],
|
],
|
||||||
|
'passphrase' => [
|
||||||
|
'name' => '私钥密码',
|
||||||
|
'type' => 'input',
|
||||||
|
'placeholder' => '若私钥有设置密码,请填写此项',
|
||||||
|
'show' => 'auth==1',
|
||||||
|
],
|
||||||
'windows' => [
|
'windows' => [
|
||||||
'name' => '是否Windows',
|
'name' => '是否Windows',
|
||||||
'type' => 'radio',
|
'type' => 'radio',
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace app\lib\deploy;
|
namespace app\lib\deploy;
|
||||||
|
|
||||||
|
use app\lib\CertHelper;
|
||||||
use app\lib\DeployInterface;
|
use app\lib\DeployInterface;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
@@ -49,7 +50,8 @@ class ssh implements DeployInterface
|
|||||||
fclose($stream);
|
fclose($stream);
|
||||||
$this->log('私钥已保存到:' . $config['pem_key_file']);
|
$this->log('私钥已保存到:' . $config['pem_key_file']);
|
||||||
} elseif ($config['format'] == 'pfx') {
|
} elseif ($config['format'] == 'pfx') {
|
||||||
$pfx = \app\lib\CertHelper::getPfx($fullchain, $privatekey, $config['pfx_pass'] ? $config['pfx_pass'] : null);
|
$pfx_pass = $config['pfx_pass'] ?? null;
|
||||||
|
$pfx = CertHelper::getPfx($fullchain, $privatekey, $pfx_pass);
|
||||||
|
|
||||||
$stream = fopen("ssh2.sftp://$sftp{$config['pfx_file']}", 'w');
|
$stream = fopen("ssh2.sftp://$sftp{$config['pfx_file']}", 'w');
|
||||||
if (!$stream) {
|
if (!$stream) {
|
||||||
@@ -157,7 +159,8 @@ class ssh implements DeployInterface
|
|||||||
file_put_contents($privateKeyPath, $this->config['privatekey']);
|
file_put_contents($privateKeyPath, $this->config['privatekey']);
|
||||||
file_put_contents($publicKeyPath, $publicKey);
|
file_put_contents($publicKeyPath, $publicKey);
|
||||||
umask($umask);
|
umask($umask);
|
||||||
if (!ssh2_auth_pubkey_file($connection, $this->config['username'], $publicKeyPath, $privateKeyPath)) {
|
$passphrase = $this->config['passphrase'] ?? null; // 私钥密码
|
||||||
|
if (!ssh2_auth_pubkey_file($connection, $this->config['username'], $publicKeyPath, $privateKeyPath, $passphrase)) {
|
||||||
throw new Exception('私钥认证失败');
|
throw new Exception('私钥认证失败');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user