コード例 #1
0
ファイル: qp_check.c プロジェクト: lavabit/magma
bool_t check_encoding_qp(void) {

	stringer_t *qp, *binary;
	byte_t buffer[QP_CHECK_SIZE];

	for (uint64_t i = 0; status() && i < QP_CHECK_ITERATIONS; i++) {

		// Fill the buffer with random data and convert the buffer to hex.
		if (rand_write(PLACER(buffer, QP_CHECK_SIZE)) != QP_CHECK_SIZE) {
			return false;
		}
		else if (!(qp = qp_encode(PLACER(buffer, QP_CHECK_SIZE)))) {
			return false;
		}

		//log_pedantic("qp = %.*s", st_length_int(qp), st_char_get(qp));

		// Convert the buffer back to binary and compare it with the original array.
		if (!(binary = qp_decode(qp))) {
			st_free(qp);
			return false;
		}
		else if (st_cmp_cs_eq(binary, PLACER(buffer, QP_CHECK_SIZE))) {
			st_free(binary);
			st_free(qp);
			return false;
		}

		st_free(binary);
		st_free(qp);
	}

	return true;
}
コード例 #2
0
bool_t check_encoding_zbase32(void) {

	stringer_t *zb32, *binary;
	byte_t buffer[ZBASE32_CHECK_SIZE];

	for (uint64_t i = 0; status() && i < ZBASE32_CHECK_ITERATIONS; i++) {

		// Fill the buffer with random data and convert the buffer to hex.
		if (rand_write(PLACER(buffer, ZBASE32_CHECK_SIZE)) != ZBASE32_CHECK_SIZE) {
			return false;
		}
		else if (!(zb32 = zbase32_encode(PLACER(buffer, ZBASE32_CHECK_SIZE)))) {
			return false;
		}

		//log_pedantic("zb32 = %.*s", st_length_int(zb32), st_char_get(zb32));

		// Convert the buffer back to binary and compare it with the original array.
		if (!(binary = zbase32_decode(zb32))) {
			st_free(zb32);
			return false;
		}
		else if (st_cmp_cs_eq(binary, PLACER(buffer, ZBASE32_CHECK_SIZE))) {
			st_free(binary);
			st_free(zb32);
			return false;
		}

		st_free(binary);
		st_free(zb32);
	}

	return true;
}
コード例 #3
0
stringer_t * check_rand_sthread(void) {

	size_t len;
	uint64_t num = 0;
	stringer_t *buffer;

	if (!(buffer = st_alloc(RAND_CHECK_SIZE_MAX))) {
		return st_dupe(NULLER("Buffer allocation error."));
	}

	for (int_t i = 0; status() && i < RAND_CHECK_ITERATIONS; i++) {

		num |= rand_get_int8();
		num |= rand_get_int16();
		num |= rand_get_int32();
		num |= rand_get_int64();

		num |= rand_get_uint8();
		num |= rand_get_uint16();
		num |= rand_get_uint32();
		num |= rand_get_uint64();

		// Pick a random length.
		len = (rand() % (RAND_CHECK_SIZE_MAX - RAND_CHECK_SIZE_MIN)) + RAND_CHECK_SIZE_MIN;

		if (rand_write(PLACER(st_char_get(buffer), len)) != len) {
			st_cleanup(buffer);
			return st_dupe(NULLER("Unable to fill the buffer with random data."));
		}
	}

	st_cleanup(buffer);

	// This time through we use the choices function since it will allocate its own output buffer.
	for (int_t i = 0; status() && i < RAND_CHECK_ITERATIONS; i++) {

		// Pick a random length.
		len = (rand() % (RAND_CHECK_SIZE_MAX - RAND_CHECK_SIZE_MIN)) + RAND_CHECK_SIZE_MIN;

		if (!(buffer = rand_choices("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", len))) {
			return st_dupe(NULLER("Unable to fill the buffer with random data."));
		}
		st_free(buffer);
	}

	return NULL;
}
コード例 #4
0
ファイル: string_check.c プロジェクト: lavabit/magma
bool_t check_string_write(void) {

	stringer_t *output = MANAGEDBUF(1024), *strings[3] = { MANAGEDBUF(32), MANAGEDBUF(64), MANAGEDBUF(128) };

	for (int i = 0; i < 3; i++) {
		rand_write(strings[i]);
	}

	if (st_write(NULL, strings[0], strings[1], strings[2]) != 224) {
		return false;
	}

	if (st_write(output, strings[0], strings[1], strings[2]) != 224) {
		return false;
	}

	return true;

}
コード例 #5
0
ファイル: hash_check.c プロジェクト: lavabit/magma
bool_t check_hash_sthread(chr_t *name) {

	stringer_t *hash;
	digest_t *digest;
	byte_t buffer[DIGEST_CHECK_SIZE];

	for (uint64_t i = 0; status() && i < DIGEST_CHECK_ITERATIONS; i++) {

		// Fill the buffer with random data and convert the buffer to encrypted.
		if (rand_write(PLACER(buffer, DIGEST_CHECK_SIZE)) != DIGEST_CHECK_SIZE) {
			return false;
		}
		//else if (!(digest = digest_name(NULLER(name))) || !(hash = hash_digest(digest, PLACER(buffer, DIGEST_CHECK_SIZE), NULL))) {
		else if (!(digest = digest_name(NULLER(name))) || !(hash = hash_digest(digest, PLACER(" ", 1), NULL))) {
			return false;
		}

		st_free(hash);
	}

	return true;
}
コード例 #6
0
ファイル: url_check.c プロジェクト: lavabit/magma
bool_t check_encoding_url(void) {

	bool_t result = true;
	stringer_t *url, *binary;
	byte_t buffer[URL_CHECK_SIZE];

	for (uint64_t i = 0; status() && result && i < URL_CHECK_ITERATIONS; i++) {

		// Fill the buffer with random data and convert the buffer to hex.
		if (rand_write(PLACER(buffer, URL_CHECK_SIZE)) != URL_CHECK_SIZE) {
			return false;
		}
		else if (!(url = url_encode(PLACER(buffer, URL_CHECK_SIZE)))) {
			return false;
		}
		else if (!url_valid_st(url)) {
			return false;
		}

		// Convert the buffer back to binary and compare it with the original array.
		if (!(binary = url_decode(url))) {
			st_free(url);
			return false;
		}
		else if (st_cmp_cs_eq(binary, PLACER(buffer, URL_CHECK_SIZE))) {
			result = false;
		}

		//log_pedantic("%-15.15s = %.*s", "plain", URL_CHECK_SIZE, buffer);
		//log_pedantic("%-15.15s = %.*s", "url", st_length_int(url), st_char_get(url));
		//log_pedantic("%-15.15s = %.*s", "decoded", st_length_int(binary), st_char_get(binary));

		st_free(binary);
		st_free(url);
	}

	return result;
}
コード例 #7
0
ファイル: keys_check.c プロジェクト: lavabit/magma
bool_t check_prime_keys_org_sthread(stringer_t *errmsg) {

	prime_t *holder = NULL;
	stringer_t *packed = NULL, *key = MANAGEDBUF(64);

	// Create a STACIE realm key.
	rand_write(key);

	// Allocate an org key.
	if (!(holder = prime_alloc(PRIME_ORG_KEY, NONE))) {
		st_sprint(errmsg, "Organizational key allocation failed.");
		return false;
	}

	prime_free(holder);

	// Generate an org key.
	if (!(holder = prime_key_generate(PRIME_ORG_KEY, NONE))) {
		st_sprint(errmsg, "Organizational key generation failed.");
		return false;
	}

	// Serialize the org key.
	else if (!(packed = prime_get(holder, BINARY, MANAGEDBUF(256)))) {
		st_sprint(errmsg, "Organizational key serialization failed.");
		prime_free(holder);
		return false;
	}

	prime_free(holder);

	// Unpack the serialized org key.
	if (!(holder = prime_set(packed, BINARY, NONE))) {
		st_sprint(errmsg, "Organizational key parsing failed.");
		return false;
	}

	// Encrypt the org key.
	else if (!(packed = prime_key_encrypt(key, holder, BINARY, MANAGEDBUF(256)))) {
		st_sprint(errmsg, "Organizational key encryption failed.");
		prime_free(holder);
		return false;
	}

	prime_free(holder);

	// Decrypt the org key.
	if (!(holder = prime_key_decrypt(key, packed, BINARY, NONE))) {
		st_sprint(errmsg, "Encrypted organizational key parsing failed.");
		return false;
	}

	prime_free(holder);

	// Perform the same checks, but this time make the functions
	// allocate memory for the output. Generate an org key.
	if (!(holder = prime_key_generate(PRIME_ORG_KEY, NONE))) {
		st_sprint(errmsg, "Organizational key generation failed.");
		return false;
	}

	// Serialize the org key.
	else if (!(packed = prime_get(holder, BINARY, NULL))) {
		st_sprint(errmsg, "Organizational key serialization failed.");
		prime_free(holder);
		return false;
	}

	prime_free(holder);

	// Unpack the serialized org key.
	if (!(holder = prime_set(packed, BINARY, NONE))) {
		st_sprint(errmsg, "Organizational key parsing failed.");
		st_free(packed);
		return false;
	}

	st_free(packed);

	// Encrypt the org key.
	if (!(packed = prime_key_encrypt(key, holder, BINARY, NULL))) {
		st_sprint(errmsg, "Organizational key encryption failed.");
		prime_free(holder);
		return false;
	}

	prime_free(holder);

	// Decrypt the org key.
	if (!(holder = prime_key_decrypt(key, packed, BINARY, NONE))) {
		st_sprint(errmsg, "Encrypted organizational key parsing failed.");
		st_free(packed);
		return false;
	}

	prime_free(holder);
	st_free(packed);

	return true;
}
コード例 #8
0
ファイル: signets_check.c プロジェクト: lavabit/magma
bool_t check_prime_signets_parameters_sthread(stringer_t *errmsg) {

	stringer_t *holder = NULL, *rand1 = MANAGEDBUF(32), *rand2 = MANAGEDBUF(128), *rand3 = MANAGEDBUF(64),
		*encrypted_key = NULL;
	prime_t *org_key = NULL, *org_signet = NULL, *user_key = NULL, *user_request = NULL, *user_signet = NULL,
		*rotation_key = NULL, *rotation_request = NULL, *rotation_signet = NULL, *check = NULL;

	// Create various PRIME types for use below.
	if (rand_write(rand1) != 32 || rand_write(rand2) != 128 || rand_write(rand3) != 64 ||
		!(org_key = prime_key_generate(PRIME_ORG_KEY, NONE)) || !(org_signet = prime_signet_generate(org_key)) ||
		!(user_key = prime_key_generate(PRIME_USER_KEY, NONE)) || !(user_request = prime_request_generate(user_key, NULL)) ||
		!(user_signet = prime_request_sign(user_request, org_key)) || !(rotation_key = prime_key_generate(PRIME_USER_KEY, NONE)) ||
		!(rotation_request = prime_request_generate(rotation_key, user_key)) || !(rotation_signet = prime_request_sign(rotation_request, org_key)) ||
		!(encrypted_key = prime_key_encrypt(rand3, user_key, ARMORED, MANAGEDBUF(512)))) {
		st_sprint(errmsg, "Signet/key creation for parameter testing failed.");
		prime_cleanup(org_key);
		prime_cleanup(org_signet);
		prime_cleanup(user_key);
		prime_cleanup(user_request);
		prime_cleanup(user_signet);
		prime_cleanup(rotation_key);
		prime_cleanup(rotation_request);
		prime_cleanup(rotation_signet);
		return false;
	}

	else if ((check = prime_signet_generate(user_key)) || (check = prime_signet_generate(user_request)) || (check = prime_signet_generate(user_signet)) ||
		(check = prime_request_generate(org_key, NULL)) || (check = prime_request_generate(org_signet, NULL)) || (check = prime_request_generate(user_request, NULL)) ||
		(check = prime_request_generate(user_signet, NULL)) || (check = prime_request_sign(org_key, user_key)) || (check = prime_request_sign(org_key, user_request)) ||
		(check = prime_request_sign(org_key, user_signet)) || (check = prime_request_sign(org_key, org_signet)) || (check = prime_request_sign(user_key, org_key)) ||
		(check = prime_request_sign(user_signet, org_key)) || prime_signet_validate(user_key, NULL) || prime_signet_validate(org_key, NULL) ||
		prime_signet_validate(org_signet, org_key) || prime_signet_validate(rotation_request, org_key) || prime_signet_validate(rotation_request, user_key) ||
		prime_signet_validate(org_signet, user_key) || prime_signet_validate(org_signet, user_signet) || prime_signet_validate(user_request, org_key) ||
		prime_signet_validate(user_request, user_key) || prime_signet_validate(user_request, org_signet) || prime_signet_validate(user_request, rotation_key) ||
		prime_signet_validate(user_signet, org_key) || prime_signet_validate(user_signet, user_key) || prime_signet_validate(user_signet, rotation_signet) ||
		prime_signet_validate(user_signet, user_request) || (check = prime_key_generate(PRIME_USER_SIGNET, NONE)) || (check = prime_key_generate(PRIME_ORG_SIGNET, NONE)) ||
		(check = prime_key_generate(PRIME_USER_SIGNING_REQUEST, NONE)) || (check = prime_get(NULL, BINARY, NULL)) ||
		(check = prime_get(NULL, BINARY, MANAGEDBUF(512))) || (check = prime_set(NULL, BINARY, NONE)) || (check = prime_set(NULL, ARMORED, NONE)) ||
		(holder = prime_signet_fingerprint(org_key, MANAGEDBUF(64))) || (holder = prime_signet_fingerprint(user_key, MANAGEDBUF(64))) ||
		(holder = prime_signet_fingerprint(user_request, MANAGEDBUF(64))) || (holder = prime_signet_fingerprint(org_signet, CONSTANT("TEST"))) ||
		(holder = prime_key_encrypt(NULL, org_key, BINARY, MANAGEDBUF(512))) || (holder = prime_key_encrypt(rand1, org_key, BINARY, MANAGEDBUF(512))) ||
		(holder = prime_key_encrypt(rand2, org_key, BINARY, MANAGEDBUF(512))) || (holder = prime_key_encrypt(rand3, org_signet, BINARY, MANAGEDBUF(512))) ||
		(holder = prime_key_encrypt(rand3, NULL, BINARY, MANAGEDBUF(512))) || (holder = prime_key_decrypt(NULL, encrypted_key, ARMORED, NONE)) ||
		(holder = prime_key_decrypt(rand3, NULL, ARMORED, NONE)) || (holder = prime_key_decrypt(rand1, encrypted_key, ARMORED, NONE)) ||
		(holder = prime_key_decrypt(rand2, encrypted_key, ARMORED, NONE)) || (holder = prime_key_decrypt(rand3, encrypted_key, BINARY, NONE)) ||
		(holder = prime_key_decrypt(rand3, prime_get(org_signet, BINARY, MANAGEDBUF(512)), BINARY, NONE)) ||
		(holder = prime_key_decrypt(rand3, prime_get(user_request, BINARY, MANAGEDBUF(512)), BINARY, NONE)) ||
		(holder = prime_key_decrypt(rand3, prime_get(user_signet, BINARY, MANAGEDBUF(512)), BINARY, NONE))) {

		st_sprint(errmsg, "Signet/key parameter checks failed.");
		prime_cleanup(check);
		prime_free(org_key);
		prime_free(org_signet);
		prime_free(user_key);
		prime_free(user_request);
		prime_free(user_signet);
		prime_free(rotation_key);
		prime_free(rotation_request);
		prime_free(rotation_signet);
	}

	prime_free(org_key);
	prime_free(org_signet);
	prime_free(user_key);
	prime_free(user_request);
	prime_free(user_signet);
	prime_free(rotation_key);
	prime_free(rotation_request);
	prime_free(rotation_signet);

	return true;
}