Hello, I am writing a very simple test script to encrypt a string with the wonderful libotr.
I attached it so as not to spam out a big file into the body of an email. However, the log I get is as such: *err: 16810065 * *err: 0 * *err: 16810065 * *err: 0 * *sending* *notify_cb* *policy_cb* *error0msg_1_plain = 'message 1'* *msg_1_crypt = 'message 1 '* *receiving* *notify_cb* *policy_cb* *write_fingerprints_cb* *msg_1_decrypt = 'message 1'* Program ended with exit code: 0 So, my msg_1_crypt is not getting the message encrypted at all, and I am getting errors on generating and reading private keys. The file write IS working (See attached). However, when I write to fingerprints, the file stays empty. I think I am close here... what am I missing my friends? Please help!! If I get this working, this will be the last piece for a tool that will really further internet security, especially enterprise. Michael
(privkeys (account (name tst1) (protocol xmpp) (private-key (dsa (p #00B7C8DD4073772DA95E250AADCFDA070696A53CE529BDB10D1740DAA03FC978F62DBD9B7D8341097AA50C3A7840B859C858E68D7CAD5150C9C02CECC4D165681516EAAFB618EDD66924885DFCFEA15347087BEF54847BC317BF57CD5A24AFD06BB7F961A00A1143A7E3FD75D851E5268A0FDACB0E1C5D09D1234D5C4BF46876EF#) (q #00EF63358A8359A71555843C1149E3A6345BF3780F#) (g #713F09EACB1ACB25B3E8BFE1FE27A6C0768D43F9B5CC6155E77DE7E3C2A46FCBE002226FFF627FA82DF8E4940AEB283934D73996CBD122AD0A111AB9C0EC28A2BAADD2D0820D934FAB5B0AEF4F1C1420235FC556110477D40A77E6F837DB42C7327363651E8882B0EC0E2A971DFDCE90F1557CECE7571614D90FB0BFBE9C66BF#) (y #2548183802C43B76EAAAB0CEB1BF11CCA9885F0BFB005E86BF6C9A42DEE0076C0650CACADA5BFEAF56B51023EAE839CE5884943A5BC98977FE04F5D10F914F92944D73DE567D09124C0E53DC65026B251860C909B89BB4E06DF16AA1B2CDFF83DCEEC60C849F01B527851653303C63B5C4EB0B5B334F5669F5E43FB3D641E050#) (x #00AD8DECF4BAA7C814961324C04A285760E846530C#) ) ) ) )
(privkeys (account (name tst2) (protocol xmpp) (private-key (dsa (p #00847957495CE4E08B4C5ADE20C301014B3CC65C7A7527B29BBD684F145EF4FA421DCA3D4CDB14F6AA4506BE19D02F224A0673BC5588DDE61348824C3FD83793E3A636974DEC090F6337D84D62EB926A15B097B4DC6B8F425E966F9DA68D67523BABB9A8C6190556EFE41319991042C61E0F52EBD586CDDAD973FE447E1EA6A663#) (q #00F53C3C871FEC46F8D5FD2566AB3912C6243F595F#) (g #48DE5D1DD1D850223D33736C1CB40686555258E2BF6CE18CFB4B1C6A314B9EA65D1329F01475D01979C7F423DDA254D4691FF4C12AC6E68891F25D13FD15AB375B3DA29CE41151C88A072FBA997170667B18A20CDF5859490016B9CA9EEC580353CDAA8304906FBCF7CA94B8957318F5E143521C484838B1B2CE7241DBA34D23#) (y #61459FF893A448980AB96B5900E785B34A3D5A53F84FE976FC57410C0CCAEC6AA921909B35E6C490D89CF72DDF2084211CC6F3EEFC40D0D7CB1D81D15CADD0519C28BBCC3E018F88E6262F9F2BC1FEB325FEECB31CC5F26BAC91A21BFD5292DE924E1CC7A0B9F512720376F3F3468F17652FB18CA5A2A7AA7ACB2F13EC9737F0#) (x #00C1E5235B49E7D05E49FD1E5002485C1348ECECA0#) ) ) ) )
(privkeys (account (name tst1) (protocol xmpp) (private-key (dsa (p #00A0FBED9E97D717B79C46D3C4D8B1C727A0D8075233269DE12CB7AA8C63F9FAC3FE275FFC6F52374FD2692F916BAE83D2D50BF145C6F04CE0165EB9B4D8E372912CBA82022DB862E953D6302B7E04A576217C45E194420D6F8E042C03323920D4F0EA3268359D41D6D23186CC351CAB425903143714538E89427EB50A893A8C13#) (q #009A0556B2EC71A4AD3AC00AB6ED64431376BC1C0D#) (g #2938FF3521F54F61F2C99AC0FA70784555B317655017C10694925F4E73C5C0B4E3D819B2EC3772FEEADC813CF94B883F3C2581FE6741DA5E8DCC5E6780A343E0B71530D03BB706E17B16C4D580C1561B0D5BCDEBDCCC9F479D8A06FC95AB0F1E72BF3D85F17584A3FA19AEBD348571D0EA3D79ADC7F03F92831E583A82DF798D#) (y #047EBF9C5E805C78314C2498822E304647252C682D255497E1D9FD1E6F09863FE0257407855BF0D61D445BC38EC0950AC2F1C7EAB0EB07E4BF9D247AE221B54A861565865B2D599B853FEB4040CCB0B1E0D3B963C63720855E183AFEA63E732227F946CF9F85521E1140A26B19E4B5DA84BBD40F75801F57102FEF13DB503DD7#) (x #1B71094CCE8D1127CEC959C48FB3C271AEE4F7FE#) ) ) ) )
// // main.c // libotrTestApp // // Created by Michael Voznesensky on 3/6/15. // Copyright (c) 2015 MV. All rights reserved. // #include "auth.h" #include "proto.h" #include "userstate.h" #include "message.h" #include "privkey.h" #include <stdio.h> #include "gcrypt.h" #include <string.h> OtrlUserState tst1_userstate; OtrlUserState tst2_userstate; OtrlMessageAppOps ui_ops ; OtrlUserState get_userstate(const char* username){ if(strcmp(username, "tst1")) return tst1_userstate; else if(strcmp(username, "tst2")) return tst2_userstate; else return NULL; } /* Set up the libotr UI ops */ static OtrlPolicy (*ui_policy_cb)(ConnContext *) = NULL; static OtrlPolicy policy_cb(void *opdata, ConnContext *context) { printf("policy_cb\n"); //return OTRL_POLICY_REQUIRE_ENCRYPTION; /* if (ui_policy_cb) { */ /* return ui_policy_cb(context); */ /* } else { */ //return OTRL_POLICY_ALLOW_V2; return OTRL_POLICY_DEFAULT; /* } */ } static void create_privkey_cb(void *opdata, const char *accountname, const char *protocol) { char *filename = malloc(snprintf(NULL, 0, "keys_%s.txt", accountname) + 1); sprintf(filename, "keys_%s.txt", accountname); printf("create_privkey_cb\n"); printf("account = %s\n", accountname); printf("filename = %s\n", filename); otrl_privkey_generate(get_userstate(accountname), filename, accountname, protocol); otrl_privkey_read(get_userstate(accountname), filename); printf("key generated\n"); } static const char *protocol_name_cb(void *opdata, const char *protocol) { printf("protocol_name_cb\n"); return "xmpp"; } static void new_fingerprint_cb(void *opdata, OtrlUserState us, const char *accountname, const char *protocol, const char *username, unsigned char fingerprint[20]) { // proxyevent_new_fingerprint(accountname, protocol, username, fingerprint); printf("new_fingerprint_cb\n"); } static void write_fingerprints_cb(void *opdata) { printf("write_fingerprints_cb\n"); } static int display_otr_message_cb(void *opdata, const char *accountname, const char *protocol, const char *username, const char *msg) { printf("display_otr_message_cb\n"); printf("message = '%s'\n", msg); return -1; } static int is_online_cb(void *opdata, const char *accountname, const char *protocol, const char *recipient) { printf("is_online_cb\n"); return -1; } /* static void gone_secure_cb(void *opdata, ConnContext *context, int protocol_version) { */ /* printf("gone_secure_cb\n"); */ /* return; */ /* } */ /* static void gone_insecure_cb(void *opdata, ConnContext *context) */ /* { */ /* printf("gone_insecure_cb\n"); */ /* } */ /* static void still_secure_cb(void *opdata, ConnContext *context, int is_reply, */ /* int protocol_version) */ /* { */ /* printf("still_secure_cb\n"); */ /* } */ static void inject_message_cb(void *opdata, const char *accountname, const char *protocol, const char *recipient, const char *message) { printf("\n\ninject_message_cb\n"); printf("from = %s\n", accountname); printf("to = %s\n", recipient); printf("message = '%s'\n", message); char *msg_decrypt = NULL; int intern_message; intern_message = otrl_message_receiving(get_userstate(recipient), &ui_ops, NULL, recipient, protocol, accountname, message, &msg_decrypt, 0, NULL, NULL, NULL); printf("decrypted msg = '%s'\n", msg_decrypt); printf("err = %i\n", intern_message); printf("\n\n"); } static void notify_cb(void *opdata, OtrlNotifyLevel level, const char *accountname, const char *protocol, const char *username, const char *title, const char *primary, const char *secondary) { printf("notify_cb\n"); } OtrlMessageAppOps ui_ops = { policy_cb, create_privkey_cb, is_online_cb, inject_message_cb, notify_cb, display_otr_message_cb, NULL, // update_context_list_cb, protocol_name_cb, NULL, // protocol_name_free_cb, new_fingerprint_cb, write_fingerprints_cb, NULL, //gone_secure_cb, NULL, //gone_insecure_cb, NULL, //still_secure_cb, NULL, // log_message_cb }; int main() { OTRL_INIT; // FILE *fp; // fp=fopen("./keys_tst1.txt", "w"); // fprintf(fp, "Testing...\n"); tst1_userstate = otrl_userstate_create(); tst2_userstate = otrl_userstate_create(); gcry_error_t err; err = otrl_privkey_generate(get_userstate("tst1"), "keys_tst1.txt", "tst1", "xmpp"); err = otrl_privkey_generate(get_userstate("tst2"), "keys_tst2.txt", "tst2", "xmpp"); printf("err: %d \n", err); err = otrl_privkey_write_fingerprints(get_userstate("tst1"), "fingerprints1.txt"); printf("err: %d \n", err); err = otrl_privkey_read(get_userstate("tst1"), "keys_tst1.txt"); printf("err: %d \n", err); otrl_privkey_read(get_userstate("tst2"), "keys_tst2.txt"); err = otrl_privkey_read_fingerprints(get_userstate("tst1"), "fingerprints1.txt", NULL, NULL); printf("err: %d \n", err); int ignore_message; char *msg1_plain = "message 1"; char *msg1_crypt = NULL; char *msg1_decrypt = NULL; printf("sending\n"); char *newmessage = NULL; err = otrl_message_sending(get_userstate("tst1"), &ui_ops, NULL, "tst1", "xmpp", "tst2", OTRL_INSTAG_BEST, msg1_plain, NULL, &msg1_crypt, OTRL_FRAGMENT_SEND_SKIP, NULL, NULL, NULL); /* To encrypt the message (if necessary; the library keeps track of which users you have secure connections to, so you should *always* call this next function), simply do this: gcry_error_t err; char *newmessage = NULL; err = otrl_message_sending(userstate, &ui_ops, opdata, accountname, protocolid, recipient_name, instag, message, tlvs, &newmessage, fragPolicy, contextp, add_app_info, add_app_info_data); add_app_info and add_app_info_data are as above, and may be NULL. tlvs should usually be NULL. If it's not, then it points to a chain of OtrlTLVs which represent machine-readable data to send along with this message. If contextp is not NULL, it will be set to the context that was used for sending the message. If err is non-zero, then the library tried to encrypt the message, but for some reason failed. DO NOT send the message in the clear in that case. If newmessage gets set by the call to something non-NULL, then you should replace your message with the contents of newmessage, and send that instead. Once the message is encrypted, it may still be too large to send over the network in a single piece. */ // err = otrl_message_sending(get_userstate("tst1"), &ui_ops, NULL, // "tst1", "xmpp", "tst2", // msg1_plain, 0, &msg1_crypt, NULL, NULL); if (err != GPG_ERR_NO_ERROR) { printf("something went wrong during encrypting\n"); } printf("error"); printf("%d", err); printf("msg_1_plain = '%s'\n", msg1_plain); printf("msg_1_crypt = '%s'\n", msg1_crypt); printf("receiving\n"); ignore_message = otrl_message_receiving(get_userstate("tst2"), &ui_ops, NULL, "tst2", "xmpp", "tst1", msg1_crypt, &msg1_decrypt, 0, NULL, NULL, NULL); printf("msg_1_decrypt = '%s'\n", msg1_decrypt); return 0; }
_______________________________________________ OTR-dev mailing list OTR-dev@lists.cypherpunks.ca http://lists.cypherpunks.ca/mailman/listinfo/otr-dev