Search in sources :

Example 16 with CertificateInfo

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;
}
Also used : KeyInfo(ee.ria.xroad.signer.protocol.dto.KeyInfo) ArrayList(java.util.ArrayList) CertificateInfo(ee.ria.xroad.signer.protocol.dto.CertificateInfo) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) CertRequestInfo(ee.ria.xroad.signer.protocol.dto.CertRequestInfo)

Example 17 with CertificateInfo

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());
    }
}
Also used : CertificateInfoBuilder(org.niis.xroad.securityserver.restapi.util.CertificateTestUtils.CertificateInfoBuilder) CertificateTestUtils(org.niis.xroad.securityserver.restapi.util.CertificateTestUtils) CertificateInfo(ee.ria.xroad.signer.protocol.dto.CertificateInfo) BadRequestException(org.niis.xroad.restapi.openapi.BadRequestException) X509Certificate(java.security.cert.X509Certificate) ErrorDeviation(org.niis.xroad.restapi.exceptions.ErrorDeviation) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 18 with CertificateInfo

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());
}
Also used : PossibleAction(org.niis.xroad.securityserver.restapi.openapi.model.PossibleAction) KeyInfo(ee.ria.xroad.signer.protocol.dto.KeyInfo) CertificateTestUtils(org.niis.xroad.securityserver.restapi.util.CertificateTestUtils) CertificateInfo(ee.ria.xroad.signer.protocol.dto.CertificateInfo) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) TokenCertificate(org.niis.xroad.securityserver.restapi.openapi.model.TokenCertificate) Test(org.junit.Test)

Example 19 with CertificateInfo

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");
}
Also used : KeyInfo(ee.ria.xroad.signer.protocol.dto.KeyInfo) CertificateInfo(ee.ria.xroad.signer.protocol.dto.CertificateInfo) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo)

Example 20 with CertificateInfo

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);
}
Also used : TokenInfoAndKeyId(ee.ria.xroad.signer.protocol.dto.TokenInfoAndKeyId) KeyInfo(ee.ria.xroad.signer.protocol.dto.KeyInfo) CertificateInfo(ee.ria.xroad.signer.protocol.dto.CertificateInfo) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo)

Aggregations

CertificateInfo (ee.ria.xroad.signer.protocol.dto.CertificateInfo)39 KeyInfo (ee.ria.xroad.signer.protocol.dto.KeyInfo)16 Test (org.junit.Test)12 TokenInfo (ee.ria.xroad.signer.protocol.dto.TokenInfo)11 TokenCertificate (org.niis.xroad.securityserver.restapi.openapi.model.TokenCertificate)9 X509Certificate (java.security.cert.X509Certificate)8 CertificateTestUtils (org.niis.xroad.securityserver.restapi.util.CertificateTestUtils)8 ClientId (ee.ria.xroad.common.identifier.ClientId)7 CodedException (ee.ria.xroad.common.CodedException)6 SignerNotReachableException (org.niis.xroad.restapi.service.SignerNotReachableException)5 CertRequestInfo (ee.ria.xroad.signer.protocol.dto.CertRequestInfo)4 KeyUsageInfo (ee.ria.xroad.signer.protocol.dto.KeyUsageInfo)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 HashSet (java.util.HashSet)4 RevokedStatus (org.bouncycastle.cert.ocsp.RevokedStatus)4 DeviationAwareRuntimeException (org.niis.xroad.restapi.exceptions.DeviationAwareRuntimeException)4 ServiceException (org.niis.xroad.restapi.service.ServiceException)4 InternalServerErrorException (org.niis.xroad.securityserver.restapi.openapi.InternalServerErrorException)4 TokenTestUtils (org.niis.xroad.securityserver.restapi.util.TokenTestUtils)4