Skip to content

Conversation

@iamnotacake
Copy link
Contributor

@iamnotacake iamnotacake commented Mar 11, 2022

When AcraServer/AcraTranslator starts and loads all the keys into cache (if the option is enabled), ignore old keys related to AcraConnector.
Add new key kind "legacy" and ignore this key if found inside keystore.

Checklist

When AcraServer starts and loads all the keys into cache (if the option
is enabled), ignore old keys related to AcraConnector.
Add new key kind "legacy" and ignore this key if found inside keystore.
@iamnotacake iamnotacake requested a review from Lagovas March 11, 2022 15:00
@Lagovas
Copy link
Collaborator

Lagovas commented Mar 15, 2022

TODO:

  • add integration tests that checks that acra works correctly with old keys and logs about existing legacy keys.

}, nil
}

if lastKeyPart == "server" || lastKeyPart == "server.pub" || lastKeyPart == "translator" || lastKeyPart == "translator.pub" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct me if I am wrong.

Here, you are checking that if fileInfo contains .pub suffix and you truncate it, right?
https://github.com/cossacklabs/acra/pull/510/files#diff-ca8937b8ce39cdc821c3d9b826aecd30d40cc5beb2aec26ea11497f39e13658fR847

So why are you checking scenarios that lastKeyPart == "server.pub" or lastKeyPart == "translator.pub". Is it not enough to just check lastKeyPart == "server" || lastKeyPart == "translator"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See these lines above

components := strings.Split(fileInfo.Name(), "_") // note the separator
// ...
lastKeyPart := components[len(components)-1]

And checked while debugging that lastKeyPart really contains server.pub or translator.pub when corresponding files exist.

@iamnotacake iamnotacake marked this pull request as ready for review March 21, 2022 11:51
tests/test.py Outdated
super().setUp()

def create_key_file(name):
open(f"{KEYS_FOLDER.name}/{name}", "w").close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really want to create some test oriented key files inside general KEYS_FOLDER directory. Probably it would be better to create some temporary directory and drop it when test is finished?

Since `testLegacyKeysIgnored` is failing right now, no need to trigger
CI yet. Resolving the issue, maybe key files are created in a wrong dir.
tests/test.py Outdated

def tearDown(self):
for key_file in self.legacy_key_files:
os.remove(f"{KEYS_FOLDER.name}/{key_file}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

$ python3 -c 'import os; os.remove("/tlqkeqwleqwlekqweq");'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: '/tlqkeqwleqwlekqweq'

we should catch exceptions here too or we may fail on first file and leave all remaining files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, wrapped with try: ... except: pass

Change order of test initialization so the legacy key files will be
created and then read by Acra. Now we're sure Acra sees but ignores
them, as expected.

Wrapped legacy key file deletion with try-catch to avoid cases where the
removal will suddenly fail and break more things.
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.

lgtm

@iamnotacake iamnotacake merged commit adfadc4 into cossacklabs:master Mar 25, 2022
@iamnotacake iamnotacake deleted the anatolii/T2502-ignore-old-keys-on-startup branch March 25, 2022 22:57
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.

3 participants