Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d9c02724 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "have one implementation of deviceSuffix" into main

parents 6fa39760 afbab608
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -99,7 +99,7 @@ const std::string RKPVM_INSTANCE_NAME =
 * e.g. for "android.hardware.security.keymint.IRemotelyProvisionedComponent/avf",
 * it returns "avf".
 */
std::string deviceSuffix(const std::string& name);
std::string_view deviceSuffix(std::string_view name);

struct EekChain {
    bytevec chain;
+2 −2
Original line number Diff line number Diff line
@@ -52,8 +52,8 @@ using EVP_PKEY_CTX_Ptr = bssl::UniquePtr<EVP_PKEY_CTX>;
using X509_Ptr = bssl::UniquePtr<X509>;
using CRYPTO_BUFFER_Ptr = bssl::UniquePtr<CRYPTO_BUFFER>;

std::string deviceSuffix(const std::string& name) {
    size_t pos = name.rfind('/');
std::string_view deviceSuffix(std::string_view name) {
    auto pos = name.rfind('/');
    if (pos == std::string::npos) {
        return name;
    }
+4 −11
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include <remote_prov/remote_prov_utils.h>
#include <optional>
#include <set>
#include <string_view>
#include <vector>

#include "KeyMintAidlTestBase.h"
@@ -150,22 +151,14 @@ ErrMsgOr<bytevec> corrupt_sig_chain(const bytevec& encodedEekChain, int which) {
    return corruptChain.encode();
}

string device_suffix(const string& name) {
    size_t pos = name.find('/');
    if (pos == string::npos) {
        return name;
    }
    return name.substr(pos + 1);
}

bool matching_keymint_device(const string& rp_name, std::shared_ptr<IKeyMintDevice>* keyMint) {
    string rp_suffix = device_suffix(rp_name);
    auto rp_suffix = deviceSuffix(rp_name);

    vector<string> km_names = ::android::getAidlHalInstanceNames(IKeyMintDevice::descriptor);
    for (const string& km_name : km_names) {
        // If the suffix of the KeyMint instance equals the suffix of the
        // RemotelyProvisionedComponent instance, assume they match.
        if (device_suffix(km_name) == rp_suffix && AServiceManager_isDeclared(km_name.c_str())) {
        if (deviceSuffix(km_name) == rp_suffix && AServiceManager_isDeclared(km_name.c_str())) {
            ::ndk::SpAIBinder binder(AServiceManager_waitForService(km_name.c_str()));
            *keyMint = IKeyMintDevice::fromBinder(binder);
            return true;
@@ -1002,7 +995,7 @@ TEST_P(CertificateRequestV2Test, DeviceInfo) {
    ASSERT_TRUE(bootPatchLevel);
    ASSERT_TRUE(securityLevel);

    auto kmDeviceName = device_suffix(GetParam());
    auto kmDeviceName = deviceSuffix(GetParam());

    // Compare DeviceInfo against IDs attested by KeyMint.
    ASSERT_TRUE((securityLevel->value() == "tee" && kmDeviceName == "default") ||