sshd: Suppress host key loading error when using a PKCS#11 based HostKey#664
Open
ifranzki wants to merge 1 commit into
Open
sshd: Suppress host key loading error when using a PKCS#11 based HostKey#664ifranzki wants to merge 1 commit into
ifranzki wants to merge 1 commit into
Conversation
When using a PKCS#11 based HostKey then the private key is loaded via the SSH agent using the HostKeyAgent setting. In this case the HostKey setting specifies a public key, not a private key. Thus, attempting to load the private host key via sshkey_load_private() will fail, but loading the public key via sshkey_load_public() below will succeed, and the private key handling is relied on the agent. Suppress the confusing error message when attempting to load the private host key when an agent is used.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is an attempt to fix the problem reported in https://bugzilla.mindrot.org/show_bug.cgi?id=3964
Problem details (copied from bugzilla);
I am using a PKCS11 based hostkey for SSHD.
I am starting an ssh-agent on the host, then add the PKCS#11 provider and its key via 'ssh-add -s /path/to/pkcs11-provider' (one EC P-256 key gets added). Then I create the public SSH key from it using 'ssh-keygen -D /path/to/pkcs11-provider > /path/to/ssh_host_pkcs11_key.pub'.
Then I edit the SSHD config file as follows:
HostKey /path/to/ssh_host_pkcs11_key.pub
HostKeyAgent SSH_AUTH_SOCK
So the key specified with HostKey is a public key, and not a private key.
Environment variable SSH_AUTH_SOCK is set to the agent socket address.
When staring sshd, I get 'Unable to load host key "/path/to/ssh_host_pkcs11_key.pub": error in libcrypto'. However, processing continues and sshd is finally up fine.
Turning on debug (-d option) shows that it recognizes the agent key later on:
debug1: will rely on agent for hostkey /path/to/ssh_host_pkcs11_key.pub
debug1: agent host key #0: ecdsa-sha2-nistp256 SHA256:
So its not a functional problem, but the error message 'Unable to load host key "/path/to/ssh_host_pkcs11_key.pub": error in libcrypto' is confusing.
The doc at https://man.openbsd.org/sshd_config#HostKey states "It is also possible to specify public host key files instead. In this case operations on the private key will be delegated to an ssh-agent(1).". So it seems legit to specify a public key here when an agent based host key is used.
Fix:
Suppress the confusing error message when attempting to load the private host key when an agent is used.