Add a fuzzer to check CBS is a DER parser.

ECDSA_verify does a runtime check that our parser round-trips, but that
should already be true. Add a fuzzer to ensure it.

Change-Id: I396863b8f9ed66c6296cfb16f7197a63ae99e156
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/52733
Reviewed-by: Adam Langley <agl@google.com>
chromium-5359
David Benjamin 3 years ago committed by Adam Langley
parent a255d7c6a1
commit 505bbf9c84
  1. 1
      fuzz/CMakeLists.txt
  2. 57
      fuzz/der_roundtrip.cc
  3. BIN
      fuzz/der_roundtrip_corpus/0461791e54b4840c109637952eab43d9b938cab8
  4. BIN
      fuzz/der_roundtrip_corpus/06e57a7b98a403a00822739739924b97ae6c74e9
  5. BIN
      fuzz/der_roundtrip_corpus/078c3c1199930781466871c8dda69bec379286a4
  6. 1
      fuzz/der_roundtrip_corpus/082a991742f652549e4b207100ee521f474e0a99
  7. BIN
      fuzz/der_roundtrip_corpus/091e3389548686c5038d04e3d76b9c4d30502074
  8. 1
      fuzz/der_roundtrip_corpus/13e484c406efe97dc9d91f8b80a27b0e597c34da
  9. BIN
      fuzz/der_roundtrip_corpus/153d254254345b61e20e7b37637dd6f6fd71ba01
  10. 1
      fuzz/der_roundtrip_corpus/163605136e22f5b5302fe60d1f17837bee6b6b2b
  11. 1
      fuzz/der_roundtrip_corpus/1a96ec99b487b93052cd860c447e6d126dcc36d4
  12. 1
      fuzz/der_roundtrip_corpus/1cc9ad96fcee279e8589b7071c7a0ccd111098f2
  13. 1
      fuzz/der_roundtrip_corpus/229b8e1825512868e0e11a199ed71231dd41bb4f
  14. BIN
      fuzz/der_roundtrip_corpus/236d820eadf7f84d70de7bb8be5f1c57a4005de2
  15. BIN
      fuzz/der_roundtrip_corpus/24fd9742dbdee3167509db4af245ad6f8c4c1e99
  16. BIN
      fuzz/der_roundtrip_corpus/2896f8deb3c4e8bdfeab743b22c64c92316880f7
  17. BIN
      fuzz/der_roundtrip_corpus/29b6252fe9c4d1186394b1664c421cca795b61a5
  18. BIN
      fuzz/der_roundtrip_corpus/2b4955132275314d1d377f37f93d8c1879a3519a
  19. BIN
      fuzz/der_roundtrip_corpus/2e7112ac524a7a663632397cbb41f7dfd22e92c6
  20. 1
      fuzz/der_roundtrip_corpus/396d197005432accf99bf0f483286e459eb24063
  21. 1
      fuzz/der_roundtrip_corpus/3c75fe79266cf639f2180722a3f03f8fc3e25685
  22. 1
      fuzz/der_roundtrip_corpus/3fbb104fb0eb6cae4af34d8a516998336b3a6778
  23. BIN
      fuzz/der_roundtrip_corpus/422fa995b3fdfed572b68b292062c330d6d05272
  24. BIN
      fuzz/der_roundtrip_corpus/428b48fc494cee828f0c27f77aef477cb2e1fd80
  25. 1
      fuzz/der_roundtrip_corpus/4bd69e424b6fa38f9e63e58b8d0e95ac2d38d598
  26. BIN
      fuzz/der_roundtrip_corpus/4be7e1f134e1c55aeadeead515200f6f1e6254ba
  27. BIN
      fuzz/der_roundtrip_corpus/4de268400e174db2dc306f45c833cf968a6c6546
  28. 1
      fuzz/der_roundtrip_corpus/52d2c7efcd7da0eb7463829e05a598e36729bfae
  29. BIN
      fuzz/der_roundtrip_corpus/53cf415eb9de49fb5a0cb46e745e413a99aa0779
  30. 1
      fuzz/der_roundtrip_corpus/53ea84c48a5792281a46eb5a9c896d54ea3f1838
  31. BIN
      fuzz/der_roundtrip_corpus/5ba93c9db0cff93f52b521d7420e43f6eda2784f
  32. 1
      fuzz/der_roundtrip_corpus/5bab61eb53176449e25c2c82f172b82cb13ffb9d
  33. BIN
      fuzz/der_roundtrip_corpus/5e5361730362736fe3e2804d8566e3c91454509b
  34. BIN
      fuzz/der_roundtrip_corpus/6654fedb1fc4b07095695b062b5af4c2f12d59ae
  35. 1
      fuzz/der_roundtrip_corpus/6cad8b2a41194372ec897bece6512fe8331e274d
  36. BIN
      fuzz/der_roundtrip_corpus/6f40330ec07e8e22f113f982b297ff7f86b8e485
  37. BIN
      fuzz/der_roundtrip_corpus/738f291e53e97c08dae378c71ef70a60e31ae900
  38. BIN
      fuzz/der_roundtrip_corpus/7396791821e64fc9340249a4bcbd2198e9f237db
  39. BIN
      fuzz/der_roundtrip_corpus/7653595e28f23e62ea6707c99ca08c780a69335f
  40. 1
      fuzz/der_roundtrip_corpus/77de68daecd823babbb58edb1c8e14d7106e83bb
  41. BIN
      fuzz/der_roundtrip_corpus/7cb5c71603a787032973d6ddc9c2c34638005784
  42. BIN
      fuzz/der_roundtrip_corpus/80a1e1ae75c1e5ef7bbde5f5877e3e5b26b3cf58
  43. 1
      fuzz/der_roundtrip_corpus/872ba8af52a8c1380c388bab0e20bec2e729db80
  44. BIN
      fuzz/der_roundtrip_corpus/8855f2d904cf1bbaffc54e68d98890fdc9ec14cc
  45. BIN
      fuzz/der_roundtrip_corpus/8a22f56ee86cc2d67e9610a6b0ed59f21008a341
  46. 1
      fuzz/der_roundtrip_corpus/935a69e9f3bfa1dd3bf058fa3e1b953e82195de6
  47. BIN
      fuzz/der_roundtrip_corpus/951ccb49640c8f9e81fb4e0d82730321f4e15bb3
  48. BIN
      fuzz/der_roundtrip_corpus/9af1f3ed10c7a54f6b57c344015141cc082db23b
  49. BIN
      fuzz/der_roundtrip_corpus/a0b7dd1684089c63a4aac2e4a832544df4d639d6
  50. BIN
      fuzz/der_roundtrip_corpus/a22d0d3565a509a4bfedce078090d8c6a908d950
  51. BIN
      fuzz/der_roundtrip_corpus/a22f1185582f66227118c8e9002a5c29728f0650
  52. 1
      fuzz/der_roundtrip_corpus/a457945cb86ec812235f407ed70fe72fbaf694a1
  53. BIN
      fuzz/der_roundtrip_corpus/a4ee44c4e8728d4924642ef8765063262e8c4601
  54. 1
      fuzz/der_roundtrip_corpus/a4fc609a6546fc0061f499f0faed9054fd388c9a
  55. 1
      fuzz/der_roundtrip_corpus/a7c13e6fe60eee08b9aac00a095a9301ea1a9824
  56. BIN
      fuzz/der_roundtrip_corpus/a98e22a5a8c2f5dda365d55e76536931010e1560
  57. BIN
      fuzz/der_roundtrip_corpus/aca6ed86348b1176bfbe4ebf32b2d48a0aa42f9f
  58. BIN
      fuzz/der_roundtrip_corpus/aeefb82d7f5cc69168aade3b196a84d0f5c14bf2
  59. 1
      fuzz/der_roundtrip_corpus/b37e0f6fa42840c773747c4cb608c278ab65021d
  60. BIN
      fuzz/der_roundtrip_corpus/b5d4e67f0ec5b1a90100d8ad424d77aea8e16353
  61. BIN
      fuzz/der_roundtrip_corpus/b65ea16ba4dae8599ebbad7c4cb9fcd505edf485
  62. 1
      fuzz/der_roundtrip_corpus/b95311782071c4d9182c0effe32487fc5cdbd33d
  63. BIN
      fuzz/der_roundtrip_corpus/bbcaf4d15f92bfc6d624eee967fade1a74329f30
  64. 1
      fuzz/der_roundtrip_corpus/bc26b8c794ac0adf948cbca02e88b3901824ef17
  65. 1
      fuzz/der_roundtrip_corpus/bc7b23c2c68e4ad33ecea493ff6e60d423371cd0
  66. BIN
      fuzz/der_roundtrip_corpus/bd8daf3e78d8ba3a25838053b6993edc7a21c30e
  67. BIN
      fuzz/der_roundtrip_corpus/c4d94647e646f02da1736b3179804ad6083acde9
  68. BIN
      fuzz/der_roundtrip_corpus/c869b259f9f81bec8ed24a9bc2cef35a513fb9fc
  69. 1
      fuzz/der_roundtrip_corpus/ceee46f04a09ef5d3342ef25d9f483e861727575
  70. BIN
      fuzz/der_roundtrip_corpus/d05c069216b54f35bc7e3ee08371baee243c089a
  71. 1
      fuzz/der_roundtrip_corpus/d18c30ba21e0d085dd983ad528f2c9001285d3d2
  72. 1
      fuzz/der_roundtrip_corpus/d2c00146b2f2bcb4c6cecb731d2062273523d8c8
  73. BIN
      fuzz/der_roundtrip_corpus/d9bc7157a485958a5fce35ce777f551fe3f7d94c
  74. 1
      fuzz/der_roundtrip_corpus/defce76f0d3c3e057bb623986bacee7bbd07d1a1
  75. BIN
      fuzz/der_roundtrip_corpus/df9b696736847e43672b7a99ca05655af8a81135
  76. 1
      fuzz/der_roundtrip_corpus/e5b420f71cf412bd9fdebdd46245fabd1f3462e5
  77. BIN
      fuzz/der_roundtrip_corpus/e7979b0e6e3e9cd64ceab99778c55205d6f92a73
  78. BIN
      fuzz/der_roundtrip_corpus/ee629f1935abc05fdc32ba314ec1f80f4bff2a17
  79. BIN
      fuzz/der_roundtrip_corpus/f944dcd635f9801f7ac90a407fbc479964dec024
  80. BIN
      fuzz/der_roundtrip_corpus/fadcde7d914246ca04bd56e68fd4045b1cf1c5ef
  81. BIN
      fuzz/der_roundtrip_corpus/fd8be6506a9995f626eef831b9c981a80b0e3640

@ -30,3 +30,4 @@ fuzzer(dtls_client ssl)
fuzzer(ssl_ctx_api ssl)
fuzzer(session ssl)
fuzzer(decode_client_hello_inner ssl)
fuzzer(der_roundtrip)

@ -0,0 +1,57 @@
/* Copyright (c) 2022, Google Inc.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
#include <stdlib.h>
#include <string.h>
#include <openssl/bytestring.h>
#include <openssl/ecdsa.h>
#include <openssl/mem.h>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
CBS cbs, body;
unsigned tag;
CBS_init(&cbs, buf, len);
if (CBS_get_any_asn1(&cbs, &body, &tag)) {
// DER has a unique encoding, so any parsed input should round-trip
// correctly.
size_t consumed = len - CBS_len(&cbs);
bssl::ScopedCBB cbb;
CBB body_cbb;
if (!CBB_init(cbb.get(), consumed) ||
!CBB_add_asn1(cbb.get(), &body_cbb, tag) ||
!CBB_add_bytes(&body_cbb, CBS_data(&body), CBS_len(&body)) ||
!CBB_flush(cbb.get()) ||
CBB_len(cbb.get()) != consumed ||
memcmp(CBB_data(cbb.get()), buf, consumed) != 0) {
abort();
}
}
ECDSA_SIG *sig = ECDSA_SIG_from_bytes(buf, len);
if (sig != NULL) {
uint8_t *enc;
size_t enc_len;
if (!ECDSA_SIG_to_bytes(&enc, &enc_len, sig) ||
enc_len != len ||
memcmp(buf, enc, len) != 0) {
abort();
}
OPENSSL_free(enc);
ECDSA_SIG_free(sig);
}
return 0;
}

@ -0,0 +1 @@
0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>_
Loading…
Cancel
Save