Bug 130518. Throw INVALID PARAMETER exception on null and empty strings
This commit is contained in:
parent
4df26f8574
commit
16eff73590
@ -35,17 +35,17 @@ namespace Novell.CASA
|
||||
{
|
||||
public uint pwordType;
|
||||
public uint pwordLen; // * enhanced protection len & pword to set
|
||||
// [MarshalAs(UnmanagedType.LPStr, SizeConst = 128)]
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||
// [MarshalAs(UnmanagedType.LPStr, SizeConst = 128)]
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||
public string pword; // * should be passed in # of chars
|
||||
} ;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public class SSCS_PASSCODE_T
|
||||
{
|
||||
public uint passcodeType;
|
||||
public IntPtr passcodeHandle;
|
||||
}
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public class SSCS_PASSCODE_T
|
||||
{
|
||||
public uint passcodeType;
|
||||
public IntPtr passcodeHandle;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public class SSCS_KEYCHAIN_ID_T
|
||||
@ -80,13 +80,13 @@ namespace Novell.CASA
|
||||
public string id; // * should be passed in # of chars
|
||||
};
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
public class SSCS_HINT_T
|
||||
{
|
||||
ulong hintLen;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||
string hint; //* should be passed in # of chars
|
||||
};
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
public class SSCS_HINT_T
|
||||
{
|
||||
ulong hintLen;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||
string hint; //* should be passed in # of chars
|
||||
};
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public class SSCS_EXT_T
|
||||
@ -166,19 +166,19 @@ namespace Novell.CASA
|
||||
public string hint; //[NSSS_MAX_MP_PWORD_HINT_LEN]];
|
||||
};
|
||||
|
||||
/*
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public class SSCS_BASIC_CREDENTIAL
|
||||
{
|
||||
public uint unFlags;
|
||||
public uint unLen;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
||||
public string username;
|
||||
public uint pwordLen;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||
public string password;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public class SSCS_BASIC_CREDENTIAL
|
||||
{
|
||||
public uint unFlags;
|
||||
public uint unLen;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
||||
public string username;
|
||||
public uint pwordLen;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||
public string password;
|
||||
}
|
||||
*/
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public class SSCS_BASIC_CREDENTIAL_UTF8
|
||||
{
|
||||
@ -232,21 +232,21 @@ namespace Novell.CASA
|
||||
[In] IntPtr credential,
|
||||
[In, Out] SSCS_EXT_T ext
|
||||
);
|
||||
[DllImport(NDK_LIBRARY)]
|
||||
public static extern int miCASASetMasterPasscode
|
||||
(
|
||||
[In] uint ssFlags,
|
||||
[In] SSCS_PASSCODE_T passcode,
|
||||
[In] SSCS_EXT_T ext
|
||||
);
|
||||
[DllImport(NDK_LIBRARY)]
|
||||
public static extern int miCASASetMasterPasscode
|
||||
(
|
||||
[In] uint ssFlags,
|
||||
[In] SSCS_PASSCODE_T passcode,
|
||||
[In] SSCS_EXT_T ext
|
||||
);
|
||||
|
||||
[DllImport(NDK_LIBRARY)]
|
||||
public static extern int miCASAIsSecretPersistent
|
||||
(
|
||||
[In] uint ssFlags,
|
||||
[In] SSCS_SECRET_ID_T secretID,
|
||||
[In, Out] SSCS_EXT_T ext
|
||||
);
|
||||
(
|
||||
[In] uint ssFlags,
|
||||
[In] SSCS_SECRET_ID_T secretID,
|
||||
[In, Out] SSCS_EXT_T ext
|
||||
);
|
||||
|
||||
[DllImport(NDK_LIBRARY)]
|
||||
public static extern IntPtr miCASAOpenSecretStoreCache
|
||||
@ -345,12 +345,12 @@ namespace Novell.CASA
|
||||
|
||||
[DllImport(NDK_LIBRARY)]
|
||||
public static extern int miCASASetMasterPassword
|
||||
(
|
||||
[In] uint ssFlags,
|
||||
[In] SSCS_PASSWORD_T password,
|
||||
[In] SSCS_HINT_T hint,
|
||||
[In, Out] SSCS_EXT_T ext
|
||||
);
|
||||
(
|
||||
[In] uint ssFlags,
|
||||
[In] SSCS_PASSWORD_T password,
|
||||
[In] SSCS_HINT_T hint,
|
||||
[In, Out] SSCS_EXT_T ext
|
||||
);
|
||||
|
||||
[DllImport(NDK_LIBRARY)]
|
||||
public static extern int miCASAUnlockSecrets
|
||||
@ -440,10 +440,10 @@ namespace Novell.CASA
|
||||
[In] SSCS_KEYCHAIN_ID_T keyChainID,
|
||||
[In] SSCS_SH_SECRET_ID_T sharedSecretID,
|
||||
[MarshalAs(UnmanagedType.LPStr)]
|
||||
string key, //* in /wchar
|
||||
string key, //* in /wchar
|
||||
[In] uint keyLenBytes, // in bytes
|
||||
[MarshalAs(UnmanagedType.LPStr)]
|
||||
string val, //* in /uchar
|
||||
string val, //* in /uchar
|
||||
[In] uint valueLenBytes, // in bytes
|
||||
[In] SSCS_PASSWORD_T password,
|
||||
[In, Out] SSCS_EXT_T ext
|
||||
@ -465,6 +465,12 @@ namespace Novell.CASA
|
||||
// Methods start here
|
||||
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();
|
||||
SSid.id = sSecretStoreName;
|
||||
SSid.len = sSecretStoreName.Length;
|
||||
@ -487,9 +493,13 @@ namespace Novell.CASA
|
||||
uint iFlags,
|
||||
string sSharedSecretID,
|
||||
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
|
||||
SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T();
|
||||
keyChainID.keychainID = sKeyChainID;
|
||||
@ -610,119 +620,119 @@ namespace Novell.CASA
|
||||
return rcode;
|
||||
}
|
||||
|
||||
/*
|
||||
internal int setSecret(
|
||||
IntPtr pHsc,
|
||||
string sKeyChainID,
|
||||
uint iFlags,
|
||||
Secret secret,
|
||||
int iSecretType)
|
||||
{
|
||||
int rcode;
|
||||
/*
|
||||
internal int setSecret(
|
||||
IntPtr pHsc,
|
||||
string sKeyChainID,
|
||||
uint iFlags,
|
||||
Secret secret,
|
||||
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++)
|
||||
if (iSecretType == Secret.SS_BINARY)
|
||||
{
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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++)
|
||||
{
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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");
|
||||
return false;
|
||||
}
|
||||
//Console.WriteLine("key = " + key + " is not present in nvc");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
internal int setSecret(
|
||||
@ -734,6 +744,8 @@ namespace Novell.CASA
|
||||
{
|
||||
|
||||
int rcode = 0;
|
||||
if (sKeyChainID == null || sKeyChainID.Length == 0)
|
||||
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
|
||||
|
||||
// now call miCASAWriteSecret
|
||||
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++)
|
||||
{
|
||||
|
||||
rcode = 0;
|
||||
rcode = 0;
|
||||
String sKey = nvc.GetKey(i);
|
||||
String sValue = nvc.Get(sKey); // = new StringBuilder();
|
||||
|
||||
@ -819,33 +831,33 @@ namespace Novell.CASA
|
||||
}
|
||||
}
|
||||
|
||||
if( 0 == rcode )
|
||||
{
|
||||
try
|
||||
{
|
||||
if( 0 == rcode )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
IEnumerator etor = keyList.GetEnumerator();
|
||||
while( etor.MoveNext() )
|
||||
{
|
||||
string key = (string)etor.Current;
|
||||
if(KeyInNewList(nvc,key) == false)
|
||||
{
|
||||
MiCasaRequestReply.Send(MiCasaRequestReply.VERB_REMOVE_KEY,sKeyChainID,secret.getID(),key, null );
|
||||
}
|
||||
if( null != keyList )
|
||||
{
|
||||
IEnumerator etor = keyList.GetEnumerator();
|
||||
while( etor.MoveNext() )
|
||||
{
|
||||
string key = (string)etor.Current;
|
||||
if(KeyInNewList(nvc,key) == false)
|
||||
{
|
||||
MiCasaRequestReply.Send(MiCasaRequestReply.VERB_REMOVE_KEY,sKeyChainID,secret.getID(),key, null );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
rcode = -803;
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
rcode = -803;
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -862,6 +874,11 @@ namespace Novell.CASA
|
||||
string sSecretID,
|
||||
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;
|
||||
|
||||
SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T();
|
||||
@ -874,7 +891,7 @@ namespace Novell.CASA
|
||||
epPassword.pwordType = 0; // todo set type
|
||||
|
||||
SSCS_SH_SECRET_ID_T secretID = new SSCS_SH_SECRET_ID_T();
|
||||
secretID.name = sSecretID;
|
||||
secretID.name = sSecretID;
|
||||
|
||||
secretID.len = sSecretID.Length + 1;
|
||||
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
|
||||
SSCS_KEYCHAIN_ID_T keyChainID = new SSCS_KEYCHAIN_ID_T();
|
||||
keyChainID.keychainID = sKeyChainID;
|
||||
@ -923,7 +945,7 @@ namespace Novell.CASA
|
||||
idList.returnedIDs = (uint)numIDS;
|
||||
|
||||
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 );
|
||||
buffer3.Append( (char)0 );
|
||||
@ -953,7 +975,7 @@ namespace Novell.CASA
|
||||
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));
|
||||
|
||||
// String st = new String(secretId.name,0,secretId.len - 1);
|
||||
// String st = new String(secretId.name,0,secretId.len - 1);
|
||||
String st = secretId.name;
|
||||
sc.Add(st);
|
||||
}
|
||||
@ -969,6 +991,10 @@ namespace Novell.CASA
|
||||
uint ssFlags,
|
||||
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();
|
||||
keyChainID.keychainID = sKeyChainID;
|
||||
keyChainID.len = sKeyChainID.Length + 1;
|
||||
@ -985,6 +1011,9 @@ namespace Novell.CASA
|
||||
uint unFlag)
|
||||
|
||||
{
|
||||
if (sAppSecretID==null || sAppSecretID.Length == 0)
|
||||
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
|
||||
|
||||
int rcode;
|
||||
BasicCredential bc = null;
|
||||
|
||||
@ -1044,8 +1073,13 @@ namespace Novell.CASA
|
||||
string sUsername,
|
||||
string sPassword)
|
||||
{
|
||||
int rcode;
|
||||
|
||||
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;
|
||||
|
||||
SSCS_SECRET_ID_T appSecretID = new SSCS_SECRET_ID_T();
|
||||
appSecretID.id = sAppSecretID;
|
||||
appSecretID.len = sAppSecretID.Length;
|
||||
@ -1061,7 +1095,7 @@ namespace Novell.CASA
|
||||
credential.unFlags = unFlag;
|
||||
|
||||
credential.unLen = GetUTF8ByteCount(sUsername);
|
||||
credential.username = GetUTF8FromString(sUsername, USERNAME_LEN);
|
||||
credential.username = GetUTF8FromString(sUsername, USERNAME_LEN);
|
||||
|
||||
credential.pwordLen = GetUTF8ByteCount(sPassword);
|
||||
credential.password = GetUTF8FromString(sPassword, PASSWORD_LEN);
|
||||
@ -1092,6 +1126,9 @@ namespace Novell.CASA
|
||||
string sSharedSecretID)
|
||||
|
||||
{
|
||||
if (sAppSecretID == null || sAppSecretID.Length==0)
|
||||
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
|
||||
|
||||
int rcode;
|
||||
SSCS_SECRET_ID_T appSecretID = new SSCS_SECRET_ID_T();
|
||||
appSecretID.id = sAppSecretID;
|
||||
@ -1113,89 +1150,101 @@ namespace Novell.CASA
|
||||
|
||||
}
|
||||
|
||||
public static int SetMasterPasscode(
|
||||
internal static int SetMasterPasscode(
|
||||
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;
|
||||
/* UTF8 ??
|
||||
passwd.pword = GetUTF8FromString(passcodeStr,PASSWORD_LEN);
|
||||
passwd.pwordLen = GetUTF8ByteCount(passcodeStr);
|
||||
*/
|
||||
passwd.pword = passcodeStr;
|
||||
passwd.pwordLen = (uint)passcodeStr.Length;
|
||||
if (passcodeStr==null || passcodeStr.Length==0)
|
||||
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
|
||||
|
||||
int rcode = -1;
|
||||
try
|
||||
{
|
||||
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;
|
||||
IntPtr temp = Marshal.AllocHGlobal(Marshal.SizeOf(passwd));
|
||||
Marshal.StructureToPtr(passwd, temp, false);
|
||||
passcode.passcodeHandle = temp;
|
||||
passcode.passcodeType = 1;
|
||||
IntPtr temp = Marshal.AllocHGlobal(Marshal.SizeOf(passwd));
|
||||
Marshal.StructureToPtr(passwd, temp, false);
|
||||
passcode.passcodeHandle = temp;
|
||||
|
||||
rcode = miCASASetMasterPasscode(ssFlags,
|
||||
passcode,
|
||||
new SSCS_EXT_T());
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
//Console.WriteLine(e.ToString());
|
||||
}
|
||||
return rcode;
|
||||
}
|
||||
rcode = miCASASetMasterPasscode(ssFlags,
|
||||
passcode,
|
||||
new SSCS_EXT_T());
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
//Console.WriteLine(e.ToString());
|
||||
}
|
||||
return rcode;
|
||||
}
|
||||
public static int SetMasterPassword(
|
||||
uint ssFlags,
|
||||
string mPasswd)
|
||||
string mPasswd)
|
||||
{
|
||||
int rcode = -1;
|
||||
try
|
||||
{
|
||||
SSCS_PASSWORD_T passwd = new SSCS_PASSWORD_T();
|
||||
|
||||
passwd.pwordType = 1;
|
||||
passwd.pword = mPasswd;
|
||||
passwd.pwordLen = (uint)mPasswd.Length;
|
||||
if (mPasswd==null || mPasswd.Length==0)
|
||||
return 1;
|
||||
|
||||
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,
|
||||
passwd,
|
||||
null,
|
||||
new SSCS_EXT_T());
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
//Console.WriteLine(e.ToString());
|
||||
}
|
||||
return rcode;
|
||||
}
|
||||
rcode = miCASASetMasterPassword(ssFlags,
|
||||
passwd,
|
||||
null,
|
||||
new SSCS_EXT_T());
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
//Console.WriteLine(e.ToString());
|
||||
}
|
||||
return rcode;
|
||||
}
|
||||
|
||||
public static bool IsSecretPersistent(uint ssFlags, string id)
|
||||
{
|
||||
int rcode;
|
||||
SSCS_SECRET_ID_T secretID = new SSCS_SECRET_ID_T();
|
||||
if(ssFlags == 0)
|
||||
{
|
||||
secretID.len = id.Length;
|
||||
secretID.id = id;
|
||||
rcode = miCASAIsSecretPersistent(ssFlags,
|
||||
secretID,
|
||||
new SSCS_EXT_T());
|
||||
}
|
||||
else
|
||||
{
|
||||
rcode = miCASAIsSecretPersistent(ssFlags,
|
||||
null,
|
||||
new SSCS_EXT_T());
|
||||
}
|
||||
if(rcode == 1)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
public static bool IsSecretPersistent(uint ssFlags, string id)
|
||||
{
|
||||
int rcode = 0;
|
||||
if (null != id && "" !=id)
|
||||
{
|
||||
SSCS_SECRET_ID_T secretID = new SSCS_SECRET_ID_T();
|
||||
if(ssFlags == 0)
|
||||
{
|
||||
secretID.len = id.Length;
|
||||
secretID.id = id;
|
||||
rcode = miCASAIsSecretPersistent(ssFlags,
|
||||
secretID,
|
||||
new SSCS_EXT_T());
|
||||
}
|
||||
else
|
||||
{
|
||||
rcode = miCASAIsSecretPersistent(ssFlags,
|
||||
null,
|
||||
new SSCS_EXT_T());
|
||||
}
|
||||
}
|
||||
|
||||
if(rcode == 1)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static string GetStringFromUTF8(byte[] utf8Bytes, int numBytes)
|
||||
@ -1231,39 +1280,46 @@ namespace Novell.CASA
|
||||
}
|
||||
internal int RemoveKey(
|
||||
string sKeyChainID,
|
||||
string secretID,
|
||||
string keyID)
|
||||
{
|
||||
string secretID,
|
||||
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;
|
||||
|
||||
if (keyID.Length > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
object o = MiCasaRequestReply.Send(
|
||||
MiCasaRequestReply.VERB_REMOVE_KEY,
|
||||
sKeyChainID, secretID, keyID, null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rcode = -803;
|
||||
}
|
||||
try
|
||||
{
|
||||
object o = MiCasaRequestReply.Send(
|
||||
MiCasaRequestReply.VERB_REMOVE_KEY,
|
||||
sKeyChainID, secretID, keyID, null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rcode = -803;
|
||||
}
|
||||
}
|
||||
return rcode;
|
||||
}
|
||||
return rcode;
|
||||
}
|
||||
|
||||
internal ArrayList GetKeyList(
|
||||
string sKeyChainID,
|
||||
string secretID)
|
||||
{
|
||||
ArrayList keyList = null;
|
||||
try
|
||||
{
|
||||
keyList = (ArrayList) MiCasaRequestReply.Send(
|
||||
MiCasaRequestReply.VERB_GET_KEY_LIST,
|
||||
sKeyChainID, secretID,null,null);
|
||||
return keyList;
|
||||
internal ArrayList GetKeyList(
|
||||
string sKeyChainID,
|
||||
string secretID)
|
||||
{
|
||||
if (sKeyChainID==null || secretID==null
|
||||
|| sKeyChainID.Length==0 || secretID.Length==0)
|
||||
throw new miCasaException(miCasaException.NSSCS_E_INVALID_PARAM);
|
||||
|
||||
ArrayList keyList = null;
|
||||
try
|
||||
{
|
||||
keyList = (ArrayList) MiCasaRequestReply.Send(
|
||||
MiCasaRequestReply.VERB_GET_KEY_LIST,
|
||||
sKeyChainID, secretID,null,null);
|
||||
return keyList;
|
||||
#if false
|
||||
|
||||
if( null != keyList )
|
||||
@ -1276,44 +1332,50 @@ namespace Novell.CASA
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
keyList = null;
|
||||
}
|
||||
return keyList;
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
keyList = null;
|
||||
}
|
||||
return keyList;
|
||||
}
|
||||
|
||||
|
||||
internal string ReadKey(
|
||||
string sKeyChainID,
|
||||
string secretID,
|
||||
string keyID)
|
||||
string secretID,
|
||||
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;
|
||||
string value = null;
|
||||
string value = null;
|
||||
|
||||
if (keyID.Length > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
value = (String)MiCasaRequestReply.Send(
|
||||
MiCasaRequestReply.VERB_REMOVE_KEY,
|
||||
sKeyChainID, secretID, keyID, null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// rcode = -803;
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
try
|
||||
{
|
||||
value = (String)MiCasaRequestReply.Send(
|
||||
MiCasaRequestReply.VERB_REMOVE_KEY,
|
||||
sKeyChainID, secretID, keyID, null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// rcode = -803;
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private string EscapeReservedChars(string origString)
|
||||
{
|
||||
if (origString==null)
|
||||
return origString;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i=0; i<origString.Length; i++)
|
||||
{
|
||||
|
@ -58,7 +58,6 @@ namespace Novell.CASA
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static BasicCredential GetBasicCredential(
|
||||
string sAppSecretID,
|
||||
string sSharedSecretID)
|
||||
@ -102,26 +101,20 @@ namespace Novell.CASA
|
||||
{
|
||||
NativeCalls.RemoveCredential(ssFlags, sAppSecretID, sSharedSecretID);
|
||||
}
|
||||
/*
|
||||
internal static int SetMasterPasscode(
|
||||
uint ssFlags,
|
||||
string passcodeStr)
|
||||
{
|
||||
return NativeCalls.SetMasterPasscode(ssFlags,passcodeStr);
|
||||
}
|
||||
*/
|
||||
public static int SetMasterPassword(
|
||||
uint ssFlags,
|
||||
string mPasswd)
|
||||
{
|
||||
return NativeCalls.SetMasterPassword(ssFlags,mPasswd);
|
||||
}
|
||||
public static bool IsSecretPersistent(
|
||||
uint ssFlags,
|
||||
string secretID)
|
||||
{
|
||||
return NativeCalls.IsSecretPersistent(ssFlags,secretID);
|
||||
}
|
||||
|
||||
public static int SetMasterPassword(
|
||||
uint ssFlags,
|
||||
string mPasswd)
|
||||
{
|
||||
return NativeCalls.SetMasterPassword(ssFlags,mPasswd);
|
||||
}
|
||||
|
||||
public static bool IsSecretPersistent(
|
||||
uint ssFlags,
|
||||
string secretID)
|
||||
{
|
||||
return NativeCalls.IsSecretPersistent(ssFlags,secretID);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -319,6 +319,11 @@ namespace Novell.CASA
|
||||
return getMessage(m_iException);
|
||||
}
|
||||
|
||||
public int getErrorCode()
|
||||
{
|
||||
return m_iException;
|
||||
}
|
||||
|
||||
public string getMessage(int iException)
|
||||
{
|
||||
switch (iException)
|
||||
|
Loading…
Reference in New Issue
Block a user