use of com.intel.mtwilson.tag.dao.jdbi.FileDAO in project OpenAttestation by OpenAttestation.
the class AssetTagCertBO method validateAssetTagCert.
/**
* Validates the asset tag certificate and returns back true/false accordingly.
*
* @param atagObj
* @return
*/
private boolean validateAssetTagCert(MwAssetTagCertificate atagObj) {
boolean isValid = false;
try {
// First let us verify if the revoked flag is set
if (atagObj.getRevoked() == true)
return false;
// X509AttributeCertificate provides a helper function that validates both the dates and the signature.
// For that we need to first get the CA certificate that signed the Attribute Certificate. We need to
// extract this from the PEM file list and pass it to the helper function
X509AttributeCertificate atagAttrCertForHost = X509AttributeCertificate.valueOf(atagObj.getCertificate());
List<X509Certificate> atagCaCerts = null;
////////////////
FileDAO fileDao;
try {
fileDao = TagJdbi.fileDao();
File cacertFile = fileDao.findByName("cacerts");
if (cacertFile == null) {
log.error("Error loading the cacert pem file to extract the CA certificate(s).");
} else {
atagCaCerts = X509Util.decodePemCertificates(new String(cacertFile.getContent(), "UTF-8"));
//IOUtils.closeQuietly(atagCaIn);
log.debug("Added {} certificates from AssetTagCA.pem", atagCaCerts.size());
// cacerts = X509Util.decodePemCertificates(new String(cacertFile.getContent(), "UTF-8"));
}
} catch (Exception e) {
log.error("Cannot load cacerts", e);
atagCaCerts = null;
}
// The below isValid function verifies both the signature and the dates.
if (atagCaCerts != null) {
for (X509Certificate atagCACert : atagCaCerts) {
if (atagAttrCertForHost.isValid(atagCACert))
return true;
}
}
} catch (Exception ex) {
throw new ASException(ex);
}
return isValid;
}
Aggregations