コード例 #1
0
// Extract the information about the public RSA key and save it in the token
int dbRSAPub2session(sqlite3* /*db*/, CK_OBJECT_HANDLE objectID, CK_SESSION_HANDLE hSession)
{
	int result = 0;
	int i;
	CK_OBJECT_HANDLE hKey;
	CK_RV rv;

	CK_ATTRIBUTE pubTemplate[] = {
		{ CKA_CLASS,		NULL,	0 },
		{ CKA_KEY_TYPE,		NULL,	0 },
		{ CKA_TOKEN,		NULL,	0 },
		{ CKA_PRIVATE,		NULL,	0 },
		{ CKA_MODIFIABLE,	NULL,	0 },
		{ CKA_LABEL,		NULL,	0 },
		{ CKA_ID,		NULL,	0 },
		{ CKA_START_DATE,	NULL,	0 },
		{ CKA_END_DATE,		NULL,	0 },
		{ CKA_DERIVE,		NULL,	0 },
		{ CKA_SUBJECT,		NULL,	0 },
		{ CKA_ENCRYPT,		NULL,	0 },
		{ CKA_VERIFY,		NULL,	0 },
		{ CKA_VERIFY_RECOVER,	NULL,	0 },
		{ CKA_WRAP,		NULL,	0 },
		{ CKA_MODULUS,		NULL,	0 },
		{ CKA_PUBLIC_EXPONENT,	NULL,	0 }
	};

	for (i = 0; i < 17; i++)
	{
		result = getAttribute(objectID, &pubTemplate[i]);
		if (result)
		{
			freeTemplate(pubTemplate, 17);
			return 1;
		}
	}

	rv = p11->C_CreateObject(hSession, pubTemplate, 17, &hKey);
	if (rv != CKR_OK)
	{
		fprintf(stderr, "ERROR %X: Could not save the public key in the token. "
				"Skipping object %lu\n", (unsigned int)rv, objectID);
		result = 1;
	}
	else
	{
		printf("Object %lu has been migrated\n", objectID);
	}

	freeTemplate(pubTemplate, 17);

	return result;
}
コード例 #2
0
ファイル: GeneratorR.c プロジェクト: SirGFM/ggj16
/*
    free memory
*/
void freeRecipe(Recipe *r)
{
    for(int i=0;i<r->numTemplates;i++){
        freeTemplate(r->templates[i]);
    }
    free(r->id);
    free(r);
}
コード例 #3
0
// Extract the information about the private RSA key and save it in the token
int dbRSAPriv2session(sqlite3* /*db*/, CK_OBJECT_HANDLE objectID, CK_SESSION_HANDLE hSession)
{
	int result = 0;
	int i;
	CK_OBJECT_HANDLE hKey;
	CK_RV rv;

	CK_ATTRIBUTE privTemplate[] = {
		{ CKA_CLASS,			NULL,	0 },
		{ CKA_TOKEN,			NULL,	0 },
		{ CKA_PRIVATE,			NULL,	0 },
		{ CKA_MODIFIABLE,		NULL,	0 },
		{ CKA_LABEL,			NULL,	0 },
		{ CKA_KEY_TYPE,			NULL,	0 },
		{ CKA_ID,			NULL,	0 },
		{ CKA_START_DATE,		NULL,	0 },
		{ CKA_END_DATE,			NULL,	0 },
		{ CKA_DERIVE,			NULL,	0 },
		{ CKA_SUBJECT,			NULL,	0 },
		{ CKA_SENSITIVE,		NULL,	0 },
		{ CKA_DECRYPT,			NULL,	0 },
		{ CKA_SIGN,			NULL,	0 },
		{ CKA_SIGN_RECOVER,		NULL,	0 },
		{ CKA_UNWRAP,			NULL,	0 },
		{ CKA_EXTRACTABLE,		NULL,	0 },
		{ CKA_WRAP_WITH_TRUSTED,	NULL,	0 },
		{ CKA_MODULUS,			NULL,	0 },
		{ CKA_PUBLIC_EXPONENT,		NULL,	0 },
		{ CKA_PRIVATE_EXPONENT,		NULL,	0 },
		{ CKA_PRIME_1,			NULL,	0 },
		{ CKA_PRIME_2,			NULL,	0 }
// SoftHSM v1 did not store these values
//		{ CKA_EXPONENT_1,		NULL,	0 },
//		{ CKA_EXPONENT_2,		NULL,	0 },
//		{ CKA_COEFFICIENT,		NULL,	0 }
	};

	for (i = 0; i < 23; i++)
	{
		result = getAttribute(objectID, &privTemplate[i]);
		if (result)
		{
			freeTemplate(privTemplate, 23);
			return 1;
		}
	}

	rv = p11->C_CreateObject(hSession, privTemplate, 23, &hKey);
	if (rv != CKR_OK)
	{
		fprintf(stderr, "ERROR %X: Could not save the private key in the token. "
				"Skipping object %lu\n", (unsigned int)rv, objectID);
		result = 1;
	}
	else
	{
		printf("Object %lu has been migrated\n", objectID);
	}

	freeTemplate(privTemplate, 23);

	return result;
}