void simple_password_test(SshAuthPolicyProc policy_proc) { SshStream client, server; simple_password_create(&client, &server, policy_proc); client_down = ssh_cross_down_create(client, client_received_packet, NULL, NULL, NULL); ssh_cross_down_can_receive(client_down, TRUE); server_down = ssh_cross_down_create(server, server_received_packet, NULL, NULL, NULL); ssh_cross_down_can_receive(server_down, TRUE); simple_password_failed = FALSE; simple_password_authenticated = FALSE; simple_password_may_fail = random() % 2; if (!pingpong_success || random() % 3 == 0) pingpong_count = random() % 5; else pingpong_count = 0; ssh_event_loop_run(); if ((!simple_password_failed && !simple_password_authenticated) || (simple_password_failed && simple_password_authenticated)) ssh_fatal("simple_password_test: exited without fail/auth"); if (!simple_password_may_fail && simple_password_failed) ssh_fatal("simple_pasword_test: failed without permission"); switch (random() % 4) { case 0: ssh_cross_down_destroy(client_down); ssh_event_loop_run(); ssh_cross_down_destroy(server_down); break; case 1: ssh_cross_down_destroy(server_down); ssh_event_loop_run(); ssh_cross_down_destroy(client_down); break; case 2: ssh_cross_down_destroy(server_down); ssh_cross_down_destroy(client_down); break; case 3: ssh_cross_down_destroy(client_down); ssh_cross_down_destroy(server_down); break; default: abort(); } ssh_event_loop_run(); }
void copy_data_test(SshStream s1, SshStream s2) { ts1 = s1; ts2 = s2; create_testdata(); if (received_data) ssh_buffer_clear(received_data); else received_data = ssh_buffer_allocate(); test_data_index = 0; destroy_count = 0; reader_sent_eof = FALSE; ssh_stream_set_callback(s1, copy_writer, NULL); ssh_stream_set_callback(s2, copy_reader, NULL); ssh_event_loop_run(); if (destroy_count != 2 || ts1 != NULL || ts2 != NULL) ssh_fatal("copy_data_test: one stream not destroyed"); if (ssh_buffer_len(received_data) > ssh_buffer_len(testdata)) ssh_fatal("copy_data_test: received more data than sent"); if (break_test) ssh_buffer_consume_end(testdata, ssh_buffer_len(testdata) - ssh_buffer_len(received_data)); if (ssh_buffer_len(testdata) != ssh_buffer_len(received_data)) ssh_fatal("copy_data_test: data lens differ"); if (memcmp(ssh_buffer_ptr(testdata), ssh_buffer_ptr(received_data), ssh_buffer_len(testdata)) != 0) ssh_fatal("copy_data_test: received data differs"); }
int main(int argc, char *argv[]) { SshFSMStruct fsmstruct; SshFSMThread thread; SshFSM fsm = &fsmstruct; if (argc == 2) ssh_debug_set_level_string(argv[1]); ssh_event_loop_initialize(); ssh_fsm_init(fsm, NULL); ssh_fsm_register_debug_names(fsm, state_array, num_states); /* Create a condition variable. */ ssh_fsm_condition_init(fsm, &cond); thread = ssh_fsm_thread_create(fsm, main_start, NULL_FNPTR, NULL_FNPTR, "main"); ssh_fsm_set_thread_name(thread, "main"); ssh_event_loop_run(); ssh_fsm_uninit(fsm); ssh_event_loop_uninitialize(); ssh_util_uninit(); return errors; }
void disconnect_test() { SshStream server; SshStream s1, s2; unsigned char buf[8192]; int len, i; ssh_stream_pair_create(&s1, &s2); /* Initialize server side. */ server = ssh_transport_server_wrap(s1, random_state, TEST_VERSION, NULL, hostkey, serverkey, hostkey_blob, hostkey_blob_len, NULL, NULL); ssh_event_loop_run(); if (random() % 5 == 0) len = 0; else len = random() % sizeof(buf); for (i = 0; i < len; i++) { buf[i] = random(); if (buf[i] < 32 && buf[i] != '\n' && buf[i] != '\r') buf[i] = 'X'; } ssh_stream_write(s2, buf, len); ssh_event_loop_run(); ssh_stream_destroy(s2); ssh_event_loop_run(); ssh_stream_destroy(server); ssh_event_loop_run(); }
int main(int ac, char **av) { int i, j; int pass; unsigned char buf[1024]; snprintf(lpath1, sizeof (lpath1), "/tmp/lstr1.%x", (unsigned)random()); snprintf(lpath2, sizeof (lpath2), "/tmp/lstr2.%x", (unsigned)random()); printf("Doing %d iterations of localstream test:", PASSES); for (pass = 0; pass < PASSES; pass++) { printf(" %d", pass); fflush(stdout); ssh_buffer_init(&send_buffer); ssh_buffer_init(&expect_buffer); for (i = 0; i < 100; i++) { for (j = 0; j < sizeof(buf); j++) buf[j] = random(); ssh_buffer_append(&send_buffer, buf, sizeof(buf)); ssh_buffer_append(&expect_buffer, buf, sizeof(buf)); send_count += sizeof(buf); } ssh_event_loop_initialize(); remove(lpath1); listener1 = ssh_local_make_listener(lpath1, listener1_callback, (void *)4); if (!listener1) { ssh_fatal("cannot create listener1"); } ssh_local_connect(lpath1, connect1_done, (void *)3); ssh_event_loop_run(); ssh_event_loop_uninitialize(); ssh_buffer_uninit(&send_buffer); ssh_buffer_uninit(&expect_buffer); } printf("\n"); return 0; }
int main(int argc, char *argv[]) { SshFSM fsm; SshFSMThread thread; ssh_event_loop_initialize(); /* Create a new FSM with NULL context data. */ fsm = ssh_fsm_create(NULL); if (fsm == NULL) { fprintf(stderr, "Could not create FSM\n"); goto error; } /* Start a thread. The context data is the greeting to display to the user. */ thread = ssh_fsm_thread_create(fsm, hello, NULL_FNPTR, NULL_FNPTR, "Hello, world!"); if (thread == NULL) { fprintf(stderr, "Could not start thread\n"); goto error; } /* Start event loop. */ ssh_event_loop_run(); /* Cleanup. */ ssh_fsm_destroy(fsm); ssh_event_loop_uninitialize(); return 0; /* Error handling. */ error: if (fsm) ssh_fsm_destroy(fsm); ssh_event_loop_uninitialize(); return 1; }
/* The main. */ int main(int argc, char **argv) { /* Parse arguments. */ parse_arguments(argc, argv); /* Initialize the event loop. */ ssh_event_loop_initialize(); /* Allocate and initialize the externalkey interface. */ test_ek_add(); /* Start the event loop. This wont return, unless somebody calls ssh_event_loop_abort(). */ ssh_event_loop_run(); /* Uninitialize the event loop. */ ssh_event_loop_uninitialize(); return 0; }
int main(int argc, char **argv) { SshStream stdio_stream; SshSigner signer; char config_filename[512]; char *temp_name; #ifdef SLEEP_AFTER_STARTUP sleep(30); #endif /* SLEEP_AFTER_STARTUP */ /* Get program name (without path). */ if ((temp_name = strrchr(argv[0], '/')) != NULL) progname = ssh_xstrdup(temp_name + 1); else progname = ssh_xstrdup(argv[0]); /* XXX there should be a way to give command-line parameters to this program, but, they should only be used if the uid is the same as euid. */ ssh_event_loop_initialize(); signer = ssh_xcalloc(1, sizeof(*signer)); #ifdef SIGNER_QUIET signer->quiet = TRUE; #else /* SIGNER_QUIET */ signer->quiet = FALSE; #endif /* SIGNER_QUIET */ ssh_debug_register_callbacks(signer_ssh_fatal, signer_ssh_warning, signer_ssh_debug, (void *)signer); #ifdef SIGNER_DEBUG ssh_debug_set_global_level(5); #endif /* SIGNER_DEBUG */ /* Act as server. */ signer->config = ssh_server_create_config(); SSH_TRACE(2, ("public key file: %s", signer->config->public_host_key_file)); SSH_TRACE(2, ("private key file: %s", signer->config->host_key_file)); SSH_TRACE(2, ("randomseed file: %s", signer->config->random_seed_file)); /* Initialize user context with euid. This is used to dig up the hostkey and such. */ signer->effective_user_data = ssh_user_initialize_with_uid(geteuid(), FALSE); signer->random_state = ssh_randseed_open(signer->effective_user_data, signer->config); /* XXX what about alternative config files? This should be possible to configure somehow. An option for configure is probably a good idea. */ snprintf(config_filename, sizeof(config_filename), "%s/%s", SSH_SERVER_DIR, SSH_SERVER_CONFIG_FILE); if (!ssh_config_read_file(signer->effective_user_data, signer->config, NULL, config_filename, NULL)) ssh_warning("%s: Failed to read config file %s", argv[0], config_filename); stdio_stream = ssh_stream_fd_wrap2(fileno(stdin), fileno(stdout), TRUE); signer->wrapper = ssh_packet_wrap(stdio_stream, signer_received_packet, signer_received_eof, signer_can_send, signer); ssh_event_loop_run(); return 0; }
int main(int argc, char* argv[]) { t_tcpc_context pcontext = 0; SshGetOptData pgetoptdata = 0; int i; SSH_TRACE(SSH_D_MY, ("%s", "main")); pcontext = ssh_xmalloc(sizeof (*pcontext)); memset(pcontext, 0, sizeof (*pcontext)); pgetoptdata = ssh_xmalloc(sizeof (*pgetoptdata)); memset(pgetoptdata, 0, sizeof (*pgetoptdata)); ssh_getopt_init_data(pgetoptdata); pcontext->pport_or_service = "23242"; while ((i = ssh_getopt(argc, argv, "p:h:d:D:G:t:", pgetoptdata)) != -1) { switch (i) { case 'p': pcontext->pport_or_service = ssh_xstrdup(pgetoptdata->arg); break; case 'h': pcontext->phost_name_or_address = ssh_xstrdup(pgetoptdata->arg); break; case 'd': pcontext->pdata = ssh_xstrdup(pgetoptdata->arg); break; case 'D': ssh_debug_set_module_level(SSH_DEBUG_MODULE, atoi(pgetoptdata->arg)); break; case 'G': ssh_debug_set_global_level(atoi(pgetoptdata->arg)); break; case 't': pcontext->timeout = atoi(pgetoptdata->arg); break; default: SSH_NOTREACHED; break; } } ssh_xfree(pgetoptdata); ssh_event_loop_initialize(); pcontext->pbuffer = ssh_buffer_allocate(); if (pcontext->phost_name_or_address) { ssh_tcp_connect(pcontext->phost_name_or_address, pcontext->pport_or_service, NULL, t_tcpc_tcp_callback, pcontext); } else { pcontext->ptcplistener = ssh_tcp_make_listener(SSH_IPADDR_ANY_IPV4, pcontext->pport_or_service, NULL, t_tcpc_tcp_callback, pcontext); } ssh_event_loop_run(); ssh_name_server_uninit(); ssh_event_loop_uninitialize(); ssh_buffer_free(pcontext->pbuffer); ssh_xfree(pcontext); ssh_util_uninit(); return 0; }
int main(int argc, char *argv[]) { int c; const char *debug_string = "SshHttpFilterProxy=5"; SshHttpServerParams params; SshHttpServerContext ctx; memset(¶ms, 0, sizeof(params)); params.port = "8080"; #ifndef WIN32 signal(SIGPIPE, SIG_IGN); #endif /* not WIN32 */ /* Remove the directory part from the program name. */ program = strrchr(argv[0], '/'); if (program == NULL) program = argv[0]; else program++; /* Parse options. */ while ((c = ssh_getopt(argc, argv, "d:hp:P:", NULL)) != EOF) { switch (c) { case 'd': debug_string = ssh_optarg; break; case 'h': usage(); exit(0); break; case 'p': params.port = ssh_optarg; break; case 'P': proxy_url = ssh_optarg; break; } } if (ssh_optind < argc) { fprintf(stderr, "%s: garbage after options.\n\n", program); usage(); exit(1); } ssh_debug_set_level_string(debug_string); ssh_event_loop_initialize(); read_censor_list(); SSH_DEBUG(SSH_D_HIGHSTART, ("running on %s", params.port)); ctx = ssh_http_server_start(¶ms); if (ctx) { /* Set the URI handlers. */ ssh_http_server_set_handler(ctx, "http://*", 0, proxy_handler, NULL); ssh_http_server_set_handler(ctx, "/catch*", 0, catch_handler, NULL); ssh_http_server_set_handler(ctx, "*", 10, authentication_handler, NULL); ssh_event_loop_run(); } else fprintf(stderr, "%s: couldn't create listener\n", program); ssh_event_loop_uninitialize(); return 0; }
int main(int ac, char **av) { char port[100]; int i; TestCase *testcase; int pass; SshTime time_now; time_now = ssh_time(); srandom(time_now); for (pass = 0; pass < PASSES; pass++) { #ifdef DEBUG ssh_debug("pass %d", pass); #endif random_state = ssh_random_allocate(); /* randomize it a bit */ ssh_random_add_noise(random_state, &time_now, sizeof(time_now)); ssh_buffer_init(&testdata); for (i = 0; i < 100000; i++) buffer_put_char(&testdata, ssh_random_get_byte(random_state)); ssh_event_loop_initialize(); for (i = 0; tests[i].name; i++) { testcase = &tests[i]; end_of_script_count = 0; #ifdef DEBUG ssh_debug("Running test %s", testcase->name); #endif snprintf(port, sizeof(port), "%d", (int)(35000 + random() % 1000)); #ifdef DEBUG ssh_debug("Making listener, port %s...", port); #endif listener = ssh_tcp_make_listener("127.0.0.1", port, listener_callback, (void *)testcase); if (!listener) ssh_fatal("making listener failed"); #ifdef DEBUG ssh_debug("Making connect..."); #endif ssh_tcp_connect_with_socks("127.0.0.1", port, NULL, 2, connect_callback, (void *)testcase); #ifdef DEBUG ssh_debug("Event loop running..."); #endif ssh_event_loop_run(); #ifdef DEBUG ssh_debug("Event loop exited..."); #endif if (end_of_script_count != 2) ssh_fatal("end_of_script_count %d, script end not reached.", end_of_script_count); /* Listener was destroyed in callback. */ } ssh_event_loop_uninitialize(); ssh_buffer_uninit(&testdata); ssh_random_free(random_state); } #ifdef DEBUG ssh_debug("Exiting..."); #endif return 0; }
int main(int ac, char **av) { int opt, i; DIR *ssh2dir = NULL; char *ssh2dirname; Boolean dynamic_array = FALSE; struct dirent * cand; /* Save program name. */ if (strchr(av[0], '/')) av0 = strrchr(av[0], '/') + 1; else av0 = av[0]; user = ssh_user_initialize(NULL, FALSE); #ifdef WITH_PGP pgp_keyring = ssh_xstrdup(SSH_PGP_SECRET_KEY_FILE); #endif /* WITH_PGP */ action = ADD; while ((opt = ssh_getopt(ac, av, "ldDput:f:F:1LUNPI", NULL)) != EOF) { if (!ssh_optval) { usage(); exit(EXIT_STATUS_ERROR); } switch (opt) { case 'N': #ifdef WITH_PGP pgp_mode = PGP_KEY_NAME; #else /* WITH_PGP */ fprintf(stderr, "%s: PGP keys not supported.\n", av0); exit(EXIT_STATUS_ERROR); #endif /* WITH_PGP */ break; case 'P': #ifdef WITH_PGP pgp_mode = PGP_KEY_FINGERPRINT; #else /* WITH_PGP */ fprintf(stderr, "%s: PGP keys not supported.\n", av0); exit(EXIT_STATUS_ERROR); #endif /* WITH_PGP */ break; case 'I': #ifdef WITH_PGP pgp_mode = PGP_KEY_ID; #else /* WITH_PGP */ fprintf(stderr, "%s: PGP keys not supported.\n", av0); exit(EXIT_STATUS_ERROR); #endif /* WITH_PGP */ break; case 'R': #ifdef WITH_PGP ssh_xfree(pgp_keyring); pgp_keyring = ssh_xstrdup(ssh_optarg); #else /* WITH_PGP */ fprintf(stderr, "%s: PGP keys not supported.\n", av0); exit(EXIT_STATUS_ERROR); #endif /* WITH_PGP */ break; case 'l': action = LIST; break; case 'p': use_stdin = TRUE; break; case 'd': if (action == ADD_URL) action = DELETE_URL; else action = DELETE; break; case 'D': action = DELETE_ALL; break; case 't': if (ssh_optargnum) { key_timeout = (SshTime)(ssh_optargval * 60); } else { usage(); exit(EXIT_STATUS_ERROR); } have_attrs = TRUE; break; case 'f': if (ssh_optargnum) { path_limit = (SshUInt32)ssh_optargval; } else { usage(); exit(EXIT_STATUS_ERROR); } have_attrs = TRUE; break; case 'F': path_constraint = ssh_xstrdup(ssh_optarg); have_attrs = TRUE; break; case '1': forbid_compat = TRUE; have_attrs = TRUE; break; case 'u': if (action == DELETE) action = DELETE_URL; else action = ADD_URL; break; case 'L': action = LOCK; break; case 'U': action = UNLOCK; break; default: usage(); exit(EXIT_STATUS_ERROR); } } #ifdef WITH_PGP if (pgp_keyring[0] != '/') { char buf[1024]; snprintf(buf, sizeof (buf), "%s/%s/%s", ssh_user_dir(user), SSH_USER_DIR, pgp_keyring); ssh_xfree(pgp_keyring); pgp_keyring = ssh_xstrdup(buf); } #endif /* WITH_PGP */ files = &av[ssh_optind]; num_files = ac - ssh_optind; /* Fetch default from ~/.ssh2/id_* (the first that we happen to get) */ #define ID_PREFIX "id" if (num_files == 0 && action != LIST && action != DELETE_ALL && action != LOCK && action != UNLOCK) { #ifdef WITH_PGP if (pgp_mode != PGP_KEY_NONE) { fprintf(stderr, "%s: Nothing to do!\n", av0); exit(EXIT_STATUS_ERROR); } #endif /* WITH_PGP */ ssh_dsprintf(&ssh2dirname, "%s/%s", ssh_user_dir(user), SSH_USER_DIR); ssh2dir = opendir(ssh2dirname); if (!ssh2dir) { fprintf(stderr, "%s: Can't open directory \"%s\"", av0, ssh2dirname); exit(EXIT_STATUS_ERROR); } while ((cand = readdir(ssh2dir)) != NULL) { if ((strlen(cand->d_name) > strlen(ID_PREFIX)) && (strncmp(cand->d_name, ID_PREFIX, strlen(ID_PREFIX)) == 0) && ((strlen(cand->d_name) < 4) || (strcmp(cand->d_name + strlen(cand->d_name) - 4, ".pub") != 0)) && ((((cand->d_name)[strlen(ID_PREFIX)]) == '_') || (((cand->d_name)[strlen(ID_PREFIX)]) == '-') || (((cand->d_name)[strlen(ID_PREFIX)]) == '.') || (((cand->d_name)[strlen(ID_PREFIX)]) == '(') || (((cand->d_name)[strlen(ID_PREFIX)]) == '[') || (((cand->d_name)[strlen(ID_PREFIX)]) == '<') || (((cand->d_name)[strlen(ID_PREFIX)]) == '>'))) { files = ssh_xcalloc(2, sizeof(char *)); ssh_dsprintf(&files[0], "%s/%s", ssh2dirname, cand->d_name); ssh_xfree(ssh2dirname); num_files++; dynamic_array = TRUE; break; } } (void)closedir(ssh2dir); } signal(SIGPIPE, SIG_IGN); ssh_event_loop_initialize(); ssh_agent_open(agent_open_callback, NULL); ssh_event_loop_run(); ssh_event_loop_uninitialize(); if (dynamic_array) { for(i = 0; i < num_files ; i++) { ssh_xfree(files[i]); } ssh_xfree(files); } ssh_user_free(user, FALSE); exit(EXIT_STATUS_OK); }
int main(int argc, char **argv) { SshExternalKeyTestCtx test_ctx; int i; SshPrivateKey prv_key; SshPublicKey pub_key; SshMPInteger n; parse_arguments(argc, argv); ssh_pk_provider_register(&ssh_pk_if_modn_generator); /* Initialize the event loop and the test context. */ ssh_event_loop_initialize(); ssh_debug_set_level_string(debug_level_string); ssh_global_init(); /* Initialize the crypto library. */ if (ssh_crypto_library_initialize() != SSH_CRYPTO_OK) ssh_fatal("Cannot initialize the crypto library"); test_ctx = ssh_xcalloc(1, sizeof(*test_ctx)); test_ctx->accelerated_encrypts_left = default_accelerated_encrypts; test_ctx->timer = ssh_time_measure_allocate(); SSH_DEBUG(3, ("Reading the test key. Please wait....")); prv_key = get_prv_key("accelerator-test.prv"); if (ssh_private_key_select_scheme(prv_key, SSH_PKF_ENCRYPT, "rsa-none-none", SSH_PKF_END) != SSH_CRYPTO_OK) ssh_fatal("Could not select the scheme for private key"); if (ssh_private_key_derive_public_key(prv_key, &pub_key) != SSH_CRYPTO_OK) { ssh_fatal("Can not derive a public key from a " "stored private key"); } if (ssh_public_key_select_scheme(pub_key, SSH_PKF_ENCRYPT, "rsa-none-none", SSH_PKF_END) != SSH_CRYPTO_OK) ssh_fatal("Could not select the scheme for public key"); n = ssh_mprz_malloc(); /* Get information about the RSA key. E and N are needed for nFast. */ if (ssh_public_key_get_info(pub_key, SSH_PKF_MODULO_N, n, SSH_PKF_END) != SSH_CRYPTO_OK) { return FALSE; } #if 0 n_bytes = (ssh_mprz_get_size(n, 2) + 7) / 8; if (n_bytes == 0 || (n_bytes & 3) != 0) n_bytes += (4 - (n_bytes & 3)); test_ctx->big_buf = ssh_xmalloc(n_bytes); test_ctx->big_buf_len = n_bytes; ssh_mprz_get_buf(test_ctx->big_buf, test_ctx->big_buf_len, n); ssh_mprz_free(n); test_ctx->big_buf_len = 128; test_ctx->big_buf[0] = 1; #else #if 0 n_bytes = ssh_mprz_get_size(n, 8); test_ctx->big_buf = ssh_xmalloc(n_bytes); test_ctx->big_buf_len = n_bytes; ssh_mprz_init(&r); ssh_mprz_rand(&r, n_bytes * 8); ssh_mprz_mod(&r, &r, n); ssh_mprz_get_buf(test_ctx->big_buf, test_ctx->big_buf_len, &r); ssh_mprz_free(n); ssh_mprz_clear(&r); #else test_ctx->big_buf = ssh_xmalloc(129); test_ctx->big_buf_len = 129; memcpy(test_ctx->big_buf, "\x00\x50\xe7\x85\x86\x40\xf8\x9b" "\xb8\xeb\x19\x64\xd8\x51\x33\xd7" "\x4f\xac\x32\x5d\x03\x66\x3d\x0c" "\xbe\xfd\x40\x29\x82\xb7\x61\x09" "\x15\x37\x4f\xe1\xd0\x57\xb0\x6d" "\x16\x49\x73\x25\x20\x3d\xa8\xfa" "\xf6\xb4\x72\xec\x75\xc8\x42\xc7" "\x99\x64\x63\x23\x29\xe0\x65\xa1" "\x2a\xc2\xb7\xf1\x5b\xb4\x9b\x30" "\xdb\xc7\x22\xb9\xf9\xde\xb5\x09" "\xb5\xe0\x0a\xca\xc5\xf9\xaf\x8f" "\x54\xf2\x9a\x06\x2b\xc1\xc2\x65" "\x87\xb3\xd5\xec\xd3\x8a\x2f\xa7" "\x5f\x69\x34\xe7\x7f\xeb\xaf\x56" "\x3c\x3d\x71\x3f\x73\xba\x8b\xa7" "\xd3\xe5\x6d\x98\xc8\x01\x6b\x18" "\x14", 129); #endif #endif test_ctx->pub_key = pub_key; test_ctx->prv_key = prv_key; test_ek_add(test_ctx); #ifndef WIN32 ssh_register_signal(SIGUSR1, test_signal_handler, test_ctx); #endif ssh_event_loop_run(); /* Uninitialize. */ for (i = 0; i < test_ctx->num_prv_keys; i++) ssh_private_key_free(test_ctx->prv_keys[i]); for (i = 0; i < test_ctx->num_pub_keys; i++) ssh_public_key_free(test_ctx->pub_keys[i]); ssh_xfree(test_ctx->prv_keys); ssh_xfree(test_ctx->pub_keys); ssh_xfree(test_ctx); return 0; }