Package com.jcraft.jsch

Examples of com.jcraft.jsch.KeyPair


      publicKeyPath = (publicKeyPath == null && privateKeyPath != null) ?
                privateKeyPath + ".pub" : publicKeyPath;
      if(privateKeyPath != null && publicKeyPath != null) {
        pairRepresentation = "(" + privateKeyPath + ", " +
            publicKeyPath + ")";
        KeyPair pair = KeyPair.load(new JSch(), privateKeyPath, publicKeyPath);
        if (pair.isEncrypted()) {
          throw new ConfigurationException("Key pair " + pairRepresentation +
              " is encrypted. Try generating a new passwordless SSH keypair " +
              "(e.g. with ssh-keygen).");
        }
        if (!sameKeyPair(new File(privateKeyPath), new File(publicKeyPath))) {
View Full Code Here


      publicKeyPath = (publicKeyPath == null && privateKeyPath != null) ?
                privateKeyPath + ".pub" : publicKeyPath;
      if(privateKeyPath != null && publicKeyPath != null) {
        pairRepresentation = "(" + privateKeyPath + ", " +
            publicKeyPath + ")";
        KeyPair pair = KeyPair.load(new JSch(), privateKeyPath, publicKeyPath);
        if (pair.isEncrypted()) {
          throw new ConfigurationException("Key pair " + pairRepresentation +
              " is encrypted. Try generating a new passwordless SSH keypair " +
              "(e.g. with ssh-keygen).");
        }
        if (!sameKeyPair(new File(privateKeyPath), new File(publicKeyPath))) {
View Full Code Here

        Assert.assertTrue(keyIsPresent(comment, keyListResponse), comment + " should have been present.");
    }

    public String getPublicKey(String comment) throws JSchException, IOException {
        JSch jsch = new JSch();
        KeyPair keyPair = KeyPair.genKeyPair(jsch, KeyPair.RSA);

        ByteArrayOutputStream publicKeyOutputStream = new ByteArrayOutputStream();
        keyPair.writePublicKey(publicKeyOutputStream, comment);
        publicKeyOutputStream.close();
        return new String(publicKeyOutputStream.toByteArray());
    }
View Full Code Here

        if (this.pubkeyOnly) {
            throw new DisabledException("SSH key generation is disabled");
        }

        final JSch jsch=new JSch();
        final KeyPair kpair;
        try {
            kpair = KeyPair.genKeyPair(jsch, this.keyType, this.keySize);
        } catch (JSchException e) {
            throw new KeyGenException(e.getMessage(), e);
        }

        final String generatedFingerprint = kpair.getFingerPrint();
        if (generatedFingerprint == null) {
            throw new KeyGenException("fingerprint is missing");
        }
        final String[] parts = generatedFingerprint.split(" ");
        if (parts.length != 2) {
            throw new KeyGenException("fingerprint not in expected " +
                    "format: '" + generatedFingerprint + "'");
        }

        final String fingerprint = parts[1];
        if (fingerprint == null || fingerprint.trim().length() == 0) {
            throw new KeyGenException("fingerprint not in expected " +
                    "format: '" + generatedFingerprint + "'");
        }
       
        final StringOutputStream pubsos = new StringOutputStream();
        final StringOutputStream privsos = new StringOutputStream();

        kpair.writePublicKey(pubsos, "clouduser-" + ownerID);
        kpair.writePrivateKey(privsos);

        final String pubKeyString = pubsos.toString();
        if (pubKeyString == null || pubKeyString.trim().length() == 0) {
            throw new KeyGenException("generated pubkey is missing");
        }
View Full Code Here

      publicKeyPath = (publicKeyPath == null && privateKeyPath != null) ?
                privateKeyPath + ".pub" : publicKeyPath;
      if(privateKeyPath != null && publicKeyPath != null) {
        pairRepresentation = "(" + privateKeyPath + ", " +
            publicKeyPath + ")";
        KeyPair pair = KeyPair.load(new JSch(), privateKeyPath, publicKeyPath);
        if (pair.isEncrypted()) {
          throw new ConfigurationException("Key pair " + pairRepresentation +
              " is encrypted. Try generating a new passwordless SSH keypair " +
              "(e.g. with ssh-keygen).");
        }
        if (!sameKeyPair(new File(privateKeyPath), new File(publicKeyPath))) {
View Full Code Here

   * @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;
  }
View Full Code Here

   *             if the key could not be created
   */
  public static SSHKeyPair create(SSHKeyType type, String passPhrase, String privateKeyPath, String publicKeyPath)
      throws OpenShiftException {
    try {
      KeyPair keyPair = KeyPair.genKeyPair(new JSch(), KeyPair.RSA, KEYLENGTH);
      keyPair.setPassphrase(passPhrase);
      keyPair.writePublicKey(publicKeyPath, "created by " + ID);
      keyPair.writePrivateKey(privateKeyPath);
      return new SSHKeyPair(keyPair, privateKeyPath, publicKeyPath, SSHKeyType.SSH_RSA);
    } catch (Exception e) {
      throw new OpenShiftException(e, "Could not create new rsa key", e);
    }
  }
View Full Code Here

   * @throws OpenShiftException
   */
  public static SSHKeyPair load(String privateKeyPath, String publicKeyPath)
      throws OpenShiftException {
    try {
      KeyPair keyPair = KeyPair.load(new JSch(), privateKeyPath, publicKeyPath);
      return new SSHKeyPair(keyPair, privateKeyPath, publicKeyPath, SSHKeyType.getByJSchKeyType(keyPair));
    } catch (JSchException e) {
      throw new OpenShiftException(e, "Could not create new ssh key");
    }
  }
View Full Code Here

      String publicKeyPath = c.getString(Property.PUBLIC_KEY_FILE.getConfigName());
      publicKeyPath = (publicKeyPath == null && privateKeyPath != null) ?
                privateKeyPath + ".pub" : publicKeyPath;
      if(privateKeyPath != null && publicKeyPath != null) {
        KeyPair pair = KeyPair.load(new JSch(), privateKeyPath, publicKeyPath);
        if (pair.isEncrypted()) {
          throw new ConfigurationException("Key pair is encrypted");
        }
        if (!sameKeyPair(new File(privateKeyPath), new File(publicKeyPath))) {
          throw new ConfigurationException("Both keys should belong " +
              "to the same key pair");
View Full Code Here

                    throw new IOException("Could not delete temp public key");
                }
            }
            System.out.println("Generating test key-pair.");
            JSch jsch = new JSch();
            KeyPair kpair = KeyPair.genKeyPair(jsch, KeyPair.RSA);

            kpair.writePrivateKey(new FileOutputStream(priv));
            kpair.writePublicKey(new FileOutputStream(pub), "Test");
            System.out.println("Finger print: " + kpair.getFingerPrint());
            kpair.dispose();
            return new KeyPairFiles(priv, pub);
        } else {
            System.out.println("Test key-pair seems to already exist.");
            return new KeyPairFiles(priv, pub);
        }
View Full Code Here

TOP

Related Classes of com.jcraft.jsch.KeyPair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.