Key usage of ECC keys on PKCS#15 smartcards doesn't allow decryption?

Mario Haustein via Gnupg-devel <[email protected]>
Newsgroups gmane.comp.encryption.gpg.devel
Organization TU Chemnitz
Message-ID <2378092.NG923GbCHz@localdomain>
Dear developers,

while implementing the D-Trust ECC smartcards I encountered an issue I 
couldn't make sense of and would like to request assistance from you. I also 
couldn't find an issue in the bug tracker looking similar to it.

My test cards provides two certificates: one for qualified signatures and one 
for (non-qualified) signatures and decryption. While the signature creation 
works out of the box for both keys, I am unable to decrypt an encrypted 
message with the latter key.

This is the secret key:

           ID: 0x2F5CD959
          S/N: 71440EE33409F4256085AFE32C15B5A6
        (dec): 150556141664708457568253825304782812582
       Issuer: /CN=D-TRUST Limited Basic Test CA 1-4 2020/O=D-Trust GmbH/C=DE
      Subject: /CN=XXX/C=DE/SerialNumber=DTR230045177P0004/SN=XXX/GN=XXX
          aka: [email protected]
     validity: 2024-01-10 22:03:55 through 2026-01-20 22:03:55
     key type: nistp256
    key usage: digitalSignature keyAgreement
ext key usage: emailProtection (suggested), clientAuth (suggested)
     policies: 1.3.6.1.4.1.4788.2.2.2:N:
  fingerprint: DF:30:3A:2E:C7:6E:60:FD:77:41:BA:03:86:F6:46:18:2F:5C:D9:59
     sha2 fpr: 53:F5:22:23:CD:AD:52:7F:8A:B6:81:FD:C3:9D:04:0A:
7D:B8:48:7C:DF:B1:4D:84:84:D2:AA:C9:BE:19:BC:94
     card s/n: 9276003211760004942F

It supports the usage flags `sign` and `derive` reported as `digitalSignature` 
and `keyAgreement` in the frontend.

I could narrow down the issue to `do_decipher()` in scd/app-p15.c. The 
function bails out at the following check.

```
  if (!(prkdf->usageflags.decrypt
        || prkdf->usageflags.unwrap
        || prkdf->gpgusage.encr     ))
    {
      log_error ("p15: key %s may not be used for decryption\n", keyidstr);
      return gpg_error (GPG_ERR_WRONG_KEY_USAGE);
    }
```

AFAIK decryption with ECDH keys is done by negotiating a common secret between 
Alice and Bob from which the symmetric encryption key is derived. So the 
`derive` key usage flag makes sense as the key is not capable of decrypting 
directly.

When skipping this check, the smartcard works fine for decryption, too.

Is it likely that the `derive` check was just forgotten at this place? I 
cannot judge the consequences of this change, which is the reason for asking 
here in advance.

Many thanks in advance for reviewing my thoughts.

Kind regards
-- 
Mario Haustein
Facharbeitsgruppe Anwendungen
Universitätsrechenzentrum

Technische Universität Chemnitz
Straße der Nationen 62 | R. 1/B303 (neu: A11.303)
09111 Chemnitz
Germany

Tel:    +49 371 531-36606
Fax:    +49 371 531-836606

[email protected]
www.tu-chemnitz.de

_______________________________________________
Gnupg-devel mailing list
[email protected]
https://lists.gnupg.org/mailman/listinfo/gnupg-devel
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEE0dWxQ/gtEp4RcqrdrrMm8sIKEfoFAmXPbWEACgkQrrMm8sIK
EfpMFw//b+tWD9wUDEnh2bkZvaGu74SPid89NsSaBQUPM+Rf8XTOlXP20oLnDkmK
9h68LV0hAW97mExI++uMQDcsu0dz9tb51Uu5o+CGT0ra2EdlL0dQAT4jRNN6sZ9f
oNTMeje/dkpQAp7Uo59rqjMWd91ePLbBVVdvhIqtd25wg9N0lAUOf2drAbhIV17l
JeLlRUDcq79jZ2+y7CJRcKsk8JSAQLjcYza5refFKq54PiR0czA0hAfDfEgQvGGO
YXTW3AYfsabx1klHFIak0WE5IB9RI5GLBHQOIx2bGqct77UymNNXox1y0vlPiWR6
zF7fC8vTMLQj2S55Oap+adzjR2+oF+1dz7vgEPkua2OWpBRkxAztE+zygnTWTa+6
uJM8mQOzhYqH7pQeNu6zLVSYH+92G0dUozVgqZPpkIGfv2ssPCIhBs1aNCH1pBiw
LnNOfaf0Bwxjd485Fd1DIhamlg/SneoWb+9i3oTsd3l6YC62YHvNLnW4nDfqIZFo
yiukzBj+Ue7RSVkgpKdsNjfYh+eESpHoL8D2VVUUk5T57Lmcr5yzkUgSE9oJTpYT
+cauUQ/hqPacIcq5ZTymuncx8Nt6R9TX0pa+hc6iGRTaTxnWlv5QThC6w50iZu2v
P/pwnrK3gsJWqqDXmBcPVOBDzP0/5VcUv2lnDAI8c12oIv4Nzbo=
=BaZ9
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.