Blame src/client/toks_client_token.c

abad9f
/*********************************************************/
abad9f
/*  toksvc: a framework-native token broker service      */
abad9f
/*  Copyright (C) 2020  Z. Gilboa                        */
abad9f
/*  Released under GPLv2 and GPLv3; see COPYING.TOKSVC.  */
abad9f
/*********************************************************/
abad9f
abad9f
#include <psxtypes/psxtypes.h>
abad9f
#include <ntapi/ntapi.h>
abad9f
abad9f
#include <toksvc/toksvc.h>
abad9f
#include "toksvc_driver_impl.h"
abad9f
abad9f
int32_t toks_client_token_to_str(
abad9f
	struct toks_driver_ctx *        dctx,
abad9f
	struct toks_token_string *      toks)
abad9f
{
abad9f
	struct _nt_port_keys *	keys;
abad9f
	unsigned char *		uch;
abad9f
abad9f
	keys = toks_get_driver_keys(dctx);
abad9f
	uch  = (unsigned char *)toks->token;
abad9f
abad9f
	ntapi->tt_generic_memset(
abad9f
		toks->token,0,
abad9f
		sizeof(toks->token));
abad9f
abad9f
	uch[8]  = '-';
abad9f
	uch[17] = '-';
abad9f
	uch[26] = '-';
abad9f
	uch[35] = '-';
abad9f
	uch[44] = '-';
abad9f
abad9f
	ntapi->tt_uint32_to_hex_utf8(keys->key[0],&uch[0]);
abad9f
	ntapi->tt_uint32_to_hex_utf8(keys->key[1],&uch[9]);
abad9f
	ntapi->tt_uint32_to_hex_utf8(keys->key[2],&uch[18]);
abad9f
	ntapi->tt_uint32_to_hex_utf8(keys->key[3],&uch[27]);
abad9f
	ntapi->tt_uint32_to_hex_utf8(keys->key[4],&uch[36]);
abad9f
	ntapi->tt_uint32_to_hex_utf8(keys->key[5],&uch[45]);
abad9f
abad9f
	return NT_STATUS_SUCCESS;
abad9f
}
abad9f
abad9f
int32_t toks_client_str_to_token(
abad9f
	struct toks_driver_ctx *            dctx,
abad9f
	const struct toks_token_string *    toks)
abad9f
{
abad9f
	struct _nt_port_keys *	keys;
abad9f
	unsigned char *		uch;
abad9f
	uint32_t		key[6];
abad9f
abad9f
	keys = toks_get_driver_keys(dctx);
abad9f
	uch  = (unsigned char *)toks->token;
abad9f
abad9f
	if ((uch[8] != '-') || (uch[17] != '-') || (uch[26] != '-')
abad9f
		|| (uch[35] != '-') || (uch[44] != '-'))
abad9f
		return NT_STATUS_INVALID_PARAMETER;
abad9f
abad9f
	if (ntapi->tt_hex_utf8_to_uint32(&uch[0],&key[0]))
abad9f
		return NT_STATUS_INVALID_PARAMETER;
abad9f
abad9f
	if (ntapi->tt_hex_utf8_to_uint32(&uch[9],&key[1]))
abad9f
		return NT_STATUS_INVALID_PARAMETER;
abad9f
abad9f
	if (ntapi->tt_hex_utf8_to_uint32(&uch[18],&key[2]))
abad9f
		return NT_STATUS_INVALID_PARAMETER;
abad9f
abad9f
	if (ntapi->tt_hex_utf8_to_uint32(&uch[27],&key[3]))
abad9f
		return NT_STATUS_INVALID_PARAMETER;
abad9f
abad9f
	if (ntapi->tt_hex_utf8_to_uint32(&uch[36],&key[4]))
abad9f
		return NT_STATUS_INVALID_PARAMETER;
abad9f
abad9f
	if (ntapi->tt_hex_utf8_to_uint32(&uch[45],&key[5]))
abad9f
		return NT_STATUS_INVALID_PARAMETER;
abad9f
abad9f
	if (uch[53])
abad9f
		return NT_STATUS_INVALID_PARAMETER;
abad9f
abad9f
	keys->key[0] = key[0];
abad9f
	keys->key[1] = key[1];
abad9f
	keys->key[2] = key[2];
abad9f
	keys->key[3] = key[3];
abad9f
	keys->key[4] = key[4];
abad9f
	keys->key[5] = key[5];
abad9f
abad9f
	return NT_STATUS_SUCCESS;
abad9f
}