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

SSlibKey: fix ecdsa nistp384 default scheme #763

Merged
merged 2 commits into from
Apr 12, 2024

Conversation

lukpueh
Copy link
Member

@lukpueh lukpueh commented Apr 2, 2024

fixes #669

Fix SSlibKey.from_crypto to assign the correct default scheme for ecdsa nistp384 keys.

This includes refactoring from_crypto to use a single switch over pyca/cryptography public key object type, in order to infer securesystemslib "keytype" and default scheme.

Previously, only "keytype" was inferred from the key object, and the default scheme then from the keytype. Given that for the same keytype (ecdsa) there can be different default schemes, this needed to be changed.

The refactoring also moves the keytype-specific public key value serialization to the same switch.

lukpueh added 2 commits April 2, 2024 13:37
Added test key pair was created with openssl:

```
openssl genpkey -algorithm EC \
        -pkeyopt ec_paramgen_curve:P-384 \
        -pkeyopt ec_param_enc:named_curve \
        -out ecdsa_secp384r1_private.pem

openssl pkey -in ecdsa_secp384r1_private.pem -pubout \
                -out ecdsa_secp384r1_public.pem
```

default keyid:
0155661bdf705f621a74f55eef36c9ae041e456141eced7a45d4a1f75ded9ac0

Signed-off-by: Lukas Puehringer <[email protected]>
fixes secure-systems-lab#669

Fix SSlibKey.from_crypto to assign the correct default scheme, for
ecdsa nistp384 keys.

This includes refactoring from_crypto to use a single switch over
pyca/cryptography public key object type, in order to infer
securesystemslib "keytype" and default scheme.

Previously, only "keytype" was inferred from the key object, and the
default scheme then from the keytype. Given that for the same keytype
(ecdsa) there can be different default schemes, this needed to be
changed.

The refactoring also moves the keytype-specific public key value
serialization to the same switch.

Signed-off-by: Lukas Puehringer <[email protected]>
encoding=Encoding.PEM, format=PublicFormat.SubjectPublicKeyInfo
)
public_key_value = pem.decode()
keytype, default_scheme, public_key_value = cls._from_crypto(public_key)
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 briefly considered to also return the list of supported schemes here, so that we can validate the optionally passed scheme (see a1f5ec2).

But I'll leave this for another PR.

@lukpueh lukpueh requested a review from jku April 3, 2024 12:40
Copy link
Collaborator

@jku jku left a comment

Choose a reason for hiding this comment

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

seems right to me

@lukpueh lukpueh merged commit 73bba08 into secure-systems-lab:main Apr 12, 2024
17 checks passed
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.

"ecdsa-sha2-nistp256" wrongly used as default scheme for any "ecdsa" key
2 participants