Search in sources :

Example 11 with CodedException

use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.

the class TokenService method activateToken.

/**
 * Activate a token
 *
 * @param id id of token
 * @param password password for token
 * @throws TokenNotFoundException if token was not found
 * @throws PinIncorrectException if token login failed due to wrong ping
 * @throws ActionNotPossibleException if token activation was not possible
 */
public void activateToken(String id, char[] password) throws TokenNotFoundException, PinIncorrectException, ActionNotPossibleException {
    // check that action is possible
    TokenInfo tokenInfo = getToken(id);
    auditDataHelper.put(tokenInfo);
    possibleActionsRuleEngine.requirePossibleTokenAction(PossibleActionEnum.TOKEN_ACTIVATE, tokenInfo);
    try {
        signerProxyFacade.activateToken(id, password);
    } catch (CodedException e) {
        if (isCausedByTokenNotFound(e)) {
            throw new TokenNotFoundException(e);
        } else if (isCausedByIncorrectPin(e)) {
            throw new PinIncorrectException(e);
        } else {
            throw e;
        }
    } catch (Exception other) {
        throw new SignerNotReachableException("token activation 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 12 with CodedException

use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.

the class ConfigurationDownloader method verifyContent.

void verifyContent(byte[] content, ConfigurationFile file) throws Exception {
    String algoId = getAlgorithmId(file.getHashAlgorithmId());
    log.trace("verifyContent({}, {})", file.getHash(), algoId);
    DigestCalculator dc = createDigestCalculator(algoId);
    dc.getOutputStream().write(content);
    byte[] hash = dc.getDigest();
    if (!Arrays.equals(hash, decodeBase64(file.getHash()))) {
        log.trace("Content {} hash {} does not match expected hash {}", new Object[] { file, encodeBase64(hash), file.getHash() });
        throw new CodedException(X_IO_ERROR, "Failed to verify content integrity (%s)", file);
    }
}
Also used : CodedException(ee.ria.xroad.common.CodedException) CryptoUtils.createDigestCalculator(ee.ria.xroad.common.util.CryptoUtils.createDigestCalculator) DigestCalculator(org.bouncycastle.operator.DigestCalculator)

Example 13 with CodedException

use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.

the class CachingServerConfImpl method isSslAuthentication.

@Override
public boolean isSslAuthentication(ServiceId service) {
    Optional<ServiceType> serviceTypeOptional = getService(service);
    if (!serviceTypeOptional.isPresent()) {
        throw new CodedException(X_UNKNOWN_SERVICE, "Service '%s' not found", service);
    }
    ServiceType serviceType = serviceTypeOptional.get();
    return (boolean) ObjectUtils.defaultIfNull(serviceType.getSslAuthentication(), true);
}
Also used : CodedException(ee.ria.xroad.common.CodedException) ServiceType(ee.ria.xroad.common.conf.serverconf.model.ServiceType)

Example 14 with CodedException

use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.

the class ManagementRequestSender method getResponse.

private static SoapMessageImpl getResponse(HttpSender sender, String expectedContentType) throws Exception {
    String baseContentType = getBaseContentType(sender.getResponseContentType());
    if (baseContentType == null || !baseContentType.equalsIgnoreCase(expectedContentType)) {
        throw new CodedException(X_HTTP_ERROR, "Unexpected or no content type (%s) in response", baseContentType);
    }
    Soap response = new SoapParserImpl().parse(baseContentType, sender.getResponseContent());
    if (response instanceof SoapFault) {
        // Server responded with fault
        throw ((SoapFault) response).toCodedException();
    }
    if (!(response instanceof SoapMessageImpl)) {
        throw new CodedException(X_INTERNAL_ERROR, "Got unexpected response message " + response);
    }
    SoapMessageImpl responseMessage = (SoapMessageImpl) response;
    if (!responseMessage.isResponse()) {
        throw new CodedException(X_INTERNAL_ERROR, "Expected response message");
    }
    return responseMessage;
}
Also used : SoapFault(ee.ria.xroad.common.message.SoapFault) CodedException(ee.ria.xroad.common.CodedException) SoapParserImpl(ee.ria.xroad.common.message.SoapParserImpl) SoapMessageImpl(ee.ria.xroad.common.message.SoapMessageImpl) Soap(ee.ria.xroad.common.message.Soap)

Example 15 with CodedException

use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.

the class KeyService method unregisterAuthCert.

/**
 * Unregister one auth cert
 */
private void unregisterAuthCert(CertificateInfo certificateInfo) throws GlobalConfOutdatedException {
    // this permission is not checked by unregisterCertificate()
    securityHelper.verifyAuthority("SEND_AUTH_CERT_DEL_REQ");
    try {
        // management request to unregister / delete
        managementRequestSenderService.sendAuthCertDeletionRequest(certificateInfo.getCertificateBytes());
        // update status
        signerProxyFacade.setCertStatus(certificateInfo.getId(), CertificateInfo.STATUS_DELINPROG);
    } catch (GlobalConfOutdatedException | CodedException e) {
        throw e;
    } catch (Exception e) {
        throw new SignerNotReachableException("Could not unregister auth cert", e);
    }
}
Also used : CodedException(ee.ria.xroad.common.CodedException) SignerNotReachableException(org.niis.xroad.restapi.service.SignerNotReachableException) NoSuchElementException(java.util.NoSuchElementException) UnhandledWarningsException(org.niis.xroad.restapi.service.UnhandledWarningsException) CodedException(ee.ria.xroad.common.CodedException) SignerNotReachableException(org.niis.xroad.restapi.service.SignerNotReachableException)

Aggregations

CodedException (ee.ria.xroad.common.CodedException)131 X509Certificate (java.security.cert.X509Certificate)28 IOException (java.io.IOException)17 ErrorCodes.translateException (ee.ria.xroad.common.ErrorCodes.translateException)15 SignerNotReachableException (org.niis.xroad.restapi.service.SignerNotReachableException)14 TokenInfo (ee.ria.xroad.signer.protocol.dto.TokenInfo)12 OCSPResp (org.bouncycastle.cert.ocsp.OCSPResp)11 ServiceException (org.niis.xroad.restapi.service.ServiceException)11 ClientId (ee.ria.xroad.common.identifier.ClientId)10 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 KeyInfo (ee.ria.xroad.signer.protocol.dto.KeyInfo)8 InputStream (java.io.InputStream)8 URISyntaxException (java.net.URISyntaxException)7 Date (java.util.Date)7 SoapFault (ee.ria.xroad.common.message.SoapFault)6 ServiceId (ee.ria.xroad.common.identifier.ServiceId)5 Soap (ee.ria.xroad.common.message.Soap)5 SoapMessageImpl (ee.ria.xroad.common.message.SoapMessageImpl)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5