Esempio n. 1
0
AJ_Status TestCreds()
{
    AJ_Status status = AJ_OK;
    AJ_GUID localGuid;
    AJ_GUID remoteGuid;
    char str[33];
    AJ_PeerCred*peerCredRead;
    int i = 0;
    AJ_GUID peerGuid;
    uint8_t secretLen = 24;
    uint8_t secret[24];
    uint32_t expiration = 50898;
    char hex[100];

    AJ_AlwaysPrintf(("Start TestCreds\n"));
    status = AJ_GetLocalGUID(&localGuid);
    if (AJ_OK != status) {
        return status;
    }
    AJ_GUID_FromString(&localGuid, str);

    AJ_InfoPrintf(("TestCreds() Layout Print\n"));
    AJ_NVRAM_Layout_Print();
    memset(&peerGuid, 1, sizeof(AJ_GUID));
    for (i = 0; i < secretLen; i++) {
        secret[i] = i;
    }
    AJ_GUID_ToString(&peerGuid, hex, 100);
    AJ_AlwaysPrintf(("AJ_StorePeerSecret guid %s\n", hex));
    status = AJ_StorePeerSecret(&peerGuid, secret, secretLen, expiration);
    memcpy(&remoteGuid, &peerGuid, sizeof(AJ_GUID)); // backup the GUID
    if (AJ_OK != status) {
        AJ_AlwaysPrintf(("AJ_StorePeerSecret failed = %d\n", status));
        return status;
    }
    AJ_NVRAM_Layout_Print();

    AJ_InfoPrintf(("TestCreds() StoreCred() Layout Print\n"));
    AJ_NVRAM_Layout_Print();

    AJ_GUID_ToString(&remoteGuid, hex, 100);
    AJ_AlwaysPrintf(("AJ_GetPeerCredential guid %s\n", hex));
    status = AJ_GetPeerCredential(&remoteGuid, &peerCredRead);
    if (AJ_OK != status) {
        AJ_AlwaysPrintf(("AJ_GetPeerCredential failed = %d\n", status));
        return status;
    }

    if (0 != memcmp(peerCredRead->id, &peerGuid, peerCredRead->idLen)) {
        AJ_AlwaysPrintf(("The retrieved credential does not match\n"));
        AJ_FreeCredential(peerCredRead);
        return AJ_ERR_FAILURE;

    }
    if (peerCredRead->dataLen != secretLen) {
        AJ_AlwaysPrintf(("no match for secretLen got %d expected %d\n",
                         peerCredRead->dataLen, secretLen));
        AJ_FreeCredential(peerCredRead);
        return AJ_ERR_FAILURE;
    }
    if (secretLen > 0) {
        if (0 != memcmp(peerCredRead->data, secret, secretLen)) {
            AJ_AlwaysPrintf(("no match for secret\n"));
            AJ_FreeCredential(peerCredRead);
            return AJ_ERR_FAILURE;
        }
    }
    if (peerCredRead->expiration != expiration) {
        AJ_AlwaysPrintf(("no match for expiration got %d expected %d\n",
                         peerCredRead->expiration, expiration));
        AJ_FreeCredential(peerCredRead);
        return AJ_ERR_FAILURE;
    }

    status = AJ_DeletePeerCredential(&remoteGuid);
    if (AJ_OK != status) {
        AJ_AlwaysPrintf(("AJ_DeleteCredential failed = %d\n", status));
        AJ_FreeCredential(peerCredRead);
        return status;
    }

    AJ_FreeCredential(peerCredRead);
    if (AJ_ERR_FAILURE == AJ_GetPeerCredential(&remoteGuid, NULL)) {
        status = AJ_OK;
    } else {
        return AJ_ERR_FAILURE;
    }
    AJ_InfoPrintf(("TestCreds() Layout Print\n"));
    AJ_NVRAM_Layout_Print();

    AJ_ClearCredentials();
    if (AJ_ERR_FAILURE == AJ_GetPeerCredential(&remoteGuid, NULL)) {
        status = AJ_OK;
    } else {
        return AJ_ERR_FAILURE;
    }
    AJ_InfoPrintf(("TestCreds() Layout Print\n"));
    AJ_NVRAM_Layout_Print();
    AJ_AlwaysPrintf(("TestCreds done.\n"));
    return status;
}
Esempio n. 2
0
AJ_Status TestNvramDelete()
{
    AJ_Status status = AJ_OK;
    AJ_NV_DATASET* nvramHandle;

    if (tid1 % 2 == 1) {
#ifndef OBS_ONLY
        if (AJ_NVRAM_Exist(tid1)) {
            AJ_ASSERT(AJ_NVRAM_Delete(tid1) == AJ_OK);
        }
        AJ_InfoPrintf(("LAYOUT AFTER DELETE 1\n"));
        AJ_NVRAM_Layout_Print();

        if (AJ_NVRAM_Exist(tid2)) {
            AJ_ASSERT(AJ_NVRAM_Delete(tid2) == AJ_OK);
        }
        AJ_InfoPrintf(("LAYOUT AFTER DELETE 2\n"));
        AJ_NVRAM_Layout_Print();

        if (AJ_NVRAM_Exist(tid3)) {
            AJ_ASSERT(AJ_NVRAM_Delete(tid3) == AJ_OK);
        }
        AJ_InfoPrintf(("LAYOUT AFTER DELETE 3\n"));
        AJ_NVRAM_Layout_Print();

        if (AJ_NVRAM_Exist(tid4)) {
            AJ_ASSERT(AJ_NVRAM_Delete(tid4) == AJ_OK);
        }
        AJ_InfoPrintf(("LAYOUT AFTER DELETE 4\n"));
        AJ_NVRAM_Layout_Print();
#endif

        if (AJ_NVRAM_Exist(AJ_NVRAM_ID_FOR_APPS)) {
            AJOBS_Info_Test emptyInfo;
            AJ_Status status = AJ_OK;
            size_t size = sizeof(AJOBS_Info_Test);

            memset(&emptyInfo, 0, sizeof(emptyInfo));
            AJ_AlwaysPrintf(("Going to write Info values: state=%d, ssid=%s authType=%d pc=%s\n", emptyInfo.state, emptyInfo.ssid, emptyInfo.authType, emptyInfo.pc));
            //AJ_NV_DATASET* nvramHandle = AJ_NVRAM_Open(AJ_NVRAM_ID_CREDS_MAX + 1, "w", size); //PROPERTY STORE DEVICE ID
            nvramHandle = AJ_NVRAM_Open(AJ_NVRAM_ID_FOR_APPS, "w", size);
            if (nvramHandle != NULL) {
                int sizeWritten = AJ_NVRAM_Write(&emptyInfo, size, nvramHandle);
                status = AJ_NVRAM_Close(nvramHandle);
                if (sizeWritten != size) {
                    status = AJ_ERR_WRITE;
                    goto _TEST_NVRAM_DELETE_EXIT;
                }
            }
            //nvramHandle = AJ_NVRAM_Open(AJ_NVRAM_ID_CREDS_MAX + 1, "r", 0); //PROPERTY STORE DEVICE ID
            nvramHandle = AJ_NVRAM_Open(AJ_NVRAM_ID_FOR_APPS, "r", 0);
            if (nvramHandle != NULL) {
                int sizeRead = AJ_NVRAM_Read(&emptyInfo, size, nvramHandle);
                status = AJ_NVRAM_Close(nvramHandle);
                if (sizeRead != sizeRead) {
                    status = AJ_ERR_READ;
                } else {
                    AJ_AlwaysPrintf(("Read Info values: state=%d, ssid=%s authType=%d pc=%s\n", emptyInfo.state, emptyInfo.ssid, emptyInfo.authType, emptyInfo.pc));
                }
            }
        }
        AJ_InfoPrintf(("LAYOUT AFTER DELETE OBS\n"));
        AJ_NVRAM_Layout_Print();
    } else {
        AJ_NVRAM_Clear();
        AJ_InfoPrintf(("LAYOUT AFTER CLEAR ALL\n"));
        AJ_NVRAM_Layout_Print();
    }
    return status;

_TEST_NVRAM_DELETE_EXIT:
    AJ_NVRAM_Close(nvramHandle);
    return status;

}
Esempio n. 3
0
AJ_Status TestNVRAM()
{
    uint16_t id = 16;
    AJ_NV_DATASET* handle = NULL;
    int i = 0;
    size_t bytes = 0;
    AJ_Status status = AJ_OK;
    AJ_NVRAM_Layout_Print();

    {
        handle = AJ_NVRAM_Open(id, "w", 40 + 5);
        AJ_NVRAM_Layout_Print();
        AJ_ASSERT(handle);

        for (i = 0; i < 10; i++) {
            bytes = AJ_NVRAM_Write(&i, sizeof(i), handle);
            if (bytes != sizeof(i)) {
                status = AJ_ERR_FAILURE;
                goto _TEST_NVRAM_EXIT;
            }
        }
        {
            uint8_t buf[3] = { 11, 22, 33 };
            uint8_t buf2[2] = { 44, 55 };
            bytes = AJ_NVRAM_Write(buf, sizeof(buf), handle);
            if (bytes != sizeof(buf)) {
                status = AJ_ERR_FAILURE;
                goto _TEST_NVRAM_EXIT;
            }
            bytes = AJ_NVRAM_Write(buf2, sizeof(buf2), handle);
            if (bytes != sizeof(buf2)) {
                status = AJ_ERR_FAILURE;
                goto _TEST_NVRAM_EXIT;
            }

        }
        AJ_NVRAM_Close(handle);
        AJ_InfoPrintf(("TestNVRAM() Layout Print\n"));
        AJ_NVRAM_Layout_Print();

        handle = AJ_NVRAM_Open(id, "r", 0);
        AJ_ASSERT(handle);
        for (i = 0; i < 10; i++) {
            int data = 0;
            bytes = AJ_NVRAM_Read(&data, sizeof(data), handle);
            if (bytes != sizeof(data) || data != i) {
                status = AJ_ERR_FAILURE;
                goto _TEST_NVRAM_EXIT;
            }
        }
        for (i = 1; i < 6; i++) {
            uint8_t data = 0;
            AJ_NVRAM_Read(&data, 1, handle);
            if (data != i * 11) {
                status = AJ_ERR_FAILURE;
                goto _TEST_NVRAM_EXIT;
            }
        }
        AJ_NVRAM_Close(handle);
    }

    if (AJ_NVRAM_Exist(id + 1)) {
        AJ_ASSERT(AJ_NVRAM_Delete(id + 1) == AJ_OK);
    }

    // Force storage compaction
    for (i = 0; i < 12; i++) {
        if (i == 6) {
            handle = AJ_NVRAM_Open(id + 2, "w", 100);
            AJ_ASSERT(handle);
            status = AJ_NVRAM_Close(handle);
            if (AJ_OK != status) {
                goto _TEST_NVRAM_EXIT;
            }
            continue;
        }
        handle = AJ_NVRAM_Open(id + 1, "w", 200);
        AJ_ASSERT(handle);
        status = AJ_NVRAM_Close(handle);
        if (AJ_OK != status) {
            goto _TEST_NVRAM_EXIT;
        }
    }
    AJ_InfoPrintf(("Compaction Layout Print\n"));
    AJ_NVRAM_Layout_Print();

_TEST_NVRAM_EXIT:
    //AJ_NVRAM_Close(handle);
    return status;
}
Esempio n. 4
0
AJ_Status TestNvramRead() {
    //uint16_t id = 0;
    AJ_NV_DATASET* d1 = NULL;
    AJ_NV_DATASET* d2 = NULL;
    AJ_NV_DATASET* d3 = NULL;
    AJ_NV_DATASET* d4 = NULL;
    int i = 0;
    size_t bytes1, bytes2, bytes3, bytes4 = 0;
    AJ_Status status = AJ_OK;

    AJ_NVRAM_Layout_Print();

#ifdef READ_STRESS
    while (TRUE) {
#endif
    //AJ_InfoPrintf(("LAYOUT AFTER OPEN - READ MODE\n"));
    //AJ_NVRAM_Layout_Print();

    d1 = AJ_NVRAM_Open(tid1, "r", 0);
    //d1 = AJ_NVRAM_Open(66, "r", 0); //NEGATIVE READ TEST
    AJ_ASSERT(d1);
    for (i = 0; i < d1->capacity / 4; i++) {
        int data1 = 0;
        bytes1 = AJ_NVRAM_Read(&data1, sizeof(data1), d1);
        if (bytes1 != sizeof(data1) || data1 != i) {
            return AJ_ERR_FAILURE;
        }
#ifdef SHOW_READ
        if (i % 10 == 0) {
            AJ_InfoPrintf(("Dataset 1 capacity %u curPos %u flash value: %u\n", d1->capacity, d1->curPos, data1));
        }
#endif
    }
    if (d1 != NULL) {
        AJ_NVRAM_Close(d1);
        AJ_ASSERT(d1);
    }

    d2 = AJ_NVRAM_Open(tid2, "r", 0);
    AJ_ASSERT(d2);
    for (i = 0; i < d2->capacity / 4; i++) {
        int data2 = 0;
        bytes2 = AJ_NVRAM_Read(&data2, sizeof(data2), d2);
        if (bytes2 != sizeof(data2) || data2 != i) {
            return AJ_ERR_FAILURE;
        }
#ifdef SHOW_READ
        if (i % 10 == 0) {
            AJ_InfoPrintf(("Dataset 2 capacity %u curPos %u flash value: %u\n", d2->capacity, d2->curPos, data2));
        }
#endif
    }
    if (d2 != NULL) {
        AJ_NVRAM_Close(d2);
        AJ_ASSERT(d2);
    }

    d3 = AJ_NVRAM_Open(tid3, "r", 0);
    AJ_ASSERT(d3);
    for (i = 0; i < d3->capacity / 4; i++) {
        int data3 = 0;
        bytes3 = AJ_NVRAM_Read(&data3, sizeof(data3), d3);
        if (bytes3 != sizeof(data3) || data3 != i) {
            return AJ_ERR_FAILURE;
        }
#ifdef SHOW_READ
        if (i % 10 == 0) {
            AJ_InfoPrintf(("Dataset 3 capacity %u curPos %u flash value: %u\n", d3->capacity, d3->curPos, data3));
        }
#endif
    }
    if (d3 != NULL) {
        AJ_NVRAM_Close(d3);
        AJ_ASSERT(d3);
    }

    d4 = AJ_NVRAM_Open(tid4, "r", 0);
    AJ_ASSERT(d4);
    for (i = 0; i < d4->capacity / 4; i++) {
        int data4 = 0;
        bytes4 = AJ_NVRAM_Read(&data4, sizeof(data4), d4);
        if (bytes4 != sizeof(data4) || data4 != i) {
            return AJ_ERR_FAILURE;
        }
#ifdef SHOW_READ
        if (i % 10 == 0) {
            AJ_InfoPrintf(("Dataset 4 capacity %u curPos %u flash value: %u\n", d4->capacity, d4->curPos, data4));
        }
#endif
    }
    if (d4 != NULL) {
        AJ_NVRAM_Close(d4);
        AJ_ASSERT(d4);
    }

    AJ_InfoPrintf(("LAYOUT AFTER READ --- END capacity %u curPos %u\n", d4->capacity, d4->curPos));
    AJ_NVRAM_Layout_Print();

#ifdef READ_STRESS
}
#endif
    return status;
}
Esempio n. 5
0
AJ_Status TestNvramWrite()
{
    AJ_NV_DATASET* d1 = NULL;
    AJ_NV_DATASET* d2 = NULL;
    AJ_NV_DATASET* d3 = NULL;
    AJ_NV_DATASET* d4 = NULL;
    int i = 0;
    uint16_t cap1, cap2, cap3, cap4 = 0;
    size_t bytes1, bytes2, bytes3, bytes4 = 0;
    AJ_Status status = AJ_OK;

#ifdef WRITE_STRESS
    while (TRUE) {
#endif
    cap1 = (tid1 % ((AJ_NVRAM_REQUESTED / 4) - 100)) + 1;
    cap2 = (tid2 % ((AJ_NVRAM_REQUESTED / 4) - 100)) + 1;
    cap3 = (tid3 % ((AJ_NVRAM_REQUESTED / 4) - 100)) + 1;
    cap4 = (tid4 % ((AJ_NVRAM_REQUESTED / 4) - 100)) + 1;

    d1 = AJ_NVRAM_Open(tid1, "w", cap1);
    for (i = 0; i < AJ_NVRAM_REQUESTED / 4; i++) {
        if ((d1->capacity - d1->curPos) >= sizeof(i)) {
            bytes1 = AJ_NVRAM_Write(&i, sizeof(i), d1);
            if (bytes1 != sizeof(i)) {
                return AJ_ERR_FAILURE;
            }
        }
    }
    AJ_InfoPrintf(("Dataset1 bytes: %u i: %u sizeof(i): %u capacity %u curPos %u\n", bytes1, i, sizeof(i), d1->capacity, d1->curPos));
    AJ_InfoPrintf(("LAYOUT AFTER WRITE\n"));
    AJ_NVRAM_Layout_Print();
    if (d1 != NULL) {
        AJ_NVRAM_Close(d1);
        AJ_ASSERT(d1);
    }

    d2 = AJ_NVRAM_Open(tid2, "w", cap2);
    AJ_ASSERT(d2);
    for (i = 0; i < AJ_NVRAM_REQUESTED / 4; i++) {
        if ((d2->capacity - d2->curPos) >= sizeof(i)) {
            bytes2 = AJ_NVRAM_Write(&i, sizeof(i), d2);
            if (bytes2 != sizeof(i)) {
                return AJ_ERR_FAILURE;
            }
        }
    }
    AJ_InfoPrintf(("Dataset2 bytes: %u i: %u sizeof(i): %u capacity %u curPos %u\n", bytes2, i, sizeof(i), d2->capacity, d2->curPos));
    AJ_InfoPrintf(("LAYOUT AFTER WRITE\n"));
    AJ_NVRAM_Layout_Print();
    if (d2 != NULL) {
        AJ_NVRAM_Close(d2);
        AJ_ASSERT(d2);
    }


    d3 = AJ_NVRAM_Open(tid3, "w", cap3);
    AJ_ASSERT(d3);
    for (i = 0; i < AJ_NVRAM_REQUESTED / 4; i++) {
        if ((d3->capacity - d3->curPos) >= sizeof(i)) {
            bytes3 = AJ_NVRAM_Write(&i, sizeof(i), d3);
            if (bytes3 != sizeof(i)) {
                return AJ_ERR_FAILURE;
            }
        }
    }
    AJ_InfoPrintf(("Dataset3 bytes: %u i: %u sizeof(i): %u capacity %u curPos %u\n", bytes2, i, sizeof(i), d2->capacity, d2->curPos));
    AJ_InfoPrintf(("LAYOUT AFTER WRITE\n"));
    AJ_NVRAM_Layout_Print();
    if (d3 != NULL) {
        AJ_NVRAM_Close(d3);
        AJ_ASSERT(d3);
    }

    d4 = AJ_NVRAM_Open(tid4, "w", cap4);
    AJ_ASSERT(d4);
    for (i = 0; i < AJ_NVRAM_REQUESTED / 4; i++) {
        if ((d4->capacity - d4->curPos) >= sizeof(i)) {
            bytes4 = AJ_NVRAM_Write(&i, sizeof(i), d4);
            if (bytes4 != sizeof(i)) {
                return AJ_ERR_FAILURE;
            }
        }
    }
    AJ_InfoPrintf(("Dataset4 bytes: %u i: %u sizeof(i): %u capacity %u curPos %u\n", bytes2, i, sizeof(i), d2->capacity, d2->curPos));
    AJ_InfoPrintf(("LAYOUT AFTER WRITE\n"));
    AJ_NVRAM_Layout_Print();
    if (d4 != NULL) {
        AJ_NVRAM_Close(d4);
        AJ_ASSERT(d4);
    }

    AJ_InfoPrintf(("LAYOUT AFTER CLOSE - WRITE MODE\n"));
    AJ_NVRAM_Layout_Print();
#ifdef WRITE_STRESS
}
#endif
    return status;
}
Esempio n. 6
0
AJ_Status TestObsWrite()
{
    AJ_Status status = AJ_OK;
    AJ_NV_DATASET* nvramHandle;
    AJOBS_Info_Test info;
    int nTest;
    size_t size = sizeof(info);
    char* ssid[] = { "abcdefghABCDEFGH", "aaaaaaaa", "bbbbbbbb", "cccccccc", "dddddddd", "eeeeeeee", "ffffffff", "gggggggg", "hhhhhhhh", "iiiiiiii",
                     "jjjjjjjj", "kkkkkkkk", "llllllll", "mmmmmmmm", "nnnnnnnn", "oooooooo", "pppppppp", "qqqqqqqq", "rrrrrrrr", "ssssssss",
                     "", "tttttttt", "uuuuuuuu", "vvvvvvvv", "wwwwwwww", "xxxxxxxx", "yyyyyyyy", "zzzzzzzz", "11111111", "22222222", "33333333",
                     "44444444", "55555555", "66666666", "77777777", "888888888888888888888888888888", "99999999", "aaaa1111", "bbbb2222", "cccc3333", "dddd4444",
                     "TRTESTING123", "eeee5555", "", "TR-TESTING-43" };
    char pc[] = "aaaaabbbbbcccccAAAAABBBBBCCCCCzzzzzZZZZZ1111122222";
    size_t i;

    AJ_NVRAM_Layout_Print();

    //if( AJ_NVRAM_Exist(AJ_NVRAM_ID_CREDS_MAX + 100)){ //NEGATIVE TEST, ID DOESN'T EXIST
    //if( AJ_NVRAM_Exist(AJ_NVRAM_ID_CREDS_MAX + 1)){ //PROPERTY STORE DEVICE ID
    if (AJ_NVRAM_Exist(AJ_NVRAM_ID_FOR_APPS)) {
        //nvramHandle = AJ_NVRAM_Open(100, "r", 0); //NEGATIVE TEST, OPEN INVALID ID
        //nvramHandle = AJ_NVRAM_Open(AJ_NVRAM_ID_CREDS_MAX + 1, "r", 0); //PROPERTY STORE DEVICE ID
        nvramHandle = AJ_NVRAM_Open(AJ_NVRAM_ID_FOR_APPS, "r", 0);
        if (nvramHandle != NULL) {
            int sizeRead = AJ_NVRAM_Read(&info, size, nvramHandle);
            status = AJ_NVRAM_Close(nvramHandle);
            AJ_InfoPrintf(("sizeRead: %u, size: %u\n", sizeRead, size));
            if (sizeRead != size) {
                status = AJ_ERR_READ;
            } else {
                AJ_InfoPrintf(("Read Info values: state=%d, ssid=%s authType=%d pc=%s\n", info.state, info.ssid, info.authType, info.pc));
            }
        }
    }

    //nTest = AJ_NVRAM_Read(&info, size, nvramHandle); //NEGATIVE TEST, READ NULL HANDLE
    //nTest = AJ_NVRAM_Write(&info, size, nvramHandle); //NEGATIVE TEST, WRITE TO NULL HANDLE

    for (i = 0; i < ArraySize(ssid); i++) {
        strncpy(info.ssid, ssid[i], sizeof(info.ssid));
        strncpy(info.pc, pc, sizeof(info.pc));
        info.authType = 0;
        info.state = 0;

#ifdef OBS_STRESS
        while (TRUE) {
#endif

#ifdef SHOW_REWRITES
        AJ_AlwaysPrintf(("Going to write Info values: state=%d, ssid=%s authType=%d pc=%s\n", info.state, info.ssid, info.authType, info.pc));
#endif

        //nvramHandle = AJ_NVRAM_Open(AJ_NVRAM_ID_CREDS_MAX + 1, "w", 0); //NEGATIVE TEST, OPEN 0 SIZE
        //nvramHandle = AJ_NVRAM_Open(AJ_NVRAM_ID_CREDS_MAX + 1, "t", size); //NEGATIVE TEST, INVALID MODE
        //nvramHandle = AJ_NVRAM_Open(0, "w", size); //NEGATIVE TEST, OPEN 0 ID
        //nvramHandle = AJ_NVRAM_Open(AJ_NVRAM_ID_CREDS_MAX + 1, "w", size); //PROPERTY STORE DEVICE ID
        nvramHandle = AJ_NVRAM_Open(AJ_NVRAM_ID_FOR_APPS, "w", size);
        if (nvramHandle != NULL) {
            int sizeWritten = AJ_NVRAM_Write(&info, size, nvramHandle);
            status = AJ_NVRAM_Close(nvramHandle);
            if (sizeWritten != size) {
                status = AJ_ERR_WRITE;
            }
        }
        //nvramHandle = AJ_NVRAM_Open(AJ_NVRAM_ID_CREDS_MAX + 1, "r", 0); //PROPERTY STORE DEVICE ID
        nvramHandle = AJ_NVRAM_Open(AJ_NVRAM_ID_FOR_APPS, "r", 0);
        if (nvramHandle != NULL) {
            int sizeRead = AJ_NVRAM_Read(&info, size, nvramHandle);
            status = AJ_NVRAM_Close(nvramHandle);
            if (sizeRead != sizeRead) {
                status = AJ_ERR_READ;
            }
#ifdef SHOW_REWRITES
            else {
                AJ_InfoPrintf(("Read Info values: state=%d, ssid=%s authType=%d pc=%s\n", info.state, info.ssid, info.authType, info.pc));
            }
#endif
        }

#ifdef NEGATIVE_OPEN
        nvramHandle = AJ_NVRAM_Open(66, "r", 0);
        status = AJ_NVRAM_Close(nvramHandle);
#endif

        //AJ_NVRAM_Layout_Print();
#ifdef OBS_STRESS
        AJ_Sleep(2000);
    }
#endif
    }
    AJ_NVRAM_Layout_Print();
    return status;
}
Esempio n. 7
0
AJ_Status TestECCCreds()
{
    AJ_Status status = AJ_OK;
    ecc_publickey publicKey;
    ecc_privatekey privateKey;
    uint16_t privateKeyID = 1;
    uint16_t publicKeyID = 2;
    AJ_PeerCred* privateKeyCred;
    AJ_PeerCred* publicKeyCred;

    AJ_AlwaysPrintf(("Start TestECCCreds\n"));
    AJ_NVRAM_Layout_Print();

    status = AJ_GenerateDSAKeyPair(&publicKey, &privateKey);
    if (AJ_OK != status) {
        AJ_AlwaysPrintf(("AJ_GenerateDSAKeyPair failed = %d\n", status));
        return status;
    }

    status = AJ_StoreLocalCredential(AJ_CRED_TYPE_DSA_PRIVATE, privateKeyID, (uint8_t*) &privateKey, sizeof(privateKey), 0xFFFFFFFF);
    if (AJ_OK != status) {
        AJ_AlwaysPrintf(("AJ_StoreLocalCredential failed = %d\n", status));
        return status;
    }
    status = AJ_GetLocalCredential(AJ_CRED_TYPE_DSA_PRIVATE, privateKeyID, &privateKeyCred);
    if (AJ_OK != status) {
        AJ_AlwaysPrintf(("AJ_GetLocalCredential failed = %d\n", status));
        return status;
    }
    if (!privateKeyCred) {
        AJ_AlwaysPrintf(("AJ_GetLocalCredential failed = %d\n", status));
        return AJ_ERR_FAILURE;
    }
    if (privateKeyCred->dataLen != sizeof(privateKey)) {
        AJ_AlwaysPrintf(("Retrieved private key length %d does not match the original %zu\n", privateKeyCred->dataLen, sizeof(privateKey)));
        AJ_FreeCredential(privateKeyCred);
        return AJ_ERR_FAILURE;
    }
    if (memcmp(privateKeyCred->data, &privateKey, sizeof(privateKey)) != 0) {
        AJ_AlwaysPrintf(("Retrieved private key does not match the original\n"));
    }
    AJ_FreeCredential(privateKeyCred);

    status = AJ_StoreLocalCredential(AJ_CRED_TYPE_DSA_PUBLIC, publicKeyID, (uint8_t*) &publicKey, sizeof(publicKey), 0xFFFFFFFF);
    if (AJ_OK != status) {
        AJ_AlwaysPrintf(("AJ_StoreLocalCredential failed = %d\n", status));
        return status;
    }
    status = AJ_GetLocalCredential(AJ_CRED_TYPE_DSA_PUBLIC, publicKeyID, &publicKeyCred);
    if (AJ_OK != status) {
        AJ_AlwaysPrintf(("AJ_GetLocalCredential failed = %d\n", status));
        return status;
    }
    if (!publicKeyCred) {
        AJ_AlwaysPrintf(("AJ_GetLocalCredential failed = %d\n", status));
        return AJ_ERR_FAILURE;
    }
    if (publicKeyCred->dataLen != sizeof(publicKey)) {
        AJ_AlwaysPrintf(("Retrieved private key length %d does not match the original %zu\n", publicKeyCred->dataLen, sizeof(publicKey)));
        return AJ_ERR_FAILURE;
    }
    if (memcmp(publicKeyCred->data, &publicKey, sizeof(publicKey)) != 0) {
        AJ_AlwaysPrintf(("Retrieved private key does not match the original\n"));
    }
    AJ_FreeCredential(publicKeyCred);
    AJ_NVRAM_Layout_Print();
    AJ_AlwaysPrintf(("TestECCCreds done.\n"));
    return status;
}
AJ_Status TestCreds()
{
    AJ_Status status = AJ_OK;
    AJ_GUID localGuid;
    AJ_GUID remoteGuid;
    char str[33];
    AJ_PeerCred peerCred;
    AJ_PeerCred peerCredRead;
    int i = 0;
    status = AJ_GetLocalGUID(&localGuid);
    if (AJ_OK != status) {
        goto TEST_CREDS_EXIT;
    }
    AJ_GUID_FromString(&localGuid, str);

    AJ_NVRAM_Layout_Print();
    memset(&peerCred.guid, 1, sizeof(AJ_GUID));
    memcpy(&remoteGuid, &peerCred.guid, sizeof(AJ_GUID)); // backup the GUID
    for (i = 0; i < 24; i++) {
        peerCred.secret[i] = i;
    }
    status = AJ_StoreCredential(&peerCred);
    if (AJ_OK != status) {
        AJ_Printf("AJ_StoreCredential failed = %d\n", status);
        goto TEST_CREDS_EXIT;
    }

    status = AJ_GetRemoteCredential(&remoteGuid, &peerCredRead);
    if (AJ_OK != status) {
        AJ_Printf("AJ_StoreCredential failed = %d\n", status);
        goto TEST_CREDS_EXIT;
    }

    if (0 != memcmp(&peerCredRead, &peerCred, sizeof(AJ_PeerCred))) {
        AJ_Printf("The retrieved credential does not match\n");
        status = AJ_ERR_FAILURE;
        goto TEST_CREDS_EXIT;
    }

    status = AJ_DeleteCredential(&remoteGuid);
    if (AJ_OK != status) {
        AJ_Printf("AJ_DeleteCredential failed = %d\n", status);
        goto TEST_CREDS_EXIT;
    }

    if (AJ_ERR_FAILURE == AJ_GetRemoteCredential(&remoteGuid, &peerCredRead)) {
        status = AJ_OK;
    } else {
        status = AJ_ERR_FAILURE;
        goto TEST_CREDS_EXIT;
    }
    AJ_NVRAM_Layout_Print();

    status = AJ_StoreCredential(&peerCred);
    if (AJ_OK != status) {
        AJ_Printf("AJ_StoreCredential failed = %d\n", status);
        goto TEST_CREDS_EXIT;
    }

    AJ_ClearCredentials();
    if (AJ_ERR_FAILURE == AJ_GetRemoteCredential(&remoteGuid, &peerCredRead)) {
        status = AJ_OK;
    } else {
        status = AJ_ERR_FAILURE;
        goto TEST_CREDS_EXIT;
    }
    AJ_NVRAM_Layout_Print();

TEST_CREDS_EXIT:
    return status;

}