curl TLS session using tpm encoded keyfile.
ray at 3econtrols.com
Does anyone know how to use a tpm keyfile generated with:
tpm2tss-genkey -a rsa -s 2048 /home/pi/certs/client.key
I have a program that uses curl and openSSL to log into a website using a cert file signed by the tpm client key. In my program, I can load and use the key with the tpm2 library to encode/decode messages. However, I am having trouble getting a TLS session going using libcurl.
My curl --engine list output is:
Build-time engines:
dynamic
tpm2tss
The basic code I am using to generate the curl session is:
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_USERNAME, username);
curl_easy_setopt(curl, CURLOPT_PASSWORD, password);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, CONNECTION_TIMEOUT);
curl_easy_setopt(curl, CURLOPT_SSLENGINE, "tpm2tss");
curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT, 1L);
curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, "ENG");When initiating the session (with curl tracing & my program tracing turned on) I get the following messages:
[2020-04-01 18:50:19] - [VERBOSE] - httpclient-http_post_json--Setting cURL to use TPM as SSL Engine tpm2tss
[LIBCURL4] --- Setting CURLOPT_SSLENGINE to : tpm2tss [LIBCURL4] --- Curl_setstropt result : 0 [LIBCURL] ---- Curl_ssl_set_engine is call. [LIBCURL4] --- Curl_ssl_set_engine result : 0
[2020-04-01 18:50:19] - [VERBOSE] - httpclient-http_post_json--Setting cURL to use TPM as the default SSL Engine tpm2tss [2020-04-01 18:50:19] - [VERBOSE] - httpclient-http_post_json--Setting cURL to have keytype as engine
[2020-04-01 18:50:19] - [TRACE] - httpclient-http_post_json-Setting trustStore to /home/pi/certs/trust.store [2020-04-01 18:50:19] - [TRACE] - httpclient-http_post_json-Setting clientCert to /home/pi/certs/client.crt [2020-04-01 18:50:19] - [TRACE] - httpclient-http_post_json-Setting clientKey to /home/pi/certs/client.key
* STATE: INIT => CONNECT handle 0x4cabb8; line 1623 (connection #-5000)
* Added connection 0. The cache now contains 1 members
* STATE: CONNECT => WAITRESOLVE handle 0x4cabb8; line 1664 (connection #0)
* family0 == v4, family1 == v6
* Trying 52.167.122.10:443...
* STATE: WAITRESOLVE => WAITCONNECT handle 0x4cabb8; line 1743 (connection #0)
* Connected to product.thedemodrive.com (52.167.122.10) port 443 (#0)
* STATE: WAITCONNECT => SENDPROTOCONNECT handle 0x4cabb8; line 1799 (connection #0)
* Marked for [keep alive]: HTTP default WARNING:esys:src/tss2-esys/esys_tcti_default.c:134:tcti_from_file() Could not load TCTI file: libtss2-tcti-default.so WARNING:esys:src/tss2-esys/esys_tcti_default.c:134:tcti_from_file() Could not load TCTI file: libtss2-tcti-default.so WARNING:esys:src/tss2-esys/esys_tcti_default.c:134:tcti_from_file() Could not load TCTI file: libtss2-tcti-default.so WARNING:esys:src/tss2-esys/esys_tcti_default.c:134:tcti_from_file() Could not load TCTI file: libtss2-tcti-default.so
* ALPN, offering http/1.1
* ssl engine didn't initialized the certificate properly.
* Marked for [closure]: Failed HTTPS connection
* multi_done
* Closing connection 0
* The cache now contains 0 members
* Expire cleared (transfer 0x4cabb8)
[2020-04-01 18:50:19] - [TRACE] - httpclient-http_post_json--libcurl: (58)
[2020-04-01 18:50:19] - [TRACE] - httpclient-http_post_json--ssl engine didn't initialized the certificate properly.
[2020-04-01 18:50:19] - [ERROR] - httpclient-http_post_json-http-WriteMemoryCallback-Problem with the local SSL certificate
[2020-04-01 18:50:19] - [VERBOSE] - session-register_session-Session Response:
[2020-04-01 18:50:19] - [VERBOSE] - (null)
[2020-04-01 18:50:19] - [ERROR] - session-register_session-Session registration failed with error code 58
Can anyone assist me?
Has anyone programmed curl with a TSS engine?
Cheers --
Ray
ray at 3econtrols.com
Also, here is the openssl read for my SSL cert:
pi(a)raspberrypi:~/tssSetup/tpm2-tss $ openssl x509 -in /home/pi/certs/client.crt -noout -text Certificate:
Data:
Version: 3 (0x2)
Serial Number:
36:4c:2c:a2:56:04:c2:54:4c:b9:c1:af:7c:ec:ed:c2:cf:7e:3a:8e
Signature Algorithm: sha256WithRSAEncryption
Issuer: C = AU, ST = Some-State, O = Internet Widgits Pty Ltd
Validity
Not Before: Mar 31 16:12:49 2020 GMT
Not After : Apr 30 16:12:49 2020 GMT
Subject: C = AU, ST = Some-State, O = Internet Widgits Pty Ltd
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public-Key: (2048 bit)
Modulus:
00:dc:0b:6f:0f:6b:4e:f7:62:5d:50:63:3d:ab:1f:
cc:43:24:18:89:42:dc:7e:17:71:9f:d4:ef:2b:5a:
39:53:16:9e:3b:b0:f7:e1:49:37:7a:c3:36:ba:9e:
e2:32:09:71:68:0e:46:91:15:f0:cf:d7:09:4e:3f:
7d:14:92:06:13:f5:ec:ea:5a:e1:b0:58:ca:32:b1:
0c:0b:b9:75:f9:c1:5a:e5:c6:71:5f:92:53:3d:c2:
32:b8:3c:ea:02:3b:9b:7a:bb:83:6f:c8:57:e6:4a:
13:b6:e2:2e:08:43:4f:93:83:6c:4f:b6:49:85:57:
d4:7d:7d:49:1e:8e:27:c4:04:80:3e:74:14:2e:76:
6d:fc:87:14:f9:1b:4e:3b:05:ba:ca:b9:6e:90:a1:
a3:c5:e2:4e:5a:90:a8:ca:28:27:54:7e:1c:8f:a9:
3a:ee:8f:fa:14:a9:2c:f4:b4:5a:29:37:b8:69:5c:
32:1c:e0:f6:b6:36:41:54:c8:8e:e2:3f:52:d2:c1:
08:85:87:77:ba:33:9a:51:1e:89:1f:f5:fa:7d:12:
1a:3f:67:b3:82:6a:aa:fa:ca:8f:8c:08:ab:60:db:
40:ae:96:db:4c:ae:78:64:82:fe:de:aa:3b:1e:b3:
08:ac:f2:df:ea:8b:eb:62:6e:20:0a:04:7b:3c:80:
4e:e9
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Subject Key Identifier:
C8:9C:72:1A:96:21:99:EC:CB:67:FE:D4:1C:03:7D:0C:60:EE:1C:A2
X509v3 Authority Key Identifier:
keyid:C8:9C:72:1A:96:21:99:EC:CB:67:FE:D4:1C:03:7D:0C:60:EE:1C:A2
X509v3 Basic Constraints: critical
CA:TRUE
Signature Algorithm: sha256WithRSAEncryption
0b:29:d6:16:92:00:98:1c:53:16:d0:aa:29:72:ac:75:04:99:
90:c0:1e:4e:f5:98:2d:7e:f9:7a:47:b4:18:d4:73:98:8b:43:
ef:7f:9f:5f:4d:db:e6:f8:45:cc:c0:50:d8:83:b3:0d:83:f7:
6d:cc:c1:ec:5b:a9:9e:3f:d9:a6:51:e3:f9:81:cb:6e:63:60:
c3:bd:45:45:e9:46:91:13:d0:40:00:95:1b:e7:3e:02:dc:b0:
be:9a:73:30:c9:9c:26:86:b0:e7:bf:54:82:db:d3:a1:11:03:
97:f0:1f:98:20:10:51:01:77:78:6b:d1:2c:6d:8d:b7:9a:10:
38:36:6f:52:8a:19:c0:ce:23:43:8f:d6:1b:0c:e9:d0:d2:9c:
58:7a:13:73:ef:92:65:6c:9a:fb:6a:49:bf:48:4b:0f:a2:aa:
01:9e:e5:2e:4e:68:60:6d:74:73:5a:cf:6e:b7:90:83:ba:d8:
e9:b7:40:f5:f2:b1:a2:5a:60:05:70:31:99:9b:d2:a5:a7:f9:
84:71:15:73:04:f9:44:02:89:60:4e:3e:db:d6:55:47:ed:82:
2d:ec:fc:92:6d:9c:bc:27:f1:41:37:f6:da:28:09:c0:5e:66:
e6:e8:fe:c9:70:6a:98:39:b0:03:18:77:c7:b6:81:4a:5a:64:
cb:72:0f:3a