Bug 130518. Throw INVALID PARAMETER exception on null and empty strings

This commit is contained in:
Jim Norman 2005-10-31 20:26:21 +00:00
parent 4df26f8574
commit 16eff73590
3 changed files with 389 additions and 329 deletions

View File

@ -35,17 +35,17 @@ namespace Novell.CASA
{ {
public uint pwordType; public uint pwordType;
public uint pwordLen; // * enhanced protection len & pword to set public uint pwordLen; // * enhanced protection len & pword to set
// [MarshalAs(UnmanagedType.LPStr, SizeConst = 128)] // [MarshalAs(UnmanagedType.LPStr, SizeConst = 128)]
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string pword; // * should be passed in # of chars public string pword; // * should be passed in # of chars
} ; } ;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class SSCS_PASSCODE_T public class SSCS_PASSCODE_T
{ {
public uint passcodeType; public uint passcodeType;
public IntPtr passcodeHandle; public IntPtr passcodeHandle;
} }
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class SSCS_KEYCHAIN_ID_T public class SSCS_KEYCHAIN_ID_T
@ -80,13 +80,13 @@ namespace Novell.CASA
public string id; // * should be passed in # of chars public string id; // * should be passed in # of chars
}; };
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public class SSCS_HINT_T public class SSCS_HINT_T
{ {
ulong hintLen; ulong hintLen;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
string hint; //* should be passed in # of chars string hint; //* should be passed in # of chars
}; };
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class SSCS_EXT_T public class SSCS_EXT_T
@ -166,19 +166,19 @@ namespace Novell.CASA
public string hint; //[NSSS_MAX_MP_PWORD_HINT_LEN]]; public string hint; //[NSSS_MAX_MP_PWORD_HINT_LEN]];
}; };
/* /*
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class SSCS_BASIC_CREDENTIAL public class SSCS_BASIC_CREDENTIAL
{ {
public uint unFlags; public uint unFlags;
public uint unLen; public uint unLen;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string username; public string username;
public uint pwordLen; public uint pwordLen;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string password; public string password;
} }
*/ */
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class SSCS_BASIC_CREDENTIAL_UTF8 public class SSCS_BASIC_CREDENTIAL_UTF8
{ {
@ -232,21 +232,21 @@ namespace Novell.CASA
[In] IntPtr credential, [In] IntPtr credential,
[In, Out] SSCS_EXT_T ext [In, Out] SSCS_EXT_T ext
); );
[DllImport(NDK_LIBRARY)] [DllImport(NDK_LIBRARY)]
public static extern int miCASASetMasterPasscode public static extern int miCASASetMasterPasscode
( (
[In] uint ssFlags, [In] uint ssFlags,
[In] SSCS_PASSCODE_T passcode, [In] SSCS_PASSCODE_T passcode,
[In] SSCS_EXT_T ext [In] SSCS_EXT_T ext
); );
[DllImport(NDK_LIBRARY)] [DllImport(NDK_LIBRARY)]
public static extern int miCASAIsSecretPersistent public static extern int miCASAIsSecretPersistent
( (
[In] uint ssFlags, [In] uint ssFlags,
[In] SSCS_SECRET_ID_T secretID, [In] SSCS_SECRET_ID_T secretID,
[In, Out] SSCS_EXT_T ext [In, Out] SSCS_EXT_T ext
); );
[DllImport(NDK_LIBRARY)] [DllImport(NDK_LIBRARY)]
public static extern IntPtr miCASAOpenSecretStoreCache public static extern IntPtr miCASAOpenSecretStoreCache
@ -345,12 +345,12 @@ namespace Novell.CASA
[DllImport(NDK_LIBRARY)] [DllImport(NDK_LIBRARY)]
public static extern int miCASASetMasterPassword public static extern int miCASASetMasterPassword
( (
[In] uint ssFlags, [In] uint ssFlags,
[In] SSCS_PASSWORD_T password, [In] SSCS_PASSWORD_T password,
[In] SSCS_HINT_T hint, [In] SSCS_HINT_T hint,
[In, Out] SSCS_EXT_T ext [In, Out] SSCS_EXT_T ext
); );
[DllImport(NDK_LIBRARY)] [DllImport(NDK_LIBRARY)]
public static extern int miCASAUnlockSecrets public static extern int miCASAUnlockSecrets
@ -440,10 +440,10 @@ namespace Novell.CASA
[In] SSCS_KEYCHAIN_ID_T keyChainID, [In] SSCS_KEYCHAIN_ID_T keyChainID,
[In] SSCS_SH_SECRET_ID_T sharedSecretID, [In] SSCS_SH_SECRET_ID_T sharedSecretID,
[MarshalAs(UnmanagedType.LPStr)] [MarshalAs(UnmanagedType.LPStr)]
string key, //* in /wchar string key, //* in /wchar
[In] uint keyLenBytes, // in bytes [In] uint keyLenBytes, // in bytes
[MarshalAs(UnmanagedType.LPStr)] [MarshalAs(UnmanagedType.LPStr)]
string val, //* in /uchar string val, //* in /uchar
[In] uint valueLenBytes, // in bytes [In] uint valueLenBytes, // in bytes
[In] SSCS_PASSWORD_T password, [In] SSCS_PASSWORD_T password,
[In, Out] SSCS_EXT_T ext [In, Out] SSCS_EXT_T ext
@ -465,6 +465,12 @@ namespace Novell.CASA
// Methods start here // Methods start here
internal IntPtr openSecretStore(string sSecretStoreName) internal IntPtr openSecretStore(string sSecretStoreName)
{ {
//check params
if (sSecretStoreName == null || sSecretStoreName.Length==0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
SSCS_SECRET_STORE_ID_T SSid = new SSCS_SECRET_STORE_ID_T(); SSCS_SECRET_STORE_ID_T SSid = new SSCS_SECRET_STORE_ID_T();
SSid.id = sSecretStoreName; SSid.id = sSecretStoreName;
SSid.len = sSecretStoreName.Length; SSid.len = sSecretStoreName.Length;
@ -488,8 +494,12 @@ namespace Novell.CASA
string sSharedSecretID, string sSharedSecretID,
int iSecretType, int iSecretType,
string sEPPassword) string sEPPassword)
{ {
if (pHsc == IntPtr.Zero || sKeyChainID == null || sSharedSecretID == null
|| sKeyChainID.Length == 0 || sSharedSecretID.Length == 0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
// setup structures // setup structures
SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T(); SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T();
keyChainID.keychainID = sKeyChainID; keyChainID.keychainID = sKeyChainID;
@ -610,119 +620,119 @@ namespace Novell.CASA
return rcode; return rcode;
} }
/* /*
internal int setSecret( internal int setSecret(
IntPtr pHsc, IntPtr pHsc,
string sKeyChainID, string sKeyChainID,
uint iFlags, uint iFlags,
Secret secret, Secret secret,
int iSecretType) int iSecretType)
{
int rcode;
if (iSecretType == Secret.SS_BINARY)
{
rcode = miCASA_AddSHSEntry(
secret.m_secretHandle,
"SS_Binary",
(uint)secret.getBinaryValue().Length,
secret.getBinaryValue().ToString());
}
else
{
NameValueCollection nvc = secret.getKeyValueCollection();
if (nvc != null)
{ {
for (int i=0; i<nvc.Count; i++) int rcode;
if (iSecretType == Secret.SS_BINARY)
{ {
rcode = miCASA_AddSHSEntry(
String sKey = nvc.GetKey(i); secret.m_secretHandle,
String sValue = nvc.Get(sKey); // = new StringBuilder(); "SS_Binary",
(uint)secret.getBinaryValue().Length,
if (sKey.Length > 0) secret.getBinaryValue().ToString());
{
// first write out all key/value pairs
rcode = miCASA_AddSHSEntry(
secret.m_secretHandle,
sKey, //sKey,
(uint)(sValue.Length+1) * 2,
sValue); //sValue);
}
} }
else
{
NameValueCollection nvc = secret.getKeyValueCollection();
if (nvc != null)
{
for (int i=0; i<nvc.Count; i++)
{
String sKey = nvc.GetKey(i);
String sValue = nvc.Get(sKey); // = new StringBuilder();
if (sKey.Length > 0)
{
// first write out all key/value pairs
rcode = miCASA_AddSHSEntry(
secret.m_secretHandle,
sKey, //sKey,
(uint)(sValue.Length+1) * 2,
sValue); //sValue);
}
}
}
}
// now call miCASAWriteSecret
SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T();
keyChainID.keychainID = sKeyChainID;
SSCS_SH_SECRET_ID_T sharedSecretID = new SSCS_SH_SECRET_ID_T();
SSCS_PASSWORD_T epPassword = new SSCS_PASSWORD_T();
SSCS_EXT_T ext =new SSCS_EXT_T();
ext.extID = 0;
ext.version = 0;
// setup keychainid
keyChainID.len = sKeyChainID.Length + 1;
String tempStr = secret.getID();
sharedSecretID.name = tempStr;
sharedSecretID.len = tempStr.Length + 1;
sharedSecretID.type = iSecretType; // TODO: type APP(1), CRED(2), or Binary(4)
if (secret.getEnhancedProtectionPassword() != null)
{
epPassword.pword = secret.getEnhancedProtectionPassword();
epPassword.pwordLen = (uint)secret.getEnhancedProtectionPassword().Length + 1;
epPassword.pwordType = 0;
}
else
{
epPassword = null;
}
ext.ext = Marshal.AllocHGlobal(10);
try
{
rcode = miCASAWriteSecret(
pHsc,
keyChainID,
iFlags,
secret.m_secretHandle,
sharedSecretID,
epPassword,
ext);
}
catch (Exception)
{
//Console.WriteLine(e.ToString());
rcode = -803;
}
Marshal.FreeHGlobal(ext.ext);
return rcode;
}
*/
internal bool KeyInNewList(NameValueCollection nvc, string key)
{
Console.WriteLine("Checking for " + key );
if (nvc != null)
{
for (int i = 0; i < nvc.Count; i++)
{
string sKey = nvc.GetKey(i);
if( key == sKey )
return true;
} }
} }
//Console.WriteLine("key = " + key + " is not present in nvc");
// now call miCASAWriteSecret return false;
SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T();
keyChainID.keychainID = sKeyChainID;
SSCS_SH_SECRET_ID_T sharedSecretID = new SSCS_SH_SECRET_ID_T();
SSCS_PASSWORD_T epPassword = new SSCS_PASSWORD_T();
SSCS_EXT_T ext =new SSCS_EXT_T();
ext.extID = 0;
ext.version = 0;
// setup keychainid
keyChainID.len = sKeyChainID.Length + 1;
String tempStr = secret.getID();
sharedSecretID.name = tempStr;
sharedSecretID.len = tempStr.Length + 1;
sharedSecretID.type = iSecretType; // TODO: type APP(1), CRED(2), or Binary(4)
if (secret.getEnhancedProtectionPassword() != null)
{
epPassword.pword = secret.getEnhancedProtectionPassword();
epPassword.pwordLen = (uint)secret.getEnhancedProtectionPassword().Length + 1;
epPassword.pwordType = 0;
}
else
{
epPassword = null;
}
ext.ext = Marshal.AllocHGlobal(10);
try
{
rcode = miCASAWriteSecret(
pHsc,
keyChainID,
iFlags,
secret.m_secretHandle,
sharedSecretID,
epPassword,
ext);
}
catch (Exception)
{
//Console.WriteLine(e.ToString());
rcode = -803;
}
Marshal.FreeHGlobal(ext.ext);
return rcode;
} }
*/
internal bool KeyInNewList(NameValueCollection nvc, string key)
{
Console.WriteLine("Checking for " + key );
if (nvc != null)
{
for (int i = 0; i < nvc.Count; i++)
{
string sKey = nvc.GetKey(i);
if( key == sKey )
return true;
}
}
Console.WriteLine("key = " + key + " is not present in nvc");
return false;
}
internal int setSecret( internal int setSecret(
@ -734,6 +744,8 @@ namespace Novell.CASA
{ {
int rcode = 0; int rcode = 0;
if (sKeyChainID == null || sKeyChainID.Length == 0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
// now call miCASAWriteSecret // now call miCASAWriteSecret
SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T(); SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T();
@ -784,7 +796,7 @@ namespace Novell.CASA
for (int i=0; i<nvc.Count; i++) for (int i=0; i<nvc.Count; i++)
{ {
rcode = 0; rcode = 0;
String sKey = nvc.GetKey(i); String sKey = nvc.GetKey(i);
String sValue = nvc.Get(sKey); // = new StringBuilder(); String sValue = nvc.Get(sKey); // = new StringBuilder();
@ -819,33 +831,33 @@ namespace Novell.CASA
} }
} }
if( 0 == rcode ) if( 0 == rcode )
{ {
try try
{ {
ArrayList keyList = (ArrayList)MiCasaRequestReply.Send(MiCasaRequestReply.VERB_GET_KEY_LIST,sKeyChainID,secret.getID(),null,null); ArrayList keyList = (ArrayList)MiCasaRequestReply.Send(MiCasaRequestReply.VERB_GET_KEY_LIST,sKeyChainID,secret.getID(),null,null);
if( null != keyList ) if( null != keyList )
{ {
IEnumerator etor = keyList.GetEnumerator(); IEnumerator etor = keyList.GetEnumerator();
while( etor.MoveNext() ) while( etor.MoveNext() )
{ {
string key = (string)etor.Current; string key = (string)etor.Current;
if(KeyInNewList(nvc,key) == false) if(KeyInNewList(nvc,key) == false)
{ {
MiCasaRequestReply.Send(MiCasaRequestReply.VERB_REMOVE_KEY,sKeyChainID,secret.getID(),key, null ); MiCasaRequestReply.Send(MiCasaRequestReply.VERB_REMOVE_KEY,sKeyChainID,secret.getID(),key, null );
} }
} }
} }
} }
catch(Exception e) catch(Exception e)
{ {
rcode = -803; rcode = -803;
Console.WriteLine(e.ToString()); Console.WriteLine(e.ToString());
} }
} }
} }
} }
@ -862,6 +874,11 @@ namespace Novell.CASA
string sSecretID, string sSecretID,
int iSecretType) int iSecretType)
{ {
if (context == IntPtr.Zero || sKeyChainID == null || sSecretID == null
|| sKeyChainID.Length==0 || sSecretID.Length==0)
return miCasaException.NSSCS_E_INVALID_PARAM;
int rcode = 0; int rcode = 0;
SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T(); SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T();
@ -874,7 +891,7 @@ namespace Novell.CASA
epPassword.pwordType = 0; // todo set type epPassword.pwordType = 0; // todo set type
SSCS_SH_SECRET_ID_T secretID = new SSCS_SH_SECRET_ID_T(); SSCS_SH_SECRET_ID_T secretID = new SSCS_SH_SECRET_ID_T();
secretID.name = sSecretID; secretID.name = sSecretID;
secretID.len = sSecretID.Length + 1; secretID.len = sSecretID.Length + 1;
secretID.type = iSecretType; secretID.type = iSecretType;
@ -903,6 +920,11 @@ namespace Novell.CASA
{ {
if (context == IntPtr.Zero || sKeyChainID==null || sSearchKey==null
|| sKeyChainID.Length==0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
// setup structures // setup structures
SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T(); SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T();
keyChainID.keychainID = sKeyChainID; keyChainID.keychainID = sKeyChainID;
@ -923,7 +945,7 @@ namespace Novell.CASA
idList.returnedIDs = (uint)numIDS; idList.returnedIDs = (uint)numIDS;
SSCS_SH_SECRET_ID_T secretId = new SSCS_SH_SECRET_ID_T(); SSCS_SH_SECRET_ID_T secretId = new SSCS_SH_SECRET_ID_T();
// secretId.name = new char[512]; // secretId.name = new char[512];
StringBuilder buffer3 = new StringBuilder( "content", 512 ); StringBuilder buffer3 = new StringBuilder( "content", 512 );
buffer3.Append( (char)0 ); buffer3.Append( (char)0 );
@ -953,7 +975,7 @@ namespace Novell.CASA
IntPtr temp = new IntPtr(idList.secretIDList.ToInt32() + (i * Marshal.SizeOf(secretId))); IntPtr temp = new IntPtr(idList.secretIDList.ToInt32() + (i * Marshal.SizeOf(secretId)));
secretId = (SSCS_SH_SECRET_ID_T)Marshal.PtrToStructure(temp, typeof(SSCS_SH_SECRET_ID_T)); secretId = (SSCS_SH_SECRET_ID_T)Marshal.PtrToStructure(temp, typeof(SSCS_SH_SECRET_ID_T));
// String st = new String(secretId.name,0,secretId.len - 1); // String st = new String(secretId.name,0,secretId.len - 1);
String st = secretId.name; String st = secretId.name;
sc.Add(st); sc.Add(st);
} }
@ -969,6 +991,10 @@ namespace Novell.CASA
uint ssFlags, uint ssFlags,
string sKeyChainID) string sKeyChainID)
{ {
if (context==IntPtr.Zero || sKeyChainID==null || sKeyChainID.Length==0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T(); SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T();
keyChainID.keychainID = sKeyChainID; keyChainID.keychainID = sKeyChainID;
keyChainID.len = sKeyChainID.Length + 1; keyChainID.len = sKeyChainID.Length + 1;
@ -985,6 +1011,9 @@ namespace Novell.CASA
uint unFlag) uint unFlag)
{ {
if (sAppSecretID==null || sAppSecretID.Length == 0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
int rcode; int rcode;
BasicCredential bc = null; BasicCredential bc = null;
@ -1044,6 +1073,11 @@ namespace Novell.CASA
string sUsername, string sUsername,
string sPassword) string sPassword)
{ {
if (sAppSecretID==null || sUsername==null || sPassword==null
|| sAppSecretID.Length==0 || sUsername.Length==0 || sPassword.Length==0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
int rcode; int rcode;
SSCS_SECRET_ID_T appSecretID = new SSCS_SECRET_ID_T(); SSCS_SECRET_ID_T appSecretID = new SSCS_SECRET_ID_T();
@ -1061,7 +1095,7 @@ namespace Novell.CASA
credential.unFlags = unFlag; credential.unFlags = unFlag;
credential.unLen = GetUTF8ByteCount(sUsername); credential.unLen = GetUTF8ByteCount(sUsername);
credential.username = GetUTF8FromString(sUsername, USERNAME_LEN); credential.username = GetUTF8FromString(sUsername, USERNAME_LEN);
credential.pwordLen = GetUTF8ByteCount(sPassword); credential.pwordLen = GetUTF8ByteCount(sPassword);
credential.password = GetUTF8FromString(sPassword, PASSWORD_LEN); credential.password = GetUTF8FromString(sPassword, PASSWORD_LEN);
@ -1092,6 +1126,9 @@ namespace Novell.CASA
string sSharedSecretID) string sSharedSecretID)
{ {
if (sAppSecretID == null || sAppSecretID.Length==0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
int rcode; int rcode;
SSCS_SECRET_ID_T appSecretID = new SSCS_SECRET_ID_T(); SSCS_SECRET_ID_T appSecretID = new SSCS_SECRET_ID_T();
appSecretID.id = sAppSecretID; appSecretID.id = sAppSecretID;
@ -1113,89 +1150,101 @@ namespace Novell.CASA
} }
public static int SetMasterPasscode( internal static int SetMasterPasscode(
uint ssFlags, uint ssFlags,
string passcodeStr) string passcodeStr)
{ {
int rcode = -1;
try
{
SSCS_PASSCODE_T passcode = new SSCS_PASSCODE_T();
SSCS_PASSWORD_T passwd = new SSCS_PASSWORD_T();
passwd.pwordType = 1; if (passcodeStr==null || passcodeStr.Length==0)
/* UTF8 ?? throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
passwd.pword = GetUTF8FromString(passcodeStr,PASSWORD_LEN);
passwd.pwordLen = GetUTF8ByteCount(passcodeStr); int rcode = -1;
*/ try
passwd.pword = passcodeStr; {
passwd.pwordLen = (uint)passcodeStr.Length; SSCS_PASSCODE_T passcode = new SSCS_PASSCODE_T();
SSCS_PASSWORD_T passwd = new SSCS_PASSWORD_T();
passwd.pwordType = 1;
/* UTF8 ??
passwd.pword = GetUTF8FromString(passcodeStr,PASSWORD_LEN);
passwd.pwordLen = GetUTF8ByteCount(passcodeStr);
*/
passwd.pword = passcodeStr;
passwd.pwordLen = (uint)passcodeStr.Length;
passcode.passcodeType = 1; passcode.passcodeType = 1;
IntPtr temp = Marshal.AllocHGlobal(Marshal.SizeOf(passwd)); IntPtr temp = Marshal.AllocHGlobal(Marshal.SizeOf(passwd));
Marshal.StructureToPtr(passwd, temp, false); Marshal.StructureToPtr(passwd, temp, false);
passcode.passcodeHandle = temp; passcode.passcodeHandle = temp;
rcode = miCASASetMasterPasscode(ssFlags, rcode = miCASASetMasterPasscode(ssFlags,
passcode, passcode,
new SSCS_EXT_T()); new SSCS_EXT_T());
} }
catch(Exception e) catch(Exception e)
{ {
//Console.WriteLine(e.ToString()); //Console.WriteLine(e.ToString());
} }
return rcode; return rcode;
} }
public static int SetMasterPassword( public static int SetMasterPassword(
uint ssFlags, uint ssFlags,
string mPasswd) string mPasswd)
{ {
int rcode = -1;
try
{
SSCS_PASSWORD_T passwd = new SSCS_PASSWORD_T();
passwd.pwordType = 1; if (mPasswd==null || mPasswd.Length==0)
passwd.pword = mPasswd; return 1;
passwd.pwordLen = (uint)mPasswd.Length;
int rcode = -1;
try
{
SSCS_PASSWORD_T passwd = new SSCS_PASSWORD_T();
passwd.pwordType = 1;
passwd.pword = mPasswd;
passwd.pwordLen = (uint)mPasswd.Length;
rcode = miCASASetMasterPassword(ssFlags, rcode = miCASASetMasterPassword(ssFlags,
passwd, passwd,
null, null,
new SSCS_EXT_T()); new SSCS_EXT_T());
} }
catch(Exception e) catch(Exception)
{ {
//Console.WriteLine(e.ToString()); //Console.WriteLine(e.ToString());
} }
return rcode; return rcode;
} }
public static bool IsSecretPersistent(uint ssFlags, string id) public static bool IsSecretPersistent(uint ssFlags, string id)
{ {
int rcode; int rcode = 0;
SSCS_SECRET_ID_T secretID = new SSCS_SECRET_ID_T(); if (null != id && "" !=id)
if(ssFlags == 0) {
{ SSCS_SECRET_ID_T secretID = new SSCS_SECRET_ID_T();
secretID.len = id.Length; if(ssFlags == 0)
secretID.id = id; {
rcode = miCASAIsSecretPersistent(ssFlags, secretID.len = id.Length;
secretID, secretID.id = id;
new SSCS_EXT_T()); rcode = miCASAIsSecretPersistent(ssFlags,
} secretID,
else new SSCS_EXT_T());
{ }
rcode = miCASAIsSecretPersistent(ssFlags, else
null, {
new SSCS_EXT_T()); rcode = miCASAIsSecretPersistent(ssFlags,
} null,
if(rcode == 1) new SSCS_EXT_T());
return true; }
else }
return false;
} if(rcode == 1)
return true;
else
return false;
}
private static string GetStringFromUTF8(byte[] utf8Bytes, int numBytes) private static string GetStringFromUTF8(byte[] utf8Bytes, int numBytes)
@ -1231,39 +1280,46 @@ namespace Novell.CASA
} }
internal int RemoveKey( internal int RemoveKey(
string sKeyChainID, string sKeyChainID,
string secretID, string secretID,
string keyID) string keyID)
{ {
if (sKeyChainID==null || secretID==null || keyID==null
|| sKeyChainID.Length==0 || secretID.Length==0 || keyID.Length==0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
int rcode = 0; int rcode = 0;
if (keyID.Length > 0) if (keyID.Length > 0)
{ {
try try
{ {
object o = MiCasaRequestReply.Send( object o = MiCasaRequestReply.Send(
MiCasaRequestReply.VERB_REMOVE_KEY, MiCasaRequestReply.VERB_REMOVE_KEY,
sKeyChainID, secretID, keyID, null); sKeyChainID, secretID, keyID, null);
} }
catch (Exception e) catch (Exception e)
{ {
rcode = -803; rcode = -803;
} }
} }
return rcode; return rcode;
} }
internal ArrayList GetKeyList( internal ArrayList GetKeyList(
string sKeyChainID, string sKeyChainID,
string secretID) string secretID)
{ {
ArrayList keyList = null; if (sKeyChainID==null || secretID==null
try || sKeyChainID.Length==0 || secretID.Length==0)
{ throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
keyList = (ArrayList) MiCasaRequestReply.Send(
MiCasaRequestReply.VERB_GET_KEY_LIST, ArrayList keyList = null;
sKeyChainID, secretID,null,null); try
return keyList; {
keyList = (ArrayList) MiCasaRequestReply.Send(
MiCasaRequestReply.VERB_GET_KEY_LIST,
sKeyChainID, secretID,null,null);
return keyList;
#if false #if false
if( null != keyList ) if( null != keyList )
@ -1276,44 +1332,50 @@ namespace Novell.CASA
} }
#endif #endif
} }
catch(Exception e) catch(Exception e)
{ {
Console.WriteLine(e.ToString()); Console.WriteLine(e.ToString());
keyList = null; keyList = null;
} }
return keyList; return keyList;
} }
internal string ReadKey( internal string ReadKey(
string sKeyChainID, string sKeyChainID,
string secretID, string secretID,
string keyID) string keyID)
{ {
if (sKeyChainID==null || secretID==null || keyID==null
|| sKeyChainID.Length==0 || secretID.Length==0 || keyID.Length==0)
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
int rcode = 0; int rcode = 0;
string value = null; string value = null;
if (keyID.Length > 0) if (keyID.Length > 0)
{ {
try try
{ {
value = (String)MiCasaRequestReply.Send( value = (String)MiCasaRequestReply.Send(
MiCasaRequestReply.VERB_REMOVE_KEY, MiCasaRequestReply.VERB_REMOVE_KEY,
sKeyChainID, secretID, keyID, null); sKeyChainID, secretID, keyID, null);
} }
catch (Exception e) catch (Exception e)
{ {
// rcode = -803; // rcode = -803;
Console.WriteLine(e.ToString()); Console.WriteLine(e.ToString());
} }
} }
return value; return value;
} }
private string EscapeReservedChars(string origString) private string EscapeReservedChars(string origString)
{ {
if (origString==null)
return origString;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i=0; i<origString.Length; i++) for (int i=0; i<origString.Length; i++)
{ {

View File

@ -58,7 +58,6 @@ namespace Novell.CASA
} }
public static BasicCredential GetBasicCredential( public static BasicCredential GetBasicCredential(
string sAppSecretID, string sAppSecretID,
string sSharedSecretID) string sSharedSecretID)
@ -102,26 +101,20 @@ namespace Novell.CASA
{ {
NativeCalls.RemoveCredential(ssFlags, sAppSecretID, sSharedSecretID); NativeCalls.RemoveCredential(ssFlags, sAppSecretID, sSharedSecretID);
} }
/*
internal static int SetMasterPasscode( public static int SetMasterPassword(
uint ssFlags, uint ssFlags,
string passcodeStr) string mPasswd)
{ {
return NativeCalls.SetMasterPasscode(ssFlags,passcodeStr); return NativeCalls.SetMasterPassword(ssFlags,mPasswd);
} }
*/
public static int SetMasterPassword( public static bool IsSecretPersistent(
uint ssFlags, uint ssFlags,
string mPasswd) string secretID)
{ {
return NativeCalls.SetMasterPassword(ssFlags,mPasswd); return NativeCalls.IsSecretPersistent(ssFlags,secretID);
} }
public static bool IsSecretPersistent(
uint ssFlags,
string secretID)
{
return NativeCalls.IsSecretPersistent(ssFlags,secretID);
}
} }
} }

View File

@ -319,6 +319,11 @@ namespace Novell.CASA
return getMessage(m_iException); return getMessage(m_iException);
} }
public int getErrorCode()
{
return m_iException;
}
public string getMessage(int iException) public string getMessage(int iException)
{ {
switch (iException) switch (iException)