int vfstest_main(int argc, char **argv) #endif { if (argc != 1) { fprintf(stderr, "USAGE: vfstest\n"); return 1; } test_init(); vfstest_start(); syscall_success(chdir(root_dir)); vfstest_stat(); vfstest_chdir(); vfstest_mkdir(); vfstest_paths(); vfstest_fd(); vfstest_open(); vfstest_read(); vfstest_getdents(); #ifdef __VM__ vfstest_s5fs_vm(); #endif /*vfstest_infinite();*/ syscall_success(chdir("..")); vfstest_term(); test_fini(); return 0; }
/** * This is the main entry point of a native application that is using * android_native_app_glue. It runs in its own thread, with its own * event loop for receiving input events and doing other things. */ void android_main (struct android_app* application) { TestData data; /* Make sure glue isn't stripped */ app_dummy (); g_android_init (); memset (&data, 0, sizeof (TestData)); application->userData = &data; application->onAppCmd = test_handle_cmd; data.app = application; while (1) { int events; struct android_poll_source* source; while ((ALooper_pollAll (0, NULL, &events, (void**)&source)) >= 0) { /* Process this event */ if (source != NULL) source->process (application, source); /* Check if we are exiting */ if (application->destroyRequested != 0) { test_fini (&data); return; } } test_draw_frame_and_swap (&data); } }
/** * Process the next main command. */ static void test_handle_cmd (struct android_app* app, int32_t cmd) { TestData *data = (TestData *) app->userData; switch (cmd) { case APP_CMD_INIT_WINDOW: /* The window is being shown, get it ready */ g_message ("command: INIT_WINDOW"); if (data->app->window != NULL) { test_init (data); test_draw_frame_and_swap (data); } break; case APP_CMD_TERM_WINDOW: /* The window is being hidden or closed, clean it up */ g_message ("command: TERM_WINDOW"); test_fini (data); break; case APP_CMD_GAINED_FOCUS: g_message ("command: GAINED_FOCUS"); break; case APP_CMD_LOST_FOCUS: /* When our app loses focus, we stop monitoring the accelerometer. * This is to avoid consuming battery while not being used. */ g_message ("command: LOST_FOCUS"); test_draw_frame_and_swap (data); break; } }
int main() { struct net2_sign_ctx *priv, *pub; struct net2_buffer *msg, *badmsg, *sig, *sig2; uint32_t v; int error; int fail = 0; test_start(); /* Initialize SSL. */ SSL_library_init(); SSL_load_error_strings(); ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); /* Load keys. */ fprintf(stderr, "Loading private key...\n"); priv = net2_signctx_privnew(net2_sign_ecdsa, ecdsa_privkey, strlen(ecdsa_privkey)); fprintf(stderr, "Private key loaded...\n"); fprintf(stderr, "Loading public key...\n"); pub = net2_signctx_pubnew( net2_sign_ecdsa, ecdsa_pubkey, strlen(ecdsa_pubkey)); fprintf(stderr, "Public key loaded...\n"); if (priv == NULL || pub == NULL) errx(1, "Failed to create public/private ecdsa signature context: pub=%p, priv=%p.", pub, priv); /* Allocate buffers. */ if ((msg = net2_buffer_new()) == NULL) errx(1, "Failed to allocate message buffer."); if ((sig = net2_buffer_new()) == NULL) errx(1, "Failed to allocate signature buffer."); if ((sig2 = net2_buffer_new()) == NULL) errx(1, "Failed to allocate signature 2 buffer."); if ((badmsg = net2_buffer_new()) == NULL) errx(1, "Failed to allocate bad message buffer."); /* Create message. */ while (net2_buffer_length(msg) < net2_signctx_maxmsglen(priv)) { v = secure_random(); if (net2_buffer_add(msg, &v, MIN(sizeof(v), net2_signctx_maxmsglen(priv) - net2_buffer_length(msg)))) errx(1, "Failed to allocate message buffer."); } /* Generate signature. */ if ((error = net2_signctx_sign(priv, msg, sig)) != 0) errx(2, "Sign operation failed, error %d", error); /* Validate signature. */ error = net2_signctx_validate(pub, sig, msg); if (error) printf("Signature is valid\n"); else { fail++; warnx("Signature is invalid (expected: valid)"); } /* Generate signature again (to see if it's different). */ if ((error = net2_signctx_sign(priv, msg, sig2)) != 0) errx(2, "Sign operation failed, error %d", error); /* Validate signature again. */ error = net2_signctx_validate(pub, sig2, msg); if (error) printf("Signature 2 is valid\n"); else { fail++; warnx("Signature 2 is invalid (expected: valid)"); } /* Ensure it is different. */ if (net2_buffer_cmp(sig, sig2) == 0) { fail++; warnx("Signature 2 is the same as first signature " "(this may happen only rarely, but is probably a bug!)"); } /* * Create tampered buffer. * * Note: this test is leaking buffers here. Don't use this as an * example of proper coding! */ net2_buffer_copyout(msg, &v, sizeof(v)); v = ~v; net2_buffer_add(badmsg, &v, sizeof(v)); { struct net2_buffer *tmp; net2_buffer_append(badmsg, tmp = net2_buffer_subrange(msg, sizeof(v), net2_buffer_length(msg) - sizeof(v))); net2_buffer_free(tmp); } /* Test tampered buffer. */ error = net2_signctx_validate(pub, sig, badmsg); if (!error) printf("Signature is invalid\n"); else { fail++; warnx("Signature is valid (expected: invalid)"); } /* Test public key extraction. */ { struct net2_buffer *priv_pk, *pub_pk; priv_pk = net2_signctx_pubkey(priv); pub_pk = net2_signctx_pubkey(pub); if (priv_pk == NULL || pub_pk == NULL) { fail++; warnx("Public key extraction failed " "(priv_pk=%p, pub_pk=%p).", priv_pk, pub_pk); goto skip_pubkey; } if (net2_buffer_length(priv_pk) == 0 || net2_buffer_length(pub_pk) == 0) { fail++; warnx("Public key length 0: " "(priv_pk: %llu bytes, pub_pk: %llu bytes).", (unsigned long long)net2_buffer_length(priv_pk), (unsigned long long)net2_buffer_length(pub_pk)); } if (net2_buffer_cmp(priv_pk, pub_pk) != 0) { fail++; warnx("Public key for priv and pub mismatch"); } net2_buffer_free(priv_pk); net2_buffer_free(pub_pk); } net2_buffer_free(msg); net2_buffer_free(badmsg); net2_buffer_free(sig); net2_buffer_free(sig2); net2_signctx_free(priv); net2_signctx_free(pub); skip_pubkey: test_fini(); /* Done. */ return fail; }