Skip to content

Commit

Permalink
ensure ssh private key ends with newline (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
cronik authored Jul 12, 2022
1 parent c564958 commit a991d19
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public MultiEnvironment bind(Run<?, ?> build, FilePath workspace, Launcher launc
StringBuilder contents = new StringBuilder();
for (String key : sshKey.getPrivateKeys()) {
contents.append(key);
contents.append('\n');
}
keyFile.write(contents.toString(), "UTF-8");
if (launcher.isUnix()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ public String getPrivateKey() {
@NonNull
@Override
public List<String> getPrivateKeys() {
return Collections.singletonList(getPrivateKey());
String key = getPrivateKey();
// ensure keys end with newline to match the reference implementation
// https://github.com/jenkinsci/ssh-credentials-plugin/blob/d141a312701bc9a04de18ac9f97dffdbae19f978/src/main/java/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKey.java#L177
return Collections.singletonList(key.endsWith("\n") ? key : key + "\n");
}

@NonNull
Expand Down

0 comments on commit a991d19

Please sign in to comment.