summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike McTernan <mikemcternan@google.com>2024-04-08 15:37:23 +0100
committerMike McTernan <mikemcternan@google.com>2024-04-08 16:08:36 +0100
commit2d76f6d0bc01d618ee28756a5843732c15dc35ca (patch)
treebc10f9ee2cad950cc70547d5592409db72c50d3b
parent93e253ae87e019dbe0c88216c9ab0bb5ed2f0db8 (diff)
downloadcast-auth-main.tar.gz
trusty: cast-auth: fix incorrect return value on error pathHEADmastermain
The function returns a bool to identify the keytype, but would return an error code on memory failure. Change the function to avoid the memory allocation failure path. Bug: 332371854 Test: build.py qemu-generic-arm64-test-debug --test com.android.trusty.cast_auth.test Change-Id: Idc0f4b2484ec5b00bf97eed3647196ef2da463bb
-rw-r--r--app/cast_auth_impl.cc11
1 files changed, 4 insertions, 7 deletions
diff --git a/app/cast_auth_impl.cc b/app/cast_auth_impl.cc
index cfa8a0f..b1ccdb4 100644
--- a/app/cast_auth_impl.cc
+++ b/app/cast_auth_impl.cc
@@ -45,13 +45,10 @@ constexpr int MESSAGE_MAX_BYTES = PAYLOAD_MAX_BYTES + BINDER_MAX_BYTES;
using android::binder::Status;
bool is_plaintext_rsa_2048_private_key(const std::vector<uint8_t>& key) {
- bssl::UniquePtr<BIO> bio(BIO_new_mem_buf(key.data(), key.size()));
- if (!bio) {
- TLOGE("is_plaintext_rsa_2048_private_key: failed to allocate memory for the "
- "device key\n");
- return ERR_NO_MEMORY;
- }
- bssl::UniquePtr<RSA> rsa(d2i_RSAPrivateKey_bio(bio.get(), NULL));
+ const uint8_t* key_data = key.data();
+
+ bssl::UniquePtr<RSA> rsa(d2i_RSAPrivateKey(NULL, &key_data, key.size()));
+
return rsa && RSA_size(rsa.get()) == RSA_2048_SIZE_BYTES;
}