From 452df6d99c81c4eeee3d2c7b2171901e8b7bc54a Mon Sep 17 00:00:00 2001 From: Mattias Nissler Date: Mon, 4 Apr 2016 16:17:01 +0200 Subject: Convert recovery to use BoringSSL instead of mincrypt. This changes the verification code in bootable/recovery to use BoringSSL instead of mincrypt. Change-Id: I37b37d84b22e81c32ac180cd1240c02150ddf3a7 --- verifier.h | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'verifier.h') diff --git a/verifier.h b/verifier.h index 4eafc7565..58083fe14 100644 --- a/verifier.h +++ b/verifier.h @@ -20,32 +20,42 @@ #include #include -#include "mincrypt/p256.h" -#include "mincrypt/rsa.h" +#include +#include +#include -typedef struct { - p256_int x; - p256_int y; -} ECPublicKey; +struct RSADeleter { + void operator()(RSA* rsa) { + RSA_free(rsa); + } +}; + +struct ECKEYDeleter { + void operator()(EC_KEY* ec_key) { + EC_KEY_free(ec_key); + } +}; struct Certificate { typedef enum { - RSA, - EC, + KEY_TYPE_RSA, + KEY_TYPE_EC, } KeyType; - Certificate(int hash_len_, KeyType key_type_, - std::unique_ptr&& rsa_, - std::unique_ptr&& ec_) : - hash_len(hash_len_), - key_type(key_type_), - rsa(std::move(rsa_)), - ec(std::move(ec_)) { } + Certificate(int hash_len_, + KeyType key_type_, + std::unique_ptr&& rsa_, + std::unique_ptr&& ec_) + : hash_len(hash_len_), + key_type(key_type_), + rsa(std::move(rsa_)), + ec(std::move(ec_)) {} - int hash_len; // SHA_DIGEST_SIZE (SHA-1) or SHA256_DIGEST_SIZE (SHA-256) + // SHA_DIGEST_LENGTH (SHA-1) or SHA256_DIGEST_LENGTH (SHA-256) + int hash_len; KeyType key_type; - std::unique_ptr rsa; - std::unique_ptr ec; + std::unique_ptr rsa; + std::unique_ptr ec; }; /* addr and length define a an update package file that has been -- cgit v1.2.3 From 5e535014dd7961fbf812abeaa27f3339775031f1 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Thu, 16 Mar 2017 17:37:38 -0700 Subject: Drop the dependency on 'ui' in verify_file(). verify_file() has a dependency on the global variable of 'ui' for posting the verification progress, which requires the users of libverifier to provide a UI instance. This CL adds an optional argument to verify_file() so that it can post the progress through the provided callback function. As a result, we can drop the MockUI class in verifier_test.cpp. Test: recovery_component_test passes. Test: verify_file() posts progress update when installing an OTA. Change-Id: I8b87d0f0d99777ea755d33d6dbbe2b6d44243bf1 --- verifier.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'verifier.h') diff --git a/verifier.h b/verifier.h index 58083fe14..067dab554 100644 --- a/verifier.h +++ b/verifier.h @@ -17,6 +17,7 @@ #ifndef _RECOVERY_VERIFIER_H #define _RECOVERY_VERIFIER_H +#include #include #include @@ -58,13 +59,14 @@ struct Certificate { std::unique_ptr ec; }; -/* addr and length define a an update package file that has been - * loaded (or mmap'ed, or whatever) into memory. Verify that the file - * is signed and the signature matches one of the given keys. Return - * one of the constants below. +/* + * 'addr' and 'length' define an update package file that has been loaded (or mmap'ed, or + * whatever) into memory. Verifies that the file is signed and the signature matches one of the + * given keys. It optionally accepts a callback function for posting the progress to. Returns one + * of the constants of VERIFY_SUCCESS and VERIFY_FAILURE. */ -int verify_file(unsigned char* addr, size_t length, - const std::vector& keys); +int verify_file(unsigned char* addr, size_t length, const std::vector& keys, + const std::function& set_progress = nullptr); bool load_keys(const char* filename, std::vector& certs); -- cgit v1.2.3 From 76fdb2419bfec0e747db2530379484a3dc571f34 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 20 Mar 2017 17:09:13 -0700 Subject: verify_file: Add constness to a few addresses. We should not touch any data while verifying packages (or parsing the in-memory ASN.1 structures). Test: mmma bootable/recovery Test: recovery_component_test passes. Test: recovery_unit_test passes. Change-Id: Ie990662c6451ec066a1807b3081c9296afbdb0bf --- verifier.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'verifier.h') diff --git a/verifier.h b/verifier.h index 067dab554..6bee74947 100644 --- a/verifier.h +++ b/verifier.h @@ -65,7 +65,7 @@ struct Certificate { * given keys. It optionally accepts a callback function for posting the progress to. Returns one * of the constants of VERIFY_SUCCESS and VERIFY_FAILURE. */ -int verify_file(unsigned char* addr, size_t length, const std::vector& keys, +int verify_file(const unsigned char* addr, size_t length, const std::vector& keys, const std::function& set_progress = nullptr); bool load_keys(const char* filename, std::vector& certs); -- cgit v1.2.3 From b49767c0bacb714e14f988423e14832689c6faf2 Mon Sep 17 00:00:00 2001 From: Mikhail Lappo Date: Thu, 23 Mar 2017 21:44:26 +0100 Subject: Const modifiers This functions do not change class variables Would be good to mark them as const, so class variables are not changed by coincidence Change-Id: Iea34f6d26dbd1bde813035160e07ff2a681989e6 --- verifier.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'verifier.h') diff --git a/verifier.h b/verifier.h index 6bee74947..6fa8f2b0a 100644 --- a/verifier.h +++ b/verifier.h @@ -26,13 +26,13 @@ #include struct RSADeleter { - void operator()(RSA* rsa) { + void operator()(RSA* rsa) const { RSA_free(rsa); } }; struct ECKEYDeleter { - void operator()(EC_KEY* ec_key) { + void operator()(EC_KEY* ec_key) const { EC_KEY_free(ec_key); } }; -- cgit v1.2.3