use of io.getlime.security.powerauth.rest.api.spring.exception.PowerAuthUpgradeException in project powerauth-restful-integration by lime-company.
the class UpgradeService method upgradeCommit.
/**
* Commit upgrade of activation to version 3.
* @param signatureHeader PowerAuth signature HTTP header.
* @param httpServletRequest HTTP servlet request.
* @return Commit upgrade response.
* @throws PowerAuthAuthenticationException in case authentication fails.
* @throws PowerAuthUpgradeException In case upgrade commit fails.
*/
public Response upgradeCommit(String signatureHeader, HttpServletRequest httpServletRequest) throws PowerAuthAuthenticationException, PowerAuthUpgradeException {
try {
// Extract request body
final byte[] requestBodyBytes = authenticationProvider.extractRequestBodyBytes(httpServletRequest);
if (requestBodyBytes == null || requestBodyBytes.length == 0) {
// Expected request body is {}, do not accept empty body
logger.warn("Empty request body");
throw new PowerAuthInvalidRequestException();
}
// Verify signature, force signature version during upgrade to version 3
final List<PowerAuthSignatureTypes> allowedSignatureTypes = Collections.singletonList(PowerAuthSignatureTypes.POSSESSION);
final PowerAuthApiAuthentication authentication = authenticationProvider.validateRequestSignatureWithActivationDetails("POST", requestBodyBytes, "/pa/upgrade/commit", signatureHeader, allowedSignatureTypes, 3);
// In case signature verification fails, upgrade fails, too
if (!authentication.getAuthenticationContext().isValid() || authentication.getActivationContext().getActivationId() == null) {
logger.debug("Signature validation failed");
throw new PowerAuthSignatureInvalidException();
}
// Get signature HTTP headers
final String activationId = authentication.getActivationContext().getActivationId();
final PowerAuthSignatureHttpHeader httpHeader = (PowerAuthSignatureHttpHeader) authentication.getHttpHeader();
final String applicationKey = httpHeader.getApplicationKey();
// Commit upgrade on PowerAuth server
final CommitUpgradeResponse upgradeResponse = powerAuthClient.commitUpgrade(activationId, applicationKey);
if (upgradeResponse.isCommitted()) {
return new Response();
} else {
logger.debug("Upgrade commit failed");
throw new PowerAuthUpgradeException();
}
} catch (PowerAuthAuthenticationException ex) {
throw ex;
} catch (Exception ex) {
logger.warn("PowerAuth upgrade commit failed, error: {}", ex.getMessage());
logger.debug(ex.getMessage(), ex);
throw new PowerAuthUpgradeException();
}
}
use of io.getlime.security.powerauth.rest.api.spring.exception.PowerAuthUpgradeException in project powerauth-restful-integration by lime-company.
the class UpgradeService method upgradeStart.
/**
* Start upgrade of activation to version 3.
* @param request ECIES encrypted upgrade start request.
* @param header PowerAuth encryption HTTP header.
* @return ECIES encrypted upgrade activation response.
* @throws PowerAuthUpgradeException In case upgrade start fails.
*/
public EciesEncryptedResponse upgradeStart(EciesEncryptedRequest request, PowerAuthEncryptionHttpHeader header) throws PowerAuthUpgradeException {
try {
// Fetch data from the request
final String ephemeralPublicKey = request.getEphemeralPublicKey();
final String encryptedData = request.getEncryptedData();
final String mac = request.getMac();
final String nonce = request.getNonce();
// Get ECIES headers
final String activationId = header.getActivationId();
final String applicationKey = header.getApplicationKey();
// Start upgrade on PowerAuth server
final StartUpgradeResponse upgradeResponse = powerAuthClient.startUpgrade(activationId, applicationKey, ephemeralPublicKey, encryptedData, mac, nonce);
// Prepare a response
final EciesEncryptedResponse response = new EciesEncryptedResponse();
response.setMac(upgradeResponse.getMac());
response.setEncryptedData(upgradeResponse.getEncryptedData());
return response;
} catch (Exception ex) {
logger.warn("PowerAuth upgrade start failed, error: {}", ex.getMessage());
logger.debug(ex.getMessage(), ex);
throw new PowerAuthUpgradeException();
}
}
Aggregations