use of ee.ria.xroad.signer.protocol.dto.CertificateInfo in project X-Road by nordic-institute.
the class ClientsApiControllerIntegrationTest method createMockTokenInfos.
/**
* @param certificateInfo one certificate to put inside this tokenInfo
* structure
* @return
*/
private List<TokenInfo> createMockTokenInfos(CertificateInfo certificateInfo) {
List<TokenInfo> mockTokens = new ArrayList<>();
List<CertificateInfo> certificates = new ArrayList<>();
if (certificateInfo != null) {
certificates.add(certificateInfo);
}
KeyInfo keyInfo = new KeyInfo(false, null, "friendlyName", "id", "label", "publicKey", certificates, new ArrayList<CertRequestInfo>(), "signMecchanismName");
TokenInfo tokenInfo = new TokenInfo("type", "friendlyName", "id", false, false, false, "serialNumber", "label", -1, null, Arrays.asList(keyInfo), null);
mockTokens.add(tokenInfo);
return mockTokens;
}
use of ee.ria.xroad.signer.protocol.dto.CertificateInfo in project X-Road by nordic-institute.
the class TokenCertificatesApiControllerIntegrationTest method importAuthCertificateFromToken.
@Test
@WithMockUser(authorities = "IMPORT_AUTH_CERT")
public void importAuthCertificateFromToken() throws Exception {
X509Certificate mockAuthCert = getMockAuthCertificate();
CertificateInfo certificateInfo = new CertificateTestUtils.CertificateInfoBuilder().certificate(mockAuthCert).certificateStatus(CertificateInfo.STATUS_SAVED).build();
doAnswer(answer -> certificateInfo).when(signerProxyFacade).getCertForHash(any());
try {
tokenCertificatesApiController.importCertificateFromToken(MOCK_AUTH_CERTIFICATE_HASH);
} catch (BadRequestException e) {
ErrorDeviation error = e.getErrorDeviation();
Assert.assertEquals(DeviationCodes.ERROR_AUTH_CERT_NOT_SUPPORTED, error.getCode());
}
}
use of ee.ria.xroad.signer.protocol.dto.CertificateInfo in project X-Road by nordic-institute.
the class TokenCertificateConverterTest method convertWithPossibleActions.
@Test
public void convertWithPossibleActions() throws Exception {
CertificateInfo certificateInfo = new CertificateTestUtils.CertificateInfoBuilder().build();
KeyInfo keyInfo = new TokenTestUtils.KeyInfoBuilder().cert(certificateInfo).build();
TokenInfo tokenInfo = new TokenTestUtils.TokenInfoBuilder().key(keyInfo).build();
TokenCertificate certificate = tokenCertificateConverter.convert(certificateInfo, keyInfo, tokenInfo);
Collection<PossibleAction> actions = certificate.getPossibleActions();
assertTrue(actions.contains(PossibleAction.ACTIVATE));
assertEquals(1, actions.size());
}
use of ee.ria.xroad.signer.protocol.dto.CertificateInfo in project X-Road by nordic-institute.
the class TokenCertificateService method deleteCertificate.
private void deleteCertificate(String certificateId, List<TokenInfo> allTokens) throws CertificateNotFoundException, ActionNotPossibleException {
// find token, key, and certificate info
for (TokenInfo tokenInfo : allTokens) {
for (KeyInfo keyInfo : tokenInfo.getKeyInfo()) {
for (CertificateInfo certificateInfo : keyInfo.getCerts()) {
if (certificateInfo.getId().equals(certificateId)) {
auditDataHelper.addCertificateHash(certificateInfo);
deleteCertificate(certificateInfo, keyInfo, tokenInfo);
return;
}
}
}
}
throw new CertificateNotFoundException("did not find certificate with id " + certificateId + " in tokens");
}
use of ee.ria.xroad.signer.protocol.dto.CertificateInfo in project X-Road by nordic-institute.
the class TokenCertificateService method deleteCertificate.
/**
* Delete certificate with given hash
* @param hash
* @throws CertificateNotFoundException if certificate with given hash was not found
* @throws KeyNotFoundException if for some reason the key linked to the cert could not
* be loaded (should not be possible)
* @throws ActionNotPossibleException if delete was not possible due to cert/key/token states
*/
public void deleteCertificate(String hash) throws CertificateNotFoundException, KeyNotFoundException, ActionNotPossibleException {
hash = hash.toLowerCase();
CertificateInfo certificateInfo = getCertificateInfo(hash);
if (certificateInfo.isSavedToConfiguration()) {
auditEventHelper.changeRequestScopedEvent(RestApiAuditEvent.DELETE_CERT_FROM_CONFIG);
} else {
auditEventHelper.changeRequestScopedEvent(RestApiAuditEvent.DELETE_CERT_FROM_TOKEN);
}
TokenInfoAndKeyId tokenInfoAndKeyId = tokenService.getTokenAndKeyIdForCertificateHash(hash);
TokenInfo tokenInfo = tokenInfoAndKeyId.getTokenInfo();
KeyInfo keyInfo = tokenInfoAndKeyId.getKeyInfo();
auditDataHelper.put(tokenInfo);
auditDataHelper.put(keyInfo);
auditDataHelper.put(certificateInfo);
deleteCertificate(certificateInfo, keyInfo, tokenInfo);
}
Aggregations