use of com.intel.mtwilson.tag.dao.jdbi.CertificateDAO in project OpenAttestation by OpenAttestation.
the class CertificateRepository method retrieve.
@Override
public // @RequiresPermissions("tag_certificates:retrieve")
Certificate retrieve(CertificateLocator locator) {
log.debug("Retrieving Certificate");
if (locator == null || locator.id == null) {
return null;
}
log.debug("Certificate:Retrieve - Got request to retrieve user with id {}.", locator.id);
try (CertificateDAO dao = TagJdbi.certificateDao()) {
Certificate obj = dao.findById(locator.id);
if (obj != null)
return obj;
} catch (Exception ex) {
log.error("Certificate:Retrieve - Error during certificate retrieval.", ex);
throw new RepositoryRetrieveException(ex, locator);
}
return null;
}
use of com.intel.mtwilson.tag.dao.jdbi.CertificateDAO in project OpenAttestation by OpenAttestation.
the class CertificateRepository method create.
@Override
public // @RequiresPermissions("tag_certificates:create")
void create(Certificate item) {
log.debug("Certificate:Create - Got request to create a new Certificate {}.", item.getId().toString());
CertificateLocator locator = new CertificateLocator();
locator.id = item.getId();
try (CertificateDAO dao = TagJdbi.certificateDao()) {
Certificate newCert = dao.findById(item.getId());
if (newCert == null) {
newCert = Certificate.valueOf(item.getCertificate());
dao.insert(item.getId(), newCert.getCertificate(), newCert.getSha1().toHexString(), newCert.getSha256().toHexString(), newCert.getSubject(), newCert.getIssuer(), newCert.getNotBefore(), newCert.getNotAfter());
log.debug("Certificate:Create - Created the Certificate {} successfully.", item.getId().toString());
} else {
log.error("Certificate:Create - Certificate {} will not be created since a duplicate Certificate already exists.", item.getId().toString());
throw new RepositoryCreateConflictException(locator);
}
} catch (RepositoryException re) {
throw re;
} catch (Exception ex) {
log.error("Certificate:Create - Error during certificate creation.", ex);
throw new RepositoryCreateException(ex, locator);
}
//Store tag values from Certificate
try {
log.info("Tags from certificate will now be stored");
KvAttributeRepository repository = new KvAttributeRepository();
KvAttribute kvAttrib = new KvAttribute();
if (kvAttrib == null || repository == null)
log.debug("kvAttrib or repository Obj is null, unable to store certificate tags");
else {
List<Attribute> certAttributes = X509AttributeCertificate.valueOf(item.getCertificate()).getAttribute();
for (Attribute attr : certAttributes) {
for (ASN1Encodable value : attr.getAttributeValues()) {
if (attr.getAttrType().toString().equals(UTF8NameValueMicroformat.OID)) {
UTF8NameValueMicroformat microformat = new UTF8NameValueMicroformat(DERUTF8String.getInstance(value));
// Check if that tag with same value already exists
KvAttributeFilterCriteria criteria = new KvAttributeFilterCriteria();
criteria.nameEqualTo = microformat.getName();
criteria.valueEqualTo = microformat.getValue();
KvAttributeCollection results = repository.search(criteria);
if (results.getDocuments().isEmpty()) {
kvAttrib.setId(new UUID());
kvAttrib.setName(microformat.getName());
kvAttrib.setValue(microformat.getValue());
repository.create(kvAttrib);
} else
log.debug("Tag with Name:{} & Value:{} is already stored.", microformat.getName(), microformat.getValue());
}
}
}
}
} catch (Exception e) {
log.error("Certificate:Create - Error during attribute scan", e);
}
}
use of com.intel.mtwilson.tag.dao.jdbi.CertificateDAO in project OpenAttestation by OpenAttestation.
the class MtWilsonImportTagCertificate method run.
@Override
@RequiresPermissions("tag_certificates:import")
public void run() {
log.debug("RPC:MtWilsonImportTagCertificate - Got request to deploy certificate with ID {}.", certificateId);
CertificateLocator locator = new CertificateLocator();
locator.id = certificateId;
try (CertificateDAO dao = TagJdbi.certificateDao()) {
Certificate obj = dao.findById(certificateId);
if (obj != null) {
log.debug("RPC:MtWilsonImportTagCertificate - Sha1 of the certificate about to be deployed is {}.", obj.getSha1());
AssetTagCertCreateRequest request = new AssetTagCertCreateRequest();
request.setCertificate(obj.getCertificate());
Global.mtwilson().importAssetTagCertificate(request);
log.info("RPC:MtWilsonImportTagCertificate - Certificate with id {} has been deployed successfully.");
} else {
log.error("RPC:MtWilsonImportTagCertificate - Specified Certificate with id {} is not valid.", certificateId);
throw new RepositoryInvalidInputException(locator);
}
} catch (RepositoryException re) {
throw re;
} catch (Exception ex) {
log.error("RPC:MtWilsonImportTagCertificate - Error during certificate deployment.", ex);
throw new RepositoryException(ex);
}
}
use of com.intel.mtwilson.tag.dao.jdbi.CertificateDAO in project OpenAttestation by OpenAttestation.
the class RevokeTagCertificate method revokeCert.
@POST
public //@RequiresPermissions("tag_certificates:delete")
void revokeCert(@QueryParam("certId") String certId) {
log.debug("RPC: RevokeTagCertificate - Got request to revocation of certificate: {}", certId);
setCertificateId(UUID.valueOf(certId));
try (CertificateDAO dao = TagJdbi.certificateDao()) {
CertificateLocator locator = new CertificateLocator();
locator.id = certificateId;
Certificate obj = dao.findById(certificateId);
if (obj != null) {
// tries jvm properties, environment variables, then mtwilson.properties; you can set location of mtwilson.properties with -Dmtwilson.home=/path/to/dir
org.apache.commons.configuration.Configuration conf = ConfigurationUtil.getConfiguration();
ApiClient mtwilson = new ApiClient(conf);
log.debug("RPC: RevokeTagCertificate - Sha1 of the certificate about to be revoked is {}.", obj.getSha1());
dao.updateRevoked(certificateId, true);
AssetTagCertRevokeRequest request = new AssetTagCertRevokeRequest();
request.setSha1OfAssetCert(obj.getSha1().toByteArray());
mtwilson.revokeAssetTagCertificate(request);
//Global.mtwilson().revokeAssetTagCertificate(request);
log.info("RPC: RevokeTagCertificate - Certificate with id {} has been revoked successfully.");
} else {
log.error("RPC: RevokeTagCertificate - Certificate with id {} does not exist.", certificateId);
throw new RepositoryInvalidInputException(locator);
}
} catch (RepositoryException re) {
throw re;
} catch (Exception ex) {
log.error("RPC: RevokeTagCertificate - Error during certificate revocation.", ex);
throw new RepositoryException(ex);
}
}
use of com.intel.mtwilson.tag.dao.jdbi.CertificateDAO in project OpenAttestation by OpenAttestation.
the class CertificateRepository method store.
@Override
public // @RequiresPermissions("tag_certificates:store")
void store(Certificate item) {
log.debug("Certificate:Store - Got request to update Certificate with id {}.", item.getId().toString());
// will be used if we need to throw an exception
CertificateLocator locator = new CertificateLocator();
locator.id = item.getId();
try (CertificateDAO dao = TagJdbi.certificateDao()) {
Certificate obj = dao.findById(item.getId());
// Allowing the user to only edit the revoked field.
if (obj != null) {
dao.updateRevoked(item.getId(), item.isRevoked());
log.debug("Certificate:Store - Updated the Certificate {} successfully.", item.getId().toString());
} else {
log.error("Certificate:Store - Certificate will not be updated since it does not exist.");
throw new RepositoryStoreConflictException(locator);
}
} catch (RepositoryException re) {
throw re;
} catch (Exception ex) {
log.error("Certificate:Store - Error during Certificate update.", ex);
throw new RepositoryStoreException(ex, locator);
}
}
Aggregations