Use proper object for key validity json answer
This commit is contained in:
@@ -20,9 +20,10 @@
|
|||||||
|
|
||||||
package io.kamax.mxisd.controller.v1
|
package io.kamax.mxisd.controller.v1
|
||||||
|
|
||||||
|
import com.google.gson.Gson
|
||||||
import groovy.json.JsonOutput
|
import groovy.json.JsonOutput
|
||||||
|
import io.kamax.mxisd.controller.v1.io.KeyValidityJson
|
||||||
import io.kamax.mxisd.exception.BadRequestException
|
import io.kamax.mxisd.exception.BadRequestException
|
||||||
import io.kamax.mxisd.exception.NotImplementedException
|
|
||||||
import io.kamax.mxisd.key.KeyManager
|
import io.kamax.mxisd.key.KeyManager
|
||||||
import org.apache.commons.lang.StringUtils
|
import org.apache.commons.lang.StringUtils
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
@@ -45,6 +46,10 @@ class KeyController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private KeyManager keyMgr
|
private KeyManager keyMgr
|
||||||
|
|
||||||
|
private Gson gson = new Gson();
|
||||||
|
private String validKey = gson.toJson(new KeyValidityJson(true));
|
||||||
|
private String invalidKey = gson.toJson(new KeyValidityJson(false));
|
||||||
|
|
||||||
@RequestMapping(value = "/pubkey/{keyType}:{keyId}", method = GET)
|
@RequestMapping(value = "/pubkey/{keyType}:{keyId}", method = GET)
|
||||||
String getKey(@PathVariable String keyType, @PathVariable int keyId) {
|
String getKey(@PathVariable String keyType, @PathVariable int keyId) {
|
||||||
if (!"ed25519".contentEquals(keyType)) {
|
if (!"ed25519".contentEquals(keyType)) {
|
||||||
@@ -59,9 +64,9 @@ class KeyController {
|
|||||||
|
|
||||||
@RequestMapping(value = "/pubkey/ephemeral/isvalid", method = GET)
|
@RequestMapping(value = "/pubkey/ephemeral/isvalid", method = GET)
|
||||||
String checkEphemeralKeyValidity(HttpServletRequest request) {
|
String checkEphemeralKeyValidity(HttpServletRequest request) {
|
||||||
log.error("{} was requested but not implemented", request.getRequestURL())
|
log.warn("Ephemeral key was request but no ephemeral key are generated, replying not valid")
|
||||||
|
|
||||||
throw new NotImplementedException()
|
return invalidKey
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/pubkey/isvalid", method = GET)
|
@RequestMapping(value = "/pubkey/isvalid", method = GET)
|
||||||
@@ -70,9 +75,7 @@ class KeyController {
|
|||||||
|
|
||||||
// TODO do in manager
|
// TODO do in manager
|
||||||
boolean valid = StringUtils.equals(pubKey, keyMgr.getPublicKeyBase64(keyMgr.getCurrentIndex()))
|
boolean valid = StringUtils.equals(pubKey, keyMgr.getPublicKeyBase64(keyMgr.getCurrentIndex()))
|
||||||
return JsonOutput.toJson(
|
return valid ? validKey : invalidKey
|
||||||
valid: valid
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* mxisd - Matrix Identity Server Daemon
|
||||||
|
* Copyright (C) 2017 Maxime Dor
|
||||||
|
*
|
||||||
|
* https://max.kamax.io/
|
||||||
|
*
|
||||||
|
* 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.kamax.mxisd.controller.v1.io;
|
||||||
|
|
||||||
|
public class KeyValidityJson {
|
||||||
|
|
||||||
|
private boolean valid;
|
||||||
|
|
||||||
|
public KeyValidityJson(boolean isValid) {
|
||||||
|
this.valid = isValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isValid() {
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user