Exemplo n.º 1
0
int copyObjectAttributes(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, struct p11Object_t *pObject,
		struct attributesForObject_t *attr)
{
	unsigned int i;
	int index, rc = CKR_OK;

	for (i = 0; (attr[i].attribute.type && (rc == CKR_OK)) ; i++) {
		index = findAttributeInTemplate(attr[i].attribute.type, pTemplate, ulCount);

		if (index == -1) { /* The attribute is not present - is it optional? */
			if (attr[i].condition == AC_DEFAULT) {
				rc = addAttribute(pObject, &attr[i].attribute);
			} else if (attr[i].condition != AC_OPTIONAL) { /* the attribute is not optional */
#ifdef DEBUG
				debug("[createKeyObject] Error creating object - the following attribute is not present!");
				dumpAttribute(&(attr[i].attribute));
#endif
				return CKR_TEMPLATE_INCOMPLETE;
			}
		} else {
			rc = addAttribute(pObject, &pTemplate[index]);
		}
	}

	return rc;
}
/**
 *  Constructor for the certificate object
 */
int createCertificateObject(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, struct p11Object_t *object)
{
	unsigned int i;
	int index, rc;

	rc = createStorageObject(pTemplate, ulCount, object);

	if (rc) {
		return rc;
	}

	for (i = 0; i < NEEDED_ATTRIBUTES_CERTIFICATEOBJECT; i++) {
		index = findAttributeInTemplate(attributesCertificateObject[i].attribute.type, pTemplate, ulCount);

		if (index == -1) { /* The attribute is not present - is it optional? */
			if (attributesCertificateObject[i].optional) {
				addAttribute(object, &attributesCertificateObject[i].attribute);
			} else { /* the attribute is not optional */
				removeAllAttributes(object);
				memset(object, 0x00, sizeof(*object));
				return CKR_TEMPLATE_INCOMPLETE;
			}
		} else {
			addAttribute(object, &pTemplate[index]);
		}
	}

#ifdef DEBUG
	dumpAttributeList(object);
#endif

	return 0;
}
Exemplo n.º 3
0
int createStorageObject(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, struct p11Object_t *pObject)
{
	int index;
	unsigned int i, rc;

	rc = createObject(pTemplate, ulCount, pObject);

	if (rc) {
		return rc;
	}

	for (i = 0; attributesStorageObject[i].attribute.type; i++) {
		index = findAttributeInTemplate(attributesStorageObject[i].attribute.type, pTemplate, ulCount);

		if (index == -1) { /* The attribute is not present - is it optional? */
			if (attributesStorageObject[i].condition == AC_DEFAULT) {
				addAttribute(pObject, &attributesStorageObject[i].attribute);
			} else if (attributesStorageObject[i].condition != AC_OPTIONAL) { /* the attribute is not optional */
#ifdef DEBUG
				debug("[createStorageObject] Error creating storage object - the following attribute is not present!");
				dumpAttribute(&(attributesStorageObject[i].attribute));
#endif
				removeAllAttributes(pObject);
				return CKR_TEMPLATE_INCOMPLETE;
			}
		} else {
			addAttribute(pObject, &pTemplate[index]);

			/* The object is public */
			if ((pTemplate[index].type == CKA_PRIVATE ) &&
					(*(CK_BBOOL *)pTemplate[index].pValue == CK_FALSE)) {
				pObject->publicObj = TRUE;
			}

			/* The object is a token object */
			if ((pTemplate[index].type == CKA_TOKEN ) &&
					(*(CK_BBOOL *)pTemplate[index].pValue == CK_TRUE)) {
				pObject->tokenObj = TRUE;
			}
		}
	}

	return 0;
}
Exemplo n.º 4
0
int createObject(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, struct p11Object_t *pObject)
{
	int index;

	/* Check if the CKA_CLASS attribute is present */

	index = findAttributeInTemplate(CKA_CLASS, pTemplate, ulCount);

	if (index == -1) { /* Attribute is not present */
#ifdef DEBUG
		debug("[createObject] Error creating object - the attribute CKA_CLASS is not present!");
#endif
		return CKR_TEMPLATE_INCOMPLETE;
	} else {
		addAttribute(pObject, &pTemplate[index]);
	}

	return 0;
}