@@ -16,7 +16,6 @@ import (
16
16
"github.com/sirupsen/logrus"
17
17
18
18
"github.com/getsops/sops/v3/logging"
19
- "golang.org/x/crypto/ssh"
20
19
)
21
20
22
21
const (
@@ -238,69 +237,6 @@ func (key *MasterKey) TypeToIdentifier() string {
238
237
return KeyTypeIdentifier
239
238
}
240
239
241
- // readPublicKeyFile attempts to read a public key based on the given private
242
- // key path. It assumes the public key is in the same directory, with the same
243
- // name, but with a ".pub" extension. If the public key cannot be read, an
244
- // error is returned.
245
- func readPublicKeyFile (privateKeyPath string ) (ssh.PublicKey , error ) {
246
- publicKeyPath := privateKeyPath + ".pub"
247
- f , err := os .Open (publicKeyPath )
248
- if err != nil {
249
- return nil , fmt .Errorf ("failed to obtain public %q key for %q SSH key: %w" , publicKeyPath , privateKeyPath , err )
250
- }
251
- defer f .Close ()
252
- contents , err := io .ReadAll (f )
253
- if err != nil {
254
- return nil , fmt .Errorf ("failed to read %q: %w" , publicKeyPath , err )
255
- }
256
- pubKey , _ , _ , _ , err := ssh .ParseAuthorizedKey (contents )
257
- if err != nil {
258
- return nil , fmt .Errorf ("failed to parse %q: %w" , publicKeyPath , err )
259
- }
260
- return pubKey , nil
261
- }
262
-
263
- // parseSSHIdentityFromPrivateKeyFile returns an age.Identity from the given
264
- // private key file. If the private key file is encrypted, it will configure
265
- // the identity to prompt for a passphrase.
266
- func parseSSHIdentityFromPrivateKeyFile (keyPath string ) (age.Identity , error ) {
267
- keyFile , err := os .Open (keyPath )
268
- if err != nil {
269
- return nil , fmt .Errorf ("failed to open file: %w" , err )
270
- }
271
- defer keyFile .Close ()
272
- contents , err := io .ReadAll (keyFile )
273
- if err != nil {
274
- return nil , fmt .Errorf ("failed to read file: %w" , err )
275
- }
276
- id , err := agessh .ParseIdentity (contents )
277
- if sshErr , ok := err .(* ssh.PassphraseMissingError ); ok {
278
- pubKey := sshErr .PublicKey
279
- if pubKey == nil {
280
- pubKey , err = readPublicKeyFile (keyPath )
281
- if err != nil {
282
- return nil , err
283
- }
284
- }
285
- passphrasePrompt := func () ([]byte , error ) {
286
- pass , err := readPassphrase (fmt .Sprintf ("Enter passphrase for %q:" , keyPath ))
287
- if err != nil {
288
- return nil , fmt .Errorf ("could not read passphrase for %q: %v" , keyPath , err )
289
- }
290
- return pass , nil
291
- }
292
- i , err := agessh .NewEncryptedSSHIdentity (pubKey , contents , passphrasePrompt )
293
- if err != nil {
294
- return nil , fmt .Errorf ("could not create encrypted SSH identity: %w" , err )
295
- }
296
- return i , nil
297
- }
298
- if err != nil {
299
- return nil , fmt .Errorf ("malformed SSH identity in %q: %w" , keyPath , err )
300
- }
301
- return id , nil
302
- }
303
-
304
240
// loadAgeSSHIdentity attempts to load the age SSH identity based on an SSH
305
241
// private key from the SopsAgeSshPrivateKeyFileEnv environment variable. If the
306
242
// environment variable is not present, it will fall back to `~/.ssh/id_ed25519`
0 commit comments