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

Validate key expiration time #22

Merged
merged 1 commit into from
Dec 31, 2020
Merged

Validate key expiration time #22

merged 1 commit into from
Dec 31, 2020

Conversation

slawekjaranowski
Copy link
Member

fix #7

@slawekjaranowski slawekjaranowski added the enhancement New feature or request. label Dec 30, 2020
@slawekjaranowski slawekjaranowski self-assigned this Dec 30, 2020
@sonarcloud
Copy link

sonarcloud bot commented Dec 30, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

93.8% 93.8% Coverage
0.0% 0.0% Duplication

*/
public static void verifyKeyExpiration(PGPSecretKey secretKey, PGPSecretKeyRing secretKeyRing) {

long validSeconds = secretKey.getPublicKey().getValidSeconds();
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if that is always correct. There is a method PGPSecretKey.replacePublicKey that would set another public key with a different valid seconds number into the same secret key. Effectively our code here would see the new expiration date. Is that correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know what for is method PGPSecretKey.replacePublicKey but in our code it is not call. We read secret key from file and don't change content of it. So it will be always correct.

Copy link
Contributor

Choose a reason for hiding this comment

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

My fear actually is not our code calling that on its own, but whether that other external tools modify the key file in a way that replacePublicKey does, and I wonder what the outcome is: Will our code still see the expiration date of the secret key, or will it now see the expiration date of that new public key? As this question has impact on the correctness of our validation check, maybe we should ask at the Bouncy Castle user list to be on the safe side?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can try to verify internal key signature, each uid and subkey has self signed signature, but we are in the same situation if somebody can change file with key probably generate new valid self signature.

Another idea is verify system access level to key file - if only is writable / readable by owner.

I will assume that key file is protected correctly by operating system.

Copy link
Contributor

Choose a reason for hiding this comment

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

Before hastily hacking in something that we possibly don't need at all, I have asked our questions at Bouncy Castle. If you like, we can merge the PR as is and I will file the open questions as an open issue in our tracker?

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, we can open issue on our list and link with bc

Copy link
Contributor

@mkarg mkarg left a comment

Choose a reason for hiding this comment

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

I am generally +1 for the benefits this PR brings, but actually vote 0 because I am not convinced that we actually read the corrrect date out of the key as I mentioned in my comment. Feel free to merge if you like, but I just have a bad gut feeling about this question being uncleared.

@slawekjaranowski slawekjaranowski merged commit 6a22a57 into master Dec 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request.
Development

Successfully merging this pull request may close these issues.

Validate key expiration time
2 participants