diff options
Diffstat (limited to 'attic/historic/anode/libanode/tests')
-rw-r--r-- | attic/historic/anode/libanode/tests/Makefile | 25 | ||||
-rw-r--r-- | attic/historic/anode/libanode/tests/aes-test.c | 191 | ||||
-rw-r--r-- | attic/historic/anode/libanode/tests/anode-secure_random-test.c | 38 | ||||
-rw-r--r-- | attic/historic/anode/libanode/tests/anode-utils-test.c | 75 | ||||
-rw-r--r-- | attic/historic/anode/libanode/tests/anode-zone-test.c | 47 | ||||
-rw-r--r-- | attic/historic/anode/libanode/tests/dictionary-test.c | 149 | ||||
-rw-r--r-- | attic/historic/anode/libanode/tests/ec-test.c | 97 | ||||
-rw-r--r-- | attic/historic/anode/libanode/tests/environment-test.c | 28 | ||||
-rw-r--r-- | attic/historic/anode/libanode/tests/http_client-test.c | 233 | ||||
-rw-r--r-- | attic/historic/anode/libanode/tests/misc-test.c | 137 | ||||
-rw-r--r-- | attic/historic/anode/libanode/tests/system_transport-test.c | 70 |
11 files changed, 1090 insertions, 0 deletions
diff --git a/attic/historic/anode/libanode/tests/Makefile b/attic/historic/anode/libanode/tests/Makefile new file mode 100644 index 00000000..a479092c --- /dev/null +++ b/attic/historic/anode/libanode/tests/Makefile @@ -0,0 +1,25 @@ +all: force clean anode-utils-test anode-zone-test aes-test ec-test + +aes-test: + gcc -Wall -O6 -ftree-vectorize -std=c99 -o aes-test aes-test.c ../aes_digest.c -lcrypto + +http_client-test: + gcc -O0 -g -std=c99 -o http_client-test http_client-test.c ../anode-utils.c ../misc.c ../http_client.c ../dictionary.c ../iptransport.c ../anode-transport.c -lcrypto + +anode-utils-test: + gcc -O0 -g -std=c99 -o anode-utils-test anode-utils-test.c ../anode-utils.c ../misc.c + +ec-test: + gcc -O0 -g -std=c99 -o ec-test ec-test.c ../impl/ec.c ../impl/misc.c -lcrypto + +anode-zone-test: + gcc -O0 -g -std=c99 -o anode-zone-test anode-zone-test.c ../anode-zone.c ../http_client.c ../dictionary.c ../misc.c ../anode-transport.c ../iptransport.c ../environment.c + +system_transport-test: + gcc -O0 -g -std=c99 -o system_transport-test system_transport-test.c ../system_transport.c ../network_address.c ../address.c ../aes_digest.c ../impl/misc.c ../impl/thread.c ../impl/dns_txt.c ../impl/aes.c -lresolv -lcrypto + +clean: force + rm -rf *.dSYM + rm -f http_client-test anode-utils-test anode-zone-test ec-test aes-test system_transport-test + +force: ; diff --git a/attic/historic/anode/libanode/tests/aes-test.c b/attic/historic/anode/libanode/tests/aes-test.c new file mode 100644 index 00000000..bca63b89 --- /dev/null +++ b/attic/historic/anode/libanode/tests/aes-test.c @@ -0,0 +1,191 @@ +/* libanode: the Anode C reference implementation + * Copyright (C) 2009 Adam Ierymenko <adam.ierymenko@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <time.h> +#include <sys/time.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include "../impl/aes.h" +#include "../anode.h" + +static const unsigned char AES_TEST_KEY[32] = { + 0x08,0x09,0x0A,0x0B,0x0D,0x0E,0x0F,0x10,0x12,0x13,0x14,0x15,0x17,0x18,0x19,0x1A, + 0x1C,0x1D,0x1E,0x1F,0x21,0x22,0x23,0x24,0x26,0x27,0x28,0x29,0x2B,0x2C,0x2D,0x2E +}; +static const unsigned char AES_TEST_IN[16] = { + 0x06,0x9A,0x00,0x7F,0xC7,0x6A,0x45,0x9F,0x98,0xBA,0xF9,0x17,0xFE,0xDF,0x95,0x21 +}; +static const unsigned char AES_TEST_OUT[16] = { + 0x08,0x0e,0x95,0x17,0xeb,0x16,0x77,0x71,0x9a,0xcf,0x72,0x80,0x86,0x04,0x0a,0xe3 +}; + +static const unsigned char CMAC_TEST_KEY[32] = { + 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81, + 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4 +}; + +static const unsigned char CMAC_TEST1_OUT[16] = { + 0x02,0x89,0x62,0xf6,0x1b,0x7b,0xf8,0x9e,0xfc,0x6b,0x55,0x1f,0x46,0x67,0xd9,0x83 +}; + +static const unsigned char CMAC_TEST2_IN[16] = { + 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a +}; +static const unsigned char CMAC_TEST2_OUT[16] = { + 0x28,0xa7,0x02,0x3f,0x45,0x2e,0x8f,0x82,0xbd,0x4b,0xf2,0x8d,0x8c,0x37,0xc3,0x5c +}; + +static const unsigned char CMAC_TEST3_IN[40] = { + 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a, + 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51, + 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11 +}; +static const unsigned char CMAC_TEST3_OUT[16] = { + 0xaa,0xf3,0xd8,0xf1,0xde,0x56,0x40,0xc2,0x32,0xf5,0xb1,0x69,0xb9,0xc9,0x11,0xe6 +}; + +static const unsigned char CMAC_TEST4_IN[64] = { + 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a, + 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51, + 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef, + 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10 +}; +static const unsigned char CMAC_TEST4_OUT[16] = { + 0xe1,0x99,0x21,0x90,0x54,0x9f,0x6e,0xd5,0x69,0x6a,0x2c,0x05,0x6c,0x31,0x54,0x10 +}; + +static void test_cmac(const AnodeAesExpandedKey *expkey,const unsigned char *in,unsigned int inlen,const unsigned char *expected) +{ + unsigned int i; + unsigned char out[16]; + + printf("Testing CMAC with %u byte input:\n",inlen); + printf(" IN: "); + for(i=0;i<inlen;++i) + printf("%.2x",(int)in[i]); + printf("\n"); + printf(" EXP: "); + for(i=0;i<16;++i) + printf("%.2x",(int)expected[i]); + printf("\n"); + Anode_cmac_aes256(expkey,in,inlen,out); + printf(" OUT: "); + for(i=0;i<16;++i) + printf("%.2x",(int)out[i]); + printf("\n"); + if (memcmp(expected,out,16)) { + printf("FAILED!\n"); + exit(1); + } else printf("Passed.\n"); +} + +static void test_cfb(const AnodeAesExpandedKey *expkey,const unsigned char *in,unsigned int inlen,unsigned char *iv,const unsigned char *expected) +{ + unsigned char tmp[131072]; + unsigned char tmp2[131072]; + unsigned char tmpiv[16]; + + printf("Testing AES-256 CFB mode with %u bytes: ",inlen); + fflush(stdout); + + memcpy(tmpiv,iv,16); + Anode_aes256_cfb_encrypt(expkey,in,tmp,tmpiv,inlen); + if (!memcmp(tmp,expected,inlen)) { + printf("FAILED (didn't encrypt)!\n"); + exit(1); + } + memcpy(tmpiv,iv,16); + Anode_aes256_cfb_decrypt(expkey,tmp,tmp2,tmpiv,inlen); + if (memcmp(tmp2,expected,inlen)) { + printf("FAILED (didn't encrypt)!\n"); + exit(1); + } else printf("Passed.\n"); +} + +static const char *AES_DIGEST_TEST_1 = "test"; +static const char *AES_DIGEST_TEST_2 = "supercalifragilisticexpealidocious"; +static const char *AES_DIGEST_TEST_3 = "12345678"; +static const char *AES_DIGEST_TEST_4 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + +int main(int argc,char **argv) +{ + AnodeAesExpandedKey expkey; + unsigned int i; + unsigned char aestestbuf[16]; + unsigned char cfbin[131072]; + unsigned char iv[16]; + + printf("Testing AES-256:"); + Anode_aes256_expand_key(AES_TEST_KEY,&expkey); + printf(" IN: "); + for(i=0;i<16;++i) + printf("%.2x",(int)AES_TEST_IN[i]); + printf("\n"); + printf(" EXP: "); + for(i=0;i<16;++i) + printf("%.2x",(int)AES_TEST_OUT[i]); + printf("\n"); + Anode_aes256_encrypt(&expkey,AES_TEST_IN,aestestbuf); + printf(" OUT: "); + for(i=0;i<16;++i) + printf("%.2x",(int)aestestbuf[i]); + printf("\n"); + if (memcmp(AES_TEST_OUT,aestestbuf,16)) { + printf("FAILED!\n"); + return 1; + } else printf("Passed.\n"); + printf("\n"); + + Anode_aes256_expand_key(CMAC_TEST_KEY,&expkey); + test_cmac(&expkey,(unsigned char *)0,0,CMAC_TEST1_OUT); + test_cmac(&expkey,CMAC_TEST2_IN,16,CMAC_TEST2_OUT); + test_cmac(&expkey,CMAC_TEST3_IN,40,CMAC_TEST3_OUT); + test_cmac(&expkey,CMAC_TEST4_IN,64,CMAC_TEST4_OUT); + printf("\n"); + + for(i=0;i<131072;++i) + cfbin[i] = (unsigned char)(i & 0xff); + for(i=0;i<16;++i) + iv[i] = (unsigned char)(i & 0xff); + for(i=12345;i<131072;i+=7777) + test_cfb(&expkey,cfbin,i,iv,cfbin); + + printf("\nTesting AES-DIGEST...\n"); + printf("0 bytes: "); + Anode_aes_digest(cfbin,0,iv); + for(i=0;i<16;++i) printf("%.2x",(unsigned int)iv[i]); + printf("\n"); + printf("%d bytes: ",(int)strlen(AES_DIGEST_TEST_1)); + Anode_aes_digest(AES_DIGEST_TEST_1,strlen(AES_DIGEST_TEST_1),iv); + for(i=0;i<16;++i) printf("%.2x",(unsigned int)iv[i]); + printf("\n"); + printf("%d bytes: ",(int)strlen(AES_DIGEST_TEST_2)); + Anode_aes_digest(AES_DIGEST_TEST_2,strlen(AES_DIGEST_TEST_2),iv); + for(i=0;i<16;++i) printf("%.2x",(unsigned int)iv[i]); + printf("\n"); + printf("%d bytes: ",(int)strlen(AES_DIGEST_TEST_3)); + Anode_aes_digest(AES_DIGEST_TEST_3,strlen(AES_DIGEST_TEST_3),iv); + for(i=0;i<16;++i) printf("%.2x",(unsigned int)iv[i]); + printf("\n"); + printf("%d bytes: ",(int)strlen(AES_DIGEST_TEST_4)); + Anode_aes_digest(AES_DIGEST_TEST_4,strlen(AES_DIGEST_TEST_4),iv); + for(i=0;i<16;++i) printf("%.2x",(unsigned int)iv[i]); + printf("\n"); + + return 0; +} + diff --git a/attic/historic/anode/libanode/tests/anode-secure_random-test.c b/attic/historic/anode/libanode/tests/anode-secure_random-test.c new file mode 100644 index 00000000..a6983653 --- /dev/null +++ b/attic/historic/anode/libanode/tests/anode-secure_random-test.c @@ -0,0 +1,38 @@ +/* libanode: the Anode C reference implementation + * Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <stdlib.h> +#include <stdio.h> +#include "../anode.h" +#include "../misc.h" + +int main(int argc,char **argv) +{ + unsigned char test[10005]; + unsigned int i; + AnodeSecureRandom srng; + + AnodeSecureRandom_init(&srng); + + AnodeSecureRandom_gen_bytes(&srng,test,sizeof(test)); + + for(i=0;i<sizeof(test);++i) { + printf("%.2x",(unsigned int)test[i]); + if ((i % 20) == 19) + printf("\n"); + } + printf("\n"); +} diff --git a/attic/historic/anode/libanode/tests/anode-utils-test.c b/attic/historic/anode/libanode/tests/anode-utils-test.c new file mode 100644 index 00000000..85bfe324 --- /dev/null +++ b/attic/historic/anode/libanode/tests/anode-utils-test.c @@ -0,0 +1,75 @@ +/* libanode: the Anode C reference implementation + * Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <stdlib.h> +#include <stdio.h> +#include "../anode.h" +#include "../misc.h" + +static const char *testuris[22] = { + "http://www.test.com", + "http://www.test.com/", + "http://www.test.com/path/to/something", + "http://user@www.test.com", + "http://user@www.test.com/path/to/something", + "http://user:password@www.test.com/path/to/something", + "http://www.test.com/path/to/something?query=foo&bar=baz", + "http://www.test.com/path/to/something#fragment", + "http://www.test.com/path/to/something?query=foo&bar=baz#fragment", + "http://user:password@www.test.com/path/to/something#fragment", + "http://user:password@www.test.com/path/to/something?query=foo&bar=baz#fragment", + "http://@www.test.com/", + "http://:@www.test.com/", + "http://www.test.com:8080/path/to/something", + "http://user:password@www.test.com:8080/path/to/something?query=foo#fragment", + "http://", + "http://www.test.com/path/to/something?#", + "http://www.test.com/path/to/something?#fragment", + "http:", + "http", + "mailto:this_is_a_urn@somedomain.com", + "" +}; + +int main(int argc,char **argv) +{ + int i,r; + char reconstbuf[2048]; + char *reconst; + AnodeURI uri; + + for(i=0;i<22;++i) { + printf("\"%s\":\n",testuris[i]); + r = AnodeURI_parse(&uri,testuris[i]); + if (r) { + printf(" error: %d\n",r); + } else { + printf(" scheme: %s\n",uri.scheme); + printf(" username: %s\n",uri.username); + printf(" password: %s\n",uri.password); + printf(" host: %s\n",uri.host); + printf(" port: %d\n",uri.port); + printf(" path: %s\n",uri.path); + printf(" query: %s\n",uri.query); + printf(" fragment: %s\n",uri.fragment); + } + reconst = AnodeURI_to_string(&uri,reconstbuf,sizeof(reconstbuf)); + printf("Reconstituted URI: %s\n",reconst ? reconst : "(null)"); + printf("\n"); + } + + return 0; +} diff --git a/attic/historic/anode/libanode/tests/anode-zone-test.c b/attic/historic/anode/libanode/tests/anode-zone-test.c new file mode 100644 index 00000000..08396716 --- /dev/null +++ b/attic/historic/anode/libanode/tests/anode-zone-test.c @@ -0,0 +1,47 @@ +/* libanode: the Anode C reference implementation + * Copyright (C) 2009 Adam Ierymenko <adam.ierymenko@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include "../anode.h" +#include "../dictionary.h" + +static int got_it = 0; + +static void zone_lookup_handler(void *ptr,long zone_id,AnodeZone *zone) +{ + if (zone) + printf("got %.8lx: %d entries\n",(unsigned long)zone_id & 0xffffffff,((struct AnodeDictionary *)zone)->size); + else printf("failed.\n"); + got_it = 1; +} + +int main(int argc,char **argv) +{ + AnodeTransportEngine transport; + + Anode_init_ip_transport_engine(&transport); + + AnodeZone_lookup(&transport,0,0,&zone_lookup_handler); + + while (!got_it) + transport.poll(&transport); + + transport.destroy(&transport); + + return 0; +} diff --git a/attic/historic/anode/libanode/tests/dictionary-test.c b/attic/historic/anode/libanode/tests/dictionary-test.c new file mode 100644 index 00000000..12a5fb2f --- /dev/null +++ b/attic/historic/anode/libanode/tests/dictionary-test.c @@ -0,0 +1,149 @@ +/* libanode: the Anode C reference implementation + * Copyright (C) 2009 Adam Ierymenko <adam.ierymenko@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <time.h> +#include <sys/time.h> +#include "../dictionary.h" + +static const char *HASH_TESTS[16] = { + "test", + "testt", + "", + "foo", + "fooo", + "1", + "2", + "3", + "4", + "11", + "22", + "33", + "44", + "adklfjklejrer", + "erngnetbekjrq", + "erklerqqqqre" +}; + +int diterate(void *arg,const char *key,const char *value) +{ + printf(" %s: %s\n",key ? key : "(null)",value ? value : "(null)"); + return 1; +} + +int main(int argc,char **argv) +{ + char tmp[1024]; + char fuzzparam1[16],fuzzparam2[16],fuzzparam3[16]; + struct AnodeDictionary d; + unsigned int i,j,k,cs; + + srandom(time(0)); + + printf("Trying out hash function a little...\n"); + for(i=0;i<16;++i) + printf(" %s: %u\n",HASH_TESTS[i],(unsigned int)AnodeDictionary__get_bucket(HASH_TESTS[i])); + + for(cs=0;cs<2;++cs) { + printf("\nTesting with case sensitivity = %d\n",cs); + AnodeDictionary_init(&d,cs); + + printf("\nTesting dictionary by adding and retrieving some keys...\n"); + AnodeDictionary_put(&d,"test1","This is the first test"); + AnodeDictionary_put(&d,"test2","This is the second test"); + AnodeDictionary_put(&d,"test3","This is the third test (lower case)"); + AnodeDictionary_put(&d,"TEST3","This is the third test (UPPER CASE)"); + AnodeDictionary_iterate(&d,(void *)0,&diterate); + if (d.size != (cs ? 4 : 3)) { + printf("Failed (size).\n"); + return 1; + } + + AnodeDictionary_clear(&d); + if (d.size||(AnodeDictionary_get(&d,"test1"))) { + printf("Failed (clear).\n"); + return 1; + } + + printf("\nTesting read, trial 1: simple key=value with unterminated line\n"); + strcpy(tmp,"foo=bar\nbar=baz\ntest1=Happy happy joyjoy!\ntest2=foobarbaz\nlinewithnocr=thisworked"); + AnodeDictionary_read(&d,tmp,"\r\n","=","",'\\',0,0); + printf("Results:\n"); + AnodeDictionary_iterate(&d,(void *)0,&diterate); + AnodeDictionary_clear(&d); + + printf("\nTesting read, trial 2: key=value with escape chars, escaped CRs\n"); + strcpy(tmp,"foo=bar\r\nbar==baz\nte\\=st1=\\=Happy happy joyjoy!\ntest2=foobarbaz\\\nfoobarbaz on next line\r\n"); + AnodeDictionary_read(&d,tmp,"\r\n","=","",'\\',0,0); + printf("Results:\n"); + AnodeDictionary_iterate(&d,(void *)0,&diterate); + AnodeDictionary_clear(&d); + + printf("\nTesting read, trial 3: HTTP header-like dictionary\n"); + strcpy(tmp,"Host: some.host.net\r\nX-Some-Header: foo bar\r\nX-Some-Other-Header: y0y0y0y0y0\r\n"); + AnodeDictionary_read(&d,tmp,"\r\n",": ","",0,0,0); + printf("Results:\n"); + AnodeDictionary_iterate(&d,(void *)0,&diterate); + AnodeDictionary_clear(&d); + + printf("\nTesting read, trial 4: single line key/value\n"); + strcpy(tmp,"Header: one line only"); + AnodeDictionary_read(&d,tmp,"\r\n",": ","",0,0,0); + printf("Results:\n"); + AnodeDictionary_iterate(&d,(void *)0,&diterate); + AnodeDictionary_clear(&d); + + printf("\nFuzzing dictionary reader...\n"); fflush(stdout); + for(i=0;i<200000;++i) { + j = random() % (sizeof(tmp) - 1); + for(k=0;k<j;++k) { + tmp[k] = (char)((unsigned int)random() >> 3); + if (!tmp[k]) tmp[k] = 1; + } + tmp[j] = (char)0; + + j = random() % (sizeof(fuzzparam1) - 1); + for(k=0;k<j;++k) { + fuzzparam1[k] = (char)((unsigned int)random() >> 3); + if (!fuzzparam1[k]) fuzzparam1[k] = 1; + } + fuzzparam1[j] = (char)0; + + j = random() % (sizeof(fuzzparam2) - 1); + for(k=0;k<j;++k) { + fuzzparam1[k] = (char)((unsigned int)random() >> 3); + if (!fuzzparam2[k]) fuzzparam2[k] = 1; + } + fuzzparam2[j] = (char)0; + + j = random() % (sizeof(fuzzparam3) - 1); + for(k=0;k<j;++k) { + fuzzparam3[k] = (char)((unsigned int)random() >> 3); + if (!fuzzparam3[k]) fuzzparam3[k] = 1; + } + fuzzparam3[j] = (char)0; + + AnodeDictionary_read(&d,tmp,fuzzparam1,fuzzparam2,fuzzparam3,random() & 3,random() & 1,random() & 1); + AnodeDictionary_clear(&d); + } + + AnodeDictionary_destroy(&d); + } + + return 0; +} diff --git a/attic/historic/anode/libanode/tests/ec-test.c b/attic/historic/anode/libanode/tests/ec-test.c new file mode 100644 index 00000000..49f04265 --- /dev/null +++ b/attic/historic/anode/libanode/tests/ec-test.c @@ -0,0 +1,97 @@ +/* libanode: the Anode C reference implementation + * Copyright (C) 2009 Adam Ierymenko <adam.ierymenko@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include "../impl/ec.h" +#include "../impl/misc.h" + +#define TEST_KEY_LEN 128 +#define AnodeEC_key_to_hex(k,b,l) Anode_to_hex((k)->key,(k)->bytes,(b),l) + +int main(int argc,char **argv) +{ + struct AnodeECKeyPair pair1; + struct AnodeECKeyPair pair2; + struct AnodeECKeyPair pair3; + unsigned char key[TEST_KEY_LEN]; + char str[16384]; + + printf("Creating key pair #1...\n"); + if (!AnodeECKeyPair_generate(&pair1)) { + printf("Could not create key pair.\n"); + return 1; + } + AnodeEC_key_to_hex(&pair1.pub,str,sizeof(str)); + printf("Public: %s\n",str); + AnodeEC_key_to_hex(&pair1.priv,str,sizeof(str)); + printf("Private: %s\n\n",str); + + printf("Creating key pair #2...\n"); + if (!AnodeECKeyPair_generate(&pair2)) { + printf("Could not create key pair.\n"); + return 1; + } + AnodeEC_key_to_hex(&pair2.pub,str,sizeof(str)); + printf("Public: %s\n",str); + AnodeEC_key_to_hex(&pair2.priv,str,sizeof(str)); + printf("Private: %s\n\n",str); + + printf("Key agreement between public #2 and private #1...\n"); + if (!AnodeECKeyPair_agree(&pair1,&pair2.pub,key,TEST_KEY_LEN)) { + printf("Agreement failed.\n"); + return 1; + } + Anode_to_hex(key,TEST_KEY_LEN,str,sizeof(str)); + printf("Agreed secret: %s\n\n",str); + + printf("Key agreement between public #1 and private #2...\n"); + if (!AnodeECKeyPair_agree(&pair2,&pair1.pub,key,TEST_KEY_LEN)) { + printf("Agreement failed.\n"); + return 1; + } + Anode_to_hex(key,TEST_KEY_LEN,str,sizeof(str)); + printf("Agreed secret: %s\n\n",str); + + printf("Testing key pair init function (init #3 from #2's parts)...\n"); + if (!AnodeECKeyPair_init(&pair3,&(pair2.pub),&(pair2.priv))) { + printf("Init failed.\n"); + return 1; + } + + printf("Key agreement between public #1 and private #3...\n"); + if (!AnodeECKeyPair_agree(&pair3,&pair1.pub,key,TEST_KEY_LEN)) { + printf("Agreement failed.\n"); + return 1; + } + Anode_to_hex(key,TEST_KEY_LEN,str,sizeof(str)); + printf("Agreed secret: %s\n\n",str); + + printf("Key agreement between public #1 and private #1...\n"); + if (!AnodeECKeyPair_agree(&pair1,&pair1.pub,key,TEST_KEY_LEN)) { + printf("Agreement failed.\n"); + return 1; + } + Anode_to_hex(key,TEST_KEY_LEN,str,sizeof(str)); + printf("Agreed secret (should not match): %s\n\n",str); + + AnodeECKeyPair_destroy(&pair1); + AnodeECKeyPair_destroy(&pair2); + AnodeECKeyPair_destroy(&pair3); + + return 0; +} diff --git a/attic/historic/anode/libanode/tests/environment-test.c b/attic/historic/anode/libanode/tests/environment-test.c new file mode 100644 index 00000000..c481a129 --- /dev/null +++ b/attic/historic/anode/libanode/tests/environment-test.c @@ -0,0 +1,28 @@ +/* libanode: the Anode C reference implementation + * Copyright (C) 2009 Adam Ierymenko <adam.ierymenko@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <stdio.h> +#include <stdlib.h> +#include "../environment.h" + +int main(int argc,char **argv) +{ + const char *cache = Anode_get_cache(); + + printf("Cache folder: %s\n",cache ? cache : "(null)"); + + return 0; +} diff --git a/attic/historic/anode/libanode/tests/http_client-test.c b/attic/historic/anode/libanode/tests/http_client-test.c new file mode 100644 index 00000000..e1f93967 --- /dev/null +++ b/attic/historic/anode/libanode/tests/http_client-test.c @@ -0,0 +1,233 @@ +/* libanode: the Anode C reference implementation + * Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <openssl/sha.h> +#include "../anode.h" +#include "../misc.h" +#include "../http_client.h" +#include "../dictionary.h" + +struct TestCase +{ + int method; + AnodeURI uri; + const void *client_data; + unsigned int client_data_len; + const char *expected_sha1; + char actual_sha1[64]; + int got_it; + int keepalive; + struct TestCase *next; +}; + +#define NUM_TEST_CASES 7 +static struct TestCase test_cases[NUM_TEST_CASES]; + +static void init_test_cases(int keepalive) +{ + AnodeURI_parse(&(test_cases[0].uri),"http://zerotier.com/for_unit_tests/test1.txt"); + test_cases[0].method = ANODE_HTTP_GET; + test_cases[0].client_data_len = 0; + test_cases[0].expected_sha1 = "0828324174b10cc867b7255a84a8155cf89e1b8b"; + test_cases[0].actual_sha1[0] = (char)0; + test_cases[0].got_it = 0; + test_cases[0].keepalive = keepalive; + test_cases[0].next = &(test_cases[1]); + + AnodeURI_parse(&(test_cases[1].uri),"http://zerotier.com/for_unit_tests/test2.bin"); + test_cases[1].method = ANODE_HTTP_GET; + test_cases[1].client_data_len = 0; + test_cases[1].expected_sha1 = "6b67c635786ab52666211d02412c0d0f0372980d"; + test_cases[1].actual_sha1[0] = (char)0; + test_cases[1].got_it = 0; + test_cases[1].keepalive = keepalive; + test_cases[1].next = &(test_cases[2]); + + AnodeURI_parse(&(test_cases[2].uri),"http://zerotier.com/for_unit_tests/test3.bin"); + test_cases[2].method = ANODE_HTTP_GET; + test_cases[2].client_data_len = 0; + test_cases[2].expected_sha1 = "efa7722029fdbb6abd0e3ed32a0b44bfb982cff0"; + test_cases[2].actual_sha1[0] = (char)0; + test_cases[2].got_it = 0; + test_cases[2].keepalive = keepalive; + test_cases[2].next = &(test_cases[3]); + + AnodeURI_parse(&(test_cases[3].uri),"http://zerotier.com/for_unit_tests/test4.bin"); + test_cases[3].method = ANODE_HTTP_GET; + test_cases[3].client_data_len = 0; + test_cases[3].expected_sha1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709"; + test_cases[3].actual_sha1[0] = (char)0; + test_cases[3].got_it = 0; + test_cases[3].keepalive = keepalive; + test_cases[3].next = &(test_cases[4]); + + AnodeURI_parse(&(test_cases[4].uri),"http://zerotier.com/for_unit_tests/echo.php?echo=foobar"); + test_cases[4].method = ANODE_HTTP_GET; + test_cases[4].client_data_len = 0; + test_cases[4].expected_sha1 = "8843d7f92416211de9ebb963ff4ce28125932878"; + test_cases[4].actual_sha1[0] = (char)0; + test_cases[4].got_it = 0; + test_cases[4].keepalive = keepalive; + test_cases[4].next = &(test_cases[5]); + + AnodeURI_parse(&(test_cases[5].uri),"http://zerotier.com/for_unit_tests/echo.php"); + test_cases[5].method = ANODE_HTTP_POST; + test_cases[5].client_data = "echo=foobar"; + test_cases[5].client_data_len = strlen((char *)test_cases[5].client_data); + test_cases[5].expected_sha1 = "8843d7f92416211de9ebb963ff4ce28125932878"; + test_cases[5].actual_sha1[0] = (char)0; + test_cases[5].got_it = 0; + test_cases[5].keepalive = keepalive; + test_cases[5].next = &(test_cases[6]); + + AnodeURI_parse(&(test_cases[6].uri),"http://zerotier.com/for_unit_tests/test3.bin"); + test_cases[6].method = ANODE_HTTP_HEAD; + test_cases[6].client_data_len = 0; + test_cases[6].expected_sha1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709"; + test_cases[6].actual_sha1[0] = (char)0; + test_cases[6].got_it = 0; + test_cases[6].keepalive = keepalive; + test_cases[6].next = 0; +} + +static int http_handler_dump_headers(void *arg,const char *key,const char *value) +{ + printf(" H %s: %s\n",key,value); + return 1; +} + +static void http_handler(struct AnodeHttpClient *client) +{ + const char *method = "???"; + char buf[1024]; + unsigned char sha[20]; + struct TestCase *test = (struct TestCase *)client->ptr[0]; + + switch(client->method) { + case ANODE_HTTP_GET: + method = "GET"; + break; + case ANODE_HTTP_HEAD: + method = "HEAD"; + break; + case ANODE_HTTP_POST: + method = "POST"; + break; + } + + if (client->response.code == 200) { + SHA1((unsigned char *)client->response.data,client->response.data_length,sha); + Anode_to_hex(sha,20,test->actual_sha1,sizeof(test->actual_sha1)); + printf("%s %s\n * SHA1: %s exp: %s\n",method,AnodeURI_to_string(&(test->uri),buf,sizeof(buf)),test->actual_sha1,test->expected_sha1); + if (strcmp(test->actual_sha1,test->expected_sha1)) + printf(" ! SHA1 MISMATCH!\n"); + AnodeDictionary_iterate(&(client->response.headers),0,&http_handler_dump_headers); + } else printf("%s %s: ERROR: %d\n",method,AnodeURI_to_string(&(test->uri),buf,sizeof(buf)),client->response.code); + + test->got_it = 1; + + if (!test->keepalive) + AnodeHttpClient_free(client); + else { + test = test->next; + if (test) { + memcpy((void *)&(client->uri),(const void *)&(test->uri),sizeof(AnodeURI)); + + client->data = test->client_data; + client->data_length = test->client_data_len; + client->ptr[0] = test; + client->keepalive = test->keepalive; + client->method = test->method; + client->handler = &http_handler; + + AnodeHttpClient_send(client); + } else { + AnodeHttpClient_free(client); + } + } +} + +int main(int argc,char **argv) +{ + struct AnodeHttpClient *client; + AnodeTransportEngine transport_engine; + int i; + + if (Anode_init_ip_transport_engine(&transport_engine)) { + printf("Failed (transport engine init)\n"); + return 1; + } + + printf("Testing without keepalive...\n\n"); + init_test_cases(0); + for(i=0;i<NUM_TEST_CASES;++i) { + client = AnodeHttpClient_new(&transport_engine); + + memcpy((void *)&(client->uri),(const void *)&(test_cases[i].uri),sizeof(AnodeURI)); + client->data = test_cases[i].client_data; + client->data_length = test_cases[i].client_data_len; + client->ptr[0] = &test_cases[i]; + client->keepalive = test_cases[i].keepalive; + client->method = test_cases[i].method; + client->handler = &http_handler; + + AnodeHttpClient_send(client); + } + + for(;;) { + for(i=0;i<NUM_TEST_CASES;++i) { + if (!test_cases[i].got_it) + break; + } + if (i == NUM_TEST_CASES) + break; + transport_engine.poll(&transport_engine); + } + printf("\n\n"); + + printf("Testing with keepalive...\n\n"); + init_test_cases(1); + + client = AnodeHttpClient_new(&transport_engine); + + i = 0; + memcpy((void *)&(client->uri),(const void *)&(test_cases[i].uri),sizeof(AnodeURI)); + client->data = test_cases[i].client_data; + client->data_length = test_cases[i].client_data_len; + client->ptr[0] = &test_cases[i]; + client->keepalive = test_cases[i].keepalive; + client->method = test_cases[i].method; + client->handler = &http_handler; + + AnodeHttpClient_send(client); + + for(;;) { + for(i=0;i<NUM_TEST_CASES;++i) { + if (!test_cases[i].got_it) + break; + } + if (i == NUM_TEST_CASES) + break; + transport_engine.poll(&transport_engine); + } + + transport_engine.destroy(&transport_engine); + + return 0; +} diff --git a/attic/historic/anode/libanode/tests/misc-test.c b/attic/historic/anode/libanode/tests/misc-test.c new file mode 100644 index 00000000..e5b9085f --- /dev/null +++ b/attic/historic/anode/libanode/tests/misc-test.c @@ -0,0 +1,137 @@ +/* libanode: the Anode C reference implementation + * Copyright (C) 2009 Adam Ierymenko <adam.ierymenko@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <time.h> +#include <sys/time.h> +#include "../misc.h" + +int main(int argc,char **argv) +{ + const char *base32TestStr = "asdf"; + char *fields[16]; + char buf[1024]; + char buf2[1024]; + char buf3[4096]; + unsigned int i; + unsigned long tmpl,tmpl2; + unsigned long long tmp64; + + srand(time(0)); + + Anode_base32_5_to_8((const unsigned char *)base32TestStr,buf); + printf("Base32 from test string: %s\n",buf); + Anode_base32_8_to_5("MFZWIZQA",(unsigned char *)buf2); + printf("Test string from Base32 (upper case): %s\n",buf2); + Anode_base32_8_to_5("mfzwizqa",(unsigned char *)buf2); + printf("Test string from Base32 (lower case): %s\n",buf2); + printf("Testing variable length encoding/decoded with pad5 functions...\n"); + for(i=0;i<1024;++i) { + tmpl = rand() % (sizeof(buf) - 8); + if (!tmpl) + tmpl = 1; + for(tmpl2=0;tmpl2<tmpl;++tmpl2) + buf[tmpl2] = (buf2[tmpl2] = (char)(rand() >> 3)); + if (!Anode_base32_encode_pad5(buf2,tmpl,buf3,sizeof(buf3))) { + printf("Failed (encode failed).\n"); + return 1; + } + memset(buf2,0,sizeof(buf2)); + if (!Anode_base32_decode_pad5(buf3,buf2,sizeof(buf2))) { + printf("Failed (decode failed).\n"); + return 1; + } + if (memcmp(buf,buf2,tmpl)) { + printf("Failed (compare failed).\n"); + return 1; + } + } + + printf("Anode_htonll(0x0102030405060708) == 0x%.16llx\n",tmp64 = Anode_htonll(0x0102030405060708ULL)); + printf("Anode_ntohll(0x%.16llx) == 0x%.16llx\n",tmp64,Anode_ntohll(tmp64)); + if (Anode_ntohll(tmp64) != 0x0102030405060708ULL) { + printf("Failed.\n"); + return 1; + } + + strcpy(buf,"foo bar baz"); + Anode_trim(buf); + printf("Testing string trim: 'foo bar baz' -> '%s'\n",buf); + strcpy(buf,"foo bar baz "); + Anode_trim(buf); + printf("Testing string trim: 'foo bar baz ' -> '%s'\n",buf); + strcpy(buf," foo bar baz"); + Anode_trim(buf); + printf("Testing string trim: ' foo bar baz' -> '%s'\n",buf); + strcpy(buf," foo bar baz "); + Anode_trim(buf); + printf("Testing string trim: ' foo bar baz ' -> '%s'\n",buf); + strcpy(buf,""); + Anode_trim(buf); + printf("Testing string trim: '' -> '%s'\n",buf); + strcpy(buf," "); + Anode_trim(buf); + printf("Testing string trim: ' ' -> '%s'\n",buf); + + printf("Testing string split.\n"); + strcpy(buf,"66.246.138.121,5323,0"); + i = Anode_split(buf,';',fields,16); + if (i != 1) { + printf("Failed.\n"); + return 1; + } else printf("Fields: %s\n",fields[0]); + strcpy(buf,"a;b;c"); + i = Anode_split(buf,';',fields,16); + if (i != 3) { + printf("Failed.\n"); + return 1; + } else printf("Fields: %s %s %s\n",fields[0],fields[1],fields[2]); + strcpy(buf,";;"); + i = Anode_split(buf,';',fields,16); + if (i != 3) { + printf("Failed.\n"); + return 1; + } else printf("Fields: %s %s %s\n",fields[0],fields[1],fields[2]); + strcpy(buf,"a;b;"); + i = Anode_split(buf,';',fields,16); + if (i != 3) { + printf("Failed.\n"); + return 1; + } else printf("Fields: %s %s %s\n",fields[0],fields[1],fields[2]); + strcpy(buf,"a;;c"); + i = Anode_split(buf,';',fields,16); + if (i != 3) { + printf("Failed.\n"); + return 1; + } else printf("Fields: %s %s %s\n",fields[0],fields[1],fields[2]); + strcpy(buf,";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"); + i = Anode_split(buf,';',fields,16); + if (i != 16) { + printf("Failed.\n"); + return 1; + } + strcpy(buf,""); + i = Anode_split(buf,';',fields,16); + if (i != 0) { + printf("Failed.\n"); + return 1; + } + printf("Passed.\n"); + + return 0; +} diff --git a/attic/historic/anode/libanode/tests/system_transport-test.c b/attic/historic/anode/libanode/tests/system_transport-test.c new file mode 100644 index 00000000..bda575ed --- /dev/null +++ b/attic/historic/anode/libanode/tests/system_transport-test.c @@ -0,0 +1,70 @@ +/* libanode: the Anode C reference implementation + * Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sys/socket.h> +#include "../anode.h" +#include "../impl/thread.h" + +static int do_client() +{ + AnodeTransport *st; + AnodeSocket *udp_sock; + int run = 1; + + st = AnodeSystemTransport_new(NULL); + if (!st) { + printf("FAILED: unable to construct AnodeSystemTransport.\n"); + return -1; + } + printf("Created AnodeSystemTransport.\n"); + + while (run) + st->poll(st); +} + +static int do_server() +{ + AnodeTransport *st; + AnodeSocket *udp_sock; + AnodeSocket *tcp_sock; + int run = 1; + + st = AnodeSystemTransport_new(NULL); + if (!st) { + printf("FAILED: unable to construct AnodeSystemTransport.\n"); + return -1; + } + printf("Created AnodeSystemTransport.\n"); + + while (run) + st->poll(st); +} + +int main(int argc,char **argv) +{ + if (argc == 2) { + if (!strcmp(argv[1],"client")) + return do_client(); + else if (!strcmp(argv[1],"server")) + return do_server(); + } + + printf("Usage: system_transport-test <client / server>\n"); + return -1; +} |