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

Extend acra-keys list with rotated keys #636

Merged
merged 7 commits into from
Feb 15, 2023

Conversation

Zhaars
Copy link
Contributor

@Zhaars Zhaars commented Feb 14, 2023

Extend acra-keys list with displaying historical keys for V1/V2. Introduce the new flag --historical-keys for the list subcommand.

Checklist

Extend acra-keys list with historical keys listing
@Zhaars Zhaars requested a review from Lagovas February 14, 2023 13:17
cmd/acra-keys/keys/list-keys_test.go Outdated Show resolved Hide resolved
}

for i := 0; i < timesToGenerateHistoricalKeys; i++ {
if descriptions[i+3].CreationTime.String() != pubKeysTimes[i].String() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if descriptions[i+3].CreationTime.String() != pubKeysTimes[i].String() {
if descriptions[i+timesToGenerateHistoricalKeys].CreationTime.String() != pubKeysTimes[i].String() {

plus we can merge two cycles into one and add comment that public keys stored after private keys in the descriptions

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and can we compare content of the keys? at least public keys which are not encrypted to be sure that they returned properly according to names?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we can compare since list subcommand just returns KeyDescription without its content.

t.Fatal(err)
}

if len(descriptions) != timesToGenerateHistoricalKeys {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description contains public and private keys together? can we check it and validate? for example, we can remember all keys generated above with an order and then compare them. Validate that first generated is last rotated key and last generated is first key. Also, we can compare public content of keys

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, under V2 only one keyring - storage.keyring. Actually we cant compare the contents of the key as list subcommand just return KeyDescription without its content.


for _, file := range files {
if file.IsDir() {
continue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it valid situation? maybe we should return error in such cases because it is unexpected folder structure?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed to return error in such cases

// PrintHistoricalKeysTable prints table which describes keys in a human readable format
// into the writer.
// Code is shared by `acra-keys list` and a couple of tests
func PrintHistoricalKeysTable(keys []KeyDescription, writer io.Writer) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add example of the expected output here? it simplifies understanding what the code does and what is expected

//
// client/${client_id}/storage
//
// And transport paths look like this, with an additional component:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now we don't have transport paths and we expected 3 parts of the path below. So, lets update comment to actual the state

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, will fix in another method too.

//components := strings.Split(path, string(filepath.Separator))
components := strings.Split(path, string(filepath.Separator))
if len(components) == 3 {
if components[0] == clientPrefix && components[2] == storageSuffix {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets use named indexes to simplify reading?

const (
  _ = iota  // I don't know how to name this part))
  clientIDIndex
  purposeIndex
)
if components[clientIDIndex] == ...

}

result := make([]keystore.KeyDescription, 0, len(keys)-1)
for i := len(keys) - 1; i > 0; i-- {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this complicated iteration pushed to think that we should test an order of result lists for rotated keys to be sure that we return and list them in the same order for v1 and v2 keystores

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we do test it.

@Zhaars Zhaars requested a review from Lagovas February 15, 2023 00:35
@Zhaars Zhaars changed the title Extend acra-keys list with historical keys Extend acra-keys list with rotated keys Feb 15, 2023
Copy link
Collaborator

@Lagovas Lagovas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job

cmd/acra-keys/keys/list-keys.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants