コード例 #1
0
ファイル: sdp.c プロジェクト: Studio-Link/baresip
/**
 * Decode an SDP fingerprint value
 *
 * @param attr SDP attribute value
 * @param hash Returned hash method
 * @param md   Returned message digest
 * @param sz   Message digest size, set on return
 *
 * @return 0 if success, otherwise errorcode
 *
 * Reference: RFC 4572
 */
int sdp_fingerprint_decode(const char *attr, struct pl *hash,
			   uint8_t *md, size_t *sz)
{
	struct pl f;
	const char *p;
	int err;

	if (!attr || !hash)
		return EINVAL;

	err = re_regex(attr, str_len(attr), "[^ ]+ [0-9A-F:]+", hash, &f);
	if (err)
		return err;

	if (md && sz) {
		if (*sz < (f.l+1)/3)
			return EOVERFLOW;

		for (p = f.p; p < (f.p+f.l); p += 3) {
			*md++ = ch_hex(p[0]) << 4 | ch_hex(p[1]);
		}

		*sz = (f.l+1)/3;
	}

	return 0;
}
コード例 #2
0
ファイル: auth.c プロジェクト: AmesianX/restund
static bool nonce_validate(char *nonce, time_t now, const struct sa *src)
{
	uint8_t nkey[MD5_SIZE], ckey[MD5_SIZE];
	uint64_t nv[3];
	struct pl pl;
	int64_t age;
	unsigned i;

	pl.p = nonce;
	pl.l = str_len(nonce);

	if (pl.l < NONCE_MIN_SIZE || pl.l > NONCE_MAX_SIZE) {
		restund_info("auth: bad nonce length (%zu)\n", pl.l);
		return false;
	}

	for (i=0; i<sizeof(nkey); i++) {
		nkey[i]  = ch_hex(*pl.p++) << 4;
		nkey[i] += ch_hex(*pl.p++);
		pl.l -= 2;
	}

	nv[0] = pl_x64(&pl);
	nv[1] = auth.secret;
	nv[2] = sa_hash(src, SA_ADDR);

	md5((uint8_t *)nv, sizeof(nv), ckey);

	if (memcmp(nkey, ckey, MD5_SIZE)) {
		restund_debug("auth: invalid nonce (%j)\n", src);
		return false;
	}

	age = now - nv[0];

	if (age < 0 || age > auth.nonce_expiry) {
		restund_debug("auth: nonce expired, age: %lli secs\n", age);
		return false;
	}

	return true;
}
コード例 #3
0
ファイル: uric.c プロジェクト: ClearwaterCore/libre-upstream
static int comp_unescape(struct re_printf *pf, const struct pl *pl, esc_h *eh)
{
	size_t i;
	int err = 0;

	if (!pf || !pl || !eh)
		return EINVAL;

	for (i=0; i<pl->l && !err; i++) {
		const char c = pl->p[i];

		if (eh(c)) {
			err = pf->vph(&c, 1, pf->arg);
			continue;
		}

		if ('%' == c) {
			if (i < (pl->l - 2)) {
				const uint8_t hi = ch_hex(pl->p[++i]);
				const uint8_t lo = ch_hex(pl->p[++i]);
				const char b = hi<<4 | lo;
				err = pf->vph(&b, 1, pf->arg);
			}
			else {
				DEBUG_WARNING("unescape: short uri (%u)\n", i);
				return EBADMSG;
			}
		}
		else {
			DEBUG_WARNING("unescape: illegal '%c' in %r\n",
				      c, pl);
			return EINVAL;
		}
	}

	return err;
}