diff --git a/CASA/micasad/lss/CASACrypto.cs b/CASA/micasad/lss/CASACrypto.cs index 29d87265..9284f62f 100644 --- a/CASA/micasad/lss/CASACrypto.cs +++ b/CASA/micasad/lss/CASACrypto.cs @@ -253,7 +253,7 @@ namespace sscs.crypto fsEncrypt.Write(hash,0,hash.Length); fsEncrypt.Flush(); -#if true//#if CLEAR //RAJ +#if CLEAR byte[] dup = (byte[])xmlData.Clone(); // write clear file FileStream fsClear = new FileStream(fileName + ".xml", FileMode.Create); diff --git a/CASA/micasad/lss/LocalStorage.cs b/CASA/micasad/lss/LocalStorage.cs index 9f8dcefe..2da94ddf 100644 --- a/CASA/micasad/lss/LocalStorage.cs +++ b/CASA/micasad/lss/LocalStorage.cs @@ -74,7 +74,7 @@ namespace sscs.lss private static string LINUXID = "Unix"; - internal LocalStorage(SecretStore store, byte[] baMasterPasscode, bool dummy) // Merge this with the next cons - RAJ + internal LocalStorage(SecretStore store, byte[] baMasterPasscode, bool dummy) { userStore = store; m_baGeneratedKey = baMasterPasscode; diff --git a/CASA/micasadk/linux/micasa_lux.exp b/CASA/micasadk/linux/micasa_lux.exp index 0161ee12..4c95418f 100644 --- a/CASA/micasadk/linux/micasa_lux.exp +++ b/CASA/micasadk/linux/micasa_lux.exp @@ -26,6 +26,7 @@ VER_1.0 miCASALockStore; miCASARemoveKeyChain; miCASARemoveCredential; + miCASADeleteCredential; miCASASetCredential; miCASAGetCredential; miCASAIsSecretPersistent; diff --git a/CASA/test/c_sample/cSample.c b/CASA/test/c_sample/cSample.c index 9e88a6c8..ab6c08c5 100644 --- a/CASA/test/c_sample/cSample.c +++ b/CASA/test/c_sample/cSample.c @@ -21,71 +21,71 @@ ***********************************************************************/ -/* Sample code for C Language miCASA APIs */ - -#include -#include - -#ifdef WIN32 -#include -#include -#else -#define getch(x) getchar(x); -#endif - - -#include -#include -#include -#include -#include - - -/////////////////////////////////////////////////////////////////////// - - -unsigned char UTF8Value[] = {0xED, 0x98, 0x9C, 0xED, 0x98, 0xA4, 0xED, 0x95, 0xAB, 0xED, 0x9B, 0xA7, 0xED, 0x9D, 0x8F, 00}; - -void Pause() -{ - printf("\nPress a key ==>\n"); - getch(); -} /* end of Pause */ - - - -void RemoveKey() -{ - int rcode = 0; - char inputID[20]; - char inputKey[20]; - char inputValue[128] = {0}; - uint32_t valueLen = 128; - uint32_t bytesRequired = 0; - - SSCS_SECRETSTORE_T store = {0}; - SSCS_SECRET_ID_T appSecretId = {0}; - SSCS_SECRET_ID_T sharedSecretId = {0}; - void *context; - SSCS_KEYCHAIN_ID_T kc = {0}; - - SSCS_EXT_T ext = {0}; - - printf("Enter secretID: "); - gets(inputID); - - printf("Enter Key to remove: "); - gets(inputKey); - - if ((sscs_Utf8Strlen(inputID) > 0) && - (sscs_Utf8Strlen(inputKey) > 0)) - - { - appSecretId.len = sscs_Utf8Strlen(inputID) + 1; - sscs_Utf8Strcpy(appSecretId.id, inputID); - - printf("SAMPLE: Calling miCASAReadKey\r\n"); - +/* Sample code for C Language miCASA APIs */ + +#include +#include + +#ifdef WIN32 +#include +#include +#else +#define getch(x) getchar(x); +#endif + + +#include +#include +#include +#include +#include + + +/////////////////////////////////////////////////////////////////////// + + +unsigned char UTF8Value[] = {0xED, 0x98, 0x9C, 0xED, 0x98, 0xA4, 0xED, 0x95, 0xAB, 0xED, 0x9B, 0xA7, 0xED, 0x9D, 0x8F, 00}; + +void Pause() +{ + printf("\nPress a key ==>\n"); + getch(); +} /* end of Pause */ + + + +void RemoveKey() +{ + int rcode = 0; + char inputID[20]; + char inputKey[20]; + char inputValue[128] = {0}; + uint32_t valueLen = 128; + uint32_t bytesRequired = 0; + + SSCS_SECRETSTORE_T store = {0}; + SSCS_SECRET_ID_T appSecretId = {0}; + SSCS_SECRET_ID_T sharedSecretId = {0}; + void *context; + SSCS_KEYCHAIN_ID_T kc = {0}; + + SSCS_EXT_T ext = {0}; + + printf("Enter secretID: "); + gets(inputID); + + printf("Enter Key to remove: "); + gets(inputKey); + + if ((sscs_Utf8Strlen(inputID) > 0) && + (sscs_Utf8Strlen(inputKey) > 0)) + + { + appSecretId.len = sscs_Utf8Strlen(inputID) + 1; + sscs_Utf8Strcpy(appSecretId.id, inputID); + + printf("SAMPLE: Calling miCASAReadKey\r\n"); + // open secretStore sscs_Utf8Strcpy(store.ssName, SSCS_DEFAULT_SECRETSTORE_ID); store.version = 1; @@ -94,69 +94,69 @@ void RemoveKey() if (context == NULL) { return; // NSSCS_E_SYSTEM_FAILURE; - } - + } + sscs_Utf8Strcpy(kc.keychainID, SSCS_SESSION_KEY_CHAIN_ID); - kc.len = SSCS_S_KC_ID_CHARS; - - rcode = miCASARemoveKey(context, - 0, - &kc, - &appSecretId, - inputKey, - strlen(inputKey)+1, - NULL, - &ext); - - miCASACloseSecretStoreCache(context, 0, NULL); - - if (rcode) - { - printf("miCASARemoveKey returned %d\r\n", rcode); - Pause(); - } - else - { - //set null - //memcpy(inputValue[valueLen + 1], - printf("Remove Key Successful\r\n"); - } - } -} - - -void ReadKey() -{ - int rcode = 0; - char inputID[20]; - char inputKey[20]; - char inputValue[128] = {0}; - uint32_t valueLen = 128; - uint32_t bytesRequired = 0; - - SSCS_SECRETSTORE_T store = {0}; - SSCS_SECRET_ID_T appSecretId = {0}; - SSCS_SECRET_ID_T sharedSecretId = {0}; - void *context; - SSCS_KEYCHAIN_ID_T kc = {0}; - - SSCS_EXT_T ext = {0}; - - printf("Enter secretID: "); - gets(inputID); - - printf("Enter Key: "); - gets(inputKey); - - if ((sscs_Utf8Strlen(inputID) > 0) && - (sscs_Utf8Strlen(inputKey) > 0)) - - { - appSecretId.len = sscs_Utf8Strlen(inputID) + 1; - sscs_Utf8Strcpy(appSecretId.id, inputID); - - printf("SAMPLE: Calling miCASAReadKey\r\n"); - + kc.len = SSCS_S_KC_ID_CHARS; + + rcode = miCASARemoveKey(context, + 0, + &kc, + &appSecretId, + inputKey, + strlen(inputKey)+1, + NULL, + &ext); + + miCASACloseSecretStoreCache(context, 0, NULL); + + if (rcode) + { + printf("miCASARemoveKey returned %d\r\n", rcode); + Pause(); + } + else + { + //set null + //memcpy(inputValue[valueLen + 1], + printf("Remove Key Successful\r\n"); + } + } +} + + +void ReadKey() +{ + int rcode = 0; + char inputID[20]; + char inputKey[20]; + char inputValue[128] = {0}; + uint32_t valueLen = 128; + uint32_t bytesRequired = 0; + + SSCS_SECRETSTORE_T store = {0}; + SSCS_SECRET_ID_T appSecretId = {0}; + SSCS_SECRET_ID_T sharedSecretId = {0}; + void *context; + SSCS_KEYCHAIN_ID_T kc = {0}; + + SSCS_EXT_T ext = {0}; + + printf("Enter secretID: "); + gets(inputID); + + printf("Enter Key: "); + gets(inputKey); + + if ((sscs_Utf8Strlen(inputID) > 0) && + (sscs_Utf8Strlen(inputKey) > 0)) + + { + appSecretId.len = sscs_Utf8Strlen(inputID) + 1; + sscs_Utf8Strcpy(appSecretId.id, inputID); + + printf("SAMPLE: Calling miCASAReadKey\r\n"); + // open secretStore sscs_Utf8Strcpy(store.ssName, SSCS_DEFAULT_SECRETSTORE_ID); store.version = 1; @@ -165,72 +165,72 @@ void ReadKey() if (context == NULL) { return; // NSSCS_E_SYSTEM_FAILURE; - } - + } + sscs_Utf8Strcpy(kc.keychainID, SSCS_SESSION_KEY_CHAIN_ID); - kc.len = SSCS_S_KC_ID_CHARS; - - rcode = miCASAReadKey(context, - 0, - &kc, - &appSecretId, - inputKey, - strlen(inputKey)+1, - inputValue, - &valueLen, - NULL, - &bytesRequired, - &ext); - - miCASACloseSecretStoreCache(context, 0, NULL); - - if (rcode) - { - printf("miCASAReadKey returned %d\r\n", rcode); - Pause(); - } - else - { - //set null - //memcpy(inputValue[valueLen + 1], - printf("KeyValue is %s\r\n", inputValue); - } - } -} - - -void ReadBinaryKey() -{ - int rcode = 0; - char inputID[20]; - char inputKey[20]; - char inputValue[128] = {0}; - uint32_t valueLen = 128; - uint32_t bytesRequired = 0; - - SSCS_SECRETSTORE_T store = {0}; - SSCS_SECRET_ID_T appSecretId = {0}; - SSCS_SECRET_ID_T sharedSecretId = {0}; - void *context; - SSCS_KEYCHAIN_ID_T kc = {0}; - - SSCS_EXT_T ext = {0}; - - printf("Enter secretID: "); - gets(inputID); - - printf("Enter Key: "); - gets(inputKey); - - if ((sscs_Utf8Strlen(inputID) > 0) && - (sscs_Utf8Strlen(inputKey) > 0)) - - { - appSecretId.len = sscs_Utf8Strlen(inputID) + 1; - sscs_Utf8Strcpy(appSecretId.id, inputID); - - printf("SAMPLE: Calling miCASAReadBinaryKey\r\n"); - + kc.len = SSCS_S_KC_ID_CHARS; + + rcode = miCASAReadKey(context, + 0, + &kc, + &appSecretId, + inputKey, + strlen(inputKey)+1, + inputValue, + &valueLen, + NULL, + &bytesRequired, + &ext); + + miCASACloseSecretStoreCache(context, 0, NULL); + + if (rcode) + { + printf("miCASAReadKey returned %d\r\n", rcode); + Pause(); + } + else + { + //set null + //memcpy(inputValue[valueLen + 1], + printf("KeyValue is %s\r\n", inputValue); + } + } +} + + +void ReadBinaryKey() +{ + int rcode = 0; + char inputID[20]; + char inputKey[20]; + char inputValue[128] = {0}; + uint32_t valueLen = 128; + uint32_t bytesRequired = 0; + + SSCS_SECRETSTORE_T store = {0}; + SSCS_SECRET_ID_T appSecretId = {0}; + SSCS_SECRET_ID_T sharedSecretId = {0}; + void *context; + SSCS_KEYCHAIN_ID_T kc = {0}; + + SSCS_EXT_T ext = {0}; + + printf("Enter secretID: "); + gets(inputID); + + printf("Enter Key: "); + gets(inputKey); + + if ((sscs_Utf8Strlen(inputID) > 0) && + (sscs_Utf8Strlen(inputKey) > 0)) + + { + appSecretId.len = sscs_Utf8Strlen(inputID) + 1; + sscs_Utf8Strcpy(appSecretId.id, inputID); + + printf("SAMPLE: Calling miCASAReadBinaryKey\r\n"); + // open secretStore sscs_Utf8Strcpy(store.ssName, SSCS_DEFAULT_SECRETSTORE_ID); store.version = 1; @@ -239,81 +239,81 @@ void ReadBinaryKey() if (context == NULL) { return; // NSSCS_E_SYSTEM_FAILURE; - } - + } + sscs_Utf8Strcpy(kc.keychainID, SSCS_SESSION_KEY_CHAIN_ID); - kc.len = SSCS_S_KC_ID_CHARS; - - rcode = miCASAReadBinaryKey(context, - 0, - &kc, - &appSecretId, - inputKey, - strlen(inputKey)+1, - inputValue, - &valueLen, - NULL, - &bytesRequired, - &ext); - - miCASACloseSecretStoreCache(context, 0, NULL); - - if (rcode) - { - printf("miCASAReadKey returned %d\r\n", rcode); - Pause(); - } - else - { - //set null - //memcpy(inputValue[valueLen + 1], - //printf("KeyValue is %s\r\n", inputValue); - if (!memcmp(inputValue, UTF8Value, valueLen)) - { - printf("Matched\r\n"); - } - else - { - printf("did not match\r\n"); - } - } - } -} - - -void WriteKey() -{ - int rcode = 0; - char inputID[20]; - char inputKey[20]; - char inputValue[20]; - - SSCS_SECRETSTORE_T store = {0}; - SSCS_SECRET_ID_T appSecretId = {0}; - SSCS_SECRET_ID_T sharedSecretId = {0}; - void *context; - SSCS_KEYCHAIN_ID_T kc = {0}; - - SSCS_EXT_T ext = {0}; - - printf("Enter secretID: "); - gets(inputID); - - printf("Enter Key: "); - gets(inputKey); - - printf("Enter Value: "); - gets(inputValue); - - if ((sscs_Utf8Strlen(inputID) > 0) && - (sscs_Utf8Strlen(inputKey) > 0) && - (sscs_Utf8Strlen(inputValue) > 0)) - { - appSecretId.len = sscs_Utf8Strlen(inputID) + 1; - sscs_Utf8Strcpy(appSecretId.id, inputID); - - printf("SAMPLE: Calling miCASAWriteKey\r\n"); - + kc.len = SSCS_S_KC_ID_CHARS; + + rcode = miCASAReadBinaryKey(context, + 0, + &kc, + &appSecretId, + inputKey, + strlen(inputKey)+1, + inputValue, + &valueLen, + NULL, + &bytesRequired, + &ext); + + miCASACloseSecretStoreCache(context, 0, NULL); + + if (rcode) + { + printf("miCASAReadKey returned %d\r\n", rcode); + Pause(); + } + else + { + //set null + //memcpy(inputValue[valueLen + 1], + //printf("KeyValue is %s\r\n", inputValue); + if (!memcmp(inputValue, UTF8Value, valueLen)) + { + printf("Matched\r\n"); + } + else + { + printf("did not match\r\n"); + } + } + } +} + + +void WriteKey() +{ + int rcode = 0; + char inputID[20]; + char inputKey[20]; + char inputValue[20]; + + SSCS_SECRETSTORE_T store = {0}; + SSCS_SECRET_ID_T appSecretId = {0}; + SSCS_SECRET_ID_T sharedSecretId = {0}; + void *context; + SSCS_KEYCHAIN_ID_T kc = {0}; + + SSCS_EXT_T ext = {0}; + + printf("Enter secretID: "); + gets(inputID); + + printf("Enter Key: "); + gets(inputKey); + + printf("Enter Value: "); + gets(inputValue); + + if ((sscs_Utf8Strlen(inputID) > 0) && + (sscs_Utf8Strlen(inputKey) > 0) && + (sscs_Utf8Strlen(inputValue) > 0)) + { + appSecretId.len = sscs_Utf8Strlen(inputID) + 1; + sscs_Utf8Strcpy(appSecretId.id, inputID); + + printf("SAMPLE: Calling miCASAWriteKey\r\n"); + // open secretStore sscs_Utf8Strcpy(store.ssName, SSCS_DEFAULT_SECRETSTORE_ID); store.version = 1; @@ -322,66 +322,66 @@ void WriteKey() if (context == NULL) { return; // NSSCS_E_SYSTEM_FAILURE; - } - + } + sscs_Utf8Strcpy(kc.keychainID, SSCS_SESSION_KEY_CHAIN_ID); - kc.len = SSCS_S_KC_ID_CHARS; - - rcode = miCASAWriteKey(context, - 0, - &kc, - &appSecretId, - inputKey, - strlen(inputKey)+1, - inputValue, - strlen(inputValue)+1, - NULL, - &ext); - - miCASACloseSecretStoreCache(context, 0, NULL); - - if (rcode) - { - printf("miCASAWriteKey returned %d\r\n", rcode); - Pause(); - } - } -} - -void WriteBinaryKey() -{ - int rcode = 0; - char inputID[20]; - char inputKey[20]; - char inputValue[20]; - uint32_t valueLen = 0; - - SSCS_SECRETSTORE_T store = {0}; - SSCS_SECRET_ID_T appSecretId = {0}; - SSCS_SECRET_ID_T sharedSecretId = {0}; - void *context; - SSCS_KEYCHAIN_ID_T kc = {0}; - - SSCS_EXT_T ext = {0}; - - printf("Enter secretID: "); - gets(inputID); - - printf("Enter Key: "); - gets(inputKey); - - //printf("Enter Value: "); - //gets(inputValue); - - if ((sscs_Utf8Strlen(inputID) > 0) && - (sscs_Utf8Strlen(inputKey) > 0)) - - { - appSecretId.len = sscs_Utf8Strlen(inputID) + 1; - sscs_Utf8Strcpy(appSecretId.id, inputID); - - printf("SAMPLE: Calling miCASAWriteBinaryKey\r\n"); - + kc.len = SSCS_S_KC_ID_CHARS; + + rcode = miCASAWriteKey(context, + 0, + &kc, + &appSecretId, + inputKey, + strlen(inputKey)+1, + inputValue, + strlen(inputValue)+1, + NULL, + &ext); + + miCASACloseSecretStoreCache(context, 0, NULL); + + if (rcode) + { + printf("miCASAWriteKey returned %d\r\n", rcode); + Pause(); + } + } +} + +void WriteBinaryKey() +{ + int rcode = 0; + char inputID[20]; + char inputKey[20]; + char inputValue[20]; + uint32_t valueLen = 0; + + SSCS_SECRETSTORE_T store = {0}; + SSCS_SECRET_ID_T appSecretId = {0}; + SSCS_SECRET_ID_T sharedSecretId = {0}; + void *context; + SSCS_KEYCHAIN_ID_T kc = {0}; + + SSCS_EXT_T ext = {0}; + + printf("Enter secretID: "); + gets(inputID); + + printf("Enter Key: "); + gets(inputKey); + + //printf("Enter Value: "); + //gets(inputValue); + + if ((sscs_Utf8Strlen(inputID) > 0) && + (sscs_Utf8Strlen(inputKey) > 0)) + + { + appSecretId.len = sscs_Utf8Strlen(inputID) + 1; + sscs_Utf8Strcpy(appSecretId.id, inputID); + + printf("SAMPLE: Calling miCASAWriteBinaryKey\r\n"); + // open secretStore sscs_Utf8Strcpy(store.ssName, SSCS_DEFAULT_SECRETSTORE_ID); store.version = 1; @@ -390,447 +390,486 @@ void WriteBinaryKey() if (context == NULL) { return; // NSSCS_E_SYSTEM_FAILURE; - } - + } + sscs_Utf8Strcpy(kc.keychainID, SSCS_SESSION_KEY_CHAIN_ID); - kc.len = SSCS_S_KC_ID_CHARS; - - valueLen = strlen(UTF8Value) + 1; - - rcode = miCASAWriteBinaryKey(context, - 0, - &kc, - &appSecretId, - inputKey, - strlen(inputKey)+1, - UTF8Value, - &valueLen, - NULL, - &ext); - - miCASACloseSecretStoreCache(context, 0, NULL); - - if (rcode) - { - printf("miCASAWriteKey returned %d\r\n", rcode); - Pause(); - } - } -} - -void AddSecret() -{ - int rcode = 0; - char inputID[20]; - char inputUsername[20]; - char inputPassword[20]; - - SSCS_BASIC_CREDENTIAL credential = {0}; - SSCS_SECRET_ID_T appSecretId = {0}; - SSCS_SECRET_ID_T sharedSecretId = {0}; - - SSCS_EXT_T ext = {0}; - - printf("Enter secretID: "); - gets(inputID); - - printf("Enter Username: "); - gets(inputUsername); - - printf("Enter Password: "); - gets(inputPassword); - - if ((sscs_Utf8Strlen(inputID) > 0) && - (sscs_Utf8Strlen(inputUsername) > 0) && - (sscs_Utf8Strlen(inputPassword) > 0)) - { - appSecretId.len = sscs_Utf8Strlen(inputID) + 1; - sscs_Utf8Strcpy(appSecretId.id, inputID); - - credential.unFlags = USERNAME_TYPE_CN_F; - sscs_Utf8Strcpy(credential.username, inputUsername); - credential.unLen = sscs_Utf8Strlen(inputUsername) + 1; - - sscs_Utf8Strcpy(credential.password, inputPassword); - credential.pwordLen = sscs_Utf8Strlen(inputPassword) + 1; - - printf("SAMPLE: Calling miCASASetCredential\r\n"); - // sets the credential for this app - rcode = miCASASetCredential( - 0, - &appSecretId, - NULL, - SSCS_CRED_TYPE_BASIC_F, - &credential, - NULL - ); - - if (rcode) - { - printf("Add Secret returned %d\r\n", rcode); - Pause(); - } - } -} - -void DisplaySecret() -{ - - int rcode = 0; - char inputID[20]; - int32_t credtype = SSCS_CRED_TYPE_BASIC_F; - - SSCS_BASIC_CREDENTIAL credential = {0}; - SSCS_SECRET_ID_T appSecretId = {0}; - SSCS_SECRET_ID_T sharedSecretId = {0}; - - SSCS_EXT_T ext = {0}; - - printf("Enter secretID to display: "); - gets(inputID); - - if (sscs_Utf8Strlen(inputID) > 0) - { - appSecretId.len = sscs_Utf8Strlen(inputID) + 1; - sscs_Utf8Strcpy(appSecretId.id, inputID); - - // set name type we desire - credential.unFlags = USERNAME_TYPE_CN_F; - - // gets the credential - rcode = miCASAGetCredential( - 0, - &appSecretId, - NULL, - &credtype, //SSCS_CRED_TYPE_BASIC_F, - &credential, - NULL - ); - - if (rcode == NSSCS_SUCCESS) - { - printf("Credential for: %s\r\n", appSecretId.id); - printf("Username: %s\r\n", credential.username); - printf("Password: %s\r\n", credential.password); - } - else - { - printf("Error: %d\r\n", rcode); - Pause(); - } - } -} - -void RemoveSecret() -{ - int rcode = 0; - char inputID[20]; - - SSCS_BASIC_CREDENTIAL credential = {0}; - SSCS_SECRET_ID_T appSecretId = {0}; - SSCS_SECRET_ID_T sharedSecretId = {0}; - - SSCS_EXT_T ext = {0}; - - printf("Enter secretID to remove: "); - gets(inputID); - - if (sscs_Utf8Strlen(inputID) > 0) - { - appSecretId.len = sscs_Utf8Strlen(inputID) + 1; - sscs_Utf8Strcpy(appSecretId.id, inputID); - - // set name type we desire - credential.unFlags = USERNAME_TYPE_CN_F; - - // gets the credential - rcode = miCASARemoveCredential( - 0, - &appSecretId, - NULL, - NULL - ); - - if (rcode == NSSCS_SUCCESS) - { - printf("Credential %s removed\r\n", inputID); - } - else - { - printf("Error: %d\r\n", rcode); - Pause(); - } - } -} - -void RunTest() -{ - { - SSCS_BASIC_CREDENTIAL credential = {0}; - SSCS_SECRET_ID_T appSecretId = {0}; - int32_t credtype = SSCS_CRED_TYPE_BASIC_F; - - int rcode = 0; - int iFlags = 0; - - sscs_Utf8Strcpy(appSecretId.id, "NativeC.AppSecretID"); - appSecretId.len = sscs_Utf8Strlen(appSecretId.id) + 1; - - credential.unFlags = USERNAME_TYPE_CN_F; - sscs_Utf8Strcpy((char*)credential.username, "SampleUsername"); - credential.unLen = sscs_Utf8Strlen(credential.username) + 1; - - sscs_Utf8Strcpy((char*)credential.password, "SamplePassword"); - credential.pwordLen = sscs_Utf8Strlen(credential.password) + 1; - - printf("Setting %s\r\n", appSecretId.id); - printf(" Username: %s\r\n", credential.username); - printf(" Password: %s\r\n", credential.password); - - // sets the credential for this app - rcode = miCASASetCredential( - iFlags, - &appSecretId, - NULL, - SSCS_CRED_TYPE_BASIC_F, - &credential, - NULL - ); - - credential.unFlags = USERNAME_TYPE_EMAIL_F; - sscs_Utf8Strcpy((char*)credential.username, "Username@novell.com"); - credential.unLen = sscs_Utf8Strlen(credential.username) + 1; - - sscs_Utf8Strcpy((char*)credential.password, "SamplePassword"); - credential.pwordLen = sscs_Utf8Strlen(credential.password) + 1; - - // sets the credential for this app - rcode = miCASASetCredential( - iFlags, - &appSecretId, - NULL, - SSCS_CRED_TYPE_BASIC_F, - &credential, - NULL - ); - - credential.unFlags = USERNAME_TYPE_LDAP_DN_F; - sscs_Utf8Strcpy((char*)credential.username, "cn=user,o=novell"); - credential.unLen = sscs_Utf8Strlen(credential.username) + 1; - - sscs_Utf8Strcpy((char*)credential.password, "SamplePassword"); - credential.pwordLen = sscs_Utf8Strlen(credential.password) + 1; - - // sets the credential for this app - rcode = miCASASetCredential( - iFlags, - &appSecretId, - NULL, - SSCS_CRED_TYPE_BASIC_F, - &credential, - NULL - ); - - credential.unFlags = USERNAME_TYPE_NDS_DN_F; - sscs_Utf8Strcpy((char*)credential.username, "Username.novell"); - credential.unLen = sscs_Utf8Strlen(credential.username) + 1; - - sscs_Utf8Strcpy((char*)credential.password, "SamplePassword"); - credential.pwordLen = sscs_Utf8Strlen(credential.password) + 1; - - // sets the credential for this app - rcode = miCASASetCredential( - iFlags, - &appSecretId, - NULL, - SSCS_CRED_TYPE_BASIC_F, - &credential, - NULL - ); - - - - // get the stuff back now - memset(&credential, 0, sizeof(SSCS_BASIC_CREDENTIAL)); - - credential.unLen = NSSCS_MAX_USERID_LEN; - credential.pwordLen = NSSCS_MAX_PWORD_LEN; - credential.unFlags = USERNAME_TYPE_CN_F; - - // gets the specific credential - rcode = miCASAGetCredential( - iFlags, - &appSecretId, - NULL, - &credtype, //SSCS_CRED_TYPE_BASIC_F, - &credential, - NULL - ); - - - if (rcode == NSSCS_SUCCESS) - { - printf("Getting Credential: %s\r\n", appSecretId.id); - printf(" Username: %s\r\n", credential.username); - printf(" Password: %s\r\n", credential.password); - } - else - { - printf("ERROR getting Credential: %d\r\n", rcode); - Pause(); - } - - printf("Removing Credential\r\n"); - rcode = miCASARemoveCredential( - iFlags, - &appSecretId, - NULL, - NULL - ); - - if (rcode != NSSCS_SUCCESS) - printf("Error removing Credential: %d\r\n", rcode); - - - // get the stuff back now - memset(&credential, 0, sizeof(SSCS_BASIC_CREDENTIAL)); - - credential.unLen = NSSCS_MAX_USERID_LEN; - credential.pwordLen = NSSCS_MAX_PWORD_LEN; - credential.unFlags = USERNAME_TYPE_CN_F; - - // gets the specific credential - rcode = miCASAGetCredential( - iFlags, - &appSecretId, - NULL, - &credtype, //SSCS_CRED_TYPE_BASIC_F, - &credential, - NULL - ); - - - if (rcode == NSSCS_E_INVALID_SECRET_ID) - printf("Credential does not exist as expected -- SUCCESS\r\n"); - else - { - printf("Credential exists, when it should not -- FAILED\r\n"); - Pause(); - } - - - - printf("Test completed\r\n"); - - } - -} - - -void RunTests() -{ - - char runtimes[6]; - int iCount = 1; - int iTemp = 0; - int i = 0; - - printf("Enter number interations to run (default 1): "); - gets(runtimes); - - iTemp = atoi(runtimes); - if (iTemp > 1) - iCount=iTemp; - - for (i=0; i 0) && + (sscs_Utf8Strlen(inputUsername) > 0) && + (sscs_Utf8Strlen(inputPassword) > 0)) + { + appSecretId.len = sscs_Utf8Strlen(inputID) + 1; + sscs_Utf8Strcpy(appSecretId.id, inputID); + + credential.unFlags = USERNAME_TYPE_CN_F; + sscs_Utf8Strcpy(credential.username, inputUsername); + credential.unLen = sscs_Utf8Strlen(inputUsername) + 1; + + sscs_Utf8Strcpy(credential.password, inputPassword); + credential.pwordLen = sscs_Utf8Strlen(inputPassword) + 1; + + printf("SAMPLE: Calling miCASASetCredential\r\n"); + // sets the credential for this app + rcode = miCASASetCredential( + 0, + &appSecretId, + NULL, + credentialType, + &credential, + NULL + ); + + if (rcode) + { + printf("Add Secret returned %d\r\n", rcode); + Pause(); + } + } +} + +void DisplaySecret(int32_t credentialType) +{ + + int rcode = 0; + char inputID[20]; + int32_t credtype = credentialType; + + SSCS_BASIC_CREDENTIAL credential = {0}; + SSCS_SECRET_ID_T appSecretId = {0}; + SSCS_SECRET_ID_T sharedSecretId = {0}; + + SSCS_EXT_T ext = {0}; + + printf("Enter secretID to display: "); + gets(inputID); + + if (sscs_Utf8Strlen(inputID) > 0) + { + appSecretId.len = sscs_Utf8Strlen(inputID) + 1; + sscs_Utf8Strcpy(appSecretId.id, inputID); + + // set name type we desire + credential.unFlags = USERNAME_TYPE_CN_F; + + // gets the credential + rcode = miCASAGetCredential( + 0, + &appSecretId, + NULL, + &credtype, + &credential, + NULL + ); + + if (rcode == NSSCS_SUCCESS) + { + printf("Credential for: %s\r\n", appSecretId.id); + printf("Username: %s\r\n", credential.username); + printf("Password: %s\r\n", credential.password); + } + else + { + printf("Error: %d\r\n", rcode); + Pause(); + } + } +} + +void RemoveSecret(int32_t credentialType) +{ + int rcode = 0; + char inputID[20]; + + SSCS_BASIC_CREDENTIAL credential = {0}; + SSCS_SECRET_ID_T appSecretId = {0}; + SSCS_SECRET_ID_T sharedSecretId = {0}; + + SSCS_EXT_T ext = {0}; + + printf("Enter secretID to remove: "); + gets(inputID); + + if (sscs_Utf8Strlen(inputID) > 0) + { + appSecretId.len = sscs_Utf8Strlen(inputID) + 1; + sscs_Utf8Strcpy(appSecretId.id, inputID); + + // set name type we desire + credential.unFlags = USERNAME_TYPE_CN_F; + + // gets the credential + rcode = miCASADeleteCredential( + 0, + &appSecretId, + NULL, + credentialType, + NULL + ); + + if (rcode == NSSCS_SUCCESS) + { + printf("Credential %s removed\r\n", inputID); + } + else + { + printf("Error: %d\r\n", rcode); + Pause(); + } + } +} + +void AddUserSecret() +{ + AddSecret(SSCS_CRED_TYPE_BASIC_F); +} + +void DisplayUserSecret() +{ + DisplaySecret(SSCS_CRED_TYPE_BASIC_F); +} + +void RemoveUserSecret() +{ + RemoveSecret(SSCS_CRED_TYPE_BASIC_F); +} + +void AddServerSecret() +{ + AddSecret(SSCS_CRED_TYPE_SERVER_F); +} + +void DisplayServerSecret() +{ + DisplaySecret(SSCS_CRED_TYPE_SERVER_F); +} + +void RemoveServerSecret() +{ + RemoveSecret(SSCS_CRED_TYPE_SERVER_F); +} + +void RunTest() +{ + { + SSCS_BASIC_CREDENTIAL credential = {0}; + SSCS_SECRET_ID_T appSecretId = {0}; + int32_t credtype = SSCS_CRED_TYPE_BASIC_F; + + int rcode = 0; + int iFlags = 0; + + sscs_Utf8Strcpy(appSecretId.id, "NativeC.AppSecretID"); + appSecretId.len = sscs_Utf8Strlen(appSecretId.id) + 1; + + credential.unFlags = USERNAME_TYPE_CN_F; + sscs_Utf8Strcpy((char*)credential.username, "SampleUsername"); + credential.unLen = sscs_Utf8Strlen(credential.username) + 1; + + sscs_Utf8Strcpy((char*)credential.password, "SamplePassword"); + credential.pwordLen = sscs_Utf8Strlen(credential.password) + 1; + + printf("Setting %s\r\n", appSecretId.id); + printf(" Username: %s\r\n", credential.username); + printf(" Password: %s\r\n", credential.password); + + // sets the credential for this app + rcode = miCASASetCredential( + iFlags, + &appSecretId, + NULL, + SSCS_CRED_TYPE_BASIC_F, + &credential, + NULL + ); + + credential.unFlags = USERNAME_TYPE_EMAIL_F; + sscs_Utf8Strcpy((char*)credential.username, "Username@novell.com"); + credential.unLen = sscs_Utf8Strlen(credential.username) + 1; + + sscs_Utf8Strcpy((char*)credential.password, "SamplePassword"); + credential.pwordLen = sscs_Utf8Strlen(credential.password) + 1; + + // sets the credential for this app + rcode = miCASASetCredential( + iFlags, + &appSecretId, + NULL, + SSCS_CRED_TYPE_BASIC_F, + &credential, + NULL + ); + + credential.unFlags = USERNAME_TYPE_LDAP_DN_F; + sscs_Utf8Strcpy((char*)credential.username, "cn=user,o=novell"); + credential.unLen = sscs_Utf8Strlen(credential.username) + 1; + + sscs_Utf8Strcpy((char*)credential.password, "SamplePassword"); + credential.pwordLen = sscs_Utf8Strlen(credential.password) + 1; + + // sets the credential for this app + rcode = miCASASetCredential( + iFlags, + &appSecretId, + NULL, + SSCS_CRED_TYPE_BASIC_F, + &credential, + NULL + ); + + credential.unFlags = USERNAME_TYPE_NDS_DN_F; + sscs_Utf8Strcpy((char*)credential.username, "Username.novell"); + credential.unLen = sscs_Utf8Strlen(credential.username) + 1; + + sscs_Utf8Strcpy((char*)credential.password, "SamplePassword"); + credential.pwordLen = sscs_Utf8Strlen(credential.password) + 1; + + // sets the credential for this app + rcode = miCASASetCredential( + iFlags, + &appSecretId, + NULL, + SSCS_CRED_TYPE_BASIC_F, + &credential, + NULL + ); + + + + // get the stuff back now + memset(&credential, 0, sizeof(SSCS_BASIC_CREDENTIAL)); + + credential.unLen = NSSCS_MAX_USERID_LEN; + credential.pwordLen = NSSCS_MAX_PWORD_LEN; + credential.unFlags = USERNAME_TYPE_CN_F; + + // gets the specific credential + rcode = miCASAGetCredential( + iFlags, + &appSecretId, + NULL, + &credtype, //SSCS_CRED_TYPE_BASIC_F, + &credential, + NULL + ); + + + if (rcode == NSSCS_SUCCESS) + { + printf("Getting Credential: %s\r\n", appSecretId.id); + printf(" Username: %s\r\n", credential.username); + printf(" Password: %s\r\n", credential.password); + } + else + { + printf("ERROR getting Credential: %d\r\n", rcode); + Pause(); + } + + printf("Removing Credential\r\n"); + rcode = miCASARemoveCredential( + iFlags, + &appSecretId, + NULL, + NULL + ); + + if (rcode != NSSCS_SUCCESS) + printf("Error removing Credential: %d\r\n", rcode); + + + // get the stuff back now + memset(&credential, 0, sizeof(SSCS_BASIC_CREDENTIAL)); + + credential.unLen = NSSCS_MAX_USERID_LEN; + credential.pwordLen = NSSCS_MAX_PWORD_LEN; + credential.unFlags = USERNAME_TYPE_CN_F; + + // gets the specific credential + rcode = miCASAGetCredential( + iFlags, + &appSecretId, + NULL, + &credtype, //SSCS_CRED_TYPE_BASIC_F, + &credential, + NULL + ); + + + if (rcode == NSSCS_E_INVALID_SECRET_ID) + printf("Credential does not exist as expected -- SUCCESS\r\n"); + else + { + printf("Credential exists, when it should not -- FAILED\r\n"); + Pause(); + } + + + + printf("Test completed\r\n"); + + } + +} + + +void RunTests() +{ + + char runtimes[6]; + int iCount = 1; + int iTemp = 0; + int i = 0; + + printf("Enter number interations to run (default 1): "); + gets(runtimes); + + iTemp = atoi(runtimes); + if (iTemp > 1) + iCount=iTemp; + + for (i=0; i