From dfebfa60a955dc8ab40461359adcb78babb69f14 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Thu, 21 Jan 2021 22:53:34 +0100 Subject: [PATCH] bug4811: trim \n off public key output in REST API; add time point to generated SSH public key comment --- .../src/com/sap/sse/landscape/aws/impl/AwsLandscapeImpl.java | 5 +++-- .../sse/landscape/aws/restapi/SSHKeyPairJsonSerializer.java | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/java/com.sap.sse.landscape.aws/src/com/sap/sse/landscape/aws/impl/AwsLandscapeImpl.java b/java/com.sap.sse.landscape.aws/src/com/sap/sse/landscape/aws/impl/AwsLandscapeImpl.java index 8a2962350be..ff7fa088be7 100755 --- a/java/com.sap.sse.landscape.aws/src/com/sap/sse/landscape/aws/impl/AwsLandscapeImpl.java +++ b/java/com.sap.sse.landscape.aws/src/com/sap/sse/landscape/aws/impl/AwsLandscapeImpl.java @@ -226,9 +226,10 @@ implements AwsLandscape { final KeyPair keyPair = KeyPair.load(new JSch(), privKey, /* pubkey */ null); // private key is unencrypted so far; public key can be obtained: final String creatorName = principal==null?"":principal.toString(); final ByteArrayOutputStream publicKeyBytes = new ByteArrayOutputStream(); - keyPair.writePublicKey(publicKeyBytes, "public key generated by user "+creatorName); + final TimePoint now = TimePoint.now(); + keyPair.writePublicKey(publicKeyBytes, "public key generated by user "+creatorName+" at "+now); final SSHKeyPair result = new SSHKeyPair(region.getId(), creatorName, - TimePoint.now(), keyPairResponse.keyName(), publicKeyBytes.toByteArray(), privKey, + now, keyPairResponse.keyName(), publicKeyBytes.toByteArray(), privKey, privateKeyEncryptionPassphrase); addSSHKeyPair(result); return result; diff --git a/java/com.sap.sse.landscape.aws/src/com/sap/sse/landscape/aws/restapi/SSHKeyPairJsonSerializer.java b/java/com.sap.sse.landscape.aws/src/com/sap/sse/landscape/aws/restapi/SSHKeyPairJsonSerializer.java index 88701269482..a8c6c7cc041 100755 --- a/java/com.sap.sse.landscape.aws/src/com/sap/sse/landscape/aws/restapi/SSHKeyPairJsonSerializer.java +++ b/java/com.sap.sse.landscape.aws/src/com/sap/sse/landscape/aws/restapi/SSHKeyPairJsonSerializer.java @@ -19,7 +19,8 @@ public class SSHKeyPairJsonSerializer implements JsonSerializer { result.put(REGION_ID_FIELD, object.getRegionId()); result.put(CREATOR_NAME_FIELD, object.getCreatorName()); result.put(CREATION_TIME_MILLIS_FIELD, object.getCreationTime().asMillis()); - result.put(PUBLIC_KEY_FIELD, object.getPublicKey() == null ? null : new String(object.getPublicKey())); + result.put(PUBLIC_KEY_FIELD, object.getPublicKey() == null ? null : new String(object.getPublicKey()) + .trim().replaceFirst("\n$", "")); return result; } }