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;
}
}
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);
}
}
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);
}
Aggregations