資源簡(jiǎn)介
Capabilities and Features
Key Exchange Methods: diffie-hellman-group1-sha1, diffie-hellman-group14-sha1, diffie-hellman-group-exchange-sha1
Hostkey Types: ssh-rsa, ssh-dss
Ciphers: aes256-cbc (rijndael-cbc@lysator.liu.se), aes192-cbc, aes128-cbc, 3des-cbc, blowfish-cbc, cast128-cbc, arcfour, none
Compression Schemes: zlib, none
MAC hashes: hmac-sha1, hmac-sha1-96, hmac-md5, hmac-md5-96, hmac-ripemd160 (hmac-ripemd160@openssh.com), none
Authentication: none, password, public-key, hostbased, keyboard-interactive
Channels: shell, exec (incl. SCP wrapper), direct-tcpip, subsystem
Global Requests: tcpip-forward
Channel Requests: x11, pty
Subsystems: sftp(version 3), publickey(version 2)
Thread-safe: just don't share handles simultaneously
Non-blocking: it can be used both blocking and non-blocking
Your sockets: the app hands over the socket, calls select() etc.
OpenSSL or gcrypt: builds with either
代碼片段和文件信息
#include?“l(fā)ibssh2_config.h“
#include?
#ifdef?WIN32
#include?
#include?
#include?
#else
#include?
#include?
#include?
#include?
#endif
#include?
#include?
#include?
#include?
#include?
#include?
#ifdef?HAVE_SYS_SELECT_H
#include?
#endif
#ifndef?INADDR_NONE
#define?INADDR_NONE?(in_addr_t)-1
#endif
const?char?*keyfile1?=?“/home/username/.ssh/id_rsa.pub“;
const?char?*keyfile2?=?“/home/username/.ssh/id_rsa“;
const?char?*username?=?“username“;
const?char?*password?=?““;
const?char?*server_ip?=?“127.0.0.1“;
const?char?*local_listenip?=?“127.0.0.1“;
unsigned?int?local_listenport?=?2222;
const?char?*remote_desthost?=?“l(fā)ocalhost“;?/*?resolved?by?the?server?*/
unsigned?int?remote_destport?=?22;
enum?{
????AUTH_NONE?=?0
????AUTH_PASSWORD
????AUTH_PUBLICKEY
};
int?main(int?argc?char?*argv[])
{
????int?rc?sock?=?-1?listensock?=?-1?forwardsock?=?-1?i?auth?=?AUTH_NONE;
????struct?sockaddr_in?sin;
????socklen_t?sinlen;
????const?char?*fingerprint;
????char?*userauthlist;
????LIBSSH2_SESSION?*session;
????LIBSSH2_CHANNEL?*channel?=?NULL;
????const?char?*shost;
????unsigned?int?sport;
????fd_set?fds;
????struct?timeval?tv;
????ssize_t?len?wr;
????char?buf[16384];
#ifdef?WIN32
????char?sockopt;
????WSADATA?wsadata;
????WSAStartup(MAKEWORD(20)?&wsadata);
#else
????int?sockopt;
#endif
????if?(argc?>?1)
????????server_ip?=?argv[1];
????if?(argc?>?2)
????????username?=?argv[2];
????if?(argc?>?3)
????????password?=?argv[3];
????if?(argc?>?4)
????????local_listenip?=?argv[4];
????if?(argc?>?5)
????????local_listenport?=?atoi(argv[5]);
????if?(argc?>?6)
????????remote_desthost?=?argv[6];
????if?(argc?>?7)
????????remote_destport?=?atoi(argv[7]);
????rc?=?libssh2_init?(0);
????if?(rc?!=?0)?{
????????fprintf?(stderr?“l(fā)ibssh2?initialization?failed?(%d)\n“?rc);
????????return?1;
????}
????/*?Connect?to?SSH?server?*/
????sock?=?socket(PF_INET?SOCK_STREAM?IPPROTO_TCP);
????sin.sin_family?=?AF_INET;
????if?(INADDR_NONE?==?(sin.sin_addr.s_addr?=?inet_addr(server_ip)))?{
????????perror(“inet_addr“);
????????return?-1;
????}
????sin.sin_port?=?htons(22);
????if?(connect(sock?(struct?sockaddr*)(&sin)
????????????????sizeof(struct?sockaddr_in))?!=?0)?{
????????fprintf(stderr?“failed?to?connect!\n“);
????????return?-1;
????}
????/*?Create?a?session?instance?*/
????session?=?libssh2_session_init();
????if(!session)?{
????????fprintf(stderr?“Could?not?initialize?SSH?session!\n“);
????????return?-1;
????}
????/*?...?start?it?up.?This?will?trade?welcome?banners?exchange?keys
?????*?and?setup?crypto?compression?and?MAC?layers
?????*/
????rc?=?libssh2_session_handshake(session?sock);
????if(rc)?{
????????fprintf(stderr?“Error?when?starting?up?SSH?session:?%d\n“?rc);
????????return?-1;
????}
????/*?At?this?point?we?havn‘t?yet?authenticated.??The?first?thing?to?do
?????*?is?check?
評(píng)論
共有 條評(píng)論