Esempio n. 1
0
static Token_t *sp_get_perm_token (const SEC_PERM *pp, Permissions_t id)
{
	Token_t			*tp;
	unsigned char		*p;
	DDS_SecurityReqData	data;
	DDS_PermissionsToken	*token;
	size_t			cred_len;
	DDS_ReturnCode_t	error;

	ARG_NOT_USED (pp)

	tp = xmalloc (sizeof (Token_t));
	if (!tp)
		return (NULL);

	token = DDS_DataHolder__alloc (GMCLASSID_SECURITY_PERMISSIONS_TOKEN);
	if (!token) {
		xfree (tp);
		return (NULL);
	}
	token->binary_value1 = DDS_OctetSeq__alloc ();
	if (!token->binary_value1)
		goto free_dh;

	error = dds_seq_require (token->binary_value1, 32);
	if (error)
		goto free_dh;

	data.handle = id;
	data.data = NULL;
	data.kdata = NULL;
	data.length = 0;
	data.rlength = 0;
	error = sec_access_control_request (DDS_GET_PERM_CRED, &data);
	if (error)
		goto free_dh;

	cred_len = data.rlength;
	p = xmalloc (cred_len);
	if (!p)
		goto free_dh;

	data.data = p;
	data.kdata = NULL;
	data.length = cred_len;
	error = sec_access_control_request (DDS_GET_PERM_CRED, &data);
	if (error)
		goto free_p;

	error = sec_hash_sha256 ((unsigned char *) p,
				 cred_len,
				 DDS_SEQ_DATA (*token->binary_value1));
	xfree (p);
	if (error)
		goto free_dh;

	tp->data = token;
	tp->nusers = 1;
	tp->encoding = 0;
	tp->integral = 0;
	tp->next = NULL;
	return (tp);

    free_p:
    	xfree (p);
    free_dh:
	DDS_DataHolder__free (token);
	xfree (tp);
	return (NULL);
}
Esempio n. 2
0
static Token_t *sd_get_perm_token (const SEC_PERM *pp, Permissions_t perm)
{
	Token_t			*token;
	DDS_IdentityToken	*tp;
	DDS_OctetSeq		*p;
	PermissionsData_t	*pdp;
	DDS_SecurityReqData	data;
	char			buf [128];
	char			*bp;
	MD5_CONTEXT		md5;
	DDS_ReturnCode_t	ret;

	ARG_NOT_USED (pp)

	token = xmalloc (sizeof (Token_t));
	if (!token)
		return (NULL);

	pdp = perm_lookup (perm, NULL);
	if (!pdp)
		goto no_perm;

	data.handle = pdp->id;
	data.data = NULL;
	data.length = 0;
	ret = sec_authentication_request (DDS_GET_ID_NAME, &data);
	if (ret || !data.rlength)
		goto no_perm;

	if (data.rlength >= sizeof (buf)) {
		bp = Alloc (data.rlength);
		if (!bp)
			goto no_perm;
	}
	else
		bp = buf;

	data.handle = pdp->id;
	data.data = bp;
	data.length = data.rlength;
	ret = sec_authentication_request (DDS_GET_ID_NAME, &data);
	if (ret)
		goto done;

	tp = DDS_DataHolder__alloc (GMCLASSID_SECURITY_DTLS_PERM_TOKEN);
	if (!tp)
		goto done;

	tp->binary_value1 = p = DDS_OctetSeq__alloc ();
	if (!p)
		goto out_of_mem;

	ret = dds_seq_require (p, 16);
	if (ret) {
		DDS_DataHolder__free (tp);
		return (NULL);
	}
	md5_init (&md5);
	md5_update (&md5, (unsigned char *) bp, strlen (bp));
	md5_final (DDS_SEQ_DATA (*p), &md5);
	if (bp != buf)
		Free (bp);

	token->data = tp;
	token->encoding = PID_V_PERMS;
	token->integral = 0;
	token->nusers = 1;
	token->next = NULL;
	return (token);

    out_of_mem:
	DDS_DataHolder__free (tp);

    done:
	if (bp != buf)
		Free (bp);

    no_perm:
	xfree (token);
	return (NULL);
}