/**
  * Creates a dsa key pair at the given paths for the public and private key. Uses external means
  * (jsch KeyPair) and no internal functionality to create the keys (so that tests can limit
  * theirselves to test single functionality bits).
  *
  * @param publicKeyPath
  * @param privateKeyPath
  * @throws IOException
  * @throws JSchException
  */
 public static KeyPair createDsaKeyPair(String publicKeyPath, String privateKeyPath)
     throws IOException, JSchException {
   KeyPair keyPair = KeyPair.genKeyPair(new JSch(), KeyPair.DSA, 1024);
   keyPair.setPassphrase(DEFAULT_PASSPHRASE);
   keyPair.writePublicKey(publicKeyPath, "created by " + IOpenShiftConnection.DEFAULT_CLIENT_ID);
   keyPair.writePrivateKey(privateKeyPath);
   return keyPair;
 }
예제 #2
0
  public static void createGridsshkey(char[] password, String id) throws Exception {

    if (gridsshkeyExists()) {
      throw new Exception("Key and/or Cert file(s) already exist.");
    }

    JSch jsch = new JSch();
    KeyPair kpair = KeyPair.genKeyPair(jsch, KEY_TYPE);
    kpair.setPassphrase(new String(password));
    kpair.writePrivateKey(CommonGridProperties.getDefault().getGridSSHKey());
    kpair.writePublicKey(CommonGridProperties.getDefault().getGridSSHCert(), id);
    kpair.dispose();

    Util.setFilePermissions(CommonGridProperties.getDefault().getGridSSHKey(), 600);
    Util.setFilePermissions(CommonGridProperties.getDefault().getGridSSHCert(), 600);
  }