Skip to content

Commit

Permalink
null check
Browse files Browse the repository at this point in the history
  • Loading branch information
cgroschupp committed Jul 27, 2020
1 parent 79fa8ce commit d2455f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/ec2/SlaveTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public class SlaveTemplate implements Describable<SlaveTemplate> {

public HostKeyVerificationStrategyEnum hostKeyVerificationStrategy;

public final String staticHostKeys;
public String staticHostKeys;

public final boolean associatePublicIp;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
import hudson.model.TaskListener;
import hudson.plugins.ec2.EC2Cloud;
import hudson.plugins.ec2.EC2Computer;
import hudson.plugins.ec2.SlaveTemplate;
import hudson.slaves.OfflineCause;

import java.util.ArrayList;
import java.util.Base64;

import java.io.IOException;
import java.util.Objects;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -51,9 +53,17 @@ public class CheckStaticStrategy extends SshHostKeyVerificationStrategy {
private static final Logger LOGGER = Logger.getLogger(CheckStaticStrategy.class.getName());

private ArrayList<HostKey> getStaticHostKeys(EC2Computer computer) {
ArrayList<HostKey> hostKeys = new ArrayList<>();
ArrayList<HostKey> hostKeys;
hostKeys = new ArrayList<>();

SlaveTemplate computerSlaveTemplate = computer.getSlaveTemplate();
if (computerSlaveTemplate == null) {
EC2Cloud.log(LOGGER, Level.WARNING, computer.getListener(), "slave template not exists");
return hostKeys;
}

Scanner scanner = new Scanner(computerSlaveTemplate.getStaticHostKeys());

Scanner scanner = new Scanner(computer.getSlaveTemplate().getStaticHostKeys());
while (scanner.hasNextLine()) {
String hostKeyString = scanner.nextLine();
String[] hostKeyParts = hostKeyString.split(" ");
Expand Down Expand Up @@ -93,7 +103,7 @@ public boolean verify(EC2Computer computer, HostKey hostKey, TaskListener listen
return false;

} else if (existingHostKey.equals(hostKey)) {
EC2Cloud.log(LOGGER, Level.INFO, computer.getListener(), String.format("Connection allowed after the host key has been verified"));
EC2Cloud.log(LOGGER, Level.INFO, computer.getListener(), "Connection allowed after the host key has been verified");
return true;
} else {
EC2Cloud.log(LOGGER, Level.WARNING, computer.getListener(), String.format("The SSH key (%s) presented by the instance has changed since first saved (%s). The connection to %s is closed to prevent a possible man-in-the-middle attack", hostKey.getFingerprint(), existingHostKey.getFingerprint(), computer.getName()));
Expand Down

0 comments on commit d2455f8

Please sign in to comment.