summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2015-01-16 13:02:28 +0000
committerBen Murdoch <benm@google.com>2015-01-16 13:02:28 +0000
commitd4816939904f8df05e7270af0379e51c84a53ddf (patch)
treee99cdccaeb3ab6d6d4e512cb573743afa3822e45
parent03d1abe83d2d93223668f4de58a32ee4cc484ed5 (diff)
parent54e455157a6e1899eb6fef9440d2410cb7fedeff (diff)
downloadsrc-d4816939904f8df05e7270af0379e51c84a53ddf.tar.gz
Merge third_party/boringssl/src from https://boringssl.googlesource.com/boringssl.git at 54e455157a6e1899eb6fef9440d2410cb7fedeff
This commit was generated by merge_from_chromium.py. Change-Id: I8e88df721d075be5ffef28c287fb29efe4a70395
-rw-r--r--crypto/ec/ec_asn1.c3
-rw-r--r--crypto/evp/evp_test.c53
2 files changed, 56 insertions, 0 deletions
diff --git a/crypto/ec/ec_asn1.c b/crypto/ec/ec_asn1.c
index 36f1cd5..ec1606d 100644
--- a/crypto/ec/ec_asn1.c
+++ b/crypto/ec/ec_asn1.c
@@ -373,6 +373,9 @@ err:
EC_KEY_free(ret);
}
ret = NULL;
+ if (a) {
+ *a = ret;
+ }
}
if (priv_key) {
diff --git a/crypto/evp/evp_test.c b/crypto/evp/evp_test.c
index 670df37..3e74cd5 100644
--- a/crypto/evp/evp_test.c
+++ b/crypto/evp/evp_test.c
@@ -229,6 +229,20 @@ static const uint8_t kExampleECKeyDER[] = {
0xc1,
};
+/* kExampleBadECKeyDER is a sample EC private key encoded as an ECPrivateKey
+ * structure. The private key is equal to the order and will fail to import */
+static const uint8_t kExampleBadECKeyDER[] = {
+ 0x30, 0x66, 0x02, 0x01, 0x00, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48,
+ 0xCE, 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03,
+ 0x01, 0x07, 0x04, 0x4C, 0x30, 0x4A, 0x02, 0x01, 0x01, 0x04, 0x20, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84, 0xF3,
+ 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51, 0xA1, 0x23, 0x03, 0x21, 0x00,
+ 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84,
+ 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51
+};
+
static EVP_PKEY *load_example_rsa_key(void) {
EVP_PKEY *ret = NULL;
const uint8_t *derp = kExampleRSAKeyDER;
@@ -539,6 +553,40 @@ done:
return ret;
}
+/* Tests loading a bad key in PKCS8 format */
+static int test_EVP_PKCS82PKEY(void) {
+ int ret = 0;
+ const uint8_t *derp = kExampleBadECKeyDER;
+ PKCS8_PRIV_KEY_INFO *p8inf = NULL;
+ EVP_PKEY *pkey = NULL;
+
+ p8inf = d2i_PKCS8_PRIV_KEY_INFO(NULL, &derp, sizeof(kExampleBadECKeyDER));
+
+ if (!p8inf || derp != kExampleBadECKeyDER + sizeof(kExampleBadECKeyDER)) {
+ fprintf(stderr, "Failed to parse key\n");
+ goto done;
+ }
+
+ pkey = EVP_PKCS82PKEY(p8inf);
+ if (pkey) {
+ fprintf(stderr, "Imported invalid EC key\n");
+ goto done;
+ }
+
+ ret = 1;
+
+done:
+ if (p8inf != NULL) {
+ PKCS8_PRIV_KEY_INFO_free(p8inf);
+ }
+
+ if (pkey != NULL) {
+ EVP_PKEY_free(pkey);
+ }
+
+ return ret;
+}
+
int main(void) {
CRYPTO_library_init();
ERR_load_crypto_strings();
@@ -581,6 +629,11 @@ int main(void) {
return 1;
}
+ if (!test_EVP_PKCS82PKEY()) {
+ fprintf(stderr, "test_EVP_PKCS82PKEY failed\n");
+ return 1;
+ }
+
printf("PASS\n");
return 0;
}