aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2016-02-02 16:02:27 -0600
committerTao Bao2016-02-02 23:51:32 -0600
commit71e3e09ec2ac4f022e8f9213657746d8cad5dd97 (patch)
treed588a2f9f86e0eac79c9aeb2dcb1591353229272 /verifier.h
parent4c07a7ec0557130b95fc1f69da818e83b0887d20 (diff)
downloadplatform-bootable-recovery-71e3e09ec2ac4f022e8f9213657746d8cad5dd97.tar.gz
platform-bootable-recovery-71e3e09ec2ac4f022e8f9213657746d8cad5dd97.tar.xz
platform-bootable-recovery-71e3e09ec2ac4f022e8f9213657746d8cad5dd97.zip
recovery: Refactor verifier and verifier_test.
Move to using std::vector and std::unique_ptr to manage key certificates to stop memory leaks. Bug: 26908001 Change-Id: Ia5f799bc8dcc036a0ffae5eaa8d9f6e09abd031c
Diffstat (limited to 'verifier.h')
-rw-r--r--verifier.h23
1 files changed, 17 insertions, 6 deletions
diff --git a/verifier.h b/verifier.h
index 15f8d98e..4eafc756 100644
--- a/verifier.h
+++ b/verifier.h
@@ -17,6 +17,9 @@
17#ifndef _RECOVERY_VERIFIER_H 17#ifndef _RECOVERY_VERIFIER_H
18#define _RECOVERY_VERIFIER_H 18#define _RECOVERY_VERIFIER_H
19 19
20#include <memory>
21#include <vector>
22
20#include "mincrypt/p256.h" 23#include "mincrypt/p256.h"
21#include "mincrypt/rsa.h" 24#include "mincrypt/rsa.h"
22 25
@@ -25,17 +28,25 @@ typedef struct {
25 p256_int y; 28 p256_int y;
26} ECPublicKey; 29} ECPublicKey;
27 30
28typedef struct { 31struct Certificate {
29 typedef enum { 32 typedef enum {
30 RSA, 33 RSA,
31 EC, 34 EC,
32 } KeyType; 35 } KeyType;
33 36
37 Certificate(int hash_len_, KeyType key_type_,
38 std::unique_ptr<RSAPublicKey>&& rsa_,
39 std::unique_ptr<ECPublicKey>&& ec_) :
40 hash_len(hash_len_),
41 key_type(key_type_),
42 rsa(std::move(rsa_)),
43 ec(std::move(ec_)) { }
44
34 int hash_len; // SHA_DIGEST_SIZE (SHA-1) or SHA256_DIGEST_SIZE (SHA-256) 45 int hash_len; // SHA_DIGEST_SIZE (SHA-1) or SHA256_DIGEST_SIZE (SHA-256)
35 KeyType key_type; 46 KeyType key_type;
36 RSAPublicKey* rsa; 47 std::unique_ptr<RSAPublicKey> rsa;
37 ECPublicKey* ec; 48 std::unique_ptr<ECPublicKey> ec;
38} Certificate; 49};
39 50
40/* addr and length define a an update package file that has been 51/* addr and length define a an update package file that has been
41 * loaded (or mmap'ed, or whatever) into memory. Verify that the file 52 * loaded (or mmap'ed, or whatever) into memory. Verify that the file
@@ -43,9 +54,9 @@ typedef struct {
43 * one of the constants below. 54 * one of the constants below.
44 */ 55 */
45int verify_file(unsigned char* addr, size_t length, 56int verify_file(unsigned char* addr, size_t length,
46 const Certificate *pKeys, unsigned int numKeys); 57 const std::vector<Certificate>& keys);
47 58
48Certificate* load_keys(const char* filename, int* numKeys); 59bool load_keys(const char* filename, std::vector<Certificate>& certs);
49 60
50#define VERIFY_SUCCESS 0 61#define VERIFY_SUCCESS 0
51#define VERIFY_FAILURE 1 62#define VERIFY_FAILURE 1