9 // Open two new meshlink instance.
11 meshlink_handle_t *mesh1 = meshlink_open("sign_verify_conf.1", "foo", "sign-verify", DEV_CLASS_BACKBONE);
14 fprintf(stderr, "Could not initialize configuration for foo\n");
18 meshlink_handle_t *mesh2 = meshlink_open("sign_verify_conf.2", "bar", "sign-verify", DEV_CLASS_BACKBONE);
21 fprintf(stderr, "Could not initialize configuration for bar\n");
25 // Import and export both side's data
27 meshlink_add_address(mesh1, "localhost");
28 meshlink_add_address(mesh2, "localhost");
30 char *data = meshlink_export(mesh1);
32 if(!meshlink_import(mesh2, data)) {
33 fprintf(stderr, "Bar could not import data from foo\n");
39 data = meshlink_export(mesh2);
41 if(!meshlink_import(mesh1, data)) {
42 fprintf(stderr, "Foo could not import data from bar\n");
48 // Verify that a signature made on one node can be verified by its peer.
50 static const char testdata1[] = "Test data 1.";
51 static const char testdata2[] = "Test data 2.";
53 char sig[MESHLINK_SIGLEN * 2];
54 size_t siglen = sizeof(sig) * 2;
56 if(!meshlink_sign(mesh1, testdata1, sizeof(testdata1), sig, &siglen)) {
57 fprintf(stderr, "Signing failed\n");
61 if(siglen != MESHLINK_SIGLEN) {
62 fprintf(stderr, "Signature has unexpected length %zu != %zu\n", siglen, MESHLINK_SIGLEN);
66 meshlink_node_t *foo = meshlink_get_node(mesh2, "foo");
69 fprintf(stderr, "Bar did not know about node foo\n");
73 meshlink_node_t *bar = meshlink_get_node(mesh2, "bar");
76 fprintf(stderr, "Bar did not know about node bar\n");
80 if(!meshlink_verify(mesh2, foo, testdata1, sizeof(testdata1), sig, siglen)) {
81 fprintf(stderr, "False negative verification\n");
85 // Check that bad signatures are revoked
87 if(meshlink_verify(mesh2, foo, testdata1, sizeof(testdata1), sig, siglen / 2)) {
88 fprintf(stderr, "False positive verification with half sized signature\n");
92 if(meshlink_verify(mesh2, foo, testdata1, sizeof(testdata1), sig, siglen * 2)) {
93 fprintf(stderr, "False positive verification with double sized signature\n");
97 if(meshlink_verify(mesh2, foo, testdata2, sizeof(testdata2), sig, siglen)) {
98 fprintf(stderr, "False positive verification with wrong data\n");
102 if(meshlink_verify(mesh2, bar, testdata1, sizeof(testdata1), sig, siglen)) {
103 fprintf(stderr, "False positive verification with wrong signer\n");
109 meshlink_close(mesh2);
110 meshlink_close(mesh1);