| 1 | package sasquatchscip-go gomod github.com/muesli/sasquatch . `github.com/muesli/sasquatch`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.14 fmt/" |
| 5 | "io/ioutilscip-go gomod github.com/golang/go/src go1.14 `io/ioutil`/" |
| 6 | |
| 7 | "golang.org/x/crypto/sshscip-go gomod golang.org/x/crypto 123391ffb6de `golang.org/x/crypto/ssh`/" |
| 8 | ) |
| 9 | |
| 10 | // A Recipient is a public key or other value that can encrypt an opaque file |
| 11 | // key to a recipient stanza. |
| 12 | type Recipientscip-go gomod github.com/muesli/sasquatch . `github.com/muesli/sasquatch`/Recipient# interface { |
| 13 | Typescip-go gomod github.com/muesli/sasquatch . `github.com/muesli/sasquatch`/Recipient#Type.() string |
| 14 | Wrapscip-go gomod github.com/muesli/sasquatch . `github.com/muesli/sasquatch`/Recipient#Wrap.(fileKey []byte) (*Stanzascip-go gomod github.com/muesli/sasquatch . `github.com/muesli/sasquatch`/Stanza#, error) |
| 15 | } |
| 16 | |
| 17 | // FindRecipients returns all available recipients. |
| 18 | func FindRecipientsscip-go gomod github.com/muesli/sasquatch . `github.com/muesli/sasquatch`/FindRecipients().() []Recipientscip-go gomod github.com/muesli/sasquatch . `github.com/muesli/sasquatch`/Recipient# { |
| 19 | // from disk |
| 20 | keys, err := FindSSHKeysscip-go gomod github.com/muesli/sasquatch . `github.com/muesli/sasquatch`/FindSSHKeys().() |
| 21 | if err != nil { |
| 22 | return nil |
| 23 | } |
| 24 | |
| 25 | ids := []Recipientscip-go gomod github.com/muesli/sasquatch . `github.com/muesli/sasquatch`/Recipient#{} |
| 26 | for _, key := range keys { |
| 27 | key += ".pub" |
| 28 | // fmt.Println("parsing", key) |
| 29 | c, err := ioutilscip-go gomod github.com/golang/go/src go1.14 `io/ioutil`/.ReadFilescip-go gomod github.com/golang/go/src go1.14 `io/ioutil`/ReadFile().(key) |
| 30 | if err != nil { |
| 31 | // fmt.Println(err) |
| 32 | continue |
| 33 | } |
| 34 | |
| 35 | r, err := ParseRecipientscip-go gomod github.com/muesli/sasquatch . `github.com/muesli/sasquatch`/ParseRecipient().(string(c)) |
| 36 | if err != nil { |
| 37 | // fmt.Println(err) |
| 38 | continue |
| 39 | } |
| 40 | ids = append(ids, r) |
| 41 | } |
| 42 | |
| 43 | // from agent |
| 44 | signers, err := SSHAgentSignersscip-go gomod github.com/muesli/sasquatch . `github.com/muesli/sasquatch`/SSHAgentSigners().() |
| 45 | if err != nil { |
| 46 | return ids |
| 47 | } |
| 48 | |
| 49 | for _, signer := range signers { |
| 50 | i, err := NewChallengeRecipientscip-go gomod github.com/muesli/sasquatch . `github.com/muesli/sasquatch`/NewChallengeRecipient().(signer) |
| 51 | if err != nil { |
| 52 | continue |
| 53 | } |
| 54 | |
| 55 | ids = append(ids, i) |
| 56 | } |
| 57 | |
| 58 | return ids |
| 59 | } |
| 60 | |
| 61 | // ParseRecipient creates a Recipient from an SSH public key. |
| 62 | func ParseRecipientscip-go gomod github.com/muesli/sasquatch . `github.com/muesli/sasquatch`/ParseRecipient().(s string) (Recipientscip-go gomod github.com/muesli/sasquatch . `github.com/muesli/sasquatch`/Recipient#, error) { |
| 63 | pubKey, _, _, _, err := sshscip-go gomod golang.org/x/crypto 123391ffb6de `golang.org/x/crypto/ssh`/.ParseAuthorizedKeyscip-go gomod golang.org/x/crypto 123391ffb6de `golang.org/x/crypto/ssh`/ParseAuthorizedKey().([]byte(s)) |
| 64 | if err != nil { |
| 65 | return nil, fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.14 fmt/Errorf().("malformed SSH recipient: %q: %v", s, err) |
| 66 | } |
| 67 | |
| 68 | var r Recipientscip-go gomod github.com/muesli/sasquatch . `github.com/muesli/sasquatch`/Recipient# |
| 69 | switch t := pubKey.Typescip-go gomod golang.org/x/crypto 123391ffb6de `golang.org/x/crypto/ssh`/PublicKey#Type().(); t { |
| 70 | case "ssh-rsa": |
| 71 | r, err = NewRSARecipientscip-go gomod github.com/muesli/sasquatch . `github.com/muesli/sasquatch`/NewRSARecipient().(pubKey) |
| 72 | case "ssh-ed25519": |
| 73 | r, err = NewEd25519Recipientscip-go gomod github.com/muesli/sasquatch . `github.com/muesli/sasquatch`/NewEd25519Recipient().(pubKey) |
| 74 | default: |
| 75 | return nil, fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.14 fmt/Errorf().("unknown SSH recipient type: %q", t) |
| 76 | } |
| 77 | if err != nil { |
| 78 | return nil, fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.14 fmt/Errorf().("malformed SSH recipient: %q: %v", s, err) |
| 79 | } |
| 80 | |
| 81 | return r, nil |
| 82 | } |