Skip to content

Commit

Permalink
Fix Rot to use decrypted Keys before trying to decrypt other keys
Browse files Browse the repository at this point in the history
  • Loading branch information
thequailman committed Mar 29, 2024
1 parent 668cd47 commit 0dddafb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions go/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ func (c *cfg) decryptPrivateKey(ctx context.Context) errs.Err {
return errNotInitialized
}

c.decryptKeysEncrypted(ctx)

var err error

var out []byte
Expand All @@ -69,6 +67,23 @@ func (c *cfg) decryptPrivateKey(ctx context.Context) errs.Err {
}
}

if c.privateKey.IsNil() {
c.decryptKeysEncrypted(ctx)
keys := c.keys.Keys()

for i := range c.DecryptKeys {
out, err = c.DecryptKeys[i].PrivateKey.Decrypt(keys)
if err == nil {
k, err := cryptolib.ParseKey[cryptolib.KeyProviderPrivate](string(out))
if err == nil {
c.privateKey = k

break
}
}
}
}

if err != nil {
return logger.Error(ctx, errs.ErrReceiver.Wrap(err))
}
Expand Down
2 changes: 1 addition & 1 deletion shared
Submodule shared updated from 786611 to 771629

0 comments on commit 0dddafb

Please sign in to comment.