/*******************************************************************-o-****** * dump_etimelist_entry * * Parameters: * e * count */ void dump_etimelist_entry(Enginetime e, int count) { u_int buflen; char tabs[SNMP_MAXBUF], *t = tabs, *s; count += 1; while (count--) { t += sprintf(t, " "); } buflen = e->engineID_len; #ifdef NETSNMP_ENABLE_TESTING_CODE if (!(s = dump_snmpEngineID(e->engineID, &buflen))) { #endif binary_to_hex(e->engineID, e->engineID_len, &s); #ifdef NETSNMP_ENABLE_TESTING_CODE } #endif DEBUGMSGTL(("dump_etimelist", "%s\n", tabs)); DEBUGMSGTL(("dump_etimelist", "%s%s (len=%d) <%d,%d>\n", tabs, s, e->engineID_len, e->engineTime, e->engineBoot)); DEBUGMSGTL(("dump_etimelist", "%s%ld (%ld)", tabs, e->lastReceivedEngineTime, snmpv3_local_snmpEngineTime() - e->lastReceivedEngineTime)); SNMP_FREE(s); } /* end dump_etimelist_entry() */
/*******************************************************************-o-****** * test_dumpseid * * Returns: * Number of failures. * * Test dump_snmpEngineID(). */ int test_dumpseid(void) { int /* rval = SNMPERR_SUCCESS, */ failcount = 0, tlen, count = 0; char buf[SNMP_MAXBUF], *s, *t, *ris, *rawid_set[ID_NUMSTRINGS+1] = { IDBLAT_4, IDVIOLATE1, IDIPv4, IDIPv6, IDMAC, IDTEXT, IDOCTETS_7, IDLOCAL_11, IDIPv4_EXTRA3, NULL }; OUTPUT( "Test of dump_snmpEngineID. " "(Does not report failure or success.)"); while ( (ris = rawid_set[count++]) ) { tlen = hex_to_binary2(ris, strlen(ris), &t); if (ris == IDTEXT) { memset(buf, 0, SNMP_MAXBUF); memcpy(buf, t, tlen); tlen += sprintf(buf+tlen, "%s", PRINTABLE); SNMP_FREE(t); t = buf; } #ifdef SNMP_TESTING_CODE s = dump_snmpEngineID(t, &tlen); printf("%s (len=%d)\n", s, tlen); #endif SNMP_FREE(s); if (t != buf) { SNMP_FREE(t); } } return failcount; } /* end test_dumpseid() */
/*******************************************************************-o-****** */ int main(int argc, char **argv) { int rval = SNMPERR_SUCCESS; size_t oldKu_len = SNMP_MAXBUF_SMALL, newKu_len = SNMP_MAXBUF_SMALL, oldkul_len = SNMP_MAXBUF_SMALL, newkul_len = SNMP_MAXBUF_SMALL, keychange_len = SNMP_MAXBUF_SMALL; char *s = NULL; u_char oldKu[SNMP_MAXBUF_SMALL], newKu[SNMP_MAXBUF_SMALL], oldkul[SNMP_MAXBUF_SMALL], newkul[SNMP_MAXBUF_SMALL], keychange[SNMP_MAXBUF_SMALL]; int i; int arg = 1; local_progname = argv[0]; /* * Parse. */ for(; (arg < argc) && (argv[arg][0] == '-') ; arg++){ switch(argv[arg][1]){ case 'D': snmp_set_do_debugging(1); break; case 'E': engineid = (u_char *)argv[++arg]; break; case 'f': forcepassphrase = 1; break; case 'N': newpass = argv[++arg]; break; case 'O': oldpass = argv[++arg]; break; case 'P': promptindicator = 0; break; case 't': transform_type_input = argv[++arg]; break; case 'v': verbose = 1; break; case 'V': visible = 1; break; case 'h': rval = 0; default: usage_to_file(stdout); exit(rval); } } if ( !transform_type_input ) { fprintf(stderr, "The -t option is mandatory.\n"); usage_synopsis(stdout); exit(1000); } /* * Convert and error check transform_type. */ if ( !strcmp(transform_type_input, "md5") ) { transform_type = usmHMACMD5AuthProtocol; } else if ( !strcmp(transform_type_input, "sha1") ) { transform_type = usmHMACSHA1AuthProtocol; } else { fprintf(stderr, "Unrecognized hash transform: \"%s\".\n", transform_type_input); usage_synopsis(stderr); QUITFUN(rval = SNMPERR_GENERR, main_quit); } if (verbose) { fprintf(stderr, "Hash:\t\t%s\n", (transform_type == usmHMACMD5AuthProtocol) ? "usmHMACMD5AuthProtocol" : "usmHMACSHA1AuthProtocol" ); } /* * Build engineID. Accept hex engineID as the bits * "in-and-of-themselves", otherwise create an engineID with the * given string as text. * * If no engineID is given, lookup the first IP address for the * localhost and use that (see setup_engineID()). */ if ( engineid && (tolower(*(engineid+1)) == 'x') ) { engineid_len = hex_to_binary2( engineid+2, strlen((char *)engineid)-2, (char **) &engineid); DEBUGMSGTL(("encode_keychange","engineIDLen: %d\n", engineid_len)); } else { engineid_len = setup_engineID(&engineid, (char *)engineid); } #ifdef SNMP_TESTING_CODE if (verbose) { fprintf(stderr, "EngineID:\t%s\n", /* XXX = */ dump_snmpEngineID(engineid, &engineid_len)); } #endif /* * Get passphrases from user. */ rval = get_user_passphrases(); QUITFUN(rval, main_quit); if ( strlen(oldpass) < USM_LENGTH_P_MIN ) { fprintf(stderr, "Old passphrase must be greater than %d " "characters in length.\n", USM_LENGTH_P_MIN); QUITFUN(rval = SNMPERR_GENERR, main_quit); } else if ( strlen(newpass) < USM_LENGTH_P_MIN ) { fprintf(stderr, "New passphrase must be greater than %d " "characters in length.\n", USM_LENGTH_P_MIN); QUITFUN(rval = SNMPERR_GENERR, main_quit); } if (verbose) { fprintf(stderr, "Old passphrase:\t%s\nNew passphrase:\t%s\n", oldpass, newpass); } /* * Compute Ku and Kul's from old and new passphrases, then * compute the keychange string & print it out. */ rval = sc_init(); QUITFUN(rval, main_quit); rval = generate_Ku( transform_type, USM_LENGTH_OID_TRANSFORM, (u_char *)oldpass, strlen(oldpass), oldKu, &oldKu_len); QUITFUN(rval, main_quit); rval = generate_Ku( transform_type, USM_LENGTH_OID_TRANSFORM, (u_char *)newpass, strlen(newpass), newKu, &newKu_len); QUITFUN(rval, main_quit); DEBUGMSGTL(("encode_keychange", "EID (%d): ", engineid_len)); for(i=0; i < (int)engineid_len; i++) DEBUGMSGTL(("encode_keychange", "%02x",(int) (engineid[i]))); DEBUGMSGTL(("encode_keychange","\n")); DEBUGMSGTL(("encode_keychange", "old Ku (%d) (from %s): ", oldKu_len, oldpass)); for(i=0; i < (int)oldKu_len; i++) DEBUGMSGTL(("encode_keychange", "%02x",(int) (oldKu[i]))); DEBUGMSGTL(("encode_keychange","\n")); rval = generate_kul( transform_type, USM_LENGTH_OID_TRANSFORM, engineid, engineid_len, oldKu, oldKu_len, oldkul, &oldkul_len); QUITFUN(rval, main_quit); DEBUGMSGTL(("encode_keychange", "generating old Kul (%d) (from Ku): ", oldkul_len)); for(i=0; i < (int)oldkul_len; i++) DEBUGMSGTL(("encode_keychange", "%02x",(int) (oldkul[i]))); DEBUGMSGTL(("encode_keychange","\n")); rval = generate_kul( transform_type, USM_LENGTH_OID_TRANSFORM, engineid, engineid_len, newKu, newKu_len, newkul, &newkul_len); QUITFUN(rval, main_quit); DEBUGMSGTL(("encode_keychange", "generating new Kul (%d) (from Ku): ", oldkul_len)); for(i=0; i < (int)newkul_len; i++) DEBUGMSGTL(("encode_keychange", "%02x",newkul[i])); DEBUGMSGTL(("encode_keychange","\n")); rval = encode_keychange(transform_type, USM_LENGTH_OID_TRANSFORM, oldkul, oldkul_len, newkul, newkul_len, keychange, &keychange_len); QUITFUN(rval, main_quit); binary_to_hex(keychange, keychange_len, &s); printf("%s%s\n", (verbose) ? "KeyChange string:\t" : "", /* XXX stdout */ s); /* * Cleanup. */ main_quit: snmp_call_callbacks(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_SHUTDOWN, NULL); SNMP_ZERO(oldpass, strlen(oldpass)); SNMP_ZERO(newpass, strlen(newpass)); SNMP_ZERO(oldKu, oldKu_len); SNMP_ZERO(newKu, newKu_len); SNMP_ZERO(oldkul, oldkul_len); SNMP_ZERO(newkul, newkul_len); SNMP_ZERO(s, strlen(s)); return rval; } /* end main() */