tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

certDN.cc (1481B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #include <cassert>
      6 #include <string>
      7 
      8 #include "cert.h"
      9 
     10 #define TEST_FUNCTION(f) \
     11  out = f(certName);     \
     12  free(out);
     13 
     14 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
     15  std::string name(data, data + size);
     16 
     17  assert(SECOID_Init() == SECSuccess);
     18 
     19  CERTName* certName = CERT_AsciiToName(name.c_str());
     20  if (certName) {
     21    char* out;
     22    TEST_FUNCTION(CERT_FormatName)
     23    TEST_FUNCTION(CERT_NameToAscii)
     24    TEST_FUNCTION(CERT_GetCertEmailAddress)
     25 
     26    // These functions call CERT_GetNameElement with different OIDs.
     27    // Unfotunately CERT_GetNameElement is not accesible from here.
     28    TEST_FUNCTION(CERT_GetCertUid)
     29    TEST_FUNCTION(CERT_GetCommonName)
     30    TEST_FUNCTION(CERT_GetCountryName)
     31    TEST_FUNCTION(CERT_GetDomainComponentName)
     32    TEST_FUNCTION(CERT_GetLocalityName)
     33    TEST_FUNCTION(CERT_GetOrgName)
     34    TEST_FUNCTION(CERT_GetOrgUnitName)
     35    TEST_FUNCTION(CERT_GetStateName)
     36 
     37    out = CERT_NameToAsciiInvertible(certName, CERT_N2A_READABLE);
     38    free(out);
     39    out = CERT_NameToAsciiInvertible(certName, CERT_N2A_STRICT);
     40    free(out);
     41    out = CERT_NameToAsciiInvertible(certName, CERT_N2A_INVERTIBLE);
     42    free(out);
     43 
     44    (void)CERT_CompareName(certName, certName);
     45  }
     46  CERT_DestroyName(certName);
     47 
     48  return 0;
     49 }