code: function validateCertChain(cert, cb)
  {
    // walk up the certificate chain and collect all the certificates in an array
    var certs = [];
    while (cert && cert.issuerCertificate &&
    (cert.fingerprint !== cert.issuerCertificate.fingerprint))
    {
      certs.push(cert);
      cert = cert.issuerCertificate;
    }
  
    // create an array to store any errors encountered
    // while validating the certificate chain
    var errors = new Array(certs.length);
  
    /**
     * Called for every certificate as we traverse the certificate chain and
     * validate each one.
     *
     * @param certs
     * @param index
     */
    var eachCallback = function(certs, index)
    {
      var cert = certs[index];
      validateCert(cert, function(err, data)
      {
        completed++;
        errors[index] = err;
  
        // if we have an ocsp response, cache it
        if (data)
        {
          getOcspResponseCache().set(cert, data);
        }
  
        // if this is the last request to complete
        if (completed === certs.length)
        {
          // if we saw one or more errors, invoke the callback with the first
          // error we saw; otherwise invoke the callback without any error
          for (var errorIndex = 0, length = errors.length;
               errorIndex < length; errorIndex++)
          {
            var error = errors[errorIndex];
            if (error)
            {
              break;
            }
          }
          cb(error);
        }
      });
    };
  
    // fire off requests to validate all the certificates in the chain
    var completed = 0;
    for (var index = 0, length = certs.length; index < length; index++)
    {
      eachCallback(certs, index);
    }
  }
docs: Validates a certificate chain using OCSP.
  
  @param {Object} cert a top-level cert that represents the leaf of a
  certificate chain.
  @param {Function} cb the callback to invoke once the validation is complete.