/** * Test error handling of importing public key. */ void test_import_public_key2(void) { keypair pair; fmpz_poly_t f, g, pub; int f_c[] = { -1, 1, 1, 0, -1, 0, 1, 0, 0, 1, -1 }; int g_c[] = { -1, 0, 1, 1, 0, 1, 0, 0, -1, 0, -1 }; ntru_params params; fmpz_poly_init(pub); params.N = 11; params.p = 3; params.q = 32; poly_new(f, f_c, 11); poly_new(g, g_c, 11); ntru_create_keypair(&pair, f, g, ¶ms); export_public_key("pub.key", pair.pub, ¶ms); import_public_key(pub, "foo", ¶ms); remove("pub.key"); CU_ASSERT_NOT_EQUAL(1, fmpz_poly_equal(pub, pair.pub)); }
/** * Test exporting public key and reading the resulting file. */ void test_export_public_key1(void) { keypair pair; fmpz_poly_t f, g; int f_c[] = { -1, 1, 1, 0, -1, 0, 1, 0, 0, 1, -1 }; int g_c[] = { -1, 0, 1, 1, 0, 1, 0, 0, -1, 0, -1 }; ntru_params params; string *pub_string; char *expected_pub_c_str = "CBkWFAwYDxMMExA="; char actual_pub_c_str[512] = "\0"; params.N = 11; params.p = 3; params.q = 32; poly_new(f, f_c, 11); poly_new(g, g_c, 11); ntru_create_keypair(&pair, f, g, ¶ms); export_public_key("pub.key", pair.pub, ¶ms); if ((pub_string = read_file("pub.key"))) { memcpy(actual_pub_c_str, pub_string->ptr, pub_string->len); actual_pub_c_str[pub_string->len] = '\0'; string_delete(pub_string); } remove("pub.key"); CU_ASSERT_EQUAL(strcmp(expected_pub_c_str, actual_pub_c_str), 0); }
static int post_read_request(request_rec *r) { if (!ap_is_initial_req(r)) return DECLINED; ap_module_trace_rcall(r); /* if ( !ssl_keying_material) return DECLINED; */ if (!ssl_is_https) return DECLINED; if (!ssl_var_lookup || !ssl_is_https(r->connection)) return DECLINED; struct req *req = ap_req_config_get(r); struct srv *srv = ap_srv_config_get(r); struct aaa *aaa = srv->aaa; r_info(r, "uri: %s", r->uri); const char *pub = export_public_key(r); const char *key = aaa_attr_get(aaa, "sess.key"); const char *sec = aaa_attr_get(aaa, "sess.sec"); const char *id = aaa_attr_get(aaa, "sess.id"); r_info(r, "sess.id: %s", id); if (key) r_info(r, "sess.key: %s", key); if (sec) r_info(r, "sess.sec: %s", sec); apr_table_t *t = r->subprocess_env; apr_table_setn(t, "AAA_SESS_KEY", aaa_attr_get(aaa, "sess.key")); apr_table_setn(t, "AAA_SESS_SEC", aaa_attr_get(aaa, "sess.sec")); if (sec) { const char *file = stk_printf("/tmp/aaa-%s", sec); r_info(r, "authentized session file=%s", file); parse_session(r, file); } if (!tls_authentication_signal(r)) return DECLINED; key = export_keying_material(r); sec = export_keying_derivate(r, pub, key); if (key) r_info(r, "sess.key: %s", key); if (sec) r_info(r, "sess.sec: %s", sec); apr_table_setn(t, "AAA_SESS_KEY", aaa_attr_get(aaa, "sess.key")); apr_table_setn(t, "AAA_SESS_SEC", aaa_attr_get(aaa, "sess.sec")); aaa_attr_set(srv->aaa, "sess.key", (char *)key); aaa_attr_set(srv->aaa, "sess.sec", (char *)sec); aaa_commit(srv->aaa); return DECLINED; }