Esempio n. 1
0
int  test_invalid_cguids(uint32_t aw)
{
    ZS_status_t ret;
    int tag = 0;
    testname[0] = "#test0: flush object with invalid cguids.";
    fprintf(fp,"****** async write = %d ******\n",aw);
    fprintf(fp,"%s\n",testname[0]);

    ret = FlushObject(-1, "xxx", 4);
    if(ZS_FAILURE == ret)
    {
        tag += 1;
        result[aw][0][0] =1;
    }
    ret = FlushObject(0, "xxx", 4);
    if(ZS_FAILURE == ret)
    {
        tag += 1;
        result[aw][0][1] =1;
    }
    ret = FlushObject(1048580, "xxx", 4);
    if(ZS_FAILURE == ret)
    {
        tag += 1;
        result[aw][0][2] +=1;
    }
    return (3 == tag);
}
Esempio n. 2
0
/* This function is called to process a _TPM_Hash_Start() indication. */
LIB_EXPORT void
_TPM_Hash_Start(
		void
		)
{
    TPM_RC              result;
    TPMI_DH_OBJECT      handle;
    // If a DRTM sequence object exists, free it up
    if(g_DRTMHandle != TPM_RH_UNASSIGNED)
	{
	    FlushObject(g_DRTMHandle);
	    g_DRTMHandle = TPM_RH_UNASSIGNED;
	}
    // Create an event sequence object and store the handle in global
    // g_DRTMHandle. A TPM_RC_OBJECT_MEMORY error may be returned at this point
    // The NULL value for the first parameter will cause the sequence structure to
    // be allocated without being set as present. This keeps the sequence from
    // being left behind if the sequence is terminated early.
    result = ObjectCreateEventSequence(NULL, &g_DRTMHandle);
    // If a free slot was not available, then free up a slot.
    if(result != TPM_RC_SUCCESS)
	{
	    // An implementation does not need to have a fixed relationship between
	    // slot numbers and handle numbers. To handle the general case, scan for
	    // a handle that is assigned and free it for the DRTM sequence.
	    // In the reference implementation, the relationship between handles and
	    // slots is fixed. So, if the call to ObjectCreateEvenSequence()
	    // failed indicating that all slots are occupied, then the first handle we
	    // are going to check (TRANSIENT_FIRST) will be occupied. It will be freed
	    // so that it can be assigned for use as the DRTM sequence object.
	    for(handle = TRANSIENT_FIRST; handle < TRANSIENT_LAST; handle++)
		{
		    // try to flush the first object
		    if(IsObjectPresent(handle))
			break;
		}
	    // If the first call to find a slot fails but none of the slots is occupied
	    // then there's a big problem
	    pAssert(handle < TRANSIENT_LAST);
	    // Free the slot
	    FlushObject(handle);
	    // Try to create an event sequence object again.  This time, we must
	    // succeed.
	    result = ObjectCreateEventSequence(NULL, &g_DRTMHandle);
	    if(result != TPM_RC_SUCCESS)
		FAIL(FATAL_ERROR_INTERNAL);
	}
    return;
}
Esempio n. 3
0
/* This function is called to close out the event sequence and clean up the hash context states. */
void
ObjectTerminateEvent(
		     void
		     )
{
    HASH_OBJECT         *hashObject;
    int                  count;
    BYTE                 buffer[MAX_DIGEST_SIZE];
    hashObject = (HASH_OBJECT *)HandleToObject(g_DRTMHandle);
    // Don't assume that this is a proper sequence object
    if(hashObject->attributes.eventSeq)
	{
	    // If it is, close any open hash contexts. This is done in case
	    // the cryptographic implementation has some context values that need to be
	    // cleaned up (hygiene).
	    //
	    for(count = 0; CryptHashGetAlgByIndex(count) != TPM_ALG_NULL; count++)
		{
		    CryptHashEnd(&hashObject->state.hashState[count], 0, buffer);
		}
	    // Flush sequence object
	    FlushObject(g_DRTMHandle);
	}
    g_DRTMHandle = TPM_RH_UNASSIGNED;
}
Esempio n. 4
0
int test_invalid_object(uint32_t aw)
{
    ZS_status_t ret;
    int tag = 0;
    testname[1] = "#test1: flush object with invalid objects.";
    fprintf(fp,"****** async write = %d ******\n",aw);
    fprintf(fp,"%s\n",testname[1]);

    for(int i = 0; i < 3; i++)
    {
        ret = OpenContainer("test1", 1, aw, i);
        if(ZS_SUCCESS == ret)
        {
            ret = FlushObject(cguid, "xxx", 4);
            if(ZS_OBJECT_UNKNOWN == ret)
            {
                result[aw][1][i] = 1;
                tag += 1;
            }
            (void)CloseContainer(cguid);
            (void)DeleteContainer(cguid);
        }
    }
    return (3 == tag);
}
Esempio n. 5
0
static ZS_status_t
io()
{
	ZS_status_t ret;

	uint32_t wr_flags = 0;
	uint32_t i = 0;

	char key[256] = {'\0'};
	char value[256] = {'\0'};

	char *data = NULL;
	uint64_t len = 0;

	fprintf(fp,"****** io started ******\n");

	fprintf(fp,"****** Writing objects *******\n");
	for (i = 0; i < MAX_ITERATION; i++) {
		snprintf(key, 255, "%s_%d", "key", i);
		snprintf(value, 255, "%s_%d", "value", i);
		if(ZS_SUCCESS == (ret = WriteObject(cguid, key, value, wr_flags)))
		{
			fprintf(fp,"write sucessful: key%s\n", key);
		} else {
			fprintf(fp,"write failed: key=%s error=%s\n", key, ZSStrError(ret));
			goto exit_io;
		}

		/*
		 * Flush few object
		 */
		if (0 == (i % 2)) {
			if(ZS_SUCCESS == (ret = FlushObject(cguid, key)))
			{
				fprintf(fp,"flush sucessful: key%s\n", key);
			} else {
				fprintf(fp,"flush failed: key=%s error=%s\n", key, ZSStrError(ret));
				goto exit_io;
			}
		}
	}

	/*
	 * Issue read
	 */
	fprintf(fp,"****** Reading objects *******\n");

	for (i = 0; i < MAX_ITERATION; i++) {
		snprintf(key, 255, "%s_%d", "key", i);
		if(ZS_SUCCESS == (ret = ReadObject(cguid, key, &data, &len)))
		{
			fprintf(fp,"read successful: key=%s data=%s\n", key, data);
		} else {
			fprintf(fp,"read failed: read key= %s error=%s\n", key, ZSStrError(ret));
			goto exit_io;
		}
	}
exit_io:
	return ret;
}
Esempio n. 6
0
int test_basic_check_1(uint32_t aw)
{
    ZS_status_t ret;
    int tag = 0;
    testname[3] = "#test3:basic check for flush object.";
    fprintf(fp,"****** async write = %d ******\n",aw);
    fprintf(fp,"%s\n",testname[3]);

    for(int i = 0; i < 3; i++)
    {
        ret = OpenContainer("test3", 1, aw, i);
        if(ZS_SUCCESS == ret)
        {
            if(ZS_SUCCESS == WriteObject(cguid, "xxx", 4, "sadf", 5, 1))
            {
                ret = FlushObject(cguid, "xxx", 4);
                if(ZS_SUCCESS == ret)
                {
                    result[aw][3][i] += 1;
                }
                if(ZS_SUCCESS == WriteObject(cguid, "xxx", 4, "yyy", 4, 2))
                {
                    ret = FlushObject(cguid, "xxx", 4);
                    if(ZS_SUCCESS == ret)
                    {
                        result[aw][3][i] += 1;
                    }
                }
                (void)DeleteObject(cguid, "xxx", 4);
            }
            (void)CloseContainer(cguid);
            (void)DeleteContainer(cguid);
        }
        if(2 == result[aw][3][i])
        {
            result[aw][3][i] = 1;
            tag += 1;
        } else {
            result[aw][3][i] = 0;
        }
    }
    return (3 == tag);
}
Esempio n. 7
0
/* This function is called to process a _TPM_Hash_End() indication. */
LIB_EXPORT void
_TPM_Hash_End(
	      void
	      )
{
    UINT32          i;
    TPM2B_DIGEST    digest;
    HASH_OBJECT    *hashObject;
    TPMI_DH_PCR     pcrHandle;
    // If the DRTM handle is not being used, then either _TPM_Hash_Start has not
    // been called, _TPM_Hash_End was previously called, or some other command
    // was executed and the sequence was aborted.
    if(g_DRTMHandle == TPM_RH_UNASSIGNED)
	return;
    // Get DRTM sequence object
    hashObject = (HASH_OBJECT *)HandleToObject(g_DRTMHandle);
    // Is this _TPM_Hash_End after Startup or before
    if(TPMIsStarted())
	{
	    // After
	    // Reset the DRTM PCR
	    PCRResetDynamics();
	    // Extend the DRTM_PCR.
	    pcrHandle = PCR_FIRST + DRTM_PCR;
	    // DRTM sequence increments restartCount
	    gr.restartCount++;
	}
    else
	{
	    pcrHandle = PCR_FIRST + HCRTM_PCR;
	    g_DrtmPreStartup = TRUE;
	}
    // Complete hash and extend PCR, or if this is an HCRTM, complete
    // the hash, reset the H-CRTM register (PCR[0]) to 0...04, and then
    // extend the H-CRTM data
    for(i = 0; i < HASH_COUNT; i++)
	{
	    TPMI_ALG_HASH       hash = CryptHashGetAlgByIndex(i);
	    // make sure that the PCR is implemented for this algorithm
	    if(PcrIsAllocated(pcrHandle,
			      hashObject->state.hashState[i].hashAlg))
		{
		    // Complete hash
		    digest.t.size = CryptHashGetDigestSize(hash);
		    CryptHashEnd2B(&hashObject->state.hashState[i], &digest.b);
		    PcrDrtm(pcrHandle, hash, &digest);
		}
	}
    // Flush sequence object.
    FlushObject(g_DRTMHandle);
    g_DRTMHandle = TPM_RH_UNASSIGNED;
    return;
}
Esempio n. 8
0
int test_invalid_key_keylen(uint32_t aw)
{
    ZS_status_t ret;
    int tag = 0;
    testname[2] = "#test2: open c/ write o/flush object with wrong key/keylen.";
    fprintf(fp,"****** async write = %d ******\n",aw);
    fprintf(fp,"%s\n",testname[2]);

    for(int i = 0; i < 3; i++)
    {
        ret = OpenContainer("test2", 1, aw, i);
        if(ZS_SUCCESS == ret)
        {
            ret = WriteObject(cguid, "aaa", 4, "sadf", 5, 1);
            if(ZS_SUCCESS == ret)
            {
                /*
                                ret = FlushObject(cguid, NULL, 4);
                                if(ZS_OBJECT_UNKNOWN == ret)
                                {
                                    result[aw][2][i] += 1;
                                }
                */
                ret = FlushObject(cguid, "aa", 4);
                if(ZS_OBJECT_UNKNOWN == ret)
                {
                    result[aw][2][i] += 1;
                }
                ret = FlushObject(cguid, "aaaaa", 4);
                if(ZS_OBJECT_UNKNOWN == ret)
                {
                    result[aw][2][i] += 1;
                }
                ret = FlushObject(cguid, "aaa", 0);
                if(ZS_OBJECT_UNKNOWN == ret)
                {
                    result[aw][2][i] += 1;
                }
                ret = FlushObject(cguid, "aaa", 1);
                if(ZS_OBJECT_UNKNOWN == ret)
                {
                    result[aw][2][i] += 1;
                }
                ret = FlushObject(cguid, "aaa", 10);
                if(ZS_OBJECT_UNKNOWN == ret)
                {
                    result[aw][2][i] += 1;
                }
                (void)DeleteObject(cguid, "aaa", 4);
            }
            (void)CloseContainer(cguid);
            (void)DeleteContainer(cguid);
        }
        if(5 == result[aw][2][i])
        {
            result[aw][2][i] = 1;
            tag += 1;
        } else {
            result[aw][2][i] = 0;
        }
    }
    return (3 == tag);
}