Files
sam ac98b68bda
deploy / plan (push) Failing after 2s
deploy / gate (push) Skipped
deploy / archied-image (push) Skipped
deploy / agent-image (push) Skipped
deploy / dist-zip (push) Skipped
feat(archied): connection commit identity and SSH commit signing (#1816)
2026-11-09 00:05:32 +11:00

34 lines
865 B
Go

package worktree
import (
"bytes"
"context"
"fmt"
"io"
"github.com/go-git/go-git/v6"
"github.com/hiddeco/sshsig"
"golang.org/x/crypto/ssh"
)
// sshSigner signs commits the way `git -c gpg.format=ssh` does, so forges
// verify them against the account's SSH signing key.
type sshSigner struct{ key ssh.Signer }
// NewSSHSigner parses an OpenSSH private key for commit signing.
func NewSSHSigner(privateKey []byte) (git.Signer, error) {
key, err := ssh.ParsePrivateKey(privateKey)
if err != nil {
return nil, fmt.Errorf("parse signing key: %w", err)
}
return sshSigner{key: key}, nil
}
func (s sshSigner) Sign(_ context.Context, message io.Reader) ([]byte, error) {
sig, err := sshsig.Sign(message, s.key, sshsig.HashSHA512, "git")
if err != nil {
return nil, fmt.Errorf("ssh sign: %w", err)
}
return bytes.TrimSpace(sshsig.Armor(sig)), nil
}