]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
When parsing tokens, reject early on spurious keys.
authorNick Mathewson <nickm@torproject.org>
Wed, 5 Feb 2020 16:57:31 +0000 (11:57 -0500)
committerNick Mathewson <nickm@torproject.org>
Wed, 5 Feb 2020 16:57:31 +0000 (11:57 -0500)
src/feature/dirparse/parsecommon.c

index 5b753f0f230fa92e22408e7a53adc4b3c21f6b1a..e8269f7ec77ca9ce3a3f54f57fc17aec4b5bb089 100644 (file)
@@ -384,10 +384,16 @@ get_next_token(memarea_t *area,
     RET_ERR("Couldn't parse object: missing footer or object much too big.");
 
   if (!strcmp(tok->object_type, "RSA PUBLIC KEY")) { /* If it's a public key */
+    if (o_syn != NEED_KEY && o_syn != NEED_KEY_1024 && o_syn != OBJ_OK) {
+      RET_ERR("Unexpected public key.");
+    }
     tok->key = crypto_pk_new();
     if (crypto_pk_read_public_key_from_string(tok->key, obstart, eol-obstart))
       RET_ERR("Couldn't parse public key.");
   } else if (!strcmp(tok->object_type, "RSA PRIVATE KEY")) { /* private key */
+    if (o_syn != NEED_SKEY_1024 && o_syn != OBJ_OK) {
+      RET_ERR("Unexpected private key.");
+    }
     tok->key = crypto_pk_new();
     if (crypto_pk_read_private_key1024_from_string(tok->key,
                                                    obstart, eol-obstart))