/** * return a "public" -> rsa public key, "private" -> its corresponding private key */ public static Map<String, String> generate() { try { return generate(KeyPairGenerator.getInstance("RSA"), new SecureRandom()); } catch (NoSuchAlgorithmException e) { throw propagate(e); } }
/** * return a "public" -> rsa public key, "private" -> its corresponding private key */ public static Map<String, String> generate() { try { return generate(KeyPairGenerator.getInstance("RSA"), new SecureRandom()); } catch (NoSuchAlgorithmException e) { throw propagate(e); } }
public Map<String, String> get() { try { return ImmutableMap.of("public", Files.toString(new File(System.getProperty("user.home") + "/.ssh/id_rsa.pub"), UTF_8), "private", Files.toString(new File(System.getProperty("user.home") + "/.ssh/id_rsa"), UTF_8)); } catch (IOException e) { return SshKeys.generate(); } } };
/** * return a "public" -> rsa public key, "private" -> its corresponding private key */ public static Map<String, String> generate() { try { return generate(KeyPairGenerator.getInstance("RSA"), new SecureRandom()); } catch (NoSuchAlgorithmException e) { throw propagate(e); } }
/** * return a "public" -> rsa public key, "private" -> its corresponding private key */ public static Map<String, String> generate() { try { return generate(KeyPairGenerator.getInstance("RSA"), new SecureRandom()); } catch (NoSuchAlgorithmException e) { throw propagate(e); } }
public Map<String, String> get() { try { return ImmutableMap.of("public", Files.toString(new File(System.getProperty("user.home") + "/.ssh/id_rsa.pub"), UTF_8), "private", Files.toString(new File(System.getProperty("user.home") + "/.ssh/id_rsa"), UTF_8)); } catch (IOException e) { return SshKeys.generate(); } } };
public Map<String, String> get() { try { return ImmutableMap.of("public", Files.toString(new File(System.getProperty("user.home") + "/.ssh/id_rsa.pub"), UTF_8), "private", Files.toString(new File(System.getProperty("user.home") + "/.ssh/id_rsa"), UTF_8)); } catch (IOException e) { return SshKeys.generate(); } } };
public Map<String, String> get() { try { return ImmutableMap.of("public", Files.toString(new File(System.getProperty("user.home") + "/.ssh/id_rsa.pub"), UTF_8), "private", Files.toString(new File(System.getProperty("user.home") + "/.ssh/id_rsa"), UTF_8)); } catch (IOException e) { return SshKeys.generate(); } } };
@Override public Map<String, String> get() { return SshKeys.generate(crypto.rsaKeyPairGenerator(), secureRandom); } }
@Override public Map<String, String> get() { return SshKeys.generate(crypto.rsaKeyPairGenerator(), secureRandom); } }
@Override public Map<String, String> get() { return SshKeys.generate(crypto.rsaKeyPairGenerator(), secureRandom); } }
@Override public Map<String, String> get() { return SshKeys.generate(crypto.rsaKeyPairGenerator(), secureRandom); } }
public static KeyPair generate(String name) { final Map.Entry<String, String> sshKeyPair = SshKeys.generate().entrySet().iterator().next(); return KeyPairBuilder.newBuilder().name(name).publicKey(sshKeyPair.getKey()) .privateKey(sshKeyPair.getValue()).build(); } }
@Test public void testCanGenerate() { Map<String, String> map = generate(); assert map.get("public").startsWith("ssh-rsa ") : map; assert map.get("private").startsWith("-----BEGIN RSA PRIVATE KEY-----") : map; assert privateKeyMatchesPublicKey(map.get("private"), map.get("public")) : map; }
@Test public void testCanGenerate() { Map<String, String> map = generate(); assert map.get("public").startsWith("ssh-rsa ") : map; assert map.get("private").startsWith("-----BEGIN RSA PRIVATE KEY-----") : map; assert privateKeyMatchesPublicKey(map.get("private"), map.get("public")) : map; }
@BeforeClass public void setupDevice() { Map<String, String> keyPair = SshKeys.generate(); sshKey = api.sshKeyApi().create(prefix + "-device-livetest", keyPair.get("public")); }
@Test public void testPublicKeyDoesNotGenerateAuthorizePublicKeyStatementIfOnlyPublicKeyOptionsConfigured() { Map<String, String> keys = SshKeys.generate(); TemplateOptions options = TemplateOptions.Builder.authorizePublicKey(keys.get("public")); NodeAndTemplateOptionsToStatementWithoutPublicKey function = new NodeAndTemplateOptionsToStatementWithoutPublicKey(); assertNull(function.apply(null, options)); }
@Test public void testPublicAndRunScriptKeyDoesNotGenerateAuthorizePublicKeyStatementIfRunScriptPresent() { Map<String, String> keys = SshKeys.generate(); TemplateOptions options = TemplateOptions.Builder.authorizePublicKey(keys.get("public")).runScript("uptime"); NodeAndTemplateOptionsToStatementWithoutPublicKey function = new NodeAndTemplateOptionsToStatementWithoutPublicKey(); Statement statement = function.apply(null, options); assertEquals(statement.render(OsFamily.UNIX), "uptime\n"); }
@BeforeClass public void setupDroplet() { region = firstAvailableRegion(); image = ubuntuImageInRegion(region); size = cheapestSizeInRegionForImage(region, image); Map<String, String> keyPair = SshKeys.generate(); key = api.keyApi().create(prefix + "-droplet-livetest", keyPair.get("public")); }
@Test public void testRegisterDeleteSSHKeyPair() { final Map<String, String> sshKey = SshKeys.generate(); final String publicKey = sshKey.get("public"); sshKeyPair = client.getSSHKeyPairClient().registerSSHKeyPair(keyPairName, publicKey); assertNull(sshKeyPair.getPrivateKey()); checkSSHKeyPair(sshKeyPair); client.getSSHKeyPairClient().deleteSSHKeyPair(keyPairName); assertEquals(client.getSSHKeyPairClient().getSSHKeyPair(sshKeyPair.getName()), null); assertEquals(SshKeys.fingerprintPublicKey(publicKey), sshKeyPair.getFingerprint()); sshKeyPair = null; }