// Copyright (c) 2013-2015 IONU Security, Inc. All rights reserved. // // Command line test program for libeye C++ and C interfaces #include #include #include #include #include #include #include #include #include #include #include #include //#include "eyeball.h" //#include "eyecontainer.h" #include "eyeencrypteddb.h" //#include "eyedirectory.h" #include "eyedrbg.h" #include "eyeinterface.h" #include "eyejson.h" #include "eyelock.h" #include "eyelog.h" //#include "eyeconnection.h" #include "eyering.h" #ifdef ALAN #include "eyesearch.h" #include "eyestemmer.h" #endif //#include "eyestream.h" #include "eyetime.h" #include "eyeutils.h" long ms; // System time in milliseconds const char* shortword = "Hi"; const char* password = "u3K2*l$qZ0a<"; static const char* passwordset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"; unsigned char garbage[SL_AES_KEY_LEN]; static const char* longtest = "test/thisisaverylongtestpathfortarformatcheckingandverificationpurposes_exceedstar1988maxpath/verylongpathtartest.txt"; static const char* testfile = "test/tartest.txt"; static const char* testfile_orig = "test/tartest.orig"; static const char* attachfile = "test/attachment.docx"; static const char* thumbfile = "test/thumb.png"; static const char* xmlfile = "test/test.xsd"; static const char* htmlfile = "test/test.html"; static const char* jsonfile = "test/test.json"; static const char* njsonfile = "test/nothere.json"; static const char* cionu = "test/ctest.ionu"; static const char* oldionu = "test/old.ionu"; static const char* yoionu = "test/yotest.ionu"; // Modified .iks files static const char* empty_iks = "test/empty.iks"; // Modified .ionu files static const char* empty_ionu = "test/empty.ionu"; static const char* perm_mods = "test/perm_mods.ionu"; static const char* meta_corrupt = "test/meta_corrupt.ionu"; static const char* fek_corrupt = "test/badfek1.ionu"; static const char* chksum_corrupt = "test/badchksum.ionu"; static const char* keystore = "test/keystore.iks"; static const unsigned char TestKey[SL_AES_KEY_LEN] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31}; //static const unsigned char TGIkey[SL_AES_KEY_LEN] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31}; static const unsigned char badkey[SL_AES_KEY_LEN] = {1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31}; static const unsigned char utf8[10] = {0x24, 0xc2,0xa2, 0xe2,0x82,0xac, 0xf0,0xa4,0xad,0xa2}; static const char* smiley = "SMILING FACE WITH OPEN MOUTH AND SMILING EYES \\uD83D\\uDE04"; static const char* utfjson = "\\u0123\\u4567\\u89AB\\uCDEF\\uabcd\\uef4A "; static const char* utfeuro = "euro \\u20ac cent \\u00a2"; static const char* URN = "urn:sl:FFFFFF:FFFFFFFF:FFFF:FFFFFFFFFFFF"; static const char* URN0 = "urn:sl:000000:00000000:FFFF:D2F04FEB8495"; static const char* URN1 = "urn:sl:000000:00000000:FFFF:"; static const char* URN2 = "urn:sl:000100:00000100::000000000ED2"; static const char* URN3 = "urn:sl:000101:00001000::"; static const char* URN4 = "urn:sl:001001:::"; static const char* URN5 = "urn:sl::::"; static const char* officeURN = "urn:sl:000000:12345678:::"; static const char* docURN = "urn:sl:000000:12345678:ABCD:0123456789AB"; static const char* burn0 = "urn:sl:000001:00000010:7fFf:000000000EG2"; // Bad digit static const char* burn1 = "urn:sl:000001:7fffffff:0A00"; // Missing field static const char* burn2 = "urn:sl:000001:00000010:0A00:000000000ED2:00"; // extra field static const char* burn3 = "urn:sl:1ffffff:fFfFfF:FfFf:000000000ED2"; // Too large van static const char* burn4 = "urn:sl:0:1fffFfFfF:FfFf:000000000ED2"; // Too large pmo static const char* burn5 = "urn:sl:0:fFfFfF:1FfFf:000000000ED2"; // Too large device static const char* burn6 = "urn:sl:ffffff:fffFfFfF:FfFf:1ffffffffffff"; // Too large device static const char* burn7 = "urn:ion:002:1ffffff:0A00:000000000ED2"; // Invalid ionu static const char* shredurn = "urn:sl:000011:00000010:0ABC:00000000DED2"; //static const char* challenges = "[{\"me\":\"urn:sl:000001:00000010::\"},{\"tim\":\"urn:sl:000011:00000010::\"}]"; #ifndef WIN32 static const std::vector challengeQuestions = {"favbook", "flame", "kiss", "kissloc", "concert", "memperson", "favchar", "favsay", "neverinv", "bestcostume", "growndiff", "wallpic", "childnames", "songdesc", "erasure", "custom"}; static const std::vector challengeAnswers = {"HARRYPOTTER", "LUANN", "LAURIE", "TRUCK", "BTO", "EDISON", "NIKITA", "HAVEYOUFIGUREDITOUT", "OBAMA", "BUNNY", "FLINTSTONE", "RANDOM", "JACK", "HMMMMMM", "ARNOLD", "MYQUESTION"}; #endif static const char* challenges = "[\"IOnU\",\"favchar::BOULDER\",\"celebrity::UNIT TEST\",\"custom:UNIT:TESTING\"]"; static const char* challenges1 = "[\"IOnU\",\"favchar::LARAMIE\",\"celebrity::UNIT TEST\",\"custom:UNIT:TESTING\"]"; static const char* challenges2 = "[\"IOnU\",\"favchar::DUBLIN\",\"celebrity::BONO\",\"custom:FAVORITE BIKE:BMW\"]"; static const char* challenges3 = "[\"IOnU\",\"favchar::RENO\",\"celebrity::HARAH\",\"custom:FAVORITEBIKE:YAMAHAH\"]"; static const char* challenges4 = "[\"IOnU\",\"favchar::NEWYORK\",\"celebrity::BLOOMBERG\",\"custom:FAVORITEBIKE:TREK\"]"; static const char* challenges5 = "[\"IOnU\",\"favchar::WASHINGTONDC\",\"celebrity::BOND\",\"custom:FAVORITEBIKE:DUCATI\"]"; static const char* challenges6 = "[\"IOnU\",\"favchar::CUPERTINO\",\"celebrity::SHIVA\",\"custom:FAVORITEBIKE:CERVELO\"]"; static const char* challenges7 = "[\"IOnU\",\"favchar::CHEYENNE\",\"celebrity::TOBYKEITH\",\"custom:FAVORITEBIKE:SUZUKI\"]"; static const char* challenges8 = "[\"IOnU\",\"BOB\",\"SMITH\",\"NIKKI\"]"; static const char* challenges9 = "[\"IOnU\",\"one\",\"two\",\"three\"]"; static const char* challenges10 = "[\"IOnU\",\"one\",\"one\",\"one\"]"; static const char* challenges11 = "[\"one\",\"two\",\"three\"]"; static const char* challenges12 = "[\"IOnU\",\"favbook::ONE\",\"flame::TWO\",\"kiss::THREE\"]"; static const char* shortchallenge = "[\"IOnU\"]"; static const char* supershortchallenge = "onetwothree"; static const char* members = "[{\"me\":\"urn:sl:000001:00000010::\"},{\"tim\":\"urn:sl:000011:00000010::\"}]"; static const char* cgurl = "/cgsl/v2/office/discover?email=freddy&password=6EVdXfSkSX%2bI15ZXGCRRH4TnpBnt17ivih5Nd7DxkPQ%3d&\ vanURN=urn%3aionu%3a000000%3a%3a%3a&deviceURN=urn%3aionu%3a000000%3aEB3AFD45%3a4239%3a"; static const char* badMeta = "\ {platform=OSX, utime=2014-04-26T17:23:19.996Z, status=modified, contents=[{\"md5\":\"b2ab1008fefd005d9ade42e3d63205ff\",\ \"metatype\":\"msg\",\"mimetype\":\"text/plain\",\"time\":\"2014-04-26T17:23:17Z\",\"size\":8},\ {\"md5\":\"30ed0df9f4203931f8a539c0fcd6539c\",\"metatype\":\"file\",\"mimetype\":\"image/jpeg\",\ \"time\":\"2014-04-26T17:23:17Z\",\"size\":131118}], modified_date=2014-04-26T17:23:17.221Z, \ mtime=2014-04-26T17:24:12.838Z, file_operations={\"vanished_on\":{\"urn:sl:000000:67D77BB4::\":\"2014-04-26T17:24:05.983Z\"}},\ digest=sha256, ver=0.1, drr=true, tgisig=656930478659, urn=urn:sl:000000:A606592D:0F47:9F496CEBE3AF, \ burn_date=2014-04-26T17:24:05.883Z, magic=IOnU Encrypted Archive, expires=2014-04-26T17:24:05.899Z, sync=false, tctr=18, \ modified_by=urn:sl:000000:A606592D:0F47:, action=VANISH, rr=[\"urn:sl:000000:67D77BB4::\"], seq=3, cipher=aes256cbc, tbr=true, rrr=true}"; static const char* vanishMeta = "\ {\"platform\":\"OSX\",\"utime\":\"2014-04-26T17:23:19.996Z\",\"status\":\"modified\",\"contents\":[{\"md5\":\"b2ab1008fefd005d9ade42e3d63205ff\",\ \"metatype\":\"msg\",\"mimetype\":\"text/plain\",\"time\":\"2014-04-26T17:23:17Z\",\"size\":8},{\"md5\":\"30ed0df9f4203931f8a539c0fcd6539c\",\ \"metatype\":\"file\",\"mimetype\":\"image/jpeg\",\"time\":\"2014-04-26T17:23:17Z\",\"size\":131118}],\"modified_date\":\"2014-04-26T17:23:17.221Z\",\ \"mtime\":\"2014-04-26T17:24:12.838Z\",\"file_operations\":{\"vanished_on\":{\"urn:sl:000000:67D77BB4::\":\"2014-04-26T17:24:05.983Z\"}},\ \"digest\":\"sha256\",\"ver\":\"0.1\",\"drr\":true,\"tgisig\":\"656930478659\",\"urn\":\"urn:sl:000000:A606592D:0F47:9F496CEBE3AF\",\ \"burn_date\":\"2014-04-26T17:24:05.883Z\",\"magic\":\"IOnU Encrypted Archive\",\"expires\":\"2014-04-26T17:24:05.899Z\",\"sync\":false,\ \"tctr\":16,\"modified_by\":\"urn:sl:000000:A606592D:0F47:\",\"action\":\"VANISH\",\"rr\":[\"urn:sl:000000:67D77BB4::\"],\"seq\":3,\ \"cipher\":\"aes256cbc\",\"tbr\":true,\"rrr\":true}"; static const char* uploadedMeta = "\ {\"magic\":\"IOnU Encrypted Archive\",\"tgisig\":\"64f2a81d678c\",\"urn\":\"urn:sl:000000:17C38E5A:C60D:79916D07C42C\",\ \"modified_by\":\"urn:sl:000000:17C38E5A:C60D:\",\"drr\":true,\"contents\":[{\"time\":\"2014-01-02T16:56:29Z\",\ \"mimetype\":\"text/plain\",\"size\":2,\"metatype\":\"msg\",\"md5\":\"23b58def11b45727d3351702515f86af\"},\ {\"time\":\"2014-01-02T16:56:29Z\",\"mimetype\":\"image\\/jpeg\",\"size\":565679,\"metatype\":\"file\",\ \"md5\":\"fa802d84e9618dc23b5dbaaa17e31a8d\"}],\"platform\":\"OSX\",\"seq\":2,\"tctr\":5,\"rr\":[\"\"],\ \"utime\":\"2014-01-02T16:56:31.308Z\",\"ver\":\"0.1\",\"synchronized_date\":\"2014-01-02T16:57:59.333Z\",\ \"modified_date\":\"2014-01-02T16:56:30.274Z\",\"cipher\":\"aes256cbc\",\"digest\":\"sha256\",\ \"status\":\"modified\",\"mtime\":\"2014-01-02T16:57:57.851Z\"}"; static const char* someMeta = "\ {\"utime\":\"2014-04-22T16:01:43.765Z\",\"platform\":\"Windows\",\"status\":\"modified\",\"modified_date\":\"2014-04-22T16:01:41.629Z\",\ \"contents\":[{\"md5\":\"9b5c5c35567fc20ad7f305014cddfcd0\",\"metatype\":\"msg\",\"mimetype\":\"text\\/plain\",\"time\":\"2014-04-22T16:01:41Z\",\ \"size\":3}],\"mtime\":\"2014-04-28T22:05:25.481Z\",\"digest\":\"sha256\",\"ver\":\"0.1\",\"drr\":true,\"tgisig\":\"16dadd9cb2ac\",\ \"urn\":\"urn:sl:000000:6BBC3A33:F9CB:6F3AE7A6CBA3\",\"magic\":\"IOnU Encrypted Archive\",\"sync\":false,\"tctr\":5,\ \"modified_by\":\"urn:sl:000000:6BBC3A33:F9CB:\",\"seq\":2,\"rr\":[\"\"],\"action\":\"DELETE\",\"cipher\":\"aes256cbc\",\"tbr\":false,\"rrr\":true,\"dr\":[\"\"]}"; static const char* updateMeta = "\ {\"modified_by\":\"urn:sl:Alan00:17C38E5A:C60D:\",\"drr\":true}"; static const char* operationsMeta = "\ {\"file_operations\":\         \"deleted_by\":{\             \"urn:sl:000000:4616E326::\":\"2014-01-07T20:15:25.543Z\",\             \"urn:sl:000000:6B424AA9::\":\"2014-01-07T07:33:11.228Z\"\       },\         \"vanished_on\":{\             \"urn:sl:000000:6B424AA9::\":\"2014-01-06T23:12:18.155Z\"\         }\     }"; static const char* megaMeta = "\ {\"ver\":\"0.1\",\"magic\":\"IOnU Encrypted Archive\",\"status\":\"modified\",\"tctr\":0,\"urn\":\"urn:ion\ u:000001:00000010:0011:00000000ffff\",\"cipher\":\"aes256cbc\",\"digest\":\"sha256\",\"tgi\ sig\":\"6a0ce1ec504b\",\"contents\":[{\"metatype\":\"msg\",\"mimetype\":\"text/plain\",\"size\"\ :11,\"time\":\"2013-08-08T20:56:57Z\"},{\"metatype\":\"file\",\"mimetype\":\"application/vn\ d.ms-word\",\"size\":20721,\"time\":\"2013-08-01T23:34:29Z\"},{\"metatype\":\"thumb\",\"mime\ type\":\"image/png\",\"size\":45119,\"time\":\"2013-08-01T23:34:29Z\"},{\"metatype\":\"msg\",\ \"mimetype\":\"text/plain\",\"size\":14,\"time\":\"2013-08-08T20:56:57Z\"}]}"; static const char* tgiMeta = "\ {\"ver\":\"0.1\",\"magic\":\"IOnU Encrypted Archive\",\"status\":\"modified\",\"tctr\":0,\"urn\":\"urn:ion\ u:000001:00000010:0011:00000000ffff\",\"cipher\":\"aes256cbc\",\"digest\":\"sha256\",\"tgi\ sig\":\"6b0ce1ec504b\",\"contents\":[{\"metatype\":\"msg\",\"mimetype\":\"text/plain\",\"size\"\ :11,\"time\":\"2013-08-08T20:56:57Z\"},{\"metatype\":\"file\",\"mimetype\":\"application/vn\ d.ms-word\",\"size\":20721,\"time\":\"2013-08-01T23:34:29Z\"},{\"metatype\":\"thumb\",\"mime\ type\":\"image/png\",\"size\":45119,\"time\":\"2013-08-01T23:34:29Z\"},{\"metatype\":\"msg\",\ \"mimetype\":\"text/plain\",\"size\":14,\"time\":\"2013-08-08T20:56:57Z\"}]}"; //static const char* members = "[\"urn:sl:000001:00000010::\",\"urn:sl:000011:00000010::\"]"; static const char* collabs = "{\"collab\":[{\"publicKey\":\"\ -----BEGIN PUBLIC KEY-----\n\ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzBTVhKef/68WvTns382x\n\ Pw9i4RvZX3y8DH70YEvP3WgqC39pD3PLhe7RiRvEGHWm0cdVpvUg1rdUE1pVPNSZ\n\ jan/I8YUuX9eqLDZf6iqCYm5KwLjreaz2T0QBaKCs98I2W5qULbzKhqtw3Yp9gOy\n\ ZTlEbgkg0ZVunzLr42se0LsvmbWlEr3UksyzAJfsE6q0eKjyvpaoAFT1nTEr84Ir\n\ ZqUdn2YKV80WX9zj7maQqWviDKowxK8NKO50oCouTXNDpxwYKqoT9/8rcpOUSXaw\n\ BDbcNZWHKvG8e8icxLQqpDT3Egdnz+VtQXRwk1Yuyt8eE9jgh5dmBoo7PspQt6EV\n\ vwIDAQAB\n\ -----END PUBLIC KEY-----\ \",\"_id\":\"urn:sl:000001:00000010::\"},\ {\"publicKey\":\"\ -----BEGIN PUBLIC KEY-----\n\ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzBTVhKef/68WvTns382x\n\ Pw9i4RvZX3y8DH70YEvP3WgqC39pD3PLhe7RiRvEGHWm0cdVpvUg1rdUE1pVPNSZ\n\ jan/I8YUuX9eqLDZf6iqCYm5KwLjreaz2T0QBaKCs98I2W5qULbzKhqtw3Yp9gOy\n\ ZTlEbgkg0ZVunzLr42se0LsvmbWlEr3UksyzAJfsE6q0eKjyvpaoAFT1nTEr84Ir\n\ ZqUdn2YKV80WX9zj7maQqWviDKowxK8NKO50oCouTXNDpxwYKqoT9/8rcpOUSXaw\n\ BDbcNZWHKvG8e8icxLQqpDT3Egdnz+VtQXRwk1Yuyt8eE9jgh5dmBoo7PspQt6EV\n\ vwIDAQAB\n\ -----END PUBLIC KEY-----\ \",\"_id\":\"urn:sl:000011:00000010::\"}]}"; static const char* PERMS = "{\"read\":[\"00000003\"],\"readAssign\":[\"00000003\"],\"write\":[\"00000003\"],\"writeAssign\":[\"00000003\"],\"admin\":[\"00000003\"],\"adminAssign\":[\"00000003\"],\"stream\":[],\"streamAssign\":[],\"doorway\":[],\"doorwayAssign\":[],\"owner\":\"00000003\"}"; static const char* PERMS2 = "{\"read\":[\"00000003\",\"00000077\"],\"readAssign\":[\"00000003\"],\"write\":[\"00000003\"],\"writeAssign\":[\"00000003\"],\"admin\":[\"00000003\"],\"adminAssign\":[\"00000003\"],\"stream\":[],\"streamAssign\":[],\"doorway\":[],\"doorwayAssign\":[],\"owner\":\"00000003\"}"; static const char* PERMS3 = "{\"read\":[\"00000003\",\"17C38E5A\"],\"adminAssign\":[\"00000003\",\"17C38E5A\"],\"admin\":[\"00000003\",\"17C38E5A\"],\"writeAssign\":[\"00000003\",\"17C38E5A\"],\"hideAssign\":[\"00000003\",\"17C38E5A\"],\"stream\":[],\"readAssign\":[\"00000003\",\"17C38E5A\"],\"owner\":\"00000003\",\"doorwayAssign\":[],\"write\":[\"00000003\",\"17C38E5A\"],\"doorway\":[],\"hide\":[],\"streamAssign\":[]}"; static const char* TopicPerms = "{\"read\":[\"123456AB\",\"123456CD\"],\"write\":[\"123456AB\"],\"admin\":[],\"doorway\":[],\"stream\":[],\"hide\":[],\"readAssign\":[\"123456AB\"],\"writeAssign\":[\"123456AB\"],\"adminAssign\":[],\"doorwayAssign\":[],\"streamAssign\":[],\"hideAssign\":[\"123456AB\"],\"topic\":\"A456BA456BA456B\"}"; static const char* policyTest = "{ \"_id\" : \"urn:sl:000000:::\", \"name\" : \"TEST VAN\", \"statusPassphrase\" : \"madman\", \"tokenPassphrase\" : \"madman\", \"policies\": [\ {\"policyName\": \"allowUserPasswordChange\", \"policyType\": \"BOOLEAN\", \"mayDelegateToAdminUsers\": true, \"mayDelegateToNormalUsers\": false, \"mayAdministerViaRemoteApp\": true, \"policyValue\": true},\ {\"policyName\": \"allowUserPasswordReset\", \"policyType\": \"BOOLEAN\", \"mayDelegateToAdminUsers\": true, \"mayDelegateToNormalUsers\": false, \"mayAdministerViaRemoteApp\": true, \"policyValue\": false},\ {\"policyName\": \"cachedTGIKeysExpire\", \"policyType\": \"duration\", \"mayDelegateToAdminUsers\": true, \"mayDelegateToNormalUsers\": false, \"mayAdministerViaRemoteApp\": true, \"policyValue\": 86400000},\ {\"policyName\": \"duration\", \"policyType\": \"BOOLEAN\", \"mayDelegateToAdminUsers\": true, \"mayDelegateToNormalUsers\": false, \"mayAdministerViaRemoteApp\": true, \"policyValue\": 1.5552E7},\ {\"policyName\": \"percentage\", \"policyType\": \"BOOLEAN\", \"mayDelegateToAdminUsers\": true, \"mayDelegateToNormalUsers\": false, \"mayAdministerViaRemoteApp\": true, \"policyValue\": 99.9}]}"; static const char *JSON = "{\"van\":{\"_id\":\"urn:sl:000000:::\",\"name\":\"TEST VAN\",\"vanPublic\":\"-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDIU1QyiN2QJbW2WUrgsvjr/OG+\ner79aVxCyXaZsdTamiOTCfw/UKm9Eg+I8IGPa9HD81wFPkN2RZYj6P4AiehaUqR4\natc+QoxmcTfv93gIVW2zkgZOn6bWk+XAw7I7qrfFM1UAEGQlDJZX+bQaxCXOBB36\n+Ba/HF3uCWqTS3OwowIDAQAB\n-----END PUBLIC KEY-----\n\",\"policies\":[{\"name\":\"challengeResponseMinLength\",\"value\":3},{\"name\":\"passwordMinLength\",\"value\":6},{\"name\":\"passphraseMinLength\",\"value\":20},{\"name\":\"customChallengeMinLength\",\"value\":6},{\"name\":\"minNumberChallengesIncludingPassword\",\"value\":4},{\"name\":\"customChallengeRequired\",\"value\":true},{\"name\":\"passwordDigitRequired\",\"value\":true},{\"name\":\"passwordAlphaRequired\",\"value\":true}]},\"cg\":\"-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDQ+S2gq98BLf43PvjF6KGnJRJA\nrhGK0YHjvYR5X53WdGG5jnzWo5Lq2JlbKNB4LxQVnPNot7wsPl1+FLAxKtGNY6Ep\nwaVasmK2aS8GX/j0BPHTXbwdVirE4EIiIPFMSv+V73phJdc4rKld66JC7EHpGI/u\ntm3qERRXtu5x6g9Q3wIDAQAB\n-----END PUBLIC KEY-----\n\",\"devices\":[{\"publicKey\":\"-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDXYZysxVvPCOLSMrOKbmefyZ7u\nAhEYCRb/jbBTDS7wsgfmWsBuc2i5oTu19sylqrk5SCFJtSiAQXM3k2N9l7+RJcoE\nsUkCgUK5LVmN+0xgqQAEZfttBIflwhqQEUROMxRBfKso5n2inAriMB/QoRntqAv4\nVe1mkrzlBa4GifU5cwIDAQAB\n-----END PUBLIC KEY-----\n\",\"enabled\":true,\"privateKey\":\"-----BEGIN RSA PRIVATE KEY-----\nMIICXQIBAAKBgQDXYZysxVvPCOLSMrOKbmefyZ7uAhEYCRb/jbBTDS7wsgfmWsBu\nc2i5oTu19sylqrk5SCFJtSiAQXM3k2N9l7+RJcoEsUkCgUK5LVmN+0xgqQAEZftt\nBIflwhqQEUROMxRBfKso5n2inAriMB/QoRntqAv4Ve1mkrzlBa4GifU5cwIDAQAB\nAoGAA4GwVlPEQeOoJbnzmF5hy4Ux1DguZRDI0hJRe5isWfjcDhEOLv4sB1GrsjO5\ncz0LVPZqrFOJvETUhmQc64+L695mhhEjLzx60DWr7Cj/ieerT+POgDXX3oOAgy/t\nNNSvn5dem/9UX7/bLSGTFPsazfiG9amfMRmYnuS3OADTf7ECQQDxQT3a3IhRYLcG\nskKC5su2OoU9klhHOYWD3WZh+O16Zfw5Yt5mP3m7RJz/L4hgOl1FUDQSom+ZiC0G\nay/TjjcpAkEA5IuLLXTI9odkKfsRqtpy1D+5bl/1tOPDe6dIxQh/N7tmX8kK73qa\nEUHVr5Fg68BbCvAGV7itXgqdSOQiwgnLOwJAQwFVxqWdjsyHyOpVormrNo+GVhWB\nQzbsqDUjrG5QtsAAj4ewMUHL84EZAZ8YB3HuWcPu0oYe7MtvherbO6yyEQJBANNB\nVeYvtG+FWQYhKQSYJlqhiONI2lNZ0eGkEPToVMgMdqYFrREOcAmRpFdEd6WTydRD\naGl/sOljwF2XW7Wm3e8CQQDCN21k+m2lwY55NPhxVCBgdl7ZCCK4RauQXyO/7a9X\nreGjb5dFQTb88P8kAwSuycc5DfHNFgU2Uv7nnSRayfLJ\n-----END RSA PRIVATE KEY-----\n\",\"_id\":\"urn:sl:000000:00000004:D1EA:\",\"description\":\"\",\"name\":\"JMeter\",\"type\":\"SNT_PEER\",\"metaType\":\"default\",\"info\":{}}],\"pmo\":{\"publicKey\":\"-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDXYZysxVvPCOLSMrOKbmefyZ7u\nAhEYCRb/jbBTDS7wsgfmWsBuc2i5oTu19sylqrk5SCFJtSiAQXM3k2N9l7+RJcoE\nsUkCgUK5LVmN+0xgqQAEZfttBIflwhqQEUROMxRBfKso5n2inAriMB/QoRntqAv4\nVe1mkrzlBa4GifU5cwIDAQAB\n-----END PUBLIC KEY-----\n\",\"enabled\":true,\"cr\":[\"password::e38ad214943daad1d64c102faec29de4afe9da3d\",\"favchar::boulder\",\"favsay::bob\",\"custom:WHO LET THE DOGS OUT:WHO WHO\"],\"phone\":{\"primary\":\"\"},\"privateKey\":\"-----BEGIN RSA PRIVATE KEY-----\nMIICXQIBAAKBgQDXYZysxVvPCOLSMrOKbmefyZ7uAhEYCRb/jbBTDS7wsgfmWsBu\nc2i5oTu19sylqrk5SCFJtSiAQXM3k2N9l7+RJcoEsUkCgUK5LVmN+0xgqQAEZftt\nBIflwhqQEUROMxRBfKso5n2inAriMB/QoRntqAv4Ve1mkrzlBa4GifU5cwIDAQAB\nAoGAA4GwVlPEQeOoJbnzmF5hy4Ux1DguZRDI0hJRe5isWfjcDhEOLv4sB1GrsjO5\ncz0LVPZqrFOJvETUhmQc64+L695mhhEjLzx60DWr7Cj/ieerT+POgDXX3oOAgy/t\nNNSvn5dem/9UX7/bLSGTFPsazfiG9amfMRmYnuS3OADTf7ECQQDxQT3a3IhRYLcG\nskKC5su2OoU9klhHOYWD3WZh+O16Zfw5Yt5mP3m7RJz/L4hgOl1FUDQSom+ZiC0G\nay/TjjcpAkEA5IuLLXTI9odkKfsRqtpy1D+5bl/1tOPDe6dIxQh/N7tmX8kK73qa\nEUHVr5Fg68BbCvAGV7itXgqdSOQiwgnLOwJAQwFVxqWdjsyHyOpVormrNo+GVhWB\nQzbsqDUjrG5QtsAAj4ewMUHL84EZAZ8YB3HuWcPu0oYe7MtvherbO6yyEQJBANNB\nVeYvtG+FWQYhKQSYJlqhiONI2lNZ0eGkEPToVMgMdqYFrREOcAmRpFdEd6WTydRD\naGl/sOljwF2XW7Wm3e8CQQDCN21k+m2lwY55NPhxVCBgdl7ZCCK4RauQXyO/7a9X\nreGjb5dFQTb88P8kAwSuycc5DfHNFgU2Uv7nnSRayfLJ\n-----END RSA PRIVATE KEY-----\n\",\"_id\":\"urn:sl:000000:00000004::\",\"email\":\"jmeter@sequencelogic.net\",\"user\":\"jmeter\",\"fullname\":\"JMeter User\"}}"; static const char* RSA_private = "-----BEGIN RSA PRIVATE KEY-----\n\ MIIEpAIBAAKCAQEAzBTVhKef/68WvTns382xPw9i4RvZX3y8DH70YEvP3WgqC39p\n\ D3PLhe7RiRvEGHWm0cdVpvUg1rdUE1pVPNSZjan/I8YUuX9eqLDZf6iqCYm5KwLj\n\ reaz2T0QBaKCs98I2W5qULbzKhqtw3Yp9gOyZTlEbgkg0ZVunzLr42se0LsvmbWl\n\ Er3UksyzAJfsE6q0eKjyvpaoAFT1nTEr84IrZqUdn2YKV80WX9zj7maQqWviDKow\n\ xK8NKO50oCouTXNDpxwYKqoT9/8rcpOUSXawBDbcNZWHKvG8e8icxLQqpDT3Egdn\n\ z+VtQXRwk1Yuyt8eE9jgh5dmBoo7PspQt6EVvwIDAQABAoIBAHkr5Zrd7CHj05yG\n\ yB4aAyNt/0epQWdwqDbDKlYCrWjIcC5jd/20wyLCqaa+1a+wK1xi/ngjE1xpfYIA\n\ IJv9ny59wP98nNGGzq1aU8l4W31OSKNBE+4tDJvvpZOy6efihV6UMIu8FKTrMkDb\n\ 6A4qI8H2PqsWwGWwU/4yPdzJvYIwkjUDayCfOYjLjYJgiDK4ZrSkH6nwlTQ0ajaP\n\ gyLZrJu8o7KOa6bmyjT4iXUsvXsh5Q37rzLQd7sUOXCRvLp6QdPWvAy9zGDDew3q\n\ 3ecA+87h1WDWVhnEUZl+pNKtBHRo9THUTIh3lG0eZNVPj+RLXLN8nARDauZb6cSy\n\ h35jQAECgYEA8exV7ssnhVlN8VZF/NN0FI+RX7fSTXcvVjtzQXsq8dm4vNj6VYde\n\ 5gsgYSar3L0hdROFBP6E6OmzrLnXHfuVp0h4Y1CcYjbaj6uqUfm4e3k8xUKqwez/\n\ 8cs7D+xhlpncf5z0ZaMJFS8bgRRUOReB2+qAcJowxJ/J+bwxHAC9y2sCgYEA1/TP\n\ gCXVt2Hh+mpwLkg1nYJItDJzGJwH8uN3pD53i03qRsfGdHaf+JHFXQF6XpupyvlZ\n\ 0jR7i7/+OY1oqRTfUcApfyUKlOv8bOz6O+DNjh9p2eDx/Oztt4vQgjRqbRVqTFVu\n\ zwni5ApvIhpz0f22GBBWOt51DpmnTsTwSJplZ/0CgYADW/K9hBiiY2EPrtD997mu\n\ 52dvWtASv0rq+ZxaFmm8Pfewt5qSQXTx4MmsT6snP4ENbR31ucsCqOwTw+jWw72K\n\ Oxlg16e0PWq/f/S3eq4zGLXdT1Wrp6zOILJLQE8CllRXeUhzeNYRczwAiNW6jTcC\n\ ZLkv1xRCRq25SAGuj9wSzQKBgQCIjWQnw8S/kEUz8tm8aix8zETsrHnatc7Q5sRg\n\ Np+glkPtPaVfPyMoKgSCKs0VxZg3oDQLluQIGf7GpYPoZipPpxKWMvXd9NpIhhA0\n\ jJFtrK9h9bsOE0K9LMtLiZlCIKh2XA8VG0s8ptxe1BsoTSU3Uh00XDXoZYBFboIB\n\ Zp94gQKBgQCR5mcD8JIWOts0ZxrTwho2kg898WRINusaIIhrCFPoWymvLpoeRzkG\n\ KvOt9T3KXVzT6lqmBRfZO50Dd9N7+oxYEA7OJb1JJ4WUmOn5llJOgsVmaT4iVdj6\n\ FqFAwmMOl6/hbaIXBUZ4q/QbzZLxmezOu0XwUzQ4ptvdgaab2qSkmQ==\n\ -----END RSA PRIVATE KEY-----"; static const char* BOT_private = "-----BEGIN RSA PRIVATE KEY-----\n\ MIIEpAIBAAKCAQEAx6wmsx+MqvvLqCpnNFT76ebpP9CHnwiv4uvGXVGEv9LJXPOw\n\ OUV8Iwrvgst8ZQWJGO2lTIwLhTQ6piyq1H0NOWtsFKtQHZm1MrjDs51w8OOwgWUb\n\ TKslQ9cSgHZ+MsNB/Tk8La2C1mDmWt0Ae0CEMY8/q/xdpWsxd+2XodwRVFKfwF3f\n\ VnjzA5gVE18c/81dJ1UF5QuPkgp8o3+sXpRLElajyFjfbTg/74phOOiyPcEptbl8\n\ /Mz6QilVCkHEW2f3CcIx7ttAoQIDMqiOVgECOMdWSW1roKCSNsQHOUYFZ7EkpZiB\n\ Py9qGMI2woXsc8UPgXppl/Buz21zd87TQmlqlQIDAQABAoIBAFKnf6mcgMVyz/4/\n\ 91LhbxqHHLzu3IVHuk9sHEQa76HcZsCUm7lJezaiWz1AcLD81qC8FzYVrtsoILMT\n\ QHAPh/7h6e6wb8yhCTIC6/gZT1xYVINr0B4vppBrolwNMPZgf5uMKs4ZylRl7lVk\n\ sMNUlKRTUR8nq7hDJEopzyAQkhfeFGyvid8i9lsHjHZhcU+b0jdDUoEs9/pLQ94+\n\ Nt7Kh/Xn0cyiUmycuVZyhjFqCiK/egohDbiKDIV9rfMupQAQCprJfo5T5Iy/zncW\n\ XS8/Oz/9bE8yRNPOhjj/32KSrTNPgdmDE7aT8Ntloh5FXSISSzYHqpn+DWRVD3iY\n\ +EjIMKECgYEA8aO5PN5/omL3CroKa9LV8Oa0fRbhKKJMaTzgIAIoHLBWgoVkPUER\n\ ALStMvCeYy3By/gSHakrf4vTjDn+cnC1Wfw8riYf0N0oQD6lZHSbBslToAiIsMD7\n\ lfWhSW8MEfnKKjWru0/sGmaBcBuBtIb9WSJ/MTmFr8U3zMFsBsMPyp0CgYEA04nx\n\ +sI2KmaTxxPZ/liUjMnRWd+ZgTlMAdDp/a7CwzDPhp0U27TxITYNf5/sg+rxx570\n\ 0XuMhUHNmoeAs7fmtJ37fqvX117guTwUaSe5UdoO3MHwr4fE+Xc70daMuqaPpwAa\n\ srAIbJGITIvdCOPK6whRkRL8Vjd9ljO04LGVwlkCgYEAwYbm7KEmh9/LC4REpGaP\n\ ggjDtQuF+Q1DNWXT+s6/YXq5Tn+W8JgUDgSmUo3zzGrxM3LSz36Vn+lU3JH1/6HV\n\ HOSvlKpkANufSRTjUbkyEBVeLGWpVCa7WDcJnc6aVCtChtvFVpeD+QDv2eGt1+/l\n\ KGZAiCQRtdy1+/9NjXzcQOECgYEAuK8JnVTrt08BG+CABOhPIS+d4CowObrNWhSM\n\ BVgLYCCAPlVr/XlWwBkR5ee4tV9soUxtD2sfPsQ5ff1pZv5apDv9cxUSh0ylQ/Np\n\ Gnl8+TI4oZGM0aLmXKo1hrka+mYqqrGTnYfEgwz4A2RkoLtH0LTdiZwaxCcENRuF\n\ glpollkCgYBuCsAUSV1irzydIktSAT1xEDpgqoeQ1iQR4jD8CR57NI94p1IT7kmZ\n\ bKkNftJL/DdmvPzuYTQgenR/5GKEw1Ca2O9Caa9YU+KDXI4jgHMBfjxcY4Sc8D2W\n\ RdC/OfVdFmIXPnB/Twyo7PR2oX1tA+XtL3WLIkkmK1JdB/s2XieMGA==\n\ -----END RSA PRIVATE KEY-----"; static const char* BOT_public = "-----BEGIN PUBLIC KEY-----\n\ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx6wmsx+MqvvLqCpnNFT7\n\ 6ebpP9CHnwiv4uvGXVGEv9LJXPOwOUV8Iwrvgst8ZQWJGO2lTIwLhTQ6piyq1H0N\n\ OWtsFKtQHZm1MrjDs51w8OOwgWUbTKslQ9cSgHZ+MsNB/Tk8La2C1mDmWt0Ae0CE\n\ MY8/q/xdpWsxd+2XodwRVFKfwF3fVnjzA5gVE18c/81dJ1UF5QuPkgp8o3+sXpRL\n\ ElajyFjfbTg/74phOOiyPcEptbl8/Mz6QilVCkHEW2f3CcIx7ttAoQIDMqiOVgEC\n\ OMdWSW1roKCSNsQHOUYFZ7EkpZiBPy9qGMI2woXsc8UPgXppl/Buz21zd87TQmlq\n\ lQIDAQAB\n\ -----END PUBLIC KEY-----"; // JSON encoded version of BOT public key as in Collaborators static const char* BOT_json = "{\"publicKey\":\"\ -----BEGIN PUBLIC KEY-----\\n\ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx6wmsx+MqvvLqCpnNFT7\\n\ 6ebpP9CHnwiv4uvGXVGEv9LJXPOwOUV8Iwrvgst8ZQWJGO2lTIwLhTQ6piyq1H0N\\n\ OWtsFKtQHZm1MrjDs51w8OOwgWUbTKslQ9cSgHZ+MsNB\\/Tk8La2C1mDmWt0Ae0CE\\n\ MY8\\/q\\/xdpWsxd+2XodwRVFKfwF3fVnjzA5gVE18c\\/81dJ1UF5QuPkgp8o3+sXpRL\\n\ ElajyFjfbTg\\/74phOOiyPcEptbl8\\/Mz6QilVCkHEW2f3CcIx7ttAoQIDMqiOVgEC\\n\ OMdWSW1roKCSNsQHOUYFZ7EkpZiBPy9qGMI2woXsc8UPgXppl\\/Buz21zd87TQmlq\\n\ lQIDAQAB\\n\ -----END PUBLIC KEY-----\"}"; // JSON encoded version of BOT public key static const char* BOT_jsonkey = "\"\ -----BEGIN PUBLIC KEY-----\\n\ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx6wmsx+MqvvLqCpnNFT7\\n\ 6ebpP9CHnwiv4uvGXVGEv9LJXPOwOUV8Iwrvgst8ZQWJGO2lTIwLhTQ6piyq1H0N\\n\ OWtsFKtQHZm1MrjDs51w8OOwgWUbTKslQ9cSgHZ+MsNB\\/Tk8La2C1mDmWt0Ae0CE\\n\ MY8\\/q\\/xdpWsxd+2XodwRVFKfwF3fVnjzA5gVE18c\\/81dJ1UF5QuPkgp8o3+sXpRL\\n\ ElajyFjfbTg\\/74phOOiyPcEptbl8\\/Mz6QilVCkHEW2f3CcIx7ttAoQIDMqiOVgEC\\n\ OMdWSW1roKCSNsQHOUYFZ7EkpZiBPy9qGMI2woXsc8UPgXppl\\/Buz21zd87TQmlq\\n\ lQIDAQAB\\n\ -----END PUBLIC KEY-----\""; static const char* BOT_tgi_encrypted = "ZZKY8mDLpOfL1KEr+I+Jc0327p1AoSbB3189wQpzBvzLWNsdIySaRRKJQnzov\ 7iP784VkF8awVcARhZ5Nklwv0m3pps1eUFEG8ivMPVSKyNmTz/CmcAAWZ7TOm/8lApHJsWbHSX76j8zYygpqrL6q4oV+vVxqFTbl9\ gL+YD4cMb6BE3T0jAi19fMyEWVLX62l/VZsdZscGIPonH/hsvz8YkJry3qAOiixmAo6Pe9UsmhJxv6qFy7u+0bB8NF+iCf0iBwDp5\ PO32n1nhq80E80p2f8H5ag8mM1OJ5iDzwUxKpkRr7Gpct2lqmidQ2o1bWu0Esgd1hof/gKXEyPxyntw=="; //static const unsigned char BOTtgi[32] = {0, 0, 0, 0, 0, 0, 0, 112, 0, 0, 0, 0, 0, 0, 0, 112, 30, 0, 0, 0, 0, 0, 0, 0, -64, 76, 100, -61, -46, 127, 0, 0}; static const unsigned char BOTtgi[32] = {0, 0, 0, 0, 0, 0, 0, 112, 0, 0, 0, 0, 0, 0, 0, 112, 30, 0, 0, 0, 0, 0, 0, 0, 192, 76, 100, 195, 210, 127, 0, 0}; using namespace std; using namespace sequencelogic; int testfailed (const char* inf, const char* msg) { printf ("FAILED: %s: %s\n", inf, msg); return 1; } int testfailed (const std::string& inf, const std::string& msg) { cout << "FAILED: " << inf << ": " << msg << endl; //printf ("FAILED: %s : %s\n", inf.c_str(), msg.c_str()); return 1; } char* fileload (const char* filename) { ifstream file (filename, ios::in | ios::binary | ios::ate); char* buff = nullptr; if (file.is_open()) { size_t bytes = (size_t)file.tellg(); file.seekg (0, ios::beg); buff = new char[bytes + 1]; file.read (buff, bytes); file.close(); buff[bytes] = '\0'; } return buff; } void filewrite (const char* filename, const char* bytes) { ofstream file (filename, ios::out | ios::binary | ios::trunc); if (file.is_open()) { file.write (bytes, strlen(bytes) + 1); file.close(); } } void filedump (const char* filename) { ifstream file (filename, ios::in | ios::binary | ios::ate); if (file.is_open()) { size_t bytes = (size_t)file.tellg(); file.seekg (0, ios::beg); char* big = new char[bytes + 1]; if (big) { file.read (big, bytes); file.close(); big[bytes] = '\0'; printf ("%s\n", big); delete[] big; } } } bool filecompare (const char* f1, const char* f2) { std::string f1md5 = sequencelogic::DigestFile ("md5", f1); std::string f2md5 = sequencelogic::DigestFile ("md5", f2); return f1md5 == f2md5; } int locktestfailed (const char* inf, const char* msg) { printf ("FAILED: %s: %s\n", inf, msg); filedump ("test/.ctest.ionu.lk"); return 1; } // Parse an urn, if valid get the urn back and compare bool CheckURN (const char* urn) { bool rc = false; EyeURN* u = new EyeURN (urn); if (u->IsValid()) { char* n = u->GetURN(); if (n && strcmp (n, urn) == 0) rc = true; else { IONUDEBUG ("%s, %s", urn, n); } delete[] n; } delete u; return rc; } int TestLogging() { printf ("\nLogging tests\n-------------------------------\n"); IONUDEBUG ("%s:%d logging test", __FILE__, __LINE__); int rc = 0; Keyring ring ("testring", "Test Key Ring"); ring.GenerateECKey ("MyAudit", "deterministic", challenges); char* pk = ring.GetPubKey ("MyAudit"); Key* pubkey = new Key ("AuditPublic", "My auditing public key", (int)strlen(pk), (const unsigned char*)pk, Key::EC_PUBLIC); ring.AddKey (pubkey); Key RSA ("Auditor", "RSA auditing key", (int)strlen(RSA_private), (const unsigned char*)RSA_private, Key::RSA); delete[] pk; remove ("test/mylog.log"); IONUCONFIGFILELOG ("audit", "urn:sl:000000:17C38E5A:C60D:79916D07C42C - Nexus-7", EyeLog::IONU_WARN, "test/mylog.log", EyeLog::IONU_FILE, "%l: %m"); IONUBEGINAUDIT (*(ring.GetKey ("MyAudit")), "test"); IONUAUDIT (EyeLog::ACCOUNT_CREATE, "madman, madman@sequencelogic.net, 303-217-8477"); IONUAUDIT (EyeLog::DEVICE_PROVISION, "Nexus-7 4.4.1"); IONUAUDIT (EyeLog::ACCOUNT_LOGIN, "Failed: invalid password"); IONUAUDIT (EyeLog::ACCOUNT_LOGIN, "Succeeded"); IONUCLOSELOG(); EyeLog::GetInstance()->ReviewAudit (*(ring.GetKey ("MyAudit")), "test/audit.ioa"); // Test the basics IONUCONFIGLOG ("test", "urn:sl:000000:17C38E5A:C60D:79916D07C42C - Nexus-7", EyeLog::IONU_WARN, EyeLog::IONU_CONSOLE, "%l: %m"); IONULOG (EyeLog::IONU_INFO, "%s", "Simple log message"); IONUFATAL ("Fatal message"); IONUERROR ("Error message"); IONUWARN ("Warning message"); IONUINFO ("not ***Info message"); IONUDEBUG ("not ***Debug message"); IONUTRACE ("not ***Trace message"); EyeLog::GetInstance()->SetLogLevel (EyeLog::IONU_TRACE); IONUINFO ("Info message"); IONUDEBUG ("Debug message"); IONUTRACE ("Trace message"); IONUCONFIGFILELOG ("ftest", "urn:sl:000000:17C38E5A:C60D:79916D07C42C - Nexus-7", EyeLog::IONU_WARN, "test/mylog.log", EyeLog::IONU_FILE, "%l: %m"); IONUERROR ("Message only in the file"); IONUCONFIGFILELOG ("ftest", "urn:sl:000000:17C38E5A:C60D:79916D07C42C - Nexus-7", EyeLog::IONU_WARN, "test/mylog.log", EyeLog::IONU_CONSOLE, "%l: %m"); IONUERROR ("Message in the file and to the console"); IONUCLOSELOG("test/mylog.log"); // Close the log file, but keep messages to the console printf ("File contents -------\n"); fstream lfile ("test/mylog.log"); if (lfile.is_open()) { std::string line; while (std::getline(lfile, line)) cout << line << endl; } printf ("-------\n"); lfile.close(); #ifndef WIN32 // VS 2012 does not support variadic templates so don't crash with these tests IONUWARN ("Not enough args %s %d %f", "missing two"); IONUWARN ("Too many args %d", "have 3, need one", 7, 33.33); IONUWARN ("Wrong arg types, but that's ok (%d %f %s)", "int float string", 13, 99.99); IONUWARN ("%% at the end of just a string %"); IONUWARN ("%% at the end with an argument %", 7); IONUWARN (cgurl); IONUWARN ("null pointer %s", NULL); // Test various custom formats IONUCONFIGLOG ("IM", "dev", EyeLog::IONU_WARN, EyeLog::IONU_CONSOLE, "[%L]|%c|%t|%m"); IONUWARN ("Format [%%L]|%%c|%%t|%%m"); IONUCONFIGLOG ("IM", "dev", EyeLog::IONU_WARN, EyeLog::IONU_CONSOLE, "%l:%c:%m"); IONUWARN ("Format %%l:%%c:%%m"); IONUCONFIGLOG ("IM", "dev", EyeLog::IONU_WARN, EyeLog::IONU_CONSOLE, "%l - %m"); IONUWARN ("Format %%l - %%m"); IONUCONFIGLOG ("smo", "dev", EyeLog::IONU_WARN, EyeLog::IONU_CONSOLE, "%l - %m <%c>"); IONUWARN ("Format %%l - %%m <%%c>"); IONUCONFIGLOG ("smo", "dev", EyeLog::IONU_INFO, EyeLog::IONU_CONSOLE, "%ems %l - %m"); IONUWARN ("Format %%eMs %%l- %%m"); #endif // Test file based logging IONUCONFIGFILELOG ("im", "urn:sl:000000:17C38E5A:C60D:79916D07C42C - TestPad", EyeLog::IONU_WARN, "test/mylog.log", EyeLog::IONU_FILE, "%l: %m"); EyeLog::GetInstance()->SetMaxLogFile (300); IONUWARN ("This is a custom warning message with %d options", 273); IONUWARN ("This is a custom warning message with %d options", 274); IONUWARN ("This is a custom warning message with %d options", 275); IONUWARN ("This is a custom warning message with %d options", 276); IONUWARN ("This is a custom warning message with %d options", 277); IONUWARN ("This is a custom warning message with %d options", 278); IONUWARN ("This is a custom warning message with %d options", 279); IONUWARN ("This is a custom warning message with %d options", 280); IONUWARN ("This is a custom warning message with %d options", 281); IONUWARN ("This is a custom warning message with %d options", 282); IONUWARN ("This is a custom warning message with %d options", 283); IONUWARN ("This is a custom warning message with %d options", 284); IONUWARN ("This is a custom warning message with %d options", 285); IONUCLOSELOG ("test/mylog.log"); EyeLog::GetInstance()->SetMaxLogFile (IONU_MAX_LOG_FILE_SIZE); EyeLog::GetInstance()->ConfigLogger ("IM", "urn:sl:000000:17C38E5A:C60D:79916D07C42C - TestPad", EyeLog::IONU_AUDIT, EyeLog::IONU_CONSOLE); EyeLog::GetInstance()->BeginAudit (RSA, "test"); IONUAUDIT (EyeLog::ACCOUNT_CREATE, "madman, madman@sequencelogic.net, 303-217-8477"); IONUAUDIT (EyeLog::DEVICE_PROVISION, "Nexus-7 4.3.1"); IONUAUDIT (EyeLog::ACCOUNT_LOGIN, "Failed: invalid password"); IONUAUDIT (EyeLog::ACCOUNT_LOGIN, "ip:192.168.8.101"); IONUAUDIT (EyeLog::ACCOUNT_CHANGE, "Added Avatar"); IONUAUDIT (EyeLog::ACCOUNT_CHANGE, "Added contect: "); IONUAUDIT (EyeLog::DOCUMENT_SEND, "Message To: "); IONUAUDIT (EyeLog::DOCUMENT_RECEIVE, "Message From: "); IONUAUDIT (EyeLog::ACCOUNT_LOGOUT, "time limit expired"); IONUWARN ("This warning should not appear"); IONUCONFIGLOG ("IM1", "dev", EyeLog::IONU_WARN, EyeLog::IONU_CONSOLE); IONUWARN ("This warning should appear"); IONUCLOSELOG(); printf ("--Reviewing IM.ioa\n"); if (!EyeLog::GetInstance()->ReviewAudit (RSA, "test/IM.ioa")) rc += testfailed ("EyeLog::ReviewAudit (RSA, test/IM.ioa)", ""); printf ("--Reviewing badaudit.ioa\n"); if (EyeLog::GetInstance()->ReviewAudit (RSA, "test/badaudit.ioa")) rc += testfailed ("EyeLog::ReviewAudit (RSA, test/badaudit.ioa", ""); printf ("--Reviewing badauditk.ioa\n"); if (EyeLog::GetInstance()->ReviewAudit (RSA, "test/badauditk.ioa")) rc += testfailed ("EyeLog::ReviewAudit (RSA, test/badauditk.ioa", ""); //printf ("--Audit consolidation tests\n"); //if (!EyeLog::GetInstance()->ReviewAudit (RSA, "test/first.ioa")) // rc += testfailed ("EyeLog::ReviewAudit (RSA, test/first.ioa", "pre-consolidation"); //EyeLog::GetInstance()->ConsolidateAudit (RSA, "test/first.ioa", "test/second.ioa"); //if (!EyeLog::GetInstance()->ReviewAudit (RSA, "test/first.ioa")) // rc += testfailed ("EyeLog::ReviewAudit (RSA, test/first.ioa", "consolidated"); if (rc) printf ("%d log tests failed\n", rc); else printf ("logging and audit tests passed\n"); return rc; } int TestFileThreadLocking() { int rc = 0; #ifdef LOCK_STRATEGY_MEMORY printf ("\nMemory file locking tests\n-------------------------------\n"); if (sequencelogic::ThreadLockFile ("lockfile.ionu", "you", IONU_FILE_LOCK_WRITE) != IONU_FILE_LOCK_OK) rc += testfailed ("failed to get initial write lock", "you"); if (sequencelogic::ThreadLockFile ("lockfile.ionu", "me", IONU_FILE_LOCK_READ) == IONU_FILE_LOCK_OK) rc += testfailed ("got read lock when should not have", "me"); if (sequencelogic::ThreadLockFile ("lockfile.ionu", "you", IONU_FILE_LOCK_CLEAR) != IONU_FILE_LOCK_OK) rc += testfailed ("failed to release initial write lock", "you"); if (EyeFileThreadLocker::GetInstance()->GetNumLocks() > 0) rc += testfailed ("should be 0 locks", "you"); EyeFileThreadLock* locka = new EyeFileThreadLock (IONU_FILE_LOCK_READ, "lockfile.ionu", "me"); EyeFileThreadLock* lockb = new EyeFileThreadLock (IONU_FILE_LOCK_READ, "lockfile.ionu", "you"); if (!locka->acquired() || !lockb->acquired()) rc += testfailed ("2 read locks", "a and b"); else cout << "2 read locks acquired" << endl; if (locka->convertToWrite()) rc += testfailed ("convert read lock should have failed", "a"); else cout << sequencelogic::GetLastEyeLockMessage() << endl; delete lockb; if (!locka->convertToWrite()) rc += testfailed ("convert read lock", "a"); lockb = new EyeFileThreadLock (IONU_FILE_LOCK_READ, "lockfile.ionu", "you"); if (lockb->acquired()) rc += testfailed ("read lock should have failed", "b"); else cout << sequencelogic::GetLastEyeLockMessage() << endl; delete locka; delete lockb; EyeFileThreadWriteLock* wlock = new EyeFileThreadWriteLock ("lockfile.ionu", "wlok"); if (!wlock->acquired()) rc += testfailed ("failed to get write lock", "wlock"); EyeFileThreadReadLock* rlock = new EyeFileThreadReadLock ("lockfile.ionu", "rlok"); if (rlock->acquired()) rc += testfailed ("read lock should have failed", "rlock"); else cout << sequencelogic::GetLastEyeLockMessage() << endl; delete rlock; delete wlock; EyeFileThreadReadLock readlock ("lockfile.ionu", "me"); if (!readlock.acquired()) rc += testfailed ("read lock", "me"); if (sequencelogic::ThreadLockFile ("lockfile.ionu", "you", IONU_FILE_LOCK_WRITE) == IONU_FILE_LOCK_OK) rc += testfailed ("thread lock write", "you"); if (!readlock.convertToWrite()) rc += testfailed ("convert write lock", "me"); else cout << "converted to write" << endl; if (!readlock.convertToRead()) rc += testfailed ("convert read lock", "me"); else cout << "converted to read" << endl; if (!readlock.release()) rc += testfailed ("release read lock", "me"); if (readlock.release()) rc += testfailed ("no lock to release", "me"); if (!readlock.acquire(IONU_FILE_LOCK_READ)) rc += testfailed ("reacquire read lock", "me"); else cout << "released and re-acquired" << endl; IONU_FILE_LOCK_STATUS st; st = sequencelogic::ThreadLockFile ("cantlocklock.lk", "me", IONU_FILE_LOCK_READ); // My read lock if (st == IONU_FILE_LOCK_OK) rc += locktestfailed ("ThreadLockFile() read lock on", "cantlocklock.lk"); st = sequencelogic::ThreadLockFile ("thisfiledoesnotexistyet", "me", IONU_FILE_LOCK_READ); // My read lock if (st != IONU_FILE_LOCK_OK) rc += locktestfailed ("ThreadLockFile() read lock - me", "thisfiledoesnotexistyet"); st = sequencelogic::ThreadLockFile ("thisfiledoesnotexistyet", "me", IONU_FILE_LOCK_CLEAR); // Clear my lock if (st != IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() read lock - you", "thisfiledoesnotexistyet"); else printf ("Lock and clear of non-existant file passed\n"); if (rc) printf ("%d lock tests failed\n", rc); else printf ("lock tests passed\n"); #endif return rc; } int TestProcessLocking() { int rc = 0; #ifdef LOCK_STRATEGY_MASTER //printf ("\nProcess file locking tests\n-------------------------------\n"); //EyeContainer* IOnU = new EyeContainer("test/lockfile.ionu", TGIkey, URN, TopicPerms); //IOnU->AddTextMessage (".imchat", "A long and verbose yo there to you from me type chat message to test various stuff with"); //IOnU->Finalize(); //delete IOnU; EyeFileProcessLock* locka = new EyeFileProcessLock (IONU_FILE_LOCK_READ, "test/lockfile.ionu", "a"); if (!locka->acquired()) rc += testfailed ("read lock", "a"); else cout << "read lock a acquired" << endl; EyeFileProcessLock* lockb = new EyeFileProcessLock (IONU_FILE_LOCK_READ, "test/lockfile.ionu", "b"); if (!locka->acquired() || !lockb->acquired()) rc += testfailed ("2 read locks", "a and b"); else cout << "2 read locks acquired" << endl; //cout << EyeContainer::GetMetaDataClassic ("test/lockfile.ionu") << endl; if (locka->convertToWrite()) rc += testfailed ("convert read lock should have failed", "a"); else cout << sequencelogic::GetLastEyeLockMessage() << endl; delete lockb; if (!locka->convertToWrite()) { rc += testfailed ("convert read lock", "a"); cout << sequencelogic::GetLastEyeLockMessage() << endl; } lockb = new EyeFileProcessLock (IONU_FILE_LOCK_READ, "test/lockfile.ionu", "b"); if (lockb->acquired()) rc += testfailed ("read lock should have failed", "b"); else cout << sequencelogic::GetLastEyeLockMessage() << endl; delete locka; delete lockb; EyeFileProcessWriteLock* wlock = new EyeFileProcessWriteLock ("test/lockfile.ionu", "w"); if (!wlock->acquired()) rc += testfailed ("failed to get write lock", "wlock"); else cout << "write lock a acquired" << endl; //IOnU = new EyeContainer("test/lockfile.ionu", TGIkey); //cout << IOnU->GetTextMessage (".imchat") << endl; //IOnU->AddTextMessage (".imchat", "Short chat"); //IOnU->Finalize(); //delete IOnU; //IOnU = new EyeContainer("test/lockfile.ionu", TGIkey); //cout << IOnU->GetTextMessage (".imchat") << endl; //delete IOnU; EyeFileProcessReadLock* rlock = new EyeFileProcessReadLock ("test/lockfile.ionu", "r"); if (rlock->acquired()) rc += testfailed ("read lock should have failed", "rlock"); else cout << sequencelogic::GetLastEyeLockMessage() << endl; delete rlock; delete wlock; cout << "deleted read and write locks" << endl; EyeFileProcessReadLock readlock ("test/lockfile.ionu", "r"); if (!readlock.acquired()) rc += testfailed ("read lock", "me"); if (!readlock.convertToWrite()) rc += testfailed ("convert write lock", "me"); else cout << "converted to write" << endl; if (!readlock.convertToRead()) rc += testfailed ("convert read lock", "me"); else cout << "converted to read" << endl; if (!readlock.release()) rc += testfailed ("release read lock", "me"); if (!readlock.acquire(IONU_FILE_LOCK_READ)) rc += testfailed ("reacquire read lock", "me"); else cout << "released and re-acquired" << endl; IONU_FILE_LOCK_STATUS st; st = sequencelogic::ProcessLockFile ("cantlocklock.lk", "me", IONU_FILE_LOCK_READ); // My read lock if (st == IONU_FILE_LOCK_OK) rc += locktestfailed ("ProcessLockFile() read lock on", "cantlocklock.lk"); st = sequencelogic::ProcessLockFile ("thisfiledoesnotexistyet", "me", IONU_FILE_LOCK_READ); // My read lock if (st != IONU_FILE_LOCK_OK) rc += locktestfailed ("ProcessLockFile() read lock - me", "thisfiledoesnotexistyet"); st = sequencelogic::ProcessLockFile ("thisfiledoesnotexistyet", "me", IONU_FILE_LOCK_CLEAR); // Clear my lock if (st != IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() read lock - you", "thisfiledoesnotexistyet"); else printf ("Lock and clear of non-existant file passed\n"); if (rc) printf ("%d lock tests failed\n", rc); else printf ("lock tests passed\n"); #endif return rc; } int TestRAIIRead() { int rc = 0; EyeFileReadLock readlock (cionu, "raii"); if (sequencelogic::LockFile (cionu, "me", IONU_FILE_LOCK_READ) != IONU_FILE_LOCK_OK) rc += testfailed ("EyeFileReadLock(RAII) read lock", "me"); if (sequencelogic::LockFile (cionu, "me", IONU_FILE_LOCK_CLEAR) != IONU_FILE_LOCK_OK) rc += testfailed ("EyeFileReadLock(RAII) clear lock", "me"); if (sequencelogic::LockFile (cionu, "me", IONU_FILE_LOCK_WRITE) == IONU_FILE_LOCK_OK) rc += testfailed ("EyeFileReadLock(RAII) read lock", "me"); return rc; } int TestRAIIWrite() { int rc = 0; EyeFileWriteLock readlock (cionu, "raii"); if (sequencelogic::LockFile (cionu, "me", IONU_FILE_LOCK_READ) == IONU_FILE_LOCK_OK) rc += testfailed ("EyeFileWriteLock(RAII) read lock", "me"); if (sequencelogic::LockFile (cionu, "me", IONU_FILE_LOCK_WRITE) == IONU_FILE_LOCK_OK) rc += testfailed ("EyeFileWriteLock(RAII) write lock", "me"); return rc; } int TestFileLocking() { printf ("\nFile locking tests\n-------------------------------\n"); int rc = 0; //ionu_eyefile_create_with_message ("test/remove_test.ionu", TGIkey, ".imchatty", "Yo!", 3, URN, PERMS); sequencelogic::EyeFileLock* ef = new EyeFileLock(IONU_FILE_LOCK_READ, "test/remove_test.ionu", "remove"); sequencelogic::RemoveFile ("test/remove_test.ionu"); delete ef; if (sequencelogic::CanReadFile ("test/.remove_test.ionu.lk")) rc += locktestfailed ("RemoveEntry() lock not deleted", "test/.remove_test.ionu.lk"); IONU_FILE_LOCK_STATUS st; st = sequencelogic::LockFile ("cantlocklock.lk", "me", IONU_FILE_LOCK_READ); // My read lock if (st == IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() read lock on", "cantlocklock.lk"); st = sequencelogic::LockFile ("thisfiledoesnotexistyet", "me", IONU_FILE_LOCK_READ); // My read lock if (st != IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() read lock - me", "thisfiledoesnotexistyet"); st = sequencelogic::LockFile ("thisfiledoesnotexistyet", "me", IONU_FILE_LOCK_CLEAR); // Clear my lock if (st != IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() read lock - you", "thisfiledoesnotexistyet"); else printf ("Lock and clear of non-existant file passed\n"); if (sequencelogic::CanReadFile ("test/.thisfiledoesnotexistyet.lk")) rc += locktestfailed ("LockFile() lockfile not deleted after clear", "test/.thisfiledoesnotexistyet.lk"); st = sequencelogic::LockFile (cionu, "me", IONU_FILE_LOCK_READ); // My read lock if (st != IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() read lock - me", cionu); st = sequencelogic::LockFile (cionu, "you", IONU_FILE_LOCK_WRITE); // Fails to get your write lock cout << sequencelogic::GetLastEyeLockMessage() << endl; if (st == IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() write lock - you", cionu); else printf ("Basic write lock test me and you passed\n"); st = sequencelogic::LockFile (cionu, "me", IONU_FILE_LOCK_CLEAR); // Clear my lock if (st != IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() read lock - you", cionu); else printf ("Clear lock passed\n"); if (sequencelogic::CanReadFile ("test/.ctest.ionu.lk")) rc += locktestfailed ("LockFile() lockfile not deleted after clear", "test/.ctest.ionu.lk"); else printf ("Lock file deleted\n"); st = sequencelogic::LockFile (cionu, "me", IONU_FILE_LOCK_CLEAR); // Clear lock on non-existant lock file if (st != IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() cleared read lock", cionu); else printf ("Double clear lock passed\n"); if (sequencelogic::CanReadFile ("test/.ctest.ionu.lk")) rc += locktestfailed ("LockFile() lockfile not deleted after clear", "test/.ctest.ionu.lk"); // Cleared lock, should get it now st = sequencelogic::LockFile (cionu, "you", IONU_FILE_LOCK_READ); // Your read lock if (st != IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() read lock - you", cionu); else printf ("Basic unlock test passed\n"); // Multiple read locks st = sequencelogic::LockFile (cionu, "me", IONU_FILE_LOCK_READ); // Now we both have read locks if (st != IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() 2nd read lock - me", cionu); else printf ("Multiple read lock test passed\n"); st = sequencelogic::LockFile (cionu, "them", IONU_FILE_LOCK_WRITE); // Their write lock fails if (st == IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() 3rd write lock - you", cionu); else printf ("Multiple read lock test passed\n"); st = sequencelogic::LockFile (cionu, "me", IONU_FILE_LOCK_CLEAR); // Clear my read if (st != IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() read lock - you", cionu); st = sequencelogic::LockFile (cionu, "you", IONU_FILE_LOCK_WRITE); // Add your lock to a write if (st != IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() changed to write lock - you", cionu); st = sequencelogic::LockFile (cionu, "me", IONU_FILE_LOCK_READ); // My read lock fails if (st == IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() read lock after you got write - me", cionu); else printf ("LockFile() read lock after you got write test passed\n"); st = sequencelogic::LockFile (cionu, "me", IONU_FILE_LOCK_WRITE); // My write lock fails cout << sequencelogic::GetLastEyeLockMessage() << endl; if (st == IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() write lock after you got write - me", cionu); else printf ("LockFile() write lock after you got write test passed\n"); st = sequencelogic::LockFile (cionu, "you", IONU_FILE_LOCK_CLEAR); // Clear your write lock if (st != IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() clear write lock - you", cionu); st = sequencelogic::LockFile (cionu, "me", IONU_FILE_LOCK_READ); // My read lock succeeds if (st == IONU_FILE_LOCK_OK) printf ("Removed your write test passed\n"); else rc += locktestfailed ("LockFile() read lock after you got write - me", cionu); st = sequencelogic::LockFile (cionu, "you", IONU_FILE_LOCK_CLEAR); // Clear your read lock if (st != IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() clear read lock - you", cionu); st = sequencelogic::LockFile (cionu, "me", IONU_FILE_LOCK_CLEAR); // Clear my read lock if (st != IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() clear read lock - me", cionu); // Try to lock a lockfile st = sequencelogic::LockFile ("test/.ctest.ionu.lk", "pad", IONU_FILE_LOCK_READ); if (st != IONU_FILE_LOCK_ERROR) rc += locktestfailed ("LockFile() lock lockfile - pad", "test/.ctest.ionu.lk"); EyeFileReadLock readlock (cionu, "me"); if (!readlock.acquired()) rc += testfailed ("read lock", "me"); if (sequencelogic::LockFile (cionu, "you", IONU_FILE_LOCK_WRITE) == IONU_FILE_LOCK_OK) rc += testfailed ("thread lock write", "you"); if (!readlock.convertToWrite()) rc += testfailed ("convert write lock", "me"); if (!readlock.convertToRead()) rc += testfailed ("convert read lock", "me"); if (!readlock.release()) rc += testfailed ("release read lock", "me"); if (!readlock.release()) rc += testfailed ("no lock to release", "me"); if (!readlock.acquire(IONU_FILE_LOCK_READ)) rc += testfailed ("reacquire read lock", "me"); if (!readlock.release()) rc += testfailed ("release after reacquire", "me"); if (sequencelogic::CanReadFile ("test/.ctest.ionu.lk")) rc += locktestfailed ("EyeFileReadLock() lockfile not deleted after clear", "test/.ctest.ionu.lk"); rc += TestRAIIRead(); if (sequencelogic::CanReadFile ("test/.ctest.ionu.lk")) rc += locktestfailed ("EyeFileReadLock() lockfile not deleted after RAII", "test/.ctest.ionu.lk"); else printf ("RAII read test passed\n"); rc += TestRAIIWrite(); if (sequencelogic::CanReadFile ("test/.ctest.ionu.lk")) rc += locktestfailed ("EyeFileWriteLock() lockfile not deleted after RAII", "test/.ctest.ionu.lk"); else printf ("RAII write test passed\n"); // Test a remote locked file std::string remote = "[{\"pid\":\"RSUS-8:7963\",\"id\":\"me\",\"type\":\"W\",\"time\":\""; EyeTime now; remote += now.GetISO8601Time(); remote += "\"}]"; filewrite ("test/.ctest.ionu.lk", remote.c_str()); filedump ("test/.ctest.ionu.lk"); st = sequencelogic::LockFile (cionu, "me", IONU_FILE_LOCK_WRITE); if (st == IONU_FILE_LOCK_OK) rc += locktestfailed ("LockFile() remote lock", cionu); else printf ("Lock check for remote system locked file passed\n"); sequencelogic::RemoveFile ("test/.ctest.ionu.lk"); // Add a stale lock for the next run sequencelogic::LockFile (cionu, "me", IONU_FILE_LOCK_READ); filedump ("test/.ctest.ionu.lk"); if (rc) printf ("%d lock tests failed\n", rc); else printf ("lock tests passed\n"); return rc; } int IONUCompressTests() { int rc = 0; unsigned char compressed[2048]; unsigned char uncompressed[4098]; const char* str = "Hello HTML

Hello World!

"; size_t len = strlen (str) + 1; size_t dest_len = 2048; sequencelogic::Compress (compressed, &dest_len, (unsigned char*)str, len); printf ("%d bytes in, %d bytes compressed\n", (int)len, (int)dest_len); sequencelogic::Uncompress (uncompressed, &len, compressed, dest_len); printf ("%d bytes out\n", (int)len); if (memcmp (str, uncompressed, len) != 0) rc += testfailed ("HTML compress", (char*)uncompressed); len = strlen (vanishMeta) + 1; dest_len = 2048; sequencelogic::Compress (compressed, &dest_len, (unsigned char*)vanishMeta, len); printf ("%d bytes in, %d bytes compressed\n", (int)len, (int)dest_len); sequencelogic::Uncompress (uncompressed, &len, compressed, dest_len); printf ("%d bytes out\n", (int)len); if (memcmp (vanishMeta, uncompressed, len) != 0) rc += testfailed ("vanishMeta compress", (char*)uncompressed); len = strlen (uploadedMeta) + 1; dest_len = 2048; sequencelogic::Compress (compressed, &dest_len, (unsigned char*)uploadedMeta, len); printf ("%d bytes in, %d bytes compressed\n", (int)len, (int)dest_len); sequencelogic::Uncompress (uncompressed, &len, compressed, dest_len); printf ("%d bytes out\n", (int)len); if (memcmp (uploadedMeta, uncompressed, len) != 0) rc += testfailed ("uploadedMeta compress", (char*)uncompressed); ifstream file ("test/system info dump.xml", ios::in | ios::binary | ios::ate); if (file.is_open()) { size_t bytes = (size_t)file.tellg(); file.seekg (0, ios::beg); char* big = new char[bytes]; char* b64 = new char[bytes]; unsigned char* data = new unsigned char[bytes]; if (big && data) { size_t rbytes = bytes; file.read (big, bytes); file.close(); sequencelogic::Compress (data, &bytes, (unsigned char*)big, bytes); sequencelogic::Base64Encode (data, bytes, b64); bytes = sequencelogic::Base64Decode (b64, data); sequencelogic::Uncompress ((unsigned char*)b64, &rbytes, data, bytes); if (memcmp (big, b64, rbytes) != 0) { rc += testfailed ("Big Xml compress", "test/system info dump.xml"); big[80] = '\0'; b64[80] = '\0'; printf ("%s\n%s\n", big, b64); } } delete[] big; delete[] b64; delete[] data; } return rc; } int TestDB() { printf ("\nDB tests\n-------------------------------\n"); int rc = 0; char* val = NULL; EyeEncryptedDB* test = new EyeEncryptedDB ("test/test.db", TestKey); std::map entries; entries["key1"] = "value1"; entries["key2"] = "value2"; entries["key3"] = "value3"; entries["key4"] = "Longervalueforkey4"; test->PutAll ("cache", entries, true); std::map dbentries = test->GetAll ("cache"); printf ("got all\n"); for (std::map::const_iterator itr = dbentries.begin(); itr != dbentries.end(); ++itr) { std::cout << itr->first << " " << itr->second << std::endl; } test->Put ("backup", "key2", "bvalue2"); // ms = sequencelogic::GetSystemTime(); // for (int i=0; i<10000; ++i) { // val = test->Get ("cache", "key1"); // delete[] val; // } // ms = sequencelogic::GetSystemTime() - ms; // printf ("Loaded 10,000 values in %ld ms\n", ms); val = test->Get ("cache", "key1"); if (val) { printf ("cache.key1.%s\n", val); delete[] val; } else rc += testfailed ("Get", "cache.key1"); val = test->Get ("cache", "key2"); if (val) { printf ("cache.key2.%s\n", val); delete[] val; } else rc += testfailed ("Get", "cache.key2"); val = test->Get ("cache", "key3"); if (val) { printf ("cache.key3.%s\n", val); delete[] val; } else rc += testfailed ("Get", "cache.key3"); val = test->Get ("cache", "key4"); if (val) { printf ("cache.key4.%s\n", val); delete[] val; } else rc += testfailed ("Get", "cache.key4"); val = test->Get ("backup", "key2"); if (val) { printf ("backup.key2.%s\n", val); delete[] val; } else rc += testfailed ("Get", "backup.key2"); val = test->Get ("cache", "keynot"); if (val) rc += testfailed ("Get", "cache.keynot"); delete test; test = new EyeEncryptedDB ("test/test.db", badkey); val = test->Get ("backup", "key2"); if (val) rc += testfailed ("Get() with bad key", "backup.key2"); else printf ("Bad DB key test passed\n"); delete test; test = new EyeEncryptedDB ("test/test.db", TestKey); //test->Dump("cache"); test->Put ("cache", "key2", "NewValue2"); test->ReKey (badkey); //test->Dump("cache"); delete test; test = new EyeEncryptedDB ("test/test.db", badkey); val = test->Get ("cache", "key2"); if (sequencelogic::StrCmp (val, "NewValue2") == 0) printf ("cache.key2.%s\n", val); else rc += testfailed ("Get() after ReKey", "cache.key2"); if (val) delete[] val; test->Remove ("cache", "key2"); //test->Dump("cache"); val = test->Get ("cache", "key2"); if (sequencelogic::StrCmp (val, "value2") == 0) rc += testfailed ("Remove key", "cache.key2"); if (val) delete[] val; test->Remove ("cache"); //test->Dump("cache"); val = test->Get ("cache", "key1"); if (sequencelogic::StrCmp (val, "value1") == 0) rc += testfailed ("Remove table", "cache"); if (val) delete[] val; test->ReKey (TestKey); delete test; #ifndef WIN32 test = new EyeEncryptedDB ("/test.db", badkey); if (test->Put ("cache", "key2", "NewValue2")) rc += testfailed ("UnCreated", "cache"); delete test; #endif if (rc == 0) printf ("C++ DB tests passed\n"); // Test the C bindings ionu_eyedb_put ("dbfile.db", TestKey, "collection", "key", "value"); ionu_eyedb_put ("dbfile.db", TestKey, "collection", "key2", "value2"); val = ionu_eyedb_get ("dbfile.db", TestKey, "collection", "key"); if (sequencelogic::StrCmp (val, "value") != 0) rc += testfailed ("ionu_eyedb_get", "collection:key"); if (val) free (val); ionu_eyedb_remove ("dbfile.db", TestKey, "collection", "key"); val = ionu_eyedb_get ("dbfile.db", TestKey, "collection", "key"); if (val) rc += testfailed ("ionu_eyedb_remove", "collection:key"); ionu_eyedb_remove ("dbfile.db", TestKey, "collection", NULL); val = ionu_eyedb_get ("dbfile.db", TestKey, "collection", "key2"); if (val) rc += testfailed ("ionu_eyedb_remove", "collection"); if (rc) printf ("%d db tests failed\n", rc); else printf ("DB tests passed\n"); return rc; } int TestDirectory() { printf ("\nDirectory tests\n-------------------------------\n"); int rc = 0; /* EyeDirectory* d = new EyeDirectory ("test", "*.ionu"); d->Dump(); d->Sort (EyeDirectory::ASCENDING_TIME); d->Dump(); d->Sort (EyeDirectory::DESCENDING_TIME); d->Dump(); d->Sort (EyeDirectory::ASCENDING_ALPHA); d->Dump(); d->Sort (EyeDirectory::DESCENDING_ALPHA); d->Dump(); size_t bytes = EyeDirectory::GetNumBytes ("test"); printf ("%ld bytes\n", (long int)bytes); std::string f = d->GetFileName(5); cout << "file 5: " << f << endl; delete d; d = new EyeDirectory ("test", "*.jk"); if (d->GetNumFiles() > 0) rc += testfailed ("EyeDirectory(*.jk)", d->GetFileName(0)); delete d; d = new EyeDirectory ("tst", "*.ionu"); if (d->GetNumFiles() > 0) rc += testfailed ("EyeDirectory(tst/*.ionu)", d->GetFileName(0)); delete d; d = new EyeDirectory ("test", "*.ion?"); delete d; size_t i = 0; size_t num = ionu_eyefile_list_directory_length ("garbage", "*.ionu"); char** list = ionu_eyefile_list_directory_sorted ("garbage", 0, num/2, "*.ionu", true); for (i = 0; iAddMember (new EyeJSONScalar ("id", "identifire", JSON_STRING)); jtest->AddMember (new EyeJSONScalar ("type", "rwlock", JSON_STRING)); jtest->GetJSONString(json); delete jtest; cout << json << std::endl; const char* utfjson = "\\u0123\\u4567\\u89AB\\uCDEF\\uabcd\\uef4A "; //const char* utfjson = "euro \\u20ac cent \\u00a2"; EyeJSONScalar* unicode = new EyeJSONScalar ("UTF-8", utfjson, JSON_STRING); printf ("%s\n", utfjson); sequencelogic::BinaryToHex ((unsigned char*)unicode->GetValue(), 16, cbuff); printf ("%s\n", cbuff); unicode->GetJSONString(json); cout << json << std::endl; if (sequencelogic::MemCmp (utfjson, json.c_str() + 9, 16) != 0) // Skip "UTF-8":" rc += testfailed ("JSON", "UTF currency"); delete unicode; jtest = new EyeJSONObject (NULL); if (jtest->GetNumMembers() > 0 || jtest->GetMember ("policies")) rc += testfailed ("JSON", "NULL"); delete jtest; jtest = new EyeJSONObject (""); if (jtest->GetNumMembers() > 0) rc += testfailed ("JSON", "empty"); delete jtest; jtest = new EyeJSONObject ("{}"); if (jtest->GetNumMembers() > 0) rc += testfailed ("JSON", "empty{}"); delete jtest; jtest = new EyeJSONObject ((char*)garbage); if (jtest->GetNumMembers() > 0) rc += testfailed ("JSON", "garbage"); delete jtest; jtest = new EyeJSONObject ("[\"\"]"); if (jtest->GetNumMembers() != 1) rc += testfailed ("JSON", "[\"\"]"); jtest->GetJSONString(json); cout << json << std::endl; delete jtest; if (rc == 0) printf ("PASSED: Bad json input data tests\n"); jtest = new EyeJSONObject (uploadedMeta); jtest->GetJSONString(json); cout << json << std::endl; delete jtest; jtest = new EyeJSONObject (someMeta); jtest->GetJSONString(json); cout << json << std::endl; delete jtest; jtest = new EyeJSONObject (policyTest); jtest->GetJSONString(json); cout << json << std::endl; delete jtest; jtest = new EyeJSONObject (vanishMeta); jtest->GetJSONString(json); cout << json << std::endl; delete jtest; jtest = new EyeJSONObject (badMeta); jtest->GetJSONString(json); cout << json << std::endl; delete jtest; FILE* fp = fopen ("test/test.json", "r"); char fbuff[104668]; size_t by = fread (fbuff, 1, 2048, fp); fbuff[by] = '\0'; //printf ("%d\n<%s>\n", int(by), fbuff); jtest = new EyeJSONObject (fbuff); jtest->GetJSONString(json); if (json.length() > 0) cout << json << std::endl; else rc += testfailed ("JSON", "coverage test"); delete jtest; fclose (fp); fp = fopen ("test/huge.json", "r"); by = fread (fbuff, 1, 104663, fp); fbuff[by] = '\0'; //printf ("%d\n<%s>\n", int(by), fbuff); jtest = new EyeJSONObject (fbuff); jtest->GetJSONString(json); if (json.length() < 3) testfailed ("JSON", "huge test"); else printf ("test/huge.json = %d bytes\n", (int)(json.length())); delete jtest; fclose (fp); jtest = new EyeJSONObject (JSON); policies = dynamic_cast(jtest->GetMember ("policies")); if (policies) { policies->GetJSONString(json); cout << json << std::endl; } delete jtest; jtest = new EyeJSONObject (policyTest); policies = dynamic_cast(jtest->GetMember ("policies")); if (policies) { for (size_t i = 0; i < policies->GetNumMembers(); ++i) { policy = dynamic_cast(policies->GetMember (i)); EyeJSONNode* item = policy->GetMember("policyName"); if (item) { item->GetJSONString(json); cout << json << std::endl; } item = policy->GetMember("policyValue"); if (item) { item->GetJSONString(json); cout << json << std::endl; } } } else rc++; delete jtest; printf ("\nPolicy tests\n-------------------------------\n"); ionu_policy_install (NULL); ionu_policy_install (""); ionu_policy_install ((char*)garbage); ionu_policy_install (policyTest); char* policychk = ionu_policy_check ("allowUserPasswordChange"); if (policychk) { printf ("%s\n", policychk); free (policychk); } else rc += testfailed ("PolicyCheck", "allowUserPasswordChange"); policychk = ionu_policy_check ("cachedTGIKeysExpire"); if (policychk) { EyeJSONObject* expire = new EyeJSONObject (policychk); EyeJSONScalar* pval = dynamic_cast(expire->GetMember("policyValue")); if (pval) printf ("Cached keys expire in %sms\n", pval->GetValue()); else rc += testfailed ("PolicyCheck", "cachedTGIKeysExpire no value found"); delete expire; free (policychk); } else rc += testfailed ("PolicyCheck", "cachedTGIKeysExpire"); // Check for policy that is not there policychk = ionu_policy_check ("allowStupidPasswords"); if (policychk) { rc += testfailed ("PolicyCheck", "allowStupidPasswords"); free (policychk); } ionu_policy_check (NULL); ionu_policy_check (""); ionu_policy_check ((char*)garbage); ionu_policy_uninstall (); // Check with no policies installed policychk = ionu_policy_check ("allowUserPasswordChange"); if (policychk) { rc += testfailed ("PolicyCheck", "uninstalled"); free (policychk); } /* printf ("\ncompute_keys tests\n-------------------------------\n"); FILE* jp = fopen ("test/collab100.json", "r"); char* jbuff = new (char[1024*1024]); by = fread (jbuff, 1, 592693, jp); fclose (jp); jbuff[by] = '\0'; //char* j = ionu_compute_keys ("[\"urn:sl:000000:1A537720::\",\"urn:sl:000000:D676E999::\"]", jbuff); //if (j) free (j); delete[] jbuff; //ionu_compute_keys (NULL, collabs); //ionu_compute_keys ("", collabs); //ionu_compute_keys ((char*)garbage, collabs); //ionu_compute_keys (members, NULL); //ionu_compute_keys (members, ""); //ionu_compute_keys (members, (char*)garbage); jtest = new EyeJSONObject (members); delete jtest; jtest = new EyeJSONObject (collabs); delete jtest; j = ionu_compute_keys (members, collabs); EyeJSONObject* collabtest = new EyeJSONObject(collabs); EyeJSONObject* membertest = new EyeJSONObject(members); std::string c2; collabtest->GetJSONString(c2); std::string m2; membertest->GetJSONString(m2); //char* j2 = ionu_compute_keys (m2.c_str(), c2.c_str()); cout << "Random" << endl; cout << j2 << endl; //if (strcmp (c2, collabs) != 0) // printf ("FAILED:\n%s\n%s\n", collabs, c2); //if (strcmp (m2, members) != 0) // printf ("FAILED:\n%s\n%s\n", members, m2); delete collabtest; delete membertest; Key* privateKey = new Key ("Check", "compute_keys", "test/private_key.pem", ""); EyeJSONObject* keys = new EyeJSONObject(j); keys->GetJSONString(m2); if (sequencelogic::StrCmp (m2.c_str(), j) != 0) rc += testfailed ("compute_keysi j != m2", m2.c_str()); for (size_t i = 0; i < keys->GetNumMembers(); ++i) { EyeJSONObject* userkey = dynamic_cast(keys->GetMember(i)); EyeJSONScalar* enkey = dynamic_cast(userkey->GetMember("key")); Base64Decode (enkey->GetValue(), buff); size_t bytes = 256; unsigned char* back = privateKey->PrivateKeyDecrypt (buff, bytes, &bytes); sequencelogic::Base64Encode (back, SL_AES_KEY_LEN, cbuff); printf ("decrypt TGI %d: %s\n", (int)bytes, cbuff); delete[] back; } free (j); free (j2); delete keys; sequencelogic::Base64Encode (TGIkey, SL_AES_KEY_LEN, cbuff); printf ("TGI: %s\n", cbuff); j2 = ionu_recompute_keys (m2.c_str(), c2.c_str(), TGIkey); cout << j2 << endl; keys = new EyeJSONObject(j2); keys->GetJSONString(m2); for (size_t i = 0; i < keys->GetNumMembers(); ++i) { EyeJSONObject* userkey = dynamic_cast(keys->GetMember(i)); EyeJSONScalar* enkey = dynamic_cast(userkey->GetMember("key")); Base64Decode (enkey->GetValue(), buff); size_t bytes = 256; unsigned char* back = privateKey->PrivateKeyDecrypt (buff, bytes, &bytes); sequencelogic::Base64Encode (back, SL_AES_KEY_LEN, cbuff); printf ("decrypt TGI %d: %s\n", (int)bytes, cbuff); delete[] back; } free (j2); delete keys; delete privateKey; */ return rc; } int TestTime() { int rc = 0; EyeTime t; const char* tstr = t.GetISO8601Time(); printf ("Current time %s\n", tstr); EyeTime nt(tstr); const char* ntstr = nt.GetISO8601Time(); if (strcmp (tstr, ntstr) != 0) rc += testfailed ("EyeTime", ntstr); tstr = t.GetISO8601TimeMs(); printf ("Current time %s\n", tstr); nt.SetTime (tstr); ntstr = nt.GetISO8601TimeMs(); if (strcmp (tstr, ntstr) != 0) rc += testfailed ("EyeTime", ntstr); tstr = t.GetUnixTime(); printf ("Current time %s\n", tstr); t.SetTime ("2014-01-23T17:44:40Z"); printf ("Seconds from now %0.0f\n", t.SecondsFromNow()); t.SetTime ("2014-01-23T17:45:40Z"); printf ("Seconds from now %0.0f\n", t.SecondsFromNow()); t.SetTime ("2014-03-07T09:31:17U"); printf ("2014-03-07T09:31:17U %s\n", t.GetUnixTime()); t.SetTime ("2014-03-07T10:18:37U"); printf ("2014-03-07T10:18:37U %s\n", t.GetUnixTime()); printf ("%s\n", t.GetISO8601Time ()); printf ("%s\n", t.GetLocalISO8601Time ()); printf ("%s\n", t.GetISO8601Time ()); t.SetTime ("2014-03-06T00:31:17Z"); tstr = t.GetUnixTime(); if (strcmp (tstr, "1394065877") != 0) rc += testfailed ("EyeTime", tstr); t.Dump(); // Test various leap years over a range of time t.SetTime ("2006-01-31T01:31:17Z"); if (strcmp (t.GetISO8601Time(), "2006-01-31T01:31:17Z") != 0) rc += testfailed ("EyeTime", t.GetISO8601Time()); t.SetTime ("2006-02-29T01:32:17Z"); if (strcmp (t.GetISO8601Time(), "2006-02-29T01:32:17Z") != 0) rc += testfailed ("EyeTime", t.GetISO8601Time()); t.SetTime ("2006-06-08T01:33:17Z"); if (strcmp (t.GetISO8601Time(), "2006-06-08T01:33:17Z") != 0) rc += testfailed ("EyeTime", t.GetISO8601Time()); t.SetTime ("2006-12-08T01:34:17Z"); if (strcmp (t.GetISO8601Time(), "2006-12-08T01:34:17Z") != 0) rc += testfailed ("EyeTime", t.GetISO8601Time()); t.SetTime ("2010-01-31T01:31:17Z"); if (strcmp (t.GetISO8601Time(), "2010-01-31T01:31:17Z") != 0) rc += testfailed ("EyeTime", t.GetISO8601Time()); t.SetTime ("2010-06-08T01:32:17Z"); if (strcmp (t.GetISO8601Time(), "2010-06-08T01:32:17Z") != 0) rc += testfailed ("EyeTime", t.GetISO8601Time()); t.SetTime ("2010-12-08T01:33:17Z"); if (strcmp (t.GetISO8601Time(), "2010-12-08T01:33:17Z") != 0) rc += testfailed ("EyeTime", t.GetISO8601Time()); t.SetTime ("2014-01-31T01:31:17Z"); if (strcmp (t.GetISO8601Time(), "2014-01-31T01:31:17Z") != 0) rc += testfailed ("EyeTime", t.GetISO8601Time()); t.SetTime ("2014-02-28T01:32:17Z"); if (strcmp (t.GetISO8601Time(), "2014-02-28T01:32:17Z") != 0) rc += testfailed ("EyeTime", t.GetISO8601Time()); t.SetTime ("2014-02-29T01:33:17Z"); if (strcmp (t.GetISO8601Time(), "2014-02-29T01:33:17Z") != 0) rc += testfailed ("EyeTime", t.GetISO8601Time()); t.SetTime ("2014-06-08T01:34:17Z"); if (strcmp (t.GetISO8601Time(), "2014-06-08T01:34:17Z") != 0) rc += testfailed ("EyeTime", t.GetISO8601Time()); t.SetTime ("2014-12-08T01:35:17Z"); if (strcmp (t.GetISO8601Time(), "2014-12-08T01:35:17Z") != 0) rc += testfailed ("EyeTime", t.GetISO8601Time()); // Most recent leap second, June 30, 2012 at 23:59:60 t.SetTime ("2012-06-30T23:59:60Z"); if (strcmp (t.GetISO8601Time(), "2012-06-30T23:59:60Z") != 0) rc += testfailed ("EyeTime", t.GetISO8601Time()); // Invalid dates and times t.SetTime ("2013-02-29T01:31:17Z"); if (strcmp (t.GetISO8601Time(), "2014-02-29T01:31:17Z") == 0) rc += testfailed ("EyeTime", t.GetISO8601Time()); t.SetTime ("2013-04-31T01:31:17Z"); if (strcmp (t.GetISO8601Time(), "2014-04-31T01:31:17Z") == 0) rc += testfailed ("EyeTime", t.GetISO8601Time()); t.SetTime ("2013-02-28T24:31:17Z"); if (strcmp (t.GetISO8601Time(), "2014-02-28T24:31:17Z") == 0) rc += testfailed ("EyeTime", t.GetISO8601Time()); t.SetTime ("2013-02-28T14:71:17Z"); if (strcmp (t.GetISO8601Time(), "2014-02-28T14:71:17Z") == 0) rc += testfailed ("EyeTime", t.GetISO8601Time()); t.SetTime ("2013-02-28T14:31:77Z"); if (strcmp (t.GetISO8601Time(), "2014-02-28T14:31:77Z") == 0) rc += testfailed ("EyeTime", t.GetISO8601Time()); t.SetTime ("2014-06-08T01:31:17.777Z"); t.Dump(); t.SetTime ("2014-06-14T01:31:17.777Z"); t.Dump(); t.SetTime ("2013-03-01T01:31:17.777Z"); t.Dump(); t.SetTime ("2012-03-01T01:31:17.555M"); t.Dump(); t.SetTime ("2012-06-11T01:31:17.333Y"); t.Dump(); t.SetTime ("2014-10-28T23:13:06.174Z"); cout << t << endl; t.SetFileTime ("t"); t.GetFileTime ("t"); cout << t << endl; t.SetTime ("2014-11-17T15:14:56-07:00"); cout << t << endl; t.SetTime ("2014-11-17T15:14:56+07:00"); cout << t << endl; t.SetTime ("2014-11-17T16:14:56-08:00"); cout << t << endl; //t.SetTime ("2008-04-10 13:30:00Z"); //cout << t << endl; //t.SetTime ("Thu, 10 Apr 2008 13:30:00 GMT"); //cout << t << endl; //t.SetTime ("Thursday, April 10, 2008 1:30:00 PM"); //cout << t << endl; //t.SetTime ("6/15/2009 1:45:30 PM"); //cout << t << endl; //t.SetTime ("6/15/2009 1:45:30 PM -07:00"); //cout << t << endl; //t.SetTime ("4/10/2008 6:30:00 AM"); //cout << t << endl; t.SetTime ("808464430-67--858993460T58:128:00.000C"); printf ("%s\n", t.GetISO8601TimeMs ()); cout << t << endl; t.Dump(); t.SetTime ("2014-06-08T01:31:17.777Z"); if (rc == 0) printf ("\nEyeTime tests passed\n-------------------------------\n"); else printf ("\n%d EyeTime tests failed\n-------------------------------\n", rc); return rc; } int TestUtils() { int rc = 0; printf ("\nUtility tests\n-------------------------------\n"); char* md = NULL; unsigned char cg_key[SL_AES_KEY_LEN]; unsigned char user_key[SL_AES_KEY_LEN]; ionu_derive_key ("u3K2*l$qZ0a<", cg_key); ionu_derive_userkey ("u3K2*l$qZ0a<", user_key, cg_key); unsigned char binary[64] = {211,231,210,248,235}; unsigned char utf8[10] = {0x20, 0xc2,0xa2, 0xe2,0x82,0xac, 0xf0,0xa4,0xad,0xa2}; if (sequencelogic::IsStrUTF8 ((char*)cg_key, SL_AES_KEY_LEN)) rc += testfailed ("sequencelogic::IsStrUTF8", "cg_key"); if (!sequencelogic::IsStrUTF8 ((char*)utf8, 10)) rc += testfailed ("sequencelogic::IsStrUTF8", "valid currency symbols"); char ascii[256]; size_t bytes = 0; //sequencelogic::DumpAsBinary (binary, 5); //sequencelogic::Base32Encode (binary, 1, ascii); //printf ("%s\n", ascii); //sequencelogic::Base32Encode (binary, 2, ascii); //printf ("%s\n", ascii); //sequencelogic::Base32Encode (binary, 3, ascii); //printf ("%s\n", ascii); //sequencelogic::Base32Encode (binary, 4, ascii); //printf ("%s\n", ascii); //sequencelogic::Base32Encode (binary, 5, ascii); //printf ("%s\n", ascii); //bytes = sequencelogic::Base32Decode (ascii, binary); //sequencelogic::DumpAsBinary (binary, 5); sequencelogic::Base32Encode (cg_key, 15, ascii); bytes = sequencelogic::Base32Decode (ascii, binary); if (bytes != 15 || sequencelogic::MemCmp (binary, cg_key, 15) != 0) rc += testfailed ("B32 15 bytes cg_key", ascii); sequencelogic::Base32Encode (cg_key, SL_AES_KEY_LEN, ascii); bytes = sequencelogic::Base32Decode (ascii, binary); if (bytes != SL_AES_KEY_LEN || sequencelogic::MemCmp (binary, cg_key, SL_AES_KEY_LEN) != 0) rc += testfailed ("B32 cg_key", ascii); sequencelogic::Base32Encode (user_key, 15, ascii); bytes = sequencelogic::Base32Decode (ascii, binary); if (bytes != 15 || sequencelogic::MemCmp (binary, user_key, 15) != 0) rc += testfailed ("B32 15 bytes user_key", ascii); sequencelogic::Base32Encode (user_key, SL_AES_KEY_LEN, ascii); bytes = sequencelogic::Base32Decode (ascii, binary); if (bytes != SL_AES_KEY_LEN || sequencelogic::MemCmp (binary, user_key, SL_AES_KEY_LEN) != 0) rc += testfailed ("B32 user_key", ascii); if (rc == 0) printf ("Base32 tests passed\n"); sequencelogic::Base64Encode (cg_key, 15, ascii); bytes = sequencelogic::Base64Decode (ascii, binary); if (bytes != 15 || sequencelogic::MemCmp (binary, cg_key, 15) != 0) rc += testfailed ("B64 15 bytes cg_key", ascii); sequencelogic::Base64Encode (cg_key, SL_AES_KEY_LEN, ascii); bytes = sequencelogic::Base64Decode (ascii, binary); if (bytes != SL_AES_KEY_LEN || sequencelogic::MemCmp (binary, cg_key, SL_AES_KEY_LEN) != 0) rc += testfailed ("B64 cg_key", ascii); sequencelogic::Base64Encode (user_key, 15, ascii); bytes = sequencelogic::Base64Decode (ascii, binary); if (bytes != 15 || sequencelogic::MemCmp (binary, user_key, 15) != 0) rc += testfailed ("B64 15 bytes user_key", ascii); sequencelogic::Base64Encode (user_key, SL_AES_KEY_LEN, ascii); bytes = sequencelogic::Base64Decode (ascii, binary); if (bytes != SL_AES_KEY_LEN || sequencelogic::MemCmp (binary, user_key, SL_AES_KEY_LEN) != 0) rc += testfailed ("B64 user_key", ascii); if (rc == 0) printf ("Base64 tests passed\n"); ionu_base64_encode (cg_key, 15, ascii); bytes = ionu_base64_decode (ascii, binary); if (bytes != 15 || sequencelogic::MemCmp (binary, cg_key, 15) != 0) rc += testfailed ("ionu_B64 15 bytes cg_key", ascii); // Test TGI signature generation /* if (ionu_gen_tgisig (NULL)) rc += testfailed ("GenerateTGISig", "NULLempty"); if (ionu_gen_tgisig ("")) rc += testfailed ("GenerateTGISig", "empty"); if (ionu_gen_tgisig ((char*)garbage)) rc += testfailed ("GenerateTGISig", "garbage"); md = ionu_gen_tgisig (PERMS); if (rc == 0 && sequencelogic::StrCmp (md, "6a0ce1ec504b") == 0) printf ("TGI signature tests passed: %s\n", md); else rc += testfailed ("TGI signature\n", md); free (md); */ md = ionu_digest_msg ("sha1", (const unsigned char*)PERMS, strlen(PERMS)); if (sequencelogic::StrCmp (md, "03b00bb4cc0edc80b9063653c8340a908775a367") != 0) rc += testfailed ("sha1", md); free (md); md = ionu_digest_msg ("sha256", (const unsigned char*)PERMS, strlen(PERMS)); if (sequencelogic::StrCmp (md, "27d80a5effacb099f49ba81a245ad4a4ea0c3e1768b3b2a7d6833365c66be8fa") != 0) rc += testfailed ("sha256", md); free (md); std::string hmd; hmd = sequencelogic::HMACMessage (NULL, SL_AES_KEY_LEN, (const unsigned char*)PERMS, strlen(PERMS)); if (hmd.size() > 0) rc += testfailed ("hmac", "NULL key"); hmd = sequencelogic::HMACMessage (TestKey, SL_AES_KEY_LEN, NULL, strlen(PERMS)); if (hmd.size() > 0) rc += testfailed ("hmac", "NULL msg"); hmd = sequencelogic::HMACMessage (TestKey, SL_AES_KEY_LEN/2, (const unsigned char*)PERMS, strlen(PERMS)); if (hmd.compare ("42963870f70684f00ebe8d083f61f20a87265ff4") != 0) rc += testfailed ("hmac cg_key/2", hmd.c_str()); hmd = sequencelogic::HMACMessage (TestKey, SL_AES_KEY_LEN, (const unsigned char*)shortword, strlen(shortword)); if (hmd.compare ("f160e4c65719db3bbcfe9bf00cd3cedda078a3dd") != 0) rc += testfailed ("hmac cg_key Hi", hmd.c_str()); hmd = sequencelogic::HMACMessage (TestKey, SL_AES_KEY_LEN, (const unsigned char*)PERMS, strlen(PERMS)); if (hmd.compare ("a06df1aacfbf923b8053773dec8b7529467faaab") != 0) rc += testfailed ("hmac cg_key", hmd.c_str()); hmd = sequencelogic::HMACMessage (badkey, SL_AES_KEY_LEN, (const unsigned char*)PERMS, strlen(PERMS)); if (hmd.compare ("c59d3a08989ffd2d30b05815d68a240d526fa49f") != 0) rc += testfailed ("hmac user_key", hmd.c_str()); if (rc == 0) printf ("Hash and HMAC tests passed\n"); //size_t len = 0; //unsigned char* enc = ionu_symmetric_encrypt_buffer (TGIkey, (const unsigned char*) "Howdy", 6, &len, badkey); //unsigned char* dec = ionu_symmetric_decrypt_buffer (TGIkey, enc, len, &len, badkey); //if (sequencelogic::StrCmp ((char*)dec, "Howdy") != 0) // rc += testfailed ("ionu_symmetric_decrypt_buffer", "Howdy"); //free (enc); //free (dec); // Test URN validation if (! CheckURN (URN)) rc += testfailed ("IsValidURN", URN); if (! CheckURN (URN0)) rc += testfailed ("IsValidURN", URN0); if (! CheckURN (URN1)) rc += testfailed ("IsValidURN", URN1); if (! CheckURN (URN2)) rc += testfailed ("IsValidURN", URN2); if (! CheckURN (URN3)) rc += testfailed ("IsValidURN", URN3); if (! CheckURN (URN4)) rc += testfailed ("IsValidURN", URN4); if (! CheckURN (URN5)) rc += testfailed ("IsValidURN", URN5); if (rc == 0) printf ("Valid URN tests passed\n"); if (sequencelogic::IsValidURN (NULL)) rc += testfailed ("IsValidURN", "NULL"); if (sequencelogic::IsValidURN ("")) rc += testfailed ("IsValidURN", "empty"); if (sequencelogic::IsValidURN ((char*)garbage)) rc += testfailed ("IsValidURN", "garbage"); if (sequencelogic::IsValidURN (burn0)) rc += testfailed ("IsValidURN", burn0); if (sequencelogic::IsValidURN (burn1)) rc += testfailed ("IsValidURN", burn1); if (sequencelogic::IsValidURN (burn2)) rc += testfailed ("IsValidURN", burn2); if (sequencelogic::IsValidURN (burn3)) rc += testfailed ("IsValidURN", burn3); if (sequencelogic::IsValidURN (burn4)) rc += testfailed ("IsValidURN", burn4); if (sequencelogic::IsValidURN (burn5)) rc += testfailed ("IsValidURN", burn5); if (sequencelogic::IsValidURN (burn6)) rc += testfailed ("IsValidURN", burn6); if (sequencelogic::IsValidURN (burn7)) rc += testfailed ("IsValidURN", burn7); if (rc == 0) printf ("Invalid URN tests passed\n"); // Test URI encode and decode //EyeBytes url; //url.AssignURIEncodedString(cgurl); //char* uri = url.GetURIEncodedString(); //if (sequencelogic::StrCmp (cgurl, uri) != 0) // rc += testfailed ("URI encoding", uri); //delete[] uri; Key bkey ("Meta", "key", SL_AES_KEY_LEN, badkey, Key::AES); std::string encfstr = sequencelogic::EncryptFilename (".imchat", bkey); encfstr = sequencelogic::DecryptFilename (encfstr, bkey); if (encfstr.compare (".imchat") != 0) rc += testfailed ("sequencelogic::DecryptFilename(.imchat)", ""); #ifdef WIN32 std::string f1 ("C:\\Users\\philip\\Dropbox\\New Text Document.txt.ionu"); std::string f2 ("C:\\Users\\philip\\Dropbox\\NEW TEXT DOCUMENT.txt.ionu"); if (sequencelogic::CompareFilenames (f1, f2) != 0) rc += testfailed ("sequencelogic::sequencelogic::CompareFilenames", "New Text Document"); #endif cout << "test.ai " << sequencelogic::GuessMimeType ("test.ai") << endl; cout << "test.doc " << sequencelogic::GuessMimeType ("test.doc") << endl; cout << "test.gzip " << sequencelogic::GuessMimeType ("test.gzip") << endl; cout << "test.docx " << sequencelogic::GuessMimeType ("test.docx") << endl; cout << "test.ionu " << sequencelogic::GuessMimeType ("test.ionu") << endl; cout << "test.jpeg " << sequencelogic::GuessMimeType ("test.jpeg") << endl; cout << "test.json " << sequencelogic::GuessMimeType ("test.json") << endl; cout << "test.m4a " << sequencelogic::GuessMimeType ("test.m4a") << endl; cout << "test.pdf " << sequencelogic::GuessMimeType ("test.pdf") << endl; cout << "test.qt " << sequencelogic::GuessMimeType ("test.qt") << endl; cout << "test.cer " << sequencelogic::GuessMimeType ("test.cer") << endl; cout << "test.crt " << sequencelogic::GuessMimeType ("test.crt") << endl; cout << "test.ionu " << sequencelogic::GuessMimeType ("test.ionu") << endl; cout << "test.wav " << sequencelogic::GuessMimeType ("test.wav") << endl; cout << "test.g " << sequencelogic::GuessMimeType ("test.g") << endl; cout << "test. " << sequencelogic::GuessMimeType ("test.") << endl; cout << "test " << sequencelogic::GuessMimeType ("test") << endl; return rc; } int TestRandom() { std::string pw (""); unsigned char buff[32768]; EyeDRBG* drbg = new EyeDRBG ((unsigned char*)"000000:tim,favbook::BOB,flame::BOB,kiss::BOB]", strlen ("000000:tim,favbook::BOB,flame::BOB,kiss::BOB]")); drbg->RandBytes (buff, 4096); ofstream file ("drbg", ios::out | ios::binary | ios::trunc); if (file.is_open()) { file.write ((char*)buff, 4096); file.close(); } delete drbg; #ifdef ENTROPY_VALIDATION // Create 3 different files with 4096 bytes of "random" data. The program "ent" can be used to // analyze these using statistical techniques for randomness. drbg = new EyeDRBG ((unsigned char*)"ALANRENOTOBYKEITH", strlen ("ALANRENOTOBYKEITH")); drbg->RandBytes (buff, 4096); ofstream nfile ("drbg1", ios::out | ios::binary | ios::trunc); if (nfile.is_open()) { nfile.write ((char*)buff, 4096); nfile.close(); } delete drbg; sequencelogic::RandomBytes (buff, 4096); ofstream rfile ("rand", ios::out | ios::binary | ios::trunc); if (rfile.is_open()) { rfile.write ((char*)buff, 4096); rfile.close(); } #endif // Generate 8 base32 and base64 passwords size_t i = 0; printf ("Base32: "); for (i = 0; i < 8; ++i) { pw = RandomBase32 (8); printf ("%s ", pw.c_str()); } printf ("\nBase64: "); for (i = 0; i < 8; ++i) { pw = RandomBase64 (8); printf ("%s ", pw.c_str()); } printf ("\nSimple: "); for (i = 0; i < 8; ++i) { pw = RandomPassWord (8, passwordset); printf ("%s ", pw.c_str()); } printf ("\nBest: "); for (i = 0; i < 6; ++i) { pw = RandomPassWord (10, NULL); printf ("%s ", pw.c_str()); } printf ("\n"); return 0; } int TestRSAKeyGeneration() { Key rkey; Keyring ring ("RSA", "tests"); ring.GenerateRSAKey ("challenges", "test to match JS implementation", challenges); ring.GetKey ("challenges", rkey); cout << rkey.GetPubKey() << endl; ring.GenerateRSAKey ("challenges1", "test to match JS implementation", challenges1); ring.GetKey ("challenges1", rkey); cout << rkey.GetPubKey() << endl; ring.GenerateRSAKey ("challenges2", "test to match JS implementation", challenges2); ring.GetKey ("challenges2", rkey); cout << rkey.GetPubKey() << endl; ring.GenerateRSAKey ("IOnUBob", "test to match JS implementation", "IOnU,Bob,Bob,Bob"); ring.GetKey ("IOnUBob", rkey); cout << rkey.PublicKeyFingerPrint() << endl; ring.GenerateRSAKey ("IONUBob", "test to match JS implementation", "IONU,Bob,Bob,Bob"); ring.GetKey ("IONUBob", rkey); cout << rkey.PublicKeyFingerPrint() << endl; #ifndef WIN32 std::vector answers; for (size_t i = 0; i < 10; ++i) { size_t pos = rand() &0x000F; std::string challengeResponse = challengeQuestions[pos]; challengeResponse += ":"; challengeResponse += challengeAnswers[pos]; answers.push_back (challengeResponse); pos = rand() &0x000F; challengeResponse = challengeQuestions[pos]; challengeResponse += ":"; challengeResponse += challengeAnswers[pos]; answers.push_back (challengeResponse); pos = rand() &0x000F; challengeResponse = challengeQuestions[pos]; challengeResponse += ":"; challengeResponse += challengeAnswers[pos]; answers.push_back (challengeResponse); std::sort (answers.begin(), answers.end()); challengeResponse = "[\"IOnU\","; for (string &answer : answers) { challengeResponse += "\""; challengeResponse += answer; } challengeResponse += "\"]"; cout << challengeResponse << endl; answers.clear(); //ring.GenerateRSAKey ("RSA", "", challengeResponse); } #endif return 0; } int TestKeys() { int rc = 0; unsigned char* pbuff = NULL; Key* k = NULL; size_t bytes = 0; unsigned char* back = NULL; printf ("\nKeyring tests\n-------------------------------\n"); const char* goodword = "password"; const char* badword = "wrong"; unsigned char hi[SL_AES_KEY_LEN]; unsigned char good[SL_AES_KEY_LEN]; unsigned char bad[SL_AES_KEY_LEN]; unsigned char aes[SL_AES_KEY_LEN]; ionu_derive_key (shortword, hi); ionu_derive_key (goodword, good); ionu_derive_key (badword, bad); Key qKey ("Good", "", SL_AES_KEY_LEN, good, Key::AES); // Test JSON and SQLite based keyrings for interop Keyring qtest ("SQLite", "test/qtest.iks", qKey); qtest.AddKey ("CloudGuard", "CG half key", SL_AES_KEY_LEN, good, Key::AES); qtest.AddKey ("String", "", 6, (unsigned char*)"string", Key::STRING); Keyring utest ("JSON", ""); cout << qtest.Stringify (qKey) << endl; utest.LoadFromJSON (qtest.Stringify (qKey)); cout << utest.Stringify (qKey) << endl; utest.Unlock (good); const Key* uk = utest.GetKey ("CloudGuard"); const Key* qk = qtest.GetKey ("CloudGuard"); if (!uk->Equals (*qk)) rc += testfailed ("SQLite and JSON key mismatch", "CloudGuard"); else printf ("JSON and SQLite based keyrings interop passed\n"); uk->Dump(); qk->Dump(); // Test public key encrypt/decrypt k = new Key ("test", "Import/Export", "test/private_key.pem", ""); pbuff = k->PublicKeyEncrypt ((unsigned char*)"Howdy", 6, &bytes); printf ("PK howdy %d bytes\n", (int)bytes); if (pbuff) { printf ("Howdy 6 bytes in, %d bytes out\n", (int)bytes); back = k->PrivateKeyDecrypt (pbuff, bytes, &bytes); if (strcmp ((char*)back, "Howdy") != 0) rc += testfailed ("pkey decrypt", (char*)back); else printf ("Howdy, decrypted %d bytes\n", (int)bytes); delete[] back; delete[] pbuff; } else rc += testfailed ("pkey encrypt", "Howdy"); delete k; k = new Key ("test", "Import/Export", "test/private_key.der", ""); k->Export ("t.pem", ""); if (! filecompare ("t.pem", "test/private_key.pem")) rc += testfailed ("Export (from der)", "t.pem"); delete k; // TODO, get import of encrypted keys working //k = new Key ("test", "Import/Export", "test/pk8_des.pem", "pk8_des"); //delete k; //k = new Key ("test", "Import/Export", "test/pk8_3des.pem", "pk8_3des"); //delete k; // Create a keyring, add 3 keys and lock with short password Keyring* ring = new Keyring ("testring", "Test Key Ring"); Key* key1 = new Key ("Sample", "do not duplicate", 16, (const unsigned char*) "0123456789abcdef", Key::GENERIC); key1->Dump(); Key* key2 = new Key ("Example", "do duplicate", 16, (const unsigned char*) "fedcba9876543210", Key::STRING); //key2->Dump(); //Key* key3 = new Key ("6a0ce1ec504b", "TGI good", SL_AES_KEY_LEN, good, Key::TGI); //Key* key4 = new Key ("ea7cb39afc1a", "TGI bad", SL_AES_KEY_LEN, bad, Key::TGI); //key3->Dump(); if (! ring->AddKey (key1)) rc += testfailed ("Keyring::AddKey", key1->GetName()); if (! ring->AddKey (key2)) rc += testfailed ("Keyring::AddKey", key2->GetName()); //if (! ring->AddKey (key3)) // rc += testfailed ("Keyring::AddKey", key3->GetName()); ring->Dump(); //ring->AddKey (key4); //ring->Dump(); //key3 = new Key ("6a0ce1ec504b", "SL good", SL_AES_KEY_LEN, good, Key::TGI); //ring->AddKey (key3); //key3 = new Key ("6a0ce1ec504b", "SL good", SL_AES_KEY_LEN, good, Key::TGI); if (ring->Lock (shortword)) printf ("Lock succeeded\n"); else rc += testfailed ("Keyring::Lock", shortword); // Unlock with short password and verify keys if (ring->Unlock (shortword)) printf ("Unlock succeeded\n"); else rc += testfailed ("Keyring::Unlock", shortword); if (! ring->GetKey (key1->GetName())) rc += testfailed ("Keyring::GetKey", key1->GetName()); if (! ring->GetKey (key2->GetName())) rc += testfailed ("Keyring::GetKey", key2->GetName()); //if (! ring->GetKey (key3->GetName())) // rc += testfailed ("Keyring::GetKey", key3->GetName()); k = new Key ("Example", "updated", 16, (const unsigned char*) "0123fedcba987654", Key::STRING); if (! ring->UpdateKey (k)) rc += testfailed ("Keyring::UpdateKey", key2->GetName()); delete k; const Key* ck = ring->GetKey (key2->GetName()); ck->Dump(); // Lock with new password ring->Lock (goodword); //ck = ring->GetKey (key3->GetName()); //ck->Dump(); ring->Unlock (goodword); ck = ring->GetKey (key2->GetName()); if (strncmp ((char*)ck->GetKey(), "0123fedcba987654", 16) != 0) rc += testfailed ("Keyring::GetKey decrypted", k->GetName()); else printf ("Key decrypt succeeded\n"); ring->Dump(); /* if (!ring->RenewTGICache(43200)) // Set expiration to 1/2 day rc += testfailed ("Keyring::RenewTGICache", ring->GetName()); ring->Dump(); if (!ring->ClearTGICache()) rc += testfailed ("Keyring::ClearTGICache", ring->GetName()); if (ring->GetNumKeys() != 2) rc += testfailed ("Keyring::ClearTGICache", ring->GetName()); if (!ring->RenewTGICache(-2*86400)) // Subtract 2 days from the expiration rc += testfailed ("Keyring::RenewTGICache", ring->GetName()); if (!ring->ClearTGICache()) rc += testfailed ("Keyring::ClearTGICache", ring->GetName()); delete key3; key3 = new Key ("6a0ce1ec504b", "TGI sig/key pair", SL_AES_KEY_LEN, good, Key::TGI); ring->AddKey (key3); // Add the TGI key back if (!ring->RenewTGICache(-2*86400)) // Set expiration to 2 days ago rc += testfailed ("Keyring::RenewTGICache", ring->GetName()); ring->Lock (goodword); ring->SaveAs (keystore); delete ring; ring = new Keyring (keystore); if (!ring->Unlock (goodword)) rc += testfailed ("Keyring::Unlock after TGI", ring->GetName()); //ring->Dump(); if (ring->GetKey("TGIsignature")) rc += testfailed ("Keyring::ClearTGICache (not expired)", ring->GetName()); else printf ("TGI key expiration test succeeded\n"); */ // Import from X.509, generate pin hash if (!ring->ImportPubKeyFromCert ("test/ionu.pem")) rc += testfailed ("Keyring::ImportPubKeyFromCert", "test_cert.pem"); else { const Key* pub = ring->GetKey ("cert"); if (pub) { pub->Export ("cert_pk.der", ""); std::string pin = sequencelogic::DigestFile ("sha1", "cert_pk.der"); cout << "X.509 pin hash: " << pin << endl; } else { rc += testfailed ("Keyring::ImportPubKeyFromCert get pubkey", "cert"); Key junk; cout << ring->Stringify (junk); } } // Generate RSA key pair if (ring->GenerateRSAKey("CloudGuard", "RSA keypair")) printf ("Generated RSA keypair\n"); else rc += testfailed ("GeneratedRSAKey", "CloudGuard"); const Key* privateK = ring->GetKey("CloudGuard"); // Test RSA IES hybrid encryption pbuff = privateK->RSAIESEncrypt ((unsigned char*)megaMeta, strlen(megaMeta)+1, &bytes); back = privateK->RSAIESDecrypt (pbuff, bytes, &bytes); if (sequencelogic::StrCmp ((char*)back, megaMeta) != 0) rc += testfailed ("RSAIESEncrypt()", "CloudGuard"); if (pbuff) delete[] pbuff; if (back) delete[] back; char* pk = ring->GetPubKey("CloudGuard"); if (!pk) rc += testfailed ("Keyring::GetPubKey", "CloudGuard not found"); else if (strncmp (pk, "-----BEGIN PUBLIC KEY", 21) != 0) rc += testfailed ("Keyring::GetPubKey", "CloudGuard"); Key* publicK = NULL; if (pk) { publicK = new Key ("CgPublic", "CloudGuard public key", (int)strlen(pk), (const unsigned char*) pk, Key::RSA_PUBLIC); delete[] pk; // Test public key encrypt/decrypt pbuff = publicK->PublicKeyEncrypt ((unsigned char*)"Howdy", 6, &bytes); if (pbuff) { back = privateK->PrivateKeyDecrypt (pbuff, bytes, &bytes); if (back == nullptr || strcmp ((char*)back, "Howdy") != 0) rc += testfailed ("pkey decrypt", (char*)back); if (back) delete[] back; // Try decrypt with wrong private key Key* badBOT = new Key ("BadBot", "RSA key", (int)strlen(BOT_private), (const unsigned char*)BOT_private, Key::RSA); back = badBOT->PrivateKeyDecrypt (pbuff, 256, &bytes); if (back || bytes > 0) rc += testfailed ("badBOT decrypt", (char*)back); else printf ("RSA decrypt test with wrong key succeeded\n"); delete[] pbuff; } else rc += testfailed ("pkey encrypt", "Howdy"); pbuff = privateK->PrivateKeySign ((unsigned char*)"ydwoH", 6, &bytes); if (pbuff) { // Verify match and not matched if (publicK->PublicKeyVerify (pbuff, bytes, (unsigned char*)"ydwoH", 6) != 1) rc += testfailed ("pkey verify", "ydwoH"); else printf ("Sign and very tests passed\n"); if (publicK->PublicKeyVerify (pbuff, bytes, (unsigned char*)"Howdy", 6) == 1) rc += testfailed ("pkey verify bad", "Howdy"); delete[] pbuff; } else rc += testfailed ("pkey sign:", "ydwoH"); } // Test secret + challenge key generation Keyring sss ("Secret", "test"); Key k1, k2, k3, k4; std::string sname = "RSA - secret"; std::string sdesc = "test"; std::string schal = ""; std::string ssalt = ""; std::string sempty = ""; std::string ssret ("secret78$joe@gmail.com$urn:sl:001001:::"); std::string van ("urn:sl:001001:::"); #ifdef LIN64 std::vector elist ({ "joe@sequencelogic.net", "jenny@sequencelogic.net", "jones@sequencelogic.net" }); if (!sss.GenerateRSAKeys (van, elist)) rc += testfailed ("Corporate email based pre-provisioning", "bulk"); #endif // Verify old style unsalted challenges sss.GenerateRSAKey ("RSA-old", "", "[sequencelogic::challenges]"); sss.GenerateRSAKey ("RSA-new", sempty, "[sequencelogic::challenges]", sempty, sempty); sss.GetKey ("RSA-old", k1); sss.GetKey ("RSA-new", k2); if (k1.Equals (k2)) printf ("Unsalted key generation tests passed\n"); else rc += testfailed ("Unsalted challenge key generation tests", "RSA - old != new"); // Verify random salted challenges unsigned char rsalt[SL_SHA256_LEN]; char b64[SL_SHA256_LEN * 4]; sequencelogic::RandomBytes (SL_SHA256_LEN, rsalt); sequencelogic::Base64Encode (rsalt, SL_SHA256_LEN, b64); std::string bsalt = b64; sss.GenerateRSAKey ("RSA-salted1", sempty, "[sequencelogic::challenges]", sempty, bsalt); sequencelogic::BinaryToHex (rsalt, SL_SHA256_LEN, b64); std::string hsalt = b64; sss.GenerateRSAKey ("RSA-salted1h", sempty, "[sequencelogic::challenges]", sempty, hsalt); sequencelogic::RandomBytes (SL_SHA256_LEN, rsalt); sequencelogic::Base64Encode (rsalt, SL_SHA256_LEN, b64); bsalt = b64; sss.GenerateRSAKey ("RSA-salted2", sempty, "[sequencelogic::challenges]", sempty, bsalt); bsalt = "random"; sss.GenerateRSAKey ("RSA-salter", sempty, "[sequencelogic::challenges]", sempty, bsalt); sss.GetKey ("RSA-salted1", k1); sss.GetKey ("RSA-salted1h", k2); sss.GetKey ("RSA-salted2", k3); sss.GetKey ("RSA-salter", k4); if (k1.Equals (k3) && !(k1.Equals (k2)) && !(k1.Equals (k4))) rc += testfailed ("Salted challenge key generation tests", "RSA - salted 1 = 2"); else printf ("Random salted key generation tests passed\n"); // Verify secret based keys sss.GenerateRSAKey (sname, sdesc, schal, ssret, ssalt); sss.GetKey (sname, k1); schal = "[sequencelogic::challenges]"; sname = "RSA - secret + challenge"; // Create key with secret, and return "salt" sss.GenerateRSAKey (sname, sdesc, schal, ssret, ssalt); sss.GetKey (sname, k2); ssret = ""; // Create key with challenges and "salt" sname = "RSA - secret + salt"; sss.GenerateRSAKey (sname, sdesc, schal, ssret, ssalt); sss.GetKey (sname, k3); if (k1.Equals (k2) && k1.Equals (k3)) printf ("Secret challenge key generation tests passed\n"); else { k1.Dump(); k2.Dump(); k3.Dump(); rc += testfailed ("Secret challenge key generation tests", "RSA - secret"); } // Test EC key generation and ECDH generation of shared secret between peers ring->GenerateECKey("me", "mine"); ring->GenerateECKey("peer", "theirs"); ring->GenerateECKey("third", "theirs"); pk = ring->GetPubKey ("me"); Key* mypubkey = new Key ("EcPublic", "Electric CloudGuard public key", (int)strlen(pk), (const unsigned char*) pk, Key::EC_PUBLIC); delete[] pk; pk = ring->GetPubKey ("peer"); Key* peerpubkey = new Key ("EcPublic", "Electric CloudGuard public key", (int)strlen(pk), (const unsigned char*) pk, Key::EC_PUBLIC); peerpubkey->Export ("test/ec_pub.pem", ""); delete[] pk; ring->GenerateECKey ("MyChallenge", "deterministic", challenges); ring->GenerateECKey ("PeerChallenge", "deterministic", challenges1); const Key* me = ring->GetKey ("me"); me->Export ("test/ec_priv.pem", ""); const Key* peer = ring->GetKey ("peer"); const Key* third = ring->GetKey ("third"); const Key* mychallenge = ring->GetKey ("MyChallenge"); mychallenge->Export ("test/ec_challenge.pem", ""); const Key* peerchallenge = ring->GetKey ("PeerChallenge"); unsigned char* secret = NULL; size_t secret_len; char ascii[256]; secret = me->GenerateECDHSecret (peer, &secret_len); sequencelogic::Base64Encode (secret, secret_len, ascii); printf ("ECDH m+p: %s\n", ascii); delete[] secret; secret = me->GenerateECDHSecret (peerpubkey, &secret_len); sequencelogic::Base64Encode (secret, secret_len, ascii); printf ("ECDH m+p: %s\n", ascii); delete[] secret; secret = peer->GenerateECDHSecret (me, &secret_len); sequencelogic::Base64Encode (secret, secret_len, ascii); printf ("ECDH p+m: %s\n", ascii); delete[] secret; secret = me->GenerateECDHSecret (third, &secret_len); sequencelogic::Base64Encode (secret, secret_len, ascii); printf ("ECDH m+t: %s\n", ascii); delete[] secret; secret = third->GenerateECDHSecret (me, &secret_len); sequencelogic::Base64Encode (secret, secret_len, ascii); printf ("ECDH t+m: %s\n", ascii); delete[] secret; secret = peer->GenerateECDHSecret (third, &secret_len); sequencelogic::Base64Encode (secret, secret_len, ascii); printf ("ECDH p+t: %s\n", ascii); delete[] secret; secret = third->GenerateECDHSecret (peer, &secret_len); sequencelogic::Base64Encode (secret, secret_len, ascii); printf ("ECDH t+p: %s\n", ascii); delete[] secret; secret = mychallenge->GenerateECDHSecret (peerchallenge, &secret_len); sequencelogic::Base64Encode (secret, secret_len, ascii); printf ("ECDH challenge m+p: %s\n", ascii); delete[] secret; secret = peerchallenge->GenerateECDHSecret (mychallenge, &secret_len); sequencelogic::Base64Encode (secret, secret_len, ascii); printf ("ECDH challenge p+m: %s\n", ascii); delete[] secret; // Test EC public key encrypt/decrypt pbuff = me->ECDHEncrypt (peerpubkey, (unsigned char*)"Howdy we are having some funny now", 35, &bytes); //printf ("EC: PK howdy %d bytes\n", (int)bytes); if (pbuff) { printf ("EC: Howdy 35 bytes in, %d bytes out\n", (int)bytes); back = peer->ECDHDecrypt (mypubkey, pbuff, bytes, &bytes); if (strcmp ((char*)back, "Howdy we are having some funny now") != 0) rc += testfailed ("pkey decrypt", (char*)back); else printf ("EC: %s, decrypted %d bytes\n", (char*)back, (int)bytes); delete[] back; delete[] pbuff; } else rc += testfailed ("EC: pkey encrypt", "Howdy"); pbuff = me->ECDHEncrypt (peerpubkey, (unsigned char*)"Howdy we are having some funny now", 35, &bytes); if (pbuff) { pbuff[bytes - 2] = 85; back = peer->ECDHDecrypt (mypubkey, pbuff, bytes, &bytes); if (back) rc += testfailed ("EC: authentication", "HMAC"); else printf ("EC: Authentication fail test passed\n"); delete[] pbuff; } pbuff = me->ECDHEncrypt (peerpubkey, hi, SL_AES_KEY_LEN, &bytes); if (pbuff) { printf ("EC: AES 32 bytes in, %d bytes out\n", (int)bytes); back = peer->ECDHDecrypt (mypubkey, pbuff, bytes, &bytes); if (sequencelogic::MemCmp (back, hi, SL_AES_KEY_LEN) != 0) rc += testfailed ("pkey aes decrypt", (char*)back); else printf ("ECDH encrypt/decrypt of AES key passed\n"); delete[] pbuff; delete[] back; } else rc += testfailed ("pkey encrypt", "Howdy"); pbuff = mypubkey->ECIESEncrypt ((unsigned char*)"Howdy we are having some ecies now", 35, &bytes); back = me->ECIESDecrypt (pbuff, bytes, &bytes); if (!back || strcmp ((char*)back, "Howdy we are having some ecies now") != 0) rc += testfailed ("ECIES encryption failed", (char*)back); else printf ("ECIES me encrypt/decrypt passed - %s\n", (char*)back); delete[] pbuff; delete[] back; pbuff = peerpubkey->ECIESEncrypt ((unsigned char*)"Howdy we are having some ecies fun", 35, &bytes); back = peer->ECIESDecrypt (pbuff, bytes, &bytes); if (!back || strcmp ((char*)back, "Howdy we are having some ecies fun") != 0) rc += testfailed ("ECIES encryption failed", (char*)back); else printf ("ECIES peer encrypt/decrypt passed - %s\n", (char*)back); delete[] pbuff; delete[] back; delete peerpubkey; delete mypubkey; // Test AES key generation, symmetric en/decrypt and public key encrypt/decrypt of that key ring->GenerateAESKey("CloudGuardTGI", "TGI half key"); const Key* aesKey = ring->GetKey ("CloudGuardTGI"); unsigned char iv[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', 'f'}; size_t ebytes = 0; unsigned char* ct = aesKey->SymmetricEncryptBuffer ((unsigned char*)PERMS, strlen (PERMS), &ebytes, iv); unsigned char* pt = aesKey->SymmetricDecryptBuffer (ct, ebytes, &ebytes, iv); if (sequencelogic::MemCmp (pt, PERMS, strlen (PERMS)) != 0) rc += testfailed ("Key::SymmetricEncryptBuffer", "perms"); delete[] ct; delete[] pt; aesKey->SymmetricEncryptFile (testfile, "test/tartest.enc", iv); aesKey->SymmetricDecryptFile ("test/tartest.enc", "test/tartest.dec", iv); if (filecompare (testfile, "test/tartest.dec")) printf ("SymmetricEncryptFile tartest.txt\n"); else rc += testfailed ("Key::SymmetricEncryptFile", testfile); // Test 128 bit key unsigned char b128[16]; sequencelogic::RandomBytes (16, b128); Key aes128 ("AES 128", "CBC", 16, b128, Key::AES); ct = aes128.SymmetricEncryptBuffer ((unsigned char*)PERMS, strlen (PERMS), &ebytes, iv); pt = aes128.SymmetricDecryptBuffer (ct, ebytes, &ebytes, iv); if (sequencelogic::MemCmp (pt, PERMS, ebytes) != 0) rc += testfailed ("Key::SymmetricEncryptBuffer aes128cbc", "perms"); delete[] ct; delete[] pt; // Test Authenticated GCM with and without additional authenticated data unsigned char aad[] = {'a', 'a', 'd', 'd'}; unsigned char abd[] = {'a', 'b', 'd', 'd'}; // No aad ct = aesKey->SymmetricEncryptAuthenticated ((unsigned char*)PERMS, strlen (PERMS), &ebytes, iv); pt = aesKey->SymmetricDecryptAuthenticated (ct, ebytes, &ebytes, iv); if (sequencelogic::MemCmp (pt, PERMS, ebytes) != 0) rc += testfailed ("Key::SymmetricEncryptAuthenticated", ""); delete[] ct; delete[] pt; // With aad ct = aesKey->SymmetricEncryptAuthenticated ((unsigned char*)PERMS, strlen (PERMS), &ebytes, iv, aad, 4); pt = aesKey->SymmetricDecryptAuthenticated (ct, ebytes, &ebytes, iv, aad, 4); if (sequencelogic::MemCmp (pt, PERMS, ebytes) != 0) rc += testfailed ("Key::SymmetricEncryptAuthenticated", "+ aad"); delete[] pt; // With invalid aad pt = aesKey->SymmetricDecryptAuthenticated (ct, ebytes, &ebytes, iv, abd, 4); if (pt) rc += testfailed ("Key::SymmetricEncryptAuthenticated", "bad aad"); delete[] ct; memcpy (aes, ring->GetKey ("CloudGuardTGI")->GetKey(), SL_AES_KEY_LEN); pbuff = publicK->PublicKeyEncrypt (aes, SL_AES_KEY_LEN, &bytes); if (pbuff) { back = privateK->PrivateKeyDecrypt (pbuff, bytes, &bytes); if (sequencelogic::MemCmp (back, aes, SL_AES_KEY_LEN) != 0) rc += testfailed ("pkey aes decrypt", (char*)back); else printf ("TGI half key tests passed\n"); delete[] pbuff; delete[] back; } else rc += testfailed ("pkey encrypt", "Howdy"); delete publicK; //ring->GenerateRSAKey ("Holy", "moly", challenges); ring->Dump(); ring->Lock (goodword); ring->Unlock (goodword); ring->Lock (goodword); unsigned char salt[SL_AES_KEY_LEN]; sequencelogic::GenerateCGKey ("u3K2*l$qZ0a<", aes, salt); if (sequencelogic::ValidateCGKey ("u3K2*l$qZ0a<", aes, salt)) printf ("CG key generate/validate passed\n"); if (sequencelogic::ValidateCGKey ("not good", aes, salt)) rc += testfailed ("CG validate", "not good"); memset (salt, 85, SL_AES_KEY_LEN); if (sequencelogic::ValidateCGKey ("u3K2*l$qZ0a<", aes, salt)) rc += testfailed ("CG validate", "who passed the pepper?"); // Failure tests, bad password if (ring->Unlock (badword)) rc += testfailed ("Keyring::Unlock", badword); if (!ring->Unlock (goodword)) rc += testfailed ("Keyring::Unlock", "after bad"); delete ring; // Create a keyring, add 10000 keys, lock, save, delete, load and find the 4777th key ring = new Keyring ("testring", "Test Key Ring"); char keyname[32]; for (int i = 0; i < 10000; ++i) { sprintf (keyname, "key%d", i); Key* key = new Key (keyname, "one of many", 16, (const unsigned char*) "0123456789abcdef", Key::GENERIC); if (! ring->AddKey (key)) rc += testfailed ("Keyring::AddKey", keyname); } ring->Lock (goodword); ring->SaveAs ("test/thousand.iks"); delete ring; ms = sequencelogic::GetSystemTime(); ring = new Keyring ("test/thousand.iks"); ring->Unlock (goodword); if (! ring->GetKey ("key4777")) rc += testfailed ("Keyring::GetKey", "key4777"); else { ms = sequencelogic::GetSystemTime() - ms; printf ("Loaded 10,000 keys, unlocked and found key4777 in %ld ms\n", ms); } if (! ring->RemoveKey ("key4777")) rc += testfailed ("Keyring::RemoveKey", "key4777"); if (ring->GetNumKeys() != 9999) rc += testfailed ("Keyring::RemoveKey", "9999"); delete ring; // Test linked key rings ring = new Keyring ("testring", "Test Linked Key Rings"); key1 = new Key ("Test", "key", 16, (const unsigned char*) "fedcba9876543210", Key::STRING); key2 = new Key ("Example", "do duplicate", 16, (const unsigned char*) "fedcba9876543210", Key::STRING); ring->AddKey (key1); ring->Lock (goodword); ring->SaveAs ("test/linked.iks"); delete ring; ring = new Keyring ("test/linked.iks"); ring->Unlock (good); Keyring* link1 = new Keyring ("private ring", "Private Key Ring"); Keyring* link2 = new Keyring ("public ring", "Public Key Ring"); link2->AddKey (key2); ring->AddKeyring (link1); ring->AddKeyring (link2); ring->Lock (goodword); ring->SaveAs ("test/linked.iks"); delete ring; ring = new Keyring ("test/linked.iks"); ring->Unlock (goodword); const Keyring* t = ring->GetKeyring ("public ring"); if (!t) rc += testfailed ("GetKeyring", "public ring"); if (t && !t->GetKey ("Example")) rc += testfailed ("GetKeyring()->GetKey()", "Example"); if (!ring->RemoveKeyring ("public ring")) rc += testfailed ("RemoveKeyring", "public ring"); delete ring; int rrc = rc; k = new Key ("test", "Import/Export", "test/private_key.pem", ""); k->Export ("t.pem", ""); if (! filecompare ("t.pem", "test/private_key.pem")) rc += testfailed ("Export", "t.pem"); k->Export ("t.der", ""); if (! filecompare ("t.der", "test/private_key.der")) rc += testfailed ("Export", "t.der"); if (!k->Import ("test/ec_challenge.pem" , "") || k->GetType() != Key::EC) rc += testfailed ("Import", "test/ec_challenge.pem"); if (!k->Import ("test/ec_pub.pem" , "") || k->GetType() != Key::EC_PUBLIC) rc += testfailed ("Import", "test/ec_pub.pem"); if (!k->Import ("test/private_key.pem" , "") || k->GetType() != Key::RSA) rc += testfailed ("Import", "test/private_key.pem"); if (!k->Import ("test/public_key.pem" , "") || k->GetType() != Key::RSA_PUBLIC) rc += testfailed ("Import", "test/public_key.pem"); if (k->Import ("test/test_cert.pem" , "") || k->GetType() != Key::GENERIC) rc += testfailed ("Import", "test/test_cert.pem"); // Verify PEM and JSON loaded keys match Key BOT ("Bot", "RSA key", BOT_public, Key::RSA_PUBLIC); Key JBOT ("jsonBot", "RSA key", BOT_jsonkey, Key::RSA_PUBLIC); EyeJSONObject botJSON (BOT_json); EyeJSONScalar* botpk = (EyeJSONScalar*)botJSON.GetMember ("publicKey"); if (sequencelogic::StrCmp ((char*)BOT.GetKey(), botpk->GetValue()) != 0) rc += testfailed ("{publicKey:", "BOT_json}"); if (!BOT.Equals (JBOT)) rc += testfailed ("JSON String", "BOT_jsonkey"); if (rc == rrc) printf ("Import/Export tests passed\n"); delete k; printf ("Bad keyring tests\n"); ring = new Keyring ((char*)good); delete ring; ring = new Keyring ("test/test.ionu"); delete ring; ring = new Keyring ("test/badmagic.iks"); ring->Unlock (good); if (ring->GetKey ("Test")) rc += testfailed ("GetKey", "bad magic"); delete ring; ring = new Keyring ("test/badiv.iks"); if (ring->Unlock (good)) rc += testfailed ("GetKey", "bad iv"); delete ring; ring = new Keyring ("test/badigest.iks"); if (ring->Unlock (good)) rc += testfailed ("GetKey", "bad digest"); delete ring; ring = new Keyring ("test/munged.iks"); ring->Unlock (good); if (ring->GetKey ("Test")) rc += testfailed ("GetKey", "munged"); delete ring; // Test SQLite based keyring std::string sqlkeyname = "SQLtest"; Key mkey ("Meta", "ring key", SL_AES_KEY_LEN, good, Key::AES); Keyring sqlring ("SQLite", "keys.db", mkey); sqlring.AddKey ("SQLtest", "AES key", SL_AES_KEY_LEN, bad, Key::AES); sqlring.AddKey ("test", "AES key", SL_AES_KEY_LEN, good, Key::AES); cout << sqlring.GetKeyNames() << endl;; cout << sqlring.Stringify (mkey) << endl;; Key tkey; sqlring.GetKey (sqlkeyname, tkey); if (memcmp (tkey.GetKey(), bad, SL_AES_KEY_LEN) != 0) rc += testfailed ("GetKey", "SQLite"); else printf ("SQLite keyring test passed\n"); if (!sqlring.RemoveKey (sqlkeyname)) rc += testfailed ("RemoveKey", "test"); printf ("remove\n"); if (sqlring.GetKey (sqlkeyname, tkey)) rc += testfailed ("GetKey after RemoveKey", "test"); printf ("get\n"); sqlring.Dump(); printf ("dump\n"); if (rc == 0) printf ("C++ Keyring tests passed\n-------------------------------\n"); unsigned char kk[4096]; const char* PEM = "-----BEGIN RSA PRIVATE KEY-----"; char prv[2048]; char pub[2048]; ionu_eyering_gen_rsa_pair (prv, pub); //ionu_eyering_shred ("test/test.iks"); if (!ionu_eyering_create ("test/test.iks", "KeyRIng", "Local key ring", hi)) rc += testfailed ("ionu_eyering_create", "KeyRIng"); else printf ("ionu_eyering_create() KeyRIng passed\n"); if (ionu_eyering_get_key ("test/test.iks", "CloudGuard", kk, hi)) rc += testfailed ("ionu_eyering_get_key", "no keys"); sequencelogic::RandomBytes (32, kk); ionu_eyering_add_binkey ("test/test.iks", "AES", "Random AES key", SL_AES_KEY_LEN, kk, hi); ionu_eyering_add_strkey ("test/test.iks", "Sample", "do not duplicate", "0123456789abcdef", hi); //ionu_eyering_add_tgikey ("test/test.iks", "6a0ce1ec504b", "Cached TGI key", TGIkey, hi); ionu_eyering_add_rsakey ("test/test.iks", "private", "Alan's private key", RSA_private, hi); ionu_eyering_add_strkey ("test/test.iks", "perms", "Just JSON", PERMS, hi); ionu_eyering_gen_rsa ("test/test.iks", "StorageGuard", "RSA keypair", hi); ionu_eyering_gen_rsa ("test/test.iks", "Nikki", "RSA keypair", hi); // Invite ch1, account ch2, provision ch3 ionu_eyering_gen_rsa_secret_challenge ("test/test.iks", "RSA-ch1", "pair", NULL, "secret78", NULL, hi); char* sssalt = ionu_eyering_gen_rsa_secret_salt ("test/test.iks", "RSA-ch2", "pair", "[sequencelogic::json]", "secret78", hi); ionu_eyering_gen_rsa_secret_challenge ("test/test.iks", "RSA-ch3", "pair", "[sequencelogic::json]", NULL, sssalt, hi); char* ch1k = ionu_eyering_get_pubkey ("test/test.iks", "RSA-ch1", hi); char* ch2k = ionu_eyering_get_pubkey ("test/test.iks", "RSA-ch2", hi); char* ch3k = ionu_eyering_get_pubkey ("test/test.iks", "RSA-ch3", hi); if (strcmp (ch1k, ch2k) == 0 && strcmp (ch1k, ch3k) == 0) printf ("C secretly salted challenge key passed\n"); else rc += testfailed ("ionu_eyering_gen_rsa_secret_challenge", "mismatched keys"); if (sssalt) free (sssalt); if (ch1k) free (ch1k); if (ch2k) free (ch2k); if (ch3k) free (ch3k); ionu_eyering_gen_rsa ("test/test.iks", "CloudGuard", "RSA keypair", hi); ionu_eyering_gen_rsa ("test/test.iks", "CloudGuard", "RSA keypair", hi); char* keynames = ionu_eyering_get_keynames ("test/test.iks"); printf ("Added: %s\n", keynames); free (keynames); char* strkey = ionu_eyering_get_strkey ("test/test.iks", "Sample", hi); if (sequencelogic::StrCmp (strkey, "0123456789abcdef") != 0) rc += testfailed ("ionu_eyering_get_strkey", "Sample"); if (strkey) free (strkey); pk = ionu_eyering_get_pubkey ("test/test.iks", "CloudGuard", hi); if (!pk || strncmp (pk, "-----BEGIN PUBLIC KEY", 21) != 0) rc += testfailed ("ionu_eyering_get_pubkey", "CloudGuard"); free (pk); ionu_eyering_get_key ("test/test.iks", "CloudGuard", kk, hi); if (memcmp (kk, "-----BEGIN RSA PRIVATE KEY", 21) != 0) rc += testfailed ("ionu_eyering_get_key", "CloudGuard"); strkey = ionu_eyering_get_strkey ("test/test.iks", "CloudGuard", hi); if (memcmp (strkey, "-----BEGIN RSA PRIVATE KEY", 21) != 0) rc += testfailed ("ionu_eyering_get_strkey", "CloudGuard"); if (strkey) free (strkey); unsigned char rsabuff[256]; size_t rbytes = ionu_eyering_pubkey_encrypt ("test/test.iks", "CloudGuard", hi, bad, SL_AES_KEY_LEN, rsabuff); rbytes = ionu_eyering_privatekey_decrypt ("test/test.iks", "CloudGuard", hi, rsabuff, rbytes, rsabuff); if (rbytes != SL_AES_KEY_LEN || memcmp (bad, rsabuff, SL_AES_KEY_LEN) != 0) rc += testfailed ("ionu_eyering_privatekey_decrypt", "Cloudgaurd"); else printf ("ionu_eyering_pubkey_encrypt/privatekey_decrypt() passed\n"); size_t sbytes = ionu_eyering_privatekey_sign ("test/test.iks", "CloudGuard", hi, bad, SL_AES_KEY_LEN, rsabuff); if (ionu_eyering_publickey_verify ("test/test.iks", "CloudGuard", hi, bad, SL_AES_KEY_LEN, rsabuff, sbytes)) printf ("ionu_eyering sign/verify() passed\n"); else rc += testfailed ("ionu_eyering sign/verify() passed\n", "CloudGuard"); // Old libionu replacements (not secure and misnamed) rbytes = ionu_eyering_rsaprivatekey_encrypt ("test/test.iks", "CloudGuard", hi, bad, SL_AES_KEY_LEN, rsabuff); rbytes = ionu_eyering_rsapublickey_decrypt ("test/test.iks", "CloudGuard", hi, rsabuff, rbytes, rsabuff); if (rbytes != SL_AES_KEY_LEN || memcmp (bad, rsabuff, SL_AES_KEY_LEN) != 0) rc += testfailed ("ionu_eyering_rsapublickey_decrypt", "Cloudgaurd"); else printf ("ionu_eyering_rsaprivatekey_encrypt/ionu_eyering_rsapublickey_decrypt() passed\n"); char public_pem[4096]; char private_pem[8192]; ionu_eyering_create ("test/rsa.iks", "KeyRIng", "RSA key ring", hi); const char* ch = "-----BEGIN PUBLIC KEY-----\n\ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApmPB9KDsrOI1J6jntYbN\n\ Oj9uWUewW+cluNQ0fVCGqoDZ5WLLrz3kpKPlGkI93TraNh2KyyTGDNN0QnCMaOM4\n\ biPfl+z/7xaRTxcYPuoJnBy+a5pCpdLFFUa4qaWPEvF5d5WJesOtvNospEtvlDJJ\n\ EmftOHCCC4NcFxGizcIk4wS/YKlDmjQ0NuJ8bfYP83CqkP8+Pv+QRcdZb5hU1+ov\n\ pOIGfFRjczxkxCTPOqPj6JIhCmxIo93WP7fdKUBFYAnJG2dVCEPmApejJlNzFM7A\n\ otqlseFQ+W1mmpkzcV7sGDb4ej7xhC2YN+u9qMbSxrm1nh4RerXNU7HWD785ScSG\n\ lwIDAQAB\n\ -----END PUBLIC KEY-----"; const char* ch1 = "-----BEGIN PUBLIC KEY-----\n\ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAssBFYAQxvl3UxukRUKSQ\n\ +K/o925SAFeq4EkuGHbDYW3JtGznDBAbTigPgBRkYm5mTZoWFKBjyYRvtPNJCFHe\n\ gAxCmJnqgLELAdsMepBpRqsQQRhlIvCx2G8ppX4BrN+PMZvPMiAyjqL9Pt2ozvob\n\ Hguanc5T++8nx+sJ9S/s7jRZIaR8V3yHmSI0twAaaUKYWRejIXts3i827ObwOGaB\n\ qJSq+bEtMan3QeUUqsnnCZkSfQBHIaRPGFedgxQTGwP2//6efmKI4yY9ODNHd2na\n\ iLMZCLBNQaJZRK4/P7/RZriPzEAjXuQ6mEcIghJtNw7rpVI9GBZB48t8cUK0O8G8\n\ ewIDAQAB\n\ -----END PUBLIC KEY-----"; const char* ch2 = "-----BEGIN PUBLIC KEY-----\n\ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx8yaQrjmL0uUWX+SQxXY\n\ obZXnJlxR6T3tpYyyHCVg11KhzUHY19Rw8NT8bSWR4JDsR/LdML2BR80d4RLxTsy\n\ qi0/LU03y1vKM6y86/4SFoPOyb1VWekq2MWoNmXzUr69I/7vYUIMIKvbZWoUyzYr\n\ ulpsb3J2DzrSvi2nvJ8TTTGe7VSpUC8d+v7hcL1jagRosiHI5fS3ni2V1xg+FBlO\n\ o/BK/IE6Zw8V7o/AjKRE06F5Ve/ou1UNyb9pqLMd1FcMywUPqSSSQkoiQGTknH5O\n\ BEn52fOPy6p1Vf3CIcaSVQeazg6cvACW0+mGkNWtFwHDr6z42sOGHMYxmZA2TAU3\n\ vQIDAQAB\n\ -----END PUBLIC KEY-----"; ionu_eyering_gen_rsa_challenge_pair (challenges, private_pem, public_pem); printf ("%s\n", public_pem); if (memcmp (ch, public_pem, strlen(ch)) != 0) rc += testfailed ("Challenge keygen", challenges); ionu_eyering_gen_rsa_challenge_pair (challenges1, private_pem, public_pem); printf ("%s\n", public_pem); if (memcmp (ch1, public_pem, strlen(ch1)) != 0) rc += testfailed ("Challenge keygen", challenges1); ionu_eyering_gen_rsa_challenge_pair (challenges2, private_pem, public_pem); printf ("%s\n", public_pem); if (memcmp (ch2, public_pem, strlen(ch2)) != 0) rc += testfailed ("Challenge keygen", challenges2); ionu_eyering_add_rsakey ("test/rsa.iks", "public", "key", public_pem, hi); ionu_eyering_add_rsakey ("test/rsa.iks", "private", "key", private_pem, hi); rbytes = ionu_eyering_pubkey_encrypt ("test/rsa.iks", "public", hi, bad, SL_AES_KEY_LEN, rsabuff); rbytes = ionu_eyering_privatekey_decrypt ("test/rsa.iks", "private", hi, rsabuff, rbytes, rsabuff); if (rbytes != SL_AES_KEY_LEN || memcmp (bad, rsabuff, SL_AES_KEY_LEN) != 0) rc += testfailed ("ionu_eyering_privatekey_decrypt", "public+private"); else printf ("ionu_eyering_pubkey_encrypt/privatekey_decrypt() pub+priv passed\n"); /* ionu_eyering_get_key ("test/test.iks", "6a0ce1ec504b", kk, hi); if (memcmp (kk, TGIkey, SL_AES_KEY_LEN) != 0) rc += testfailed ("ionu_eyering_get_key", "TGI key"); else printf ("ionu_eyering_get_key() TGI passed\n"); */ ionu_eyering_get_key ("test/test.iks", "private", kk, hi); if (memcmp (kk, PEM, 6) != 0) rc += testfailed ("ionu_eyering_get_key", PEM); else printf ("ionu_eyering_get_key() RSA passed\n"); ionu_eyering_get_key ("test/test.iks", "perms", kk, bad); if (memcmp (kk, PERMS, strlen(PERMS)) == 0) rc += testfailed ("ionu_eyering_get_key()", "wrong password"); else printf ("ionu_eyering_get_key() wrong password check passed\n"); // change the key ionu_eyering_change_key ("test/test.iks", hi, bad); ionu_eyering_get_key ("test/test.iks", "perms", kk, bad); if (memcmp (kk, PERMS, strlen(PERMS)) != 0) rc += testfailed ("ionu_eyering_get_key()", "after rekey"); else printf ("ionu_eyering_get_key() after rekey check passed\n"); ionu_eyering_change_key ("test/test.iks", bad, hi); /* ionu_eyering_clear_tgi_cache ("test/test.iks", hi); if (ionu_eyering_get_key ("test/test.iks", "TGI", kk, hi)) rc += testfailed ("ionu_eyering_get_key", "should not be any TGI keys left"); else printf ("ionu_eyering_clear_tgi_cache() passed\n"); ionu_eyering_get_key ("test/test.iks", "perms", kk, hi); if (memcmp (kk, PERMS, strlen(PERMS)) != 0) rc += testfailed ("ionu_eyering_get_key", "perms JSON data"); else printf ("ionu_eyering_get_key() JSON data passed\n"); */ ionu_eyering_create ("test/tim.iks", "KeyRIng", "Local key ring", good); ionu_eyering_add_strkey ("test/tim.iks", "keyringConfig", "EyeGlass", JSON, good); ionu_eyering_get_key ("test/tim.iks", "keyringConfig", kk, good); if (memcmp (kk, "{\"van\":{\"_id\":\"urn:sl:000000:::\",\"name\":\"TEST VAN\",\"vanPublic\"", 64) != 0) rc += testfailed ("Huge JSON", (char*)kk); else printf ("Huge JSON test passed\n"); ionu_eyering_add_strkey ("test/tim.iks", "Sample", "do not duplicate", "0123456789abcdef", good); ionu_eyering_add_strkey("test/tim.iks", "foo", "Replace Test", "bar", good); ionu_eyering_get_key ("test/tim.iks", "foo", kk, good); if (memcmp(kk, "bar", 4) != 0){ rc += testfailed ("foobar", (char*)kk); } ionu_eyering_add_strkey("test/tim.iks", "foo", "Replaced bar with newbar", "newbar", good); int len = ionu_eyering_get_key_len ("test/tim.iks", "foo", good); if (len != 7){ rc += testfailed ("eyering_get_key_len", "7"); } ionu_eyering_get_key ("test/tim.iks", "foo", kk, good); if (memcmp(kk, "newbar", 7) != 0){ rc += testfailed ("newbar", (char*)kk); } else { printf ("update key passed\n"); } ionu_eyering_remove_key("test/tim.iks", "foo", good); if (ionu_eyering_get_key ("test/tim.iks", "foo", kk, good)) rc += testfailed ("ionu_eyering_remove_key", "foo"); ionu_eyering_get_key ("test/tim.iks", "Sample", kk, good); if (memcmp(kk, "0123", 4) != 0){ rc += testfailed ("sample", (char*)kk); } ionu_derive_cgkey ("u3K2*l$qZ0a<", kk); sequencelogic::GenerateCGKey ("u3K2*l$qZ0a<", aes, salt); if (ionu_validate_cgkey ("u3K2*l$qZ0a<", (unsigned char*)kk)) printf ("CG key generate/validate passed\n"); else rc += testfailed ("CG validate", "u3K2*l$qZ0a<"); if (ionu_validate_cgkey ("not good", (unsigned char*)kk)) rc += testfailed ("CG validate", "not good"); memset (kk + SL_AES_KEY_LEN, 85, SL_AES_KEY_LEN); if (ionu_validate_cgkey ("u3K2*l$qZ0a<", (unsigned char*)kk)) rc += testfailed ("CG validate", "who passed the pepper?"); // Test the challenge response RSA key generation ionu_eyering_create ("test/challenge.iks", "KeyRing", "Private key ring", good); ionu_eyering_gen_rsa_challenge ("test/challenge.iks", "Unit", "test", challenges, good); char* upk = ionu_eyering_get_pubkey ("test/challenge.iks", "Unit", good); ionu_eyering_gen_rsa_challenge ("test/challenge.iks", "Laramie", "test", challenges1, good); pk = ionu_eyering_get_pubkey ("test/challenge.iks", "Laramie", good); if (sequencelogic::StrCmp (upk, pk) == 0) rc += testfailed ("Laramie", "is not Boulder"); free (pk); ionu_eyering_gen_rsa_challenge ("test/challenge.iks", "Cervelo", "test", challenges2, good); pk = ionu_eyering_get_pubkey ("test/challenge.iks", "Cervelo", good); if (sequencelogic::StrCmp (upk, pk) == 0) rc += testfailed ("Nikki", "is not Cervelo"); free (pk); ionu_eyering_gen_rsa_challenge ("test/challenge.iks", "Unit2", "test", challenges, good); pk = ionu_eyering_get_pubkey ("test/challenge.iks", "Unit2", good); if (sequencelogic::StrCmp (upk, pk) != 0) rc += testfailed ("Challenge", "is not repeated"); free (pk); free (upk); ionu_eyering_gen_rsa_challenge ("test/challenge.iks", "JavaScript", "test to match JS implementation", "IOnU,Bob,Bob,Bob", good); #ifdef JS char hex[512]; rbytes = ionu_eyering_pubkey_encrypt ("test/challenge.iks", "JavaScript", good, (unsigned char*)"TGIkey 32 bytes", 16, rsabuff); sequencelogic::BinaryToHex (rsabuff, rbytes, hex); printf ("%s\n", hex); rbytes = ionu_eyering_pubkey_encrypt ("test/challenge.iks", "JavaScript", good, (unsigned char*)"TGIkey 32 bytes", 16, rsabuff); sequencelogic::BinaryToHex (rsabuff, rbytes, hex); printf ("%s\n", hex); rbytes = ionu_eyering_privatekey_decrypt ("test/challenge.iks", "JavaScript", good, rsabuff, rbytes, rsabuff); printf ("%s\n", (char*)rsabuff); char* mdhex = sequencelogic::DigestMessage ("sha256", (unsigned char*)"IOnU,Bob,Bob,Bob", 16); printf ("%s\n", mdhex); unsigned char hash[32]; sequencelogic::HexToBinary (mdhex, hash); mdhex = sequencelogic::DigestMessage ("sha256", hash, 32); printf ("%s\n", mdhex); #endif // Test EC public key encrypt/decrypt unsigned char ecbuf[2048]; char plain[2048]; ionu_eyering_gen_ec_challenge_pair (challenges, private_pem, public_pem); //printf ("%s\n", private_pem); //printf ("%s\n", public_pem); ionu_eyering_create ("test/ecdh.iks", "KeyRing", "Private key ring", good); if (ionu_eyering_gen_ec_challenge ("test/ecdh.iks", "mine", "Mine", challenges, good)) printf ("Generated EC challenge pair\n"); if (ionu_eyering_gen_ec ("test/ecdh.iks", "peer", "Theirs", good)) printf ("Generated EC random pair\n"); bytes = ionu_eyering_ec_encrypt ("test/ecdh.iks", "mine", "peer", good, (unsigned char*)"Howdy we are having some fune now", 35, ecbuf); //printf ("EC: PK encrypted %d bytes\n", (int)bytes); bytes = ionu_eyering_ec_decrypt ("test/ecdh.iks", "peer", "mine", good, ecbuf, bytes, (unsigned char*)plain); //printf ("EC: PK howdy %d bytes\n", (int)bytes); if (bytes >= 35) { if (strcmp (plain, "Howdy we are having some fune now") != 0) rc += testfailed ("ionu_eyering_ec_decrypt", plain); else printf ("EC: %s, decrypted %d bytes\n", plain, (int)bytes); } else rc += testfailed ("ionu_eyering_ec_encrypt", "Howdy"); if (!ionu_eyering_gen_rsa_challenge ("test/challenge.iks", "Unit3", "test", challenges3, good)) rc += testfailed ("ionu_eyering_gen_rsa_challenge", "Unit3"); if (!ionu_eyering_gen_rsa_challenge ("test/challenge.iks", "Unit4", "test", challenges4, good)) rc += testfailed ("ionu_eyering_gen_rsa_challenge", "Unit4"); if (!ionu_eyering_gen_rsa_challenge ("test/challenge.iks", "Unit5", "test", challenges5, good)) rc += testfailed ("ionu_eyering_gen_rsa_challenge", "Unit5"); if (!ionu_eyering_gen_rsa_challenge ("test/challenge.iks", "Unit6", "test", challenges6, good)) rc += testfailed ("ionu_eyering_gen_rsa_challenge", "Unit6"); if (!ionu_eyering_gen_rsa_challenge ("test/challenge.iks", "Unit7", "test", challenges7, good)) rc += testfailed ("ionu_eyering_gen_rsa_challenge", "Unit7"); if (!ionu_eyering_gen_rsa_challenge ("test/challenge.iks", "Unit8", "test", challenges8, good)) rc += testfailed ("ionu_eyering_gen_rsa_challenge", "Unit8"); if (!ionu_eyering_gen_rsa_challenge ("test/challenge.iks", "Unit9", "test", challenges9, good)) rc += testfailed ("ionu_eyering_gen_rsa_challenge", "Unit9"); if (!ionu_eyering_gen_rsa_challenge ("test/challenge.iks", "Unit10", "test", challenges10, good)) rc += testfailed ("ionu_eyering_gen_rsa_challenge", "Unit10"); if (!ionu_eyering_gen_rsa_challenge ("test/challenge.iks", "Unit11", "test", challenges11, good)) rc += testfailed ("ionu_eyering_gen_rsa_challenge", "Unit11"); if (!ionu_eyering_gen_rsa_challenge ("test/challenge.iks", "Unit12", "test", challenges12, good)) rc += testfailed ("ionu_eyering_gen_rsa_challenge", "Unit12"); if (!ionu_eyering_gen_rsa_challenge ("test/challenge.iks", "too short", "test", shortchallenge, good)) rc += testfailed ("ionu_eyering_gen_rsa_challenge", "too short"); if (!ionu_eyering_gen_rsa_challenge ("test/challenge.iks", "super short", "test", supershortchallenge, good)) rc += testfailed ("ionu_eyering_gen_rsa_challenge", "super short"); rbytes = ionu_eyering_pubkey_encrypt ("test/challenge.iks", "Unit", good, bad, SL_AES_KEY_LEN, rsabuff); rbytes = ionu_eyering_privatekey_decrypt ("test/challenge.iks", "Unit", good, rsabuff, rbytes, rsabuff); if (rbytes != SL_AES_KEY_LEN || memcmp (bad, rsabuff, SL_AES_KEY_LEN) != 0) rc += testfailed ("ionu_eyering_privatekey_decrypt", "Cloudgaurd"); else printf ("challenge pubkey_encrypt/privatekey_decrypt() passed\n"); if (ionu_eyering_get_key ("test/ionu-keyring.iks", "devicePrivate", kk, good)) rc += testfailed ("devicePrivate", (char*)kk); ionu_eyering_create (NULL, "bad", "Bad key tests", NULL); ionu_eyering_create ("/garbonzo-beans/what.iks", "bad", "Bad key tests", hi); ionu_eyering_create ("test/bad.iks", NULL, NULL, hi); ionu_eyering_create ("test/bad.iks", (char*)bad, "Bad key tests", hi); ionu_eyering_create ("test/bad.iks", "bad", (char*)bad, hi); ionu_eyering_create ("test/bad.iks", "bad", "Bad key tests", hi); ionu_eyering_add_binkey ("junkpathtest/test.iks", "AES", "Random AES key", SL_AES_KEY_LEN, kk, hi); ionu_eyering_gen_rsa (empty_iks, "CloudGuard", "RSA keypair", hi); ionu_eyering_add_strkey(empty_iks, "foo", "Replaced bar with newbar", "newbar", hi); ionu_eyering_add_rsakey ("test/bad.iks", "public", "key", NULL, hi); ionu_eyering_add_rsakey ("test/rsa.iks", "private", "key", "---RSA PRIVATE", hi); rbytes = ionu_eyering_pubkey_encrypt ("test/rsa.iks", "public", hi, bad, SL_AES_KEY_LEN, rsabuff); rbytes = ionu_eyering_privatekey_decrypt ("test/rsa.iks", "private", hi, rsabuff, rbytes, rsabuff); if (rbytes == SL_AES_KEY_LEN || memcmp (bad, rsabuff, SL_AES_KEY_LEN) == 0) rc += testfailed ("ionu_eyering_privatekey_decrypt", "bad"); if (rc == 0) printf ("\nKeyring tests passed\n-------------------------------\n"); else printf ("\n%d Keyring tests failed\n-------------------------------\n", rc); return rc; } void IOnUKeyDerive (const char* password) { unsigned char key[SL_AES_KEY_LEN]; char hex[SL_AES_KEY_LEN * 2 + 1]; ionu_derive_key (password, key); sequencelogic::Base64Encode (key, SL_AES_KEY_LEN, hex); printf ("%0.2f <%s> %s\n", ionu_password_strength (password), password, hex); if (strcmp (password, "Hi") == 0 && strcmp (hex, "9Hyf4kupGoPEv3qf6APiiOs29gJEKIbc4DVzylmxmT0=") != 0) printf ("***************** DATA WIPE REQUIRED, PASSWORD KEY DERIVATION CHANGES VALUES *****************\n"); } int IOnUPasswordTests() { int rc = 0; unsigned char userkey[SL_AES_KEY_LEN]; unsigned char cghkey[SL_AES_KEY_LEN*2]; unsigned char tgikey[SL_AES_KEY_LEN]; unsigned char testkey[SL_AES_KEY_LEN]; char hex[SL_AES_KEY_LEN * 2 + 1]; sequencelogic::DeriveKey ("madman12", userkey); const char* cghk = "fwHi1hYx6wMXSQKxRexqu23ngeBM7ccmKwie0ddkAakNLKV/J9NLjYUzZqOFqllm5pFp8GIdsS5/67ewZyUiYw=="; size_t cghkLength = sequencelogic::Base64Decode (cghk, cghkey); if (cghkLength != 2 * SL_AES_KEY_LEN) rc += testfailed ("CGHK: expected 64 bytes\n", "oops"); sequencelogic::XorKeys (userkey, cghkey, tgikey, SL_AES_KEY_LEN); sequencelogic::Base64Encode (tgikey, SL_AES_KEY_LEN, hex); printf ("TGI key: %s\n", hex); sequencelogic::XorKeys (tgikey, cghkey, testkey, SL_AES_KEY_LEN); if (sequencelogic::MemCmp (testkey, userkey, SL_AES_KEY_LEN) != 0) rc += testfailed ("XOR key test", "user"); IOnUKeyDerive ("password"); IOnUKeyDerive ("admin"); IOnUKeyDerive ("qwerty"); IOnUKeyDerive ("H"); IOnUKeyDerive ("Hi"); IOnUKeyDerive ("Hello"); IOnUKeyDerive ("He11o"); IOnUKeyDerive ("H3ll0"); IOnUKeyDerive ("12345678"); IOnUKeyDerive ("123456789"); IOnUKeyDerive ("madman12"); IOnUKeyDerive ("ijfijfijf"); IOnUKeyDerive ("ijfIjfijf*"); IOnUKeyDerive ("@bCd1960"); IOnUKeyDerive ("Abcd1960"); IOnUKeyDerive ("gonefishing1125"); IOnUKeyDerive ("LeeAnn82994"); IOnUKeyDerive ("Lee@nn82994"); IOnUKeyDerive ("GeekBand2013"); IOnUKeyDerive ("u3K2*l"); IOnUKeyDerive ("u3K2*l$"); IOnUKeyDerive ("u3K2*l$q"); IOnUKeyDerive ("u3K2*l$qZ"); IOnUKeyDerive ("u3K2*l$qZ0"); IOnUKeyDerive ("u3K2*l$qZ0a"); IOnUKeyDerive ("u3K2*l$qZ0a<"); IOnUKeyDerive ("areallyveryextrasuperduperhugelylongAndSTOOPIDpassword*l$qZ0aSetStreamSize (sentry, 0); if (IOnU->GetStreamSize (sentry) != 0) rc += testfailed ("SetStreamSize", "expected 0 size"); IOnU->SetStreamSize (sentry, 4096); if (IOnU->GetStreamSize (sentry) != 4096) rc += testfailed ("SetStreamSize", "expected 4096 size"); IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/setsize.ionu", tgi, ios::in); ssize = IOnU->GetStreamSize (sentry); IOnU->ReadStream (sentry, 0, vbuff, 4096, &nread); if (ssize != 4096 || nread != 4096) rc += testfailed ("SetStreamSize", "expected 4096 bytes"); else if (memcmp (zbuff, vbuff, 4096) != 0) rc += testfailed ("SetStreamSize", "expected 4096 0's"); delete IOnU; // Create an alternating pattern of real writes and expansion padding IOnU = new EyeContainer("test/setsize.ionu", tgi, ios::out); for (ssize = 0; ssize < 5*IONU_MEGA_BYTES; ssize += 8192) { IOnU->WriteStream (sentry, ssize, pbuff, 4096, &nread); IOnU->SetStreamSize (sentry, ssize + 8192); } IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/setsize.ionu", tgi, ios::in); ssize = IOnU->GetStreamSize (sentry); if (ssize != IONU_MEGA_BYTES) rc += testfailed ("SetStreamSize", "expected 1MB size"); for (ssize = 0; ssize < IONU_MEGA_BYTES; ssize += 8192) { IOnU->ReadStream (sentry, ssize, vbuff, 4096, &nread); if (nread != 4096 || memcmp (pbuff, vbuff, 4096) != 0) rc += testfailed ("Alternating", "expected 4096 1's"); IOnU->ReadStream (sentry, ssize + 4096, vbuff, 4096, &nread); if (nread != 4096 || memcmp (zbuff, vbuff, 4096) != 0) rc += testfailed ("Alternating", "expected 4096 0's"); } delete IOnU; if (rc == 0) printf ("SetSize tests passed\n"); */ return rc; } int TestStreams() { printf ("\nEyeStream tests\n-------------------------------\n"); int rc = 0; /* #ifdef OBSOLETE size_t n = 0; EyeContainer* IOnU = NULL; char ebuff[4096]; char sbuff[4096]; std::string txtmsg; Key tgi ("tgi", "stream", SL_AES_KEY_LEN, TGIkey, Key::AES); std::streamoff eyebigsize (8*1024*1024); #ifdef LIN64 EyeHeader eyehead; eyehead.SetFileSize (eyebigsize); if (eyehead.GetFileSize() != eyebigsize) { std::stringstream ss; ss << eyebigsize << " != " << eyehead.GetFileSize(); rc += testfailed ("EyeHeader.SetStreamSize ", ss.str()); } #endif IOnU = new EyeContainer("test/stream.ionu", tgi, URN, PERMS); printf ("Created\n"); memset (sbuff, '1', 4096); memset (sbuff, 'a', 64); memset (sbuff+64, 'b', 64); memset (sbuff+128, 'c', 64); memset (sbuff+192, 'd', 64); memset (sbuff+256, 'e', 64); memset (sbuff+320, 'f', 64); memset (sbuff+384, 'g', 64); memset (sbuff+448, 'h', 64); IOnU->AddMemoryFile ("stream", (unsigned char*)sbuff, 512, "test/stream"); IOnU->Finalize(); delete IOnU; printf ("Closed\n"); IOnU = new EyeContainer("test/stream.ionu", tgi, ios::in); printf ("Opened\n"); cout << IOnU->GetMetaData() << endl; delete IOnU; printf ("Closed\n"); EyeStream wty ("test/stream.ionu", tgi, "stream"); printf ("opened as stream\n"); wty.read (ebuff, 512); if (memcmp (sbuff, ebuff, 512) != 0) cout << "Error" << endl; else cout << "Stream read passed" << endl; printf ("read 512\n"); memset (sbuff, 'o', 512); wty.write (16, sbuff, 64, &n); printf ("wrote 64\n"); //wty.write (512, sbuff, 64, &n); wty.close(); printf ("close stream\n"); wty.open ("test/stream.ionu", tgi, "stream"); eyebigsize = 5; wty.read (ebuff, 512); txtmsg.assign ((char*)ebuff, 81); cout << txtmsg << endl; wty.read (eyebigsize, ebuff, 51, &n); txtmsg.assign ((char*)ebuff, 51); cout << txtmsg << endl; wty.read (ebuff, 512); txtmsg.assign ((char*)ebuff, 81); cout << txtmsg << endl; wty.close(); IOnU = new EyeContainer("test/stream.ionu", tgi); txtmsg = IOnU->GetTextMessage ("stream"); if (txtmsg.size() != 512) cout << "Expected 512 got " << txtmsg.size() << endl; else cout << txtmsg << endl; delete IOnU; cout << "TestStreams() - wrote " << n << endl; wty.read (0, ebuff, 81, &n); txtmsg.assign (ebuff, 81); cout << txtmsg << endl; wty.close(); cout << "big stream test" << endl; #define SMALL #ifdef SMALL wty.open ("test/stream.ionu", tgi, "stream"); wty.write (sbuff, 2048); wty.write (sbuff+2048, 2048); wty.close(); #else wty.open ("test/stream.ionu", tgi, "stream"); for (int i = 0; i < 2048*1024; ++i) wty.write (sbuff, 4096); wty.close(); #endif IOnU = new EyeContainer("test/stream.ionu", tgi); txtmsg = IOnU->GetTextMessage ("stream"); if (txtmsg.size() != 4096) cout << "Expected 4096 got " << txtmsg.size() << endl; else cout << "read 4096" << endl; delete IOnU; wty.open ("test/stream.ionu", tgi, "stream"); wty.read (sbuff, 2048); txtmsg.assign (sbuff, 64); cout << txtmsg << endl; wty.read (sbuff, 2048); txtmsg.assign (sbuff, 64); cout << txtmsg << endl; wty.close(); ionu_eyefile_create_with_message ("test/stream.ionu", TGIkey, "stream", "Yo there Alan Frost, what are you up to!", 40, URN, PERMS); EyeStream tty ("test/stream.ionu", tgi, "stream"); tty.read (ebuff, 37); std::string tee (ebuff, 37); std::cout << tee << std::endl; tty.read (4, ebuff, 33, &n); tee.assign (ebuff, n); std::cout << tee << std::endl; tty.read (24, ebuff, 33, &n); tee.assign (ebuff, n); std::cout << tee << std::endl; tty.read (44, ebuff, 33, &n); tee.assign (ebuff, n); std::cout << tee << std::endl; tty.seekg (0); tty.read (ebuff, 13); tee.assign (ebuff, 13); tty.read (ebuff, 13); tee.append (ebuff, 13); tty.read (ebuff, 13); tee.append (ebuff, 13); tty.read (ebuff, 13); //tee.append (ebuff, 13); std::cout << tee << std::endl; printf ("----------------------------------------------\n"); IOnU = new EyeContainer("test/stream.ionu", tgi, URN, PERMS); IOnU->AddMemoryFile ("stream", (unsigned char*)"This stream is 28 bytes long", 28, "test/streaming"); IOnU->Finalize(); delete IOnU; cout << EyeContainer::GetMetaData ("test/stream.ionu", ".ionumeta", tgi) << endl; EyeStream efile ("test/stream.ionu", tgi, URN, PERMS, "stream"); efile.write ("This stream is 28 bytes long", 28); efile.close(); IOnU = new EyeContainer("test/stream.ionu", tgi); cout << IOnU->GetMetaData() << endl; cout << IOnU->GetTextMessage ("stream") << endl; delete IOnU; efile.open ("test/stream.ionu", tgi, URN, PERMS, "stream"); efile.write ("This stream is", 14); efile.write (" 28 bytes long", 14); efile.close(); IOnU = new EyeContainer("test/stream.ionu", tgi); cout << IOnU->GetMetaData() << endl; cout << IOnU->GetTextMessage ("stream") << endl; delete IOnU; //efile.open ("test/stream.ionu", tgi, URN, PERMS, "stream"); efile.open ("test/stream.ionu", tgi, "stream"); efile.write ("This is my stream", 17); efile.write (", this is your stream", 22); efile.close(); IOnU = new EyeContainer("test/stream.ionu", tgi); cout << IOnU->GetMetaData() << endl; cout << IOnU->GetPermissions() << endl; txtmsg = IOnU->GetTextMessage ("stream"); if (txtmsg.size() > 0) cout << "<" << txtmsg << ">" << endl; else printf ("Failed to find stream\n"); delete IOnU; IOnU = new EyeContainer("test/stream.ionu", tgi); cout << IOnU->GetMetaData() << endl; delete IOnU; efile.open ("test/stream.ionu", tgi, "stream"); efile.seekg (19); efile.read (ebuff, 19); std::string ee (ebuff, 19); std::cout << ee << std::endl; efile.read (0, ebuff, 40, &n); cout << "read " << n << " of requested 40 bytes" << endl; strcpy (ebuff, "a garbage stream"); efile.write (8, ebuff, 16, &n); efile.read (10, ebuff, 14, &n); efile.dump(); ee.assign (ebuff, 14); std::cout << ee << std::endl; efile.open ("test/badstream.ionu", tgi, "stream"); if (efile.is_open()) rc += testfailed ("efile.is_open", "test/badstream.ionu"); efile.flush(); efile.close(); efile.open ("test/stream.ionu", tgi, "stream"); efile.setsize (100); cout << efile.getsize() << endl; efile.write ("The stream is larger than this", 30); efile.close(); IOnU = new EyeContainer("test/stream.ionu", tgi); txtmsg = IOnU->GetTextMessage ("stream"); if (txtmsg.size() != 130) cout << "Expected 130 got " << txtmsg.size() << endl; else cout << txtmsg << endl; delete IOnU; efile.open ("test/stream.ionu", tgi, "stream"); efile.write ("The stream is larger than this", 30); efile.setsize (20); cout << efile.getsize() << endl; efile.close(); IOnU = new EyeContainer("test/stream.ionu", tgi); txtmsg = IOnU->GetTextMessage ("stream"); if (txtmsg.size() != 20) cout << "Expected 20 got " << txtmsg.size() << endl; else cout << txtmsg << endl; delete IOnU; efile.open ("test/stream.ionu", tgi, "stream"); efile.setsize (1*1024*1024); efile.write ("This a 2MB stream padded out t", 30); cout << efile.getsize() << endl; efile.close(); efile.open ("test/stream.ionu", tgi, "stream"); cout << efile.getsize() << endl; efile.read (10, ebuff, 14, &n); ee.assign (ebuff, 14); std::cout << ee << std::endl; efile.close(); efile.open ("test/stream.ionu", tgi, "stream"); efile.setsize (65536*2); cout << efile.getsize() << endl; efile.setsize (20); efile.write ("The stream is larger than this", 30); cout << efile.getsize() << endl; efile.rename ("tstream"); efile.close(); IOnU = new EyeContainer("test/stream.ionu", tgi); txtmsg = IOnU->GetTextMessage ("tstream"); if (txtmsg.size() != 30) cout << "Expected 30 got " << txtmsg.size() << endl; else cout << txtmsg << endl; delete IOnU; if (rc == 0) printf ("\nStream tests passed\n-------------------------------\n"); else printf ("\n%d Stream tests failed\n-------------------------------\n", rc); #endif */ return rc; } int TestP2P() { printf ("\nP2P tests\n-------------------------------\n"); int rc = 0; /* size_t bytes = 0; EyeBytes msg; unsigned char* cmd; std::string arg; std::string meta; std::vector args; Keyring ring ("testring", "Test Key Ring"); ring.GenerateRSAKey("Client", "RSA keypair"); ring.GenerateRSAKey("Peer", "RSA keypair"); ring.GenerateRSAKey("CG", "RSA keypair"); char* pk = ring.GetPubKey ("Client"); Key clientpubkey ("client", "public key", (int)strlen(pk), (const unsigned char*) pk, Key::RSA_PUBLIC); delete[] pk; pk = ring.GetPubKey ("Peer"); Key peerpubkey ("peer", "public key", (int)strlen(pk), (const unsigned char*) pk, Key::RSA_PUBLIC); delete[] pk; pk = ring.GetPubKey ("CG"); Key cgpubkey ("CG", "public key", (int)strlen(pk), (const unsigned char*) pk, Key::RSA_PUBLIC); delete[] pk; EyeConnection::MESSAGE_CODE mc; EyeConnection client (URN2, ring.GetKey ("Client"), &peerpubkey); EyeConnection peer (URN1, ring.GetKey ("Peer"), &clientpubkey); EyeConnection cg (URN1, ring.GetKey ("CG"), &clientpubkey); if (! client.ClientHello (msg)) rc += testfailed ("EyeConnection::ClientHello", "uh oh"); cout << "client state " << client.GetState() << endl; //while (client.GetState() != EyePeer::FINISHED && peer.GetState() != EyePeer::FINISHED) { mc = peer.Receive (msg.GetBytes(), msg.GetSize(), msg); cout << mc << " peer state " << peer.GetState() << endl; mc = client.Receive (msg.GetBytes(), msg.GetSize(), msg); cout << mc << " client state " << client.GetState() << endl; //} mc = peer.Receive (msg.GetBytes(), msg.GetSize(), msg); cout << mc << " peer state " << peer.GetState() << endl; // mc = client.Receive (msg.GetBytes(), msg.GetSize(), msg); //cout << "client state " << client.GetState() << endl; cmd = client.Send (EyeConnection::DATA, (const unsigned char*)"P2P test message", 17, &bytes); mc = peer.Receive (cmd, bytes, msg); cout << mc << endl; delete[] cmd; cout << msg.GetString() << endl; client.Dump(); peer.Dump(); cmd = peer.Send (EyeConnection::DATA, (const unsigned char*)"F2F test message", 17, &bytes); mc = client.Receive (cmd, bytes, msg); cout << mc << endl; delete[] cmd; cout << msg.GetString() << endl; arg = "test/*.ionu"; cmd = peer.Command (EyeConnection::LIST, arg, &bytes); mc = client.Receive (cmd, bytes, msg); cout << mc << endl; delete[] cmd; mc = peer.Receive (msg.GetBytes(), msg.GetSize(), msg); cout << mc << endl; meta.assign ((char*)msg.GetBytes(), msg.GetSize()); cout << meta << endl; arg = "test.ionu"; cmd = peer.Command (EyeConnection::GET, arg, &bytes); mc = client.Receive (cmd, bytes, msg); cout << mc << endl; delete[] cmd; mc = peer.Receive (msg.GetBytes(), msg.GetSize(), msg); if (mc != EyeConnection::RETCODE || msg.GetByte(0) == 0) { rc += testfailed ("EyeConnection::GET", arg); cout << mc << endl; } arg = cionu; cmd = peer.Command (EyeConnection::HEAD, arg, &bytes); mc = client.Receive (cmd, bytes, msg); cout << mc << endl; delete[] cmd; mc = peer.Receive (msg.GetBytes(), msg.GetSize(), msg); cout << mc << endl; meta.assign ((char*)msg.GetBytes(), msg.GetSize()); cout << meta << endl; cmd = peer.Command (EyeConnection::GET, arg, &bytes); mc = client.Receive (cmd, bytes, msg); cout << mc << endl; delete[] cmd; mc = peer.Receive (msg.GetBytes(), msg.GetSize(), msg); if (mc != EyeConnection::DATA) { rc += testfailed ("EyeConnection::GET", arg); cout << mc << endl; } args.push_back (cionu); args.push_back ("alan"); args.push_back ("W"); cmd = peer.Command (EyeConnection::LOCK, args, &bytes); mc = client.Receive (cmd, bytes, msg); cout << mc << endl; delete[] cmd; mc = peer.Receive (msg.GetBytes(), msg.GetSize(), msg); if (mc == EyeConnection::RETCODE && msg.GetByte(0) == 0) cout << "Lock succeeded" << endl; args.pop_back (); cmd = peer.Command (EyeConnection::UNLOCK, args, &bytes); mc = client.Receive (cmd, bytes, msg); cout << mc << endl; delete[] cmd; mc = peer.Receive (msg.GetBytes(), msg.GetSize(), msg); if (mc == EyeConnection::RETCODE && msg.GetByte(0) == 0) cout << "Unlock succeeded" << endl; cmd = peer.Send (EyeConnection::SUSPEND, (const unsigned char*)"suspend", 7, &bytes); mc = client.Receive (cmd, bytes, msg); if (mc == EyeConnection::SUSPEND) cout << "Client suspended" << endl; delete[] cmd; mc = peer.Receive (msg.GetBytes(), msg.GetSize(), msg); if (mc == EyeConnection::RETCODE && msg.GetByte(0) == 0) cout << "Suspend succeeded" << endl; cmd = peer.Send (EyeConnection::RESUME, (const unsigned char*)"suspend", 7, &bytes); mc = client.Receive (cmd, bytes, msg); cout << mc << endl; delete[] cmd; mc = peer.Receive (msg.GetBytes(), msg.GetSize(), msg); if (mc == EyeConnection::RETCODE && msg.GetByte(0) == 0) cout << "Resume succeeded" << endl; client.Dump(); peer.Dump(); if (rc == 0) printf ("\nP2P tests passed\n-------------------------------\n"); else printf ("\n%d P2P tests failed\n-------------------------------\n", rc); */ return rc; } int TestMixedUpKeys() { printf ("\nMixed up key tests\n-------------------------------\n"); int rc = 0; /* std::string sentry ("stream"); size_t written = 0; std::string sb; char sbuffer[1024]; Key junk; EyeContainer* mixup = new EyeContainer("test/mixup.ionu", TGIkey, URN, PERMS); std::streamoff spos = 0; mixup->WriteStream (sentry, spos, "This is a streaming video test s", 32, &written); spos = 32; mixup->WriteStream (sentry, spos, "tream not really", 16, &written); mixup->Finalize(); delete mixup; cout << EyeContainer::GetContentMetaData ("test/mixup.ionu", "stream", junk) << endl; mixup = new EyeContainer("test/mixup.ionu", TGIkey); spos = 0; mixup->ReadStream (sentry, spos, sbuffer, 48, &written); sb.assign (sbuffer, written); delete mixup; if (written != 48 && sb.compare ("This is a streaming video test stream not really") != 0) rc += testfailed ("Mixup readstream ios::in", sb); mixup = new EyeContainer("test/mixup.ionu", TGIkey, ios::in); spos = 0; mixup->ReadStream (sentry, spos, sbuffer, 48, &written); sb.assign (sbuffer, written); delete mixup; if (written != 48 && sb.compare ("This is a streaming video test stream not really") != 0) rc += testfailed ("Mixup readstream ios::in", sb); mixup = new EyeContainer("test/mixup.ionu", badkey); spos = 0; mixup->WriteStream (sentry, spos, "trash", 5, &written); mixup->Finalize(); delete mixup; if (written != 0) rc += testfailed ("Mixup writestream", "trash"); mixup = new EyeContainer("test/mixup.ionu", badkey); spos = 32; mixup->WriteStream (sentry, spos, "tream yes it is!", 16, &written); mixup->Finalize(); delete mixup; if (written != 0) rc += testfailed ("Mixup writestream", "tream yes it is!"); mixup = new EyeContainer("test/mixup.ionu", TGIkey); spos = 0; mixup->ReadStream (sentry, spos, sbuffer, 48, &written); sb.assign (sbuffer, written); delete mixup; if (written != 48 && sb.compare ("This is a streaming video test stream not really") != 0) rc += testfailed ("Mixup readstream after bad writes", sb); spos = 0; mixup = new EyeContainer("test/mixup.ionu", badkey); mixup->ReadStream (sentry, spos, sbuffer, 48, &written); sb.assign (sbuffer, written); delete mixup; if (written != 0) rc += testfailed ("Mixup readstream with bad key", sb); mixup = new EyeContainer("test/mixup.ionu", badkey); unsigned char* ex = mixup->ExtractMemoryFile (sentry, &written); delete mixup; if (ex || written > 0) rc += testfailed ("ExtractMemoryFile()", sentry); mixup = new EyeContainer("test/mixup.ionu", badkey, ios::in); ex = mixup->ExtractMemoryFile (sentry, &written); delete mixup; if (ex || written > 0) rc += testfailed ("ExtractMemoryFile() ios::in", sentry); if (rc == 0) printf ("\nMixed up key tests passed\n-------------------------------\n"); else printf ("\n%d Mixed up key tests failed\n-------------------------------\n", rc); */ return rc; } int TestEyeContainer() { int rc = 0; /* struct stat stat_buf; char* coldmeta = NULL; char* cmeta = NULL; char* cmsg = NULL; std::string txtmsg; std::string msg; EyeBytes currency (utf8, 6); EyeBytes utfmsg; EyeContainer* IOnU = NULL; const std::string tags = "{\"title\":\"Encrypted World\",\"description\":\"The world is now encrypted\"}"; const std::string tags1 = "{\"title\":\"Parade of Fans\",\"description\":\"NEWARK - The guest list and the parade of limousines...\"}"; const std::string tags2 = "{\"title\":\"D-Link Patches Router\",\"description\":\"D-Link has taken action over three serious...\"}"; std::string realsig = sequencelogic::GenerateTGISig (TopicPerms); unsigned char tgi64[64]; memcpy (tgi64, TGIkey, 32); memset (tgi64+32, 85, 32); Key tkey (realsig.c_str(), "key", 64, tgi64, Key::TGI); Key mkey (realsig.c_str(), "key", 32, tgi64+32, Key::AES); //SSL_load_error_strings(); /* readable error messages * / //SSL_library_init(); /* initialize library * / // Test the C++ interfaces printf ("\nTestin C++ interfaces\n-------------------------------\n"); IOnU = new EyeContainer("test/nocontent.ionu", TGIkey, URN, TopicPerms); IOnU->Finalize(); delete IOnU; cout << EyeContainer::GetMetaData ("test/nocontent.ionu", IONU_EYE_META_FILE, mkey) << endl; cout << EyeContainer::GetMetaData ("test/nocontent.ionu", IONU_EYE_PERM_FILE, mkey) << endl; cout << EyeContainer::GetContentMetaData ("test/nocontent.ionu", ".imchat", mkey) << endl; cout << EyeContainer::GetContentMetaData ("test/nocontent.ionu", "", mkey) << endl; IOnU = new EyeContainer("test/test.ionu", TGIkey, URN, TopicPerms); IOnU->AddContent ("test/Screen Shot 2013-04-18 at 1.14.42 PM.png", "image/png"); IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/test.ionu", TGIkey); if (!IOnU->ExtractFile ("Screen Shot 2013-04-18 at 1.14.42 PM.png")) rc += testfailed ("ExtractFile", "Screen Shot 2013-04-18 at 1.14.42 PM.png"); if (!filecompare ("test/Screen Shot 2013-04-18 at 1.14.42 PM.png", "Screen Shot 2013-04-18 at 1.14.42 PM.png")) rc += testfailed ("File compare", "Screen Shot 2013-04-18 at 1.14.42 PM.png"); delete IOnU; sequencelogic::RemoveFile ("Screen Shot 2013-04-18 at 1.14.42 PM.png"); IOnU = new EyeContainer("test/test.ionu", TGIkey, URN, TopicPerms); IOnU->AddContent ("test/Disruptor-1.0.pdf", "application/pdf"); IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/test.ionu", TGIkey); if (!IOnU->ExtractFile ("Disruptor-1.0.pdf")) rc += testfailed ("ExtractFile", "Disruptor-1.0.pdf"); if (!filecompare ("test/Disruptor-1.0.pdf", "Disruptor-1.0.pdf")) rc += testfailed ("File compare", "Disruptor-1.0.pdf"); delete IOnU; sequencelogic::RemoveFile ("Disruptor-1.0.pdf"); IOnU = new EyeContainer("test/test.ionu", TGIkey, URN, TopicPerms); IOnU->AddContent ("test/photo.jpg", "image/jpeg"); IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/test.ionu", TGIkey); if (!IOnU->ExtractFile ("photo.jpg")) rc += testfailed ("ExtractFile", "photo.jpg"); if (!filecompare ("test/photo.jpg", "photo.jpg")) rc += testfailed ("File compare", "photo.jpg"); delete IOnU; sequencelogic::RemoveFile ("photo.jpg"); IOnU = new EyeContainer("test/test.ionu", TGIkey, URN, TopicPerms); IOnU->AddContent ("test/Nikki-Temp.jpg", "image/jpeg"); IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/test.ionu", TGIkey); if (!IOnU->ExtractFile ("Nikki-Temp.jpg")) rc += testfailed ("ExtractFile", "Nikki-Temp.jpg"); if (!filecompare ("test/Nikki-Temp.jpg", "Nikki-Temp.jpg")) rc += testfailed ("File compare", "Nikki-Temp.jpg"); delete IOnU; sequencelogic::RemoveFile ("Nikki-Temp.jpg"); IOnU = new EyeContainer("test/test.ionu", TGIkey, URN, TopicPerms); IOnU->AddContent ("test/End User License Agreement.rtf", "text/rtf"); IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/test.ionu", TGIkey); if (!IOnU->ExtractFile ("End User License Agreement.rtf")) rc += testfailed ("ExtractFile", "End User License Agreement.rtf"); if (!filecompare ("test/End User License Agreement.rtf", "End User License Agreement.rtf")) rc += testfailed ("File compare", "End User License Agreement.rtf"); delete IOnU; sequencelogic::RemoveFile ("End User License Agreement.rtf"); IOnU = new EyeContainer("test/test.ionu", TGIkey, URN, TopicPerms); IOnU->AddContent ("test/TestWordDoc2.docx", "application/vnd.ms-word"); IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/test.ionu", TGIkey); if (!IOnU->ExtractFile ("TestWordDoc2.docx")) rc += testfailed ("ExtractFile", "TestWordDoc2.docx"); if (!filecompare ("test/TestWordDoc2.docx", "TestWordDoc2.docx")) rc += testfailed ("File compare", "TestWordDoc2.docx"); delete IOnU; sequencelogic::RemoveFile ("TestWordDoc2.docx"); IOnU = new EyeContainer("test/test.ionu", tkey, URN, TopicPerms); IOnU->AddTextMessage (".imchat", "A long and verbose yo there to you from me type chat message to test various stuff with"); IOnU->AddTags (tags); IOnU->AddContent(testfile, "test/plaintext"); cout << "LastModifiedTimeOfEntry() " << IOnU->LastModifiedTimeOfEntry (".imchat") << endl; cout << "MIMETypeOfEntry() " << IOnU->MIMETypeOfEntry (".imchat") << endl; cout << "SizeOfEntry(.imchat) " << IOnU->SizeOfEntry (".imchat") << endl; cout << "SizeOfEntry(tartest.txt) " << IOnU->SizeOfEntry ("tartest.txt") << endl; cout << "SizeOfEntry(bad) " << IOnU->SizeOfEntry ("bad") << endl; IOnU->Finalize(); delete IOnU; // Corrupt .ionu files ifstream ifile ("test/test.ionu", ios::in | ios::binary | ios::ate); if (ifile.is_open()) { size_t bytes = (size_t)ifile.tellg(); ifile.seekg (0, ios::beg); char* big = new char[bytes]; ifile.read (big, bytes); ifile.close(); for (size_t i = 0; i < bytes; i += 179) { char pb = big[i]; ofstream rfile ("rand.ionu", ios::out | ios::binary | ios::trunc); big[i] = 85; rfile.write (big, bytes); rfile.close(); //EyeContainer::GetStatus ("rand.ionu"); big[i] = pb; IOnU = new EyeContainer("rand.ionu", TGIkey); //txtmsg = IOnU->GetMetaData (); txtmsg = IOnU->GetTextMessage (".imchat"); if (txtmsg.size() > 0) rc += testfailed ("Corruption", txtmsg); delete IOnU; } delete[] big; } if (rc == 0) printf ("Corruption tests passed\n"); cout << EyeContainer::GetMetaData ("test/test.ionu", IONU_EYE_META_FILE, mkey) << endl; cout << EyeContainer::GetContentMetaData ("test/test.ionu", ".imchat", mkey) << endl; cout << EyeContainer::GetContentMetaData ("test/test.ionu", "", mkey) << endl; IOnU = new EyeContainer("test/test.ionu", tkey); cout << IOnU->GetMetaData() << endl; cout << IOnU->GetPermissions() << endl; txtmsg = IOnU->GetTextMessage (".imchat"); if (txtmsg.size() > 0) cout << "<" << txtmsg << ">" << endl; else rc += testfailed ("Can't find", ".imchat"); cout << IOnU->GetContentFileObjects() << endl; cout << IOnU->GetContentFilenames() << endl; IOnU->ListFiles(); std::string gtags = IOnU->GetTags(); if (gtags == tags) cout << "Tags: " << gtags << endl; else rc += testfailed ("Can't find tags", gtags); IOnU->ShredContents (shredurn); delete IOnU; std::string shredded = EyeContainer::GetMetaData ("test/test.ionu", IONU_EYE_META_FILE, mkey); if (shredded.find ("deleted") == string::npos) rc += testfailed ("ShredContents status not set to deleted - static", "test/test.ionu"); cout << shredded << endl; IOnU = new EyeContainer("test/test.ionu", tkey); shredded = IOnU->GetContentFilenames(); if (shredded.compare ("[]") != 0) rc += testfailed ("ShredContents content array not empty", "test/test.ionu"); shredded = IOnU->GetMetaData(); if (shredded.find ("deleted") == string::npos) rc += testfailed ("ShredContents status not set to deleted", "test/test.ionu"); shredded = IOnU->GetPermissions(); if (shredded.compare (TopicPerms) != 0) rc += testfailed ("ShredContents perms messed up", "test/test.ionu"); IOnU->ShredContents (shredurn); delete IOnU; IOnU = new EyeContainer("test/test.ionu", TGIkey, URN, PERMS); IOnU->AddTextMessage (".imchat", "Hi"); Key bkey ("Meta", "key", SL_AES_KEY_LEN, badkey, Key::AES); Key gkey; Key rkey ("Meta", "RSA", (int)strlen(RSA_private), (const unsigned char*)RSA_private, Key::RSA); IOnU->AddMetaData (".ionuhistory", "This is the history", mkey); IOnU->AddMetaData (".ionutags", "history,middle,kingdom", gkey); IOnU->AddMetaData (".private", "RSA encrypted private data", rkey); IOnU->AddTextMessage (".imchat", "Hi"); size_t siglen = 0; unsigned char* sig = rkey.PrivateKeySign ((unsigned char*)"Hi", 2, &siglen); std::string signature ((char*)sig, siglen); IOnU->AddMetaData (".signature", signature, gkey); delete[] sig; std::cout << IOnU->GetMetaData (".ionuhistory", mkey) << std::endl; std::cout << IOnU->GetMetaData (".ionuhistory", bkey) << std::endl; std::cout << IOnU->GetMetaData (".ionutags", gkey) << std::endl; std::cout << IOnU->GetMetaData (".private", rkey) << std::endl; signature = IOnU->GetMetaData (".signature", gkey); std::cout << rkey.PublicKeyVerify ((unsigned char*)signature.data(), signature.size(), (unsigned char*)"Hi", 2) << std::endl; delete IOnU; //exit (1); IOnU = new EyeContainer("test/test.ionu", TGIkey, URN, PERMS); IOnU->AddTextMessage (".imchat", "Hi there from someone who is not who you think"); //IOnU->AddContent ("test/test.jpeg", NULL); IOnU->Finalize(); std::string metadata = IOnU->GetMetaData(); std::string spoof = metadata; size_t pos = spoof.find ("FFFFFFFFFFFF"); spoof.replace (pos, 12, "FFFFFFFFFFF7"); cout << spoof << endl; IOnU->ReplaceMetaData (spoof.c_str()); IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/test.ionu", TGIkey); txtmsg = IOnU->GetTextMessage (".imchat"); if (txtmsg.size() > 0) rc += testfailed ("Spoof", txtmsg); if (IOnU->ReplaceMetaData (tgiMeta)) rc += testfailed ("ReplaceMetaData()", "mismatching tgi keys"); delete IOnU; IOnU = new EyeContainer("test/test.ionu", TGIkey, URN, PERMS); IOnU->AddContent(testfile, "test/plain"); IOnU->Finalize(); metadata = IOnU->GetMetaData(); if (metadata.size() > 0) cout << metadata << endl; else rc += testfailed ("GetMetaData", testfile); delete IOnU; IOnU = new EyeContainer ("test/test.ionu", TGIkey); if (IOnU->ExtractFile (testfile) && filecompare (testfile, testfile_orig)) printf ("Extracted tartest.txt\n"); else rc += testfailed ("Extract", testfile); delete IOnU; //IOnU = new EyeContainer("test/7E303527-9996-462C-BAAC-D39BADCA377E.ionu", TGIkey); IOnU = new EyeContainer("test/test.ionu", TGIkey); IOnU->ListFiles(); metadata = IOnU->GetMetaData(); if (metadata.size() > 0) cout << metadata << endl; else rc += testfailed ("GetMetaData", testfile); EyeContainer* merge = new EyeContainer ("test/test.ionu", TGIkey, URN, PERMS); merge->AddContent (testfile, "test/plain"); merge->AddTextMessage ("Merger", "mergers and acquisitions are my specialty"); IOnU->MergeContent (merge); delete merge; IOnU->AddTextMessage ("Thread", "Hello, is anyone out there?"); IOnU->AddTextMessage ("Currency Symbols", currency, "text/plain;charset=utf-8"); IOnU->AddTextMessage ("Last", "The last word"); bool found = IOnU->GetTextMessage ("Thread", utfmsg); if (found) printf ("%s\n", utfmsg.GetString()); else rc += testfailed ("GetTextMessage", "Thread"); found = IOnU->GetTextMessage ("Merger", utfmsg); if (found) printf ("%s\n", utfmsg.GetString()); else rc += testfailed ("GetTextMessage", "Merger"); utfmsg.Assign ("UTF-8 encoded string"); IOnU->AddTextMessage ("Thread", "Nobody here but us chickens"); IOnU->AddTextMessage ("UTFThread", utfmsg, "text/plain;charset=utf-8"); found = IOnU->GetTextMessage ("Thread", utfmsg); if (found) printf ("%s\n", utfmsg.GetString()); else rc += testfailed ("GetTextMessage", "Chicken Thread"); IOnU->Finalize(); delete IOnU; if (rc == 0) printf ("so far passed\n"); IOnU = new EyeContainer("test/test.ionu", TGIkey); IOnU->ListFiles(); metadata = IOnU->GetMetaData(); if (metadata.size() > 0) cout << metadata << endl; else rc += testfailed ("GetMetaData", testfile); IOnU->UpdateMetaData (updateMeta); metadata = IOnU->GetMetaData(); if (metadata.size() > 0) cout << metadata << endl; else rc += testfailed ("UpdateMetaData", testfile); found = IOnU->GetTextMessage ("Thread", utfmsg); if (found) printf ("%s\n", utfmsg.GetString()); else rc += testfailed ("GetTextMessage", "Thread"); found = IOnU->GetTextMessage ("UTFThread", utfmsg); if (found) printf ("%s\n", utfmsg.GetString()); else rc += testfailed ("GetTextMessage", "UTFThread"); found = IOnU->GetTextMessage ("Currency Symbols", utfmsg); if (!found || !currency.Equals (utfmsg)) rc += testfailed ("GetTextMessage", "Currency"); // Change the TGI key and try both old and new TGI keys Key bbkey ("Bad", "key", SL_AES_KEY_LEN, badkey, Key::TGI); Key ggkey ("Good", "key", SL_AES_KEY_LEN, TGIkey, Key::TGI); IOnU->ReKey (bbkey); msg = IOnU->GetTextMessage ("Thread"); if (msg.compare ("Nobody here but us chickens") != 0) rc += testfailed ("ReKey - memory", testfile); IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/test.ionu", TGIkey); txtmsg = IOnU->GetTextMessage ("Thread"); if (txtmsg.size() > 1 && txtmsg[0] == 'N' && txtmsg[1] == 'o') rc += testfailed ("ReKey - old key", txtmsg); delete IOnU; IOnU = new EyeContainer("test/test.ionu", badkey); msg = IOnU->GetTextMessage ("Thread"); if (msg.compare ("Nobody here but us chickens") != 0) rc += testfailed ("ReKey - new key", testfile); std::string oldmeta = IOnU->GetMetaData(); // Rekey and update permissions, which should change TGIsig in meta IOnU->ReKey (ggkey, PERMS2); metadata = IOnU->GetMetaData(); if (metadata.compare (oldmeta) == 0) rc += testfailed ("ReKey - new perms, TGIsig", testfile); msg = IOnU->GetTextMessage ("Thread"); if (msg.compare ("Nobody here but us chickens") != 0) rc += testfailed ("ReKey - new key and perms", testfile); IOnU->Finalize(); delete IOnU; metadata = EyeContainer::GetPermissionsClassic ("test/test.ionu"); if (metadata.compare (PERMS2) != 0 ) rc += testfailed ("ReKey", PERMS2); if (rc == 0) printf ("Rekey tests passed\n"); if (!IOnU->Shred ("test/test.ionu")) rc += testfailed ("Shred", testfile); if (rc == 0) printf ("so far passed\n"); if (stat("test/test.ionu", &stat_buf) != 0) printf ("Shred passed\n"); else rc += testfailed ("Shred", testfile); // Message with attachments and thumbnail IOnU = new EyeContainer("test/test.ionu", TGIkey, URN, PERMS); IOnU->AddTextMessage ("Message", "See attached coding guidlines, html, and xml"); if (!IOnU->AddContent (attachfile, "")) rc += testfailed ("AddContent", attachfile); if (!IOnU->AddContent (htmlfile, "text/html;charset=utf-8")) rc += testfailed ("AddContent", htmlfile); if (!IOnU->AddMetaData (".ionuhistory", operationsMeta)) rc += testfailed ("AddContent", ".ionuhistory"); if (!IOnU->AddContent ("style.xsd", xmlfile, "")) rc += testfailed ("AddContent", "style.xsd"); if (!IOnU->AddContent (xmlfile, "")) rc += testfailed ("AddContent", xmlfile); if (!IOnU->AddContent (jsonfile, "application/json")) rc += testfailed ("AddContent", jsonfile); if (IOnU->AddContent (njsonfile, "")) // This file does not exist rc += testfailed ("AddContent", njsonfile); if (!IOnU->AddThumbnail (thumbfile, "")) rc += testfailed ("AddThumbnail", thumbfile); IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/test.ionu", TGIkey); if (!IOnU->HasContent (xmlfile)) rc += testfailed ("HasContent", xmlfile); IOnU->ListFiles(); std::string cf = IOnU->GetContentFilenames(); if (cf.size() > 4) cout << cf << endl; else rc += testfailed ("GetContentFilenames", testfile); cf = IOnU->GetContentFileObjects(); if (cf.size() > 4) cout << cf << endl; else rc += testfailed ("GetContentFileObjects", testfile); metadata = IOnU->GetMetaData(); if (metadata.size() > 0) cout << metadata << endl; else rc += testfailed ("GetMetaData", testfile); txtmsg = IOnU->GetTextMessage ("Message"); if (txtmsg.size() > 0) cout << txtmsg << endl; else rc += testfailed ("GetTextMessage", "Message"); metadata = IOnU->GetPermissions(); if (metadata.size() > 0) cout << metadata << endl; else rc += testfailed ("GetPermissions", testfile); IOnU->UpdatePermissions ("{\"read\":[\"me\",\"you\"],\"write\":[\"me\",\"you\"]}"); metadata = IOnU->GetPermissions(); if (metadata.size() > 0) cout << metadata << endl; else rc += testfailed ("GetPermissions", testfile); IOnU->UpdatePermissions ("{\"read\":[\"me\"]}"); metadata = IOnU->GetPermissions(); if (metadata.size() > 0) cout << metadata << endl; else rc += testfailed ("GetPermissions", testfile); IOnU->UpdatePermissions ("{\"read\":[\"+george\"], \"write\":[\"+george\"]}"); metadata = IOnU->GetPermissions(); if (metadata.size() > 0) cout << metadata << endl; else rc += testfailed ("GetPermissions", testfile); IOnU->UpdatePermissions ("{\"read\":[\"-george\"]}"); metadata = IOnU->GetPermissions(); if (metadata.size() > 0) cout << metadata << endl; else rc += testfailed ("GetPermissions", testfile); IOnU->UpdateMetaData ("{\"msg\":{\"drr\":true}}"); metadata = IOnU->GetMetaData(); if (metadata.size() > 0) cout << metadata << endl; else rc += testfailed ("UpdateMetaData", testfile); // Get HTML file contents as a message txtmsg = IOnU->GetTextMessage ("test.html"); if (txtmsg.size() > 1 && txtmsg.compare (0, 14, "", 14) == 0) printf ("HTML message passed\n"); else rc += testfailed ("GetTextMessage", ""); if (!IOnU->RemoveEntry (xmlfile)) rc += testfailed ("RemoveEntry", xmlfile); IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/test.ionu", TGIkey); IOnU->ListFiles(); metadata = IOnU->GetMetaData(); if (metadata.size() > 0) cout << metadata << endl; if (!IOnU->ExtractFile ("style.xsd", "test/extracted.xsd")) rc += testfailed ("ExtractFile", "style.xsd"); delete IOnU; // Create a large archive IOnU = new EyeContainer("test/bigtest.ionu", TGIkey, URN, PERMS); IOnU->AddTextMessage ("test/Message", "Holy crap Batman there are a lot of files in here, and there are no problems with that"); char message[64]; //for (int i = 0; i < 1000; ++i) { // Verified with 1,000, but just use 10 for regular test runs for (int i = 0; i < 10; ++i) { sprintf (message, "test/Message%d", i); IOnU->AddTextMessage (message, "I'm a robot and I love to chat with other bots"); } if (!IOnU->RenameFile ("test/Message4", "test/renamed")) rc += testfailed ("RenameFile()", "r/o"); IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/tags1.ionu", TGIkey, URN, TopicPerms); IOnU->AddTextMessage (".imchat", "A long and verbose yo there to you from me type chat message to test various stuff with"); IOnU->AddTags (tags1); IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/tags2.ionu", TGIkey, URN, TopicPerms); IOnU->AddTextMessage (".imchat", "A long and verbose yo there to you from me type chat message to test various stuff with"); IOnU->AddTags (tags2); IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/tags1.ionu", TGIkey, ios::in); gtags = IOnU->GetTags(); cout << gtags << endl; delete IOnU; IOnU = new EyeContainer("test/tags2.ionu", TGIkey, ios::in); gtags = IOnU->GetTags(); cout << gtags << endl; delete IOnU; if (rc == 0) printf ("so far passed\n"); // Test readonly EyeContainer printf ("Readonly tests ----------------\n"); size_t nwritten = 0; std::string sb; std::string sentry ("test/Message"); std::streamoff spos = 0; std::streamoff ssize = 0; char sbuffer[1024]; IOnU = new EyeContainer("test/bigtest.ionu", ggkey, ios::in); IOnU->ListFiles(); IOnU->ExtractFiles(); metadata = IOnU->GetMetaData(); if (metadata.size() < 50) rc += testfailed ("GetMetaData", "r/o"); cout << metadata << endl; metadata = IOnU->GetPermissions(); if (metadata.size() < 50) rc += testfailed ("GetPermissions", "r/o"); metadata = IOnU->GetMetaData(".ionumeta"); if (metadata.size() < 50) rc += testfailed ("GetMetaData(.ionumeta)", "r/o"); metadata = IOnU->GetMetaData(".ionuperm"); if (metadata.size() < 50) rc += testfailed ("GetMetaData(.ionuperm)", "r/o"); metadata = IOnU->GetContentFilenames(); if (metadata.size() < 50) rc += testfailed ("GetContentFilenames()", "r/o"); metadata = IOnU->GetContentFileObjects(); if (metadata.size() < 50) rc += testfailed ("GetContentFileObjects()", "r/o"); if (!IOnU->HasEntry (sentry, &ssize)) rc += testfailed ("GetContentMetaData()", "r/o"); else cout << "found " << sentry << " " << ssize << endl; if (IOnU->GetFileSize ("test/Message3") != 46) rc += testfailed ("GetFileSize()", "r/o"); metadata = IOnU->GetTextMessage (sentry); if (metadata.compare (0, 9, "Holy crap", 9) != 0) rc += testfailed ("GetTextMessage()", "r/o"); if (!IOnU->ExtractFile (sentry, sentry)) rc += testfailed ("ExtractFile()", "r/o"); spos = 0; IOnU->ReadStream (sentry, spos, sbuffer, 35, &nwritten); sb.assign (sbuffer, nwritten); cout << sb << endl; spos += nwritten; IOnU->ReadStream (sentry, spos, sbuffer, 32, &nwritten); sb.assign (sbuffer, nwritten); cout << sb << endl; spos += nwritten; IOnU->ReadStream (sentry, spos, sbuffer, 32, &nwritten); sb.assign (sbuffer, nwritten); cout << sb << endl; spos = 7; IOnU->ReadStream (sentry, spos, sbuffer, 32, &nwritten); sb.assign (sbuffer, nwritten); cout << sb << endl; if (metadata.compare (0, 9, "Holy crap", 9) != 0) rc += testfailed ("GetTextMessage()", "r/o"); delete IOnU; //exit(1); // Test EyeContainer stream interfaces if (rc == 0) printf ("so far passed\n"); printf ("Stream interface tests ----------------\n"); sentry = "stream"; IOnU = new EyeContainer("test/streamtest.ionu", TGIkey, URN, PERMS); spos = 0; IOnU->WriteStream (sentry, spos, "This is a streaming video test s", 32, &nwritten); spos = 32; IOnU->WriteStream (sentry, spos, "tream not really", 16, &nwritten); IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/streamtest.ionu", TGIkey); unsigned char* ex = IOnU->ExtractMemoryFile (sentry, &nwritten); if (ex) { sb.assign ((char*)ex, nwritten); cout << sb << endl; delete[] ex; } else rc += testfailed ("ExtractMemoryFile()", sentry); spos = 0; IOnU->ReadStream (sentry, spos, sbuffer, 48, &nwritten); sb.assign (sbuffer, 48); cout << sb << endl; spos = 32; IOnU->WriteStream (sentry, spos, "tream yes it is!", 16, &nwritten); IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/streamtest.ionu", TGIkey); IOnU->ListFiles(); metadata = IOnU->GetMetaData(); cout << metadata << endl; spos = 0; IOnU->ReadStream (sentry, spos, sbuffer, 48, &nwritten); sb.assign (sbuffer, 48); cout << sb << endl; spos = 30; IOnU->SetStreamSize (sentry, spos); cout << "streamsize " << IOnU->GetStreamSize(sentry) << endl; IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/streamtest.ionu", ggkey, ios::in); IOnU->ListFiles(); IOnU->ExtractFiles(); metadata = IOnU->GetMetaData(); cout << metadata << endl; delete IOnU; IOnU = new EyeContainer("test/streamtest.ionu", TGIkey); cout << "streamsize " << IOnU->GetStreamSize(sentry) << endl; spos = 0; IOnU->SetStreamSize (sentry, spos); cout << "streamsize " << IOnU->GetStreamSize(sentry) << endl; IOnU->WriteStream (sentry, spos, (void*)"First chunk of data for stream", 30, &nwritten); spos = 30; IOnU->WriteStream (sentry, spos, (void*)", second chunk of data for stream", 33, &nwritten); spos = 63; IOnU->WriteStream (sentry, spos, (void*)", last chunk of data for stream", 31, &nwritten); IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/streamtest.ionu", TGIkey); cout << "streamsize " << IOnU->GetStreamSize(sentry) << endl; spos = 0; IOnU->ReadStream (sentry, spos, sbuffer, 94, &nwritten); sb.assign (sbuffer, 94); cout << sb << endl; cout << IOnU->GetMetaData() << endl; ex = IOnU->ExtractMemoryFile (sentry, &nwritten); if (nwritten != 94 || sequencelogic::MemCmp (sb.data(), ex, nwritten) != 0) rc += testfailed ("ExtractMemoryFile", "stream 94"); if (ex) delete[] ex; delete IOnU; IOnU = new EyeContainer("test/streamtest.ionu", TGIkey); cout << "streamsize " << IOnU->GetStreamSize(sentry) << endl; spos = 40; IOnU->SetStreamSize (sentry, spos); IOnU->Finalize(); delete IOnU; IOnU = new EyeContainer("test/streamtest.ionu", TGIkey); ex = IOnU->ExtractMemoryFile (sentry, &nwritten); if (nwritten != 40) rc += testfailed ("ExtractMemoryFile", "stream 40"); if (ex) delete[] ex; delete IOnU; if (rc == 0) printf ("\nC++ interface tests passed\n-------------------------------\n"); else printf ("\n%d C++ interface tests failed\n-------------------------------\n", rc); // Test the extern "C" interfaces printf ("\nTestin C interfaces\n-------------------------------\n"); if (ionu_eyefile_is_valid (NULL)) rc += testfailed ("ionu_eye_is_valid", "NULL"); if (ionu_eyefile_is_valid ("bogus")) rc += testfailed ("ionu_eye_is_valid", "bogus"); if (ionu_eyefile_is_valid (testfile)) rc += testfailed ("ionu_eye_is_valid", testfile); if (! ionu_eyefile_create_with_content (cionu, TGIkey, "TGI", TGIkey, SL_AES_KEY_LEN, "application/tgi", URN, PERMS)) rc += testfailed ("ionu_eye_create_with_content", "TGI"); if (! ionu_eyefile_create_with_message (cionu, TGIkey, "Thread", "Hello there", 11, URN, PERMS)) rc += testfailed ("ionu_eye_create_with_message", "Thread"); if (! ionu_eyefile_is_valid (cionu)) rc += testfailed ("ionu_eye_is_valid", cionu); // Simple message test cmsg = ionu_eyefile_get_message (cionu, TGIkey, "Thread"); if (cmsg) { printf ("%s\n", cmsg); free (cmsg); } else rc += testfailed ("ionu_eye_get_message", "Thread"); // File test with bad key, then good key if (! ionu_eyefile_create_with_file (cionu, TGIkey, testfile, "test/plain", URN, PERMS)) rc += testfailed ("ionu_eye_create_with_file", cionu); if (ionu_eyefile_extract_file (cionu, badkey, testfile)) { if (filecompare (testfile, testfile_orig)) rc += testfailed ("Extract Bad TGI key", testfile); else printf ("PASSED: Bad TGI key test check\n"); } else { printf ("PASSED: Bad TGI key test\n"); } if (ionu_eyefile_extract_file (cionu, TGIkey, testfile)) { if (filecompare (testfile, testfile_orig)) printf ("PASSED: ionu_eyefile_extract_file: Good TGI key test\n"); else rc += testfailed ("ionu_eyefile_extract_file: file differences", testfile); } else rc += testfailed ("ionu_eyefile_extract_file: extract", testfile); // Long path test if (! ionu_eyefile_create_with_file (cionu, TGIkey, longtest, "test/plain", URN, PERMS)) rc += testfailed ("ionu_eye_create_with_file - longpath test", cionu); if (ionu_eyefile_extract_file (cionu, TGIkey, longtest)) { if (filecompare (longtest, testfile_orig)) printf ("PASSED: ionu_eyefile_extract_file: Long path test\n"); else rc += testfailed ("ionu_eyefile_extract_file long path: file differences in long", testfile); } else rc += testfailed ("ionu_eyefile_extract_file: extract long", testfile); // Verify meta data cmeta = ionu_eyefile_get_meta_data (cionu); if (cmeta) { printf ("%s\n", cmeta); free (cmeta); } else rc += testfailed ("ionu_eye_get_meta_data", cionu); // Verify permissions data cmeta = ionu_eyefile_get_perms (cionu); if (cmeta) { printf ("%s\n", cmeta); free (cmeta); } else rc += testfailed ("ionu_eye_get_permissions", cionu); EyeLog::GetInstance()->SetLogLevel (EyeLog::IONU_DEBUG); // Replace meta data, works first time, second fails because transaction count is too low cmeta = ionu_eyefile_get_meta_data (cionu); if (!ionu_eyefile_replace_meta_data (cionu, cmeta)) rc += testfailed ("ionu_eyefile_replace_meta_data - same meta", cionu); if (ionu_eyefile_replace_meta_data (cionu, cmeta)) rc += testfailed ("ionu_eyefile_replace_meta_data - old meta", cionu); free (cmeta); // SHredd if (ionu_eyefile_shred (cionu)) printf ("Shred passed\n"); else rc += testfailed ("Shred failed", cionu); // Message with multiple associated files and attachments if (! ionu_eyefile_create_with_message (cionu, TGIkey, "Thread", "Hello there", 11, URN2, PERMS)) rc += testfailed ("ionu_eye_create_with_message", "Thread"); cmeta = ionu_eyefile_get_meta_data (cionu); if (cmeta) { printf ("%s\n", cmeta); free (cmeta); } ionu_eyefile_add_file (cionu, TGIkey, attachfile, NULL); ionu_eyefile_add_thumbnail (cionu, TGIkey, thumbfile, NULL); ionu_eyefile_add_message (cionu, TGIkey, "Word", "see attachment", 14); ionu_eyefile_add_content (cionu, TGIkey, "TGI", TGIkey, SL_AES_KEY_LEN, "application/tgi"); ionu_eyefile_add_message (cionu, TGIkey, "UTF", smiley, strlen(smiley)+1); // Verify meta data cmeta = ionu_eyefile_get_meta_data (cionu); if (cmeta) { printf ("%s\n", cmeta); free (cmeta); } else rc += testfailed ("ionu_eye_get_meta_data multiple files", cionu); // Verify meta data cmeta = ionu_eyefile_get_file_objects (cionu); if (cmeta) { printf ("%s\n", cmeta); free (cmeta); } else rc += testfailed ("ionu_eyefile_get_file_objects multiple files", cionu); cmsg = ionu_eyefile_get_message (cionu, TGIkey, "Thread"); if (cmsg) { printf ("%s\n", cmsg); free (cmsg); } else rc += testfailed ("ionu_eye_get_message", "Thread"); ionu_eyefile_add_message (cionu, TGIkey, "Word", "see attachment - replaced", 25); cmsg = ionu_eyefile_get_message (cionu, TGIkey, "Word"); if (cmsg) { printf ("%s\n", cmsg); free (cmsg); } else rc += testfailed ("ionu_eye_get_message", "Word"); cmsg = ionu_eyefile_get_message (cionu, TGIkey, "UTF"); if (cmsg) { if (sequencelogic::StrCmp (cmsg, smiley) != 0) rc += testfailed ("ionu_eye_get_message", smiley); free (cmsg); } size_t thumbsize = ionu_eyefile_get_file_size (cionu, TGIkey, "thumb.png"); if (thumbsize != 45119) { rc += testfailed ("ionu_eyefile_get_file_size", thumbfile); } if (ionu_eyefile_get_file_size (cionu, TGIkey, "TGI") != SL_AES_KEY_LEN) rc += testfailed ("ionu_eyefile_get_file_size", "TGI"); unsigned char tbuff[SL_AES_KEY_LEN]; if (!ionu_eyefile_get_content (cionu, TGIkey, "TGI", tbuff)) rc += testfailed ("ionu_eyefile_get_content", "TGI"); if (memcmp (TGIkey, tbuff, SL_AES_KEY_LEN) != 0) rc += testfailed ("ionu_eyefile_get_content", "TGI does not match"); if (ionu_eyefile_get_content_and_write_to_file (cionu, badkey, "Word", "test/word")) rc += testfailed ("ionu_eyefile_get_content_and_write_to_file", "bad should fail"); if (!ionu_eyefile_get_content_and_write_to_file (cionu, TGIkey, "Word", "test/word")) rc += testfailed ("ionu_eyefile_get_content_and_write_to_file", "didn't get the word"); if (!ionu_eyefile_get_content_and_write_to_file (cionu, TGIkey, "Word", "test/word")) rc += testfailed ("ionu_eyefile_get_content_and_write_to_file", "didn't get the word twice"); if (ionu_eyefile_get_content_and_write_to_file (cionu, TGIkey, "Word", "test/readonly")) rc += testfailed ("ionu_eyefile_get_content_and_write_to_file", "got the readonly word"); // Try to get a text message with badkey, should return NULL cmsg = ionu_eyefile_get_message (cionu, badkey, "Word"); if (cmsg) { rc += testfailed ("ionu_eye_get_message", "badkey Word"); free (cmsg); } // Change the key and try again ionu_eyefile_change_key (cionu, TGIkey, badkey); cmsg = ionu_eyefile_get_message (cionu, badkey, "Word"); if (cmsg) { printf ("Rekeyed: %s\n", cmsg); free (cmsg); } else rc += testfailed ("ionu_eye_get_message", "rekeyed Word"); // Verify meta data cmeta = ionu_eyefile_get_meta_data (cionu); if (cmeta) { printf ("%s\n", cmeta); free (cmeta); } else rc += testfailed ("ionu_eye_get_meta_data", cionu); // Verify list of file names cmeta = ionu_eyefile_get_filenames (cionu); if (cmeta) { printf ("%s\n", cmeta); free (cmeta); } else rc += testfailed ("ionu_eyefile_get_filenames", cionu); cmeta = ionu_eyefile_get_file_objects (cionu); if (cmeta) { printf ("%s\n", cmeta); free (cmeta); } else rc += testfailed ("ionu_eyefile_get_file_objects", cionu); const char* chatbot = "I'm a robot and I love to chat with other bots"; size_t chatsize = strlen (chatbot); // Replace the permissions, which should change the tgisig cmeta = ionu_eyefile_get_meta_data (cionu); ionu_eyefile_replace_perms (cionu, PERMS3); coldmeta = ionu_eyefile_get_meta_data (cionu); if (sequencelogic::StrCmp (coldmeta, cmeta) == 0) rc += testfailed ("ionu_eyefile_replace_perms TGI sig unchanged", cionu); free (cmeta); free (coldmeta); coldmeta = ionu_eyefile_get_perms (cionu); if (ionu_eyefile_shred_contents (cionu, TGIkey, shredurn)) { if (ionu_eyefile_get_status (cionu) != SHREDDED) rc += testfailed ("ionu_eyefile_get_status", "shredded"); cmeta = ionu_eyefile_get_filenames (cionu); if (cmeta && strcmp (cmeta, "[]") != 0) rc += testfailed ("ionu_eyefile_shred_contents []", cmeta); // Verify meta data cmeta = ionu_eyefile_get_meta_data (cionu); if (cmeta) { if (! strstr (cmeta, "status\":\"deleted")) rc += testfailed ("ionu_eyefile_shred_contents deleted", cmeta); free (cmeta); } else rc += testfailed ("ionu_eyefile_get_meta_data after shred", cionu); // Verify perms cmeta = ionu_eyefile_get_perms (cionu); if (cmeta) { if (sequencelogic::StrCmp (coldmeta, cmeta) != 0) rc += testfailed ("ionu_eyefile_shred_contents perms", cmeta); free (cmeta); } else rc += testfailed ("ionu_eyefile_get_perms after shred", cionu); } else rc += testfailed ("ionu_eyefile_shred_contents failed", cionu); free (coldmeta); // Try adding a message to shredded container if (ionu_eyefile_add_message (cionu, TGIkey, "1000's", chatbot, chatsize)) rc += testfailed ("ionu_eyefile_add_message to shredded container", cionu); coldmeta = ionu_eyefile_get_meta_data (cionu); ionu_eyefile_replace_meta_data (cionu, megaMeta); cmeta = ionu_eyefile_get_meta_data (cionu); // Shredded container, so it should fail to update if (sequencelogic::StrCmp (coldmeta, cmeta) != 0) rc += testfailed ("ionu_eyefile_shred_contents replace meta data", cionu); free (coldmeta); free (cmeta); ionu_eyefile_create_with_message (cionu, TGIkey, "1000's", chatbot, chatsize, URN1, PERMS); //for (int i = 0; i < 1000; ++i) { // Verified with 1,000, but just use 10 for regular test runs for (int i = 0; i < 10; ++i) { ionu_eyefile_add_message (cionu, TGIkey, "1000's", chatbot, chatsize); char* msg = ionu_eyefile_get_message (cionu, TGIkey, "1000's"); if (sequencelogic::MemCmp (msg, chatbot, chatsize) != 0) { rc += testfailed ("Get1000Messages", chatbot); } if (msg) free (msg); } ionu_eyefile_add_message (cionu, TGIkey, "1000's", "Short chat", 10); cmeta = ionu_eyefile_get_message (cionu, TGIkey, "1000's"); if (sequencelogic::MemCmp (cmeta, "Short chat", 10) != 0) { rc += testfailed ("Get1000Messages", "Short chat"); } if (cmeta) free (cmeta); cmeta = ionu_eyefile_get_meta_data (cionu); if (cmeta) { printf ("%s\n", cmeta); free (cmeta); } //long ms = sequencelogic::GetSystemTime(); //for (int i=0; i<10000; ++i) { // meta = ionu_eyefile_get_meta_data (cionu); // free (meta); //} //ms = sequencelogic::GetSystemTime() - ms; //printf ("get_meta_data() 10,000 values in %ld ms\n", ms); if (! ionu_eyefile_create_with_message (cionu, TGIkey, "Empty", "", 0, URN1, PERMS)) rc += testfailed ("ionu_eye_create_with_message", "Empty"); cmsg = ionu_eyefile_get_message (cionu, TGIkey, "Empty"); if (cmsg && *cmsg == '\0') { printf ("Empty message passed <>\n"); free (cmsg); } else rc += testfailed ("ionu_eye_get_message", "Empty"); ionu_eyefile_replace_meta_data (cionu, megaMeta); cmeta = ionu_eyefile_get_meta_data (cionu); if (cmeta) { printf ("%s\n", cmeta); free (cmeta); } else rc += testfailed ("ionu_eyefile_replace_meta_data", cionu); ionu_eyefile_create_with_message (yoionu, TGIkey, ".imchat", "Yo!", 3, URN, PERMS); cmsg = ionu_eyefile_get_message (yoionu, TGIkey, ".imchat"); if (!cmsg || strcmp (cmsg, "Yo!") != 0) rc += testfailed ("ionu_eye_get_message", "Yo!"); if (cmsg) free (cmsg); cmsg = ionu_eyefile_get_message ("test/yo_eyecontainer.ionu", TGIkey, ".imchat"); if (!cmsg || strcmp (cmsg, "Yo!") != 0) rc += testfailed ("ionu_eye_get_message - EyeContainer", "Yo!"); if (cmsg) free (cmsg); if (ionu_eyefile_get_content_and_write_to_file ("test/yo_eyecontainer.ionu", badkey, ".imchat", "test/chat")) rc += testfailed ("ionu_eyefile_get_content_and_write_to_file - EyeContainer", "Yo!"); // Invalid argument and modified file tests printf ("Invalid argument tests\n-------------------------------\n"); if (ionu_eyefile_get_message (cionu, TGIkey, NULL)) rc += testfailed ("ionu_eye_get_message", "extracted NULL"); if (ionu_eyefile_get_message (cionu, NULL, "Empty")) rc += testfailed ("ionu_eye_get_message", "NULL key"); if (ionu_eyefile_get_message (NULL, TGIkey, "Empty")) rc += testfailed ("ionu_eye_get_message", "NULL .ionu"); if (ionu_eyefile_get_message (empty_ionu, TGIkey, "Empty")) rc += testfailed ("ionu_eye_get_message", "empty .ionu"); if (ionu_eyefile_get_meta_data (empty_ionu)) rc += testfailed ("ionu_eyefile_get_meta_data", "empty .ionu"); if (ionu_eyefile_get_filenames (empty_ionu)) rc += testfailed ("ionu_eyefile_get_filenames", "empty .ionu"); if (ionu_eyefile_get_message ("", TGIkey, "Empty")) rc += testfailed ("ionu_eye_get_message", "empty .ionu"); if (ionu_eyefile_get_message ("this path does not exist/test.ionu", TGIkey, "Empty")) rc += testfailed ("ionu_eye_get_message", "this path does not exist .ionu"); if (ionu_eyefile_get_message ((char*)TGIkey, TGIkey, "Empty")) rc += testfailed ("ionu_eye_get_message", "bad .ionu"); if (ionu_eyefile_get_message ("test\ncionu", TGIkey, "Empty")) rc += testfailed ("ionu_eye_get_message", "bad file path"); if (ionu_eyefile_get_message (cionu, TGIkey, "bogus")) rc += testfailed ("ionu_eye_get_message", "extracted bogus"); if (ionu_eyefile_extract_file (cionu, TGIkey, (char*)TGIkey)) rc += testfailed ("ionu_eye_extract_file", "extracted TGIkey"); if (ionu_eyefile_extract_file (cionu, TGIkey, "bogus")) rc += testfailed ("ionu_eye_extract_file", "extracted bogus"); if (ionu_eyefile_create_with_file (cionu, TGIkey, NULL, "test/plain", URN, PERMS)) rc += testfailed ("ionu_eye_create_with_file", "added NULL"); if (ionu_eyefile_create_with_file (cionu, TGIkey, "bogus", "test/plain", URN, PERMS)) rc += testfailed ("ionu_eye_create_with_file", "added bogus"); if (ionu_eyefile_get_message (perm_mods, TGIkey, "Empty")) rc += testfailed ("ionu_eyefile_get_message", perm_mods); if (ionu_eyefile_get_message (meta_corrupt, TGIkey, "Empty")) rc += testfailed ("ionu_eyefile_get_message", meta_corrupt); if (ionu_eyefile_get_message (fek_corrupt, TGIkey, "Empty")) rc += testfailed ("ionu_eye_get_message", "fek_corrupt"); if (ionu_eyefile_get_meta_data (chksum_corrupt)) rc += testfailed ("ionu_eye_get_meta_data", "chksum_corrupt"); if (ionu_eyefile_get_message (chksum_corrupt, TGIkey, "Empty")) rc += testfailed ("ionu_eye_get_message", "chksum_corrupt"); if (rc == 0) printf ("\nEyeContainer interface tests passed\n-------------------------------\n"); else printf ("\n%d EyeContainer interface tests failed\n-------------------------------\n", rc); */ return rc; } void GeneratePattern (unsigned char* buffer, std::streamoff spos) { char posbuf[16]; sprintf (posbuf, "%08lx", spos); memcpy (buffer, posbuf, 8); } int RandomStreamTest (const std::string& sentry, size_t chunk, size_t chunks, unsigned char* rbuffer, unsigned char* wbuffer) { int rc = 0; /* std::vector positions; std::streamoff spos = 0; size_t i = 0; for (i = 0; i < chunks; ++i) { positions.push_back (spos); spos += chunk; } for (i = 0; i < chunks * 100; ++i) { size_t a = rand() % positions.size(); size_t b = rand() % positions.size(); if (a != b) { std::streamoff save = positions[a]; positions[a] = positions[b]; positions[b] = save; } } memset (rbuffer, '1', chunk); memset (wbuffer, '1', chunk); Key tgi ("tgi", "stream", SL_AES_KEY_LEN, TGIkey, Key::AES); EyeContainer* eye = new EyeContainer("test/performance.ionu", tgi, URN, PERMS); eye->SetStreamSize (sentry, chunk * chunks); cout << "RandomStreamTest - streamsize " << eye->GetStreamSize(sentry) << endl; // Write the random blocks size_t nwritten = 0; for (i = 0; i < chunks; ++i) { spos = positions[i]; GeneratePattern (wbuffer, spos); eye->WriteStream (sentry, spos, wbuffer, chunk, &nwritten); if (nwritten != chunk) { IONUDEBUG ("FAILED: RandomStreamTest() - wrote %d of %d at %d", nwritten, chunk, spos); rc++; break; } } // Read them and verify content match for (i = 0; i < chunks; ++i) { spos = positions[i]; eye->ReadStream (sentry, spos, rbuffer, chunk, &nwritten); if (nwritten != chunk) { IONUDEBUG ("FAILED: RandomStreamTest() - read %d of %d at %d", nwritten, chunk, spos); rc++; break; } GeneratePattern (wbuffer, spos); if (memcmp (wbuffer, rbuffer, nwritten) != 0) { IONUDEBUG ("FAILED: RandomStreamTest() - read/write mismatch, before flush in block starting at %d of size %d", spos, nwritten); rc++; size_t badbytes = 0; std::streamoff badpos = spos; for (size_t j = 0; j < chunk; ++j) { if (rbuffer[j] != '1') { if (badbytes == 0) badpos += j; badbytes++; } } if (badbytes > 0) { IONUDEBUG ("RandomStreamTest() - %d bytes starting at %d", badbytes, badpos); } } } // Flush to disk and verify read again eye->Flush(); delete eye; eye = new EyeContainer("test/performance.ionu", tgi); for (i = 0; i < chunks; ++i) { spos = positions[i]; eye->ReadStream (sentry, spos, rbuffer, chunk, &nwritten); if (nwritten != chunk) { IONUDEBUG ("FAILED: RandomStreamTest() - read after flush %d of %d at %d on block %d", nwritten, chunk, spos, i); rc++; break; } GeneratePattern (wbuffer, spos); if (memcmp (wbuffer, rbuffer, nwritten) != 0) { IONUDEBUG ("FAILED: RandomStreamTest() - read/write mismatch, after flush in block %d starting at %d of size %d", i, spos, nwritten); rc++; size_t badbytes = 0; std::streamoff badpos = spos; for (size_t j = 0; j < chunk; ++j) { if (rbuffer[j] != '1') { if (badbytes == 0) badpos += j; badbytes++; } } if (badbytes > 0) { IONUDEBUG ("RandomStreamTest() - %d bytes starting at %d", badbytes, badpos); break; } } } delete eye; // Verify readonly eye = new EyeContainer("test/performance.ionu", tgi, ios::in); for (i = 0; i < chunks; ++i) { spos = positions[i]; eye->ReadStream (sentry, spos, rbuffer, chunk, &nwritten); if (nwritten != chunk) { IONUDEBUG ("FAILED: RandomStreamTest() - readonly read %d of %d at %d", nwritten, chunk, spos); rc++; break; } GeneratePattern (wbuffer, spos); if (memcmp (wbuffer, rbuffer, nwritten) != 0) { IONUDEBUG ("FAILED: RandomStreamTest() - read/write mismatch, readonly in block starting at %d of size %d", spos, nwritten); rc++; size_t badbytes = 0; std::streamoff badpos = spos; for (size_t j = 0; j < chunk; ++j) { if (rbuffer[j] != '1') { if (badbytes == 0) badpos += j; badbytes++; } } if (badbytes > 0) { IONUDEBUG ("RandomStreamTest() - %d bytes starting at %d", badbytes, badpos); } } } delete eye; */ return rc; } // Sequential read, with readonly file, verify data with expected value bool StreamVerify (const std::string& sentry, size_t chunk, size_t chunks, unsigned char* rbuffer, unsigned char* wbuffer) { bool rc = true; /* size_t nwritten = 0; std::streamoff spos = 0; Key tgi ("tgi", "stream", SL_AES_KEY_LEN, TGIkey, Key::AES); EyeContainer* eye = new EyeContainer("test/performance.ionu", tgi, ios::in); for (size_t i = 0; i < chunks; ++i) { spos = i * chunk; GeneratePattern (wbuffer, spos); eye->ReadStream (sentry, spos, rbuffer, chunk, &nwritten); if (nwritten != chunk) { IONUDEBUG ("FAILED: StreamVerify() - read %d of %d at %d", nwritten, chunk, spos); break; } if (memcmp (wbuffer, rbuffer, nwritten) != 0) { rc = false; IONUDEBUG ("FAILED: StreamVerify() - read/write mismatch in block starting at %d of size %d", spos, nwritten); size_t badbytes = 0; std::streamoff badpos = spos; for (size_t j = 0; j < chunk; ++j) { if (rbuffer[j] != wbuffer[j]) { if (badbytes == 0) badpos += j; badbytes++; } } if (badbytes > 0) { IONUDEBUG ("FAILED: StreamVerify() - %d bytes starting at %d", badbytes, badpos); } } } delete eye; */ return rc; } int PerformanceTest() { printf ("\nSpeed Testin stream interfaces\n-------------------------------\n"); int rc = 0; /* size_t chunk = IONU_EYE_STREAM_CHUNK/4; size_t chunks = 98; EyeContainer* IOnU = NULL; std::string sentry ("stream"); std::streamoff spos = 0; std::string baseline = ""; std::string digest = ""; size_t nwritten = 0; Key junk; Key tgi ("tgi", "stream", SL_AES_KEY_LEN, TGIkey, Key::AES); unsigned char iv[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', 'f'}; unsigned char* rbuffer = sequencelogic::New (chunk); unsigned char* wbuffer = sequencelogic::New (chunk); memset (wbuffer, '1', chunk); std::chrono::high_resolution_clock::time_point begin; std::chrono::high_resolution_clock::time_point end; std::chrono::duration time_span; // Sequential write begin = std::chrono::high_resolution_clock::now(); IOnU = new EyeContainer("test/performance.ionu", tgi, URN, PERMS); for (size_t i = 0; i < chunks; ++i) { spos = i * chunk; GeneratePattern (wbuffer, spos); IOnU->WriteStream (sentry, spos, wbuffer, chunk, &nwritten); if (nwritten != chunk) { IONUDEBUG ("PerformanceTest() - wrote %d of %d", nwritten, chunk); break; } } //IOnU->WriteStream (sentry, chunk * chunks, wbuffer, 3, &nwritten); IOnU->Finalize(); delete IOnU; end = std::chrono::high_resolution_clock::now(); time_span = std::chrono::duration_cast>(end - begin); cout << "Sequential write in " << time_span.count() << " seconds" << endl; // Get baseline hash IOnU = new EyeContainer("test/performance.ionu", tgi, ios::in); IOnU->ExtractFile (sentry); //unsigned char* membuf = IOnU->ExtractMemoryFile (sentry, &nwritten); delete IOnU; //if (membuf) delete[] membuf; begin = std::chrono::high_resolution_clock::now(); baseline = sequencelogic::DigestFile ("sha1", "stream"); cout << baseline << endl; end = std::chrono::high_resolution_clock::now(); time_span = std::chrono::duration_cast>(end - begin); cout << "Digested in " << time_span.count() << " seconds" << endl; begin = std::chrono::high_resolution_clock::now(); if (!StreamVerify (sentry, chunk, chunks, rbuffer, wbuffer)) rc++; end = std::chrono::high_resolution_clock::now(); time_span = std::chrono::duration_cast>(end - begin); cout << "Sequential readonly in " << time_span.count() << " seconds" << endl; // Raw file encryption time begin = std::chrono::high_resolution_clock::now(); tgi.SymmetricEncryptFile ("stream", "estream", iv); end = std::chrono::high_resolution_clock::now(); time_span = std::chrono::duration_cast>(end - begin); cout << "Encrypted in " << time_span.count() << " seconds" << endl; begin = std::chrono::high_resolution_clock::now(); tgi.SymmetricDecryptFile ("estream", "stream", iv); end = std::chrono::high_resolution_clock::now(); time_span = std::chrono::duration_cast>(end - begin); cout << "Decrypted in " << time_span.count() << " seconds" << endl; digest = sequencelogic::DigestFile ("sha1", "stream"); if (digest != baseline) cout << "FAIL: digest mismatch " << digest << " expected " << baseline << endl; // Random write/read tests begin = std::chrono::high_resolution_clock::now(); rc += RandomStreamTest (sentry, chunk, chunks, rbuffer, wbuffer); IOnU = new EyeContainer("test/performance.ionu", tgi, ios::in); IOnU->ExtractFile (sentry); delete IOnU; digest = sequencelogic::DigestFile ("sha1", "stream"); if (digest != baseline) cout << "FAIL: digest mismatch " << digest << " expected " << baseline << endl; end = std::chrono::high_resolution_clock::now(); time_span = std::chrono::duration_cast>(end - begin); cout << "Random stream test in " << time_span.count() << " seconds" << endl; // Reverse write new stream begin = std::chrono::high_resolution_clock::now(); IOnU = new EyeContainer("test/performance.ionu", tgi, URN, PERMS); IOnU->SetStreamSize (sentry, chunk * chunks); for (int i = chunks - 1; i >= 0; --i) { spos = i * chunk; GeneratePattern (wbuffer, spos); IOnU->WriteStream (sentry, spos, wbuffer, chunk, &nwritten); if (nwritten != chunk) { IONUDEBUG ("PerformanceTest() - wrote %d of %d at %d", nwritten, chunk, spos); break; } } IOnU->Finalize(); delete IOnU; end = std::chrono::high_resolution_clock::now(); time_span = std::chrono::duration_cast>(end - begin); cout << "Reverse write in " << time_span.count() << " seconds" << endl; IOnU = new EyeContainer("test/performance.ionu", tgi, ios::in); IOnU->ExtractFile (sentry); delete IOnU; digest = sequencelogic::DigestFile ("sha1", "stream"); if (digest != baseline) cout << "FAIL: digest mismatch " << digest << " expected " << baseline << endl; if (!StreamVerify (sentry, chunk, chunks, rbuffer, wbuffer)) rc++; // Skip write in existing stream begin = std::chrono::high_resolution_clock::now(); IOnU = new EyeContainer("test/performance.ionu", tgi); for (size_t i = 0; i < chunks; i += 4) { spos = i * chunk; GeneratePattern (wbuffer, spos); IOnU->WriteStream (sentry, spos, wbuffer, chunk, &nwritten); if (nwritten != chunk) { IONUDEBUG ("PerformanceTest() - wrote %d of %d", nwritten, chunk); break; } } IOnU->Finalize(); delete IOnU; end = std::chrono::high_resolution_clock::now(); time_span = std::chrono::duration_cast>(end - begin); cout << "Skip 4 write in " << time_span.count() << " seconds" << endl; if (!StreamVerify (sentry, chunk, chunks, rbuffer, wbuffer)) rc++; IOnU = new EyeContainer("test/performance.ionu", tgi, ios::in); IOnU->ExtractFile (sentry); delete IOnU; digest = sequencelogic::DigestFile ("sha1", "stream"); if (digest != baseline) cout << "FAIL: digest mismatch " << digest << " expected " << baseline << endl; begin = std::chrono::high_resolution_clock::now(); cout << EyeContainer::GetMetaData ("test/performance.ionu", ".ionumeta", tgi) << endl; end = std::chrono::high_resolution_clock::now(); time_span = std::chrono::duration_cast>(end - begin); cout << "GetMetaData in " << time_span.count() << " seconds" << endl; // Verify baseline hash IOnU = new EyeContainer("test/performance.ionu", tgi, ios::in); IOnU->ExtractFile (sentry); delete IOnU; digest = sequencelogic::DigestFile ("sha1", "stream"); if (digest != baseline) cout << "FAIL: digest mismatch " << digest << " expected " << baseline << endl; // Skip read begin = std::chrono::high_resolution_clock::now(); IOnU = new EyeContainer("test/performance.ionu", tgi); for (size_t i = 0; i < chunks; i += 4) { spos = i * chunk; GeneratePattern (wbuffer, spos); IOnU->ReadStream (sentry, spos, rbuffer, chunk, &nwritten); if (nwritten != chunk) { IONUDEBUG ("PerformanceTest() - read %d of %d", nwritten, chunk); break; } if (memcmp (wbuffer, rbuffer, nwritten) != 0) { IONUDEBUG ("PerformanceTest() - read/write mismatch in block starting at %d of size %d", spos, nwritten); size_t badbytes = 0; std::streamoff badpos = spos; for (size_t j = 0; j < chunk; ++j) { if (rbuffer[j] != wbuffer[j]) { if (badbytes == 0) badpos += j; badbytes++; } } if (badbytes > 0) { IONUDEBUG ("PerformanceTest() - %d bytes starting at %d", badbytes, badpos); } } } delete IOnU; end = std::chrono::high_resolution_clock::now(); time_span = std::chrono::duration_cast>(end - begin); cout << "Skip 4 read in " << time_span.count() << " seconds" << endl; // Reverse read begin = std::chrono::high_resolution_clock::now(); IOnU = new EyeContainer("test/performance.ionu", tgi, ios::in | ios::out); for (int i = chunks - 1; i >= 0; --i) { spos = i * chunk; GeneratePattern (wbuffer, spos); IOnU->ReadStream (sentry, spos, rbuffer, chunk, &nwritten); if (nwritten != chunk) { IONUDEBUG ("PerformanceTest() - read %d of %d at %d", nwritten, chunk, spos); break; } if (memcmp (wbuffer, rbuffer, nwritten) != 0) { IONUDEBUG ("PerformanceTest() - read/write mismatch in block starting at %d of size %d", spos, nwritten); size_t badbytes = 0; std::streamoff badpos = spos; for (size_t j = 0; j < chunk; ++j) { if (rbuffer[j] != wbuffer[j]) { if (badbytes == 0) badpos += j; badbytes++; } } if (badbytes > 0) { IONUDEBUG ("PerformanceTest() - %d bytes starting at %d", badbytes, badpos); } } } delete IOnU; end = std::chrono::high_resolution_clock::now(); time_span = std::chrono::duration_cast>(end - begin); cout << "Reverse read in " << time_span.count() << " seconds" << endl; // Extract plaintext file begin = std::chrono::high_resolution_clock::now(); IOnU = new EyeContainer("test/performance.ionu", tgi, ios::in); IOnU->ExtractFile (sentry); delete IOnU; end = std::chrono::high_resolution_clock::now(); time_span = std::chrono::duration_cast>(end - begin); cout << "Extracted in " << time_span.count() << " seconds" << endl; begin = std::chrono::high_resolution_clock::now(); digest = sequencelogic::DigestFile ("sha1", "stream"); if (digest != baseline) cout << "FAIL: digest mismatch " << digest << " expected " << baseline << endl; end = std::chrono::high_resolution_clock::now(); time_span = std::chrono::duration_cast>(end - begin); cout << "Digested in " << time_span.count() << " seconds" << endl; // Add plaintext file begin = std::chrono::high_resolution_clock::now(); IOnU = new EyeContainer("test/performance.ionu", tgi, URN, PERMS); IOnU->AddContent (sentry, "text/stream"); IOnU->Finalize(); delete IOnU; end = std::chrono::high_resolution_clock::now(); time_span = std::chrono::duration_cast>(end - begin); cout << "Added in " << time_span.count() << " seconds" << endl; begin = std::chrono::high_resolution_clock::now(); IOnU = new EyeContainer("test/performance.ionu", tgi); IOnU->AddContent (sentry, "text/stream"); IOnU->Finalize(); delete IOnU; end = std::chrono::high_resolution_clock::now(); time_span = std::chrono::duration_cast>(end - begin); cout << "Replaced in " << time_span.count() << " seconds" << endl; cout << EyeContainer::GetMetaData ("test/performance.ionu", ".ionumeta", tgi) << endl; // Sequential read, with read/write file begin = std::chrono::high_resolution_clock::now(); IOnU = new EyeContainer("test/performance.ionu", tgi, ios::in | ios::out); for (int i = 0; i < chunks; ++i) { spos = i * chunk; GeneratePattern (wbuffer, spos); IOnU->ReadStream (sentry, spos, rbuffer, chunk, &nwritten); if (nwritten != chunk) { IONUDEBUG ("PerformanceTest() - read %d of %d at %d", nwritten, chunk, spos); break; } if (memcmp (wbuffer, rbuffer, nwritten) != 0) { IONUDEBUG ("PerformanceTest() - read/write mismatch in block starting at %d of size %d", spos, nwritten); size_t badbytes = 0; std::streamoff badpos = spos; for (size_t j = 0; j < chunk; ++j) { if (rbuffer[j] != '1') { if (badbytes == 0) badpos += j; badbytes++; } } if (badbytes > 0) { IONUDEBUG ("PerformanceTest() - %d bytes starting at %d", badbytes, badpos); } } } delete IOnU; end = std::chrono::high_resolution_clock::now(); time_span = std::chrono::duration_cast>(end - begin); cout << "Sequential read in " << time_span.count() << " seconds" << endl; // Reverse write with SetStreamSize() begin = std::chrono::high_resolution_clock::now(); IOnU = new EyeContainer("test/performance.ionu", tgi, URN, PERMS); IOnU->SetStreamSize (sentry, chunk * chunks); for (int i = chunks - 1; i >= 0; --i) { spos = i * chunk; GeneratePattern (wbuffer, spos); IOnU->WriteStream (sentry, spos, wbuffer, chunk, &nwritten); if (nwritten != chunk) { IONUDEBUG ("PerformanceTest() - wrote %d of %d at %d", nwritten, chunk, spos); break; } } IOnU->Finalize(); delete IOnU; end = std::chrono::high_resolution_clock::now(); time_span = std::chrono::duration_cast>(end - begin); cout << "Reverse write, SetStreamSize in " << time_span.count() << " seconds" << endl; if (!StreamVerify (sentry, chunk, chunks, rbuffer, wbuffer)) rc++; #ifdef SLOW // Reverse write begin = std::chrono::high_resolution_clock::now(); IOnU = new EyeContainer("test/performance.ionu", tgi, ios::in | ios::out); for (int i = chunks - 1; i >= 0; --i) { spos = i * chunk; GeneratePattern (wbuffer, spos); IOnU->WriteStream (sentry, spos, rbuffer, chunk, &nwritten); if (nwritten != chunk) { IONUDEBUG ("PerformanceTest() - wrote %d of %d at %d", nwritten, chunk, spos); break; } } IOnU->Finalize(); delete IOnU; end = std::chrono::high_resolution_clock::now(); time_span = std::chrono::duration_cast>(end - begin); cout << "Reverse write in " << time_span.count() << " seconds" << endl; EyeContainer::UpdateMetaData ("test/performance.ionu", ".ionumeta", "{\"urn\":\"urn:sl:FFFFFF:FFFFFFFF:ALAN:FROSTFFFFFFF\"}", junk); // Verify that reverse write worked IOnU = new EyeContainer("test/performance.ionu", tgi, ios::in); IOnU->ExtractFile (sentry); membuf = IOnU->ExtractMemoryFile (sentry, &nwritten); delete IOnU; if (membuf) delete[] membuf; cout << "Extracted " << nwritten << " bytes - " << sequencelogic::DigestFile ("sha1", "stream") << endl; // Reverse write with sequential read begin = std::chrono::high_resolution_clock::now(); std::streamoff rpos = 0; IOnU = new EyeContainer("test/performance.ionu", tgi, ios::in | ios::out); for (int i = chunks - 1; i >= 0; --i) { spos = i * chunk; GeneratePattern (wbuffer, spos); IOnU->WriteStream (sentry, spos, rbuffer, chunk, &nwritten); if (nwritten != chunk) { IONUDEBUG ("PerformanceTest() - wrote %d of %d at %d", nwritten, chunk, spos); break; } IOnU->ReadStream (sentry, rpos, rbuffer, chunk, &nwritten); rpos += chunk; } IOnU->Finalize(); delete IOnU; end = std::chrono::high_resolution_clock::now(); time_span = std::chrono::duration_cast>(end - begin); cout << "Reverse write, sequential read in " << time_span.count() << " seconds" << endl; // Verify that reverse write with sequential read worked IOnU = new EyeContainer("test/performance.ionu", tgi, ios::in); IOnU->ExtractFile (sentry); delete IOnU; digest = sequencelogic::DigestFile ("sha1", "stream"); if (digest != baseline) cout << "FAIL: digest mismatch " << digest << " expected " << baseline << endl; #endif // Test static methods for metadata, rename and permissions cout << EyeContainer::GetMetaData ("test/performance.ionu", ".ionumeta", junk) << endl; EyeContainer::UpdateMetaData ("test/performance.ionu", ".ionumeta", "{\"msg\":{\"drr\":true}}", junk); cout << EyeContainer::GetMetaData ("test/performance.ionu", ".ionumeta", junk) << endl; EyeContainer::RenameFile ("test/performance.ionu", "stream", "renamed", junk); cout << EyeContainer::GetContentMetaData ("test/performance.ionu", "stream", junk) << endl; EyeContainer::UpdateMetaData ("test/performance.ionu", ".ionuperm", "{\"read\":[\"00000003\",\"17C38E5A\"]}", junk); cout << EyeContainer::GetMetaData ("test/performance.ionu", ".ionuperm", junk) << endl; if (EyeContainer::GetStatus ("test/performance.ionu") != EyeContainer::EYE_VALID) cout << "FAIL: invalid EyeContainer after static metadata tests" << endl; delete[] wbuffer; delete[] rbuffer; if (rc == 0) printf ("\nIVFS interface tests passed\n-------------------------------\n"); else printf ("\n%d IVFS interface tests failed\n-------------------------------\n", rc); */ return rc; } #ifdef ALAN void SearchQuery (EyeSearch& bing, const std::string query) { cout << query << " - " << bing.Search (query, 7) << endl; } int TestSearch() { int rc = 0; #ifndef WIN32 Key tgi ("tgi", "stream", SL_AES_KEY_LEN, TGIkey, Key::AES); EyeSearch bing ("index", tgi); bing.IndexDocument ("test/applications.txt", "text/plain", "{\"title\":\"Applications and Tools\"}"); bing.IndexDocument ("test/authentication.txt", "text/plain", "{\"title\":\"Advanced Authentication\"}"); bing.IndexDocument ("test/cloud.txt", "text/plain", "{\"title\":\"Cloud Services\"}"); bing.IndexDocument ("test/management.txt", "text/plain", "{\"title\":\"Key Management\"}"); bing.IndexDocument ("test/mobility.txt", "text/plain", "{\"title\":\"Mobility and BYOD\"}"); bing.IndexDocument ("test/transparent.txt", "text/plain", "{\"title\":\"Transparent Encryption\"}"); bing.IndexMessage ("Message", "Secure your mobile device with IONU", "{\"title\":\"Mobile Security\"}"); bing.IndexMessage ("unCompound", "Secure your cell or mobile phone and bike for mountain with IONU", "{\"title\":\"Compound Security\"}"); bing.IndexMessage ("Compound", "Secure your cell phone and mountain bike with IONU", "{\"title\":\"Compound Security\"}"); bing.SortByRank(); bing.Dump(); SearchQuery (bing, "security"); SearchQuery (bing, "encryption"); SearchQuery (bing, "mobile security"); SearchQuery (bing, "mobile security storage"); SearchQuery (bing, "attack key encryption"); SearchQuery (bing, "cell phone"); SearchQuery (bing, "cellphone"); SearchQuery (bing, "phone"); SearchQuery (bing, "mountain bike"); EyeStemmer stem; char* stems = fileload ("test/voc.txt"); std::string stemstr (stems, strlen (stems)); std::vector words = SplitString (stemstr, '\n'); for (auto& word: words) { if (word.size() > 2) cout << stem.Stem (word) << endl; else cout << word << endl; } cout << stem.Stem ("feed") << endl; cout << stem.Stem ("like") << endl; cout << stem.Stem ("liked") << endl; cout << stem.Stem ("pencils") << endl; cout << stem.Stem ("agreed") << endl; cout << stem.Stem ("agreeable") << endl; cout << stem.Stem ("rationalize") << endl; cout << stem.Stem ("rationalization") << endl; cout << stem.Stem ("rationals") << endl; cout << stem.Stem ("abate") << endl; cout << stem.Stem ("windpipe") << endl; #endif return rc; } #endif int main () { int rc = 0; Key junk; //Key tgi ("tgi", "stream", SL_AES_KEY_LEN, TGIkey, Key::AES); EyeLog::GetInstance()->ConfigLogger ("libeye", "test", EyeLog::IONU_DEBUG, EyeLog::IONU_CONSOLE, "%l:%c %m"); //cout << sequencelogic::GetVersionInfo() << endl; //TestSearch(); //TestProcessLocking(); //TestFileThreadLocking(); TestFileLocking(); //TestRandom(); // TestEyeContainer(); exit (0); /* TestKeys(); TestMixedUpKeys(); TestEyeContainer(); PerformanceTest(); //TestSearch(); //TestRSAKeyGeneration(); ionu_eyefile_create_with_message (yoionu, TGIkey, ".imchatty", "Yo!", 3, URN, PERMS); std::string tarjson = EyeContainer::Stringify (yoionu); cout << tarjson << endl; EyeContainer::Tarify ("tarjson.ionu", tarjson); size_t rbytes; unsigned char* rbuffer = sequencelogic::New (70000); memset (rbuffer, '7', 70000); EyeContainer* reye = new EyeContainer("test/rename.ionu", tgi, URN, PERMS); reye->WriteStream ("stream", 0, rbuffer, 70000, &rbytes); reye->Finalize(); delete reye; std::string smallermeta = EyeContainer::GetMetaData ("test/rename.ionu", IONU_EYE_META_FILE, junk); tarjson = EyeContainer::Stringify ("test/rename.ionu"); cout << "tarjson " << tarjson.size() << endl; cout << tarjson.substr (0, 1024) << endl; EyeContainer::Tarify ("tarjson.ionu", tarjson); EyeContainer::RenameFile ("test/rename.ionu", "stream", "stream12345", junk); EyeContainer::RenameFile ("test/rename.ionu", "stream12345", "stream123456", junk); std::string largermeta = EyeContainer::GetMetaData ("test/rename.ionu", IONU_EYE_META_FILE, junk); EyeContainer::RenameFile ("test/rename.ionu", "stream123456", "stream12345", junk); EyeContainer::RenameFile ("test/rename.ionu", "stream12345", "stream", junk); ionu_eyefile_replace_meta_data ("test/rename.ionu", largermeta.c_str()); ionu_eyefile_replace_meta_data ("test/rename.ionu", smallermeta.c_str()); ionu_eyefile_replace_meta_data ("test/empty.ionu", smallermeta.c_str()); sequencelogic::CopyFiles ("test/old.ionu", "test/oldrename.ionu"); EyeContainer* oldren = new EyeContainer ("test/oldrename.ionu", TGIkey); oldren->RenameFile (".imchat", "renamed"); oldren->Finalize(); delete oldren; cout << EyeContainer::GetMetaData ("test/oldrename.ionu", IONU_EYE_META_FILE, junk) << endl; sequencelogic::RemoveFile ("test/oldrename.ionu"); sequencelogic::RemoveFile ("test/oldrename.ionu"); cout << "done" << endl; exit (0); exit (0); TestFileThreadLocking(); TestFileLocking(); ionu_eyefile_create_with_message (yoionu, TGIkey, ".imchatty", "Yo!", 3, URN, PERMS); cout << ionu_eyefile_get_message (yoionu, TGIkey, ".imchatty") << endl; ionu_eyefile_rename_file (yoionu, ".imchatty", ".imchat"); cout << ionu_eyefile_get_message (yoionu, TGIkey, ".imchat") << endl; Keyring rring ("js", "test"); rring.GenerateRSAKey ("bob", "bob", "IOnU,Bob,Bob,Bob"); Key rrkey; rring.GetKey ("bob", rrkey); rrkey.PublicKeyFingerPrint(); rring.ImportPubKeyFromCert ("test/isis.pem"); rring.GetKey ("cert", rrkey); if (rrkey.PublicKeyFingerPrint() != "fc:34:2b:b3:a2:f6:91:c9:fb:79:16:ca:2e:d2:47:3d:b3:38:8a:b2") rc += testfailed ("isis.nu - fc:34:2b:b3:a2:f6:91:c9:fb:79:16:ca:2e:d2:47:3d:b3:38:8a:b2", rrkey.PublicKeyFingerPrint()); exit (0); // Test capture and replace of FEK in compressed EyeContainer EyeContainer* rionu = new EyeContainer("test/test.ionu", TGIkey, URN, PERMS); rionu->AddTextMessage ("Message", "Updated FEK from captured FEK after container ReKey and restore FEK"); rionu->Finalize(); delete rionu; std::string oldfek = EyeContainer::GetMetaData ("test/test.ionu", IONU_EYE_FEK_FILE, junk); Key bbkey ("Bad", "key", SL_AES_KEY_LEN, badkey, Key::TGI); rionu = new EyeContainer("test/test.ionu", TGIkey); rionu->ReKey (bbkey); rionu->Finalize(); delete rionu; rionu = new EyeContainer("test/test.ionu", TGIkey); std::string rmsg = rionu->GetTextMessage ("Message"); if (rmsg.size() > 1 && rmsg[0] == 'U' && rmsg[1] == 'p') rc += testfailed ("ReKey - old key", rmsg); delete rionu; EyeContainer::ReplaceMetaData ("test/test.ionu", IONU_EYE_FEK_FILE, oldfek, junk); rionu = new EyeContainer("test/test.ionu", TGIkey); rmsg = rionu->GetTextMessage ("Message"); if (rmsg.size() > 1 && rmsg[0] == 'U' && rmsg[1] == 'p') cout << rmsg << endl; delete rionu; // Test capture and replace of FEK in uncompressed EyeContainer rionu = new EyeContainer("test/test.ionu", TGIkey, URN, PERMS); size_t nwritten = 0; rionu->WriteStream ("Message", 0, "Updated FEK from captured FEK... uncompressed EyeContainer", 58, &nwritten); rionu->Finalize(); delete rionu; oldfek = EyeContainer::GetMetaData ("test/test.ionu", IONU_EYE_FEK_FILE, junk); rionu = new EyeContainer("test/test.ionu", TGIkey); rionu->ReKey (bbkey); rionu->Finalize(); delete rionu; rionu = new EyeContainer("test/test.ionu", TGIkey); rmsg = rionu->GetTextMessage ("Message"); if (rmsg.size() > 1 && rmsg[0] == 'U' && rmsg[1] == 'p') rc += testfailed ("ReKey - old key", rmsg); delete rionu; EyeContainer::ReplaceMetaData ("test/test.ionu", IONU_EYE_FEK_FILE, oldfek, junk); rionu = new EyeContainer("test/test.ionu", TGIkey); rmsg = rionu->GetTextMessage ("Message"); if (rmsg.size() > 1 && rmsg[0] == 'U' && rmsg[1] == 'p') cout << rmsg << endl; delete rionu; exit (0); //if (!ionu_eyefile_replace_fek ("test/performance.ionu", fek64)) // rc += testfailed ("ionu_eyefile_replace_fek", "test/performance.ionu"); //rc = EyeContainer::ReplaceMetaData (eyefile, IONU_EYE_FEK_FILE, fek64, junk); TestEyeContainer(); exit (0); cout << ionu_eyefile_get_status ("test/oldtest.ionu") << endl; cout << ionu_eyefile_get_filenames ("test/oldtest.ionu"); //exit (0); Keyring* b = new Keyring ("test/testbot-keyring.iks.device.iks"); b->Dump(); b = new Keyring ("test/testbot-keyring.iks"); b->Dump(); static const char* pkcs1_5 = "R6wk+Bv95uTd0ipk4azmDnOIrUNFuV4eB1USG4uRIcsGcZS7Zh86nBXP8XxvYjjYglYf8234IrFMccmQ5Dk8a5F2fgdLZhwW976h8zhMOgpMHsyaWKELeTdncfd1kR3yTXxRHPCGrS5uglC4WACRmtkjlpWQNs5SHTzFgKcNphtVw7n8bUj5A4h0gTURWPw+uQ7/F6+/el1K6W+4gIBxhJ+Phqws5rJZtp4RHnBFWBTAtNkRx/4XvTk472CCCnG4D5C7mzqbgBpDOKYfq0JVptw8YV9dbkjrxUg4ioNQGAq1YN3xqSqiAy2tHsImTaPtTZMH+CRA/BwCMCpiRUtU9Q=="; static const char* pkcs2_0 = "qiU6RjO7JsiuW8o9J6gerBClAGUY5fXu09JCKXbVE+3RHaG741yzvTuXOi+6ZZrL4ldBzSXvtXwBngGuKZZhQU++eUmiuZyMJeifKuqCpTrwQ3rmBpCxrTCvlXO+br64+w81apgaDySh3EyU7y1q7DyiqAgOjrhpN9zcLxX2hRjrdTtZD8LPsQ2k1eSNjx9/tDIE3BXcRIi5kngL2lT/spjiF1OULVH+AWj0hizzR+iDHOpPxbOAJDD2ckNRYb4UoLnF3ELA3jBvG82CS0oXvWc8rHroDEJX6ja7f0GCPwwiSJA1wm94M31cu1L/YZ10LJXEt+imcLYx9Ixoes3Org=="; unsigned char* pbuff; unsigned char* back; Key* RSA = new Key ("Auditor", "RSA auditing key", (int)strlen(BOT_private), (const unsigned char*)BOT_private, Key::RSA); Keyring* botk = new Keyring("j", "k"); botk->AddKey (RSA); botk->Lock (TGIkey); botk->SaveAs ("test/bot.iks"); delete botk; botk = new Keyring ("test/bot.iks"); botk->Unlock (TGIkey); std::string pem; pem.assign ((char*)botk->GetKey ("Auditor")->GetKey(), botk->GetKey ("Auditor")->GetLength()); cout << pem << endl; char* pkk = botk->GetPubKey ("Auditor"); cout << pkk << endl; const Key* A = botk->GetKey ("Auditor"); Key kpubkey ("CG", "public key", (int)strlen(pkk), (const unsigned char*) pkk, Key::RSA_PUBLIC); unsigned char b64bot[1024]; size_t botbytes = sequencelogic::Base64Decode (pkcs1_5, b64bot); cout << "decoded " << botbytes << endl; unsigned char* bot = A->PrivateKeyDecrypt (b64bot, 256, &botbytes); cout << "decrypted " << botbytes << endl; botbytes = sequencelogic::Base64Decode (pkcs2_0, b64bot); bot = A->PrivateKeyDecrypt (b64bot, 256, &botbytes); cout << "decrypted " << botbytes << endl; pbuff = kpubkey.PublicKeyEncrypt (BOTtgi, 32, &botbytes); sequencelogic::Base64Encode (pbuff, 256, (char*)b64bot); cout << (char*)b64bot << endl; back = A->PrivateKeyDecrypt (pbuff, botbytes, &botbytes); cout << "decrypted " << botbytes << endl; if (memcmp (back, BOTtgi, 32) != 0) cout << "fail " << endl; Keyring ring ("tim", "test"); ring.GenerateRSAKey("random", "RSA keypair"); ring.GenerateRSAKey("office", "RSA keypair"); char* pk = ring.GetPubKey ("random"); Key publicK ("CG", "public key", (int)strlen(pk), (const unsigned char*) pk, Key::RSA_PUBLIC); const Key* privateK = ring.GetKey("office"); size_t bytes = 0; pbuff = publicK.PublicKeyEncrypt ((unsigned char*)"Howdy", 6, &bytes); back = privateK->PrivateKeyDecrypt (pbuff, bytes, &bytes); char b64[1024]; sequencelogic::Base64Encode (back, bytes, b64); cout << "decrypted " << bytes << " " << b64 << endl; //unsigned char bk[32] = {-8, -19, 27, -82, 116, 77, -97, 125, -76, 21, 15, 89, -81, 121, -11, 103, -86, -55, -55, -63, -37, 26, -112, -115, 29, -71, -98, 96, 108, 44, -12, 27}; //EyeContainer* bc = new EyeContainer("test/BCollaborators.json.ionu", bk); //cout << bc->GetTextMessage("Collaborators"); #ifdef ddbbggrr unsigned char buff[32]; EyeDRBG drbg ((unsigned char*)"IOnU,Bob,Bob,Bob", strlen ("IOnU,Bob,Bob,Bob")); drbg.RandBytes (buff, 32); char bhex[128]; sequencelogic::BinaryToHex (buff, 32, bhex); cout << bhex << endl; exit (0); #endif EyeTime now ("2014-10-28T23:13:06.174Z"); cout << now << endl; now.SetFileTime ("t"); now.GetFileTime ("t"); cout << now << endl; EyeContainer jj ("jjj.ionu", tgi); cout << jj.GetLastErrorMessage() << endl; fstream tf ("jjj"); cout << sequencelogic::GetLastErrorMessage(); EyeLog::GetInstance()->SetLogLevel (EyeLog::IONU_DEBUG); EyeContainer::UpdateMetaData ("test/performance.ionu", ".ionumeta", "{\"modified_date\":\"2014-10-28T23:13:06.174Z\"}", junk); EyeContainer::SynchronizeFileTime ("test/performance.ionu", junk); //exit (0); std::string alan ("Yo there Alan Frost, what are you up to!"); std::string frost ("Working my ass off you fool"); std::streamoff entrysize; EyeContainer* zero = new EyeContainer("test/zero.ionu", tgi, URN, PERMS); zero->AddMemoryFile ("stream", (unsigned char*)alan.data(), 0, "zero/stream"); zero->UpdateMetaData ("{\"entry\":\"bstream\"}"); if (zero->RenameFile ("stream", "bstream")) cout << "success" << endl; cout << zero->GetContentFilenames() << endl; zero->SetStreamSize ("stream", 100); zero->Finalize(); delete zero; cout << EyeContainer::GetMetaData ("test/zero.ionu", ".ionumeta", junk) << endl; //exit (1); EyeContainer* greg = new EyeContainer("test/greg.ionu", tgi, URN, PERMS); greg->AddMemoryFile ("stream", (unsigned char*)alan.data(), alan.size(), "test/stream"); if (greg->ExtractFile ("stream", "test")) rc += testfailed ("greg->ExtractFile(stream)", "test"); EyeContainer* frank = new EyeContainer("test/frank.ionu", tgi, URN, PERMS); frank->AddMemoryFile ("frank", (unsigned char*)frost.data(), frost.size(), "test/frankly"); greg->CopyEntry (frank, "frank"); greg->CopyEntry (frank, "frank"); greg->CopyEntry (frank, "fred"); if (greg->HasEntry ("stream", &entrysize)) cout << "stream " << entrysize << endl; frank->Finalize(); delete frank; greg->Finalize(); delete greg; greg = new EyeContainer("test/greg.ionu", tgi); cout << greg->GetTextMessage ("stream") << endl; cout << greg->GetTextMessage ("frank") << endl; cout << greg->GetMetaData() << endl; delete greg; greg = new EyeContainer("test/greg.ionu", tgi, URN, PERMS); greg->AddMemoryFile (".imchat", (unsigned char*)alan.data(), alan.size(), "test/stream"); greg->Finalize(); delete greg; greg = new EyeContainer("test/greg.ionu", tgi); frost = greg->GetTextMessage (".imchat"); cout << frost << endl; cout << greg->GetMetaData() << endl; delete greg; //rc += TestStreams(); //rc += TestEyeContainer(); const char* tk = "a0W4wBu0ZTANeEEokBlVChhHY818ztsqadHDqNrbeuo="; unsigned char gtk[SL_AES_KEY_LEN]; sequencelogic::Base64Decode (tk, gtk); char buffy[65536]; ionu_eyefile_get_content ("test/HTML.html.ionu", gtk, "HTML.html", (unsigned char*)buffy); std::string kool (buffy, 100); cout << kool << endl; const char* ttk = "veR+rSvtWMOZlqwlL9tlZ2/n1YtGtEO8aaNjDy8paRU="; sequencelogic::Base64Decode (ttk, gtk); //ionu_eyefile_get_content ("test/Test.txt.ionu", gtk, "Test.txt", (unsigned char*)buffy); //kool.assign (buffy, 100); //cout << kool << endl; //EyeContainer* geye = new EyeContainer ("test/PDF.pdf.ionu", gtk); //geye->ExtractFile ("PDF.pdf"); EyeContainer* nU = new EyeContainer("test/stream.ionu", tgi, URN, PERMS); nU->AddMemoryFile ("stream", (unsigned char*)alan.data(), alan.size(), "test/stream"); nU->Finalize(); delete nU; nU = new EyeContainer("test/stream.ionu", tgi); frost = nU->GetTextMessage ("stream"); cout << frost << endl; EyeLog::GetInstance()->SetLogLevel (EyeLog::IONU_WARN); EyeLog::GetInstance()->SetLogLevel (EyeLog::IONU_DEBUG); #define WOW #ifdef WOW std::string m = ionu_eyefile_get_message (oldionu, TGIkey, ".imchat"); if (m.compare ("Yo!") == 0) cout << m << " - old .ionu quick check passed" << endl; else rc += testfailed ("ionu_eyefile_get_message", oldionu); cout << "---" << endl; ionu_eyefile_create_with_message (yoionu, TGIkey, ".imchatty", "Yo!", 3, URN, PERMS); cout << ionu_eyefile_get_message (yoionu, TGIkey, ".imchatty") << endl; ionu_eyefile_rename_file (yoionu, ".imchatty", ".imchat"); cout << ionu_eyefile_get_message (yoionu, TGIkey, ".imchat") << endl; char* modmeta = ionu_eyefile_get_meta_data (yoionu); cout << modmeta << endl << "------" << endl; EyeJSONObject modtest (modmeta); if (modmeta) free (modmeta); EyeJSONScalar* murn = (EyeJSONScalar*)modtest.GetMember ("urn"); std::string murnjson; murn->ReplaceValue (officeURN); murn->GetJSONString (murnjson); murnjson = "{" + murnjson + "}"; cout << murnjson << endl << "------" << endl; EyeContainer* eye = new EyeContainer (yoionu, TGIkey); eye->UpdateMetaData (murnjson); eye->Finalize(); delete eye; m = EyeContainer::GetMetaDataClassic (yoionu); cout << "meta = " << m << endl; m = EyeContainer::GetPermissionsClassic (yoionu); cout << "perm = " << m << endl; EyeContainer::UpdateMetaData (yoionu, ".ionumeta", "{\"msg\":{\"drr\":true}}", junk); m = EyeContainer::GetMetaDataClassic (yoionu); cout << "meta = " << m << endl; cout << ionu_eyefile_get_message (yoionu, TGIkey, ".imchat") << endl; //exit (0); murn->ReplaceValue (docURN); modtest.GetJSONString (murnjson); cout << murnjson << endl << "------" << endl; ionu_eyefile_replace_meta_data (yoionu, murnjson.c_str()); m = EyeContainer::GetMetaDataClassic (yoionu); cout << "--\nmeta = " << m << endl; m = EyeContainer::GetPermissionsClassic (yoionu); cout << "--\nperm = " << m << endl; cout << "--\nmsg = " << ionu_eyefile_get_message (yoionu, TGIkey, ".imchat") << endl; #endif //TestP2P(); //exit (1); // casting output of GetNumBytes to match format string printf ("%ld test\n", long(EyeDirectory::GetNumBytes ("test"))); std::string meta; std::string msg; char* cmsg = NULL; EyeBytes currency (utf8, 6); EyeBytes utfmsg; utfmsg.Assign (utf8, 6); cmsg = utfmsg.GetUTF8EncodedString(); if (cmsg) { printf ("%d bytes <%s>\n", (int)(utfmsg.GetSize()), cmsg); delete[] cmsg; } utfmsg.AssignUTF8EncodedString (smiley); cmsg = utfmsg.GetUTF8EncodedString(); if (cmsg) { printf ("%d bytes <%s>\n", (int)(utfmsg.GetSize()), cmsg); delete[] cmsg; } utfmsg.AssignUTF8EncodedString (utfeuro); cmsg = utfmsg.GetUTF8EncodedString(); if (cmsg) { printf ("%d bytes <%s>\n", (int)(utfmsg.GetSize()), cmsg); delete[] cmsg; } utfmsg.AssignUTF8EncodedString (utfjson); cmsg = utfmsg.GetUTF8EncodedString(); if (cmsg) { printf ("%d bytes <%s>\n", (int)(utfmsg.GetSize()), cmsg); delete[] cmsg; } ionu_derive_key (password, garbage); // Create a key (32 bytes of random binary data) for testing // Test logging, json and other utilities rc += TestLogging(); rc += TestRandom(); rc += TestJSON(); rc += TestUtils(); rc += TestTime(); rc += IONUCompressTests(); rc += IOnUPasswordTests(); rc += TestDB(); rc += TestDirectory(); rc += TestFileLocking(); rc += TestFileThreadLocking(); // Test the Keyring rc += TestKeys(); rc += TestRSAKeyGeneration(); // Test the EyeContainer EyeLog::GetInstance()->SetLogLevel (EyeLog::IONU_DEBUG); rc += TestEyeContainer(); rc += TestMixedUpKeys(); rc += PerformanceTest(); if (rc == 0) { printf ("All tests passed\n-------------------------------\n"); return 0; } else { printf ("%d tests failed\n-------------------------------\n", rc); return 1; } */ }