Search in sources :

Example 6 with Sha1Digest

use of com.intel.mtwilson.util.crypto.Sha1Digest in project OpenAttestation by OpenAttestation.

the class KeystoreCertificateRepository method isCertificateInKeystore.

protected boolean isCertificateInKeystore(Sha1Digest test) {
    try {
        // throws KeyStoreException
        List<String> aliases = Collections.list(keystore.aliases());
        for (String alias : aliases) {
            log.debug("Keystore entry alias: {}", alias);
            // throws KeyManagementException
            X509Certificate cert = getCertificate(alias);
            if (cert != null) {
                Sha1Digest known = Sha1Digest.digestOf(cert.getEncoded());
                if (Arrays.equals(test.toByteArray(), known.toByteArray())) {
                    return true;
                }
            }
        }
        return false;
    } catch (KeyStoreException | KeyManagementException | CertificateEncodingException e) {
        log.debug("Cannot check if certificate is in keystore", e);
        return false;
    }
}
Also used : Sha1Digest(com.intel.mtwilson.util.crypto.Sha1Digest) CertificateEncodingException(java.security.cert.CertificateEncodingException) KeyStoreException(java.security.KeyStoreException) X509Certificate(java.security.cert.X509Certificate) KeyManagementException(java.security.KeyManagementException)

Example 7 with Sha1Digest

use of com.intel.mtwilson.util.crypto.Sha1Digest in project OpenAttestation by OpenAttestation.

the class KeystoreCertificateRepository method addCertificate.

/**
     *
     * @param certificate
     * @throws KeyManagementException
     */
@Override
public void addCertificate(X509Certificate certificate) throws KeyManagementException {
    try {
        Sha1Digest fingerprint = Sha1Digest.digestOf(certificate.getEncoded());
        if (isCertificateInKeystore(fingerprint)) {
            log.debug("Certificate {} is already in keystore", fingerprint.toHexString());
            return;
        }
        String alias = fingerprint.toHexString();
        log.debug("Adding certificate to repository: {}", alias);
        keystore.setCertificateEntry(alias, certificate);
        // save the keystore!
        save();
    } catch (KeyStoreException | IOException | NoSuchAlgorithmException | CertificateException e) {
        throw new KeyManagementException("Cannot add certificate", e);
    }
}
Also used : Sha1Digest(com.intel.mtwilson.util.crypto.Sha1Digest) CertificateException(java.security.cert.CertificateException) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyManagementException(java.security.KeyManagementException)

Example 8 with Sha1Digest

use of com.intel.mtwilson.util.crypto.Sha1Digest in project OpenAttestation by OpenAttestation.

the class TAHelper method convertHostTpmEventLogEntryToMeasurement.

/**
     * Helper method to create the Measurement Object.
     *
     * @param extendedToPcr
     * @param moduleName
     * @param moduleHash
     * @return
     */
private static Measurement convertHostTpmEventLogEntryToMeasurement(int extendedToPcr, String moduleName, String moduleHash, boolean useHostSpecificDigest) {
    HashMap<String, String> info = new HashMap<String, String>();
    // For OpenSource since we do not have any events associated, we are creating a dummy one.
    info.put("EventName", "OpenSource.EventName");
    // Removing the prefix of "OpenSource" as it is being captured in the event type
    info.put("ComponentName", moduleName);
    info.put("PackageName", "");
    info.put("PackageVendor", "");
    info.put("PackageVersion", "");
    info.put("ExtendedToPCR", String.valueOf(extendedToPcr));
    if (useHostSpecificDigest) {
        info.put("UseHostSpecificDigest", "true");
    } else {
        info.put("UseHostSpecificDigest", "false");
    }
    return new Measurement(new Sha1Digest(moduleHash), moduleName, info);
}
Also used : Measurement(com.intel.mtwilson.util.model.Measurement) HashMap(java.util.HashMap) Sha1Digest(com.intel.mtwilson.util.crypto.Sha1Digest)

Aggregations

Sha1Digest (com.intel.mtwilson.util.crypto.Sha1Digest)8 KeyManagementException (java.security.KeyManagementException)4 MwAssetTagCertificate (com.intel.mtwilson.as.data.MwAssetTagCertificate)3 IOException (java.io.IOException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 CertificateException (java.security.cert.CertificateException)3 ASException (com.intel.mountwilson.as.common.ASException)2 ApiException (com.intel.mtwilson.ApiException)2 MwAssetTagCertificateJpaController (com.intel.mtwilson.as.controller.MwAssetTagCertificateJpaController)2 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)2 KeyStoreException (java.security.KeyStoreException)2 SignatureException (java.security.SignatureException)2 AssetTagCertAssociateRequest (com.intel.mtwilson.datatypes.AssetTagCertAssociateRequest)1 Certificate (com.intel.mtwilson.datatypes.Certificate)1 X509AttributeCertificate (com.intel.mtwilson.datatypes.X509AttributeCertificate)1 Sha256Digest (com.intel.mtwilson.util.crypto.Sha256Digest)1 ByteArray (com.intel.mtwilson.util.io.ByteArray)1 UUID (com.intel.mtwilson.util.io.UUID)1 Measurement (com.intel.mtwilson.util.model.Measurement)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1