Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ExtendedAgent #123

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion agent/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func Eq(a, b ssh.PublicKey) bool {
}

func (vaultAgent vaultAgent) Sign(key ssh.PublicKey, data []byte) (*ssh.Signature, error) {
return vaultAgent.SignWithFlags(key, data, agent.SignatureFlagReserved)
}

func (vaultAgent vaultAgent) SignWithFlags(key ssh.PublicKey, data []byte, flags agent.SignatureFlags) (*ssh.Signature, error) {
log.Info("Sign Request for key: %s", ssh.FingerprintSHA256(key))
if vaultAgent.vault.Keyring.IsLocked() {
if !vaultAgent.unlockRequestAction() {
Expand Down Expand Up @@ -156,7 +160,30 @@ func (vaultAgent vaultAgent) Sign(key ssh.PublicKey, data []byte) (*ssh.Signatur
} else {
notify.Notify("Goldwarden", fmt.Sprintf("SSH Signing Request Approved for %s", sshKey.Name), "", 10*time.Second, func() {})
}
return signer.Sign(rand, data)

algo := ""

switch flags {
case agent.SignatureFlagRsaSha256:
algo = ssh.KeyAlgoRSASHA256
case agent.SignatureFlagRsaSha512:
algo = ssh.KeyAlgoRSASHA512
default:
return signer.Sign(rand, data)
}

log.Info("%s algorithm requested", algo)

algoSigner, err := ssh.NewSignerWithAlgorithms(signer.(ssh.AlgorithmSigner), []string{algo})
if err != nil {
return nil, err
}

return algoSigner.SignWithAlgorithm(rand, data, algo)
}

func (vaultAgent) Extension(extensionType string, contents []byte) ([]byte, error) {
return nil, agent.ErrExtensionUnsupported
}

func (vaultAgent) Signers() ([]ssh.Signer, error) {
Expand Down
Loading