Example #1
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);
				}
			}
		}
	}
}
Example #2
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);
		}
	}
}
Example #3
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 ***");
}