Skip to content

sshd: Suppress host key loading error when using a PKCS#11 based HostKey#664

Open
ifranzki wants to merge 1 commit into
openssh:masterfrom
ifranzki:fix-host-agent-key-load
Open

sshd: Suppress host key loading error when using a PKCS#11 based HostKey#664
ifranzki wants to merge 1 commit into
openssh:masterfrom
ifranzki:fix-host-agent-key-load

Conversation

@ifranzki
Copy link
Copy Markdown

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant