src/vsl_api.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2006, Internet2
00003  * Legal conditions are in file LICENSE
00004  * (MD5 = c434f2e53b8089d8b4d0172c7ce07360).
00005  */
00006 
00007 /**
00008  *
00009  * @file   vsl_api.h
00010  * @author Nikolaus Rath
00011  * @brief  Security Layer API declarations
00012  *
00013  */
00014 
00015 #ifndef VSL_API_H
00016 #define VSL_API_H
00017 
00018 #include "vfer_api.h"
00019 
00020 //! VSL main key length
00021 #define VSL_KEYLEN 32
00022 
00023 //! VSL encryption key length
00024 #define VSL_ENC_KEYLEN 16
00025 
00026 //! VSL MAC length
00027 #define VSL_MACLEN 16
00028 
00029 //! VSL MAC key length
00030 #define VSL_AUTH_KEYLEN 32
00031 
00032 //! VSL authentication types
00033 typedef enum {
00034     VSL_AUTH_SSH,
00035     VSL_AUTH_DH,
00036 } vsl_auth_t;
00037 
00038 //! VSL errorcodes
00039 typedef enum {
00040     VSL_BADPROT = -255,         //!< protocol error
00041     VSL_MAXMSG,                 //!< maximum message count reached
00042     VSL_ERRNO,                  //!< system call failed
00043     VSL_SSHF,                   //!< ssh process failed
00044     VSL_TOOBIG,                 //!< message too big
00045 
00046     //! temporary server error (ssh starting mode)
00047     VSL_TEMP=20,
00048     //! permanent server error (ssh starting mode)
00049     VSL_PERM,
00050 } vsl_errcode_t;
00051 
00052 //! VSL socket structure
00053 typedef struct {
00054     vfer_fd vfd;               //!< underlying vfer socket identifier
00055      vsl_auth_t auth;           //!< type of authentication performed
00056      unsigned char enc_send_key[VSL_ENC_KEYLEN]; //!< encrytion key for sending
00057      unsigned char enc_recv_key[VSL_ENC_KEYLEN]; //!< encrytion key for receiving
00058      unsigned char auth_send_key[VSL_AUTH_KEYLEN]; //!< authentication key for sending
00059      unsigned char auth_recv_key[VSL_AUTH_KEYLEN]; //!< authentication key for receiving
00060      uint64_t sent_nr;          //!< nr of last sent packet
00061      uint64_t recv_nr;          //!< nr of last received packet
00062      int status;                //!< connection status
00063      int selectmark;            //!< select marks for this socket
00064      int selectres; //!< results of the last select call for this socket
00065      pid_t ssh_pid;         //!< pid of ssh process (client mode only)
00066     int ssh_pid_stat;        //!< exit status of ssh process if received by vsl_select().
00067      int ssh_stdin_fd; //!< fd of ssh process stdin (client mode only)
00068      int ssh_stdout_fd; //!< fd of ssh process stdout (client mode only)
00069     int ssh_stderr_fd; //!< fd of ssh process stderr (client mode only)
00070     bool test_mode; //!< whether the socket is in special testing mode
00071 } vsl_sock;
00072 
00073 
00074 //! VSL socket select markers
00075 typedef enum {
00076     VSL_READABLE=1,             //!< ready to read
00077     VSL_WRITABLE=2,             //!< ready to write
00078     VSL_EXCEPTION=4,            //!< exception occured
00079     VSL_AUTHABLE=8,             //!< ready fror next authentication step
00080 } vsl_sock_mark_t;
00081 
00082 
00083 /*
00084  * function prototypes
00085  */
00086 
00087 // Global init+destruct
00088 int vsl_init            (void);
00089 int vsl_uninit          (void);
00090 
00091 // Socket init+destruct
00092 int vsl_socket          (vsl_sock* socket, const vfer_fd vfd);
00093 void vsl_close          (vsl_sock* socket);
00094 
00095 // Handshake
00096 int vsl_connect_ssh     (vsl_sock* sock, const char* host, const char* user,
00097                          const char* cmd, int argc, const char* const *argv, char* errmsg);
00098 int vsl_accept_ssh      (vsl_sock* sock);
00099 
00100 // IO Multiplexing
00101 int vsl_selectmark      (vsl_sock* socket, int mark);
00102 int vsl_selecttest      (vsl_sock* socket);
00103 int vsl_select          (int len, vsl_sock **socks, struct timeval *timeout);
00104 int vsl_selectpoll(int len, vsl_sock** socks, struct timeval *stimeout, int usec);
00105 
00106 
00107 // Information
00108 char* vsl_errortext     (int err);
00109 vfer_fd vsl_vferfd      (vsl_sock* socket);
00110 ssize_t vsl_max_frame_size  (vsl_sock* socket);
00111 
00112 // Sending and receiving
00113 ssize_t vsl_send            (vsl_sock* socket, const void * buf, size_t len);
00114 ssize_t vsl_recv            (vsl_sock* socket, void *buf, size_t len);
00115 ssize_t vsl_sendfile        (vsl_sock* socket, int fd, off_t offset, size_t size);
00116 ssize_t vsl_recvfile        (vsl_sock* socket, int fd, off_t offset, size_t size);
00117 
00118 // Testing and debugging
00119 extern FILE* debug;
00120 void vsl_debug          (FILE* fp, const char* vfer);
00121 void vsl_test_mode(vsl_sock* sock);
00122 
00123 
00124 #endif
00125 
00126 /*
00127  * Local Variables:
00128  * compile-command: "cd ..; make tests file_xfer"
00129  * compilation-search-path: ("..")
00130  * End:
00131  */

Generated on Tue Aug 8 16:07:19 2006 for VFER by  doxygen 1.4.7