Package com.sshtools.j2ssh.transport.publickey

Examples of com.sshtools.j2ssh.transport.publickey.SshPrivateKeyFile


            // Initialize the authentication data.
            PublicKeyAuthenticationClient publicKeyAuth = new PublicKeyAuthenticationClient();

            publicKeyAuth.setUsername(username);

            SshPrivateKeyFile file = SshPrivateKeyFile.parse( key );
            SshPrivateKey privateKey = file.toPrivateKey( keyPassPhrase );
            publicKeyAuth.setKey( privateKey );

            // Authenticate
            int result = sshClient.authenticate( publicKeyAuth );
            if( result != AuthenticationProtocolState.COMPLETE )
View Full Code Here


            });

            // Initialize the authentication data.
            PublicKeyAuthenticationClient publicKeyAuth = new PublicKeyAuthenticationClient();
            publicKeyAuth.setUsername("ec2-user");
            SshPrivateKeyFile file = SshPrivateKeyFile.parse(new File(PRIVATE_KEY_FILE_PATH));
            SshPrivateKey privateKey = file.toPrivateKey("");
            publicKeyAuth.setKey(privateKey);

            // Authenticate
            int result = sshClient.authenticate(publicKeyAuth);
            if(result== AuthenticationProtocolState.FAILED) {
View Full Code Here

                Log.out("keyfile-auth: " + keyfile);

                PublicKeyAuthenticationClient pk = new PublicKeyAuthenticationClient();
                pk.setUsername(user);

                SshPrivateKeyFile file = SshPrivateKeyFile.parse(new File(keyfile));
                SshPrivateKey key = file.toPrivateKey(pass);

                pk.setKey(key);
                result = ssh.authenticate(pk);
            }
View Full Code Here

            });
            GFacUtils.updateApplicationJobStatus(jobExecutionContext, jobId, ApplicationJobStatus.AUTHENTICATE);
            // Initialize the authentication data.
            PublicKeyAuthenticationClient publicKeyAuth = new PublicKeyAuthenticationClient();
            publicKeyAuth.setUsername(amazonSecurityContext.getUserName());
            SshPrivateKeyFile file = SshPrivateKeyFile.
                    parse(new File(System.getProperty("user.home") + "/.ssh/" + KEY_PAIR_NAME));
            SshPrivateKey privateKey = file.toPrivateKey("");
            publicKeyAuth.setKey(privateKey);

            // Authenticate
            int result = sshClient.authenticate(publicKeyAuth);
            if(result== AuthenticationProtocolState.FAILED) {
View Full Code Here

            });
            GFacUtils.updateApplicationJobStatus(jobExecutionContext, jobId, ApplicationJobStatus.AUTHENTICATE);
            // Initialize the authentication data.
            PublicKeyAuthenticationClient publicKeyAuth = new PublicKeyAuthenticationClient();
            publicKeyAuth.setUsername(amazonSecurityContext.getUserName());
            SshPrivateKeyFile file = SshPrivateKeyFile.
                    parse(new File(System.getProperty("user.home") + "/.ssh/" + KEY_PAIR_NAME));
            SshPrivateKey privateKey = file.toPrivateKey("");
            publicKeyAuth.setKey(privateKey);

            // Authenticate
            int result = sshClient.authenticate(publicKeyAuth);
            if(result== AuthenticationProtocolState.FAILED) {
View Full Code Here

            });
            GFacUtils.updateApplicationJobStatus(jobExecutionContext, jobId, ApplicationJobStatus.AUTHENTICATE);
            // Initialize the authentication data.
            PublicKeyAuthenticationClient publicKeyAuth = new PublicKeyAuthenticationClient();
            publicKeyAuth.setUsername(amazonSecurityContext.getUserName());
            SshPrivateKeyFile file = SshPrivateKeyFile.
                    parse(new File(System.getProperty("user.home") + "/.ssh/" + KEY_PAIR_NAME));
            SshPrivateKey privateKey = file.toPrivateKey("");
            publicKeyAuth.setKey(privateKey);

            // Authenticate
            int result = sshClient.authenticate(publicKeyAuth);
            if(result== AuthenticationProtocolState.FAILED) {
View Full Code Here

      pk.setUsername(username);
      // Get the private key file
      System.out.print("Path to private key file? ");
      String filename = reader.readLine();
      // Open up the private key file
      SshPrivateKeyFile file =
          SshPrivateKeyFile.parse(new File(filename));
      // If the private key is passphrase protected then ask for the passphrase
      String passphrase = null;
      if (file.isPassphraseProtected()) {
        System.out.print("Enter passphrase? ");
        passphrase = reader.readLine();
      }
      // Get the key
      SshPrivateKey key = file.toPrivateKey(passphrase);
      pk.setKey(key);
      // Try the authentication
      int result = ssh.authenticate(pk);
      // Evaluate the result
      if (result == AuthenticationProtocolState.COMPLETE) {
View Full Code Here

        }

        File keyfile = (instance.getKeyfile() == null) ? null
                                                       : new File(instance.getKeyfile());
        String passphrase = null;
        SshPrivateKeyFile pkf = null;
        SshPrivateKey key;

        if ((keyfile == null) || !keyfile.exists()) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileHidingEnabled(false);
            chooser.setDialogTitle("Select Private Key File For Authentication");

            if (chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
                keyfile = chooser.getSelectedFile();
            } else {
                return false;
            }
        }

        FileInputStream in = null;

        try {
            pkf = SshPrivateKeyFile.parse(keyfile);
        } catch (InvalidSshKeyException iske) {
            JOptionPane.showMessageDialog(parent, iske.getMessage());

            return false;
        } catch (IOException ioe) {
            JOptionPane.showMessageDialog(parent, ioe.getMessage());
        }

        // Now see if its passphrase protected
        if (pkf.isPassphraseProtected()) {
            // Show the passphrase dialog
            Window w = (Window) SwingUtilities.getAncestorOfClass(Window.class,
                    parent);
            PassphraseDialog dialog = null;

            if (w instanceof Frame) {
                dialog = new PassphraseDialog((Frame) w);
            } else if (w instanceof Dialog) {
                dialog = new PassphraseDialog((Dialog) w);
            } else {
                dialog = new PassphraseDialog();
            }

            do {
                dialog.setVisible(true);

                if (dialog.isCancelled()) {
                    return false;
                }

                passphrase = new String(dialog.getPassphrase());

                try {
                    key = pkf.toPrivateKey(passphrase);

                    break;
                } catch (InvalidSshKeyException ihke) {
                    dialog.setMessage("Passphrase Invalid! Try again");
                    dialog.setMessageForeground(Color.red);
                }
            } while (true);
        } else {
            try {
                key = pkf.toPrivateKey(passphrase);
            } catch (InvalidSshKeyException ihke) {
                return false;
            }
        }
View Full Code Here

                }
            });
            // Initialize the authentication data.
            PublicKeyAuthenticationClient publicKeyAuth = new PublicKeyAuthenticationClient();
            publicKeyAuth.setUsername(amazonSecurityContext.getUserName());
            SshPrivateKeyFile file = SshPrivateKeyFile.
                    parse(new File(System.getProperty("user.home") + "/.ssh/" + KEY_PAIR_NAME));
            SshPrivateKey privateKey = file.toPrivateKey("");
            publicKeyAuth.setKey(privateKey);

            // Authenticate
            int result = sshClient.authenticate(publicKeyAuth);
            if(result== AuthenticationProtocolState.FAILED) {
View Full Code Here

        }

        File keyfile = (instance.getKeyfile() == null) ? null
                                                       : new File(instance.getKeyfile());
        String passphrase = null;
        SshPrivateKeyFile pkf = null;
        SshPrivateKey key;

        if ((keyfile == null) || !keyfile.exists()) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileHidingEnabled(false);
            chooser.setDialogTitle("Select Private Key File For Authentication");

            if (chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
                keyfile = chooser.getSelectedFile();
            } else {
                return false;
            }
        }

        FileInputStream in = null;

        try {
            pkf = SshPrivateKeyFile.parse(keyfile);
        } catch (InvalidSshKeyException iske) {
            JOptionPane.showMessageDialog(parent, iske.getMessage());

            return false;
        } catch (IOException ioe) {
            JOptionPane.showMessageDialog(parent, ioe.getMessage());
        }

        // Now see if its passphrase protected
        if (pkf.isPassphraseProtected()) {
            // Show the passphrase dialog
            Window w = (Window) SwingUtilities.getAncestorOfClass(Window.class,
                    parent);
            PassphraseDialog dialog = null;

            if (w instanceof Frame) {
                dialog = new PassphraseDialog((Frame) w);
            } else if (w instanceof Dialog) {
                dialog = new PassphraseDialog((Dialog) w);
            } else {
                dialog = new PassphraseDialog();
            }

            do {
                dialog.setVisible(true);

                if (dialog.isCancelled()) {
                    return false;
                }

                passphrase = new String(dialog.getPassphrase());

                try {
                    key = pkf.toPrivateKey(passphrase);

                    break;
                } catch (InvalidSshKeyException ihke) {
                    dialog.setMessage("Passphrase Invalid! Try again");
                    dialog.setMessageForeground(Color.red);
                }
            } while (true);
        } else {
            try {
                key = pkf.toPrivateKey(passphrase);
            } catch (InvalidSshKeyException ihke) {
                return false;
            }
        }
View Full Code Here

TOP

Related Classes of com.sshtools.j2ssh.transport.publickey.SshPrivateKeyFile

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.