summaryrefslogtreecommitdiff
path: root/futility/vb2_helper.c
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2015-10-15 17:54:34 -0700
committerchrome-bot <chrome-bot@chromium.org>2015-10-17 09:53:07 -0700
commit27c90708e63f5f042aa52de6bc1b89c282ca8c4a (patch)
tree356818f84486955e3591c4ab974ce70639c5097a /futility/vb2_helper.c
parent4d47243c9088ef295892fbc25b9c3622e43ad639 (diff)
downloadvboot-27c90708e63f5f042aa52de6bc1b89c282ca8c4a.tar.gz
futility: add support for .pem with public keystabilize-smaug-7566.B
Add support for PEM file containing a RSA Public key in futility "show" and "create" commands. When "futility create" is given a PEM file with only a RSA public key, generate the proper .vbpubk2 rather than failing. BRANCH=smaug BUG=none TEST=make runtests and run manually futility show tests/testkeys/key_rsa4096.pub.pem futility show tests/testkeys/key_rsa4096.pem Change-Id: I707ceca54c80ba21f53869ad86c86fa23b31e665 Reviewed-on: https://chromium-review.googlesource.com/306683 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'futility/vb2_helper.c')
-rw-r--r--futility/vb2_helper.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/futility/vb2_helper.c b/futility/vb2_helper.c
index 4ee0a28b..51a78375 100644
--- a/futility/vb2_helper.c
+++ b/futility/vb2_helper.c
@@ -184,6 +184,11 @@ static RSA *rsa_from_buffer(uint8_t *buf, uint32_t len)
rsa_key = PEM_read_bio_RSAPrivateKey(bp, NULL, NULL, NULL);
if (!rsa_key) {
+ if (BIO_reset(bp) < 0)
+ return 0;
+ rsa_key = PEM_read_bio_RSA_PUBKEY(bp, NULL, NULL, NULL);
+ }
+ if (!rsa_key) {
BIO_free(bp);
return 0;
}
@@ -212,13 +217,15 @@ int ft_show_pem(const char *name, uint8_t *buf, uint32_t len, void *data)
uint32_t keyb_len;
int i, bits;
- printf("Private Key file: %s\n", name);
-
/* We're called only after ft_recognize_pem, so this should work. */
rsa_key = rsa_from_buffer(buf, len);
if (!rsa_key)
DIE;
+ /* Use to presence of the private exponent to decide if it's public */
+ printf("%s Key file: %s\n", rsa_key->d ? "Private" : "Public",
+ name);
+
bits = BN_num_bits(rsa_key->n);
printf(" Key length: %d\n", bits);