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

Fix keyring import from older versions. #8436

Merged
merged 8 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
26 changes: 16 additions & 10 deletions client/keys/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {

var (
tmpDir string
migrator keyring.InfoImporter
migrator keyring.Importer
)

if dryRun, _ := cmd.Flags().GetBool(flags.FlagDryRun); dryRun {
Expand All @@ -73,10 +73,10 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {

defer os.RemoveAll(tmpDir)

migrator, err = keyring.NewInfoImporter(keyringServiceName, "test", tmpDir, buf)
migrator, err = keyring.New(keyringServiceName, keyring.BackendTest, tmpDir, buf)
} else {
backend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend)
migrator, err = keyring.NewInfoImporter(keyringServiceName, backend, rootDir, buf)
migrator, err = keyring.New(keyringServiceName, backend, rootDir, buf)
}

if err != nil {
Expand All @@ -86,12 +86,12 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {
))
}

for _, key := range oldKeys {
legKeyInfo, err := legacyKb.Export(key.GetName())
if err != nil {
return err
}
if len(oldKeys) == 0 {
cmd.Print("Migration Aborted: no keys to migrate")
return nil
}

for _, key := range oldKeys {
keyName := key.GetName()
keyType := key.GetType()

Expand All @@ -107,7 +107,12 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {
}

if keyType != keyring.TypeLocal {
if err := migrator.Import(keyName, legKeyInfo); err != nil {
pubkeyArmor, err := legacyKb.ExportPubKey(keyName)
if err != nil {
return err
}

if err := migrator.ImportPubKey(keyName, pubkeyArmor); err != nil {
return err
}

Expand All @@ -127,10 +132,11 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {
return err
}

if err := migrator.Import(keyName, armoredPriv); err != nil {
if err := migrator.ImportPrivKey(keyName, armoredPriv, migratePassphrase); err != nil {
return err
}
}
cmd.Print("Migration Complete")

return err
}
Binary file removed client/keys/testdata/keys/keys.db/000002.ldb
Binary file not shown.
2 changes: 1 addition & 1 deletion client/keys/testdata/keys/keys.db/CURRENT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MANIFEST-000004
MANIFEST-000011
2 changes: 1 addition & 1 deletion client/keys/testdata/keys/keys.db/CURRENT.bak
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MANIFEST-000000
MANIFEST-000009
81 changes: 63 additions & 18 deletions client/keys/testdata/keys/keys.db/LOG
Original file line number Diff line number Diff line change
@@ -1,18 +1,63 @@
=============== Mar 30, 2020 (CEST) ===============
02:07:34.137606 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
02:07:34.144547 db@open opening
02:07:34.144770 version@stat F·[] S·0B[] Sc·[]
02:07:34.145843 db@janitor F·2 G·0
02:07:34.145875 db@open done T·1.315251ms
02:07:34.335635 db@close closing
02:07:34.335736 db@close done T·98.95µs
=============== Mar 30, 2020 (CEST) ===============
02:08:33.239115 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
02:08:33.239264 version@stat F·[] S·0B[] Sc·[]
02:08:33.239281 db@open opening
02:08:33.239310 journal@recovery F·1
02:08:33.239398 journal@recovery recovering @1
02:08:33.322008 memdb@flush created L0@2 N·4 S·391B "cos..ess,v4":"run..nfo,v3"
02:08:33.323091 version@stat F·[1] S·391B[391B] Sc·[0.25]
02:08:33.421979 db@janitor F·3 G·0
02:08:33.422153 db@open done T·182.707962ms
=============== Feb 1, 2021 (IST) ===============
alessio marked this conversation as resolved.
Show resolved Hide resolved
16:21:11.241398 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
16:21:11.243153 db@open opening
16:21:11.243424 version@stat F·[] S·0B[] Sc·[]
16:21:11.244292 db@janitor F·2 G·0
16:21:11.244303 db@open done T·1.142421ms
16:21:11.244375 db@close closing
16:21:11.244408 db@close done T·31.874µs
=============== Feb 1, 2021 (IST) ===============
16:21:17.369959 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
16:21:17.370084 version@stat F·[] S·0B[] Sc·[]
16:21:17.370100 db@open opening
16:21:17.370135 journal@recovery F·1
16:21:17.370329 journal@recovery recovering @1
16:21:17.370945 version@stat F·[] S·0B[] Sc·[]
16:21:17.374111 db@janitor F·2 G·0
16:21:17.374126 db@open done T·4.016021ms
16:21:17.374195 db@close closing
16:21:17.374225 db@close done T·27.227µs
=============== Feb 1, 2021 (IST) ===============
16:21:48.914309 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
16:21:48.914401 version@stat F·[] S·0B[] Sc·[]
16:21:48.914416 db@open opening
16:21:48.914450 journal@recovery F·1
16:21:48.914706 journal@recovery recovering @2
16:21:48.915231 version@stat F·[] S·0B[] Sc·[]
16:21:48.918621 db@janitor F·2 G·0
16:21:48.918633 db@open done T·4.211047ms
16:21:48.918705 db@close closing
16:21:48.918742 db@close done T·34.202µs
=============== Feb 1, 2021 (IST) ===============
16:22:52.655807 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
16:22:52.655895 version@stat F·[] S·0B[] Sc·[]
16:22:52.655910 db@open opening
16:22:52.655941 journal@recovery F·1
16:22:52.656203 journal@recovery recovering @4
16:22:52.656729 version@stat F·[] S·0B[] Sc·[]
16:22:52.662351 db@janitor F·2 G·0
16:22:52.662365 db@open done T·6.448973ms
16:22:52.662441 db@close closing
16:22:52.662481 db@close done T·36.569µs
=============== Feb 1, 2021 (IST) ===============
16:24:37.777292 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
16:24:37.777381 version@stat F·[] S·0B[] Sc·[]
16:24:37.777395 db@open opening
16:24:37.777428 journal@recovery F·1
16:24:37.777493 journal@recovery recovering @6
16:24:37.777727 version@stat F·[] S·0B[] Sc·[]
16:24:37.780960 db@janitor F·2 G·0
16:24:37.780971 db@open done T·3.570978ms
16:24:37.780980 db@close closing
16:24:37.781006 db@close done T·23.906µs
=============== Feb 1, 2021 (IST) ===============
16:24:43.762162 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
16:24:43.762469 version@stat F·[] S·0B[] Sc·[]
16:24:43.762571 db@open opening
16:24:43.762743 journal@recovery F·1
16:24:43.764835 journal@recovery recovering @8
16:24:43.765010 version@stat F·[] S·0B[] Sc·[]
16:24:43.769368 db@janitor F·2 G·0
16:24:43.769396 db@open done T·6.808452ms
16:24:44.024164 db@close closing
16:24:44.024216 db@close done T·50.711µs
Binary file removed client/keys/testdata/keys/keys.db/MANIFEST-000004
Binary file not shown.
1 change: 1 addition & 0 deletions crypto/keyring/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ type Signer interface {
type Importer interface {
// ImportPrivKey imports ASCII armored passphrase-encrypted private keys.
ImportPrivKey(uid, armor, passphrase string) error

// ImportPubKey imports ASCII armored public keys.
ImportPubKey(uid string, armor string) error
}
Expand Down