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

can this tool support certificate generation for the card/ePassport? #6

Open
rathorearvind19 opened this issue Jul 12, 2023 · 1 comment

Comments

@rathorearvind19
Copy link

See subject line.
Seems like the certificates that are generated are meant to be used in the terminal authentication protocol to authenticate the inspection system accessing data from a card. What changes will be required to generate certificates for the card itself which are verified by the inspection system to authenticate the card?

@polhenarejos
Copy link
Owner

Sure. pycvc can be used to generate CVC.

If you need to reformat your certificates from a cryptographic card, you must first to convert to .PEM format and then convert it to CVC. However, note that certificate must be signed by a private key, probably located inside your card. If your card allows signatures, you must pass the SHA256 hash of your certificate body to your card and obtain the signature. Finally, you have to embed your CV body and the signature into the CVC container.

To generate a certificate:

ASN1().add_tag(0x7f21, self.body(pubkey, scheme, car, chr, role, days, since, extensions, req or chr==car).sign(signkey, signscheme).encode()).encode()

Instead of doing this in a single step, split it in two:

scheme = oid.ID_TA_ECDSA_SHA_256 
# pubkey is an instance of [EllipticCurvePublicKey](https://cryptography.io/en/latest/hazmat/primitives/asymmetric/ec/#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey)
body = CVC().body(pubkey, scheme, car, chr, role, days, since, extensions, req or chr==car).encode()
hash = sha256(body).digest()
signature = call_your_card(hash, ECDSA_SHA_256) # Adapt it to your card protocol
cert = ASN1().add_tag(0x7f21, body + ASN1().add_tag(0x5f37, signature).encode()).encode()

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

2 participants