Replies: 15 comments 10 replies
-
Get debug log
…On Thu, Apr 18, 2024, 11:11 AM msetina ***@***.***> wrote:
After creating a key pair on the card I try to get public key information,
but it is invalid. In case of 2048 bit RSA key I get 271 bytes instead of
270 bytes that properly decodes to public key information. (this also
applys to EC key)
Getting this key data little latter, the public key information is valid.
—
Reply to this email directly, view it on GitHub
<#3124>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGTIMMHLJ6HYXVCF3SPQFLY57WE7AVCNFSM6AAAAABGNSZA6WVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZWGUZDIOJSGU>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
In my case when it goes wrong I see:
After this my code raises exception that the EC POINT is not correctly formated.
This example is for EC key (384 bits).Both should be on the same key. |
Beta Was this translation helpful? Give feedback.
-
I am not sure what you mean by: "OK. I've prepared for #3000, but am not sure if result from ASN.1" The trace does not show enough to see what was read from card. Did you take the code from #3000 which may not be complete?
Both strings start with 04 which is ASN1 for OCTET STRING and breaks down as: Tag 04 Octet String X=E7D7A61073CE87722A6872FD0FA0B too short If you don't have a copy of: "A Layman`s Guide to a Subset of ASN.1, BER and DER" find on internet. |
Beta Was this translation helpful? Give feedback.
-
Here is another must have tool for asn1 debugging https://lapo.it/asn1js/ |
Beta Was this translation helpful? Give feedback.
-
Length of key in bits
…On Thu, Apr 18, 2024, 4:11 PM msetina ***@***.***> wrote:
I cut out as much as I was bothered by this:
P:5584; T:0x140319610138624 20:04:39.327 [opensc-pkcs11] asn1.c:1826:asn1_encode_entry: encoding 'ecpointQ'
P:5584; T:0x140319610138624 20:04:39.327 [opensc-pkcs11] asn1.c:1831:asn1_encode_entry: type=4, tag=0x04, parm=0x55f220130410, len=384
P:5584; T:0x140319610138624 20:04:39.327 [opensc-pkcs11] asn1.c:2024:asn1_encode_entry: length of encoded item=388
why would len be 384?
—
Reply to this email directly, view it on GitHub
<#3124 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGTIMMUGY4JLCGSXGVSALLY6AZI3AVCNFSM6AAAAABGNSZA6WVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TCNJZGY4DQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
In https://github.com/OpenSC/OpenSC/files/15030306/opensc-debug_ec.txt Duing a session to create a key
If you strip off the TLV and APDU status of 90 00 you get 0x61 bytes:
This is the 04||X||Y for the curve 'secp384r1' (lines 2030-2032) (384/2=48= 0x30 the length in bytes for X and for Y In opensc-debug_ec_bad.txt when not creating a key but running some other command? lines 2418 and following it read:
The same '04||X||Y' as before.
6A 88 is Referenced data or reference data not found (exact meaning depending on the command) What commands and arguments did you use for these two runs? The ATR of your card is: 3b:da:18:ff:81:b1:fe:75:1f:03:00:31:f5:73:c0:01:60:00:90:00:1c https://smartcard-atr.apdu.fr/ says "OpenPGP Card V3" Most testing of OpenPGP cards are Yubikey or Nitro. So applets may vary. Also note PKCS11 only supports one user PIN for a slot. OpenPGP has two user keys , and PKCS11 so OpenSC uses 2 slots. |
Beta Was this translation helpful? Give feedback.
-
The https://github.com/OpenSC/OpenSC/files/15030306/opensc-debug_ec.txt is a run whe the key is not created but just read by CKA_ID.
The value that cryptoraphy is capable of reading into pubic key is one byte shorter:
Which is strange as by online DER parser they should be the same, just the last one has a shorter exponent field. THe one it does not want to read has I got the card here:
They prepared the card and it still has the original user and SO pin. |
Beta Was this translation helpful? Give feedback.
-
With a little intuitive revolation I made it work in multiple processes where it generates key in one process and creates certificate with public key retrieval in another. This execution does not retrieve public key data in the problematic way I saw before. |
Beta Was this translation helpful? Give feedback.
-
Good to hear you have a circumvention. What would be helpful if you were to post the data read from the card in both cases. It might be the card knows it is an RSA modules followed by a length byte and exponent. And card handles adding/removing leading zero bytes, but when read from the card it always truncates or pads to 4 bytes. This could also happen in software if exponent was stored in OpenSSL BIGNUM and the BIGNUM is stored without leading zeros. "BN_num_bytes() returns the size of a BIGNUM in bytes." |
Beta Was this translation helpful? Give feedback.
-
Also sounds a lot like #1959 |
Beta Was this translation helpful? Give feedback.
-
What is your ultimate goals for your project? OpenSC supports many smartcards in a user only mode, for example government issued ID cards. But OpenSC does not support in many cases, initialization and provisioning of cards by users. OpenSC has some special tools for some of these cards. You are using an OpenPGP ZeitControl card for your testing. OpenSC support to erase the card is available via pkcs15-init, but via not PKCS11. And OpenSC cards have a number of fields that can read by PKCS11 but not written even by pkcs15-init. Many supported cards are based on PKCS15, and other like OpenPGP are not. So far all the issues you have found are related to OpenPGP with ZeitControl and PKCS11 using a card with a version of OpenPGP that I am not familiar with. Other developers or users may have these cards. I have been working on another issue #2952 and PR #3090 as OpenPGP was any early adopter of 25519 curves. The PR is big and needs testing before making even more changes to OpenSC to support what you are requesting via PKCS11. If you want to get involved with OpenSC please have a look at #3090. |
Beta Was this translation helpful? Give feedback.
-
What would be helpful is to use OpenSC-SPY to show the PKCS11 calls and responses. I see C_FindObjectsInit(): CKA_CLASS = CKO_PUBLIC_KEY and request to get CKA_VALUE BUT... https://github.com/OpenSC/OpenSC/blob/master/src/pkcs11/framework-pkcs15.c#L5030-L5038 #3090 adds CKA_PUBLIC_KEY_INFO: which is define in PKCS11 3.0 which is the same as the OPENSC define CKA_SPKI If you look at key type, there are other ways to get a CKA_EC_POINT, CKA_MODULUS, etc for different type keys if you need them. https://github.com/OpenSC/OpenSC/files/15040309/opensc-debug_rsa.txt line 3656: T:0x139929353580544 22:09:12.431 [opensc-pkcs11] pkcs11-object.c:270:C_GetAttributeValue: Object 94276059045568: CKA_VALUE = 3082010B02820101008376C31AA92A7175C01A753D73B7975E8F4613B7CB9FEF This is the SPKI of the public key, from lines starting at 3277 and from lines starting at 2955 The term "public key" is over loaded and has different means in different contexts. In PKCS11 3.0: CKO_PUBLIC_KEY has: CKA_PUBLIC_KEY_INFO The card appears to be working as expected. |
Beta Was this translation helpful? Give feedback.
-
Looks like some caching issue and/or compounded by bits vs bytes. in This is not on my priority list, but will keep an eye on it. |
Beta Was this translation helpful? Give feedback.
-
By not using CKA_VALUE the problem with RSA key is out of scope. If you want I can prepare the same for CKA_VALUE or will it be set to null in the future? |
Beta Was this translation helpful? Give feedback.
-
After creating a key pair on the card I try to get public key information, but it is invalid. In case of 2048 bit RSA key I get 271 bytes instead of 270 bytes that properly decodes to public key information. (this also applys to EC key)
Getting this key data little latter, the public key information is valid.
Beta Was this translation helpful? Give feedback.
All reactions