CASA/c_sharp/NSSCSWrapper/SecretStore.cs

144 lines
3.5 KiB
C#
Raw Normal View History

using System;
using System.Collections.Specialized;
namespace Novell.CASA
{
/// <summary>
/// Represents the SecretStore
/// </summary>
public class SecretStore : MarshalByRefObject
{
private string m_sMasterPassword = null;
private static string SESSION_KEY_CHAIN = "SSCS_SESSION_KEY_CHAIN_ID";
public static string LOCAL_REMOTE_KEY_CHAIN = "SSCS_LOCAL_REMOTE_KEY_CHAIN_ID";
private NativeCalls m_NativeCalls = null;
private IntPtr m_hsc = IntPtr.Zero;
public SecretStore()
{
doSetup();
}
private void doSetup()
{
m_NativeCalls = new NativeCalls();
m_hsc = m_NativeCalls.openSecretStore("SecretStore");
//Console.WriteLine("Session handle: {0}", m_hsc);
}
public static SecretStore getInstance()
{
2005-11-03 21:24:36 +01:00
SecretStore newSS = new SecretStore();
return newSS;
}
2005-11-03 21:24:36 +01:00
public void ReleaseInstance()
{
if (m_hsc != IntPtr.Zero)
m_NativeCalls.closeSecretStore(m_hsc);
}
/*
public static void ReleaseInstance()
{
// TODO:
}
2005-11-03 21:24:36 +01:00
*/
internal Secret getSecret(string sKeyChainID, uint ssFlags, string sSecretID, int iSecretType, string sEPPassword)
{
if (m_NativeCalls != null)
return m_NativeCalls.getSecret(m_hsc, sKeyChainID, ssFlags, sSecretID, iSecretType, sEPPassword);
else
return null;
}
public Secret getSecret(string id)
{
string sSecretId = id;
int iSecretType = Secret.SS_BINARY;
2005-10-21 02:55:56 +02:00
//Console.WriteLine("GetSecret called for "+id);
if (sSecretId.StartsWith("SS_CredSet"))
{
sSecretId = sSecretId.Substring(11);
iSecretType = Secret.SS_CREDSET;
}
else if (sSecretId.StartsWith("SS_App"))
{
sSecretId = sSecretId.Substring(10);
iSecretType = Secret.SS_APP;
}
return getSecret(0, sSecretId, iSecretType, "");
}
public Secret getSecret(uint ssFlags, string sSecretID, int iSecretType, string sEPPassword)
{
return getSecret(SESSION_KEY_CHAIN, ssFlags, sSecretID, iSecretType, sEPPassword);
}
public void setSecret(uint flags, string sKeyChainID, Secret secret, int iSecretType)
{
m_NativeCalls.setSecret(m_hsc, sKeyChainID, flags, secret, iSecretType);
}
public void setSecret(uint flags, Secret secret, int iSecretType)
{
// call the native calls to write this secret
m_NativeCalls.setSecret(m_hsc, SESSION_KEY_CHAIN, flags, secret, iSecretType);
}
private void setSecret(uint flags, string sSecretID, string sEPPassword)
{
//setSecret(flags, SESSION_KEY_CHAIN, sSecretID, sEPPassword);
}
public void removeSecret(uint ssFlags, string sKeyChainID, string sEPPassword, string sSecretID, int iSecretType)
{
m_NativeCalls.RemoveSecret(m_hsc, ssFlags, sKeyChainID, sEPPassword, sSecretID, iSecretType);
}
public void removeSecret(string sSecretID, int iSecretType)
{
removeSecret(0, SESSION_KEY_CHAIN, "", sSecretID, iSecretType);
}
private void enumerateKeychainIDs(string sSearchSting)
{
if (m_NativeCalls != null)
{
//m_NativeCalls.enumKeychainIDs();
}
}
public void setMasterPassword(string sMasterPassword)
{
m_sMasterPassword = sMasterPassword;
}
public StringCollection enumerateSecretIDs()
{
return enumerateSecretIDs(SESSION_KEY_CHAIN);
}
public StringCollection enumerateSecretIDs(string sKeyChainID)
{
return m_NativeCalls.EnumerateSecretIDs(m_hsc, 0, sKeyChainID, "");
}
public void addKeyChain(string sKeyChainID)
{
m_NativeCalls.AddKeyChain(m_hsc, 0, sKeyChainID);
}
}
}