crv = pk11_Attribute2SecItem(NULL,&pubKey,object,CKA_NETSCAPE_DB);
crv = pk11_Attribute2SSecItem(NULL,&pubKey,object,CKA_NETSCAPE_DB);
pk11_handlePrivateKeyObject(PK11Session *session,PK11Object *object,CK_KEY_TYPE key_type){    CK_BBOOL cktrue = CK_TRUE;    CK_BBOOL encrypt = CK_TRUE;    CK_BBOOL recover = CK_TRUE;    CK_BBOOL wrap = CK_TRUE;    CK_BBOOL ckfalse = CK_FALSE;    SECItem mod;    CK_RV crv;    switch (key_type) {    case CKK_RSA:	if ( !pk11_hasAttribute(object, CKA_MODULUS)) {	    return CKR_TEMPLATE_INCOMPLETE;	}	if ( !pk11_hasAttribute(object, CKA_PUBLIC_EXPONENT)) {	    return CKR_TEMPLATE_INCOMPLETE;	}	if ( !pk11_hasAttribute(object, CKA_PRIVATE_EXPONENT)) {	    return CKR_TEMPLATE_INCOMPLETE;	}	if ( !pk11_hasAttribute(object, CKA_PRIME_1)) {	    return CKR_TEMPLATE_INCOMPLETE;	}	if ( !pk11_hasAttribute(object, CKA_PRIME_2)) {	    return CKR_TEMPLATE_INCOMPLETE;	}	if ( !pk11_hasAttribute(object, CKA_EXPONENT_1)) {	    return CKR_TEMPLATE_INCOMPLETE;	}	if ( !pk11_hasAttribute(object, CKA_EXPONENT_2)) {	    return CKR_TEMPLATE_INCOMPLETE;	}	if ( !pk11_hasAttribute(object, CKA_COEFFICIENT)) {	    return CKR_TEMPLATE_INCOMPLETE;	}	/* make sure Netscape DB attribute is set correctly */	crv = pk11_Attribute2SSecItem(NULL, &mod, object, CKA_MODULUS);	if (crv != CKR_OK) return crv;	crv = pk11_forceAttribute(object, CKA_NETSCAPE_DB, 						pk11_item_expand(&mod));	if (mod.data) PORT_Free(mod.data);	if (crv != CKR_OK) return crv;		break;    case CKK_DSA:	if ( !pk11_hasAttribute(object, CKA_SUBPRIME)) {	    return CKR_TEMPLATE_INCOMPLETE;	}	if ( !pk11_hasAttribute(object, CKA_NETSCAPE_DB)) {	    return CKR_TEMPLATE_INCOMPLETE;	}    case CKK_DH:	if ( !pk11_hasAttribute(object, CKA_PRIME)) {	    return CKR_TEMPLATE_INCOMPLETE;	}	if ( !pk11_hasAttribute(object, CKA_BASE)) {	    return CKR_TEMPLATE_INCOMPLETE;	}	if ( !pk11_hasAttribute(object, CKA_VALUE)) {	    return CKR_TEMPLATE_INCOMPLETE;	}	encrypt = CK_FALSE;	recover = CK_FALSE;	wrap = CK_FALSE;	break;    default:	return CKR_ATTRIBUTE_VALUE_INVALID;    }    crv = pk11_defaultAttribute(object,CKA_SUBJECT,NULL,0);    if (crv != CKR_OK)  return crv;     crv = pk11_defaultAttribute(object,CKA_SENSITIVE,&cktrue,sizeof(CK_BBOOL));    if (crv != CKR_OK)  return crv;     crv = pk11_defaultAttribute(object,CKA_EXTRACTABLE,&cktrue,sizeof(CK_BBOOL));    if (crv != CKR_OK)  return crv;     crv = pk11_defaultAttribute(object,CKA_DECRYPT,&encrypt,sizeof(CK_BBOOL));    if (crv != CKR_OK)  return crv;     crv = pk11_defaultAttribute(object,CKA_SIGN,&cktrue,sizeof(CK_BBOOL));    if (crv != CKR_OK)  return crv;     crv = pk11_defaultAttribute(object,CKA_SIGN_RECOVER,&recover,							     sizeof(CK_BBOOL));    if (crv != CKR_OK)  return crv;     crv = pk11_defaultAttribute(object,CKA_UNWRAP,&wrap,sizeof(CK_BBOOL));    if (crv != CKR_OK)  return crv;     /* the next two bits get modified only in the key gen and token cases */    crv = pk11_forceAttribute(object,CKA_ALWAYS_SENSITIVE,						&ckfalse,sizeof(CK_BBOOL));    if (crv != CKR_OK)  return crv;     crv = pk11_forceAttribute(object,CKA_NEVER_EXTRACTABLE,						&ckfalse,sizeof(CK_BBOOL));    if (crv != CKR_OK)  return crv;     if (pk11_isTrue(object,CKA_TOKEN)) {	PK11Slot *slot = session->slot;	NSSLOWKEYPrivateKey *privKey;	char *label;	SECStatus rv = SECSuccess;	SECItem pubKey;	if (slot->keyDB == NULL) {	    return CKR_TOKEN_WRITE_PROTECTED;	}	privKey=pk11_mkPrivKey(object,key_type);	if (privKey == NULL) return CKR_HOST_MEMORY;	label = pk11_getString(object,CKA_LABEL);	crv = pk11_Attribute2SecItem(NULL,&pubKey,object,CKA_NETSCAPE_DB);	if (crv != CKR_OK) {	    if (label) PORT_Free(label);	    nsslowkey_DestroyPrivateKey(privKey);	    return CKR_TEMPLATE_INCOMPLETE;	}	rv = nsslowkey_StoreKeyByPublicKey(object->slot->keyDB,			privKey, &pubKey, label, object->slot->password);	if (label) PORT_Free(label);	object->handle = pk11_mkHandle(slot,&pubKey,PK11_TOKEN_TYPE_PRIV);	if (pubKey.data) PORT_Free(pubKey.data);	nsslowkey_DestroyPrivateKey(privKey);	if (rv != SECSuccess) return CKR_DEVICE_ERROR;    } else {	object->objectInfo = pk11_mkPrivKey(object,key_type);	if (object->objectInfo == NULL) return CKR_HOST_MEMORY;	object->infoFree = (PK11Free) nsslowkey_DestroyPrivateKey;	/* now NULL out the sensitive attributes */	if (pk11_isTrue(object,CKA_SENSITIVE)) {	    pk11_nullAttribute(object,CKA_PRIVATE_EXPONENT);	    pk11_nullAttribute(object,CKA_PRIME_1);	    pk11_nullAttribute(object,CKA_PRIME_2);	    pk11_nullAttribute(object,CKA_EXPONENT_1);	    pk11_nullAttribute(object,CKA_EXPONENT_2);	    pk11_nullAttribute(object,CKA_COEFFICIENT);	}    }    return CKR_OK;}