{"action":"created","issue":{"url":"https://api.github.com/repos/OpenSC/OpenSC/issues/1269","repository_url":"https://api.github.com/repos/OpenSC/OpenSC","labels_url":"https://api.github.com/repos/OpenSC/OpenSC/issues/1269/labels{/name}","comments_url":"https://api.github.com/repos/OpenSC/OpenSC/issues/1269/comments","events_url":"https://api.github.com/repos/OpenSC/OpenSC/issues/1269/events","html_url":"https://github.com/OpenSC/OpenSC/issues/1269","id":298275585,"number":1269,"title":"PKCS#11 workflow with ALWAYS_AUTHENTICATE private keys","user":{"login":"Jakuje","id":2694489,"avatar_url":"https://avatars3.githubusercontent.com/u/2694489?v=4","gravatar_id":"","url":"https://api.github.com/users/Jakuje","html_url":"https://github.com/Jakuje","followers_url":"https://api.github.com/users/Jakuje/followers","following_url":"https://api.github.com/users/Jakuje/following{/other_user}","gists_url":"https://api.github.com/users/Jakuje/gists{/gist_id}","starred_url":"https://api.github.com/users/Jakuje/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jakuje/subscriptions","organizations_url":"https://api.github.com/users/Jakuje/orgs","repos_url":"https://api.github.com/users/Jakuje/repos","events_url":"https://api.github.com/users/Jakuje/events{/privacy}","received_events_url":"https://api.github.com/users/Jakuje/received_events","type":"User","site_admin":false},"labels":[{"id":140752579,"url":"https://api.github.com/repos/OpenSC/OpenSC/labels/Regression","name":"Regression","color":"f7c6c7","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2018-02-19T13:30:22Z","updated_at":"2018-04-13T13:50:20Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"### Problem Description\r\nThe \"correct\" workflow of PKCS#11 operations involving ALWAYS_AUTHENTICATE key is following:\r\n```\r\nC_Login()\r\nC_FindObjectsInit()\r\nC_FindObjects()\r\nC_FindObjectsFinal()\r\nC_GetAttributeValue(CKA_ALWAYS_AUTHENTICATE)\r\nC_SignInit()\r\nC_Login(CKU_CONTEXT_SPECIFIC)\r\nC_Sign()\r\n```\r\nThis means that for one-shot applications, user needs to write a PIN twice.\r\n\r\nThere is a chicken-egg problem with `ALWAYS_AUTHENTICATE` attribute of private keys:\r\n * One can not start the `C_SignInit` operation before the `C_Login` was performed, object handle obtained and the `CKA_ALWAYS_AUTHENTICATE` attribute detected.\r\n * One can not use `C_Login()` before `C_SignInit()`, because after #1256, the card is losing login state (using keepalive messages).\r\n\r\nIn OpenSC 0.17.0, also the workflow without the second login worked for legacy applications (for the first signature), but it is not true after merging the #1256:\r\n```\r\nC_Login()\r\nC_FindObjectsInit()\r\nC_FindObjects()\r\nC_FindObjectsFinal()\r\nC_SignInit()\r\nC_Sign()\r\n```\r\n\r\n\r\n### Proposed Resolution\r\nThere  is no good solution. There are several workarounds, such as PIN caching, ignoring this restriction (`pin_cache_ignore_user_consent = true`).\r\n\r\nMore complicated solutions might be introducing some timers (might interfere with the calling application). For more options, see the [dengert's comment](https://github.com/OpenSC/OpenSC/pull/1256#issuecomment-366073468). I am inclining to solution in this direction, unless it will be too complicated and fragile.\r\n\r\nWe should not obtain the card log in the `C_Login()` infinitely, because for example `ssh-agent` workflow does not immediately follow the `C_SignInit` operation.\r\n\r\n### Steps to reproduce\r\nSimplest use case is one-shot OpenSSH session with yubikey and the \"digital signature key\" used for ssh authentication:\r\n```\r\nssh-keygen -D /path/to/opensc-pkcs11.so >> ~/.ssh/authorized_keys ## select only the signature key!\r\nssh -I /path/to/opensc-pkcs11.so localhost\r\n```\r\n\r\n### Logs\r\nWorking with OpenSC 0.17.0 (from #1256): https://github.com/OpenSC/OpenSC/files/1736542/opensc-debug.log"},"comment":{"url":"https://api.github.com/repos/OpenSC/OpenSC/issues/comments/381141537","html_url":"https://github.com/OpenSC/OpenSC/issues/1269#issuecomment-381141537","issue_url":"https://api.github.com/repos/OpenSC/OpenSC/issues/1269","id":381141537,"user":{"login":"dengert","id":865329,"avatar_url":"https://avatars2.githubusercontent.com/u/865329?v=4","gravatar_id":"","url":"https://api.github.com/users/dengert","html_url":"https://github.com/dengert","followers_url":"https://api.github.com/users/dengert/followers","following_url":"https://api.github.com/users/dengert/following{/other_user}","gists_url":"https://api.github.com/users/dengert/gists{/gist_id}","starred_url":"https://api.github.com/users/dengert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dengert/subscriptions","organizations_url":"https://api.github.com/users/dengert/orgs","repos_url":"https://api.github.com/users/dengert/repos","events_url":"https://api.github.com/users/dengert/events{/privacy}","received_events_url":"https://api.github.com/users/dengert/received_events","type":"User","site_admin":false},"created_at":"2018-04-13T13:50:20Z","updated_at":"2018-04-13T13:50:20Z","author_association":"MEMBER","body":"I believe the primary application we are addressing here is OpenSSH and agent? And then only if it is trying to use a key that has ALWAYS_AUTHENTICATE and enforced by the card.\r\n\r\nI would suggest that we do nothing in the code, but recommend, based on the card and policies of the card issuer that this key should not be used in this manor. \r\n\r\nSome cards may have a workaround. Use other keys on the card, or turn off the card's enforcing of the ALWAYS_AUTHENTICATE. \r\nFor example: PIV specs define 20 extra retired encryption keys and certificates The History object defines how many there are, and if the certificates are on or off the card.  There is code in card-piv.c to allow these to be used for any use based on the keyUsage in the certificate, but only if this is not a US gov issued card. This requires a CHUID with the FASC-N with the agency code of 9999 which indicates it is not a US gov issued card.\r\n\r\nThe Yubico piv-tool can create such a CHUID (really needs to be checked, I have not looked closely at it.)\r\nI don't see a create a History Object command with their tool yet. The history object can be create using piv-tool -s \"DER of the history object\" Their tool can import or generate keys on their devices.  \r\n\r\nCan someone who uses a Yubikey clarify if then can set or turn off the card enforcement of ALWAYS_AUTHENTICATE? We could then change pkcs15-piv.c  to test this before doing \r\n`prkey_obj.user_consent = prkeys[i].user_consent;` for the sign key. \r\n\r\nYubico should be involved in this, and add the needed commands and documentyation to their yubico-piv tool. \r\n\r\n**In other words** may it easier for a user to not  misuse a ALWAYS_AUTHENTICATE key.  \r\n\r\n\r\n\r\n\r\n\r\n"}}
{"actor":{"display_login":"dengert"}}