Exemplo n.º 1
0
int xattrs_compare(const char *filename1, const char *filename2)
{
	char *new_xattrs;
	char *old_xattrs;
	size_t new_xattrs_len;
	size_t old_xattrs_len;
	int ret = 0;

	xattrs_get_blob(filename1, &old_xattrs, &old_xattrs_len);
	xattrs_get_blob(filename2, &new_xattrs, &new_xattrs_len);

	if ((old_xattrs_len == 0) && (new_xattrs_len == 0)) {
		return ret;
	}

	if (old_xattrs_len != new_xattrs_len) {
		ret = -1;
		goto out;
	}

	if (memcmp(old_xattrs, new_xattrs, old_xattrs_len) != 0) {
		ret = -1;
	}
out:
	if (old_xattrs_len != 0) {
		free(old_xattrs);
	}

	if (new_xattrs_len != 0) {
		free(new_xattrs);
	}

	return ret;
}
Exemplo n.º 2
0
static void hmac_compute_key(const char *filename,
			     const struct update_stat *updt_stat,
			     char *key, size_t *key_len, bool use_xattrs)
{
	char *xattrs_blob = (void *)0xdeadcafe;
	size_t xattrs_blob_len = 0;

	if (use_xattrs) {
		xattrs_get_blob(filename, &xattrs_blob, &xattrs_blob_len);
	}

	hmac_sha256_for_data(key, (const unsigned char *)updt_stat,
			     sizeof(struct update_stat),
			     (const unsigned char *)xattrs_blob,
			     xattrs_blob_len);

	if (hash_is_zeros(key)) {
		*key_len = 0;
	} else {
		*key_len = SWUPD_HASH_LEN - 1;
	}

	if (xattrs_blob_len != 0) {
		free(xattrs_blob);
	}
}
Exemplo n.º 3
0
static void hmac_compute_key(const char *file,
			     const struct update_stat *updt_stat,
			     char **key, size_t *key_len, bool use_xattrs)
{
	char *xattrs_blob = (void *)0xdeadcafe;
	size_t xattrs_blob_len = 0;

	if (use_xattrs)
		xattrs_get_blob(file, &xattrs_blob, &xattrs_blob_len);
	*key = hmac_sha256_for_data((const unsigned char *)updt_stat,
				    sizeof(struct update_stat),
				    (const unsigned char *)xattrs_blob,
				    xattrs_blob_len);

	if (*key == NULL)
		*key_len = 0;
	else
		*key_len = strlen((const char*)*key);

	if (xattrs_blob_len != 0)
		free(xattrs_blob);
}