Skip to content

Commit f8405e2

Browse files
yosuke-wolfsslejohnstown
authored andcommitted
tpm-ssh.yml, README: test and document TPM keys with OpenSSH certs
- tpm-ssh.yml builds wolfSSH with --enable-ossh-certs, and the RSA raw cells log in with the TPM key offered as an OpenSSH user certificate, and fail with a certificate for another key. - README: a TPM PUBLIC KEY AUTHENTICATION subsection on offering the TPM key as an OpenSSH user certificate.
1 parent 30182b9 commit f8405e2

2 files changed

Lines changed: 89 additions & 1 deletion

File tree

‎.github/workflows/tpm-ssh.yml‎

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ jobs:
112112
run: |
113113
cd wolfssh
114114
./autogen.sh
115-
./configure --enable-tpm --enable-certs
115+
./configure --enable-tpm --enable-certs --enable-ossh-certs
116116
make
117117
sudo make install
118118
sudo ldconfig
@@ -230,6 +230,60 @@ jobs:
230230
timeout 20 ./examples/client/client -i ../wolftpm/keyblob.bin \
231231
-u hansel -K ThisIsMyKeyAuth
232232
233+
# The same TPM key offered as an OpenSSH user certificate. The certificate
234+
# is a file carrying the TPM key's public half; the TPM still signs.
235+
- name: Test TPM client OpenSSH certificate auth
236+
if: matrix.keytype == 'rsa' && matrix.hostkey == 'raw'
237+
run: |
238+
cd wolfssh
239+
ssh-keygen -q -t rsa -N '' -f ossh_ca < /dev/null
240+
cp key.ssh tpmkey.pub
241+
ssh-keygen -q -s ossh_ca -I tpm-cert -n hansel tpmkey.pub
242+
timeout 30 ./examples/echoserver/echoserver -1 -p 22225 -s key.ssh \
243+
> ossh_cert_server.txt 2>&1 &
244+
SERVER_PID=$!
245+
echo "Echoserver (TPM key behind an OpenSSH certificate) PID: $SERVER_PID"
246+
sleep 2
247+
timeout 20 ./examples/client/client -i ../wolftpm/keyblob.bin \
248+
-u hansel -K ThisIsMyKeyAuth -j tpmkey-cert.pub -p 22225 -x \
249+
< /dev/null > ossh_cert_client.txt 2>&1 || {
250+
cat ossh_cert_client.txt
251+
exit 1
252+
}
253+
# The one-shot server flushes its output when it exits.
254+
wait $SERVER_PID || true
255+
echo "----- server -----"; cat ossh_cert_server.txt
256+
grep -q "auth = Success" ossh_cert_server.txt
257+
258+
# Negative test: a certificate for another key. The echoserver accepts
259+
# that key, so only the signature check can refuse the TPM's signature.
260+
- name: Test TPM client OpenSSH certificate for another key fails
261+
if: matrix.keytype == 'rsa' && matrix.hostkey == 'raw'
262+
run: |
263+
cd wolfssh
264+
# Same size as the TPM key, or the client fails before signing. The
265+
# comment is cut because the echoserver appends the user name.
266+
ssh-keygen -q -t rsa -b 2048 -N '' -f other < /dev/null
267+
ssh-keygen -q -s ossh_ca -I other-cert -n hansel other.pub
268+
cut -d' ' -f1,2 other.pub > other.ssh
269+
timeout 30 ./examples/echoserver/echoserver -1 -p 22226 -s other.ssh \
270+
> ossh_cert_server_neg.txt 2>&1 &
271+
SERVER_PID=$!
272+
echo "Echoserver (another key's certificate) PID: $SERVER_PID"
273+
sleep 2
274+
if timeout 20 ./examples/client/client -i ../wolftpm/keyblob.bin \
275+
-u hansel -K ThisIsMyKeyAuth -j other-cert.pub -p 22226 -x \
276+
< /dev/null > ossh_cert_client_neg.txt 2>&1; then
277+
echo "ERROR: a certificate for another key authenticated"
278+
cat ossh_cert_client_neg.txt
279+
exit 1
280+
fi
281+
wait $SERVER_PID || true
282+
echo "----- server -----"; cat ossh_cert_server_neg.txt
283+
echo "----- client -----"; cat ossh_cert_client_neg.txt
284+
# The server took the key and then refused the signature.
285+
grep -q "auth = Failure" ossh_cert_server_neg.txt
286+
233287
- name: Archive test artifacts
234288
if: always()
235289
uses: actions/upload-artifact@v7
@@ -243,4 +297,8 @@ jobs:
243297
wolfssh/tpmcert_client.txt
244298
wolfssh/tpmcert_server_neg.txt
245299
wolfssh/tpmcert_client_neg.txt
300+
wolfssh/ossh_cert_server.txt
301+
wolfssh/ossh_cert_client.txt
302+
wolfssh/ossh_cert_server_neg.txt
303+
wolfssh/ossh_cert_client_neg.txt
246304
wolfssh/tests/api.log

‎README.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,36 @@ If you used a custom password for keygen you must specify the password you used:
672672

673673
$ ./examples/client/client -i ../wolfTPM/keyblob.bin -u hansel -K <custompassword>
674674

675+
with an OpenSSH user certificate
676+
--------------------------------
677+
678+
The TPM key can also be offered as an OpenSSH user certificate
679+
(`ssh-rsa-cert-v01@openssh.com`). The certificate is a file carrying the TPM
680+
key's public half; the private key stays in the TPM, which makes the
681+
signature. Build wolfSSH with OpenSSH certificate support as well:
682+
683+
wolfSSH
684+
$ ./configure --enable-tpm --enable-ossh-certs
685+
686+
Create the key and `key.ssh` as above, then have your CA sign the public key.
687+
`ssh-keygen` names the certificate after its input, so this writes
688+
`tpmkey-cert.pub`:
689+
690+
$ cp key.ssh tpmkey.pub
691+
$ ssh-keygen -s <CA private key> -I <key id> -n hansel tpmkey.pub
692+
693+
Run the echoserver with `key.ssh` as above, and pass the certificate to the
694+
client with `-j`:
695+
696+
$ ./examples/client/client -i ../wolfTPM/keyblob.bin -u hansel \
697+
-K ThisIsMyKeyAuth -j tpmkey-cert.pub
698+
699+
Notes:
700+
701+
- RSA keys only, as for the plain TPM key.
702+
- The certificate must be issued for the key in the TPM, or the server
703+
rejects the signature.
704+
675705
TPM SERVER HOST KEY (ECDSA / RSA)
676706
=================================
677707

0 commit comments

Comments
 (0)