ssh.h revision 60576
1/* 2 * 3 * ssh.h 4 * 5 * Author: Tatu Ylonen <ylo@cs.hut.fi> 6 * 7 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 8 * All rights reserved 9 * 10 * Created: Fri Mar 17 17:09:37 1995 ylo 11 * 12 * Generic header file for ssh. 13 * 14 * $FreeBSD: head/crypto/openssh/ssh.h 60576 2000-05-15 05:24:25Z kris $ 15 */ 16 17/* RCSID("$Id: ssh.h,v 1.45 2000/05/08 17:12:16 markus Exp $"); */ 18 19#ifndef SSH_H 20#define SSH_H 21 22#include "rsa.h" 23#include "cipher.h" 24 25/* 26 * XXX 27 * The default cipher used if IDEA is not supported by the remote host. It is 28 * recommended that this be one of the mandatory ciphers (DES, 3DES), though 29 * that is not required. 30 */ 31#define SSH_FALLBACK_CIPHER SSH_CIPHER_3DES 32 33/* Cipher used for encrypting authentication files. */ 34#define SSH_AUTHFILE_CIPHER SSH_CIPHER_3DES 35 36/* Default port number. */ 37#define SSH_DEFAULT_PORT 22 38 39/* Maximum number of TCP/IP ports forwarded per direction. */ 40#define SSH_MAX_FORWARDS_PER_DIRECTION 100 41 42/* 43 * Maximum number of RSA authentication identity files that can be specified 44 * in configuration files or on the command line. 45 */ 46#define SSH_MAX_IDENTITY_FILES 100 47 48/* 49 * Major protocol version. Different version indicates major incompatiblity 50 * that prevents communication. 51 * 52 * Minor protocol version. Different version indicates minor incompatibility 53 * that does not prevent interoperation. 54 */ 55#define PROTOCOL_MAJOR_1 1 56#define PROTOCOL_MINOR_1 5 57 58/* We support both SSH1 and SSH2 */ 59#define PROTOCOL_MAJOR_2 2 60#define PROTOCOL_MINOR_2 0 61 62/* 63 * Name for the service. The port named by this service overrides the 64 * default port if present. 65 */ 66#define SSH_SERVICE_NAME "ssh" 67 68#define ETCDIR "/etc/ssh" 69#define PIDDIR "/var/run" 70 71/* 72 * System-wide file containing host keys of known hosts. This file should be 73 * world-readable. 74 */ 75#define SSH_SYSTEM_HOSTFILE ETCDIR "/ssh_known_hosts" 76#define SSH_SYSTEM_HOSTFILE2 ETCDIR "/ssh_known_hosts2" 77 78/* 79 * Of these, ssh_host_key must be readable only by root, whereas ssh_config 80 * should be world-readable. 81 */ 82#define HOST_KEY_FILE ETCDIR "/ssh_host_key" 83#define SERVER_CONFIG_FILE ETCDIR "/sshd_config" 84#define HOST_CONFIG_FILE ETCDIR "/ssh_config" 85#define HOST_DSA_KEY_FILE ETCDIR "/ssh_host_dsa_key" 86 87#define SSH_PROGRAM "/usr/bin/ssh" 88 89/* 90 * The process id of the daemon listening for connections is saved here to 91 * make it easier to kill the correct daemon when necessary. 92 */ 93#define SSH_DAEMON_PID_FILE PIDDIR "/sshd.pid" 94 95/* 96 * The directory in user\'s home directory in which the files reside. The 97 * directory should be world-readable (though not all files are). 98 */ 99#define SSH_USER_DIR ".ssh" 100 101/* 102 * Per-user file containing host keys of known hosts. This file need not be 103 * readable by anyone except the user him/herself, though this does not 104 * contain anything particularly secret. 105 */ 106#define SSH_USER_HOSTFILE "~/.ssh/known_hosts" 107#define SSH_USER_HOSTFILE2 "~/.ssh/known_hosts2" 108 109/* 110 * Name of the default file containing client-side authentication key. This 111 * file should only be readable by the user him/herself. 112 */ 113#define SSH_CLIENT_IDENTITY ".ssh/identity" 114#define SSH_CLIENT_ID_DSA ".ssh/id_dsa" 115 116/* 117 * Configuration file in user\'s home directory. This file need not be 118 * readable by anyone but the user him/herself, but does not contain anything 119 * particularly secret. If the user\'s home directory resides on an NFS 120 * volume where root is mapped to nobody, this may need to be world-readable. 121 */ 122#define SSH_USER_CONFFILE ".ssh/config" 123 124/* 125 * File containing a list of those rsa keys that permit logging in as this 126 * user. This file need not be readable by anyone but the user him/herself, 127 * but does not contain anything particularly secret. If the user\'s home 128 * directory resides on an NFS volume where root is mapped to nobody, this 129 * may need to be world-readable. (This file is read by the daemon which is 130 * running as root.) 131 */ 132#define SSH_USER_PERMITTED_KEYS ".ssh/authorized_keys" 133#define SSH_USER_PERMITTED_KEYS2 ".ssh/authorized_keys2" 134 135/* 136 * Per-user and system-wide ssh "rc" files. These files are executed with 137 * /bin/sh before starting the shell or command if they exist. They will be 138 * passed "proto cookie" as arguments if X11 forwarding with spoofing is in 139 * use. xauth will be run if neither of these exists. 140 */ 141#define SSH_USER_RC ".ssh/rc" 142#define SSH_SYSTEM_RC ETCDIR "/sshrc" 143 144/* 145 * Ssh-only version of /etc/hosts.equiv. Additionally, the daemon may use 146 * ~/.rhosts and /etc/hosts.equiv if rhosts authentication is enabled. 147 */ 148#define SSH_HOSTS_EQUIV ETCDIR "/shosts.equiv" 149 150/* 151 * Name of the environment variable containing the pathname of the 152 * authentication socket. 153 */ 154#define SSH_AUTHSOCKET_ENV_NAME "SSH_AUTH_SOCK" 155 156/* 157 * Name of the environment variable containing the pathname of the 158 * authentication socket. 159 */ 160#define SSH_AGENTPID_ENV_NAME "SSH_AGENT_PID" 161 162/* 163 * Default path to ssh-askpass used by ssh-add, 164 * environment variable for overwriting the default location 165 */ 166#define SSH_ASKPASS_DEFAULT "/usr/X11R6/bin/ssh-askpass" 167#define SSH_ASKPASS_ENV "SSH_ASKPASS" 168 169/* 170 * Force host key length and server key length to differ by at least this 171 * many bits. This is to make double encryption with rsaref work. 172 */ 173#define SSH_KEY_BITS_RESERVED 128 174 175/* 176 * Length of the session key in bytes. (Specified as 256 bits in the 177 * protocol.) 178 */ 179#define SSH_SESSION_KEY_LENGTH 32 180 181/* Name of Kerberos service for SSH to use. */ 182#define KRB4_SERVICE_NAME "rcmd" 183 184/* 185 * Authentication methods. New types can be added, but old types should not 186 * be removed for compatibility. The maximum allowed value is 31. 187 */ 188#define SSH_AUTH_RHOSTS 1 189#define SSH_AUTH_RSA 2 190#define SSH_AUTH_PASSWORD 3 191#define SSH_AUTH_RHOSTS_RSA 4 192#define SSH_AUTH_TIS 5 193#define SSH_AUTH_KRB4 6 194#define SSH_PASS_KRB4_TGT 7 195 /* 8 to 15 are reserved */ 196#define SSH_PASS_AFS_TOKEN 21 197 198#define SSH_AUTH_KRB5 29 199#define SSH_PASS_KRB5_TGT 30 200 201/* Protocol flags. These are bit masks. */ 202#define SSH_PROTOFLAG_SCREEN_NUMBER 1 /* X11 forwarding includes screen */ 203#define SSH_PROTOFLAG_HOST_IN_FWD_OPEN 2 /* forwarding opens contain host */ 204 205/* 206 * Definition of message types. New values can be added, but old values 207 * should not be removed or without careful consideration of the consequences 208 * for compatibility. The maximum value is 254; value 255 is reserved for 209 * future extension. 210 */ 211/* Message name */ /* msg code */ /* arguments */ 212#define SSH_MSG_NONE 0 /* no message */ 213#define SSH_MSG_DISCONNECT 1 /* cause (string) */ 214#define SSH_SMSG_PUBLIC_KEY 2 /* ck,msk,srvk,hostk */ 215#define SSH_CMSG_SESSION_KEY 3 /* key (BIGNUM) */ 216#define SSH_CMSG_USER 4 /* user (string) */ 217#define SSH_CMSG_AUTH_RHOSTS 5 /* user (string) */ 218#define SSH_CMSG_AUTH_RSA 6 /* modulus (BIGNUM) */ 219#define SSH_SMSG_AUTH_RSA_CHALLENGE 7 /* int (BIGNUM) */ 220#define SSH_CMSG_AUTH_RSA_RESPONSE 8 /* int (BIGNUM) */ 221#define SSH_CMSG_AUTH_PASSWORD 9 /* pass (string) */ 222#define SSH_CMSG_REQUEST_PTY 10 /* TERM, tty modes */ 223#define SSH_CMSG_WINDOW_SIZE 11 /* row,col,xpix,ypix */ 224#define SSH_CMSG_EXEC_SHELL 12 /* */ 225#define SSH_CMSG_EXEC_CMD 13 /* cmd (string) */ 226#define SSH_SMSG_SUCCESS 14 /* */ 227#define SSH_SMSG_FAILURE 15 /* */ 228#define SSH_CMSG_STDIN_DATA 16 /* data (string) */ 229#define SSH_SMSG_STDOUT_DATA 17 /* data (string) */ 230#define SSH_SMSG_STDERR_DATA 18 /* data (string) */ 231#define SSH_CMSG_EOF 19 /* */ 232#define SSH_SMSG_EXITSTATUS 20 /* status (int) */ 233#define SSH_MSG_CHANNEL_OPEN_CONFIRMATION 21 /* channel (int) */ 234#define SSH_MSG_CHANNEL_OPEN_FAILURE 22 /* channel (int) */ 235#define SSH_MSG_CHANNEL_DATA 23 /* ch,data (int,str) */ 236#define SSH_MSG_CHANNEL_CLOSE 24 /* channel (int) */ 237#define SSH_MSG_CHANNEL_CLOSE_CONFIRMATION 25 /* channel (int) */ 238/* SSH_CMSG_X11_REQUEST_FORWARDING 26 OBSOLETE */ 239#define SSH_SMSG_X11_OPEN 27 /* channel (int) */ 240#define SSH_CMSG_PORT_FORWARD_REQUEST 28 /* p,host,hp (i,s,i) */ 241#define SSH_MSG_PORT_OPEN 29 /* ch,h,p (i,s,i) */ 242#define SSH_CMSG_AGENT_REQUEST_FORWARDING 30 /* */ 243#define SSH_SMSG_AGENT_OPEN 31 /* port (int) */ 244#define SSH_MSG_IGNORE 32 /* string */ 245#define SSH_CMSG_EXIT_CONFIRMATION 33 /* */ 246#define SSH_CMSG_X11_REQUEST_FORWARDING 34 /* proto,data (s,s) */ 247#define SSH_CMSG_AUTH_RHOSTS_RSA 35 /* user,mod (s,mpi) */ 248#define SSH_MSG_DEBUG 36 /* string */ 249#define SSH_CMSG_REQUEST_COMPRESSION 37 /* level 1-9 (int) */ 250#define SSH_CMSG_MAX_PACKET_SIZE 38 /* size 4k-1024k (int) */ 251#define SSH_CMSG_AUTH_TIS 39 /* we use this for s/key */ 252#define SSH_SMSG_AUTH_TIS_CHALLENGE 40 /* challenge (string) */ 253#define SSH_CMSG_AUTH_TIS_RESPONSE 41 /* response (string) */ 254#define SSH_CMSG_AUTH_KRB4 42 /* (KTEXT) */ 255#define SSH_SMSG_AUTH_KRB4_RESPONSE 43 /* (KTEXT) */ 256#define SSH_CMSG_HAVE_KRB4_TGT 44 /* credentials (s) */ 257#define SSH_CMSG_HAVE_AFS_TOKEN 65 /* token (s) */ 258 259#define SSH_CMSG_AUTH_KRB5 110 260#define SSH_SMSG_AUTH_KRB5_RESPONSE 111 261#define SSH_CMSG_HAVE_KRB5_TGT 112 262 263/*------------ definitions for login.c -------------*/ 264 265/* 266 * Returns the time when the user last logged in. Returns 0 if the 267 * information is not available. This must be called before record_login. 268 * The host from which the user logged in is stored in buf. 269 */ 270unsigned long 271get_last_login_time(uid_t uid, const char *logname, 272 char *buf, unsigned int bufsize); 273 274/* 275 * Records that the user has logged in. This does many things normally done 276 * by login(1). 277 */ 278void 279record_login(pid_t pid, const char *ttyname, const char *user, uid_t uid, 280 const char *host, struct sockaddr *addr); 281 282/* 283 * Records that the user has logged out. This does many thigs normally done 284 * by login(1) or init. 285 */ 286void record_logout(pid_t pid, const char *ttyname); 287 288/*------------ definitions for sshconnect.c ----------*/ 289 290/* 291 * Opens a TCP/IP connection to the remote server on the given host. If port 292 * is 0, the default port will be used. If anonymous is zero, a privileged 293 * port will be allocated to make the connection. This requires super-user 294 * privileges if anonymous is false. Connection_attempts specifies the 295 * maximum number of tries, one per second. This returns true on success, 296 * and zero on failure. If the connection is successful, this calls 297 * packet_set_connection for the connection. 298 */ 299int 300ssh_connect(const char *host, struct sockaddr_storage * hostaddr, 301 u_short port, int connection_attempts, 302 int anonymous, uid_t original_real_uid, 303 const char *proxy_command); 304 305/* 306 * Starts a dialog with the server, and authenticates the current user on the 307 * server. This does not need any extra privileges. The basic connection to 308 * the server must already have been established before this is called. If 309 * login fails, this function prints an error and never returns. This 310 * initializes the random state, and leaves it initialized (it will also have 311 * references from the packet module). 312 */ 313 314void 315ssh_login(int host_key_valid, RSA * host_key, const char *host, 316 struct sockaddr * hostaddr, uid_t original_real_uid); 317 318/*------------ Definitions for various authentication methods. -------*/ 319 320/* 321 * Tries to authenticate the user using the .rhosts file. Returns true if 322 * authentication succeeds. If ignore_rhosts is non-zero, this will not 323 * consider .rhosts and .shosts (/etc/hosts.equiv will still be used). 324 */ 325int auth_rhosts(struct passwd * pw, const char *client_user); 326 327/* 328 * Tries to authenticate the user using the .rhosts file and the host using 329 * its host key. Returns true if authentication succeeds. 330 */ 331int 332auth_rhosts_rsa(struct passwd * pw, const char *client_user, RSA* client_host_key); 333 334/* 335 * Tries to authenticate the user using password. Returns true if 336 * authentication succeeds. 337 */ 338int auth_password(struct passwd * pw, const char *password); 339 340/* 341 * Performs the RSA authentication dialog with the client. This returns 0 if 342 * the client could not be authenticated, and 1 if authentication was 343 * successful. This may exit if there is a serious protocol violation. 344 */ 345int auth_rsa(struct passwd * pw, BIGNUM * client_n); 346 347/* 348 * Parses an RSA key (number of bits, e, n) from a string. Moves the pointer 349 * over the key. Skips any whitespace at the beginning and at end. 350 */ 351int auth_rsa_read_key(char **cpp, unsigned int *bitsp, BIGNUM * e, BIGNUM * n); 352 353/* 354 * Returns the name of the machine at the other end of the socket. The 355 * returned string should be freed by the caller. 356 */ 357char *get_remote_hostname(int socket); 358 359/* 360 * Return the canonical name of the host in the other side of the current 361 * connection (as returned by packet_get_connection). The host name is 362 * cached, so it is efficient to call this several times. 363 */ 364const char *get_canonical_hostname(void); 365 366/* 367 * Returns the remote IP address as an ascii string. The value need not be 368 * freed by the caller. 369 */ 370const char *get_remote_ipaddr(void); 371 372/* Returns the port number of the peer of the socket. */ 373int get_peer_port(int sock); 374 375/* Returns the port number of the remote/local host. */ 376int get_remote_port(void); 377int get_local_port(void); 378 379 380/* 381 * Performs the RSA authentication challenge-response dialog with the client, 382 * and returns true (non-zero) if the client gave the correct answer to our 383 * challenge; returns zero if the client gives a wrong answer. 384 */ 385int auth_rsa_challenge_dialog(RSA *pk); 386 387/* 388 * Reads a passphrase from /dev/tty with echo turned off. Returns the 389 * passphrase (allocated with xmalloc). Exits if EOF is encountered. If 390 * from_stdin is true, the passphrase will be read from stdin instead. 391 */ 392char *read_passphrase(const char *prompt, int from_stdin); 393 394 395/*------------ Definitions for logging. -----------------------*/ 396 397/* Supported syslog facilities and levels. */ 398typedef enum { 399 SYSLOG_FACILITY_DAEMON, 400 SYSLOG_FACILITY_USER, 401 SYSLOG_FACILITY_AUTH, 402 SYSLOG_FACILITY_LOCAL0, 403 SYSLOG_FACILITY_LOCAL1, 404 SYSLOG_FACILITY_LOCAL2, 405 SYSLOG_FACILITY_LOCAL3, 406 SYSLOG_FACILITY_LOCAL4, 407 SYSLOG_FACILITY_LOCAL5, 408 SYSLOG_FACILITY_LOCAL6, 409 SYSLOG_FACILITY_LOCAL7 410} SyslogFacility; 411 412typedef enum { 413 SYSLOG_LEVEL_QUIET, 414 SYSLOG_LEVEL_FATAL, 415 SYSLOG_LEVEL_ERROR, 416 SYSLOG_LEVEL_INFO, 417 SYSLOG_LEVEL_VERBOSE, 418 SYSLOG_LEVEL_DEBUG 419} LogLevel; 420/* Initializes logging. */ 421void log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr); 422 423/* Logging implementation, depending on server or client */ 424void do_log(LogLevel level, const char *fmt, va_list args); 425 426/* name to facility/level */ 427SyslogFacility log_facility_number(char *name); 428LogLevel log_level_number(char *name); 429 430/* Output a message to syslog or stderr */ 431void fatal(const char *fmt,...) __attribute__((format(printf, 1, 2))); 432void error(const char *fmt,...) __attribute__((format(printf, 1, 2))); 433void log(const char *fmt,...) __attribute__((format(printf, 1, 2))); 434void verbose(const char *fmt,...) __attribute__((format(printf, 1, 2))); 435void debug(const char *fmt,...) __attribute__((format(printf, 1, 2))); 436 437/* same as fatal() but w/o logging */ 438void fatal_cleanup(void); 439 440/* 441 * Registers a cleanup function to be called by fatal()/fatal_cleanup() 442 * before exiting. It is permissible to call fatal_remove_cleanup for the 443 * function itself from the function. 444 */ 445void fatal_add_cleanup(void (*proc) (void *context), void *context); 446 447/* Removes a cleanup function to be called at fatal(). */ 448void fatal_remove_cleanup(void (*proc) (void *context), void *context); 449 450/* ---- misc */ 451 452/* 453 * Expands tildes in the file name. Returns data allocated by xmalloc. 454 * Warning: this calls getpw*. 455 */ 456char *tilde_expand_filename(const char *filename, uid_t my_uid); 457 458/* 459 * Performs the interactive session. This handles data transmission between 460 * the client and the program. Note that the notion of stdin, stdout, and 461 * stderr in this function is sort of reversed: this function writes to stdin 462 * (of the child program), and reads from stdout and stderr (of the child 463 * program). 464 */ 465void server_loop(pid_t pid, int fdin, int fdout, int fderr); 466void server_loop2(void); 467 468/* Client side main loop for the interactive session. */ 469int client_loop(int have_pty, int escape_char); 470 471/* Linked list of custom environment strings (see auth-rsa.c). */ 472struct envstring { 473 struct envstring *next; 474 char *s; 475}; 476 477/* 478 * Ensure all of data on socket comes through. f==read || f==write 479 */ 480ssize_t atomicio(ssize_t (*f)(), int fd, void *s, size_t n); 481 482#ifdef KRB5 483#include <krb5.h> 484int auth_krb5(); /* XXX Doplnit prototypy */ 485int auth_krb5_tgt(); 486int krb5_init(); 487void krb5_cleanup_proc(void *ignore); 488int auth_krb5_password(struct passwd *pw, const char *password); 489#endif /* KRB5 */ 490 491#ifdef KRB4 492#include <krb.h> 493/* 494 * Performs Kerberos v4 mutual authentication with the client. This returns 0 495 * if the client could not be authenticated, and 1 if authentication was 496 * successful. This may exit if there is a serious protocol violation. 497 */ 498int auth_krb4(const char *server_user, KTEXT auth, char **client); 499int krb4_init(uid_t uid); 500void krb4_cleanup_proc(void *ignore); 501int auth_krb4_password(struct passwd * pw, const char *password); 502 503#ifdef AFS 504#include <kafs.h> 505 506/* Accept passed Kerberos v4 ticket-granting ticket and AFS tokens. */ 507int auth_krb4_tgt(struct passwd * pw, const char *string); 508int auth_afs_token(struct passwd * pw, const char *token_string); 509 510int creds_to_radix(CREDENTIALS * creds, unsigned char *buf, size_t buflen); 511int radix_to_creds(const char *buf, CREDENTIALS * creds); 512#endif /* AFS */ 513 514#endif /* KRB4 */ 515 516#ifdef SKEY 517#include <opie.h> 518char *skey_fake_keyinfo(char *username); 519int auth_skey_password(struct passwd * pw, const char *password); 520#endif /* SKEY */ 521 522/* AF_UNSPEC or AF_INET or AF_INET6 */ 523extern int IPv4or6; 524 525#endif /* SSH_H */ 526