Fix DeviceInfo encoding and checks

 - Make the default implementation include the DeviceInfo as a map, not
   a bstr-holding-a-map, to match the spec.
 - Check the signature of the signed MAC even in test mode.
 - Include the DeviceInfo in the data that the signature covers.

Test: VtsHalRemotelyProvisionedComponentTargetTest
Change-Id: I9084343c1273c16a9cbd5a1156e7057a1c54a860
diff --git a/security/keymint/aidl/vts/functional/VtsRemotelyProvisionedComponentTests.cpp b/security/keymint/aidl/vts/functional/VtsRemotelyProvisionedComponentTests.cpp
index e4c4a22..516be3b 100644
--- a/security/keymint/aidl/vts/functional/VtsRemotelyProvisionedComponentTests.cpp
+++ b/security/keymint/aidl/vts/functional/VtsRemotelyProvisionedComponentTests.cpp
@@ -370,7 +370,7 @@
         }
     }
 
-    void checkProtectedData(bool testMode, const cppbor::Array& keysToSign,
+    void checkProtectedData(const DeviceInfo& deviceInfo, const cppbor::Array& keysToSign,
                             const bytevec& keysToSignMac, const ProtectedData& protectedData) {
         auto [parsedProtectedData, _, protDataErrMsg] = cppbor::parse(protectedData.protectedData);
         ASSERT_TRUE(parsedProtectedData) << protDataErrMsg;
@@ -404,11 +404,16 @@
         ASSERT_TRUE(bccContents) << "\n" << bccContents.message() << "\n" << prettyPrint(bcc.get());
         ASSERT_GT(bccContents->size(), 0U);
 
+        auto [deviceInfoMap, __2, deviceInfoErrMsg] = cppbor::parse(deviceInfo.deviceInfo);
+        ASSERT_TRUE(deviceInfoMap) << "Failed to parse deviceInfo: " << deviceInfoErrMsg;
+        ASSERT_TRUE(deviceInfoMap->asMap());
+
         auto& signingKey = bccContents->back().pubKey;
-        auto macKey = verifyAndParseCoseSign1(testMode, signedMac->asArray(), signingKey,
-                                              cppbor::Array()  // DeviceInfo
+        auto macKey = verifyAndParseCoseSign1(/* ignore_signature = */ false, signedMac->asArray(),
+                                              signingKey,
+                                              cppbor::Array()  // SignedMacAad
                                                       .add(challenge_)
-                                                      .add(cppbor::Map())
+                                                      .add(std::move(deviceInfoMap))
                                                       .encode());
         ASSERT_TRUE(macKey) << macKey.message();
 
@@ -451,7 +456,7 @@
                 &protectedData, &keysToSignMac);
         ASSERT_TRUE(status.isOk()) << status.getMessage();
 
-        checkProtectedData(testMode, cppbor::Array(), keysToSignMac, protectedData);
+        checkProtectedData(deviceInfo, cppbor::Array(), keysToSignMac, protectedData);
     }
 }
 
@@ -499,7 +504,7 @@
                 &keysToSignMac);
         ASSERT_TRUE(status.isOk()) << status.getMessage();
 
-        checkProtectedData(testMode, cborKeysToSign_, keysToSignMac, protectedData);
+        checkProtectedData(deviceInfo, cborKeysToSign_, keysToSignMac, protectedData);
     }
 }