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 e02a168
Show file tree
Hide file tree
Showing 2 changed files with 9 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 @@ -51,9 +51,14 @@ 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<>();

Scanner scanner = new Scanner(computer.getSlaveTemplate().getStaticHostKeys());
String staticHostKeys;
if (computer.getSlaveTemplate() == null) staticHostKeys = "";
else staticHostKeys = computer.getSlaveTemplate().getStaticHostKeys();

Scanner scanner = new Scanner(staticHostKeys);
while (scanner.hasNextLine()) {
String hostKeyString = scanner.nextLine();
String[] hostKeyParts = hostKeyString.split(" ");
Expand Down Expand Up @@ -93,7 +98,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 e02a168

Please sign in to comment.