Bug 1690552

Summary: ssh-agent stops working with certificate in alternate yubikey slot
Product: Red Hat Enterprise Linux 7 Reporter: Orion Poplawski <orion>
Component: openscAssignee: Jakub Jelen <jjelen>
Status: CLOSED NEXTRELEASE QA Contact: Asha Akkiangady <aakkiang>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 7.6   
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-04-04 14:08:27 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Orion Poplawski 2019-03-19 16:37:59 UTC
Description of problem:

I'm trying to make use of a YubiKey configured as follows:

 * Certificate for PIV Authentication - slot 9a: USER certificate
 * Certificate for Key Management - slot 9d: MacOS encryption certificate
 * Retired Certificate for Key Management 1 - slot 82: USER-admin certificate

This is because the of the apparent requirement for an encryption certificate to use the yubikey on a Mac: https://support.yubico.com/support/solutions/articles/15000010854-macos-native-smart-card-support-for-logon-with-windows-server and the need for a separate -admin certificate.

The Windows minidriver puts the admin certificate into slot 82 will look at the retired certificate slots automatically, so that works out of the box. For Linux though, we need to tell OpenSC that the extra slots are available. The magic incantation to do this is:

echo C10114C20100FE00 | xxd -r -p |  ykman piv write-object 0x5FC10C -

See https://github.com/OpenSC/OpenSC/issues/847#issuecomment-238119888 for more information about that.

This allows me to login/su using the certificates and pin.  However, using the ssh agent with my orion-admin certificate in slot 82 is flaky.  It works fine until some other authentication operation is done with the card (su - orion-admin for example): 

sign_and_send_pubkey: signing failed: agent refused operation

ssh-pkcs11-helper[28856]: error: C_Sign failed: 257
ssh-agent[28815]: error: process_sign_request2: sshkey_sign: error in libcrypto

or 

ssh-pkcs11-helper[28856]: error: cannot find private key
ssh-agent[28815]: error: process_sign_request2: sshkey_sign: error in libcrypto

I enabled opensc debugging - and I see entries when I successfully add the card to the agent, but I don't see any further activity when I ssh to other machines.

I do not have this problem with a different yubikey with my orion-admin certificate in the Key Management slot 9d.

Version-Release number of selected component (if applicable):
openssh-7.4p1-16.el7.x86_64

Comment 2 Jakub Jelen 2019-03-19 17:15:59 UTC
The current RHEL7.6 OpenSC does not have any mechanisms to detect and resolve concurrent access to the PIV card from different applications. Actually even existence of the "magic object" (0x5FC10C) and some operation might break the login state so I really think this should be filled against opensc.

To follow up from here, we actually know about this issue and it should be already resolved in the current opensc. Can you check that current master will work for you? If not, I will need some more debugging information from OpenSC.

Comment 3 Orion Poplawski 2019-03-19 17:43:11 UTC
From a quick test it appears that current OpenSC master does work.  Thanks!

Comment 4 Jakub Jelen 2019-04-04 14:08:27 UTC
This will most probably be fixed in the next release of OpenSC in RHEL7. Please, reopen if the problems persist.