-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for temporary keys (#546)
* Add temporary key ID to service calls * Added endpoints for requesting temporary key * Fix exception and controller bean names * Move temporary key ID to the request body * Fix supported version support * Removed unnecessary annotation * Add version to status endpoint if available * Improve the structure of the application info in status endpoint * Add request/response wrapper
- Loading branch information
1 parent
68e56df
commit 2c1ac1e
Showing
26 changed files
with
449 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...c/main/java/io/getlime/security/powerauth/rest/api/model/request/TemporaryKeyRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* PowerAuth integration libraries for RESTful API applications, examples and | ||
* related software components | ||
* | ||
* Copyright (C) 2024 Wultra s.r.o. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.getlime.security.powerauth.rest.api.model.request; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* Request class with temporary public key. | ||
* | ||
* @author Petr Dvorak, [email protected] | ||
*/ | ||
@Data | ||
public class TemporaryKeyRequest { | ||
|
||
/** | ||
* JWT with encoded temporary key request. | ||
*/ | ||
private String jwt; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,5 +25,12 @@ | |
* @param serverTime Server time. | ||
* @author Roman Strobl, [email protected] | ||
*/ | ||
public record ServerStatusResponse(long serverTime) { | ||
public record ServerStatusResponse(long serverTime, Application application) { | ||
/** | ||
* Record for information about the application. | ||
* @param name Application name, if present in BuildProperties. | ||
* @param version Application version, if present in BuildProperties. | ||
*/ | ||
public record Application(String name, String version) { | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...main/java/io/getlime/security/powerauth/rest/api/model/response/TemporaryKeyResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* PowerAuth integration libraries for RESTful API applications, examples and | ||
* related software components | ||
* | ||
* Copyright (C) 2024 Wultra s.r.o. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.getlime.security.powerauth.rest.api.model.response; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* Response class with temporary key. | ||
* | ||
* @author Petr Dvorak, [email protected] | ||
*/ | ||
@Data | ||
public class TemporaryKeyResponse { | ||
|
||
/** | ||
* JWT with encoded temporary key response. | ||
*/ | ||
private String jwt; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
.../getlime/security/powerauth/rest/api/spring/exception/PowerAuthTemporaryKeyException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* PowerAuth integration libraries for RESTful API applications, examples and | ||
* related software components | ||
* | ||
* Copyright (C) 2024 Wultra s.r.o. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.getlime.security.powerauth.rest.api.spring.exception; | ||
|
||
/** | ||
* Exception raised in case PowerAuth fails to return temporary keys. | ||
* | ||
* @author Petr Dvorak, [email protected] | ||
*/ | ||
public class PowerAuthTemporaryKeyException extends Exception { | ||
|
||
private static final String DEFAULT_CODE = "ERR_TEMPORARY_KEY"; | ||
private static final String DEFAULT_ERROR = "POWER_AUTH_TEMPORARY_KEY_FAILURE"; | ||
|
||
/** | ||
* Default constructor. | ||
*/ | ||
public PowerAuthTemporaryKeyException() { | ||
super(DEFAULT_ERROR); | ||
} | ||
|
||
/** | ||
* Get the default error code, used for example in REST response. | ||
* @return Default error code. | ||
*/ | ||
public String getDefaultCode() { | ||
return DEFAULT_CODE; | ||
} | ||
|
||
/** | ||
* Get default error message, used for example in the REST response. | ||
* @return Default error message. | ||
*/ | ||
public String getDefaultError() { | ||
return DEFAULT_ERROR; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,9 @@ | |
* <p><b>PowerAuth protocol versions:</b> | ||
* <ul> | ||
* <li>3.0</li> | ||
* <li>3.1</li> | ||
* <li>3.2</li> | ||
* <li>3.3</li> | ||
* </ul> | ||
* | ||
* @author Roman Strobl, [email protected] | ||
|
85 changes: 85 additions & 0 deletions
85
...ain/java/io/getlime/security/powerauth/rest/api/spring/controller/KeyStoreController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* PowerAuth integration libraries for RESTful API applications, examples and | ||
* related software components | ||
* | ||
* Copyright (C) 2024 Wultra s.r.o. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.getlime.security.powerauth.rest.api.spring.controller; | ||
|
||
import io.getlime.core.rest.model.base.request.ObjectRequest; | ||
import io.getlime.core.rest.model.base.response.ObjectResponse; | ||
import io.getlime.security.powerauth.rest.api.model.request.TemporaryKeyRequest; | ||
import io.getlime.security.powerauth.rest.api.model.response.TemporaryKeyResponse; | ||
import io.getlime.security.powerauth.rest.api.spring.exception.PowerAuthTemporaryKeyException; | ||
import io.getlime.security.powerauth.rest.api.spring.service.KeyStoreService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.util.StringUtils; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
/** | ||
* Controller for obtaining temporary encryption keys. | ||
* | ||
* <p><b>PowerAuth protocol versions:</b> | ||
* <ul> | ||
* <li>3.3</li> | ||
* </ul> | ||
* | ||
* @author Petr Dvorak, [email protected] | ||
*/ | ||
@RestController("keyStoreControllerV3") | ||
@RequestMapping(value = "/pa/v3/keystore") | ||
public class KeyStoreController { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(KeyStoreController.class); | ||
|
||
private final KeyStoreService service; | ||
|
||
/** | ||
* Default autowiring constructor. | ||
* @param service Keystore service. | ||
*/ | ||
@Autowired | ||
public KeyStoreController(KeyStoreService service) { | ||
this.service = service; | ||
} | ||
|
||
/** | ||
* Create a new temporary key. | ||
* @param request Request for temporary key. | ||
* @return Response with temporary key. | ||
* @throws PowerAuthTemporaryKeyException In case temporary key cannot be returned. | ||
*/ | ||
@PostMapping("create") | ||
public ObjectResponse<TemporaryKeyResponse> fetchTemporaryKey(@RequestBody ObjectRequest<TemporaryKeyRequest> request) throws PowerAuthTemporaryKeyException { | ||
if (request == null) { | ||
logger.warn("Null request while fetching temporary key"); | ||
throw new PowerAuthTemporaryKeyException(); | ||
} | ||
final TemporaryKeyRequest requestObject = request.getRequestObject(); | ||
if (requestObject == null) { | ||
logger.warn("Null request object while fetching temporary key"); | ||
throw new PowerAuthTemporaryKeyException(); | ||
} | ||
if (!StringUtils.hasLength(requestObject.getJwt())) { | ||
logger.warn("Invalid request object with empty JWT while fetching temporary key"); | ||
throw new PowerAuthTemporaryKeyException(); | ||
} | ||
return new ObjectResponse<>(service.fetchTemporaryKey(requestObject)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,9 @@ | |
* <p><b>PowerAuth protocol versions:</b> | ||
* <ul> | ||
* <li>3.0</li> | ||
* <li>3.1</li> | ||
* <li>3.2</li> | ||
* <li>3.3</li> | ||
* </ul> | ||
* | ||
* @author Roman Strobl, [email protected] | ||
|
@@ -85,8 +88,7 @@ public EciesEncryptedResponse confirmRecoveryCode(@RequestBody EciesEncryptedReq | |
|
||
PowerAuthAuthenticationUtil.checkAuthentication(auth); | ||
PowerAuthVersionUtil.checkUnsupportedVersion(auth.getVersion()); | ||
PowerAuthVersionUtil.checkMissingRequiredNonce(auth.getVersion(), request.getNonce()); | ||
PowerAuthVersionUtil.checkMissingRequiredTimestamp(auth.getVersion(), request.getTimestamp()); | ||
PowerAuthVersionUtil.checkEciesParameters(auth.getVersion(), request); | ||
|
||
return recoveryService.confirmRecoveryCode(request, auth); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,9 @@ | |
* <p><b>PowerAuth protocol versions:</b> | ||
* <ul> | ||
* <li>3.0</li> | ||
* <li>3.1</li> | ||
* <li>3.2</li> | ||
* <li>3.3</li> | ||
* </ul> | ||
* | ||
* @author Roman Strobl, [email protected] | ||
|
@@ -100,9 +103,7 @@ public EciesEncryptedResponse unlockVault( | |
} | ||
|
||
PowerAuthVersionUtil.checkUnsupportedVersion(header.getVersion()); | ||
PowerAuthVersionUtil.checkMissingRequiredNonce(header.getVersion(), request.getNonce()); | ||
PowerAuthVersionUtil.checkMissingRequiredTimestamp(header.getVersion(), request.getTimestamp()); | ||
|
||
PowerAuthVersionUtil.checkEciesParameters(header.getVersion(), request); | ||
|
||
return secureVaultServiceV3.vaultUnlock(header, request, httpServletRequest); | ||
} | ||
|
Oops, something went wrong.