net-snmp 5.7
snmpusm.h
00001 /*
00002  * snmpusm.h
00003  *
00004  * Header file for USM support.
00005  */
00006 
00007 #ifndef SNMPUSM_H
00008 #define SNMPUSM_H
00009 
00010 #ifdef __cplusplus
00011 extern          "C" {
00012 #endif
00013 
00014 #define WILDCARDSTRING "*"
00015 
00016     /*
00017      * General.
00018      */
00019 #define USM_MAX_ID_LENGTH               1024    /* In bytes. */
00020 #define USM_MAX_SALT_LENGTH             128     /* In BITS. */
00021 #define USM_DES_SALT_LENGTH             64      /* In BITS. */
00022 #define USM_AES_SALT_LENGTH             128     /* In BITS. */
00023 #define USM_MAX_KEYEDHASH_LENGTH        128     /* In BITS. */
00024 
00025 #define USM_TIME_WINDOW                 150
00026 #define USM_MD5_AND_SHA_AUTH_LEN        12      /* bytes */
00027 #define USM_MAX_AUTHSIZE                USM_MD5_AND_SHA_AUTH_LEN
00028 
00029 #define USM_SEC_MODEL_NUMBER            SNMP_SEC_MODEL_USM
00030 
00031     /*
00032      * Structures.
00033      */
00034     struct usmStateReference {
00035         char           *usr_name;
00036         size_t          usr_name_length;
00037         u_char         *usr_engine_id;
00038         size_t          usr_engine_id_length;
00039         oid            *usr_auth_protocol;
00040         size_t          usr_auth_protocol_length;
00041         u_char         *usr_auth_key;
00042         size_t          usr_auth_key_length;
00043         oid            *usr_priv_protocol;
00044         size_t          usr_priv_protocol_length;
00045         u_char         *usr_priv_key;
00046         size_t          usr_priv_key_length;
00047         u_int           usr_sec_level;
00048     };
00049 
00050 
00051     /*
00052      * struct usmUser: a structure to represent a given user in a list 
00053      */
00054     /*
00055      * Note: Any changes made to this structure need to be reflected in
00056      * the following functions: 
00057      */
00058 
00059     struct usmUser;
00060     struct usmUser {
00061         u_char         *engineID;
00062         size_t          engineIDLen;
00063         char           *name;
00064         char           *secName;
00065         oid            *cloneFrom;
00066         size_t          cloneFromLen;
00067         oid            *authProtocol;
00068         size_t          authProtocolLen;
00069         u_char         *authKey;
00070         size_t          authKeyLen;
00071         oid            *privProtocol;
00072         size_t          privProtocolLen;
00073         u_char         *privKey;
00074         size_t          privKeyLen;
00075         u_char         *userPublicString;
00076         size_t          userPublicStringLen;
00077         int             userStatus;
00078         int             userStorageType;
00079        /* these are actually DH * pointers but only if openssl is avail. */
00080         void           *usmDHUserAuthKeyChange;
00081         void           *usmDHUserPrivKeyChange;
00082         struct usmUser *next;
00083         struct usmUser *prev;
00084     };
00085 
00086 
00087 
00088     /*
00089      * Prototypes.
00090      */
00091     struct usmStateReference *usm_malloc_usmStateReference(void);
00092 
00093     void            usm_free_usmStateReference(void *old);
00094 
00095     int             usm_set_usmStateReference_name(struct usmStateReference
00096                                                    *ref, char *name,
00097                                                    size_t name_len);
00098 
00099     int             usm_set_usmStateReference_engine_id(struct
00100                                                         usmStateReference
00101                                                         *ref,
00102                                                         u_char * engine_id,
00103                                                         size_t
00104                                                         engine_id_len);
00105 
00106     int             usm_set_usmStateReference_auth_protocol(struct
00107                                                             usmStateReference
00108                                                             *ref,
00109                                                             oid *
00110                                                             auth_protocol,
00111                                                             size_t
00112                                                             auth_protocol_len);
00113 
00114     int             usm_set_usmStateReference_auth_key(struct
00115                                                        usmStateReference
00116                                                        *ref,
00117                                                        u_char * auth_key,
00118                                                        size_t
00119                                                        auth_key_len);
00120 
00121     int             usm_set_usmStateReference_priv_protocol(struct
00122                                                             usmStateReference
00123                                                             *ref,
00124                                                             oid *
00125                                                             priv_protocol,
00126                                                             size_t
00127                                                             priv_protocol_len);
00128 
00129     int             usm_set_usmStateReference_priv_key(struct
00130                                                        usmStateReference
00131                                                        *ref,
00132                                                        u_char * priv_key,
00133                                                        size_t
00134                                                        priv_key_len);
00135 
00136     int             usm_set_usmStateReference_sec_level(struct
00137                                                         usmStateReference
00138                                                         *ref,
00139                                                         int sec_level);
00140 
00141 #ifdef NETSNMP_ENABLE_TESTING_CODE
00142     void            emergency_print(u_char * field, u_int length);
00143 #endif
00144 
00145     int             asn_predict_int_length(int type, long number,
00146                                            size_t len);
00147 
00148     int             asn_predict_length(int type, u_char * ptr,
00149                                        size_t u_char_len);
00150 
00151     int             usm_set_salt(u_char * iv,
00152                                  size_t * iv_length,
00153                                  u_char * priv_salt,
00154                                  size_t priv_salt_length,
00155                                  u_char * msgSalt);
00156 
00157     int             usm_parse_security_parameters(u_char * secParams,
00158                                                   size_t remaining,
00159                                                   u_char * secEngineID,
00160                                                   size_t * secEngineIDLen,
00161                                                   u_int * boots_uint,
00162                                                   u_int * time_uint,
00163                                                   char *secName,
00164                                                   size_t * secNameLen,
00165                                                   u_char * signature,
00166                                                   size_t *
00167                                                   signature_length,
00168                                                   u_char * salt,
00169                                                   size_t * salt_length,
00170                                                   u_char ** data_ptr);
00171 
00172     int             usm_check_and_update_timeliness(u_char * secEngineID,
00173                                                     size_t secEngineIDLen,
00174                                                     u_int boots_uint,
00175                                                     u_int time_uint,
00176                                                     int *error);
00177 
00178     SecmodSessionCallback usm_open_session;
00179     SecmodOutMsg    usm_secmod_generate_out_msg;
00180     SecmodOutMsg    usm_secmod_generate_out_msg;
00181     SecmodInMsg     usm_secmod_process_in_msg;
00182     int             usm_generate_out_msg(int, u_char *, size_t, int, int,
00183                                          u_char *, size_t, char *, size_t,
00184                                          int, u_char *, size_t, void *,
00185                                          u_char *, size_t *, u_char **,
00186                                          size_t *);
00187     int             usm_rgenerate_out_msg(int, u_char *, size_t, int, int,
00188                                           u_char *, size_t, char *, size_t,
00189                                           int, u_char *, size_t, void *,
00190                                           u_char **, size_t *, size_t *);
00191 
00192     int             usm_process_in_msg(int, size_t, u_char *, int, int,
00193                                        u_char *, size_t, u_char *,
00194                                        size_t *, char *, size_t *,
00195                                        u_char **, size_t *, size_t *,
00196                                        void **, netsnmp_session *, u_char);
00197 
00198     int             usm_check_secLevel(int level, struct usmUser *user);
00199     NETSNMP_IMPORT
00200     struct usmUser *usm_get_userList(void);
00201     NETSNMP_IMPORT
00202     struct usmUser *usm_get_user(u_char * engineID, size_t engineIDLen,
00203                                  char *name);
00204     struct usmUser *usm_get_user_from_list(u_char * engineID,
00205                                            size_t engineIDLen, char *name,
00206                                            struct usmUser *userList,
00207                                            int use_default);
00208     NETSNMP_IMPORT
00209     struct usmUser *usm_add_user(struct usmUser *user);
00210     struct usmUser *usm_add_user_to_list(struct usmUser *user,
00211                                          struct usmUser *userList);
00212     NETSNMP_IMPORT
00213     struct usmUser *usm_free_user(struct usmUser *user);
00214     NETSNMP_IMPORT
00215     struct usmUser *usm_create_user(void);
00216     NETSNMP_IMPORT
00217     struct usmUser *usm_create_initial_user(const char *name,
00218                                             const oid * authProtocol,
00219                                             size_t authProtocolLen,
00220                                             const oid * privProtocol,
00221                                             size_t privProtocolLen);
00222     NETSNMP_IMPORT
00223     struct usmUser *usm_cloneFrom_user(struct usmUser *from,
00224                                        struct usmUser *to);
00225     NETSNMP_IMPORT
00226     struct usmUser *usm_remove_user(struct usmUser *user);
00227     struct usmUser *usm_remove_user_from_list(struct usmUser *user,
00228                                               struct usmUser **userList);
00229     char           *get_objid(char *line, oid ** optr, size_t * len);
00230     NETSNMP_IMPORT
00231     void            usm_save_users(const char *token, const char *type);
00232     void            usm_save_users_from_list(struct usmUser *user,
00233                                              const char *token,
00234                                              const char *type);
00235     void            usm_save_user(struct usmUser *user, const char *token,
00236                                   const char *type);
00237     NETSNMP_IMPORT
00238     SNMPCallback    usm_store_users;
00239     struct usmUser *usm_read_user(const char *line);
00240     NETSNMP_IMPORT
00241     void            usm_parse_config_usmUser(const char *token,
00242                                              char *line);
00243 
00244     void            usm_set_password(const char *token, char *line);
00245     NETSNMP_IMPORT
00246     void            usm_set_user_password(struct usmUser *user,
00247                                           const char *token, char *line);
00248     void            init_usm(void);
00249     NETSNMP_IMPORT
00250     void            init_usm_conf(const char *app);
00251     int             init_usm_post_config(int majorid, int minorid,
00252                                          void *serverarg, void *clientarg);
00253     int             deinit_usm_post_config(int majorid, int minorid, void *serverarg,
00254                                            void *clientarg);
00255     NETSNMP_IMPORT
00256     void            clear_user_list(void);
00257     NETSNMP_IMPORT
00258     void            shutdown_usm(void);
00259 
00260     NETSNMP_IMPORT
00261     int             usm_create_user_from_session(netsnmp_session * session);
00262     SecmodPostDiscovery usm_create_user_from_session_hook;
00263     NETSNMP_IMPORT
00264     void            usm_parse_create_usmUser(const char *token,
00265                                              char *line);
00266     NETSNMP_IMPORT
00267     const oid      *get_default_authtype(size_t *);
00268     NETSNMP_IMPORT
00269     const oid      *get_default_privtype(size_t *);
00270     void            snmpv3_authtype_conf(const char *word, char *cptr);
00271     void            snmpv3_privtype_conf(const char *word, char *cptr);
00272 
00273 #ifdef __cplusplus
00274 }
00275 #endif
00276 #endif                          /* SNMPUSM_H */