763 lines
22 KiB
C
763 lines
22 KiB
C
|
/* This file contains all the keychain related test cases.
|
||
|
*/
|
||
|
#include "testcases.h"
|
||
|
|
||
|
void EnumerateIDs(SSCS_SECRETSTORE_HANDLE_T *ssHandle,int type,
|
||
|
SSCS_KEYCHAIN_ID_T *keychainID)
|
||
|
{
|
||
|
SSCS_KEYCHAIN_ID_LIST_T kcIDList;
|
||
|
SSCS_SECRET_ID_LIST_T secretIDList;
|
||
|
|
||
|
uint32_t ssFlags = 0;
|
||
|
unsigned int bytesRequired = 0;
|
||
|
int i = 0;
|
||
|
|
||
|
int retVal = 0;
|
||
|
if(type == 0) //keychains
|
||
|
{
|
||
|
kcIDList.keyChainIDList = (SSCS_KEYCHAIN_ID_T *)malloc(
|
||
|
sizeof(SSCS_KEYCHAIN_ID_T) * MAX_RETURNED_IDS );
|
||
|
assert(kcIDList.keyChainIDList);
|
||
|
|
||
|
//kcIDList.bufferSizeRequired = sizeof(SSCS_KEYCHAIN_ID_T) * MAX_RETURNED_IDS;
|
||
|
kcIDList.returnedIDs = MAX_RETURNED_IDS;
|
||
|
retVal = sscs_CacheEnumerateKeychainIDs(ssHandle, ssFlags,NULL, &kcIDList,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheEnumerateKeychainIDs failed: %d\n",retVal);
|
||
|
}
|
||
|
|
||
|
printf("KEYCHAINLIST : \n");
|
||
|
for( i = 0 ; i < kcIDList.returnedIDs; i++ )
|
||
|
{
|
||
|
printf("%s\n",kcIDList.keyChainIDList[i].keychainID);
|
||
|
}
|
||
|
|
||
|
free(kcIDList.keyChainIDList);
|
||
|
}
|
||
|
else //secrets
|
||
|
{
|
||
|
secretIDList.secIDList = (SSCS_SECRET_ID_T*)malloc(
|
||
|
sizeof(SSCS_SECRET_ID_T)* MAX_RETURNED_IDS);
|
||
|
assert(secretIDList.secIDList);
|
||
|
|
||
|
// secretIDList.bufferSizeRequired = sizeof(SSCS_SECRET_ID_T)* MAX_RETURNED_IDS;
|
||
|
secretIDList.returnedIDs = MAX_RETURNED_IDS;
|
||
|
retVal = sscs_CacheEnumerateSecretIDs(ssHandle, ssFlags, keychainID, NULL, &secretIDList, NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheEnumerateSecretIDs failed: %d\n",retVal);
|
||
|
}
|
||
|
|
||
|
printf("SECRETIDLIST:\n");
|
||
|
for( i = 0 ; i < secretIDList.returnedIDs; i++ )
|
||
|
{
|
||
|
printf("%s\n",secretIDList.secIDList[i].id);
|
||
|
}
|
||
|
|
||
|
free(secretIDList.secIDList);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void TestCacheAddKeyChain_Valid(void)
|
||
|
{
|
||
|
SSCS_SECRETSTORE_T secID;
|
||
|
SSCS_SECRETSTORE_HANDLE_T *ssHandle = NULL;
|
||
|
SSCS_KEYCHAIN_ID_LIST_T kcIDList;
|
||
|
|
||
|
int retVal = 0;
|
||
|
uint32_t ssFlags = 0;
|
||
|
SSCS_KEYCHAIN_ID_T keychainID;
|
||
|
memset(&keychainID,0,sizeof(SSCS_KEYCHAIN_ID_T));
|
||
|
strcpy((char*)(keychainID.keychainID),"MyKeychain");
|
||
|
keychainID.len = strlen("MyKeychain") +1 ;
|
||
|
|
||
|
DECORATE
|
||
|
secID.version = 0x00040000;
|
||
|
strcpy((char *)secID.ssName,"SecretStore");
|
||
|
|
||
|
ssHandle = sscs_CacheOpenSecretStore(&secID,ssFlags, NULL);
|
||
|
if(!ssHandle)
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore failed\n");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore succeeded\n");
|
||
|
}
|
||
|
printf("Platform ID is %d; socketID is %d\n",ssHandle->platformID,
|
||
|
*(int*)ssHandle->platHandle);
|
||
|
|
||
|
ssFlags |= SSCS_LOCAL_KEY_CHAIN_F;
|
||
|
printf("Adding keychain - %s\n",keychainID.keychainID);
|
||
|
|
||
|
retVal = sscs_CacheAddKeychain(ssHandle,ssFlags,&keychainID,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheAddKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
EnumerateIDs(ssHandle,0,NULL);
|
||
|
|
||
|
retVal = sscs_CacheRemoveKeychain(ssHandle,ssFlags, &keychainID,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheRemoveKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
|
||
|
retVal = sscs_CacheCloseSecretStore(ssHandle, ssFlags, NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheCloseSecretStore failed: %d\n",retVal);
|
||
|
}
|
||
|
DECORATE
|
||
|
}
|
||
|
|
||
|
void TestCacheAddKeyChain_LongKeychainId(void)
|
||
|
{
|
||
|
SSCS_SECRETSTORE_T secID;
|
||
|
SSCS_SECRETSTORE_HANDLE_T *ssHandle = NULL;
|
||
|
SSCS_KEYCHAIN_ID_LIST_T kcIDList;
|
||
|
int retVal = 0;
|
||
|
uint32_t ssFlags = 0;
|
||
|
|
||
|
SSCS_KEYCHAIN_ID_T keychainID;
|
||
|
memset(&keychainID,0,sizeof(SSCS_KEYCHAIN_ID_T));
|
||
|
strcpy((char*)(keychainID.keychainID),LONG_WSTRING);
|
||
|
keychainID.len = strlen(LONG_WSTRING) + 1;
|
||
|
|
||
|
/* sscs_CacheOpenSecretStore */
|
||
|
|
||
|
DECORATE
|
||
|
secID.version = 0x00040000;
|
||
|
strcpy((char *)secID.ssName,"SecretStore");
|
||
|
|
||
|
ssHandle = sscs_CacheOpenSecretStore(&secID, ssFlags, NULL);
|
||
|
if(!ssHandle)
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore failed\n");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore succeeded\n");
|
||
|
}
|
||
|
printf("Platform ID is %d; socketID is %d\n",ssHandle->platformID,
|
||
|
*(int*)ssHandle->platHandle);
|
||
|
|
||
|
ssFlags |= SSCS_LOCAL_KEY_CHAIN_F;
|
||
|
retVal = sscs_CacheAddKeychain(ssHandle,ssFlags,&keychainID,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheAddKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
PRINT_ERR;
|
||
|
retVal = sscs_CacheRemoveKeychain(ssHandle,ssFlags,&keychainID,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheRemoveKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
retVal = sscs_CacheCloseSecretStore(ssHandle, ssFlags, NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheCloseSecretStore failed: %d\n",retVal);
|
||
|
}
|
||
|
DECORATE
|
||
|
}
|
||
|
|
||
|
void TestCacheAddKeyChain_ExistingKeychain(void)
|
||
|
{
|
||
|
SSCS_SECRETSTORE_T secID;
|
||
|
SSCS_SECRETSTORE_HANDLE_T *ssHandle = NULL;
|
||
|
SSCS_KEYCHAIN_ID_LIST_T kcIDList;
|
||
|
unsigned int bytesRequired = 0;
|
||
|
int retVal = 0;
|
||
|
uint32_t ssFlags = 0;
|
||
|
|
||
|
SSCS_KEYCHAIN_ID_T keychainID;
|
||
|
memset(&keychainID,0,sizeof(SSCS_KEYCHAIN_ID_T));
|
||
|
strcpy((char*)(keychainID.keychainID),"MyKeychain");
|
||
|
keychainID.len = strlen("MyKeychain") + 1;
|
||
|
|
||
|
/* sscs_CacheOpenSecretStore */
|
||
|
|
||
|
DECORATE
|
||
|
secID.version = 0x00040000;
|
||
|
strcpy((char *)secID.ssName,"SecretStore");
|
||
|
|
||
|
ssHandle = sscs_CacheOpenSecretStore(&secID, ssFlags, NULL);
|
||
|
if(!ssHandle)
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore failed\n");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore succeeded\n");
|
||
|
}
|
||
|
printf("Platform ID is %d; socketID is %d\n",ssHandle->platformID,
|
||
|
*(int*)ssHandle->platHandle);
|
||
|
|
||
|
ssFlags |= SSCS_LOCAL_KEY_CHAIN_F;
|
||
|
|
||
|
printf("Adding keychain %s\n",keychainID.keychainID);
|
||
|
retVal = sscs_CacheAddKeychain(ssHandle,ssFlags,&keychainID,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheAddKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
EnumerateIDs(ssHandle,0,NULL);
|
||
|
|
||
|
printf("Re-adding keychain %S\n",keychainID.keychainID);
|
||
|
retVal = sscs_CacheAddKeychain(ssHandle,ssFlags,&keychainID,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheAddKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
EnumerateIDs(ssHandle,0,NULL);
|
||
|
|
||
|
retVal = sscs_CacheRemoveKeychain(ssHandle,ssFlags,&keychainID,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheRemoveKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
|
||
|
retVal = sscs_CacheCloseSecretStore(ssHandle, ssFlags,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheCloseSecretStore failed: %d\n",retVal);
|
||
|
}
|
||
|
DECORATE
|
||
|
}
|
||
|
#define NSSCS_MAX_KEYCHAINS 10
|
||
|
|
||
|
void TestCacheAddKeyChain_MaxKeychains(void)
|
||
|
{
|
||
|
SSCS_SECRETSTORE_T secID;
|
||
|
SSCS_SECRETSTORE_HANDLE_T *ssHandle = NULL;
|
||
|
SSCS_KEYCHAIN_ID_LIST_T kcIDList;
|
||
|
int retVal = 0;
|
||
|
int i = 0;
|
||
|
uint32_t ssFlags = 0;
|
||
|
// wchar_t *keychainID = L"MyKeychain";
|
||
|
char keychainID[256] = "";
|
||
|
char ch = 'a';
|
||
|
|
||
|
SSCS_KEYCHAIN_ID_T keychainIDStruct;
|
||
|
memset(&keychainIDStruct,0,sizeof(SSCS_KEYCHAIN_ID_T));
|
||
|
|
||
|
/* sscs_CacheOpenSecretStore */
|
||
|
|
||
|
DECORATE
|
||
|
printf("INPUT: {0x00040000, SecretStore}\n");
|
||
|
|
||
|
secID.version = 0x00040000;
|
||
|
strcpy((char *)secID.ssName,"SecretStore");
|
||
|
|
||
|
ssHandle = sscs_CacheOpenSecretStore(&secID, ssFlags, NULL);
|
||
|
if(!ssHandle)
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore failed\n");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore succeeded\n");
|
||
|
}
|
||
|
printf("Platform ID is %d; socketID is %d\n",ssHandle->platformID,
|
||
|
*(int*)ssHandle->platHandle);
|
||
|
|
||
|
ssFlags |= SSCS_LOCAL_KEY_CHAIN_F;
|
||
|
|
||
|
for( i = 0 ; i < NSSCS_MAX_KEYCHAINS + 1 ; i++ )
|
||
|
{
|
||
|
sprintf(keychainID,"key%c",ch+i);
|
||
|
|
||
|
printf("Adding %s\n",keychainIDStruct.keychainID);
|
||
|
|
||
|
strcpy((char*)(keychainIDStruct.keychainID),keychainID);
|
||
|
keychainIDStruct.len = strlen(keychainID)+1;
|
||
|
|
||
|
retVal = sscs_CacheAddKeychain(ssHandle,ssFlags,&keychainIDStruct,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheAddKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
memset(keychainID,0,sizeof(keychainID));
|
||
|
for( i = 0 ; i < NSSCS_MAX_KEYCHAINS + 1 ; i++ )
|
||
|
{
|
||
|
sprintf(keychainID,"key%c",ch+i);
|
||
|
|
||
|
printf("Removing %s\n",keychainIDStruct.keychainID);
|
||
|
strcpy((char*)(keychainIDStruct.keychainID),keychainID);
|
||
|
keychainIDStruct.len = strlen(keychainID)+1;
|
||
|
|
||
|
retVal = sscs_CacheRemoveKeychain(ssHandle,ssFlags, &keychainIDStruct,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheRemoveKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
retVal = sscs_CacheCloseSecretStore(ssHandle, ssFlags, NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheCloseSecretStore failed: %d\n",retVal);
|
||
|
}
|
||
|
DECORATE
|
||
|
}
|
||
|
|
||
|
void TestCacheEnumerateKeyChainIds_Valid(void)
|
||
|
{
|
||
|
SSCS_SECRETSTORE_T secID;
|
||
|
SSCS_SECRETSTORE_HANDLE_T *ssHandle = NULL;
|
||
|
SSCS_KEYCHAIN_ID_LIST_T kcIDList;
|
||
|
int retVal = 0;
|
||
|
int i = 0;
|
||
|
uint32_t ssFlags = 0;
|
||
|
/* sscs_CacheOpenSecretStore */
|
||
|
|
||
|
DECORATE
|
||
|
printf("INPUT: {0x00040000, SecretStore}\n");
|
||
|
|
||
|
secID.version = 0x00040000;
|
||
|
strcpy((char *)secID.ssName,"SecretStore");
|
||
|
|
||
|
ssHandle = sscs_CacheOpenSecretStore(&secID, ssFlags, NULL);
|
||
|
if(!ssHandle)
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore failed\n");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore succeeded\n");
|
||
|
}
|
||
|
printf("Platform ID is %d; socketID is %d\n",ssHandle->platformID,
|
||
|
*(int*)ssHandle->platHandle);
|
||
|
|
||
|
kcIDList.keyChainIDList = (SSCS_KEYCHAIN_ID_T *)malloc(
|
||
|
sizeof(SSCS_KEYCHAIN_ID_T) * MAX_RETURNED_IDS );
|
||
|
assert(kcIDList.keyChainIDList);
|
||
|
|
||
|
// kcIDList.bufferSizeRequired = sizeof(SSCS_KEYCHAIN_ID_T) * MAX_RETURNED_IDS;
|
||
|
kcIDList.returnedIDs = MAX_RETURNED_IDS;
|
||
|
|
||
|
|
||
|
retVal = sscs_CacheEnumerateKeychainIDs(ssHandle,ssFlags, NULL,&kcIDList,
|
||
|
NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheEnumerateKeychainIDs failed: %d\n",retVal);
|
||
|
}
|
||
|
|
||
|
printf("KEYCHAINLIST\n");
|
||
|
for( i = 0 ; i < kcIDList.returnedIDs; i++ )
|
||
|
{
|
||
|
printf("%s\n",kcIDList.keyChainIDList[i].keychainID);
|
||
|
}
|
||
|
|
||
|
free(kcIDList.keyChainIDList);
|
||
|
|
||
|
retVal = sscs_CacheCloseSecretStore(ssHandle, ssFlags, NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheCloseSecretStore failed: %d\n",retVal);
|
||
|
}
|
||
|
DECORATE
|
||
|
}
|
||
|
|
||
|
|
||
|
void TestCacheEnumerateKeyChainIds_WithoutOpen(void)
|
||
|
{
|
||
|
SSCS_SECRETSTORE_T secID;
|
||
|
SSCS_SECRETSTORE_HANDLE_T cookedUpSSHandle;
|
||
|
SSCS_KEYCHAIN_ID_LIST_T kcIDList;
|
||
|
int socketFd = FAKE_SOCK_FD;
|
||
|
int retVal = 0;
|
||
|
int i = 0;
|
||
|
uint32_t ssFlags = 0;
|
||
|
|
||
|
DECORATE
|
||
|
|
||
|
/* Passing a cookedup SSHandle */
|
||
|
printf("INPUT: Cookedup SSHandle\n");
|
||
|
cookedUpSSHandle.platformID = 1;
|
||
|
cookedUpSSHandle.platHandle = (int*)&socketFd;
|
||
|
|
||
|
kcIDList.keyChainIDList = (SSCS_KEYCHAIN_ID_T *)malloc(
|
||
|
sizeof(SSCS_KEYCHAIN_ID_T) * MAX_RETURNED_IDS );
|
||
|
assert(kcIDList.keyChainIDList);
|
||
|
|
||
|
// kcIDList.bufferSizeRequired = sizeof(SSCS_KEYCHAIN_ID_T) * MAX_RETURNED_IDS;
|
||
|
kcIDList.returnedIDs = MAX_RETURNED_IDS;
|
||
|
|
||
|
retVal = sscs_CacheEnumerateKeychainIDs(&cookedUpSSHandle,ssFlags, NULL, &kcIDList,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheEnumerateKeychainIDs failed: %d\n",retVal);
|
||
|
}
|
||
|
|
||
|
printf("KEYCHAINLIST\n");
|
||
|
for( i = 0 ; i < kcIDList.returnedIDs; i++ )
|
||
|
{
|
||
|
printf("%s\n",kcIDList.keyChainIDList[i].keychainID);
|
||
|
}
|
||
|
|
||
|
free(kcIDList.keyChainIDList);
|
||
|
|
||
|
DECORATE
|
||
|
}
|
||
|
|
||
|
void TestCacheEnumerateKeyChainIds_LessBufferLen(void)
|
||
|
{
|
||
|
SSCS_SECRETSTORE_T secID;
|
||
|
SSCS_SECRETSTORE_HANDLE_T *ssHandle = NULL;
|
||
|
SSCS_KEYCHAIN_ID_LIST_T kcIDList;
|
||
|
uint32_t ssFlags = 0;
|
||
|
int retVal = 0;
|
||
|
int i = 0;
|
||
|
SSCS_KEYCHAIN_ID_T keychainID;
|
||
|
memset(&keychainID,0,sizeof(SSCS_KEYCHAIN_ID_T));
|
||
|
strcpy((char*)(keychainID.keychainID),"MyKeychain1");
|
||
|
keychainID.len = strlen("MyKeychain1")+1;
|
||
|
|
||
|
|
||
|
/* sscs_CacheOpenSecretStore */
|
||
|
|
||
|
DECORATE
|
||
|
printf("INPUT: {0x00040000, SecretStore}\n");
|
||
|
|
||
|
secID.version = 0x00040000;
|
||
|
strcpy((char *)secID.ssName,"SecretStore");
|
||
|
|
||
|
ssHandle = sscs_CacheOpenSecretStore(&secID, ssFlags, NULL);
|
||
|
if(!ssHandle)
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore failed\n");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore succeeded\n");
|
||
|
}
|
||
|
printf("Platform ID is %d; socketID is %d\n",ssHandle->platformID,
|
||
|
*(int*)ssHandle->platHandle);
|
||
|
|
||
|
printf("Adding keychain..%s\n",keychainID.keychainID);
|
||
|
ssFlags |= SSCS_LOCAL_KEY_CHAIN_F;
|
||
|
|
||
|
retVal = sscs_CacheAddKeychain(ssHandle,ssFlags,&keychainID,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheAddKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
|
||
|
strcpy((char*)(keychainID.keychainID),"MyKeychain2");
|
||
|
keychainID.len = strlen("MyKeychain2")+1;
|
||
|
|
||
|
printf("Adding keychain..%s\n",keychainID.keychainID);
|
||
|
|
||
|
retVal = sscs_CacheAddKeychain(ssHandle,ssFlags,&keychainID,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheAddKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
|
||
|
kcIDList.keyChainIDList = (SSCS_KEYCHAIN_ID_T *)malloc(
|
||
|
sizeof(SSCS_KEYCHAIN_ID_T) * MAX_RETURNED_IDS );
|
||
|
assert(kcIDList.keyChainIDList);
|
||
|
|
||
|
// kcIDList.bufferSizeRequired = sizeof(SSCS_KEYCHAIN_ID_T) * 1;
|
||
|
kcIDList.returnedIDs = 1;
|
||
|
|
||
|
|
||
|
retVal = sscs_CacheEnumerateKeychainIDs(ssHandle, ssFlags, NULL, &kcIDList,
|
||
|
NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheEnumerateKeychainIDs failed: %d\n",retVal);
|
||
|
}
|
||
|
|
||
|
printf("KEYCHAINLIST\n");
|
||
|
for( i = 0 ; i < kcIDList.returnedIDs; i++ )
|
||
|
{
|
||
|
printf("%s\n",kcIDList.keyChainIDList[i].keychainID);
|
||
|
}
|
||
|
|
||
|
free(kcIDList.keyChainIDList);
|
||
|
|
||
|
retVal = sscs_CacheRemoveKeychain(ssHandle,ssFlags, &keychainID, NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheRemoveKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
|
||
|
strcpy((char*)(keychainID.keychainID),"MyKeychain1");
|
||
|
keychainID.len = strlen("MyKeychain1")+1;
|
||
|
|
||
|
retVal = sscs_CacheRemoveKeychain(ssHandle,ssFlags, &keychainID, NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheRemoveKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
|
||
|
|
||
|
retVal = sscs_CacheCloseSecretStore(ssHandle, ssFlags, NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheCloseSecretStore failed: %d\n",retVal);
|
||
|
}
|
||
|
|
||
|
DECORATE
|
||
|
}
|
||
|
|
||
|
void TestCacheEnumerateKeyChainIds_WithNoKeychains(void)
|
||
|
{
|
||
|
SSCS_SECRETSTORE_T secID;
|
||
|
SSCS_SECRETSTORE_HANDLE_T *ssHandle = NULL;
|
||
|
SSCS_KEYCHAIN_ID_LIST_T kcIDList;
|
||
|
int retVal = 0;
|
||
|
uint32_t ssFlags = 0;
|
||
|
int i = 0;
|
||
|
/* sscs_CacheOpenSecretStore */
|
||
|
|
||
|
DECORATE
|
||
|
printf("INPUT: {0x00040000, SecretStore}\n");
|
||
|
|
||
|
secID.version = 0x00040000;
|
||
|
strcpy((char *)secID.ssName,"SecretStore");
|
||
|
|
||
|
ssHandle = sscs_CacheOpenSecretStore(&secID, ssFlags, NULL);
|
||
|
if(!ssHandle)
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore failed\n");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore succeeded\n");
|
||
|
}
|
||
|
printf("Platform ID is %d; socketID is %d\n",ssHandle->platformID,
|
||
|
*(int*)ssHandle->platHandle);
|
||
|
|
||
|
kcIDList.keyChainIDList = (SSCS_KEYCHAIN_ID_T *)malloc(
|
||
|
sizeof(SSCS_KEYCHAIN_ID_T) * MAX_RETURNED_IDS );
|
||
|
assert(kcIDList.keyChainIDList);
|
||
|
|
||
|
// kcIDList.bufferSizeRequired = sizeof(SSCS_KEYCHAIN_ID_T) * MAX_RETURNED_IDS;
|
||
|
kcIDList.returnedIDs = MAX_RETURNED_IDS;
|
||
|
retVal = sscs_CacheEnumerateKeychainIDs(ssHandle, ssFlags,NULL, &kcIDList,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheEnumerateKeychainIDs failed: %d\n",retVal);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("KEYCHAINLIST\n");
|
||
|
for( i = 0 ; i < kcIDList.returnedIDs; i++ )
|
||
|
{
|
||
|
printf("%s\n",kcIDList.keyChainIDList[i].keychainID);
|
||
|
}
|
||
|
}
|
||
|
free(kcIDList.keyChainIDList);
|
||
|
kcIDList.keyChainIDList = NULL;
|
||
|
|
||
|
retVal = sscs_CacheCloseSecretStore(ssHandle, ssFlags, NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheCloseSecretStore failed: %d\n",retVal);
|
||
|
}
|
||
|
DECORATE
|
||
|
}
|
||
|
|
||
|
|
||
|
void TestCacheRemoveKeyChain_Valid(void)
|
||
|
{
|
||
|
SSCS_SECRETSTORE_T secID;
|
||
|
SSCS_SECRETSTORE_HANDLE_T *ssHandle = NULL;
|
||
|
SSCS_KEYCHAIN_ID_LIST_T kcIDList;
|
||
|
int retVal = 0;
|
||
|
uint32_t ssFlags = 0;
|
||
|
SSCS_KEYCHAIN_ID_T keychainID;
|
||
|
memset(&keychainID,0,sizeof(SSCS_KEYCHAIN_ID_T));
|
||
|
strcpy((char*)(keychainID.keychainID),"MyKeychain");
|
||
|
keychainID.len = strlen("MyKeychain")+1;
|
||
|
|
||
|
/* sscs_CacheOpenSecretStore */
|
||
|
|
||
|
DECORATE
|
||
|
secID.version = 0x00040000;
|
||
|
strcpy((char *)secID.ssName,"SecretStore");
|
||
|
|
||
|
ssHandle = sscs_CacheOpenSecretStore(&secID, ssFlags, NULL);
|
||
|
if(!ssHandle)
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore failed\n");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore succeeded\n");
|
||
|
}
|
||
|
printf("Platform ID is %d; socketID is %d\n",ssHandle->platformID,
|
||
|
*(int*)ssHandle->platHandle);
|
||
|
|
||
|
ssFlags |= SSCS_LOCAL_KEY_CHAIN_F;
|
||
|
|
||
|
printf("Adding %s \n",keychainID.keychainID);
|
||
|
|
||
|
retVal = sscs_CacheAddKeychain(ssHandle,ssFlags,&keychainID,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheAddKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
EnumerateIDs(ssHandle,0,NULL);
|
||
|
|
||
|
printf("Removing %s\n",keychainID.keychainID);
|
||
|
|
||
|
retVal = sscs_CacheRemoveKeychain(ssHandle,ssFlags,&keychainID,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheRemoveKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
|
||
|
EnumerateIDs(ssHandle,0,&keychainID);
|
||
|
|
||
|
retVal = sscs_CacheCloseSecretStore(ssHandle, ssFlags, NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheCloseSecretStore failed: %d\n",retVal);
|
||
|
}
|
||
|
DECORATE
|
||
|
}
|
||
|
|
||
|
void TestCacheRemoveKeyChain_NonExistentKeychain(void)
|
||
|
{
|
||
|
SSCS_SECRETSTORE_T secID;
|
||
|
SSCS_SECRETSTORE_HANDLE_T *ssHandle = NULL;
|
||
|
SSCS_KEYCHAIN_ID_LIST_T kcIDList;
|
||
|
int retVal = 0;
|
||
|
uint32_t ssFlags = 0;
|
||
|
SSCS_KEYCHAIN_ID_T keychainID;
|
||
|
memset(&keychainID,0,sizeof(SSCS_KEYCHAIN_ID_T));
|
||
|
strcpy((char*)(keychainID.keychainID),"Non-existent");
|
||
|
keychainID.len = strlen("Non-existent")+1;
|
||
|
|
||
|
DECORATE
|
||
|
printf("INPUT: {0x00040000, SecretStore}\n");
|
||
|
|
||
|
secID.version = 0x00040000;
|
||
|
strcpy((char *)secID.ssName,"SecretStore");
|
||
|
|
||
|
ssHandle = sscs_CacheOpenSecretStore(&secID, ssFlags, NULL);
|
||
|
if(!ssHandle)
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore failed\n");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore succeeded\n");
|
||
|
}
|
||
|
printf("Platform ID is %d; socketID is %d\n",ssHandle->platformID,
|
||
|
*(int*)ssHandle->platHandle);
|
||
|
|
||
|
printf("Removing %s\n",keychainID.keychainID);
|
||
|
|
||
|
retVal = sscs_CacheRemoveKeychain(ssHandle,ssFlags,&keychainID,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheAddKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
|
||
|
EnumerateIDs(ssHandle,0,&keychainID);
|
||
|
|
||
|
retVal = sscs_CacheCloseSecretStore(ssHandle, ssFlags,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheCloseSecretStore failed: %d\n",retVal);
|
||
|
}
|
||
|
DECORATE
|
||
|
}
|
||
|
|
||
|
void TestCacheRemoveKeyChain_OverlappingNames(void)
|
||
|
{
|
||
|
SSCS_SECRETSTORE_T secID;
|
||
|
SSCS_SECRETSTORE_HANDLE_T *ssHandle = NULL;
|
||
|
SSCS_KEYCHAIN_ID_LIST_T kcIDList;
|
||
|
int retVal = 0;
|
||
|
uint32_t ssFlags = 0;
|
||
|
SSCS_KEYCHAIN_ID_T keychainID;
|
||
|
memset(&keychainID,0,sizeof(SSCS_KEYCHAIN_ID_T));
|
||
|
strcpy((char*)(keychainID.keychainID),"Keychain1");
|
||
|
keychainID.len = strlen("Keychain1")+1;
|
||
|
|
||
|
/* sscs_CacheOpenSecretStore */
|
||
|
|
||
|
DECORATE
|
||
|
secID.version = 0x00040000;
|
||
|
strcpy((char *)secID.ssName,"SecretStore");
|
||
|
|
||
|
ssHandle = sscs_CacheOpenSecretStore(&secID, ssFlags, NULL);
|
||
|
if(!ssHandle)
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore failed\n");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("sscs_CacheOpenSecretStore succeeded\n");
|
||
|
}
|
||
|
printf("Platform ID is %d; socketID is %d\n",ssHandle->platformID,
|
||
|
*(int*)ssHandle->platHandle);
|
||
|
|
||
|
ssFlags |= SSCS_LOCAL_KEY_CHAIN_F;
|
||
|
printf("Adding %s \n",keychainID.keychainID);
|
||
|
|
||
|
retVal = sscs_CacheAddKeychain(ssHandle,ssFlags,&keychainID,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheAddKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
|
||
|
strcpy(keychainID.keychainID,"Keychain1");
|
||
|
keychainID.len = strlen("Keychain1")+1;
|
||
|
printf("Adding %s \n",keychainID.keychainID);
|
||
|
|
||
|
retVal = sscs_CacheAddKeychain(ssHandle,ssFlags,&keychainID,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheAddKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
|
||
|
strcpy(keychainID.keychainID,"Keychain");
|
||
|
keychainID.len = strlen("Keychain")+1;
|
||
|
|
||
|
printf("Removing %s\n",keychainID.keychainID);
|
||
|
|
||
|
retVal = sscs_CacheRemoveKeychain(ssHandle,ssFlags, &keychainID,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheRemoveKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
|
||
|
EnumerateIDs(ssHandle,0,&keychainID);
|
||
|
|
||
|
strcpy(keychainID.keychainID,"Keychain1");
|
||
|
keychainID.len = strlen("Keychain1")+1;
|
||
|
printf("Removing %s\n",keychainID.keychainID);
|
||
|
|
||
|
retVal = sscs_CacheRemoveKeychain(ssHandle,ssFlags,&keychainID,NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheRemoveKeychain failed: %d\n",retVal);
|
||
|
}
|
||
|
EnumerateIDs(ssHandle,0,&keychainID);
|
||
|
|
||
|
retVal = sscs_CacheCloseSecretStore(ssHandle, ssFlags, NULL);
|
||
|
if(retVal != 0)
|
||
|
{
|
||
|
printf("sscs_CacheCloseSecretStore failed: %d\n",retVal);
|
||
|
}
|
||
|
DECORATE
|
||
|
}
|
||
|
|