Search in sources :

Example 6 with CertificateInfo

use of ee.ria.xroad.signer.protocol.dto.CertificateInfo in project X-Road by nordic-institute.

the class TokenCertificateService method importCertificateFromToken.

/**
 * Find an existing cert from a token (e.g. HSM) by cert hash and import it to keyconf.xml. This enables the cert
 * to be used for signing messages.
 * @param hash cert hash of an existing cert
 * @return CertificateType
 * @throws CertificateNotFoundException
 * @throws InvalidCertificateException other general import failure
 * @throws GlobalConfOutdatedException
 * @throws KeyNotFoundException
 * @throws CertificateAlreadyExistsException
 * @throws WrongCertificateUsageException
 * @throws ClientNotFoundException
 * @throws CsrNotFoundException
 * @throws AuthCertificateNotSupportedException if trying to import an auth cert from a token
 * @throws ActionNotPossibleException if import was not possible due to cert/key/token states
 */
public CertificateInfo importCertificateFromToken(String hash) throws CertificateNotFoundException, InvalidCertificateException, GlobalConfOutdatedException, KeyNotFoundException, CertificateAlreadyExistsException, WrongCertificateUsageException, ClientNotFoundException, CsrNotFoundException, AuthCertificateNotSupportedException, ActionNotPossibleException {
    CertificateInfo certificateInfo = getCertificateInfo(hash);
    TokenInfoAndKeyId tokenInfoAndKeyId = tokenService.getTokenAndKeyIdForCertificateHash(hash);
    TokenInfo tokenInfo = tokenInfoAndKeyId.getTokenInfo();
    KeyInfo keyInfo = tokenInfoAndKeyId.getKeyInfo();
    auditDataHelper.put(tokenInfo);
    auditDataHelper.put(keyInfo);
    auditDataHelper.put(RestApiAuditProperty.CERT_ID, certificateInfo.getId());
    EnumSet<PossibleActionEnum> possibleActions = getPossibleActionsForCertificateInternal(hash, certificateInfo, keyInfo, tokenInfo);
    possibleActionsRuleEngine.requirePossibleAction(PossibleActionEnum.IMPORT_FROM_TOKEN, possibleActions);
    return importCertificate(certificateInfo.getCertificateBytes(), true);
}
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)

Example 7 with CertificateInfo

use of ee.ria.xroad.signer.protocol.dto.CertificateInfo in project X-Road by nordic-institute.

the class TokenCertificateService method unregisterAuthCertAndMarkForDeletion.

/**
 * Send the authentication certificate deletion request to central server and set the cert status to
 * {@link CertificateInfo#STATUS_DELINPROG}
 * @param hash certificate hash
 * @param skipUnregister whether to skip the actual delete request and only change cert status
 * @throws SignCertificateNotSupportedException
 * @throws ActionNotPossibleException
 * @throws GlobalConfOutdatedException
 * @throws InvalidCertificateException
 * @throws KeyNotFoundException
 * @throws CertificateNotFoundException
 * @throws ManagementRequestSendingFailedException
 */
private void unregisterAuthCertAndMarkForDeletion(String hash, boolean skipUnregister) throws CertificateNotFoundException, GlobalConfOutdatedException, InvalidCertificateException, SignCertificateNotSupportedException, KeyNotFoundException, ActionNotPossibleException, ManagementRequestSendingFailedException {
    CertificateInfo certificateInfo = getCertificateInfo(hash);
    auditLogTokenKeyAndCert(hash, certificateInfo, false);
    verifyAuthCert(certificateInfo);
    verifyCertAction(PossibleActionEnum.UNREGISTER, certificateInfo, hash);
    if (!skipUnregister) {
        Integer requestId = managementRequestSenderService.sendAuthCertDeletionRequest(certificateInfo.getCertificateBytes());
        auditDataHelper.putManagementRequestId(requestId);
    }
    try {
        auditDataHelper.put(RestApiAuditProperty.CERT_STATUS, CertificateInfo.STATUS_DELINPROG);
        signerProxyFacade.setCertStatus(certificateInfo.getId(), CertificateInfo.STATUS_DELINPROG);
    } catch (Exception e) {
        // this means that cert was not found (which has been handled already) or some Akka error
        throw new SignerNotReachableException("Could not change auth cert status", e);
    }
}
Also used : CertificateInfo(ee.ria.xroad.signer.protocol.dto.CertificateInfo) InternalServerErrorException(org.niis.xroad.securityserver.restapi.openapi.InternalServerErrorException) SignerNotReachableException(org.niis.xroad.restapi.service.SignerNotReachableException) ServiceException(org.niis.xroad.restapi.service.ServiceException) DeviationAwareRuntimeException(org.niis.xroad.restapi.exceptions.DeviationAwareRuntimeException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) CodedException(ee.ria.xroad.common.CodedException) SignerNotReachableException(org.niis.xroad.restapi.service.SignerNotReachableException)

Example 8 with CertificateInfo

use of ee.ria.xroad.signer.protocol.dto.CertificateInfo in project X-Road by nordic-institute.

the class TokenCertificateService method registerAuthCert.

/**
 * Send the authentication certificate registration request to central server
 * @param hash certificate hash
 * @param securityServerAddress IP address or DNS name of the security server
 * @throws CertificateNotFoundException
 * @throws GlobalConfOutdatedException
 * @throws InvalidCertificateException
 * @throws SignCertificateNotSupportedException
 * @throws KeyNotFoundException
 * @throws ActionNotPossibleException
 */
public void registerAuthCert(String hash, String securityServerAddress) throws CertificateNotFoundException, GlobalConfOutdatedException, InvalidCertificateException, SignCertificateNotSupportedException, KeyNotFoundException, ActionNotPossibleException {
    CertificateInfo certificateInfo = getCertificateInfo(hash);
    auditLogTokenKeyAndCert(hash, certificateInfo, false);
    verifyAuthCert(certificateInfo);
    verifyCertAction(PossibleActionEnum.REGISTER, certificateInfo, hash);
    try {
        Integer requestId = managementRequestSenderService.sendAuthCertRegisterRequest(securityServerAddress, certificateInfo.getCertificateBytes());
        auditDataHelper.put(RestApiAuditProperty.ADDRESS, securityServerAddress);
        auditDataHelper.putManagementRequestId(requestId);
        auditDataHelper.put(RestApiAuditProperty.CERT_STATUS, CertificateInfo.STATUS_REGINPROG);
        signerProxyFacade.setCertStatus(certificateInfo.getId(), CertificateInfo.STATUS_REGINPROG);
    } catch (GlobalConfOutdatedException | CodedException e) {
        throw e;
    } catch (Exception e) {
        throw new SignerNotReachableException("Could not register auth cert", e);
    }
}
Also used : CodedException(ee.ria.xroad.common.CodedException) CertificateInfo(ee.ria.xroad.signer.protocol.dto.CertificateInfo) InternalServerErrorException(org.niis.xroad.securityserver.restapi.openapi.InternalServerErrorException) SignerNotReachableException(org.niis.xroad.restapi.service.SignerNotReachableException) ServiceException(org.niis.xroad.restapi.service.ServiceException) DeviationAwareRuntimeException(org.niis.xroad.restapi.exceptions.DeviationAwareRuntimeException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) CodedException(ee.ria.xroad.common.CodedException) SignerNotReachableException(org.niis.xroad.restapi.service.SignerNotReachableException)

Example 9 with CertificateInfo

use of ee.ria.xroad.signer.protocol.dto.CertificateInfo in project X-Road by nordic-institute.

the class KeyConverterTest method convert.

@Test
public void convert() throws Exception {
    List<CertificateInfo> certs = new ArrayList<>();
    certs.add(new CertificateTestUtils.CertificateInfoBuilder().build());
    List<CertRequestInfo> csrs = new ArrayList<>();
    csrs.add(new CertRequestInfo("id", ClientId.create("a", "b", "c"), "sujbect-name"));
    KeyInfo info = new KeyInfo(true, KeyUsageInfo.SIGNING, "friendly-name", "id", "label", "public-key", certs, csrs, "sign-mechanism-name");
    Key key = keyConverter.convert(info);
    assertEquals(true, key.getAvailable());
    assertNotNull(key.getCertificates());
    assertEquals(1, key.getCertificates().size());
    assertNotNull(key.getCertificateSigningRequests());
    assertEquals(1, key.getCertificateSigningRequests().size());
    assertEquals("id", key.getId());
    assertEquals("label", key.getLabel());
    assertEquals("friendly-name", key.getName());
    assertEquals(true, key.getSavedToConfiguration());
    assertEquals(KeyUsageType.SIGNING, key.getUsage());
}
Also used : KeyInfo(ee.ria.xroad.signer.protocol.dto.KeyInfo) ArrayList(java.util.ArrayList) CertificateInfo(ee.ria.xroad.signer.protocol.dto.CertificateInfo) Key(org.niis.xroad.securityserver.restapi.openapi.model.Key) CertRequestInfo(ee.ria.xroad.signer.protocol.dto.CertRequestInfo) Test(org.junit.Test)

Example 10 with CertificateInfo

use of ee.ria.xroad.signer.protocol.dto.CertificateInfo in project X-Road by nordic-institute.

the class CertificateInfoSensorTest method createTestKeyInfo.

private KeyInfo createTestKeyInfo(CertificateInfo caInfo) {
    KeyInfo keyInfo = new KeyInfo(true, null, "friendlyName", "id", "label", "publickey", new ArrayList<CertificateInfo>(), new ArrayList<CertRequestInfo>(), "mechanismName");
    keyInfo.getCerts().add(caInfo);
    return keyInfo;
}
Also used : KeyInfo(ee.ria.xroad.signer.protocol.dto.KeyInfo) CertificateInfo(ee.ria.xroad.signer.protocol.dto.CertificateInfo) CertRequestInfo(ee.ria.xroad.signer.protocol.dto.CertRequestInfo)

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