From d5aced5d7de4a6a19228cd7eaa76fa7de7dd24da Mon Sep 17 00:00:00 2001 From: dan-du-car Date: Thu, 25 Jun 2020 13:08:50 -0700 Subject: [PATCH 1/3] fix signature validity --- .../sec/controllers/SignatureController.java | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/main/java/us/dot/its/jpo/sec/controllers/SignatureController.java b/src/main/java/us/dot/its/jpo/sec/controllers/SignatureController.java index f998477..a9bf2d1 100644 --- a/src/main/java/us/dot/its/jpo/sec/controllers/SignatureController.java +++ b/src/main/java/us/dot/its/jpo/sec/controllers/SignatureController.java @@ -1,3 +1,18 @@ +/******************************************************************************* + * Copyright 2018 572682 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + ******************************************************************************/ package us.dot.its.jpo.sec.controllers; import java.net.URI; @@ -46,9 +61,12 @@ public class SignatureController implements EnvironmentAware { // public boolean mockResponse; public boolean useHsm; - public static class Message { + public static class Message{ @JsonProperty("message") public String msg; + + @JsonProperty("sigValidityOverride") + public int sigValidityOverride = 0; } private static final Logger logger = LoggerFactory.getLogger(SignatureController.class); @@ -58,6 +76,7 @@ public static class Message { public ResponseEntity> sign(@RequestBody Message message) throws URISyntaxException { logger.info("Received message: {}", message.msg); + logger.info("Received sigValidityOverride: {}", message.sigValidityOverride); ResponseEntity> response; @@ -84,7 +103,7 @@ public ResponseEntity> sign(@RequestBody Message message) thr } logger.debug("After Trimming: cryptoServiceBaseUri={}, cryptoServiceEndpointSignPath={}", cryptoServiceBaseUri, cryptoServiceEndpointSignPath); - + String resultString = message.msg; if (!StringUtils.isEmpty(cryptoServiceBaseUri) && !StringUtils.isEmpty(cryptoServiceEndpointSignPath)) { logger.info("Sending signature request to external service"); @@ -105,6 +124,7 @@ public ResponseEntity> sign(@RequestBody Message message) thr response = ResponseEntity.status(HttpStatus.NOT_FOUND).body(result); } + } return response; @@ -115,9 +135,19 @@ private ResponseEntity forwardMessageToExternalService(Message message) HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); - - HttpEntity> entity = new HttpEntity<>(Collections.singletonMap("message", message.msg), headers); - + Map map; + + if(message.sigValidityOverride > 0) + { + map = new HashMap<>(); + map.put("message",message.msg); + map.put("sigValidityOverride", Integer.toString(message.sigValidityOverride)); + } + else + { + map = Collections.singletonMap("message", message.msg); + } + HttpEntity> entity = new HttpEntity<>(map, headers); RestTemplate template = new RestTemplate(); logger.debug("Received request: {}", entity); From af695acb4b4108ab53e623ec79ea4e04302b2a50 Mon Sep 17 00:00:00 2001 From: dan-du-car Date: Thu, 20 Aug 2020 09:16:12 -0700 Subject: [PATCH 2/3] add message-expiry --- .../us/dot/its/jpo/sec/controllers/SignatureController.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/us/dot/its/jpo/sec/controllers/SignatureController.java b/src/main/java/us/dot/its/jpo/sec/controllers/SignatureController.java index a9bf2d1..e280b75 100644 --- a/src/main/java/us/dot/its/jpo/sec/controllers/SignatureController.java +++ b/src/main/java/us/dot/its/jpo/sec/controllers/SignatureController.java @@ -112,7 +112,11 @@ public ResponseEntity> sign(@RequestBody Message message) thr JSONObject json = new JSONObject(result.getBody()); resultString = json.getString("message-signed"); - response = ResponseEntity.status(HttpStatus.OK).body(Collections.singletonMap("result", resultString)); + String resultMsgExpiry = json.getString("message-expiry"); + Map mapResult = new HashMap<>(); + mapResult.put("message-expiry", resultMsgExpiry); + mapResult.put("message-signed", resultString); + response = ResponseEntity.status(HttpStatus.OK).body(Collections.singletonMap("result", new JSONObject(mapResult).toString())); } else { String msg = "Properties sec.cryptoServiceBaseUri=" + cryptoServiceBaseUri + ", sec.cryptoServiceEndpointSignPath=" + cryptoServiceEndpointSignPath From 1712679b8566b7025c37f591c21f34ea85671d76 Mon Sep 17 00:00:00 2001 From: dan-du-car Date: Thu, 3 Sep 2020 19:49:26 -0700 Subject: [PATCH 3/3] update message expiry --- .../its/jpo/sec/controllers/SignatureController.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/us/dot/its/jpo/sec/controllers/SignatureController.java b/src/main/java/us/dot/its/jpo/sec/controllers/SignatureController.java index e280b75..48f8603 100644 --- a/src/main/java/us/dot/its/jpo/sec/controllers/SignatureController.java +++ b/src/main/java/us/dot/its/jpo/sec/controllers/SignatureController.java @@ -112,9 +112,17 @@ public ResponseEntity> sign(@RequestBody Message message) thr JSONObject json = new JSONObject(result.getBody()); resultString = json.getString("message-signed"); - String resultMsgExpiry = json.getString("message-expiry"); Map mapResult = new HashMap<>(); - mapResult.put("message-expiry", resultMsgExpiry); + try + { + + mapResult.put("message-expiry", String.valueOf(json.getLong("message-expiry"))); + + } + catch(Exception e) + { + mapResult.put("message-expiry", "null"); + } mapResult.put("message-signed", resultString); response = ResponseEntity.status(HttpStatus.OK).body(Collections.singletonMap("result", new JSONObject(mapResult).toString())); } else {