Esempio n. 1
0
int ModulesLoaded(WPARAM wParam, LPARAM lParam)
{
	InitUtils();

	lib_cs_lock();
	otr_user_state = otrl_userstate_create();
	lib_cs_unlock();

	// this calls ReadPrivkeyFiles (above) to set filename values (also called on ME_FOLDERS_PATH_CHANGED)
	InitOptions();

	InitDBFilter();
	InitIcons();
	InitMenu();

	InitSRMM();

	hEventWindow = HookEvent(ME_MSG_WINDOWEVENT, WindowEvent);

	if (options.bHaveSecureIM && !db_get_b(0, MODULENAME, "sim_warned", 0)) {
		db_set_b(0, MODULENAME, "sim_warned", 1);
		options.default_policy = OTRL_POLICY_MANUAL_MOD;
		SaveOptions();
		MessageBox(0, TranslateT(LANG_OTR_SECUREIM_TEXT), TranslateT(LANG_OTR_SECUREIM_TITLE), 0x30);
	}
	return 0;
}
Esempio n. 2
0
static void test_otrl_instag_find(void)
{
	OtrlUserState us = otrl_userstate_create();
    OtrlInsTag* p1 = (OtrlInsTag *)malloc(sizeof(OtrlInsTag));
    OtrlInsTag* p2 = (OtrlInsTag *)malloc(sizeof(OtrlInsTag));

    p1->accountname = strdup("account one");
    p1->protocol = strdup("protocol one");
    p1->instag = otrl_instag_get_new();
    p1->next = us->instag_root;
    p1->tous = &(us->instag_root);
    us->instag_root = p1;

    p2->accountname = strdup("account two");
    p2->protocol = strdup("protocol two");
    p2->instag = otrl_instag_get_new();
    p2->next = us->instag_root;
	p2->next->tous = &(p2->next);
    p2->tous = &(us->instag_root);
    us->instag_root = p2;

	ok(otrl_instag_find(us, "account two", "protocol two") == p2,
			"Found instag");
	ok(otrl_instag_find(us, "account one", "protocol two") == NULL,
			"Instag not found");
	ok(otrl_instag_find(us, "account three", "protocol three") == NULL,
			"Instag not found");
}
Esempio n. 3
0
int main() {
    OtrlUserState userstate;
    OTRL_INIT;
    userstate = otrl_userstate_create();
    otrl_userstate_free(userstate);
    return 0;
}
Esempio n. 4
0
static void test_otrl_instag_read_FILEp(void)
{
    FILE* instf = fopen(instag_filepath, "rb");
	OtrlUserState us = otrl_userstate_create();
	OtrlInsTag* one, *two, *three, *four;
	char sone[9] = {0},
		 stwo[9] = {0},
		 sfour[9] = {0};
	one = two = three = four = NULL;

    ok(otrl_instag_read_FILEp(us, instf) == gcry_error(GPG_ERR_NO_ERROR),
			"Instead read from FILEp");
    fclose(instf);

	one = otrl_instag_find(us, "alice_xmpp", "XMPP");
	snprintf(sone, sizeof(sone), "%08x", one->instag);

	two = otrl_instag_find(us, "alice_irc", "IRC");
	snprintf(stwo, sizeof(stwo), "%08x", two->instag);
	
	three = otrl_instag_find(us, "alice_inv", "IRC");
	
	four = otrl_instag_find(us, "alice_icq", "ICQ");
	snprintf(sfour, sizeof(sfour), "%08x", four->instag);

	ok(one && two && !three && four &&
			strcmp(sone, "01234567") == 0 &&
			strcmp(stwo, "9abcdef0") == 0 &&
			strcmp(sfour, "98765432") == 0,
			"Instag succesfully read");
}
Esempio n. 5
0
static void test_otrl_instag_read(void)
{
	OtrlUserState us = otrl_userstate_create();
	OtrlInsTag* one, *two, *three, *four;
	char sone[9] = {0},
		 stwo[9] = {0},
		 sfour[9] = {0};
	one = two = three = four = NULL;
	ok(otrl_instag_read(us, "/non_existent_file") ==
			gcry_error_from_errno(ENOENT),
			"Non-existent file detected");

	ok(otrl_instag_read(us, instag_filepath) == GPG_ERR_NO_ERROR,
			"Instag called with success");

	one = otrl_instag_find(us, "alice_xmpp", "XMPP");
	snprintf(sone, sizeof(sone), "%08x", one->instag);

	two = otrl_instag_find(us, "alice_irc", "IRC");
	snprintf(stwo, sizeof(stwo), "%08x", two->instag);
	
	three = otrl_instag_find(us, "alice_inv", "IRC");
	
	four = otrl_instag_find(us, "alice_icq", "ICQ");
	snprintf(sfour, sizeof(sfour), "%08x", four->instag);

	ok(one && two && !three && four &&
			strcmp(sone, "01234567") == 0 &&
			strcmp(stwo, "9abcdef0") == 0 &&
			strcmp(sfour, "98765432") == 0,
			"Instag succesfully read");
}
OtrInternal::OtrInternal(psiotr::OtrCallback* callback,
                         psiotr::OtrPolicy& policy)
    : m_userstate(),
      m_uiOps(),
      m_callback(callback),
      m_otrPolicy(policy),
      is_generating(false)
{
    QDir profileDir(callback->dataDir());

    m_keysFile        = profileDir.filePath(OTR_KEYS_FILE);
    m_instagsFile     = profileDir.filePath(OTR_INSTAGS_FILE);
    m_fingerprintFile = profileDir.filePath(OTR_FINGERPRINTS_FILE);

    OTRL_INIT;
    m_userstate                 = otrl_userstate_create();
    m_uiOps.policy              = (*OtrInternal::cb_policy);
    m_uiOps.create_privkey      = (*OtrInternal::cb_create_privkey);
    m_uiOps.is_logged_in        = (*OtrInternal::cb_is_logged_in);
    m_uiOps.inject_message      = (*OtrInternal::cb_inject_message);
    m_uiOps.update_context_list = (*OtrInternal::cb_update_context_list);
    m_uiOps.new_fingerprint     = (*OtrInternal::cb_new_fingerprint);
    m_uiOps.write_fingerprints  = (*OtrInternal::cb_write_fingerprints);
    m_uiOps.gone_secure         = (*OtrInternal::cb_gone_secure);
    m_uiOps.gone_insecure       = (*OtrInternal::cb_gone_insecure);
    m_uiOps.still_secure        = (*OtrInternal::cb_still_secure);

#if (OTRL_VERSION_MAJOR > 3 || (OTRL_VERSION_MAJOR == 3 && OTRL_VERSION_MINOR >= 2))
    m_uiOps.max_message_size    = NULL;
    m_uiOps.account_name        = (*OtrInternal::cb_account_name);
    m_uiOps.account_name_free   = (*OtrInternal::cb_account_name_free);
#endif

#if (OTRL_VERSION_MAJOR >= 4)
    m_uiOps.handle_msg_event    = (*OtrInternal::cb_handle_msg_event);
    m_uiOps.handle_smp_event    = (*OtrInternal::cb_handle_smp_event);
    m_uiOps.create_instag       = (*OtrInternal::cb_create_instag);
#else
    m_uiOps.log_message         = (*OtrInternal::cb_log_message);

    m_uiOps.notify              = (*OtrInternal::cb_notify);
    m_uiOps.display_otr_message = (*OtrInternal::cb_display_otr_message);

    m_uiOps.protocol_name       = (*OtrInternal::cb_protocol_name);
    m_uiOps.protocol_name_free  = (*OtrInternal::cb_protocol_name_free);
#endif

    otrl_privkey_read(m_userstate, QFile::encodeName(m_keysFile).constData());
    otrl_privkey_read_fingerprints(m_userstate,
                                   QFile::encodeName(m_fingerprintFile).constData(),
                                   NULL, NULL);
#if (OTRL_VERSION_MAJOR >= 4)
    otrl_instag_read(m_userstate, QFile::encodeName(m_instagsFile).constData());
#endif
}
/** 
 * constructor to initialize the libotr
 */
OtrConnection::OtrConnection() {
	protocolString = "prpl-jabber";
	OTRL_INIT;
	userstate = otrl_userstate_create();
	ui_ops.policy = (*OtrConnection::cb_policy);
	ui_ops.create_privkey = (*OtrConnection::cb_create_privkey);
	ui_ops.is_logged_in = (*OtrConnection::cb_is_logged_in);
	ui_ops.inject_message = (*OtrConnection::cb_inject_message);
	ui_ops.notify = (*OtrConnection::cb_notify);
	ui_ops.display_otr_message = (*OtrConnection::cb_display_otr_message);
	ui_ops.update_context_list = (*OtrConnection::cb_update_context_list);
	ui_ops.protocol_name = (*OtrConnection::cb_protocol_name);
	ui_ops.protocol_name_free = (*OtrConnection::cb_protocol_name_free);
	ui_ops.new_fingerprint = (*OtrConnection::cb_new_fingerprint);
	ui_ops.write_fingerprints = (*OtrConnection::cb_write_fingerprints);
	ui_ops.gone_secure = (*OtrConnection::cb_gone_secure);
	ui_ops.gone_insecure = (*OtrConnection::cb_gone_insecure);
	ui_ops.still_secure = (*OtrConnection::cb_still_secure);
	ui_ops.log_message = (*OtrConnection::cb_log_message);
}
Esempio n. 8
0
/*
 * Return a newly allocated OTR user state.
 */
struct otr_user_state *otr_init_user_state(void)
{
	struct otr_user_state *ous = NULL;

	ous = zmalloc(sizeof(*ous));
	if (!ous) {
		goto error;
	}

	ous->otr_state = otrl_userstate_create();

	instag_load(ous);

	/* Load keys and fingerprints. */
	key_load(ous);
	key_load_fingerprints(ous);

error:
	return ous;
}
Esempio n. 9
0
File: tests.c Progetto: Ri0n/libotr
int main(int argc, char **argv)
{
    OTRL_INIT;
    us = otrl_userstate_create();

    otrl_privkey_read(us, "/home/iang/.gaim/otr.private_key");
    otrl_instag_read(us, "inst.txt");

    test(1,0);
    test(2,0);
    test(3,0);
    test(1,1);
    test(2,1);
    test_unreadable();
    test_crash1();
    test_refresh(3);
    test_refresh(2);
    test_refresh(1);

    otrl_userstate_free(us);

    return 0;
}
Esempio n. 10
0
static void test_otrl_instag_forget_all(void)
{
	OtrlUserState us = otrl_userstate_create();
    OtrlInsTag* p = (OtrlInsTag *)malloc(sizeof(OtrlInsTag));
    p->accountname = strdup("account name");
    p->protocol = strdup("protocol name");
    p->instag = otrl_instag_get_new();

	/*
	otrl_instag_forget_all(NULL);
	ok(1, "Forget all on NULL didn't segfaulted");
	*/

	otrl_instag_forget_all(us);
	ok(1, "Forget all on empty user state");

    p->next = us->instag_root;
    p->tous = &(us->instag_root);
    us->instag_root = p;

	otrl_instag_forget_all(us);
	ok(1, "Forget all on a non-empty user state");
}
Esempio n. 11
0
// static
void OTR_Wrapper::init()
{
    otrwui_trace("OTR_Wrapper::init()");
    if (! gOTR)
    {
        gOTR = new OTR_Wrapper;
        if (!gOTR)
        {
            llwarns << "$PLOTR$ Can't new otr_wrapper." << llendl;
        }
        else
        {
            llinfos << "$PLOTR$ newed otr_wrapper." << llendl;
            gOTR->uistate.policy = &otrwui_policy;
            gOTR->uistate.create_privkey = &otrwui_create_privkey;
            gOTR->uistate.is_logged_in = &otrwui_is_logged_in;
            gOTR->uistate.inject_message = &otrwui_inject_message;
            gOTR->uistate.notify = &otrwui_notify;
            gOTR->uistate.display_otr_message = &otrwui_display_otr_message;
            gOTR->uistate.update_context_list = &otrwui_update_context_list;
            gOTR->uistate.protocol_name = &otrwui_protocol_name;
            gOTR->uistate.protocol_name_free = &otrwui_protocol_name_free;
            gOTR->uistate.new_fingerprint = &otrwui_new_fingerprint;
            gOTR->uistate.write_fingerprints = &otrwui_write_fingerprints;
            gOTR->uistate.gone_secure = &otrwui_gone_secure;
            gOTR->uistate.gone_insecure = &otrwui_gone_insecure;
            gOTR->uistate.still_secure = &otrwui_still_secure;
            gOTR->uistate.log_message = &otrwui_log_message;
            gOTR->uistate.max_message_size = &otrwui_max_message_size;
            gOTR->uistate.account_name = &otrwui_account_name;
            gOTR->uistate.account_name_free = &otrwui_account_name_free;
            OTRL_INIT;
            gOTR->userstate = otrl_userstate_create();
            std::string privpath =
                gDirUtilp->getExpandedFilename(
                    LL_PATH_PER_SL_ACCOUNT, OTR_PRIVATE_KEYS_FILE);
            otrl_privkey_read(gOTR->userstate,              privpath.c_str());
            std::string pubpath =
                gDirUtilp->getExpandedFilename(
                    LL_PATH_PER_SL_ACCOUNT, OTR_PUBLIC_KEYS_FILE);
            otrl_privkey_read_fingerprints(gOTR->userstate, pubpath.c_str(), NULL, NULL);
#if 0 // this will gen a key, if the user doesn't have one, at init() time
            if (gOTR && gOTR->userstate)
            {
                OtrlPrivKey *r = gOTR->userstate->privkey_root;
                OtrlPrivKey *k = gOTR->userstate->privkey_root;
                while (k && (k != r))
                {
                    if (0 == strcmp(gOTR->get_protocolid(), k->protocol))
                    {
                        return;
                    }
                }
                char my_uuid[UUID_STR_SIZE];
                gAgent.getID().toString(&(my_uuid[0]));
                otrl_privkey_generate(gOTR->userstate, privpath.c_str(),
                                      my_uuid, gOTR->get_protocolid());
            }
#endif
        }
    }
}
Esempio n. 12
0
void
otr_on_connect(ProfAccount *account)
{
    if (jid) {
        free(jid);
    }
    jid = strdup(account->jid);
    log_info("Loading OTR key for %s", jid);

    gchar *data_home = xdg_get_data_home();
    GString *basedir = g_string_new(data_home);
    free(data_home);

    gchar *account_dir = str_replace(jid, "@", "_at_");
    g_string_append(basedir, "/profanity/otr/");
    g_string_append(basedir, account_dir);
    g_string_append(basedir, "/");
    free(account_dir);

    if (!mkdir_recursive(basedir->str)) {
        log_error("Could not create %s for account %s.", basedir->str, jid);
        cons_show_error("Could not create %s for account %s.", basedir->str, jid);
        g_string_free(basedir, TRUE);
        return;
    }

    user_state = otrl_userstate_create();

    gcry_error_t err = 0;

    GString *keysfilename = g_string_new(basedir->str);
    g_string_append(keysfilename, "keys.txt");
    if (!g_file_test(keysfilename->str, G_FILE_TEST_IS_REGULAR)) {
        log_info("No OTR private key file found %s", keysfilename->str);
        data_loaded = FALSE;
    } else {
        log_info("Loading OTR private key %s", keysfilename->str);
        err = otrl_privkey_read(user_state, keysfilename->str);
        if (!err == GPG_ERR_NO_ERROR) {
            log_warning("Failed to read OTR private key file: %s", keysfilename->str);
            cons_show_error("Failed to read OTR private key file: %s", keysfilename->str);
            g_string_free(basedir, TRUE);
            g_string_free(keysfilename, TRUE);
            return;
        }

        OtrlPrivKey* privkey = otrl_privkey_find(user_state, jid, "xmpp");
        if (!privkey) {
            log_warning("No OTR private key found for account \"%s\", protocol \"xmpp\" in file: %s", jid, keysfilename->str);
            cons_show_error("No OTR private key found for account \"%s\", protocol \"xmpp\" in file: %s", jid, keysfilename->str);
            g_string_free(basedir, TRUE);
            g_string_free(keysfilename, TRUE);
            return;
        }
        log_info("Loaded OTR private key");
        data_loaded = TRUE;
    }

    GString *fpsfilename = g_string_new(basedir->str);
    g_string_append(fpsfilename, "fingerprints.txt");
    if (!g_file_test(fpsfilename->str, G_FILE_TEST_IS_REGULAR)) {
        log_info("No OTR fingerprints file found %s", fpsfilename->str);
        data_loaded = FALSE;
    } else {
        log_info("Loading OTR fingerprints %s", fpsfilename->str);
        err = otrl_privkey_read_fingerprints(user_state, fpsfilename->str, NULL, NULL);
        if (!err == GPG_ERR_NO_ERROR) {
            log_error("Failed to load OTR fingerprints file: %s", fpsfilename->str);
            g_string_free(basedir, TRUE);
            g_string_free(keysfilename, TRUE);
            g_string_free(fpsfilename, TRUE);
            return;
        } else {
            log_info("Loaded OTR fingerprints");
            data_loaded = TRUE;
        }
    }

    if (data_loaded) {
        cons_show("Loaded OTR private key for %s", jid);
    }

    g_string_free(basedir, TRUE);
    g_string_free(keysfilename, TRUE);
    g_string_free(fpsfilename, TRUE);
    return;
}
Esempio n. 13
0
int main(int argc, char *argv[]) {
  char* remote_ip = DEFAULT_IP;
  uint32_t remote_port = DEFAULT_PORT;
  struct sockaddr_in addr;

  OTRL_INIT;

  us = otrl_userstate_create();
  
  if (argc > 1) {
    our_account = argv[1];
  }

  if (argc > 2) {
    our_protocol = argv[2];
  }

  if (argc > 3) {
    remote_ip = argv[3];
  }

  if (argc > 4) {
    remote_port = atoi(argv[4]);
  }

  if (argc > 5) {
    logfd = fopen(argv[5], "w");
  } else {
    logfd = fopen(our_account, "w");
  }

  pthread_mutex_lock(&log_mutex);
  fprintf(logfd, "Connecting to dummy_im: %s:%u\n", remote_ip, remote_port);
  fflush(logfd);
  pthread_mutex_unlock(&log_mutex);
  
  if ((sockfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
    fprintf(stderr, "Cannot create socket\n");
    exit(1);
  }

  memset(&addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = inet_addr(remote_ip);
  addr.sin_port = htons(remote_port);

  if (connect(sockfd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
    fprintf(stderr, "Cannot connect to server\n");
    exit(1);
  }

  pthread_mutex_init(&stdout_mutex, NULL);
  pthread_mutex_init(&log_mutex, NULL);
  

  /* pthread launch thread that receives from socket and wrties to stdout */
  pthread_t t_socker_reader;
  pthread_create(&t_socker_reader, NULL, receive_msgs, (void*) &sockfd);

  /* the main thread will receive commands from stdin and write to socket */
  while(1) {
    unsigned char buf[10];
    uint16_t command = 0;
    uint32_t id = 0;
    uint32_t size = 0;
    char* payload = 0;

    if (read_stdin(buf, 10) != 10) {
      fprintf(stderr, "Error reading from stdin\n");
      return;
    }

    command = ntohs(*((uint16_t*)(buf)));
    id = ntohl(*((uint32_t*)(buf+2)));
    size = ntohl(*((uint32_t*)(buf+6)));
    
    pthread_mutex_lock(&log_mutex);
    fprintf(logfd, "Received command msg: %X id: %u size: %u\n", command, id, size);
    fflush(logfd);
    pthread_mutex_unlock(&log_mutex);

    check_finished(command);
    payload = malloc(size);
    
    if (read_stdin(payload, size) != size) {
      fprintf(stderr, "Error reading from stdin\n");
      return;
    }
    
    pthread_mutex_lock(&log_mutex);
    
    fprintf(logfd, "Received payload\n");
    fflush(logfd);
    pthread_mutex_unlock(&log_mutex);
    
    process_command(command, id, size, &payload);

    free(payload);
  }

}
Esempio n. 14
0
static VALUE user_state_allocate(VALUE klass) {
  OtrlUserState us;

  us = otrl_userstate_create();
  return Data_Wrap_Struct(klass, NULL, user_state_deallocate, us);
}
Esempio n. 15
0
int main(){
	OTRL_INIT;
	OtrlUserState userstate;
	char *newmessage = NULL;
	char *nlmsg=NULL;
	OtrlMessageAppOps ui_ops;
	int sockfd, clientfd, recvbytes, recv_ret;
	socklen_t sin_size;
	char buf[1024], pwdbuf[1024];
	char *dbuf;
	struct sockaddr_in remote_addr, my_addr;
	fd_set fds;
	int one = 1;
	
	/* initialize ui callbacks */
	memset(&ui_ops, 0, sizeof(OtrlMessageAppOps));
	ui_ops.inject_message= inject_msg;
	ui_ops.gone_secure=gone_secure;
	printf("\033[31mStarting driver...\033[0m\n");

	/* initialize socket connection */
	sockfd = socket(AF_INET, SOCK_STREAM, 0);
	my_addr.sin_family=AF_INET;
	my_addr.sin_port= htons(3333);
	my_addr.sin_addr.s_addr = INADDR_ANY;
	bzero(&(my_addr.sin_zero),8);

	/* Allow rebinding to address */
	setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));

	if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) {
		perror("bind");
		exit(1);
	}
	if (listen(sockfd, 1) == -1) {
		perror("listen");
		exit(1);
	}
	sin_size = sizeof(struct sockaddr_in);
	if ((clientfd = accept(sockfd, (struct sockaddr *)&remote_addr, \
					&sin_size)) == -1) {
		perror("accept");
	}
	printf("\033[31mConnected to Bob\033[0m\n");

	/* create userstate, and read the private key */
	userstate = otrl_userstate_create();
	getcwd(pwdbuf, 1024);
	strcat(pwdbuf, "/private_key");
	otrl_privkey_read(userstate, pwdbuf);


	/* Clients send messages asynchronously*/
	while(1){
		FD_ZERO(&fds);
		FD_SET(0, &fds);
		FD_SET(clientfd, &fds);
		select(clientfd+1, &fds, NULL, NULL, NULL);
		if(FD_ISSET(0, &fds)){
			/* send message */
			fgets(buf, 1023, stdin);
			buf[strlen(buf)-1]= '\0';
			printf("\033[31mTo OTR:%d:\033[0m%s\n\033[0m",strlen(buf), buf);
			dbuf = strdup(buf);
			otrl_message_sending(userstate, &ui_ops, NULL, "*****@*****.**",
					"msn", "*****@*****.**", &dbuf, NULL, &newmessage,
					OTRL_FRAGMENT_SEND_SKIP, NULL, NULL, NULL, NULL);
			free(dbuf);
			nlmsg = (char*)malloc(strlen(newmessage)+2);			
			memcpy(nlmsg, newmessage, strlen(newmessage));
			nlmsg[strlen(newmessage)]='\n';
			nlmsg[strlen(newmessage)+1]='\0';
			send(clientfd, nlmsg, strlen(nlmsg), 0);
			printf("\033[31mTo network:%d:\033[35m%s\033[0m\n\033[0m", strlen(newmessage), newmessage);
		}else{
			/*receive message */
			recvbytes=recv(clientfd, buf, MAXDATASIZE, 0);
			if(recvbytes==0) break;
			recvbytes--;
			buf[recvbytes] = '\0';
			if(buf[recvbytes-1]=='\r'){
				 recvbytes--;
				 buf[recvbytes]='\0';
			}
			printf("\033[31mFrom network:%d:\033[35m %s\033[0m\n",recvbytes, buf);
			recv_ret=otrl_message_receiving(userstate, &ui_ops, &clientfd, "*****@*****.**",
					"msn", "*****@*****.**", buf, &newmessage, NULL,
					NULL, NULL, NULL, NULL);
			if(recv_ret==0)
				printf("\033[31mFrom OTR:%d:\033[0m %s\n", newmessage ? strlen(newmessage) : 0, newmessage);
		}
	}
	return 0;
}