You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whirr.apache.org by to...@apache.org on 2010/12/15 05:52:51 UTC

svn commit: r1049424 - in /incubator/whirr/trunk: ./ cli/src/test/java/org/apache/whirr/cli/command/ core/src/main/java/org/apache/whirr/service/ core/src/main/java/org/apache/whirr/ssh/ core/src/main/resources/ core/src/test/java/org/apache/whirr/serv...

Author: tomwhite
Date: Wed Dec 15 04:52:51 2010
New Revision: 1049424

URL: http://svn.apache.org/viewvc?rev=1049424&view=rev
Log:
WHIRR-160. Improve SSH key diagnostics. Contributed by Andrei Savu.

Added:
    incubator/whirr/trunk/core/src/main/java/org/apache/whirr/ssh/
    incubator/whirr/trunk/core/src/main/java/org/apache/whirr/ssh/KeyPair.java   (with props)
Removed:
    incubator/whirr/trunk/core/src/test/java/org/apache/whirr/ssh/KeyPair.java
Modified:
    incubator/whirr/trunk/CHANGES.txt
    incubator/whirr/trunk/cli/src/test/java/org/apache/whirr/cli/command/DestroyClusterCommandTest.java
    incubator/whirr/trunk/cli/src/test/java/org/apache/whirr/cli/command/LaunchClusterCommandTest.java
    incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/ClusterSpec.java
    incubator/whirr/trunk/core/src/main/resources/whirr-default.properties
    incubator/whirr/trunk/core/src/test/java/org/apache/whirr/service/ClusterSpecTest.java

Modified: incubator/whirr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/CHANGES.txt?rev=1049424&r1=1049423&r2=1049424&view=diff
==============================================================================
--- incubator/whirr/trunk/CHANGES.txt (original)
+++ incubator/whirr/trunk/CHANGES.txt Wed Dec 15 04:52:51 2010
@@ -19,6 +19,8 @@ Trunk (unreleased changes)
 
     WHIRR-154. Cassandra: expose JMX port. (Kelvin Kakugawa via tomwhite)
 
+    WHIRR-160. Improve SSH key diagnostics. (Andrei Savu via tomwhite)
+
   BUG FIXES
 
     WHIRR-128. Fix DNS resolution for clients running within EC2.

Modified: incubator/whirr/trunk/cli/src/test/java/org/apache/whirr/cli/command/DestroyClusterCommandTest.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/cli/src/test/java/org/apache/whirr/cli/command/DestroyClusterCommandTest.java?rev=1049424&r1=1049423&r2=1049424&view=diff
==============================================================================
--- incubator/whirr/trunk/cli/src/test/java/org/apache/whirr/cli/command/DestroyClusterCommandTest.java (original)
+++ incubator/whirr/trunk/cli/src/test/java/org/apache/whirr/cli/command/DestroyClusterCommandTest.java Wed Dec 15 04:52:51 2010
@@ -25,17 +25,18 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import com.google.common.io.Files;
 import com.google.common.collect.Lists;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.PrintStream;
 import java.util.Collections;
+import java.util.Map;
 
 import org.apache.whirr.service.ClusterSpec;
 import org.apache.whirr.service.Service;
 import org.apache.whirr.service.ServiceFactory;
+import org.apache.whirr.ssh.KeyPair;
 import org.hamcrest.Matcher;
 import org.junit.Before;
 import org.junit.Test;
@@ -76,23 +77,15 @@ public class DestroyClusterCommandTest {
     when(factory.create((String) any())).thenReturn(service);
     
     DestroyClusterCommand command = new DestroyClusterCommand(factory);
-    
-    File privateKeyFile = File.createTempFile("private", "key");
-    privateKeyFile.deleteOnExit();
-    Files.write("-----BEGIN RSA PRIVATE KEY-----".getBytes(),
-             privateKeyFile);
-    
-    File publicKeyFile = File.createTempFile("public", "key");
-    publicKeyFile.deleteOnExit();
-    Files.write("ssh-rsa".getBytes(), publicKeyFile);
+    Map<String, File> keys = KeyPair.generateTemporaryFiles();
     
     int rc = command.run(null, out, null, Lists.newArrayList(
         "--service-name", "test-service",
         "--cluster-name", "test-cluster",
         "--provider", "rackspace",
         "--identity", "myusername", "--credential", "mypassword",
-        "--private-key-file", privateKeyFile.getAbsolutePath(),
-        "--public-key-file", publicKeyFile.getAbsolutePath()
+        "--private-key-file", keys.get("private").getAbsolutePath(),
+        "--public-key-file", keys.get("public").getAbsolutePath()
         ));
     
     assertThat(rc, is(0));
@@ -103,8 +96,8 @@ public class DestroyClusterCommandTest {
     expectedClusterSpec.setIdentity("myusername");
     expectedClusterSpec.setCredential("mypassword");
     expectedClusterSpec.setClusterName("test-cluster");
-    expectedClusterSpec.setPrivateKey(privateKeyFile);
-    expectedClusterSpec.setPublicKey(publicKeyFile);
+    expectedClusterSpec.setPrivateKey(keys.get("private"));
+    expectedClusterSpec.setPublicKey(keys.get("public"));
     
     verify(factory).create("test-service");
     

Modified: incubator/whirr/trunk/cli/src/test/java/org/apache/whirr/cli/command/LaunchClusterCommandTest.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/cli/src/test/java/org/apache/whirr/cli/command/LaunchClusterCommandTest.java?rev=1049424&r1=1049423&r2=1049424&view=diff
==============================================================================
--- incubator/whirr/trunk/cli/src/test/java/org/apache/whirr/cli/command/LaunchClusterCommandTest.java (original)
+++ incubator/whirr/trunk/cli/src/test/java/org/apache/whirr/cli/command/LaunchClusterCommandTest.java Wed Dec 15 04:52:51 2010
@@ -27,18 +27,19 @@ import static org.mockito.Mockito.verify
 import static org.mockito.Mockito.when;
 
 import com.google.common.collect.Sets;
-import com.google.common.io.Files;
 import com.google.common.collect.Lists;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.PrintStream;
 import java.util.Collections;
+import java.util.Map;
 
 import org.apache.whirr.service.Cluster;
 import org.apache.whirr.service.ClusterSpec;
 import org.apache.whirr.service.Service;
 import org.apache.whirr.service.ServiceFactory;
+import org.apache.whirr.ssh.KeyPair;
 import org.hamcrest.Matcher;
 import org.junit.Before;
 import org.junit.Test;
@@ -55,6 +56,7 @@ public class LaunchClusterCommandTest {
   public void setUp() {
     outBytes = new ByteArrayOutputStream();
     out = new PrintStream(outBytes);
+
     errBytes = new ByteArrayOutputStream();
     err = new PrintStream(errBytes);
   }
@@ -80,15 +82,7 @@ public class LaunchClusterCommandTest {
     when(service.launchCluster((ClusterSpec) any())).thenReturn(cluster);
     
     LaunchClusterCommand command = new LaunchClusterCommand(factory);
-    
-    File privateKeyFile = File.createTempFile("private", "key");
-    privateKeyFile.deleteOnExit();
-    Files.write("-----BEGIN RSA PRIVATE KEY-----".getBytes(),
-             privateKeyFile);
-    
-    File publicKeyFile = File.createTempFile("public", "key");
-    publicKeyFile.deleteOnExit();
-    Files.write("ssh-rsa".getBytes(), publicKeyFile);
+    Map<String, File> keys = KeyPair.generateTemporaryFiles();
     
     int rc = command.run(null, out, null, Lists.newArrayList(
         "--service-name", "test-service",
@@ -96,8 +90,8 @@ public class LaunchClusterCommandTest {
         "--instance-templates", "1 role1+role2,2 role3",
         "--provider", "rackspace",
         "--identity", "myusername", "--credential", "mypassword",
-        "--private-key-file", privateKeyFile.getAbsolutePath(),
-        "--public-key-file", publicKeyFile.getAbsolutePath()
+        "--private-key-file", keys.get("private").getAbsolutePath(),
+        "--public-key-file", keys.get("public").getAbsolutePath()
         ));
     
     assertThat(rc, is(0));
@@ -112,8 +106,8 @@ public class LaunchClusterCommandTest {
     expectedClusterSpec.setIdentity("myusername");
     expectedClusterSpec.setCredential("mypassword");
     expectedClusterSpec.setClusterName("test-cluster");
-    expectedClusterSpec.setPrivateKey(privateKeyFile);
-    expectedClusterSpec.setPublicKey(publicKeyFile);
+    expectedClusterSpec.setPrivateKey(keys.get("private"));
+    expectedClusterSpec.setPublicKey(keys.get("public"));
     
     verify(factory).create("test-service");
     

Modified: incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/ClusterSpec.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/ClusterSpec.java?rev=1049424&r1=1049423&r2=1049424&view=diff
==============================================================================
--- incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/ClusterSpec.java (original)
+++ incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/ClusterSpec.java Wed Dec 15 04:52:51 2010
@@ -21,7 +21,6 @@ package org.apache.whirr.service;
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.jclouds.io.Payloads.newStringPayload;
-import static org.jclouds.io.Payloads.newFilePayload;
 import static org.jclouds.util.Utils.toStringAndClose;
 
 import com.google.common.base.Objects;
@@ -29,6 +28,7 @@ import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 
 import java.io.File;
+import java.io.FileReader;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
@@ -36,10 +36,14 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.KeyPair;
 import org.apache.commons.configuration.CompositeConfiguration;
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.io.IOUtils;
 import org.jclouds.io.Payload;
 
 /**
@@ -169,13 +173,15 @@ public class ClusterSpec {
   
   /**
    * 
-   * @throws ConfigurationException if the public or private key cannot be read.
+   * @throws ConfigurationException if something is wrong
    */
   public ClusterSpec(Configuration config)
       throws ConfigurationException {
+
     CompositeConfiguration c = new CompositeConfiguration();
     c.addConfiguration(config);
     c.addConfiguration(new PropertiesConfiguration(DEFAULT_PROPERTIES));
+
     setServiceName(c.getString(Property.SERVICE_NAME.getConfigName()));
     setInstanceTemplates(InstanceTemplate.parse(
         c.getStringArray(Property.INSTANCE_TEMPLATES.getConfigName())));
@@ -183,26 +189,40 @@ public class ClusterSpec {
     setIdentity(c.getString(Property.IDENTITY.getConfigName()));
     setCredential(c.getString(Property.CREDENTIAL.getConfigName()));
     setClusterName(c.getString(Property.CLUSTER_NAME.getConfigName()));
+
     try {
       String privateKeyPath = c.getString(
           Property.PRIVATE_KEY_FILE.getConfigName());
-      if (privateKeyPath != null && new File(privateKeyPath).exists())
-        setPrivateKey(new File(privateKeyPath));
-      String publicKeyPath = c.getString(Property.PUBLIC_KEY_FILE.
-               getConfigName());
-      publicKeyPath = publicKeyPath == null && privateKeyPath != null ?
+
+      String publicKeyPath = c.getString(Property.PUBLIC_KEY_FILE.getConfigName());
+      publicKeyPath = (publicKeyPath == null && privateKeyPath != null) ?
                 privateKeyPath + ".pub" : publicKeyPath;
-      if (publicKeyPath != null && new File(publicKeyPath).exists())
-        setPublicKey(new File(publicKeyPath));
+
+      KeyPair pair = KeyPair.load(new JSch(), privateKeyPath, publicKeyPath);
+      if (pair.isEncrypted()) {
+        throw new ConfigurationException("Key pair is encrypted");
+      }
+
+      setPrivateKey(new File(privateKeyPath));
+      setPublicKey(new File(publicKeyPath));
+
+    } catch (JSchException e) {
+      throw new ConfigurationException("Invalid key pair", e);
+
+    } catch (IllegalArgumentException e) {
+      throw new ConfigurationException("Invalid key", e);
+
     } catch (IOException e) {
-      throw new ConfigurationException("error reading key from file", e);
+      throw new ConfigurationException("Error reading one of key file", e);
     }
+
     setImageId(config.getString(Property.IMAGE_ID.getConfigName()));
     setHardwareId(config.getString(Property.HARDWARE_ID.getConfigName()));
     setLocationId(config.getString(Property.LOCATION_ID.getConfigName()));
     setClientCidrs(c.getList(Property.CLIENT_CIDRS.getConfigName()));
     setVersion(c.getString(Property.VERSION.getConfigName()));
     String runUrlBase = c.getString(Property.RUN_URL_BASE.getConfigName());
+
     if (runUrlBase == null) {
       try {
         runUrlBase = String.format("http://whirr.s3.amazonaws.com/%s/",
@@ -212,6 +232,7 @@ public class ClusterSpec {
       }
     }
     setRunUrlBase(runUrlBase);
+
     this.config = c;
   }
 
@@ -316,8 +337,13 @@ public class ClusterSpec {
    * @param publicKey
    */
   public void setPublicKey(String publicKey) {
-    checkArgument(checkNotNull(publicKey, "publicKey").startsWith("ssh-rsa"),
-        "key should start with ssh-rsa");
+    /*
+     * http://stackoverflow.com/questions/2494645#2494645
+     */
+    checkArgument(checkNotNull(publicKey, "publicKey")
+            .startsWith("ssh-rsa AAAAB3NzaC1yc2EA"),
+        "key should start with ssh-rsa AAAAB3NzaC1yc2EA");
+
     this.publicKey = newStringPayload(publicKey);
   }
   
@@ -328,8 +354,7 @@ public class ClusterSpec {
    * @see #setPublicKey(String)
    */
   public void setPublicKey(File publicKey) throws IOException {
-    this.publicKey = newFilePayload(checkNotNull(publicKey,
-        "publicKey"));
+    setPublicKey(IOUtils.toString(new FileReader(publicKey)));
   }
 
   /**
@@ -352,8 +377,7 @@ public class ClusterSpec {
    * @see #setPrivateKey(String)
    */
   public void setPrivateKey(File privateKey) throws IOException {
-    this.privateKey = newFilePayload(
-        checkNotNull(privateKey, "privateKey"));
+    setPrivateKey(IOUtils.toString(new FileReader(privateKey)));
   }
 
   public void setImageId(String imageId) {

Added: incubator/whirr/trunk/core/src/main/java/org/apache/whirr/ssh/KeyPair.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/core/src/main/java/org/apache/whirr/ssh/KeyPair.java?rev=1049424&view=auto
==============================================================================
--- incubator/whirr/trunk/core/src/main/java/org/apache/whirr/ssh/KeyPair.java (added)
+++ incubator/whirr/trunk/core/src/main/java/org/apache/whirr/ssh/KeyPair.java Wed Dec 15 04:52:51 2010
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.whirr.ssh;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.io.Files;
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.JSchException;
+
+/**
+ * A convenience class for generating an RSA key pair.
+ */
+public class KeyPair {
+
+  public static Map<String, String> generate() throws JSchException {
+      return generate(null);
+  }
+
+  /**
+   * return a "public" -> rsa public key, "private" -> its corresponding
+   *   private key
+   */
+  public static Map<String,String> generate(String passPhrase)
+  throws JSchException {
+    com.jcraft.jsch.KeyPair pair = com.jcraft.jsch.KeyPair.genKeyPair(
+        new JSch(),  com.jcraft.jsch.KeyPair.RSA);
+    if (passPhrase != null) {
+      pair.setPassphrase(passPhrase);
+    }
+
+    ByteArrayOutputStream publicKeyOut = new ByteArrayOutputStream();
+    ByteArrayOutputStream privateKeyOut = new ByteArrayOutputStream();
+
+    pair.writePublicKey(publicKeyOut, "whirr");
+    pair.writePrivateKey(privateKeyOut);
+
+    String publicKey = new String(publicKeyOut.toByteArray());
+    String privateKey = new String(privateKeyOut.toByteArray());
+
+    return ImmutableMap.<String, String> of("public", publicKey,
+        "private", privateKey);
+  }
+
+  public static Map<String, File> generateTemporaryFiles()
+  throws JSchException, IOException {
+    return generateTemporaryFiles(null); 
+  }
+
+  public static Map<String, File> generateTemporaryFiles(String passPhrase)
+  throws JSchException, IOException {
+    Map<String, String> keys = KeyPair.generate(passPhrase);
+
+    File privateKeyFile = File.createTempFile("private", "key");
+    privateKeyFile.deleteOnExit();
+    Files.write(keys.get("private").getBytes(), privateKeyFile);
+
+    File publicKeyFile = new File(privateKeyFile.getAbsolutePath() + ".pub");
+    publicKeyFile.deleteOnExit();
+    Files.write(keys.get("public").getBytes(), publicKeyFile);
+
+    return ImmutableMap.<String, File> of("public", publicKeyFile,
+              "private", privateKeyFile);
+  }
+}

Propchange: incubator/whirr/trunk/core/src/main/java/org/apache/whirr/ssh/KeyPair.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/whirr/trunk/core/src/main/resources/whirr-default.properties
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/core/src/main/resources/whirr-default.properties?rev=1049424&r1=1049423&r2=1049424&view=diff
==============================================================================
--- incubator/whirr/trunk/core/src/main/resources/whirr-default.properties (original)
+++ incubator/whirr/trunk/core/src/main/resources/whirr-default.properties Wed Dec 15 04:52:51 2010
@@ -11,5 +11,8 @@
 #   limitations under the License.
 
 whirr.private-key-file=${sys:user.home}/.ssh/id_rsa
-whirr.public-key-file=${sys:user.home}/.ssh/id_rsa.pub
+
+# whirr.public-key-file = ${whirr.private-key-file}.pub
+# this is created in ClusterSpec class constructor
+
 whirr.version=${version}

Modified: incubator/whirr/trunk/core/src/test/java/org/apache/whirr/service/ClusterSpecTest.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/core/src/test/java/org/apache/whirr/service/ClusterSpecTest.java?rev=1049424&r1=1049423&r2=1049424&view=diff
==============================================================================
--- incubator/whirr/trunk/core/src/test/java/org/apache/whirr/service/ClusterSpecTest.java (original)
+++ incubator/whirr/trunk/core/src/test/java/org/apache/whirr/service/ClusterSpecTest.java Wed Dec 15 04:52:51 2010
@@ -25,11 +25,18 @@ import static org.junit.Assert.assertTha
 import com.google.common.collect.Iterators;
 import com.google.common.collect.Lists;
 
+import java.io.IOException;
 import java.util.List;
+import java.util.Map;
 
+import com.google.common.io.Files;
+import com.jcraft.jsch.JSchException;
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.io.IOUtils;
+import org.apache.whirr.ssh.KeyPair;
+import org.junit.Assert;
 import org.junit.Test;
 
 public class ClusterSpecTest {
@@ -67,12 +74,90 @@ public class ClusterSpecTest {
     conf.setProperty("a.b", 1);
     conf.setProperty("b.a", 2);
     conf.setProperty("a.c", 3);
+
     ClusterSpec spec = new ClusterSpec(conf);
     Configuration prefixConf = spec.getConfigurationForKeysWithPrefix("a");
+
     List<String> prefixKeys = Lists.newArrayList();
     Iterators.addAll(prefixKeys, prefixConf.getKeys());
+
     assertThat(prefixKeys.size(), is(2));
     assertThat(prefixKeys.get(0), is("a.b"));
     assertThat(prefixKeys.get(1), is("a.c"));
   }
+
+  @Test
+  public void testDefaultPublicKey()
+  throws ConfigurationException, JSchException, IOException {
+    Map<String, File> keys = KeyPair.generateTemporaryFiles();
+
+    Configuration conf = new PropertiesConfiguration();
+    conf.setProperty("whirr.private-key-file", keys.get("private").getAbsolutePath());
+    // If no public-key-file is specified it should append .pub to the private-key-file
+
+    ClusterSpec spec = new ClusterSpec(conf);
+    Assert.assertEquals(IOUtils.toString(
+            new FileReader(keys.get("public"))), spec.readPublicKey());
+  }
+
+  @Test(expected = ConfigurationException.class)
+  public void testDummyPrivateKey()
+  throws JSchException, IOException, ConfigurationException {
+    File privateKeyFile = File.createTempFile("private", "key");
+    privateKeyFile.deleteOnExit();
+    Files.write(("-----BEGIN RSA PRIVATE KEY-----\n" +
+            "DUMMY FILE\n" +
+            "-----END RSA PRIVATE KEY-----").getBytes(), privateKeyFile);
+
+    Configuration conf = new PropertiesConfiguration();
+    conf.setProperty("whirr.private-key-file", privateKeyFile.getAbsolutePath());
+
+    ClusterSpec spec = new ClusterSpec(conf);
+  }
+
+  @Test(expected = ConfigurationException.class)
+  public void testEncryptedPrivateKey()
+  throws JSchException, IOException, ConfigurationException {
+    File privateKey = KeyPair.generateTemporaryFiles("dummy").get("private");
+
+    Configuration conf = new PropertiesConfiguration();
+    conf.setProperty("whirr.private-key-file", privateKey.getAbsolutePath());
+
+    ClusterSpec spec = new ClusterSpec(conf);
+  }
+
+  @Test(expected = ConfigurationException.class)
+  public void testMissingPrivateKey() throws ConfigurationException {
+    Configuration conf = new PropertiesConfiguration();
+    conf.setProperty("whirr.private-key-file", "/dummy/path/that/does/not/exists");
+
+    ClusterSpec spec = new ClusterSpec(conf);      
+  }
+
+  @Test(expected = ConfigurationException.class)
+  public void testMissingPublicKey() throws JSchException, IOException, ConfigurationException {
+    File privateKey = KeyPair.generateTemporaryFiles().get("private");
+
+    Configuration conf = new PropertiesConfiguration();
+    conf.setProperty("whirr.private-key-file", privateKey.getAbsolutePath());
+    conf.setProperty("whirr.public-key-file", "/dummy/path/that/does/not/exists");
+
+    ClusterSpec spec = new ClusterSpec(conf);
+  }
+
+  @Test(expected = ConfigurationException.class)
+  public void testBrokenPublicKey() throws IOException, JSchException, ConfigurationException {
+    File privateKey = KeyPair.generateTemporaryFiles().get("private");
+
+    File publicKey = File.createTempFile("public", "key");
+    publicKey.deleteOnExit();
+    Files.write("ssh-rsa BROKEN PUBLIC KEY".getBytes(), publicKey);
+
+    Configuration conf = new PropertiesConfiguration();
+    conf.setProperty("whirr.private-key-file", privateKey.getAbsolutePath());
+    conf.setProperty("whirr.public-key-file", publicKey.getAbsolutePath());
+
+    ClusterSpec spec = new ClusterSpec(conf);
+  }
+
 }