Gets a validation result from the memory cache

@param certFingerprint
the certificate fingerprint for the certificate at the top of the
chain
@return the validation result, if found. <code>null</code> otherwise.
438990
protected ValidationResult getCachedResult(String certFingerprint) {

    CachedValidationResult cvr = validationResultsCache.get(certFingerprint);

    if (cvr == null)
      return null;

    if (!cachedValidationResultHasExpired(cvr, System.currentTimeMillis())) {
      return cvr.getResult();
    }

    validationResultsCache.remove(certFingerprint, cvr);
    return null;
  }
1253092
public static Certificate getCertificate(KeyStore keyStore, String alias) {
		return KeyUtil.getCertificate(keyStore, alias);
	}
68994
boolean validateCertificate(byte[] certPEM) {

        if (certPEM == null) {
            return false;
        }

        try {

            X509Certificate certificate = getX509Certificate(certPEM);
            if (null == certificate) {
                throw new Exception("Certificate transformation returned null");
            }

            return validateCertificate(certificate);
        } catch (Exception e) {
            logger.error("Cannot validate certificate. Error is: " + e.getMessage() + "\r\nCertificate (PEM, hex): "
                    + DatatypeConverter.printHexBinary(certPEM));
            return false;
        }
    }
543547
static int getFingerprint(Method method) {
    int hashcode = method.getName().hashCode();
    hashcode =  hashcode + 31*method.getReturnType().getName().hashCode();
    for (Class<?> type : method.getParameterTypes()) {
      hashcode = 31*hashcode ^ type.getName().hashCode();
    }
    return hashcode;
  }
643589
public void verify() throws GlobusCredentialException {
        try {
            String caCertsLocation = "file:" + CoGProperties.getDefault().getCaCertLocations();
            String crlPattern = caCertsLocation + "/*.r*";
            String sigPolPattern = caCertsLocation + "/*.signing_policy";
            KeyStore keyStore = KeyStore.getInstance(GlobusProvider.KEYSTORE_TYPE, GlobusProvider.PROVIDER_NAME);
            CertStore crlStore = CertStore.getInstance(GlobusProvider.CERTSTORE_TYPE, new ResourceCertStoreParameters(null,crlPattern));
            ResourceSigningPolicyStore sigPolStore = new ResourceSigningPolicyStore(new ResourceSigningPolicyStoreParameters(sigPolPattern));
            keyStore.load(KeyStoreParametersFactory.createTrustStoreParameters(caCertsLocation));
            X509ProxyCertPathParameters parameters = new X509ProxyCertPathParameters(keyStore, crlStore, sigPolStore, false);
            X509ProxyCertPathValidator validator = new X509ProxyCertPathValidator();
            validator.engineValidate(CertificateUtil.getCertPath(this.cred.getCertificateChain()), parameters);
        } catch (Exception e) {
        	e.printStackTrace();
            throw new GlobusCredentialException(GlobusCredentialException.FAILURE, e.getMessage(), e);
        }
    }
665093
public KeyStore getCaCertKeystore() {
        try {
            KeyStore returnKeyStore = KeyStore.getInstance(KeyStore.getDefaultType());
            returnKeyStore.load(null, null);
            Enumeration<String> e = CACertService.caCertKeystore.aliases();
            while(e.hasMoreElements()) {
                Certificate cert = CACertService.caCertKeystore.getCertificate(e.nextElement());
                returnKeyStore.setCertificateEntry(((X509Certificate) cert).getSubjectDN().toString(), cert);
            }
            return CACertService.caCertKeystore;
        } catch (KeyStoreException e) {
            return null;
        } catch (CertificateException e) {
            return null;
        } catch (NoSuchAlgorithmException e) {
            return null;
        } catch (IOException e) {
            return null;
        }
    }
1295806
public static String fingerprint(String str) {
		try {
			MessageDigest md = MessageDigest.getInstance("SHA-1");
			return byteArrayToHexString(md.digest(str.getBytes()));
		}
		catch (NoSuchAlgorithmException nsae) {
			LOGGER.warning("Unable to calculate the fingerprint for string [" + str + "].");
			return null;
		}
	}
1040374
@StaplerDispatchable
    public Object getFingerprint( String md5sum ) throws IOException {
        Fingerprint r = fingerprintMap.get(md5sum);
        if(r==null)     return new NoFingerprintMatch(md5sum);
        else            return r;
    }
700967
@Override
    public void check(Certificate cert, Collection<String> unresCritExts)
        throws CertPathValidatorException
    {
        X509Certificate currCert = (X509Certificate)cert;

        remainingCerts--;

        // if final certificate, check that target constraints are satisfied
        if (remainingCerts == 0) {
            if (targetConstraints != null &&
                targetConstraints.match(currCert) == false) {
                throw new CertPathValidatorException("target certificate " +
                    "constraints check failed");
            }
        } else {
            // otherwise, verify that keyCertSign bit is set in CA certificate
            verifyCAKeyUsage(currCert);
        }

        // remove the extensions that we have checked
        if (unresCritExts != null && !unresCritExts.isEmpty()) {
            unresCritExts.remove(KeyUsage_Id.toString());
            unresCritExts.remove(ExtendedKeyUsage_Id.toString());
            unresCritExts.remove(SubjectAlternativeName_Id.toString());
        }
    }
74621
@Override
	public Certificate engineGetCertificate(String s) {
		ResourceTrustAnchor trustAnchor = getCertificateEntry(s);
		if (trustAnchor != null) {
			try {
				return trustAnchor.getTrustAnchor().getTrustedCert();
			} catch (ResourceStoreException e) {
				return null;
			}
		}
		return null;
	}
1294158
public Set<OpenPgpV4Fingerprint> getTrustedFingerprints()
            throws IOException, PGPException {
        return getFingerprintsOfKeysWithState(getAnyPublicKeys(), OpenPgpTrustStore.Trust.trusted);
    }
1244391
private static int[] getFingerprints(Method[] methods) {
    if (methods == null) {
      return null;
    }
    int[] hashCodes = new int[methods.length];
    for (int i = 0; i<methods.length; i++) {
      hashCodes[i] = getFingerprint(methods[i]);
    }
    return hashCodes;
  }
1341285
public static String getFingerprint(byte[] encoded, String algorithm)
			throws SshException {

		Digest md5 = (Digest) ComponentManager.getInstance().supportedDigests()
				.getInstance(algorithm);

		md5.putBytes(encoded);

		byte[] digest = md5.doFinal();

		StringBuffer buf = new StringBuffer();
		int ch;
		for (int i = 0; i < digest.length; i++) {
			ch = digest[i] & 0xFF;
			if (i > 0) {
				buf.append(':');
			}
			buf.append(HEX[(ch >>> 4) & 0x0F]);
			buf.append(HEX[ch & 0x0F]);
		}

		return buf.toString();
	}
957904
public IOException checkCertificate() {
	SSLSocketFactory factory = context.getSocketFactory();

	try {
	    SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
	    socket.setSoTimeout(10000);
	    socket.startHandshake();
	    socket.close();
	    return null;
	}
	catch (IOException e) {
	    return e;
	}
    }
96488
private String getCertificateFingerPrint(String mdAlg) {
        String fingerPrint = "";
        try {
            byte[] encCertInfo = getEncoded();
            MessageDigest md = MessageDigest.getInstance(mdAlg);
            byte[] digest = md.digest(encCertInfo);
            StringBuffer buf = new StringBuffer();
            for (int i = 0; i < digest.length; i++) {
                byte2hex(digest[i], buf);
            }
            fingerPrint = buf.toString();
        } catch (NoSuchAlgorithmException | CertificateEncodingException e) {
            // ignored
        }
        return fingerPrint;
    }
1012520
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);
  }
}
942529
def assert_fingerprint(cert, fingerprint):
    

    # Maps the length of a digest to a possible hash function producing
    # this digest.
    hashfunc_map = {
        16: md5,
        20: sha1,
        32: sha256,
    }

    fingerprint = fingerprint.replace(':', '').lower()
    digest_length, odd = divmod(len(fingerprint), 2)

    if odd or digest_length not in hashfunc_map:
        raise SSLError('Fingerprint is of invalid length.')

    # We need encode() here for py32; works on py2 and p33.
    fingerprint_bytes = unhexlify(fingerprint.encode())

    hashfunc = hashfunc_map[digest_length]

    cert_digest = hashfunc(cert).digest()

    if not cert_digest == fingerprint_bytes:
        raise SSLError('Fingerprints did not match. Expected "{0}", got "{1}".'
                       .format(hexlify(fingerprint_bytes),
                               hexlify(cert_digest)))