Пример #1
0
void pkcs11_logger_log_flag(CK_ULONG flags, CK_ULONG flag_value, const char *flag_name)
{
	if (flags & flag_value)
		pkcs11_logger_log("%s: TRUE", flag_name);
	else
		pkcs11_logger_log("%s: FALSE", flag_name);
}
Пример #2
0
void pkcs11_logger_log_attribute_template_with_indent(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, int level)
{
	int i = 0;
	char indent[level*3+1];
	char horizontal_line[] = "--------------------------------------";


	if ((NULL == pTemplate) || (ulCount < 1))
		return;
	
	for(i = 0; i < level*3+1; i++)
	{
		indent[i] = ' ';
	}
	if(i > 1) {
		indent[i++] = '|';
	}
	indent[i] = '\0';

	for (i = 0; i < ulCount; i++)
	{
		pkcs11_logger_log("%s  Attribute %d", indent, i);
		pkcs11_logger_log("%s   Attribute: %lu (%s)", indent, pTemplate[i].type, pkcs11_logger_translate_ck_attribute(pTemplate[i].type));
		pkcs11_logger_log("%s   pValue: %p", indent, pTemplate[i].pValue);
		pkcs11_logger_log("%s   ulValueLen: %lu", indent, pTemplate[i].ulValueLen);

		if (NULL != pTemplate[i].pValue)
		{
			char *value = NULL;
			if(0x40000000 & pTemplate[i].type)
			{
				pkcs11_logger_log("%s   *pValue: is nested attribute array", indent);
				pkcs11_logger_log("%s   %s", indent, horizontal_line);
				pkcs11_logger_log_attribute_template_with_indent(pTemplate[i].pValue, pTemplate[i].ulValueLen / sizeof(CK_ATTRIBUTE), level + 1);
				pkcs11_logger_log("%s   %s", indent, horizontal_line);
			}
			else
			{
				value = pkcs11_logger_translate_ck_byte_ptr(pTemplate[i].pValue, pTemplate[i].ulValueLen);
				if (NULL != value)
				{
					pkcs11_logger_log("%s   *pValue: HEX(%s)", indent, value);
					CALL_N_CLEAR(free, value);
				}
				else
				{
					pkcs11_logger_log("%s   *pValue: *** cannot be displayed ***", indent);
				}
			}
		}
	}
}
Пример #3
0
void pkcs11_logger_log_byte_array(const char *name, CK_BYTE_PTR byte_array, CK_ULONG byte_array_len)
{
	if (NULL != byte_array)
	{
		char *array = NULL;
		array = pkcs11_logger_translate_ck_byte_ptr(byte_array, byte_array_len);
		if (NULL != array)
		{
			pkcs11_logger_log("%s: HEX(%s)", name, array);
			CALL_N_CLEAR(free, array);
		}
		else
		{
			pkcs11_logger_log("%s: *** cannot be displayed ***", name);
		}
	}
}
Пример #4
0
void pkcs11_logger_log_nonzero_string(const char *name, const unsigned char *nonzero_string, CK_ULONG nonzero_string_len)
{
	if (NULL != nonzero_string)
	{
		unsigned char *zero_string = NULL;
		zero_string = (unsigned char*) malloc(nonzero_string_len + 1);
		if (NULL != zero_string)
		{
			memset(zero_string, 0, nonzero_string_len + 1);
			memcpy(zero_string, nonzero_string, nonzero_string_len);
			pkcs11_logger_log("%s: %s", name, zero_string);
			CALL_N_CLEAR(free, zero_string);
		}
		else
		{
			pkcs11_logger_log("%s: *** cannot be displayed ***", name);
		}
	}
}
Пример #5
0
// Logs array of cryptoki attributes
void pkcs11_logger_log_attribute_template(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount)
{
    CK_ULONG i = 0;
    
    if ((NULL == pTemplate) || (ulCount < 1))
        return;
    
    pkcs11_logger_log("  *** Begin attribute template ***");
    
    for (i = 0; i < ulCount; i++)
    {
        pkcs11_logger_log("  Attribute %d", i);
        pkcs11_logger_log("   Attribute: %lu (%s)", pTemplate[i].type, pkcs11_logger_translate_ck_attribute(pTemplate[i].type));
        pkcs11_logger_log("   pValue: %p", pTemplate[i].pValue);
        pkcs11_logger_log("   ulValueLen: %lu", pTemplate[i].ulValueLen);

        if (NULL != pTemplate[i].pValue)
        {
            char *value = NULL;

            if ((pTemplate[i].type & CKF_ARRAY_ATTRIBUTE) == CKF_ARRAY_ATTRIBUTE)
            {
                if (0 == (pTemplate[i].ulValueLen % sizeof(CK_ATTRIBUTE)))
                {
                    pkcs11_logger_log_attribute_template(pTemplate[i].pValue, pTemplate[i].ulValueLen / sizeof(CK_ATTRIBUTE));
                    continue;
                }
            }

            value = pkcs11_logger_translate_ck_byte_ptr(pTemplate[i].pValue, pTemplate[i].ulValueLen);
            if (NULL != value)
            {
                pkcs11_logger_log("   *pValue: HEX(%s)", value);
                CALL_N_CLEAR(free, value);
            }
            else
            {
                pkcs11_logger_log("   *pValue: *** cannot be displayed ***");
            }
        }
    }

    pkcs11_logger_log("  *** End attribute template ***");
}
Пример #6
0
void pkcs11_logger_log_separator(void)
{
	char str_time[20];
	current_time_str(str_time, sizeof(str_time));
	pkcs11_logger_log("****************************** %s ***", str_time);
}
Пример #7
0
void pkcs11_logger_log_output_params(void)
{
	pkcs11_logger_log("Output");
}
Пример #8
0
void pkcs11_logger_log_input_params(void)
{
	pkcs11_logger_log("Input");
}
Пример #9
0
void pkcs11_logger_log_function_exit(CK_RV rv)
{
	pkcs11_logger_log("Returning %lu (%s)", rv, pkcs11_logger_translate_ck_rv(rv));
}
Пример #10
0
void pkcs11_logger_log_function_enter(const char *function)
{
	pkcs11_logger_log_separator();
	pkcs11_logger_log("Calling %s", function);
}