示例#1
0
文件: Tpw_tpmutil.c 项目: guoang/tpw
TPW_RESULT create_auth_key(TSS_HCONTEXT tss_context, TSS_UUID uuid, TSS_HKEY *auth_key, TSS_HKEY srk_key, char *auth, int authlen)
{
    TPW_RESULT result;
    TSS_FLAG aflags = TSS_KEY_TYPE_STORAGE | TSS_KEY_SIZE_2048 |
                       TSS_KEY_NON_VOLATILE | TSS_KEY_NOT_MIGRATABLE;
    TSS_HKEY tmp;

    result = create_key(tss_context, aflags, auth_key, srk_key, auth, authlen);
    if(TPW_SUCCESS != result)
    {
        Log_Text("create auth key", TPW_KEY_ERROR);
        return result;
    }

    result = keyUnregisterKey(tss_context, uuid);
    if(TPW_SUCCESS != result)
        ;
        //Log_Text("unreisterkey auth key", TPW_KEY_ERROR);
        //return result;
    else
        printf("unregisterKey success!!");

    result = keyRegisterKey(tss_context, *auth_key, uuid, SRK_UUID);
    if(TPW_SUCCESS != result)
    {
        Log_Text("reisterkey auth key", TPW_KEY_ERROR);
        return result;
    }
    return TPW_SUCCESS;


}
示例#2
0
文件: safelib.c 项目: delgor/4t4c
char *SAFE_strncpy (char *destination, const char *source, size_t buffer_size)
{
    // handy wrapper for operations we always forget, like checking for string terminations

    unsigned int index;

    // first off, check if buffer size is valid
    if (buffer_size <= 0)
    {
        Log_Text (LOG_MAIN, "SAFE_strncpy(): function called with invalid buffer size!\n");
        return (destination);
    }

    // also check if the destination buffer is valid
    if (destination == NULL)
    {
        Log_Text (LOG_MAIN, "SAFE_strncpy(): function called with invalid destination buffer!\n");
        return (destination);
    }

    // for each character we find up to buffer_size...
    for (index = 0; index < buffer_size; index++)
    {
        destination[index] = source[index]; // copy everything
        if (source[index] == 0)
            break; // don't copy beyond the end of source
    }
    destination[buffer_size - 1] = 0; // ...but let us set the terminator zero ourselves

    return (destination); // finished
}
示例#3
0
文件: safelib.c 项目: delgor/4t4c
int SAFE_vsnprintf (char *destination, size_t buffer_size, const char *fmt, va_list argptr)
{
    // handy wrapper for operations we always forget, like checking for string terminations.
    // This function should return the number of characters that would be written if there had
    // been enough buffer space to be C99 compatible.

    int result;

    // first off, check if buffer size is valid
    if (buffer_size <= 0)
    {
        Log_Text (LOG_MAIN, "SAFE_vsnprintf(): function called with invalid buffer size!\n");
        return (0);
    }

    // also check if the destination buffer is valid
    if (destination == NULL)
    {
        Log_Text (LOG_MAIN, "SAFE_vsnprintf(): function called with invalid destination buffer!\n");
        return (0);
    }

    // concatenate all the arguments in the destination string...
    result = vsnprintf_s (destination, buffer_size, buffer_size, fmt, argptr);
    if (result < 0)
        destination[buffer_size - 1] = 0; // ...but let us set the terminator zero ourselves

    return (result); // finished
}
示例#4
0
文件: safelib.c 项目: delgor/4t4c
char *SAFE_strncatf (char *destination, size_t buffer_size, const char *fmt, ...)
{
    // handy wrapper for operations we always forget, like checking for string terminations.
    // This function adds variable arguments to strcat(), printf()-style.

    va_list argptr;
    char message[1024];
    int index;
    int result;
    unsigned int index2;
    unsigned int amount_to_copy;

    // first off, check if buffer size is valid
    if (buffer_size <= 0)
    {
        Log_Text (LOG_MAIN, "SAFE_strncatf(): function called with invalid buffer size!\n");
        return (destination);
    }

    // also check if the destination buffer is valid
    if (destination == NULL)
    {
        Log_Text (LOG_MAIN, "SAFE_strncatf(): function called with invalid destination buffer!\n");
        return (destination);
    }

    // concatenate all the arguments in one string
    va_start (argptr, fmt);
    result = vsnprintf_s (message, sizeof (message), sizeof (message), fmt, argptr);
    va_end (argptr);
//   if (result < 0)
    message[sizeof (message) - 1] = 0; // ...but let us set the terminator zero ourselves

    // get the destination string end position
    index = strlen (destination);

    // see how much data we can copy
    amount_to_copy = strlen (message);
    if (amount_to_copy > buffer_size - index)
        amount_to_copy = buffer_size - index; // don't copy more than the space left

    // and finally append ourselves the right number of characters, not to overflow
    for (index2 = 0; index2 < amount_to_copy; index2++)
    {
        destination[index + index2] = message[index2]; // append message to destination string
        if (message[index2] == 0)
            break; // don't copy beyond the end of source
    }
    destination[index + amount_to_copy] = 0; // ...but let us set the terminator zero ourselves

    return (destination); // finished
}
示例#5
0
文件: Tpw_tpmutil.c 项目: guoang/tpw
TPW_RESULT create_key(TSS_HCONTEXT tss_context, TSS_FLAG aflags, TSS_HKEY *user_key, TSS_HKEY p_key, char *auth, int authlen)
{
    TSS_RESULT result;
    TSS_HPOLICY policy;
    if(!authlen)
        aflags |= TSS_KEY_NO_AUTHORIZATION;
    else
        aflags |= TSS_KEY_AUTHORIZATION;

    result = Tspi_Context_CreateObject(tss_context, TSS_OBJECT_TYPE_RSAKEY, aflags, user_key);

    if(TSS_SUCCESS != result)
    {
        Log_Text("create_key", TPW_KEY_ERROR);
        return TPW_KEY_ERROR;
    }

    if(authlen)
    {
        result = Tspi_Context_CreateObject(tss_context, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &policy); 
 
        result = policySetSecret(policy, authlen, auth);

        if(TSS_SUCCESS != result)
        {
            Log_Text("setPolicy_in_create_key", TPW_POLICY_ERROR);
            return TPW_POLICY_ERROR;
        }

        result = policyAssign(policy, *user_key);

        if(TSS_SUCCESS != result)
        {
            Log_Text("assignPolicy_in_create_key", TPW_POLICY_ERROR);
            return TPW_KEY_ERROR;
        }
    }

    result = keyCreateKey(*user_key, p_key, 0);
    if(TSS_SUCCESS != result)
    {
        Log_Text("Create_in_create_key", TPW_KEY_ERROR);
        return TPW_KEY_ERROR;
    }

    return TPW_SUCCESS;
}
示例#6
0
文件: Tpw_tpmutil.c 项目: guoang/tpw
TPW_RESULT load_auth_key(TSS_HCONTEXT tss_context, TSS_UUID auth_uuid, TSS_HKEY *auth_key, char *auth, int auth_len)
{
    TPW_RESULT result;

    result = load_key_and_auth(tss_context, auth_key, auth_uuid, TSS_PS_TYPE_SYSTEM, auth, auth_len);
    if(TPW_SUCCESS != result)
    {
        Log_Text("load auth key", TPW_KEY_ERROR);
        return result;
    }
    return TPW_SUCCESS;
}
示例#7
0
void CPlayer::DebugError(const char* logstr,...)
{
	static char logbuf[MAX_LOG_BUF_SIZE+1] = {0};
	va_list args;
	va_start(args, logstr);
	int len = _vsnprintf_s(logbuf, MAX_LOG_BUF_SIZE, logstr, args);
	va_end(args);
	if (len>0 && len<=MAX_LOG_BUF_SIZE )
	{
		Log_Text(LOGLEVEL_ERROR,logbuf);
		printf_s("Error: Player AID=%d PID=%d %s \n",m_AID,m_PID,logbuf);
	}
}
示例#8
0
文件: Tpw_tpmutil.c 项目: guoang/tpw
TPW_RESULT create_process_key(TSS_HCONTEXT tss_context, TSS_HKEY *process_key, TSS_HKEY auth_key)
{
    TPW_RESULT result;
    TSS_FLAG aflags = TSS_KEY_TYPE_SIGNING | TSS_KEY_SIZE_2048 |
                       TSS_KEY_NON_VOLATILE | TSS_KEY_NOT_MIGRATABLE;
    result = create_key(tss_context, aflags, process_key, auth_key, NULL, 0);
    if(TPW_SUCCESS != result)
    {
        Log_Text("create process key", TPW_KEY_ERROR);
        return result;
    }
    return TPW_SUCCESS;
}
示例#9
0
void CGameDBSocket::DebugError(const char* logstr,...)
{
	static char logbuf[MAX_LOG_BUF_SIZE+1] = {0};
	va_list args;
	va_start(args, logstr);
	int len = _vsnprintf_s(logbuf, MAX_LOG_BUF_SIZE, logstr, args);
	va_end(args);
	if (len>0 && len<=MAX_LOG_BUF_SIZE )
	{
		Log_Text(LOGLEVEL_ERROR,logbuf);
		printf_s("Error CGameDBSocket %s \n",logbuf);
	}
}
示例#10
0
文件: safelib.c 项目: delgor/4t4c
void *SAFE_realloc (void *allocation, int old_count, int new_count, size_t element_size, bool cleanup)
{
    // handy wrapper for things we always forget, like checking malloc's returned pointer and
    // ensuring the extra allocated space is zeroed out if necessary.

    void *new_allocation;

    // do we want to reallocate a void space ?
    if (new_count == 0)
    {
        SAFE_free (&allocation); // free it if needed
        return (NULL); // and return an empty pointer
    }

    // do we NOT actually need to reallocate ?
    if (old_count == new_count)
        return (allocation); // allocation is well-suited for the purpose already

    // try re allocating the requested size
    new_allocation = realloc (allocation, new_count * element_size);

#ifdef DEBUG_MALLOC
    // on debug mode, print out verbose info
    Log_Text (LOG_MAIN, "SAFE_realloc(): Reallocating (%d -> %d blocks) of %d bytes each (total: %d bytes) from 0x%x to 0x%x\n", old_count, new_count, element_size, new_count * element_size, allocation, new_allocation);
#endif

    if (new_allocation == NULL)
    {
        Log_Text (LOG_MAIN, "SAFE_realloc(): failure reallocating from %d to %d blocks of %d bytes at 0x%x!\n", old_count, new_count, element_size, allocation);
        return (new_allocation);
    }

    // zero out extra allocated content if necessary
    if (cleanup && (new_count > old_count))
        memset ((void *) ((unsigned long) new_allocation + (old_count * element_size)), 0, (new_count - old_count) * element_size);

    return (new_allocation); // here we are guaranteed to have some correctly reallocated space
}
示例#11
0
void CPlayer::DebugInfo(const char* logstr,...)
{
#ifdef LOG
	static char logbuf[MAX_LOG_BUF_SIZE+1] = {0};
	va_list args;
	va_start(args, logstr);
	int len = _vsnprintf_s(logbuf, MAX_LOG_BUF_SIZE, logstr, args);
	va_end(args);
	if (len>0 && len<=MAX_LOG_BUF_SIZE )
	{
		Log_Text(LOGLEVEL_INFO,logbuf);
	}
#endif
}
示例#12
0
文件: Tpw_tpmutil.c 项目: guoang/tpw
TPW_RESULT load_srk_key(TSS_HCONTEXT tss_context, TSS_HKEY *h_srk)
{
    BYTE srk_auth[] = SRK_WELLKNOWN;
    TPW_RESULT result;
    int srk_len = sizeof(srk_auth);
    result = load_key_and_auth(tss_context, h_srk, SRK_UUID, TSS_PS_TYPE_SYSTEM, srk_auth, srk_len);

    if(TPW_SUCCESS != result)
    {
        Log_Text("load key", TPW_KEY_ERROR);
        return result;
    }
    return TPW_SUCCESS;
}
示例#13
0
文件: safelib.c 项目: delgor/4t4c
void SAFE_free (void **address_of_pointer_to_allocation)
{
    // handy wrapper for things we always forget, like checking the buffer pointer's validity
    // before freeing it and nulling it out after it has been freed.

    if (address_of_pointer_to_allocation == NULL)
        return; // consistency check

#ifdef DEBUG_MALLOC
    // on debug mode, print out verbose info
    Log_Text (LOG_MAIN, "SAFE_free(): Freeing blocks at 0x%x\n", *address_of_pointer_to_allocation);
#endif

    // is it a valid block pointer ?
    if (*address_of_pointer_to_allocation != NULL)
        free (*address_of_pointer_to_allocation); // only free valid block pointers
    *address_of_pointer_to_allocation = NULL; // reset the pointer (ensures it won't get freed twice)

    return; // finished
}