mirror of
https://github.com/jkl1337/duplicacy.git
synced 2026-01-03 12:14:39 -06:00
Assume the signed certificate of a ssh key file has the suffix '-cert.pub'.
So if the ssh key file is 'mykey' then Duplicacy will check if the signed certificate can be loaded from the file 'mykey-cert.pub'. This avoids the use of another preference variable 'ssh_cert_file'.
This commit is contained in:
@@ -336,7 +336,7 @@ func CreateStorage(preference Preference, resetPassword bool, threads int) (stor
|
|||||||
keyFile = GetPassword(preference, "ssh_key_file", "Enter the path of the private key file:",
|
keyFile = GetPassword(preference, "ssh_key_file", "Enter the path of the private key file:",
|
||||||
true, resetPassword)
|
true, resetPassword)
|
||||||
|
|
||||||
var key ssh.Signer
|
var keySigner ssh.Signer
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if keyFile == "" {
|
if keyFile == "" {
|
||||||
@@ -347,7 +347,7 @@ func CreateStorage(preference Preference, resetPassword bool, threads int) (stor
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
LOG_INFO("SSH_PUBLICKEY", "Failed to read the private key file: %v", err)
|
LOG_INFO("SSH_PUBLICKEY", "Failed to read the private key file: %v", err)
|
||||||
} else {
|
} else {
|
||||||
key, err = ssh.ParsePrivateKey(content)
|
keySigner, err = ssh.ParsePrivateKey(content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Contains(err.Error(), "cannot decode encrypted private keys") {
|
if strings.Contains(err.Error(), "cannot decode encrypted private keys") {
|
||||||
LOG_TRACE("SSH_PUBLICKEY", "The private key file is encrypted")
|
LOG_TRACE("SSH_PUBLICKEY", "The private key file is encrypted")
|
||||||
@@ -355,7 +355,7 @@ func CreateStorage(preference Preference, resetPassword bool, threads int) (stor
|
|||||||
if len(passphrase) == 0 {
|
if len(passphrase) == 0 {
|
||||||
LOG_INFO("SSH_PUBLICKEY", "No passphrase to descrypt the private key file %s", keyFile)
|
LOG_INFO("SSH_PUBLICKEY", "No passphrase to descrypt the private key file %s", keyFile)
|
||||||
} else {
|
} else {
|
||||||
key, err = ssh.ParsePrivateKeyWithPassphrase(content, []byte(passphrase))
|
keySigner, err = ssh.ParsePrivateKeyWithPassphrase(content, []byte(passphrase))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LOG_INFO("SSH_PUBLICKEY", "Failed to parse the encrypted private key file %s: %v", keyFile, err)
|
LOG_INFO("SSH_PUBLICKEY", "Failed to parse the encrypted private key file %s: %v", keyFile, err)
|
||||||
}
|
}
|
||||||
@@ -364,37 +364,35 @@ func CreateStorage(preference Preference, resetPassword bool, threads int) (stor
|
|||||||
LOG_INFO("SSH_PUBLICKEY", "Failed to parse the private key file %s: %v", keyFile, err)
|
LOG_INFO("SSH_PUBLICKEY", "Failed to parse the private key file %s: %v", keyFile, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
certFile := GetPasswordFromPreference(preference, "ssh_cert_file")
|
if keySigner != nil {
|
||||||
var pubKey ssh.PublicKey
|
certFile := keyFile + "-cert.pub"
|
||||||
var certSigner ssh.Signer
|
if stat, err := os.Stat(certFile); err == nil && !stat.IsDir() {
|
||||||
|
|
||||||
if certFile != "" {
|
|
||||||
LOG_DEBUG("SSH_CERTIFICATE", "Attempting to use ssh certificate from file %s", certFile)
|
LOG_DEBUG("SSH_CERTIFICATE", "Attempting to use ssh certificate from file %s", certFile)
|
||||||
var content []byte
|
var content []byte
|
||||||
content, err = ioutil.ReadFile(certFile)
|
content, err = ioutil.ReadFile(certFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LOG_INFO("SSH_CERTIFICATE", "Failed to read ssh certificate file: %v", err)
|
LOG_INFO("SSH_CERTIFICATE", "Failed to read ssh certificate file %s: %v", certFile, err)
|
||||||
} else {
|
} else {
|
||||||
pubKey, _, _, _, err = ssh.ParseAuthorizedKey(content)
|
pubKey, _, _, _, err := ssh.ParseAuthorizedKey(content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LOG_INFO("SSH_CERTIFICATE", "Failed parse ssh certificate file: %v", err)
|
LOG_INFO("SSH_CERTIFICATE", "Failed parse ssh certificate file %s: %v", certFile, err)
|
||||||
} else {
|
} else {
|
||||||
certSigner, err = ssh.NewCertSigner(pubKey.(*ssh.Certificate), key)
|
certSigner, err := ssh.NewCertSigner(pubKey.(*ssh.Certificate), keySigner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LOG_INFO("SSH_CERTIFICATE", "Failed to create certificate signer: %v", err)
|
LOG_INFO("SSH_CERTIFICATE", "Failed to create certificate signer: %v", err)
|
||||||
|
} else {
|
||||||
|
keySigner = certSigner
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we have a valid cert signer use it instead of the normal private key
|
if keySigner != nil {
|
||||||
if certSigner != nil {
|
signers = append(signers, keySigner)
|
||||||
signers = append(signers, certSigner)
|
|
||||||
} else if key != nil {
|
|
||||||
signers = append(signers, key)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(signers) > 0 {
|
if len(signers) > 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user