Skip to content

Commit 2cefe30

Browse files
committed
Remote-attestation with tools: Changes to aik properties and usage
AIK is now only used for signing quotes A separate service content key signed by AIK is used to encrypt/ decrypt service content. Signed-off-by: Imran Desai <imran.desai@intel.com>
1 parent fd7efcf commit 2cefe30

1 file changed

Lines changed: 109 additions & 31 deletions

File tree

_posts/2020-06-12-Remote-Attestation-With-tpm2-tools.md

Lines changed: 109 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,8 @@ The sequence diagram below shown the interactions during this stage.
620620
At this stage, by validating the “SERVICE-TOKEN“ and the attestation-quote it
621621
received from the “Device-Node“, the “Service-Provider“ has ascertained the
622622
“Device-Node“ anonymous identity and system-software state. With the system in
623-
a known state, the “Service-Provider“ can now wrap the “SERVICE-SECRET“ with the
624-
AIK Public Key.
623+
a known state, the “Service-Provider“ can now wrap the “SERVICE-SECRET“ with a service-content-key signed by the
624+
device AIK.<br>
625625
626626
![Service-delivery](/images/tpm2-attestation-demo/service-delivery.png)
627627
@@ -873,12 +873,17 @@ device_registration() {
873873
tpm2_createek --ek-context rsa_ek.ctx --key-algorithm rsa \
874874
--public rsa_ek.pub -Q
875875

876-
tpm2_startauthsession -S session.ctx --policy-session -Q
877-
tpm2_policysecret -S session.ctx -c e -Q
878-
tpm2_create -C rsa_ek.ctx -c rsa_ak.ctx -u rsa_ak.pub -r rsa_ak.priv \
879-
-P session:session.ctx -Q
880-
tpm2_readpublic -c rsa_ak.ctx -f pem -o rsa_ak.pub -n rsa_ak.name -Q
881-
tpm2_flushcontext session.ctx -Q
876+
tpm2_createak \
877+
--ek-context rsa_ek.ctx \
878+
--ak-context rsa_ak.ctx \
879+
--key-algorithm rsa \
880+
--hash-algorithm sha256 \
881+
--signing-algorithm rsassa \
882+
--public rsa_ak.pub \
883+
--private rsa_ak.priv \
884+
--ak-name rsa_ak.name \
885+
-Q
886+
tpm2_readpublic -c rsa_ak.ctx -f pem -o rsa_ak.pub -Q
882887

883888
touch fake_ek_certificate.txt
884889

@@ -1023,7 +1028,7 @@ process_device_software_state_validation_request() {
10231028
--pcr-list "$pcr_selection" \
10241029
--pcr pcr.bin -Q
10251030

1026-
cp attestation_quote.dat attestation_quote.signature \
1031+
cp attestation_quote.dat attestation_quote.signature pcr.bin \
10271032
$service_provider_location/.
10281033

10291034
return 0
@@ -1042,7 +1047,7 @@ process_encrypted_service_data_content() {
10421047
event_file_found=0
10431048

10441049
service_data_status_string="Decryption of service-data-content receipt from Service-Provider"
1045-
tpm2 rsadecrypt -c rsa_ak.ctx -o s_d_service_content.decrypted \
1050+
tpm2 rsadecrypt -c service_content_key.ctx -o s_d_service_content.decrypted \
10461051
s_d_service_content.encrypted -Q
10471052
if [ $? == 1 ];then
10481053
LOG_ERROR "$service_data_status_string"
@@ -1058,6 +1063,34 @@ process_encrypted_service_data_content() {
10581063
return 0
10591064
}
10601065

1066+
process_generate_service_content_key() {
1067+
1068+
tpm2_create \
1069+
-C n \
1070+
-c service_content_key.ctx \
1071+
-u service_content_key.pub \
1072+
-r service_content_key.priv \
1073+
-Q
1074+
1075+
tpm2_readpublic \
1076+
-c service_content_key.ctx \
1077+
-f pem \
1078+
-o d_s_service_content_key.pub \
1079+
-Q
1080+
cp d_s_service_content_key.pub $service_provider_location/.
1081+
1082+
tpm2_sign \
1083+
-c rsa_ak.ctx \
1084+
-g sha256 \
1085+
-s rsassa \
1086+
-f plain \
1087+
-o d_s_service_content_key_pub.sig \
1088+
d_s_service_content_key.pub
1089+
cp d_s_service_content_key_pub.sig $service_provider_location/.
1090+
1091+
return 0
1092+
}
1093+
10611094
request_device_service() {
10621095

10631096
request_service_status_string="Device anonymous identity challenge."
@@ -1076,6 +1109,14 @@ request_device_service() {
10761109
fi
10771110
LOG_INFO "$request_service_status_string"
10781111

1112+
request_service_status_string="Generating certified service key"
1113+
process_generate_service_content_key
1114+
if [ $? == 1 ];then
1115+
LOG_ERROR "$request_service_status_string"
1116+
return 1
1117+
fi
1118+
LOG_INFO "$request_service_status_string"
1119+
10791120
request_service_status_string="Service data content processing"
10801121
process_encrypted_service_data_content
10811122
if [ $? == 1 ];then
@@ -1355,6 +1396,43 @@ system_software_state_validation() {
13551396
return 0
13561397
}
13571398

1399+
device_service_content_key_validation() {
1400+
request_service_content_key_string="Retrieving service content key from device"
1401+
max_wait=60
1402+
wait_loop $max_wait d_s_service_content_key.pub
1403+
if [ $event_file_found == 0 ];then
1404+
LOG_ERROR "$request_service_content_key_string"
1405+
return 1
1406+
fi
1407+
event_file_found=0
1408+
LOG_INFO "$request_service_content_key_string"
1409+
1410+
max_wait=60
1411+
wait_loop $max_wait d_s_service_content_key_pub.sig
1412+
if [ $event_file_found == 0 ];then
1413+
LOG_ERROR "$request_service_content_key_string"
1414+
return 1
1415+
fi
1416+
event_file_found=0
1417+
LOG_INFO "$request_service_content_key_string"
1418+
1419+
openssl dgst -sha256 -binary d_s_service_content_key.pub > service_content_key.pub.digest
1420+
1421+
openssl pkeyutl \
1422+
-verify \
1423+
-in service_content_key.pub.digest \
1424+
-sigfile d_s_service_content_key_pub.sig \
1425+
-pubin \
1426+
-inkey d_s_service_aik.pub \
1427+
-keyform pem \
1428+
-pkeyopt digest:sha256
1429+
if [ $? == 1 ];then
1430+
return 1
1431+
fi
1432+
1433+
return 0
1434+
}
1435+
13581436
request_device_service() {
13591437
# Start device service registration with device identity challenge
13601438
request_device_service_status_string="Anonymous identity validation by Privacy-CA."
@@ -1376,13 +1454,25 @@ request_device_service() {
13761454
fi
13771455
LOG_INFO "$request_device_service_status_string"
13781456

1457+
# Verify service content key from the device
1458+
request_device_service_status_string="Device service content key validation."
1459+
device_service_content_key_validation
1460+
if [ $? == 1 ];then
1461+
LOG_ERROR "$request_device_service_status_string"
1462+
rm -f d_s_service_aik.pub
1463+
rm -f d_s_service_content_key.pub
1464+
return 1
1465+
fi
1466+
LOG_INFO "$request_device_service_status_string"
1467+
13791468
# Encrypt service data content and deliver
13801469
echo "$SERVICE_CONTENT" > service-content.plain
1381-
openssl rsautl -encrypt -inkey d_s_service_aik.pub -pubin \
1470+
openssl rsautl -encrypt -inkey d_s_service_content_key.pub -pubin \
13821471
-in service-content.plain -out s_d_service_content.encrypted
13831472

13841473
cp s_d_service_content.encrypted $device_location/.
13851474
rm -f d_s_service_aik.pub
1475+
rm -f d_s_service_content_key.pub
13861476
rm -f s_d_service_content.encrypted
13871477
rm -f service-content.plain
13881478
LOG_INFO "Sending service-content: \e[5m$SERVICE_CONTENT"
@@ -1505,9 +1595,13 @@ credential_challenge() {
15051595
loaded_key_name=`cat rsa_ak.name | xxd -p -c $file_size`
15061596

15071597
echo "this is my secret" > file_input.data
1508-
tpm2_makecredential --tcti none --encryption-key rsa_ek.pub \
1509-
--secret file_input.data --name $loaded_key_name \
1510-
--credential-blob cred.out
1598+
tpm2_makecredential \
1599+
--tcti none \
1600+
--encryption-key rsa_ek.pub \
1601+
--secret file_input.data \
1602+
--name $loaded_key_name \
1603+
--credential-blob cred.out \
1604+
-Q
15111605

15121606
cp cred.out $device_location/.
15131607

@@ -1552,7 +1646,7 @@ process_device_registration_processing_with_device() {
15521646
rm -f d_p_device_ready.txt
15531647

15541648
cp $device_location/rsa_ek.pub .
1555-
cp $device_location/rsa_ak.pub .
1649+
#cp $device_location/rsa_ak.pub .
15561650
cp $device_location/rsa_ak.name .
15571651
LOG_INFO "Received EKcertificate EK and AIK from device"
15581652

@@ -1722,21 +1816,5 @@ exit 0
17221816
been used in the device-node.sh scripts in this tutorial as well to generate a
17231817
pem formatted file.
17241818

1725-
2. ***Why is tpm2_createak tool not used to create the AIK in the demo scripts?***
1726-
1727-
In our demo example we intend to have an AIK with following properties:
1728-
a. It will have to be validated for anonymous identity relationship with EK.
1729-
b. It has to be a signing key for it to be used to sign an attestation quote.
1730-
c. It has to be usable as RSA encrypt/ decrypt key.
1731-
1732-
The combination of the above properties is not the default attributes chosen
1733-
in the tpm2_createak tool. Specifically, the key generated with tpm2_createak
1734-
cannot be used as a decryption key.
1735-
1736-
Note that the authorization for using the endorsement key which is the parent
1737-
of the attestation identity key needs to be satisfied to be able to create
1738-
the AIK and is satisfied through a policy session using a policy
1739-
"policysecret" to reference the authorization of the endorsement hierarchy.
1740-
17411819
# Author
17421820
Imran Desai

0 commit comments

Comments
 (0)