From bf11192fd038be877b9a0abe2a9e782ac780c9d9 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Thu, 8 Nov 2018 10:08:56 +0100 Subject: [PATCH 1/2] simplify UI and exposed Data model As only directly entered key is supported for SECURITY-440 Signed-off-by: Nicolas De Loof --- .../impl/BasicSSHUserPrivateKey.java | 14 ++++++++- .../DirectEntryPrivateKeySource/config.jelly | 31 ------------------- .../config_de.properties | 24 -------------- .../config_ja.properties | 24 -------------- .../FileOnMasterPrivateKeySource/config.jelly | 31 ------------------- .../config_de.properties | 24 -------------- .../config_ja.properties | 24 -------------- .../UsersPrivateKeySource/help.html | 10 ------ .../BasicSSHUserPrivateKey/credentials.jelly | 22 ++----------- 9 files changed, 15 insertions(+), 189 deletions(-) delete mode 100644 src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/DirectEntryPrivateKeySource/config.jelly delete mode 100644 src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/DirectEntryPrivateKeySource/config_de.properties delete mode 100644 src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/DirectEntryPrivateKeySource/config_ja.properties delete mode 100644 src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/FileOnMasterPrivateKeySource/config.jelly delete mode 100644 src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/FileOnMasterPrivateKeySource/config_de.properties delete mode 100644 src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/FileOnMasterPrivateKeySource/config_ja.properties delete mode 100644 src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/UsersPrivateKeySource/help.html diff --git a/src/main/java/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey.java b/src/main/java/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey.java index cc7bb8d..523cdfc 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey.java @@ -26,6 +26,7 @@ import com.cloudbees.jenkins.plugins.sshcredentials.SSHUserPrivateKey; import com.cloudbees.plugins.credentials.CredentialsProvider; import com.cloudbees.plugins.credentials.CredentialsScope; +import com.google.common.base.Optional; import edu.umd.cs.findbugs.annotations.CheckForNull; import edu.umd.cs.findbugs.annotations.NonNull; import hudson.DescriptorExtensionList; @@ -100,11 +101,22 @@ public class BasicSSHUserPrivateKey extends BaseSSHUser implements SSHUserPrivat * * @param scope the credentials scope * @param username the username. - * @param privateKeySource the private key. + * @param privateKey the private key. * @param passphrase the password. * @param description the description. */ @DataBoundConstructor + public BasicSSHUserPrivateKey(CredentialsScope scope, String id, String username, String privateKey, + String passphrase, + String description) { + super(scope, id, username, description); + privateKey = StringUtils.trimToNull(privateKey); + this.privateKeySource = privateKey == null ? null : new DirectEntryPrivateKeySource(privateKey); + this.passphrase = fixEmpty(passphrase == null ? null : Secret.fromString(passphrase)); + } + + + @Deprecated public BasicSSHUserPrivateKey(CredentialsScope scope, String id, String username, PrivateKeySource privateKeySource, String passphrase, String description) { diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/DirectEntryPrivateKeySource/config.jelly b/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/DirectEntryPrivateKeySource/config.jelly deleted file mode 100644 index feabf1b..0000000 --- a/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/DirectEntryPrivateKeySource/config.jelly +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/DirectEntryPrivateKeySource/config_de.properties b/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/DirectEntryPrivateKeySource/config_de.properties deleted file mode 100644 index 42e493f..0000000 --- a/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/DirectEntryPrivateKeySource/config_de.properties +++ /dev/null @@ -1,24 +0,0 @@ -# -# The MIT License -# -# Copyright (c) 2013 Harald Albers -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -Key=Schl\u00FCssel \ No newline at end of file diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/DirectEntryPrivateKeySource/config_ja.properties b/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/DirectEntryPrivateKeySource/config_ja.properties deleted file mode 100644 index c9116e1..0000000 --- a/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/DirectEntryPrivateKeySource/config_ja.properties +++ /dev/null @@ -1,24 +0,0 @@ -# The MIT License -# -# Copyright (c) 2013 Seiji Sogabe. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -Key=\u9375 - diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/FileOnMasterPrivateKeySource/config.jelly b/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/FileOnMasterPrivateKeySource/config.jelly deleted file mode 100644 index 93ef454..0000000 --- a/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/FileOnMasterPrivateKeySource/config.jelly +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/FileOnMasterPrivateKeySource/config_de.properties b/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/FileOnMasterPrivateKeySource/config_de.properties deleted file mode 100644 index c9d315d..0000000 --- a/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/FileOnMasterPrivateKeySource/config_de.properties +++ /dev/null @@ -1,24 +0,0 @@ -# -# The MIT License -# -# Copyright (c) 2013 Harald Albers -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -File=Datei \ No newline at end of file diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/FileOnMasterPrivateKeySource/config_ja.properties b/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/FileOnMasterPrivateKeySource/config_ja.properties deleted file mode 100644 index 1d0777b..0000000 --- a/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/FileOnMasterPrivateKeySource/config_ja.properties +++ /dev/null @@ -1,24 +0,0 @@ -# The MIT License -# -# Copyright (c) 2013 Seiji Sogabe. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -File=\u30d5\u30a1\u30a4\u30eb - diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/UsersPrivateKeySource/help.html b/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/UsersPrivateKeySource/help.html deleted file mode 100644 index 0c4e115..0000000 --- a/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/UsersPrivateKeySource/help.html +++ /dev/null @@ -1,10 +0,0 @@ -
- The following files will be read if present: -
    -
  • ~/.ssh/id_ecdsa
  • -
  • ~/.ssh/id_ed25519
  • -
  • ~/.ssh/id_rsa
  • -
  • ~/.ssh/id_dsa
  • -
  • ~/.ssh/identity
  • -
-
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/credentials.jelly b/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/credentials.jelly index 81a8284..6d38549 100644 --- a/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/credentials.jelly +++ b/src/main/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey/credentials.jelly @@ -28,26 +28,8 @@ - - - - - - - - - - - - - - - - - -
-
+ + From ee19be411cc28d9a59e55d7ed049237590f6fdc9 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Thu, 8 Nov 2018 15:32:55 +0100 Subject: [PATCH 2/2] use Secret as privateKey constructor arg Signed-off-by: Nicolas De Loof --- .../impl/BasicSSHUserPrivateKey.java | 31 +++++-------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey.java b/src/main/java/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey.java index 523cdfc..682a6b9 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey.java @@ -24,9 +24,7 @@ package com.cloudbees.jenkins.plugins.sshcredentials.impl; import com.cloudbees.jenkins.plugins.sshcredentials.SSHUserPrivateKey; -import com.cloudbees.plugins.credentials.CredentialsProvider; import com.cloudbees.plugins.credentials.CredentialsScope; -import com.google.common.base.Optional; import edu.umd.cs.findbugs.annotations.CheckForNull; import edu.umd.cs.findbugs.annotations.NonNull; import hudson.DescriptorExtensionList; @@ -34,7 +32,6 @@ import hudson.model.AbstractDescribableImpl; import hudson.model.Descriptor; import hudson.model.Items; -import hudson.remoting.Channel; import hudson.util.Secret; import java.io.File; import java.io.IOException; @@ -106,12 +103,11 @@ public class BasicSSHUserPrivateKey extends BaseSSHUser implements SSHUserPrivat * @param description the description. */ @DataBoundConstructor - public BasicSSHUserPrivateKey(CredentialsScope scope, String id, String username, String privateKey, + public BasicSSHUserPrivateKey(CredentialsScope scope, String id, String username, Secret privateKey, String passphrase, String description) { super(scope, id, username, description); - privateKey = StringUtils.trimToNull(privateKey); - this.privateKeySource = privateKey == null ? null : new DirectEntryPrivateKeySource(privateKey); + this.privateKeySource = new DirectEntryPrivateKeySource(privateKey); this.passphrase = fixEmpty(passphrase == null ? null : Secret.fromString(passphrase)); } @@ -308,6 +304,7 @@ public boolean isSnapshotSource() { /** * Descriptor for a {@link PrivateKeySource} */ + @Deprecated public static abstract class PrivateKeySourceDescriptor extends Descriptor { } @@ -322,9 +319,12 @@ public static class DirectEntryPrivateKeySource extends PrivateKeySource impleme private final Secret privateKey; - @DataBoundConstructor + public DirectEntryPrivateKeySource(Secret privateKey) { + this.privateKey = privateKey; + } + public DirectEntryPrivateKeySource(String privateKey) { - this.privateKey = Secret.fromString(privateKey); + this(Secret.fromString(privateKey)); } public DirectEntryPrivateKeySource(List privateKeys) { @@ -360,21 +360,6 @@ public String getPrivateKey() { public boolean isSnapshotSource() { return true; } - - /** - * {@inheritDoc} - */ - @Extension - public static class DescriptorImpl extends PrivateKeySourceDescriptor { - - /** - * {@inheritDoc} - */ - @Override - public String getDisplayName() { - return Messages.BasicSSHUserPrivateKey_DirectEntryPrivateKeySourceDisplayName(); - } - } } /**