diff --git a/src/main/groovy/io/kamax/mxisd/controller/v1/KeyController.groovy b/src/main/groovy/io/kamax/mxisd/controller/v1/KeyController.groovy index 7c583e7..3fd8cb7 100644 --- a/src/main/groovy/io/kamax/mxisd/controller/v1/KeyController.groovy +++ b/src/main/groovy/io/kamax/mxisd/controller/v1/KeyController.groovy @@ -20,9 +20,10 @@ package io.kamax.mxisd.controller.v1 +import com.google.gson.Gson import groovy.json.JsonOutput +import io.kamax.mxisd.controller.v1.io.KeyValidityJson import io.kamax.mxisd.exception.BadRequestException -import io.kamax.mxisd.exception.NotImplementedException import io.kamax.mxisd.key.KeyManager import org.apache.commons.lang.StringUtils import org.slf4j.Logger @@ -45,6 +46,10 @@ class KeyController { @Autowired 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) String getKey(@PathVariable String keyType, @PathVariable int keyId) { if (!"ed25519".contentEquals(keyType)) { @@ -59,9 +64,9 @@ class KeyController { @RequestMapping(value = "/pubkey/ephemeral/isvalid", method = GET) 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) @@ -70,9 +75,7 @@ class KeyController { // TODO do in manager boolean valid = StringUtils.equals(pubKey, keyMgr.getPublicKeyBase64(keyMgr.getCurrentIndex())) - return JsonOutput.toJson( - valid: valid - ) + return valid ? validKey : invalidKey } } diff --git a/src/main/groovy/io/kamax/mxisd/controller/v1/io/KeyValidityJson.java b/src/main/groovy/io/kamax/mxisd/controller/v1/io/KeyValidityJson.java new file mode 100644 index 0000000..9f914d0 --- /dev/null +++ b/src/main/groovy/io/kamax/mxisd/controller/v1/io/KeyValidityJson.java @@ -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 . + */ + +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; + } + +}