| 1 |
/* |
| 2 |
* Note: this file originally auto-generated by mib2c using |
| 3 |
* : mib2c.scalar.conf,v 1.7 2003/04/08 14:57:04 dts12 Exp $ |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <net-snmp/net-snmp-config.h> |
| 7 |
#include <net-snmp/library/openssl_config.h> |
| 8 |
#include <net-snmp/net-snmp-includes.h> |
| 9 |
#include <net-snmp/library/snmp_openssl.h> |
| 10 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 11 |
#include "usmDHParameters.h" |
| 12 |
|
| 13 |
#include <openssl/dh.h> |
| 14 |
|
| 15 |
static DH *dh_params = NULL; |
| 16 |
|
| 17 |
DH * |
| 18 |
get_dh_params(void) |
| 19 |
{ |
| 20 |
return dh_params; |
| 21 |
} |
| 22 |
|
| 23 |
/** Initializes the usmDHParameters module */ |
| 24 |
void |
| 25 |
init_usmDHParameters(void) |
| 26 |
{ |
| 27 |
BIGNUM *p = NULL, *g = NULL; |
| 28 |
static oid usmDHParameters_oid[] = |
| 29 |
{ 1, 3, 6, 1, 3, 101, 1, 1, 1 }; |
| 30 |
|
| 31 |
DEBUGMSGTL(("usmDHParameters", "Initializing\n")); |
| 32 |
|
| 33 |
netsnmp_register_scalar(netsnmp_create_handler_registration |
| 34 |
("usmDHParameters", handle_usmDHParameters, |
| 35 |
usmDHParameters_oid, |
| 36 |
OID_LENGTH(usmDHParameters_oid), |
| 37 |
HANDLER_CAN_RWRITE)); |
| 38 |
|
| 39 |
/* currently hard coded to the oakly group 2 set. */ |
| 40 |
/* these values are modifiable via SNMP SETs if needed by |
| 41 |
management apps though */ |
| 42 |
if (!dh_params) { |
| 43 |
dh_params = DH_new(); |
| 44 |
BN_hex2bn(&g, "02"); |
| 45 |
BN_hex2bn(&p, "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece65381ffffffffffffffff"); |
| 46 |
DH_set0_pqg(dh_params, p, NULL, g); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
int |
| 51 |
handle_usmDHParameters(netsnmp_mib_handler *handler, |
| 52 |
netsnmp_handler_registration *reginfo, |
| 53 |
netsnmp_agent_request_info *reqinfo, |
| 54 |
netsnmp_request_info *requests) |
| 55 |
{ |
| 56 |
/* |
| 57 |
* We are never called for a GETNEXT if it's registered as a |
| 58 |
* "instance", as it's "magically" handled for us. |
| 59 |
*/ |
| 60 |
|
| 61 |
static unsigned char *cp = NULL; |
| 62 |
static DH *dh_tmpp = NULL; |
| 63 |
int cp_len; |
| 64 |
|
| 65 |
/* |
| 66 |
* a instance handler also only hands us one request at a time, so |
| 67 |
* we don't need to loop over a list of requests; we'll only get one. |
| 68 |
*/ |
| 69 |
|
| 70 |
switch (reqinfo->mode) { |
| 71 |
|
| 72 |
case MODE_GET: |
| 73 |
if(cp) { |
| 74 |
free(cp); |
| 75 |
cp = NULL; |
| 76 |
} |
| 77 |
cp_len = i2d_DHparams(dh_params, &cp); |
| 78 |
if (cp_len > 0) |
| 79 |
snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, |
| 80 |
(u_char *) cp, cp_len); |
| 81 |
break; |
| 82 |
|
| 83 |
/* |
| 84 |
* SET REQUEST |
| 85 |
* |
| 86 |
* multiple states in the transaction. See: |
| 87 |
* http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg |
| 88 |
*/ |
| 89 |
case MODE_SET_RESERVE1: |
| 90 |
break; |
| 91 |
|
| 92 |
case MODE_SET_RESERVE2: |
| 93 |
cp = requests->requestvb->val.string; |
| 94 |
dh_tmpp = d2i_DHparams(NULL, (const unsigned char **) (void *)&cp, |
| 95 |
requests->requestvb->val_len); |
| 96 |
if ( !dh_tmpp) { |
| 97 |
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGVALUE); |
| 98 |
} |
| 99 |
if (cp - requests->requestvb->val.string != |
| 100 |
requests->requestvb->val_len) { |
| 101 |
/* value too long; we didn't parse the whole thing */ |
| 102 |
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGVALUE); |
| 103 |
DH_free(dh_tmpp); |
| 104 |
dh_tmpp = NULL; |
| 105 |
} |
| 106 |
break; |
| 107 |
|
| 108 |
case MODE_SET_FREE: |
| 109 |
case MODE_SET_COMMIT: |
| 110 |
DH_free(dh_tmpp); |
| 111 |
dh_tmpp = NULL; |
| 112 |
break; |
| 113 |
|
| 114 |
case MODE_SET_ACTION: |
| 115 |
{ |
| 116 |
DH *tmpp; |
| 117 |
tmpp = dh_params; |
| 118 |
dh_params = dh_tmpp; |
| 119 |
dh_tmpp = tmpp; |
| 120 |
break; |
| 121 |
} |
| 122 |
|
| 123 |
case MODE_SET_UNDO: |
| 124 |
{ |
| 125 |
DH_free(dh_params); /* free new value */ |
| 126 |
dh_params = dh_tmpp; /* restore old value */ |
| 127 |
dh_tmpp = NULL; |
| 128 |
break; |
| 129 |
} |
| 130 |
|
| 131 |
default: |
| 132 |
/* |
| 133 |
* we should never get here, so this is a really bad error |
| 134 |
*/ |
| 135 |
return SNMP_ERR_GENERR; |
| 136 |
} |
| 137 |
|
| 138 |
return SNMP_ERR_NOERROR; |
| 139 |
} |