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

Get the keyid ? and ecdsa-with-SHA256? #1

Open
developer2013 opened this issue Jul 6, 2021 · 25 comments
Open

Get the keyid ? and ecdsa-with-SHA256? #1

developer2013 opened this issue Jul 6, 2021 · 25 comments

Comments

@developer2013
Copy link

developer2013 commented Jul 6, 2021

Hello,

how can i create the keyid for the certificate and get an SHA256 Key?

thank you very much
developer2013

@nofaceinbook
Copy link
Owner

Hi,
this was not relevant for my tests. However, the keyid should consist of the first 8 hex values of SHA256 of the certificate of the signing key you use. Check out the script from @dirkx for generating all keys and certificates used in this context by using openssl: https://github.com/ehn-dcc-development/ehn-sign-verify-python-trivial/blob/main/gen-csca-dsc.sh

@developer2013
Copy link
Author

Thank's that worked.
i have one last question: how can I change the algorithm to ECDSA prime256v1 ?
thanks

@nofaceinbook
Copy link
Owner

Well, my understandig is that the algorithm above or used for the key in the code did use ECDS with prime2561.
(openssl ecparam -name prime256v1 -genkey -noout -out sign.key)

@developer2013
Copy link
Author

but there is some issue: Could not deserialize key data. The data may be in an "
ValueError: Could not deserialize key data. The data may be in an incorrect format or it may be encrypted with an unsupported algorithm.

keyid = '30593013'

pem = b'-----BEGIN EC PRIVATE KEY-----\n'
b'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAETHfi8foQF4UtSNVxSFxeu7W+gMxd'
b'SGElhdo7825SD3Lyb+Sqh4G6Kra0ro1BdrM6Qx+hsUx4Qwdby7QY0pzxyA=='
b'\n-----END EC PRIVATE KEY-----'

@nofaceinbook
Copy link
Owner

Seems you are missing / at end of these lines (refer to my key in the code). Or you put all together in one single long line string between b'......'

@developer2013
Copy link
Author

sorry, that's not working :( the same error

pem = b'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAETHfi8foQF4UtSNVxSFxeu7W+gMxdSGElhdo7825SD3Lyb+Sqh4G6Kra0ro1BdrM6Qx+hsUx4Qwdby7QY0pzxyA==/'

@nofaceinbook
Copy link
Owner

You are now missing begin and end of certificate statements. Do do it exactly the way as in my example and it should work. Don't forget the / after each line....

@nofaceinbook
Copy link
Owner

And after /n'

@developer2013
Copy link
Author

I got the same error:

pem = b'-----BEGIN EC PRIVATE KEY-----\n'
b'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAETHfi8foQF4UtSNVxSFxeu7W+gMxd\n'
b'SGElhdo7825SD3Lyb+Sqh4G6Kra\n'
b'0ro1BdrM6Qx+hsUx4Qwdby7QY0pzxyA=='
b'\n-----END EC PRIVATE KEY-----'

it's the same code from you.
can you check it with this key for me?
thanks

@nofaceinbook
Copy link
Owner

Ok. Same error with your key. Actually it seems a bit short. Are you sure you did not miss a part?
Which command did you use for key generation?

@dirkx-gavirate-2021
Copy link

dirkx-gavirate-2021 commented Jul 14, 2021

Make use you specifyc the curve (https://github.com/ehn-dcc-development/ehn-sign-verify-python-trivial/blob/aac51a6df51cdc8d3a06f1e3ab099dc6c35e3f1c/gen-csca-dsc.sh#L9 -- the -name flag).

And make sure that the key is uncompressed. Check this with

openssl x509 -in dsc.key -noout -pubkey | openssl pkey -pubin -noout -text

and verify that the hex string starts with 04: and is followed by exactly 2x32 = 64 hex pairs.

The code from this line https://github.com/ehn-dcc-development/ehn-sign-verify-python-trivial/blob/aac51a6df51cdc8d3a06f1e3ab099dc6c35e3f1c/hc1_verify.py#L186 shows how to do this in Python

@teckow
Copy link

teckow commented Sep 1, 2021

HI

I need help
i'm getting this error

File "C:\Python39\lib\site-packages\cose\headers.py", line 173, in is_bstr
raise ValueError("KID should be a byte string")
ValueError: KID should be a byte string

i

@teckow
Copy link

teckow commented Sep 1, 2021

i fixed it :)
i haven't installed the correct library.

@nofaceinbook
Copy link
Owner

Great that you could directly fix it :-)

@michafroh
Copy link

I just want to ask here, whether someone find a solution to this comment:
#1 (comment)

@grynays
Copy link

grynays commented Oct 30, 2021

HI

I need help i'm getting this error

File "C:\Python39\lib\site-packages\cose\headers.py", line 173, in is_bstr raise ValueError("KID should be a byte string") ValueError: KID should be a byte string

i

Replace
keyid = '01234567'
Ti
keyid = bytes('01234567','utf-8')

@Newpython22
Copy link

Good morning, first of all, thank you for leaving this material and that we can learn everything, I have been trying it and it gives me a series of errors, I am new and I would like to continue learning. the errors are these:
line 90, in
msg = Sign1Message(phdr={Algorithm: Es256, KID: keyid}, payload=payload)

line 41, in init
super().init(phdr, uhdr, payload, external_aad, key, *args, **kwargs)

line 84, in init
super().init(phdr, uhdr, *args, **kwargs)

line 53, in init
CoseBase._transform_header_buckets(self._phdr, phdr, kwargs.get("allow_unknown_attributes", True))

line 166, in _transform_header_buckets
_value = hp.value_parser(_value)

line 173, in is_bstr
raise ValueError("KID should be a byte string")
ValueError: KID should be a byte string

Thank u, very much!!

@dirkx
Copy link

dirkx commented Jan 8, 2022 via email

@Newpython22
Copy link

I have already followed all the same code and it only gives me this error: line 125, in
qr_image = qrcode.make (out)
AttributeError: module 'qrcode' has no attribute 'make

@dirkx-gavirate-2021
Copy link

dirkx-gavirate-2021 commented Jan 8, 2022 via email

@Newpython22
Copy link

Sin título21
Using the same code from the beginning, with the required libraries, changing the "keyid" it generates the code in base45 that is not the same as what it should generate, regardless of whether or not it generates the qr

@grynays
Copy link

grynays commented Jan 9, 2022 via email

@nofaceinbook
Copy link
Owner

nofaceinbook commented Jan 9, 2022

@Newpython22 Did you install this qrcode package: https://pypi.org/project/qrcode/ ?

@Newpython22
Copy link

already solved!!
thank you

@ Newpython22 ¿ Instaló este paquete qrcode: https://pypi.org/project/qrcode/ ?

@Newpython22
Copy link

He modificado hc1_test_cert está escrito en tres versiones, funcionan bien, gp_cert1 para vacuna, gp_rec1 para hospitalizado, un gp_tamp1 para prueba antigénica, espero que puedan ser de utilidad. Il sab 8 gen 2022, 20:21 Newpython22 @.> ha scritto:
...
[image: Sin título21] https://user-images.githubusercontent.com/97358530/148656929-8d5e0021-4243-4f12-8ca7-eb2dee0eae0b.jpg Using the same code from the beginning, with the required libraries, changing the "keyid" it generates the code in base45 that is not the same as what it should generate, regardless of whether or not it generates the qr — Reply to this email directly, view it on GitHub <#1 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJL6ZSF4R6KNZV37EHKLBNDUVCFDDANCNFSM475HFPQA . You are receiving this because you commented.Message ID: @.
>

Where are those versions published?

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

No branches or pull requests

8 participants