function downloadAndParseChromeCerts(filename, certSKDToName) {
  // Prefixes that we care about.
  const BEGIN_CERT = "-----BEGIN CERTIFICATE-----";
  const END_CERT = "-----END CERTIFICATE-----";

  // Parsing states.
  const PRE_NAME = 0;
  const POST_NAME = 1;
  const IN_CERT = 2;
  let state = PRE_NAME;

  let lines = download(filename).split("\n");
  let name = "";
  let pemCert = "";
  let hash = "";
  let chromeNameToHash = {};
  let chromeNameToMozName = {}
  for (let i = 0; i < lines.length; ++i) {
    let line = lines[i];
    // Skip comments and newlines.
    if (line.length == 0 || line[0] == '#') {
      continue;
    }
    switch(state) {
      case PRE_NAME:
        chromeName = line;
        state = POST_NAME;
        break;
      case POST_NAME:
        if (line.startsWith(SHA1_PREFIX) ||
            line.startsWith(SHA256_PREFIX)) {
          if (line.startsWith(SHA1_PREFIX)) {
            hash = line.substring(SHA1_PREFIX.length);
          } else if (line.startsWith(SHA256_PREFIX)) {
            hash = line.substring(SHA256_PREFIX);
          }
          // Store the entire prefixed hash, so we can disambiguate sha1 from
          // sha256 later.
          chromeNameToHash[chromeName] = line;
          certNameToSKD[chromeName] = hash;
          certSKDToName[hash] = chromeName;
          state = PRE_NAME;
        } else if (line.startsWith(BEGIN_CERT)) {
          state = IN_CERT;
        } else {
          throw "ERROR: couldn't parse Chrome certificate file " + line;
        }
        break;
      case IN_CERT:
        if (line.startsWith(END_CERT)) {
          state = PRE_NAME;
          hash = getSKDFromPem(pemCert);
          pemCert = "";
          if (hash in certSKDToName) {
            mozName = certSKDToName[hash];
          } else {
            // Not one of our built-in certs. Prefix the name with
            // GOOGLE_PIN_.
            mozName = GOOGLE_PIN_PREFIX + chromeName;
            dump("Can't find hash in builtin certs for Chrome nickname " +
                 chromeName + ", inserting " + mozName + "\n");
            certSKDToName[hash] = mozName;
            certNameToSKD[mozName] = hash;
          }
          chromeNameToMozName[chromeName] = mozName;
        } else {
          pemCert += line;
        }
        break;
      default:
        throw "ERROR: couldn't parse Chrome certificate file " + line;
    }
  }
  return [ chromeNameToHash, chromeNameToMozName ];
}
// otherwise we skip all pinsets referring to that Chrome name.
otherwise we skip all pinsets referring to that Chrome name.
otherwise we skip all pinsets referring to that Chrome name .
function downloadAndParseChromeCerts(filename, certSKDToName) {
  const BEGIN_CERT = "-----BEGIN CERTIFICATE-----";
  const END_CERT = "-----END CERTIFICATE-----";
  const PRE_NAME = 0;
  const POST_NAME = 1;
  const IN_CERT = 2;
  let state = PRE_NAME;
  let lines = download(filename).split("\n");
  let name = "";
  let pemCert = "";
  let hash = "";
  let chromeNameToHash = {};
  let chromeNameToMozName = {}
  for (let i = 0; i < lines.length; ++i) {
    let line = lines[i];
    if (line.length == 0 || line[0] == '#') {
      continue;
    }
    switch(state) {
      case PRE_NAME:
        chromeName = line;
        state = POST_NAME;
        break;
      case POST_NAME:
        if (line.startsWith(SHA1_PREFIX) ||
            line.startsWith(SHA256_PREFIX)) {
          if (line.startsWith(SHA1_PREFIX)) {
            hash = line.substring(SHA1_PREFIX.length);
          } else if (line.startsWith(SHA256_PREFIX)) {
            hash = line.substring(SHA256_PREFIX);
          }
          chromeNameToHash[chromeName] = line;
          certNameToSKD[chromeName] = hash;
          certSKDToName[hash] = chromeName;
          state = PRE_NAME;
        } else if (line.startsWith(BEGIN_CERT)) {
          state = IN_CERT;
        } else {
          throw "ERROR: couldn't parse Chrome certificate file " + line;
        }
        break;
      case IN_CERT:
        if (line.startsWith(END_CERT)) {
          state = PRE_NAME;
          hash = getSKDFromPem(pemCert);
          pemCert = "";
          if (hash in certSKDToName) {
            mozName = certSKDToName[hash];
          } else {
            mozName = GOOGLE_PIN_PREFIX + chromeName;
            dump("Can't find hash in builtin certs for Chrome nickname " +
                 chromeName + ", inserting " + mozName + "\n");
            certSKDToName[hash] = mozName;
            certNameToSKD[mozName] = hash;
          }
          chromeNameToMozName[chromeName] = mozName;
        } else {
          pemCert += line;
        }
        break;
      default:
        throw "ERROR: couldn't parse Chrome certificate file " + line;
    }
  }
  return [ chromeNameToHash, chromeNameToMozName ];
}
function downloadAndParseChromeCerts ( filename , certSKDToName ) { const BEGIN_CERT = "-----BEGIN CERTIFICATE-----" ; const END_CERT = "-----END CERTIFICATE-----" ; const PRE_NAME = 0 ; const POST_NAME = 1 ; const IN_CERT = 2 ; let state = PRE_NAME ; let lines = download ( filename ) . split ( "\n" ) ; let name = "" ; let pemCert = "" ; let hash = "" ; let chromeNameToHash = { } ; let chromeNameToMozName = { } for ( let i = 0 ; i < lines . length ; ++ i ) { let line = lines [ i ] ; if ( line . length == 0 || line [ 0 ] == '#' ) { continue ; } switch ( state ) { case PRE_NAME : chromeName = line ; state = POST_NAME ; break ; case POST_NAME : if ( line . startsWith ( SHA1_PREFIX ) || line . startsWith ( SHA256_PREFIX ) ) { if ( line . startsWith ( SHA1_PREFIX ) ) { hash = line . substring ( SHA1_PREFIX . length ) ; } else if ( line . startsWith ( SHA256_PREFIX ) ) { hash = line . substring ( SHA256_PREFIX ) ; } chromeNameToHash [ chromeName ] = line ; certNameToSKD [ chromeName ] = hash ; certSKDToName [ hash ] = chromeName ; state = PRE_NAME ; } else if ( line . startsWith ( BEGIN_CERT ) ) { state = IN_CERT ; } else { throw "ERROR: couldn't parse Chrome certificate file " + line ; } break ; case IN_CERT : if ( line . startsWith ( END_CERT ) ) { state = PRE_NAME ; hash = getSKDFromPem ( pemCert ) ; pemCert = "" ; if ( hash in certSKDToName ) { mozName = certSKDToName [ hash ] ; } else { mozName = GOOGLE_PIN_PREFIX + chromeName ; dump ( "Can't find hash in builtin certs for Chrome nickname " + chromeName + ", inserting " + mozName + "\n" ) ; certSKDToName [ hash ] = mozName ; certNameToSKD [ mozName ] = hash ; } chromeNameToMozName [ chromeName ] = mozName ; } else { pemCert += line ; } break ; default : throw "ERROR: couldn't parse Chrome certificate file " + line ; } } return [ chromeNameToHash , chromeNameToMozName ] ; }
otherwise we skip all pinsets referring to that Chrome name.
otherwise we skip all pinsets referring to that Chrome name .
// Prefixes that we care about. // Parsing states. // Skip comments and newlines. // Store the entire prefixed hash, so we can disambiguate sha1 from // sha256 later. // Not one of our built-in certs. Prefix the name with // GOOGLE_PIN_.