2006-01-19 00:34:21 +01:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
2006-02-01 18:48:29 +01:00
|
|
|
* Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved.
|
2006-01-19 00:34:21 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; version 2.1
|
|
|
|
* of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2006-01-31 23:01:47 +01:00
|
|
|
* Library Lesser General Public License for more details.
|
2006-01-19 00:34:21 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-01-31 23:01:47 +01:00
|
|
|
* License along with this library; if not, Novell, Inc.
|
2006-01-19 00:34:21 +01:00
|
|
|
*
|
|
|
|
* To contact Novell about this file by physical or electronic mail,
|
|
|
|
* you may find current contact information at www.novell.com.
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
|
|
|
|
2006-01-31 23:01:47 +01:00
|
|
|
|
2005-10-11 21:51:00 +02:00
|
|
|
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();
|
2005-10-11 21:51:00 +02:00
|
|
|
return newSS;
|
|
|
|
}
|
|
|
|
|
2005-11-03 21:24:36 +01:00
|
|
|
public void ReleaseInstance()
|
|
|
|
{
|
|
|
|
if (m_hsc != IntPtr.Zero)
|
|
|
|
m_NativeCalls.closeSecretStore(m_hsc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-10-11 21:51:00 +02:00
|
|
|
public static void ReleaseInstance()
|
|
|
|
{
|
|
|
|
// TODO:
|
|
|
|
|
|
|
|
}
|
2005-11-03 21:24:36 +01:00
|
|
|
*/
|
2005-10-11 21:51:00 +02: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);
|
2005-10-11 21:51:00 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|