Search in sources :

Example 26 with TokenInfo

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

the class TokenService method updateTokenFriendlyName.

/**
 * update token friendly name
 *
 * @param tokenId
 * @param friendlyName
 * @throws TokenNotFoundException if token was not found
 */
public TokenInfo updateTokenFriendlyName(String tokenId, String friendlyName) throws TokenNotFoundException, ActionNotPossibleException {
    // check that updating friendly name is possible
    TokenInfo tokenInfo = getToken(tokenId);
    auditDataHelper.put(tokenInfo);
    // Override old value with the new
    auditDataHelper.put(RestApiAuditProperty.TOKEN_FRIENDLY_NAME, friendlyName);
    possibleActionsRuleEngine.requirePossibleTokenAction(PossibleActionEnum.EDIT_FRIENDLY_NAME, tokenInfo);
    try {
        signerProxyFacade.setTokenFriendlyName(tokenId, friendlyName);
        tokenInfo = signerProxyFacade.getToken(tokenId);
    } catch (CodedException e) {
        if (isCausedByTokenNotFound(e)) {
            throw new TokenNotFoundException(e);
        } else {
            throw e;
        }
    } catch (Exception other) {
        throw new SignerNotReachableException("update token friendly name failed", other);
    }
    return tokenInfo;
}
Also used : CodedException(ee.ria.xroad.common.CodedException) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) SignerNotReachableException(org.niis.xroad.restapi.service.SignerNotReachableException) CodedException(ee.ria.xroad.common.CodedException) ServiceException(org.niis.xroad.restapi.service.ServiceException) SignerNotReachableException(org.niis.xroad.restapi.service.SignerNotReachableException)

Example 27 with TokenInfo

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

the class TokenService method updateSoftwareTokenPin.

/**
 * Update the pin code for a token and it's keys
 *
 * @param tokenId ID of the token
 * @param oldPin the old (current) passing pin
 * @param newPin the new pin
 * @throws TokenNotFoundException token not found
 * @throws PinIncorrectException incorrect pin
 */
public void updateSoftwareTokenPin(String tokenId, String oldPin, String newPin) throws TokenNotFoundException, PinIncorrectException, ActionNotPossibleException, InvalidCharactersException, WeakPinException {
    TokenInfo tokenInfo = getToken(tokenId);
    auditDataHelper.put(tokenInfo);
    possibleActionsRuleEngine.requirePossibleTokenAction(PossibleActionEnum.TOKEN_CHANGE_PIN, tokenInfo);
    char[] newPinCharArray = newPin.toCharArray();
    tokenPinValidator.validateSoftwareTokenPin(newPinCharArray);
    try {
        signerProxyFacade.updateSoftwareTokenPin(tokenId, oldPin.toCharArray(), newPinCharArray);
    } catch (CodedException ce) {
        if (isCausedByTokenNotFound(ce)) {
            throw new TokenNotFoundException(ce);
        } else if (isCausedByIncorrectPin(ce)) {
            throw new PinIncorrectException(ce);
        } else {
            throw ce;
        }
    } catch (Exception other) {
        throw new SignerNotReachableException("updateSoftwareTokenPin failed", other);
    }
}
Also used : CodedException(ee.ria.xroad.common.CodedException) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) SignerNotReachableException(org.niis.xroad.restapi.service.SignerNotReachableException) CodedException(ee.ria.xroad.common.CodedException) ServiceException(org.niis.xroad.restapi.service.ServiceException) SignerNotReachableException(org.niis.xroad.restapi.service.SignerNotReachableException)

Example 28 with TokenInfo

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

the class TokenService method deactivateToken.

/**
 * Deactivate a token
 *
 * @param id id of token
 * @throws TokenNotFoundException if token was not found
 * @throws ActionNotPossibleException if deactivation was not possible
 */
public void deactivateToken(String id) throws TokenNotFoundException, ActionNotPossibleException {
    // check that action is possible
    TokenInfo tokenInfo = getToken(id);
    auditDataHelper.put(tokenInfo);
    possibleActionsRuleEngine.requirePossibleTokenAction(PossibleActionEnum.TOKEN_DEACTIVATE, tokenInfo);
    try {
        signerProxyFacade.deactivateToken(id);
    } catch (CodedException e) {
        if (isCausedByTokenNotFound(e)) {
            throw new TokenNotFoundException(e);
        } else {
            throw e;
        }
    } catch (Exception other) {
        throw new SignerNotReachableException("token deactivation failed", other);
    }
}
Also used : CodedException(ee.ria.xroad.common.CodedException) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) SignerNotReachableException(org.niis.xroad.restapi.service.SignerNotReachableException) CodedException(ee.ria.xroad.common.CodedException) ServiceException(org.niis.xroad.restapi.service.ServiceException) SignerNotReachableException(org.niis.xroad.restapi.service.SignerNotReachableException)

Example 29 with TokenInfo

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

the class TokenCertificatesApiControllerIntegrationTest method setup.

@Before
public void setup() throws Exception {
    doAnswer(answer -> "key-id").when(signerProxyFacade).importCert(any(), any(), any());
    doAnswer(answer -> null).when(globalConfFacade).verifyValidity();
    doAnswer(answer -> TestUtils.INSTANCE_FI).when(globalConfFacade).getInstanceIdentifier();
    doAnswer(answer -> TestUtils.getM1Ss1ClientId()).when(globalConfFacade).getSubjectName(any(), any());
    CertificateInfo signCertificateInfo = new CertificateInfoBuilder().certificate(getMockCertificate()).certificateStatus("SAVED").build();
    CertificateInfo authCertificateInfo = new CertificateInfoBuilder().certificate(getMockAuthCertificate()).certificateStatus("SAVED").build();
    CertificateInfo unknownCertificateInfo = new CertificateInfoBuilder().certificate(getMockCertificateWithoutExtensions()).certificateStatus("SAVED").build();
    doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        String certId = (String) args[0];
        if (AUTH_CERT_HASH.equals(certId)) {
            return authCertificateInfo;
        } else if (UNKNOWN_CERT_HASH.equals(certId)) {
            return unknownCertificateInfo;
        } else {
            return signCertificateInfo;
        }
    }).when(signerProxyFacade).getCertForHash(any());
    doAnswer(answer -> "key-id").when(signerProxyFacade).getKeyIdForCertHash(any());
    TokenInfo tokenInfo = new TokenTestUtils.TokenInfoBuilder().build();
    KeyInfo keyInfo = new TokenTestUtils.KeyInfoBuilder().id("key-id").build();
    tokenInfo.getKeyInfo().add(keyInfo);
    doAnswer(answer -> Collections.singletonList(tokenInfo)).when(signerProxyFacade).getTokens();
    TokenInfoAndKeyId tokenInfoAndKeyId = new TokenInfoAndKeyId(tokenInfo, keyInfo.getId());
    doAnswer(answer -> tokenInfoAndKeyId).when(signerProxyFacade).getTokenAndKeyIdForCertRequestId(any());
    doAnswer(answer -> tokenInfoAndKeyId).when(signerProxyFacade).getTokenAndKeyIdForCertHash(any());
    // by default all actions are possible
    doReturn(EnumSet.allOf(PossibleActionEnum.class)).when(possibleActionsRuleEngine).getPossibleCertificateActions(any(), any(), any());
}
Also used : TokenInfoAndKeyId(ee.ria.xroad.signer.protocol.dto.TokenInfoAndKeyId) KeyInfo(ee.ria.xroad.signer.protocol.dto.KeyInfo) PossibleActionEnum(org.niis.xroad.securityserver.restapi.service.PossibleActionEnum) CertificateInfo(ee.ria.xroad.signer.protocol.dto.CertificateInfo) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) TokenTestUtils(org.niis.xroad.securityserver.restapi.util.TokenTestUtils) CertificateInfoBuilder(org.niis.xroad.securityserver.restapi.util.CertificateTestUtils.CertificateInfoBuilder) Before(org.junit.Before)

Example 30 with TokenInfo

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

the class TokenCertificateSigningRequestConverterTest method convertWithPossibleActions.

@Test
public void convertWithPossibleActions() throws Exception {
    CertRequestInfo certRequestInfo = new CertificateTestUtils.CertRequestInfoBuilder().build();
    KeyInfo keyInfo = new TokenTestUtils.KeyInfoBuilder().csr(certRequestInfo).build();
    TokenInfo tokenInfo = new TokenTestUtils.TokenInfoBuilder().key(keyInfo).build();
    TokenCertificateSigningRequest csr = csrConverter.convert(certRequestInfo, keyInfo, tokenInfo);
    Collection<PossibleAction> actions = csr.getPossibleActions();
    assertTrue(actions.contains(PossibleAction.DELETE));
    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) TokenCertificateSigningRequest(org.niis.xroad.securityserver.restapi.openapi.model.TokenCertificateSigningRequest) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) CertRequestInfo(ee.ria.xroad.signer.protocol.dto.CertRequestInfo) Test(org.junit.Test)

Aggregations

TokenInfo (ee.ria.xroad.signer.protocol.dto.TokenInfo)52 KeyInfo (ee.ria.xroad.signer.protocol.dto.KeyInfo)33 Test (org.junit.Test)19 TokenTestUtils (org.niis.xroad.securityserver.restapi.util.TokenTestUtils)16 CodedException (ee.ria.xroad.common.CodedException)14 CertificateInfo (ee.ria.xroad.signer.protocol.dto.CertificateInfo)13 SignerNotReachableException (org.niis.xroad.restapi.service.SignerNotReachableException)11 TokenInfoAndKeyId (ee.ria.xroad.signer.protocol.dto.TokenInfoAndKeyId)9 ServiceException (org.niis.xroad.restapi.service.ServiceException)8 Before (org.junit.Before)7 CertRequestInfo (ee.ria.xroad.signer.protocol.dto.CertRequestInfo)6 CertificateTestUtils (org.niis.xroad.securityserver.restapi.util.CertificateTestUtils)6 ClientId (ee.ria.xroad.common.identifier.ClientId)5 HashMap (java.util.HashMap)5 DeviationAwareRuntimeException (org.niis.xroad.restapi.exceptions.DeviationAwareRuntimeException)5 Command (asg.cliche.Command)4 Utils.printTokenInfo (ee.ria.xroad.signer.console.Utils.printTokenInfo)4 KeyUsageInfo (ee.ria.xroad.signer.protocol.dto.KeyUsageInfo)4 ListTokens (ee.ria.xroad.signer.protocol.message.ListTokens)4 ArrayList (java.util.ArrayList)4