comparison src/ch/ethz/ssh2/Connection.java @ 285:486df527ddc5 ganymed

start conversion from trilead to ganymed
author Carl Byington <carl@five-ten-sg.com>
date Fri, 18 Jul 2014 18:33:40 -0700
parents 91a31873c42a
children db9b028016de
comparison
equal deleted inserted replaced
284:4ec87de11e71 285:486df527ddc5
499 throw new IllegalArgumentException("pemPrivateKey argument is null"); 499 throw new IllegalArgumentException("pemPrivateKey argument is null");
500 } 500 }
501 501
502 authenticated = am.authenticatePublicKey(user, pemPrivateKey, password, getOrCreateSecureRND()); 502 authenticated = am.authenticatePublicKey(user, pemPrivateKey, password, getOrCreateSecureRND());
503 503
504 return authenticated;
505 }
506
507 /**
508 * After a successful connect, one has to authenticate oneself. The
509 * authentication method "publickey" works by signing a challenge sent by
510 * the server. The signature is either DSA or RSA based - it just depends on
511 * the type of private key you specify, either a DSA or RSA private key in
512 * PEM format. And yes, this is may seem to be a little confusing, the
513 * method is called "publickey" in the SSH-2 protocol specification, however
514 * since we need to generate a signature, you actually have to supply a
515 * private key =).
516 * <p>
517 * If the authentication phase is complete, <code>true</code> will be
518 * returned. If the server does not accept the request (or if further
519 * authentication steps are needed), <code>false</code> is returned and
520 * one can retry either by using this or any other authentication method
521 * (use the <code>getRemainingAuthMethods</code> method to get a list of
522 * the remaining possible methods).
523 *
524 * @param user
525 * A <code>String</code> holding the username.
526 * @param pair
527 * A <code>RSAPrivateKey</code> or <code>DSAPrivateKey</code>
528 * containing a DSA or RSA private key of
529 * the user in Trilead object format.
530 *
531 * @return whether the connection is now authenticated.
532 * @throws IOException
533 */
534
535 public synchronized boolean authenticateWithPublicKey(String user, KeyPair pair)
536 throws IOException {
537 if (tm == null)
538 throw new IllegalStateException("Connection is not established!");
539
540 if (authenticated)
541 throw new IllegalStateException("Connection is already authenticated!");
542
543 if (am == null)
544 am = new AuthenticationManager(tm);
545
546 if (cm == null)
547 cm = new ChannelManager(tm);
548
549 if (user == null)
550 throw new IllegalArgumentException("user argument is null");
551
552 if (pair == null)
553 throw new IllegalArgumentException("Key pair argument is null");
554
555 authenticated = am.authenticatePublicKey(user, pair, getOrCreateSecureRND());
504 return authenticated; 556 return authenticated;
505 } 557 }
506 558
507 /** 559 /**
508 * A convenience wrapper function which reads in a private key (PEM format, either DSA or RSA) 560 * A convenience wrapper function which reads in a private key (PEM format, either DSA or RSA)