use of ee.ria.xroad.signer.protocol.dto.CertificateInfo in project X-Road by nordic-institute.
the class ClientServiceIntegrationTest method createSimpleSignCertList.
/**
* - FI:GOV:M1 has a sign cert "cert1" with ocsp status GOOD
* - FI:GOV:M1 has a sign cert "cert2" with ocsp status REVOKED
* - FI:GOV:M2 has a sign cert "cert3" with ocsp status UNKNOWN
*/
private List<CertificateInfo> createSimpleSignCertList() {
CertificateTestUtils.CertificateInfoBuilder certificateInfoBuilder = new CertificateTestUtils.CertificateInfoBuilder();
// Create cert with good ocsp response status
// This certificate is valid for all subsystems owned by the member "FI:GOV:M1".
ClientId clientId1 = ClientId.create("FI", "GOV", "M1");
certificateInfoBuilder.clientId(clientId1);
CertificateInfo cert1 = certificateInfoBuilder.build();
// Create cert with revoked ocsp response status
// N.B. This cert is ignored, and FI:GOV:M1 is considered to have valid sign cert since there's also a valid one
ClientId clientId2 = ClientId.create("FI", "GOV", "M1");
certificateInfoBuilder.clientId(clientId2).ocspStatus(new RevokedStatus(new Date(), CRLReason.certificateHold));
CertificateInfo cert2 = certificateInfoBuilder.build();
// Create cert with unknown ocsp response status
ClientId clientId3 = ClientId.create("FI", "GOV", "M2");
certificateInfoBuilder.clientId(clientId3).ocspStatus(new UnknownStatus());
CertificateInfo cert3 = certificateInfoBuilder.build();
return Arrays.asList(cert2, cert3, cert1);
}
use of ee.ria.xroad.signer.protocol.dto.CertificateInfo in project X-Road by nordic-institute.
the class HardwareTokenWorker method deleteCert.
@Override
protected void deleteCert(String certId) throws Exception {
log.trace("deleteCert({})", certId);
assertTokenWritable();
assertActiveSession();
KeyInfo keyInfo = TokenManager.getKeyInfoForCertId(certId);
if (keyInfo == null) {
throw certWithIdNotFound(certId);
}
if (!certs.containsKey(keyInfo.getId())) {
return;
}
for (CertificateInfo certInfo : keyInfo.getCerts()) {
if (certInfo.getId().equals(certId)) {
List<X509PublicKeyCertificate> certsOnModule = certs.get(keyInfo.getId());
for (X509PublicKeyCertificate cert : certsOnModule) {
if (Arrays.equals(certInfo.getCertificateBytes(), cert.getValue().getByteArrayValue())) {
destroyCert(cert);
certsOnModule.remove(cert);
TokenManager.removeCert(certId);
break;
}
}
return;
}
}
}
use of ee.ria.xroad.signer.protocol.dto.CertificateInfo in project X-Road by nordic-institute.
the class TokenCertificatesApiController method importCertificateFromToken.
@Override
@PreAuthorize("hasAnyAuthority('IMPORT_AUTH_CERT', 'IMPORT_SIGN_CERT', 'IMPORT_UNKNOWN_CERT')")
@AuditEventMethod(event = RestApiAuditEvent.IMPORT_CERT_TOKEN)
public ResponseEntity<TokenCertificate> importCertificateFromToken(String hash) {
CertificateInfo certificate = null;
try {
certificate = tokenCertificateService.importCertificateFromToken(hash);
} catch (ClientNotFoundException | KeyNotFoundException | TokenCertificateService.WrongCertificateUsageException | InvalidCertificateException | TokenCertificateService.AuthCertificateNotSupportedException e) {
throw new BadRequestException(e);
} catch (GlobalConfOutdatedException | CertificateAlreadyExistsException | CsrNotFoundException | ActionNotPossibleException e) {
throw new ConflictException(e);
} catch (CertificateNotFoundException e) {
throw new ResourceNotFoundException(e);
}
TokenCertificate tokenCertificate = tokenCertificateConverter.convert(certificate);
return ControllerUtil.createCreatedResponse("/api/token-certificates/{hash}", tokenCertificate, tokenCertificate.getCertificateDetails().getHash());
}
use of ee.ria.xroad.signer.protocol.dto.CertificateInfo in project X-Road by nordic-institute.
the class TokenCertificatesApiController method importCertificate.
@Override
@PreAuthorize("hasAnyAuthority('IMPORT_AUTH_CERT', 'IMPORT_SIGN_CERT')")
@AuditEventMethod(event = RestApiAuditEvent.IMPORT_CERT_FILE)
public ResponseEntity<TokenCertificate> importCertificate(Resource certificateResource) {
// there's no filename since we only get a binary application/octet-stream.
// Have audit log anyway (null behaves as no-op) in case different content type is added later
String filename = certificateResource.getFilename();
auditDataHelper.put(RestApiAuditProperty.CERT_FILE_NAME, filename);
byte[] certificateBytes = ResourceUtils.springResourceToBytesOrThrowBadRequest(certificateResource);
CertificateInfo certificate = null;
try {
certificate = tokenCertificateService.importCertificate(certificateBytes);
} catch (ClientNotFoundException | KeyNotFoundException | TokenCertificateService.WrongCertificateUsageException | InvalidCertificateException | TokenCertificateService.AuthCertificateNotSupportedException e) {
throw new BadRequestException(e);
} catch (GlobalConfOutdatedException | CertificateAlreadyExistsException | CsrNotFoundException e) {
throw new ConflictException(e);
}
TokenCertificate tokenCertificate = tokenCertificateConverter.convert(certificate);
return ControllerUtil.createCreatedResponse("/api/token-certificates/{hash}", tokenCertificate, tokenCertificate.getCertificateDetails().getHash());
}
Aggregations