- Distribution of Firefox Password Manager secrets.
This commit is contained in:
parent
66b98cc0d0
commit
1cd3c566a7
@ -1,3 +1,8 @@
|
||||
-------------------------------------------------------------------
|
||||
Fri Sep 29 17:10:23 IST 2006 - smanojna@novell.com
|
||||
|
||||
- Distribution of Firefox Password Manager secrets.
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Wed Sep 27 15:10:47 MDT 2006 - jnorman@novell.com
|
||||
|
||||
|
@ -326,6 +326,15 @@ namespace Novell.CASA.DataEngines
|
||||
}
|
||||
|
||||
|
||||
public static String GetDefaultProfileName(int StoreID)
|
||||
{
|
||||
if (StoreID == ConstStrings.CASA_STORE_FFOX)
|
||||
return FFEngine.GetDefaultProfileName();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
Remove will delete a Secret.
|
||||
|
||||
|
@ -74,6 +74,11 @@ namespace Novell.CASA.DataEngines
|
||||
FireFox.UninitProfile(defaultProfileName);
|
||||
}
|
||||
|
||||
public static String GetDefaultProfileName()
|
||||
{
|
||||
return FireFox.GetDefaultProfileName();
|
||||
}
|
||||
|
||||
public XmlNode Aggregate()
|
||||
{
|
||||
|
||||
@ -145,7 +150,7 @@ namespace Novell.CASA.DataEngines
|
||||
}catch(Exception e)
|
||||
{
|
||||
Console.WriteLine("Unable to Marshal the SecretName" + e.ToString());
|
||||
}
|
||||
}
|
||||
XmlNodeList keylist = secret.SelectNodes("descendant::Key");
|
||||
try
|
||||
{
|
||||
@ -165,11 +170,14 @@ namespace Novell.CASA.DataEngines
|
||||
nh.isPassword = Convert.ToInt32(passwordstatus);
|
||||
nh.next = next;
|
||||
next = Marshal.AllocHGlobal(Marshal.SizeOf(nh));
|
||||
Marshal.StructureToPtr(nh,next,false);
|
||||
Marshal.StructureToPtr(nh,next,false);
|
||||
}
|
||||
newHost.hostElement = next;
|
||||
|
||||
retVal = FireFox.Modify_Host(ProfileName,newHost,1);
|
||||
if (opnType == ConstStrings.OPERATION_ADD_SECRET)
|
||||
retVal = FireFox.Add_Host(ProfileName,newHost,1);
|
||||
else
|
||||
retVal = FireFox.Modify_Host(ProfileName,newHost,1);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
@ -265,10 +273,10 @@ namespace Novell.CASA.DataEngines
|
||||
XmlElement xmlProfileElement;
|
||||
|
||||
String hostName;
|
||||
String name;
|
||||
String value;
|
||||
String name;
|
||||
String value;
|
||||
int isPassword;
|
||||
|
||||
|
||||
methodStatusCode=1;
|
||||
xmlProfileElement = doc.CreateElement(ConstStrings.CCF_FFPROFILE); //<Profile>
|
||||
XmlAttribute idAttr = doc.CreateAttribute(ConstStrings.CCF_ID); //<Profile>-ID
|
||||
@ -357,7 +365,7 @@ namespace Novell.CASA.DataEngines
|
||||
|
||||
}//~Aggregate profileName
|
||||
|
||||
return methodStatusCode;
|
||||
return methodStatusCode;
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,10 +30,10 @@ namespace Novell.CASA.DataEngines.FF
|
||||
{
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public class Host
|
||||
{
|
||||
public IntPtr hostName;
|
||||
public IntPtr hostElement;
|
||||
public class Host
|
||||
{
|
||||
public IntPtr hostName;
|
||||
public IntPtr hostElement;
|
||||
public IntPtr next;
|
||||
/*public Host()
|
||||
//NOT NEEDED SINCE WE GET THIS FILLED FROM NATIVE WHEN
|
||||
@ -52,15 +52,15 @@ namespace Novell.CASA.DataEngines.FF
|
||||
Console.WriteLine("FireFox:Marshal FreeHGlobal Exception for Host:");
|
||||
}
|
||||
}*/
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public class HostElement
|
||||
{
|
||||
public IntPtr name;
|
||||
public IntPtr value;
|
||||
public int isPassword;
|
||||
public class HostElement
|
||||
{
|
||||
public IntPtr name;
|
||||
public IntPtr value;
|
||||
public int isPassword;
|
||||
public IntPtr next;
|
||||
/*public HostElement()
|
||||
{
|
||||
@ -174,6 +174,8 @@ namespace Novell.CASA.DataEngines.FF
|
||||
//Signon functions
|
||||
[DllImport(FF_LIB)]
|
||||
public static extern int FPM_GetSignonData(string profileName,out IntPtr host,int doRefresh);
|
||||
[DllImport(FF_LIB)]
|
||||
public static extern int FPM_AddHost(string profileName, Host host, int doUpdate);
|
||||
|
||||
[DllImport(FF_LIB)]
|
||||
public static extern int FPM_ModifyHost(string profileName, Host host, int doUpdate);
|
||||
@ -183,7 +185,6 @@ namespace Novell.CASA.DataEngines.FF
|
||||
|
||||
//TBD
|
||||
//int FPM_WriteSignonData(char *profileName)
|
||||
//int FPM_AddHost(char *profileName, struct Host *host, int doUpdate)
|
||||
|
||||
public static int IsStoreAvailable()
|
||||
{
|
||||
@ -195,6 +196,11 @@ namespace Novell.CASA.DataEngines.FF
|
||||
return (FPM_RemoveHost(ProfileName, hostName, 1));
|
||||
}
|
||||
|
||||
public static int Add_Host(string profileName, Host ahost, int doUpdate)
|
||||
{
|
||||
return FPM_AddHost(profileName, ahost, 1);
|
||||
}
|
||||
|
||||
public static int Modify_Host(string profileName, Host mhost, int doUpdate)
|
||||
{
|
||||
//Console.WriteLine("FireFox.cs : ProfileName : " + profileName);
|
||||
@ -218,20 +224,20 @@ namespace Novell.CASA.DataEngines.FF
|
||||
int[] profileFlags=null;
|
||||
String profileName=null;
|
||||
int profileFlag=0;
|
||||
int profCount=0;
|
||||
int profCount=0;
|
||||
String defaultProfileName=null;
|
||||
|
||||
|
||||
//Console.WriteLine("FireFox:Invoking FPM_GetProfileList:");
|
||||
profCount=FPM_GetProfileList(out profileListIntPtr,out profileFlagsIntPtr);
|
||||
//Console.WriteLine("FireFox:No of Profiles found= "+profCount);
|
||||
|
||||
//try
|
||||
///{
|
||||
for(int i=0; i< profCount; i++)
|
||||
for(int i=0; i< profCount; i++)
|
||||
{
|
||||
//Console.WriteLine("Firefox.cs : Inside The for Loop");
|
||||
profileName=Marshal.PtrToStringAnsi(profileListIntPtr[i]);
|
||||
profileFlag=(int)profileFlagsIntPtr[i];
|
||||
profileFlag=(int)profileFlagsIntPtr[i];
|
||||
//Console.WriteLine("FireFox:Iter="+i+"profileName="+profileName);
|
||||
//Console.WriteLine("FireFox:Iter="+i+"profileFlag="+profileFlag);
|
||||
if(profileFlag==1)
|
||||
|
@ -20,96 +20,122 @@
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
|
||||
#include "FirefoxPasswordManager.h"
|
||||
#include "Common.h"
|
||||
|
||||
char lastErrorMesg[10000];
|
||||
|
||||
void PrintMessage( int level, char *mesg , ...)
|
||||
{
|
||||
va_list vl;
|
||||
|
||||
va_start( vl , mesg );
|
||||
vsprintf( lastErrorMesg , mesg , vl );
|
||||
va_end( vl );
|
||||
|
||||
// if we are not debugging then print DEBUG level messages
|
||||
#ifdef DEBUG
|
||||
printf("%s", lastErrorMesg );
|
||||
#else
|
||||
|
||||
|
||||
#include "FirefoxPasswordManager.h"
|
||||
#include "Common.h"
|
||||
|
||||
char lastErrorMesg[10000];
|
||||
|
||||
void PrintMessage( int level, char *mesg , ...)
|
||||
{
|
||||
va_list vl;
|
||||
|
||||
va_start( vl , mesg );
|
||||
vsprintf( lastErrorMesg , mesg , vl );
|
||||
va_end( vl );
|
||||
|
||||
// if we are not debugging then print DEBUG level messages
|
||||
#ifdef DEBUG
|
||||
printf("%s", lastErrorMesg );
|
||||
#else
|
||||
if( level != MESG_DEBUG )
|
||||
{
|
||||
//printf("%s", lastErrorMesg );
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts given string to lower case....
|
||||
*
|
||||
*/
|
||||
void StrLwr(char *str)
|
||||
{
|
||||
int n=strlen(str);
|
||||
|
||||
for(int i=0; i<n; i++)
|
||||
{
|
||||
if( str[i] >=65 && str[i]<=90 )
|
||||
str[i]+=32;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if specified directory exists
|
||||
*
|
||||
* return MC_TRUE if directory exists else MC_FALSE
|
||||
*
|
||||
*/
|
||||
int IsDirectoryExists( char *path )
|
||||
{
|
||||
if( path == NULL )
|
||||
return 0;
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
DWORD attr = GetFileAttributes(path);
|
||||
|
||||
if( (attr == -1) || !(attr & FILE_ATTRIBUTE_DIRECTORY ) )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n IsDirectoryExists : Directory does not exist : [%s] ", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
#else
|
||||
|
||||
char *program = (char*) malloc(strlen(path)+20);
|
||||
|
||||
if( program == NULL )
|
||||
return 0;
|
||||
|
||||
strcpy(program, "test -d ");
|
||||
strcat(program, path);
|
||||
|
||||
int result= system(program);
|
||||
free(program);
|
||||
|
||||
if( result != 0 )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n IsDirectoryExists : Directory does not exist : [%s] ", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts given string to lower case....
|
||||
*
|
||||
*/
|
||||
void StrLwr(char *str)
|
||||
{
|
||||
int n=strlen(str);
|
||||
|
||||
for(int i=0; i<n; i++)
|
||||
{
|
||||
if( str[i] >=65 && str[i]<=90 )
|
||||
str[i]+=32;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if specified directory exists
|
||||
*
|
||||
* return MC_TRUE if directory exists else MC_FALSE
|
||||
*
|
||||
*/
|
||||
int IsDirectoryExists( char *path )
|
||||
{
|
||||
if( path == NULL )
|
||||
return 0;
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
DWORD attr = GetFileAttributes(path);
|
||||
|
||||
if( (attr == -1) || !(attr & FILE_ATTRIBUTE_DIRECTORY ) )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n IsDirectoryExists : Directory does not exist : [%s] ", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
#else
|
||||
|
||||
char *program = (char*) malloc(strlen(path)+20);
|
||||
|
||||
if( program == NULL )
|
||||
return 0;
|
||||
|
||||
strcpy(program, "test -d ");
|
||||
strcat(program, path);
|
||||
|
||||
int result= system(program);
|
||||
free(program);
|
||||
|
||||
if( result != 0 )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n IsDirectoryExists : Directory does not exist : [%s] ", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a directory in specified path
|
||||
*
|
||||
* return MC_TRUE if directory successfully created else MC_FALSE
|
||||
*
|
||||
*/
|
||||
int CreateDirectory( char *path )
|
||||
{
|
||||
|
||||
if( path == NULL )
|
||||
return 0;
|
||||
#ifdef WIN32
|
||||
int result = mkdir(path);
|
||||
#else
|
||||
int result = mkdir(path, S_IRWXU);
|
||||
#endif
|
||||
if( result != 0 )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n CreateDirectory : Can't create Directory : [%s] ", path);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
@ -1,458 +1,460 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* 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
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#include "CryptManager.h"
|
||||
|
||||
|
||||
|
||||
void CryptManager::SetupFunctions(void *funList[])
|
||||
{
|
||||
|
||||
//PK11SetPasswordFunc = (PK11_SetPasswordFunc) funList[0];
|
||||
PK11GetInternalKeySlot = (PK11_GetInternalKeySlot) funList[1];
|
||||
PK11FreeSlot = (PK11_FreeSlot) funList[2];
|
||||
PK11Authenticate = (PK11_Authenticate) funList[3];
|
||||
PK11CheckUserPassword =(PK11_CheckUserPassword) funList[4];
|
||||
PK11SDRDecrypt = (PK11SDR_Decrypt) funList[5];
|
||||
PK11SDREncrypt = (PK11SDR_Encrypt) funList[6];
|
||||
PLBase64Encode = (PL_Base64Encode) funList[7];
|
||||
PLBase64Decode = (PL_Base64Decode) funList[8];
|
||||
|
||||
}
|
||||
|
||||
int CryptManager::GetEncryptionPref()
|
||||
{
|
||||
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function encrypts the clear text data. First it performs TRIPLE DES encryption
|
||||
* and then performs base64 encoding on the encrypted data.
|
||||
*
|
||||
* @param(in) clearData clear text data to be encrypted
|
||||
* @param(out) finalData encrypted data ( null terminated)
|
||||
*
|
||||
* @return FPM_TRUE on success and FPM_FALSE on error.
|
||||
*
|
||||
*/
|
||||
int CryptManager::EncryptString (char *clearData, char **finalData)
|
||||
{
|
||||
int encryptDataLen = 0;
|
||||
char *encryptData = NULL;
|
||||
char *encodeData = NULL;
|
||||
int retValue;
|
||||
|
||||
|
||||
if( clearData == NULL )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n EncryptString : Text Data is NULL");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
// Do the encryption if encryption pref is set otherwise just do base64 encoding...
|
||||
if ( GetEncryptionPref() )
|
||||
{
|
||||
PrintMessage(MESG_DEBUG, "\n EncryptString : Performing PK11 Encryption...");
|
||||
|
||||
retValue = FPM_FALSE;
|
||||
if( ((retValue = CryptPK11EncryptString(clearData, strlen(clearData), &encryptData, &encryptDataLen)) != FPM_TRUE) || ( encryptData == NULL) )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n EncryptString : Failed to encrypt the string : %s ", clearData);
|
||||
return retValue;
|
||||
}
|
||||
|
||||
if( (CryptBase64Encode(encryptData, encryptDataLen, finalData) != FPM_TRUE) || (*finalData == NULL) )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n EncryptString : BASE64 encoding failed");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n EncryptString : Success ");
|
||||
|
||||
// WARNING : If you uncomment , then be ready for side effects , crashes..etc
|
||||
// Need full analysis of malloc for this data..
|
||||
// Free the allocated blocks...
|
||||
|
||||
//if( encryptData )
|
||||
// free( encryptData);
|
||||
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
// otherwise do our own obscuring using Base64 encoding
|
||||
PrintMessage(MESG_DEBUG, "\n EncryptString : Performing JUST base64 encoding...");
|
||||
|
||||
if( (CryptBase64Encode(clearData, strlen(clearData), &encodeData) == FPM_FALSE) || (encodeData == NULL) )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n EncryptString : BASE64 encoding failed");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
// We need to add the CRYPT_PREFIX at the begining of encoded data...
|
||||
// This will help during decrption process to identify type of encryption
|
||||
|
||||
int prefixLen = strlen( CRYPT_PREFIX );
|
||||
int encodeLen = strlen( encodeData );
|
||||
*finalData = (char *)malloc( prefixLen + encodeLen + 1);
|
||||
|
||||
if( *finalData == NULL )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n EncryptString : Insufficient memory");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
// FinalData = CRYPT_PREFIX + Encoded Data + '\0'
|
||||
strcpy(*finalData, CRYPT_PREFIX);
|
||||
strcat(*finalData, encodeData);
|
||||
*(*finalData + prefixLen + encodeLen) = 0;
|
||||
|
||||
free(encodeData);
|
||||
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This function decrypts the encrypted data. First it performs base64 decoding and
|
||||
* then performs TRIPLE DES decryption.
|
||||
*
|
||||
* @param(in) cryptData encrypted data
|
||||
* @param(out) clearData clear text data ( null terminated)
|
||||
*
|
||||
* @return FPM_TRUE on success and FPM_FALSE on error.
|
||||
*
|
||||
*/
|
||||
|
||||
int CryptManager::DecryptString(char *cryptData, char **clearData)
|
||||
{
|
||||
int decodeLen = 0;
|
||||
int finalLen = 0;
|
||||
char *decodeData = NULL;
|
||||
char *finalData = NULL;
|
||||
int retValue;
|
||||
|
||||
if( cryptData == NULL )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n DecryptString: CryptData is NULL...");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
// treat zero-length crypt string as a special case
|
||||
if(cryptData[0] == '\0')
|
||||
{
|
||||
*clearData = (char*) malloc(1);
|
||||
**clearData = 0;
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
// use PK11 encryption stuff if crypt doesn't starts with prefix
|
||||
if( cryptData[0] != CRYPT_PREFIX[0] )
|
||||
{
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n Performing PK11 Decryption ");
|
||||
|
||||
// First do base64 decoding.....
|
||||
if( (CryptBase64Decode(cryptData, &decodeData, &decodeLen) != FPM_TRUE) || (decodeData == NULL) )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n DecryptString : Base64 decoding of crypt data failed ");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n DecryptString : base64data (%d) = %s ", decodeLen, decodeData);
|
||||
|
||||
// Now do actual PK11 decryption
|
||||
retValue = FPM_FALSE;
|
||||
retValue = CryptPK11DecryptString(decodeData, decodeLen, &finalData, &finalLen);
|
||||
|
||||
if( retValue != FPM_TRUE )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n DecryptString : Failed to decrypt the string ");
|
||||
return retValue;
|
||||
}
|
||||
|
||||
|
||||
// WARNING : Decrypted string is not NULL terminated
|
||||
// So we will create new NULL terminated string here...
|
||||
|
||||
*clearData = (char*) malloc( finalLen + 1 );
|
||||
|
||||
if( *clearData == NULL )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n DecryptString :Insufficient memory... ");
|
||||
return FPM_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
else
|
||||
{
|
||||
PrintMessage(MESG_DEBUG, "\n DecryptString : Copying new data ....");
|
||||
memcpy(*clearData, finalData, finalLen);
|
||||
*(*clearData + finalLen) = 0; // Null terminate the string....
|
||||
}
|
||||
|
||||
/*
|
||||
// Free the allocated memory
|
||||
// This is causing the problems currently...Later point we have to reanalyze the cause for this
|
||||
|
||||
if( decodeData )
|
||||
free(decodeData);
|
||||
|
||||
if( finalData )
|
||||
free(finalData);
|
||||
*/
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n decryptString : finalLen = %d ", finalLen);
|
||||
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
|
||||
// otherwise do our own de-obscuring
|
||||
PrintMessage(MESG_DEBUG, "\n DecryptString : Performing simple Base64 Decoding ");
|
||||
|
||||
unsigned int PREFIX_Len = strlen(CRYPT_PREFIX);
|
||||
if( strlen(cryptData) == PREFIX_Len )
|
||||
{
|
||||
*clearData = (char *)malloc(1);
|
||||
**clearData = '\0';
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
if( CryptBase64Decode(&cryptData[PREFIX_Len], clearData, &decodeLen) == FPM_FALSE )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n DecryptString : Base64 decoding of crypt data failed ");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Performs base64 encoding of the encrypted data..
|
||||
*
|
||||
* @param(in) cryptData encrypted data
|
||||
* @param(in) cryptDataLen length of encrypted data
|
||||
* @param(out) encodeData base64 encoded data
|
||||
*
|
||||
* @return FPM_TRUE on success and FPM_FALSE on error.
|
||||
*
|
||||
*/
|
||||
|
||||
int CryptManager::CryptBase64Encode(char *cryptData, int cryptDataLen, char **encodeData)
|
||||
{
|
||||
|
||||
*encodeData = (*PLBase64Encode)((const char *)cryptData, cryptDataLen, NULL);
|
||||
|
||||
if ( *encodeData == NULL )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n Base64 encoding failed ...");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Performs base64 decoding of the encrypted data..
|
||||
*
|
||||
* @param(in) cryptData encrypted data
|
||||
* @param(out) decodeData base64 decoded data
|
||||
* @param(out) decodeLen length of base64 decoded data
|
||||
*
|
||||
* @return FPM_TRUE on success and FPM_FALSE on error.
|
||||
*
|
||||
*/
|
||||
int CryptManager::CryptBase64Decode(char *cryptData, char **decodeData, int *decodeLen)
|
||||
{
|
||||
int len = strlen( cryptData );
|
||||
int adjust = 0;
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n CryptBase64Decode : Length of crypt data = %d", len);
|
||||
|
||||
// Compute length adjustment
|
||||
if (cryptData[len-1] == '=')
|
||||
{
|
||||
adjust++;
|
||||
if (cryptData[len-2] == '=')
|
||||
adjust++;
|
||||
}
|
||||
|
||||
*decodeData = ( char *)(*PLBase64Decode)(cryptData, len, NULL);
|
||||
|
||||
if( *decodeData == NULL )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n Base64 decoding failed ...");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
*decodeLen = (len*3)/4 - adjust;
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n CryptBase64Decode : Length of decoded data = %d", *decodeLen);
|
||||
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Performs TRIPLE DES encryption of clear text data
|
||||
*
|
||||
* @param(in) clearData clear text data to be encrypted
|
||||
* @param(in) clearDataLen length of clear text data
|
||||
* @param(out) cryptData TRIPLE DES encrypted data
|
||||
* @param(out) cryptDataLen length of encrypted data
|
||||
*
|
||||
* @return FPM_TRUE on success and FPM_FALSE on error.
|
||||
*
|
||||
*/
|
||||
int CryptManager::CryptPK11EncryptString(char *clearData, int clearDataLen, char **cryptData, int *cryptDataLen)
|
||||
{
|
||||
PK11SlotInfo *slot = 0;
|
||||
SECItem keyid;
|
||||
SECItem request;
|
||||
SECItem reply;
|
||||
SECStatus status;
|
||||
|
||||
slot = (*PK11GetInternalKeySlot)();
|
||||
|
||||
if (!slot)
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n CryptPK11EncryptString : PK11_GetInternalKeySlot failed ...");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
// PK11 authentication
|
||||
if ( (*PK11Authenticate)(slot, PR_TRUE, NULL) != SECSuccess)
|
||||
{
|
||||
// since we have specified password callback function , we won't come here...
|
||||
PrintMessage(MESG_ERROR, "\n CryptPK11EncryptString : PK11_Authenticate failed, possibly master password is wrong");
|
||||
(*PK11FreeSlot) (slot);
|
||||
return FPM_MASTERPASSWORD_WRONG;
|
||||
}
|
||||
|
||||
|
||||
// Use default key id
|
||||
keyid.data = 0;
|
||||
keyid.len = 0;
|
||||
request.data = (unsigned char *)clearData;
|
||||
request.len = clearDataLen;
|
||||
reply.data = 0;
|
||||
reply.len = 0;
|
||||
|
||||
status = (*PK11SDREncrypt)(&keyid, &request, &reply, NULL);
|
||||
|
||||
if (status != SECSuccess)
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n CryptPK11EncryptString : PK11SDR_Encrypt failed ...");
|
||||
(*PK11FreeSlot) (slot);
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
|
||||
*cryptData = (char*)reply.data;
|
||||
*cryptDataLen = reply.len;
|
||||
|
||||
(*PK11FreeSlot) (slot);
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Performs TRIPLE DES decryption of base64 decoded data
|
||||
*
|
||||
* @param(in) decodeData base64 decoded data
|
||||
* @param(in) decodeLen length of base64 decoded data
|
||||
* @param(out) clearData decrypted data
|
||||
* @param(out) finalLen length of decrypted data
|
||||
*
|
||||
* @return FPM_TRUE on success and FPM_FALSE on error.
|
||||
*
|
||||
*/
|
||||
int CryptManager::CryptPK11DecryptString(char *decodeData, int decodeLen, char **clearData, int *finalLen)
|
||||
{
|
||||
PK11SlotInfo *slot = 0;
|
||||
SECStatus status;
|
||||
SECItem request;
|
||||
SECItem reply;
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n CryptPK11DecryptString entered ...");
|
||||
|
||||
// Find token with SDR key
|
||||
slot = (*PK11GetInternalKeySlot)();
|
||||
|
||||
if (!slot)
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n PK11_GetInternalKeySlot failed ...");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n PK11_GetInternalKeySlot SUCCESS ...");
|
||||
|
||||
// Force authentication
|
||||
if ( (*PK11Authenticate)(slot, PR_TRUE, NULL) != SECSuccess)
|
||||
{
|
||||
// since we have specified password callback function , we won't come here...
|
||||
PrintMessage(MESG_ERROR, "\n PK11_Authenticate failed, Probably master password is wrong");
|
||||
(*PK11FreeSlot) (slot);
|
||||
return FPM_MASTERPASSWORD_WRONG;
|
||||
}
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n PK11_Authenticate SUCCESS ...");
|
||||
|
||||
// Decrypt the string
|
||||
request.data = (unsigned char *)decodeData;
|
||||
request.len = decodeLen;
|
||||
reply.data = 0;
|
||||
reply.len = 0;
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n calling PK11SDR_Decrypt ...");
|
||||
|
||||
status = (*PK11SDRDecrypt)(&request, &reply, NULL);
|
||||
|
||||
if (status != SECSuccess)
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n PK11SDR_Decrypt failed ...");
|
||||
(*PK11FreeSlot) (slot);
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n PK11SDR_Decrypt SUCCESS ");
|
||||
|
||||
// WARNING : This string is not NULL terminated..
|
||||
*clearData = (char*)reply.data;
|
||||
*finalLen = reply.len;
|
||||
|
||||
// Free the slot
|
||||
(*PK11FreeSlot) (slot);
|
||||
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* 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
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#include "CryptManager.h"
|
||||
|
||||
|
||||
|
||||
void CryptManager::SetupFunctions(void *funList[])
|
||||
{
|
||||
|
||||
//PK11SetPasswordFunc = (PK11_SetPasswordFunc) funList[0];
|
||||
PK11GetInternalKeySlot = (PK11_GetInternalKeySlot) funList[1];
|
||||
PK11FreeSlot = (PK11_FreeSlot) funList[2];
|
||||
PK11Authenticate = (PK11_Authenticate) funList[3];
|
||||
PK11CheckUserPassword =(PK11_CheckUserPassword) funList[4];
|
||||
PK11SDRDecrypt = (PK11SDR_Decrypt) funList[5];
|
||||
PK11SDREncrypt = (PK11SDR_Encrypt) funList[6];
|
||||
PLBase64Encode = (PL_Base64Encode) funList[7];
|
||||
PLBase64Decode = (PL_Base64Decode) funList[8];
|
||||
PK11NeedUserInit = (PK11_NeedUserInit) funList[9];
|
||||
PK11InitPin = (PK11_InitPin) funList[10];
|
||||
|
||||
}
|
||||
|
||||
int CryptManager::GetEncryptionPref()
|
||||
{
|
||||
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function encrypts the clear text data. First it performs TRIPLE DES encryption
|
||||
* and then performs base64 encoding on the encrypted data.
|
||||
*
|
||||
* @param(in) clearData clear text data to be encrypted
|
||||
* @param(out) finalData encrypted data ( null terminated)
|
||||
*
|
||||
* @return FPM_TRUE on success and FPM_FALSE on error.
|
||||
*
|
||||
*/
|
||||
int CryptManager::EncryptString (char *clearData, char **finalData)
|
||||
{
|
||||
int encryptDataLen = 0;
|
||||
char *encryptData = NULL;
|
||||
char *encodeData = NULL;
|
||||
int retValue;
|
||||
|
||||
|
||||
if( clearData == NULL )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n EncryptString : Text Data is NULL");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
// Do the encryption if encryption pref is set otherwise just do base64 encoding...
|
||||
if ( GetEncryptionPref() )
|
||||
{
|
||||
PrintMessage(MESG_DEBUG, "\n EncryptString : Performing PK11 Encryption...");
|
||||
|
||||
retValue = FPM_FALSE;
|
||||
if( ((retValue = CryptPK11EncryptString(clearData, strlen(clearData), &encryptData, &encryptDataLen)) != FPM_TRUE) || ( encryptData == NULL) )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n EncryptString : Failed to encrypt the string : %s ", clearData);
|
||||
return retValue;
|
||||
}
|
||||
|
||||
if( (CryptBase64Encode(encryptData, encryptDataLen, finalData) != FPM_TRUE) || (*finalData == NULL) )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n EncryptString : BASE64 encoding failed");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n EncryptString : Success ");
|
||||
|
||||
// WARNING : If you uncomment , then be ready for side effects , crashes..etc
|
||||
// Need full analysis of malloc for this data..
|
||||
// Free the allocated blocks...
|
||||
|
||||
//if( encryptData )
|
||||
// free( encryptData);
|
||||
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
// otherwise do our own obscuring using Base64 encoding
|
||||
PrintMessage(MESG_DEBUG, "\n EncryptString : Performing JUST base64 encoding...");
|
||||
|
||||
if( (CryptBase64Encode(clearData, strlen(clearData), &encodeData) == FPM_FALSE) || (encodeData == NULL) )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n EncryptString : BASE64 encoding failed");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
// We need to add the CRYPT_PREFIX at the begining of encoded data...
|
||||
// This will help during decrption process to identify type of encryption
|
||||
|
||||
int prefixLen = strlen( CRYPT_PREFIX );
|
||||
int encodeLen = strlen( encodeData );
|
||||
*finalData = (char *)malloc( prefixLen + encodeLen + 1);
|
||||
|
||||
if( *finalData == NULL )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n EncryptString : Insufficient memory");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
// FinalData = CRYPT_PREFIX + Encoded Data + '\0'
|
||||
strcpy(*finalData, CRYPT_PREFIX);
|
||||
strcat(*finalData, encodeData);
|
||||
*(*finalData + prefixLen + encodeLen) = 0;
|
||||
|
||||
free(encodeData);
|
||||
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This function decrypts the encrypted data. First it performs base64 decoding and
|
||||
* then performs TRIPLE DES decryption.
|
||||
*
|
||||
* @param(in) cryptData encrypted data
|
||||
* @param(out) clearData clear text data ( null terminated)
|
||||
*
|
||||
* @return FPM_TRUE on success and FPM_FALSE on error.
|
||||
*
|
||||
*/
|
||||
|
||||
int CryptManager::DecryptString(char *cryptData, char **clearData)
|
||||
{
|
||||
int decodeLen = 0;
|
||||
int finalLen = 0;
|
||||
char *decodeData = NULL;
|
||||
char *finalData = NULL;
|
||||
int retValue;
|
||||
|
||||
if( cryptData == NULL )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n DecryptString: CryptData is NULL...");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
// treat zero-length crypt string as a special case
|
||||
if(cryptData[0] == '\0')
|
||||
{
|
||||
*clearData = (char*) malloc(1);
|
||||
**clearData = 0;
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
// use PK11 encryption stuff if crypt doesn't starts with prefix
|
||||
if( cryptData[0] != CRYPT_PREFIX[0] )
|
||||
{
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n Performing PK11 Decryption ");
|
||||
|
||||
// First do base64 decoding.....
|
||||
if( (CryptBase64Decode(cryptData, &decodeData, &decodeLen) != FPM_TRUE) || (decodeData == NULL) )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n DecryptString : Base64 decoding of crypt data failed ");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n DecryptString : base64data (%d) = %s ", decodeLen, decodeData);
|
||||
|
||||
// Now do actual PK11 decryption
|
||||
retValue = FPM_FALSE;
|
||||
retValue = CryptPK11DecryptString(decodeData, decodeLen, &finalData, &finalLen);
|
||||
|
||||
if( retValue != FPM_TRUE )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n DecryptString : Failed to decrypt the string ");
|
||||
return retValue;
|
||||
}
|
||||
|
||||
|
||||
// WARNING : Decrypted string is not NULL terminated
|
||||
// So we will create new NULL terminated string here...
|
||||
|
||||
*clearData = (char*) malloc( finalLen + 1 );
|
||||
|
||||
if( *clearData == NULL )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n DecryptString :Insufficient memory... ");
|
||||
return FPM_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
else
|
||||
{
|
||||
PrintMessage(MESG_DEBUG, "\n DecryptString : Copying new data ....");
|
||||
memcpy(*clearData, finalData, finalLen);
|
||||
*(*clearData + finalLen) = 0; // Null terminate the string....
|
||||
}
|
||||
|
||||
/*
|
||||
// Free the allocated memory
|
||||
// This is causing the problems currently...Later point we have to reanalyze the cause for this
|
||||
|
||||
if( decodeData )
|
||||
free(decodeData);
|
||||
|
||||
if( finalData )
|
||||
free(finalData);
|
||||
*/
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n decryptString : finalLen = %d ", finalLen);
|
||||
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
|
||||
// otherwise do our own de-obscuring
|
||||
PrintMessage(MESG_DEBUG, "\n DecryptString : Performing simple Base64 Decoding ");
|
||||
|
||||
unsigned int PREFIX_Len = strlen(CRYPT_PREFIX);
|
||||
if( strlen(cryptData) == PREFIX_Len )
|
||||
{
|
||||
*clearData = (char *)malloc(1);
|
||||
**clearData = '\0';
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
if( CryptBase64Decode(&cryptData[PREFIX_Len], clearData, &decodeLen) == FPM_FALSE )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n DecryptString : Base64 decoding of crypt data failed ");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Performs base64 encoding of the encrypted data..
|
||||
*
|
||||
* @param(in) cryptData encrypted data
|
||||
* @param(in) cryptDataLen length of encrypted data
|
||||
* @param(out) encodeData base64 encoded data
|
||||
*
|
||||
* @return FPM_TRUE on success and FPM_FALSE on error.
|
||||
*
|
||||
*/
|
||||
|
||||
int CryptManager::CryptBase64Encode(char *cryptData, int cryptDataLen, char **encodeData)
|
||||
{
|
||||
|
||||
*encodeData = (*PLBase64Encode)((const char *)cryptData, cryptDataLen, NULL);
|
||||
|
||||
if ( *encodeData == NULL )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n Base64 encoding failed ...");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Performs base64 decoding of the encrypted data..
|
||||
*
|
||||
* @param(in) cryptData encrypted data
|
||||
* @param(out) decodeData base64 decoded data
|
||||
* @param(out) decodeLen length of base64 decoded data
|
||||
*
|
||||
* @return FPM_TRUE on success and FPM_FALSE on error.
|
||||
*
|
||||
*/
|
||||
int CryptManager::CryptBase64Decode(char *cryptData, char **decodeData, int *decodeLen)
|
||||
{
|
||||
int len = strlen( cryptData );
|
||||
int adjust = 0;
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n CryptBase64Decode : Length of crypt data = %d", len);
|
||||
|
||||
// Compute length adjustment
|
||||
if (cryptData[len-1] == '=')
|
||||
{
|
||||
adjust++;
|
||||
if (cryptData[len-2] == '=')
|
||||
adjust++;
|
||||
}
|
||||
|
||||
*decodeData = ( char *)(*PLBase64Decode)(cryptData, len, NULL);
|
||||
|
||||
if( *decodeData == NULL )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n Base64 decoding failed ...");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
*decodeLen = (len*3)/4 - adjust;
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n CryptBase64Decode : Length of decoded data = %d", *decodeLen);
|
||||
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Performs TRIPLE DES encryption of clear text data
|
||||
*
|
||||
* @param(in) clearData clear text data to be encrypted
|
||||
* @param(in) clearDataLen length of clear text data
|
||||
* @param(out) cryptData TRIPLE DES encrypted data
|
||||
* @param(out) cryptDataLen length of encrypted data
|
||||
*
|
||||
* @return FPM_TRUE on success and FPM_FALSE on error.
|
||||
*
|
||||
*/
|
||||
int CryptManager::CryptPK11EncryptString(char *clearData, int clearDataLen, char **cryptData, int *cryptDataLen)
|
||||
{
|
||||
PK11SlotInfo *slot = 0;
|
||||
SECItem keyid;
|
||||
SECItem request;
|
||||
SECItem reply;
|
||||
SECStatus status;
|
||||
|
||||
slot = (*PK11GetInternalKeySlot)();
|
||||
|
||||
if (!slot)
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n CryptPK11EncryptString : PK11_GetInternalKeySlot failed ...");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
// PK11 authentication
|
||||
if ( (*PK11Authenticate)(slot, PR_TRUE, NULL) != SECSuccess)
|
||||
{
|
||||
// since we have specified password callback function , we won't come here...
|
||||
PrintMessage(MESG_ERROR, "\n CryptPK11EncryptString : PK11_Authenticate failed, possibly master password is wrong");
|
||||
(*PK11FreeSlot) (slot);
|
||||
return FPM_MASTERPASSWORD_WRONG;
|
||||
}
|
||||
|
||||
|
||||
// Use default key id
|
||||
keyid.data = 0;
|
||||
keyid.len = 0;
|
||||
request.data = (unsigned char *)clearData;
|
||||
request.len = clearDataLen;
|
||||
reply.data = 0;
|
||||
reply.len = 0;
|
||||
|
||||
status = (*PK11SDREncrypt)(&keyid, &request, &reply, NULL);
|
||||
|
||||
if (status != SECSuccess)
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n CryptPK11EncryptString : PK11SDR_Encrypt failed ...");
|
||||
(*PK11FreeSlot) (slot);
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
|
||||
*cryptData = (char*)reply.data;
|
||||
*cryptDataLen = reply.len;
|
||||
|
||||
(*PK11FreeSlot) (slot);
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Performs TRIPLE DES decryption of base64 decoded data
|
||||
*
|
||||
* @param(in) decodeData base64 decoded data
|
||||
* @param(in) decodeLen length of base64 decoded data
|
||||
* @param(out) clearData decrypted data
|
||||
* @param(out) finalLen length of decrypted data
|
||||
*
|
||||
* @return FPM_TRUE on success and FPM_FALSE on error.
|
||||
*
|
||||
*/
|
||||
int CryptManager::CryptPK11DecryptString(char *decodeData, int decodeLen, char **clearData, int *finalLen)
|
||||
{
|
||||
PK11SlotInfo *slot = 0;
|
||||
SECStatus status;
|
||||
SECItem request;
|
||||
SECItem reply;
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n CryptPK11DecryptString entered ...");
|
||||
|
||||
// Find token with SDR key
|
||||
slot = (*PK11GetInternalKeySlot)();
|
||||
|
||||
if (!slot)
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n PK11_GetInternalKeySlot failed ...");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n PK11_GetInternalKeySlot SUCCESS ...");
|
||||
|
||||
// Force authentication
|
||||
if ( (*PK11Authenticate)(slot, PR_TRUE, NULL) != SECSuccess)
|
||||
{
|
||||
// since we have specified password callback function , we won't come here...
|
||||
PrintMessage(MESG_ERROR, "\n PK11_Authenticate failed, Probably master password is wrong");
|
||||
(*PK11FreeSlot) (slot);
|
||||
return FPM_MASTERPASSWORD_WRONG;
|
||||
}
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n PK11_Authenticate SUCCESS ...");
|
||||
|
||||
// Decrypt the string
|
||||
request.data = (unsigned char *)decodeData;
|
||||
request.len = decodeLen;
|
||||
reply.data = 0;
|
||||
reply.len = 0;
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n calling PK11SDR_Decrypt ...");
|
||||
|
||||
status = (*PK11SDRDecrypt)(&request, &reply, NULL);
|
||||
|
||||
if (status != SECSuccess)
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n PK11SDR_Decrypt failed ...");
|
||||
(*PK11FreeSlot) (slot);
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n PK11SDR_Decrypt SUCCESS ");
|
||||
|
||||
// WARNING : This string is not NULL terminated..
|
||||
*clearData = (char*)reply.data;
|
||||
*finalLen = reply.len;
|
||||
|
||||
// Free the slot
|
||||
(*PK11FreeSlot) (slot);
|
||||
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,62 +1,64 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* 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
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef __FPM_CRYPT_MANAGER_H__
|
||||
#define __FPM_CRYPT_MANAGER_H__
|
||||
|
||||
#include "FirefoxPasswordManager.h"
|
||||
#include "Common.h"
|
||||
|
||||
|
||||
class CryptManager
|
||||
{
|
||||
|
||||
//PK11_SetPasswordFunc PK11SetPasswordFunc;
|
||||
PK11_GetInternalKeySlot PK11GetInternalKeySlot;
|
||||
PK11_FreeSlot PK11FreeSlot;
|
||||
PK11_Authenticate PK11Authenticate;
|
||||
PK11_CheckUserPassword PK11CheckUserPassword;
|
||||
PK11SDR_Decrypt PK11SDRDecrypt;
|
||||
PK11SDR_Encrypt PK11SDREncrypt;
|
||||
|
||||
PL_Base64Encode PLBase64Encode;
|
||||
PL_Base64Decode PLBase64Decode;
|
||||
|
||||
public:
|
||||
|
||||
int DecryptString(char *cryptData, char **clearData);
|
||||
int EncryptString (char *clearData, char **finalData) ;
|
||||
int CryptBase64Decode(char *cryptData, char **decodeData, int *decodeLen);
|
||||
int CryptBase64Encode(char *cryptData, int cryptDataLen, char **encodeData);
|
||||
int CryptPK11DecryptString(char *decodeData, int decodeLen, char **clearData, int *finalLen);
|
||||
int CryptPK11EncryptString(char *clearData, int clearDataLen, char **cryptData, int *cryptDataLen);
|
||||
|
||||
void SetupFunctions(void *funList[]);
|
||||
int GetEncryptionPref();
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* 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
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef __FPM_CRYPT_MANAGER_H__
|
||||
#define __FPM_CRYPT_MANAGER_H__
|
||||
|
||||
#include "FirefoxPasswordManager.h"
|
||||
#include "Common.h"
|
||||
|
||||
|
||||
class CryptManager
|
||||
{
|
||||
|
||||
//PK11_SetPasswordFunc PK11SetPasswordFunc;
|
||||
PK11_GetInternalKeySlot PK11GetInternalKeySlot;
|
||||
PK11_FreeSlot PK11FreeSlot;
|
||||
PK11_Authenticate PK11Authenticate;
|
||||
PK11_CheckUserPassword PK11CheckUserPassword;
|
||||
PK11SDR_Decrypt PK11SDRDecrypt;
|
||||
PK11SDR_Encrypt PK11SDREncrypt;
|
||||
PK11_NeedUserInit PK11NeedUserInit;
|
||||
PK11_InitPin PK11InitPin;
|
||||
|
||||
PL_Base64Encode PLBase64Encode;
|
||||
PL_Base64Decode PLBase64Decode;
|
||||
|
||||
public:
|
||||
|
||||
int DecryptString(char *cryptData, char **clearData);
|
||||
int EncryptString (char *clearData, char **finalData) ;
|
||||
int CryptBase64Decode(char *cryptData, char **decodeData, int *decodeLen);
|
||||
int CryptBase64Encode(char *cryptData, int cryptDataLen, char **encodeData);
|
||||
int CryptPK11DecryptString(char *decodeData, int decodeLen, char **clearData, int *finalLen);
|
||||
int CryptPK11EncryptString(char *clearData, int clearDataLen, char **cryptData, int *cryptDataLen);
|
||||
|
||||
void SetupFunctions(void *funList[]);
|
||||
int GetEncryptionPref();
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,186 +1,193 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* 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
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef __FPM_Firefox_Password_MANAGER_H__
|
||||
#define __FPM_Firefox_Password_MANAGER_H__
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#include <userenv.h>
|
||||
#pragma comment(lib,"userenv.lib")
|
||||
|
||||
#define STRCMPI strcmpi
|
||||
#define APIEXPORT __declspec(dllexport)
|
||||
|
||||
#define NSS_LIBRARY_NAME "nss3.dll"
|
||||
#define PLC_LIBRARY_NAME "plc4.dll"
|
||||
#define NSPR_LIBRARY_NAME "nspr4.dll"
|
||||
#define PLDS_LIBRARY_NAME "plds4.dll"
|
||||
#define SOFTN_LIBRARY_NAME "softokn3.dll"
|
||||
|
||||
#define LOADLIBRARY(x) LoadLibrary(x)
|
||||
#define GETPROCADDRESS GetProcAddress
|
||||
#define FREELIBRARY FreeLibrary
|
||||
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
#define STRCMPI strcasecmp
|
||||
#define APIEXPORT
|
||||
|
||||
#define NSS_LIBRARY_NAME "libnss3.so"
|
||||
#define PLC_LIBRARY_NAME "libplc4.so"
|
||||
#define NSPR_LIBRARY_NAME "libnspr4.so"
|
||||
#define PLDS_LIBRARY_NAME "libplds4.so"
|
||||
#define SOFTN_LIBRARY_NAME "libsoftokn3.so"
|
||||
|
||||
#define LOADLIBRARY(x) dlopen(x, RTLD_LAZY) // alternative : RTLD_NOW
|
||||
#define GETPROCADDRESS dlsym
|
||||
#define FREELIBRARY dlclose
|
||||
|
||||
#define HMODULE void *
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define FPM_TRUE 1
|
||||
#define FPM_FALSE 0
|
||||
|
||||
#define MESG_DEBUG 0
|
||||
#define MESG_PRINT 1
|
||||
#define MESG_ERROR 2
|
||||
|
||||
#define MAX_PROFILE_COUNT 5
|
||||
|
||||
//#define DEBUG 11
|
||||
|
||||
#define Unichar unsigned int
|
||||
|
||||
#define HEADER_VERSION "#2c"
|
||||
#define CRYPT_PREFIX "~"
|
||||
|
||||
#define SIGNON_FILE_NAME "signons.txt"
|
||||
|
||||
// Internal structure declaration taken from firefox.....
|
||||
typedef enum SECItemType
|
||||
{
|
||||
siBuffer = 0,
|
||||
siClearDataBuffer = 1,
|
||||
siCipherDataBuffer = 2,
|
||||
siDERCertBuffer = 3,
|
||||
siEncodedCertBuffer = 4,
|
||||
siDERNameBuffer = 5,
|
||||
siEncodedNameBuffer = 6,
|
||||
siAsciiNameString = 7,
|
||||
siAsciiString = 8,
|
||||
siDEROID = 9,
|
||||
siUnsignedInteger = 10,
|
||||
siUTCTime = 11,
|
||||
siGeneralizedTime = 12
|
||||
};
|
||||
|
||||
//typedef struct SECItemStr SECItem;
|
||||
|
||||
struct SECItem
|
||||
{
|
||||
SECItemType type;
|
||||
unsigned char *data;
|
||||
unsigned int len;
|
||||
};
|
||||
|
||||
|
||||
typedef enum SECStatus
|
||||
{
|
||||
SECWouldBlock = -2,
|
||||
SECFailure = -1,
|
||||
SECSuccess = 0
|
||||
};
|
||||
|
||||
// For some PR type varialbes...just to remove gecko-sdk dependency
|
||||
// following is added here.
|
||||
#define PRBool int
|
||||
#define PRUint32 unsigned int
|
||||
#define PR_TRUE 1
|
||||
#define PR_FALSE 0
|
||||
|
||||
|
||||
|
||||
// End
|
||||
|
||||
|
||||
|
||||
typedef struct PK11SlotInfoStr PK11SlotInfo;
|
||||
|
||||
// NSS Library functions
|
||||
//typedef char *(PR_CALLBACK *PK11PasswordFunc)(PK11SlotInfo *slot, PRBool retry, void *arg);
|
||||
typedef SECStatus (*NSS_Init) (const char *configdir);
|
||||
typedef SECStatus (*NSS_Shutdown) (void);
|
||||
//typedef void (*PK11_SetPasswordFunc) (PK11PasswordFunc func);
|
||||
typedef PK11SlotInfo * (*PK11_GetInternalKeySlot) (void);
|
||||
typedef void (*PK11_FreeSlot) (PK11SlotInfo *slot);
|
||||
typedef SECStatus (*PK11_Authenticate) (PK11SlotInfo *slot, PRBool loadCerts, void *wincx);
|
||||
typedef SECStatus (*PK11_CheckUserPassword) (PK11SlotInfo *slot,char *pw);
|
||||
typedef SECStatus (*PK11SDR_Decrypt) (SECItem *data, SECItem *result, void *cx);
|
||||
typedef SECStatus (*PK11SDR_Encrypt) (SECItem *keyid, SECItem *data, SECItem *result, void *cx);
|
||||
|
||||
// PLC Library functions
|
||||
typedef char * (*PL_Base64Encode)( const char *src, PRUint32 srclen, char *dest);
|
||||
typedef char * (*PL_Base64Decode)( const char *src, PRUint32 srclen, char *dest);
|
||||
|
||||
void PrintMessage( int level, char *mesg , ...);
|
||||
int IsDirectoryExists( char *path );
|
||||
void StrLwr(char *str);
|
||||
|
||||
|
||||
|
||||
// Profile initiliazation functions
|
||||
extern "C" APIEXPORT int FPM_IsStoreAvailable();
|
||||
extern "C" APIEXPORT int FPM_GetProfileList(char **profileList[], int **profileFlag);
|
||||
extern "C" APIEXPORT int FPM_FirefoxProfileInit(char *profileName);
|
||||
extern "C" APIEXPORT int FPM_FirefoxProfileExit(char *profileName);
|
||||
|
||||
// Master password functions
|
||||
extern "C" APIEXPORT int FPM_IsMasterPasswordSet(char *profileName);
|
||||
extern "C" APIEXPORT int FPM_CheckMasterPassword(char *profileName, char *masterPassword);
|
||||
|
||||
// Signon data update functions
|
||||
extern "C" APIEXPORT int FPM_GetSignonData(char *profileName,struct Host **host, int doRefresh);
|
||||
extern "C" APIEXPORT int FPM_WriteSignonData(char *profileName);
|
||||
extern "C" APIEXPORT int FPM_AddHost(char *profileName, struct Host *host, int doUpdate);
|
||||
extern "C" APIEXPORT int FPM_ModifyHost(char *profileName, struct Host *host, int doUpdate);
|
||||
extern "C" APIEXPORT int FPM_RemoveHost(char *profileName, char *hostname, int doUpdate);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* 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
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef __FPM_Firefox_Password_MANAGER_H__
|
||||
#define __FPM_Firefox_Password_MANAGER_H__
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#include <userenv.h>
|
||||
#include <direct.h>
|
||||
#pragma comment(lib,"userenv.lib")
|
||||
|
||||
#define STRCMPI strcmpi
|
||||
#define APIEXPORT __declspec(dllexport)
|
||||
|
||||
#define NSS_LIBRARY_NAME "nss3.dll"
|
||||
#define PLC_LIBRARY_NAME "plc4.dll"
|
||||
#define NSPR_LIBRARY_NAME "nspr4.dll"
|
||||
#define PLDS_LIBRARY_NAME "plds4.dll"
|
||||
#define SOFTN_LIBRARY_NAME "softokn3.dll"
|
||||
|
||||
#define LOADLIBRARY(x) LoadLibrary(x)
|
||||
#define GETPROCADDRESS GetProcAddress
|
||||
#define FREELIBRARY FreeLibrary
|
||||
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
#define STRCMPI strcasecmp
|
||||
#define APIEXPORT
|
||||
|
||||
#define NSS_LIBRARY_NAME "libnss3.so"
|
||||
#define PLC_LIBRARY_NAME "libplc4.so"
|
||||
#define NSPR_LIBRARY_NAME "libnspr4.so"
|
||||
#define PLDS_LIBRARY_NAME "libplds4.so"
|
||||
#define SOFTN_LIBRARY_NAME "libsoftokn3.so"
|
||||
|
||||
#define LOADLIBRARY(x) dlopen(x, RTLD_LAZY) // alternative : RTLD_NOW
|
||||
#define GETPROCADDRESS dlsym
|
||||
#define FREELIBRARY dlclose
|
||||
|
||||
#define HMODULE void *
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define FPM_TRUE 1
|
||||
#define FPM_FALSE 0
|
||||
|
||||
#define MESG_DEBUG 0
|
||||
#define MESG_PRINT 1
|
||||
#define MESG_ERROR 2
|
||||
|
||||
#define MAX_PROFILE_COUNT 5
|
||||
|
||||
//#define DEBUG 11
|
||||
|
||||
#define Unichar unsigned int
|
||||
|
||||
#define HEADER_VERSION "#2c"
|
||||
#define CRYPT_PREFIX "~"
|
||||
|
||||
#define SIGNON_FILE_NAME "signons.txt"
|
||||
|
||||
// Internal structure declaration taken from firefox.....
|
||||
typedef enum SECItemType
|
||||
{
|
||||
siBuffer = 0,
|
||||
siClearDataBuffer = 1,
|
||||
siCipherDataBuffer = 2,
|
||||
siDERCertBuffer = 3,
|
||||
siEncodedCertBuffer = 4,
|
||||
siDERNameBuffer = 5,
|
||||
siEncodedNameBuffer = 6,
|
||||
siAsciiNameString = 7,
|
||||
siAsciiString = 8,
|
||||
siDEROID = 9,
|
||||
siUnsignedInteger = 10,
|
||||
siUTCTime = 11,
|
||||
siGeneralizedTime = 12
|
||||
};
|
||||
|
||||
//typedef struct SECItemStr SECItem;
|
||||
|
||||
struct SECItem
|
||||
{
|
||||
SECItemType type;
|
||||
unsigned char *data;
|
||||
unsigned int len;
|
||||
};
|
||||
|
||||
|
||||
typedef enum SECStatus
|
||||
{
|
||||
SECWouldBlock = -2,
|
||||
SECFailure = -1,
|
||||
SECSuccess = 0
|
||||
};
|
||||
|
||||
// For some PR type varialbes...just to remove gecko-sdk dependency
|
||||
// following is added here.
|
||||
#define PRBool int
|
||||
#define PRUint32 unsigned int
|
||||
#define PR_TRUE 1
|
||||
#define PR_FALSE 0
|
||||
|
||||
|
||||
|
||||
// End
|
||||
|
||||
|
||||
|
||||
typedef struct PK11SlotInfoStr PK11SlotInfo;
|
||||
|
||||
// NSS Library functions
|
||||
//typedef char *(PR_CALLBACK *PK11PasswordFunc)(PK11SlotInfo *slot, PRBool retry, void *arg);
|
||||
typedef SECStatus (*NSS_Init) (const char *configdir);
|
||||
typedef SECStatus (*NSS_Shutdown) (void);
|
||||
//typedef void (*PK11_SetPasswordFunc) (PK11PasswordFunc func);
|
||||
typedef PK11SlotInfo * (*PK11_GetInternalKeySlot) (void);
|
||||
typedef void (*PK11_FreeSlot) (PK11SlotInfo *slot);
|
||||
typedef SECStatus (*PK11_Authenticate) (PK11SlotInfo *slot, PRBool loadCerts, void *wincx);
|
||||
typedef SECStatus (*PK11_CheckUserPassword) (PK11SlotInfo *slot,char *pw);
|
||||
typedef SECStatus (*PK11SDR_Decrypt) (SECItem *data, SECItem *result, void *cx);
|
||||
typedef SECStatus (*PK11SDR_Encrypt) (SECItem *keyid, SECItem *data, SECItem *result, void *cx);
|
||||
typedef PRBool (*PK11_NeedUserInit) (PK11SlotInfo *slot);
|
||||
typedef SECStatus (*PK11_InitPin) (PK11SlotInfo *slot,char *ssopw, char *pk11_userpwd);
|
||||
typedef SECStatus (*NSS_InitReadWrite) (const char *configdir);
|
||||
|
||||
// PLC Library functions
|
||||
typedef char * (*PL_Base64Encode)( const char *src, PRUint32 srclen, char *dest);
|
||||
typedef char * (*PL_Base64Decode)( const char *src, PRUint32 srclen, char *dest);
|
||||
|
||||
void PrintMessage( int level, char *mesg , ...);
|
||||
int IsDirectoryExists( char *path );
|
||||
void StrLwr(char *str);
|
||||
int CreateDirectory( char *path );
|
||||
|
||||
|
||||
|
||||
// Profile initiliazation functions
|
||||
extern "C" APIEXPORT int FPM_IsStoreAvailable();
|
||||
extern "C" APIEXPORT int FPM_GetProfileList(char **profileList[], int **profileFlag);
|
||||
extern "C" APIEXPORT int FPM_FirefoxProfileInit(char *profileName);
|
||||
extern "C" APIEXPORT int FPM_FirefoxProfileExit(char *profileName);
|
||||
|
||||
// Master password functions
|
||||
extern "C" APIEXPORT int FPM_IsMasterPasswordSet(char *profileName);
|
||||
extern "C" APIEXPORT int FPM_CheckMasterPassword(char *profileName, char *masterPassword);
|
||||
|
||||
// Signon data update functions
|
||||
extern "C" APIEXPORT int FPM_GetSignonData(char *profileName,struct Host **host, int doRefresh);
|
||||
extern "C" APIEXPORT int FPM_WriteSignonData(char *profileName);
|
||||
extern "C" APIEXPORT int FPM_AddHost(char *profileName, struct Host *host, int doUpdate);
|
||||
extern "C" APIEXPORT int FPM_ModifyHost(char *profileName, struct Host *host, int doUpdate);
|
||||
extern "C" APIEXPORT int FPM_RemoveHost(char *profileName, char *hostname, int doUpdate);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,93 +1,96 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* 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
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef __FPM_PROFILE_MANAGER_H__
|
||||
#define __FPM_PROFILE_MANAGER_H__
|
||||
|
||||
#include "FirefoxPasswordManager.h"
|
||||
#include "Common.h"
|
||||
#include "SignonManager.h"
|
||||
|
||||
|
||||
class ProfileManager
|
||||
{
|
||||
SignonManager signonManager;
|
||||
|
||||
char *profilePath;
|
||||
char *libraryPath;
|
||||
char *masterPassword;
|
||||
|
||||
HMODULE libnss;
|
||||
HMODULE libplc;
|
||||
|
||||
// NSS Library function pointers
|
||||
NSS_Init NSSInit;
|
||||
NSS_Shutdown NSSShutdown;
|
||||
//PK11_SetPasswordFunc PK11SetPasswordFunc;
|
||||
PK11_GetInternalKeySlot PK11GetInternalKeySlot;
|
||||
PK11_FreeSlot PK11FreeSlot;
|
||||
PK11_Authenticate PK11Authenticate;
|
||||
PK11_CheckUserPassword PK11CheckUserPassword;
|
||||
PK11SDR_Decrypt PK11SDRDecrypt;
|
||||
PK11SDR_Encrypt PK11SDREncrypt;
|
||||
|
||||
PL_Base64Encode PLBase64Encode;
|
||||
PL_Base64Decode PLBase64Decode;
|
||||
|
||||
public :
|
||||
|
||||
char *profileName;
|
||||
int isInitialized;
|
||||
|
||||
private :
|
||||
|
||||
char *GetFirefoxProfilePath(char *profileName);
|
||||
char *GetFirefoxLibPath();
|
||||
HMODULE PMLoadLibrary(char *firefoxDir, char *libName);
|
||||
int RefreshSignonData();
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
ProfileManager();
|
||||
|
||||
int IsStoreAvailable();
|
||||
int ProfileInit(char *profileName);
|
||||
void ProfileExit();
|
||||
|
||||
int IsMasterPasswordSet();
|
||||
int CheckMasterPassword(char *masterPassword, int doSave);
|
||||
|
||||
int GetSignonData( struct Host **host, int doRefresh);
|
||||
int WriteSignonData();
|
||||
|
||||
int AddHost(struct Host *host, int doUpdate);
|
||||
int ModifyHost(struct Host *host, int doUpdat);
|
||||
int RemoveHost(char *hostname, int doUpdate);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* 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
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef __FPM_PROFILE_MANAGER_H__
|
||||
#define __FPM_PROFILE_MANAGER_H__
|
||||
|
||||
#include "FirefoxPasswordManager.h"
|
||||
#include "Common.h"
|
||||
#include "SignonManager.h"
|
||||
|
||||
|
||||
class ProfileManager
|
||||
{
|
||||
SignonManager signonManager;
|
||||
|
||||
char *profilePath;
|
||||
char *libraryPath;
|
||||
char *masterPassword;
|
||||
|
||||
HMODULE libnss;
|
||||
HMODULE libplc;
|
||||
|
||||
// NSS Library function pointers
|
||||
NSS_Init NSSInit;
|
||||
NSS_Shutdown NSSShutdown;
|
||||
//PK11_SetPasswordFunc PK11SetPasswordFunc;
|
||||
PK11_GetInternalKeySlot PK11GetInternalKeySlot;
|
||||
PK11_FreeSlot PK11FreeSlot;
|
||||
PK11_Authenticate PK11Authenticate;
|
||||
PK11_CheckUserPassword PK11CheckUserPassword;
|
||||
PK11SDR_Decrypt PK11SDRDecrypt;
|
||||
PK11SDR_Encrypt PK11SDREncrypt;
|
||||
PK11_NeedUserInit PK11NeedUserInit;
|
||||
PK11_InitPin PK11InitPin;
|
||||
NSS_InitReadWrite NSSInitReadWrite;
|
||||
|
||||
PL_Base64Encode PLBase64Encode;
|
||||
PL_Base64Decode PLBase64Decode;
|
||||
|
||||
public :
|
||||
|
||||
char *profileName;
|
||||
int isInitialized;
|
||||
|
||||
private :
|
||||
|
||||
char *GetFirefoxProfilePath(char *profileName);
|
||||
char *GetFirefoxLibPath();
|
||||
HMODULE PMLoadLibrary(char *firefoxDir, char *libName);
|
||||
int RefreshSignonData();
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
ProfileManager();
|
||||
|
||||
int IsStoreAvailable();
|
||||
int ProfileInit(char *profileName);
|
||||
void ProfileExit();
|
||||
|
||||
int IsMasterPasswordSet();
|
||||
int CheckMasterPassword(char *masterPassword, int doSave);
|
||||
|
||||
int GetSignonData( struct Host **host, int doRefresh);
|
||||
int WriteSignonData();
|
||||
|
||||
int AddHost(struct Host *host, int doUpdate);
|
||||
int ModifyHost(struct Host *host, int doUpdat);
|
||||
int RemoveHost(char *hostname, int doUpdate);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -78,9 +78,25 @@ char *signonFilePath = NULL;
|
||||
|
||||
if( signonFile == NULL )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n SignonManager : Error opening signon file %s", signonFilePath);
|
||||
free(signonFilePath);
|
||||
return FPM_SIGNON_FILE_NOT_PRESENT;
|
||||
PrintMessage(MESG_DEBUG, "\n SignonManager : Error opening signon file %s", signonFilePath);
|
||||
PrintMessage(MESG_DEBUG, "\n SignonManager : Creating new signon file %s", signonFilePath);
|
||||
|
||||
if((signonFile = fopen(signonFilePath, "a")) == NULL)
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n SignonManager : Error creating signon file %s", signonFilePath);
|
||||
free(signonFilePath);
|
||||
return FPM_SIGNON_FILE_NOT_PRESENT;
|
||||
}
|
||||
if( WriteLine(HEADER_VERSION) != FPM_TRUE)
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n SignonManager : Error writing header to new signon file %s", signonFilePath);
|
||||
free(signonFilePath);
|
||||
fclose(signonFile);
|
||||
return FPM_SIGNON_FILE_NOT_PRESENT;
|
||||
}
|
||||
|
||||
fclose(signonFile);
|
||||
signonFile = fopen(signonFilePath, accessType);
|
||||
}
|
||||
|
||||
// cleanup
|
||||
@ -238,7 +254,7 @@ int SignonManager::WriteCharUTF8(Unichar c)
|
||||
int SignonManager::WriteLine(char *line)
|
||||
{
|
||||
|
||||
for(int i=0; i < strlen(line); i++)
|
||||
for(unsigned int i=0; i < strlen(line); i++)
|
||||
{
|
||||
if( WriteCharUTF8(line[i]) != FPM_TRUE )
|
||||
return FPM_SIGNON_FILE_WRITE_ERROR;
|
||||
@ -269,6 +285,7 @@ char name[1024];
|
||||
int bufferLength = 4095;
|
||||
int retValue;
|
||||
char *clearData = NULL;
|
||||
char *newHostName, *uname;
|
||||
int count = 0;
|
||||
|
||||
|
||||
@ -349,6 +366,7 @@ int count = 0;
|
||||
PrintMessage(MESG_DEBUG, "\n\n Host : %s ", hostName);
|
||||
|
||||
// prepare to read the name/value pairs
|
||||
count = 0;
|
||||
while( ReadLine(buffer, bufferLength) == FPM_TRUE )
|
||||
{
|
||||
// line starting with . terminates the pairs for this URL entry
|
||||
@ -370,7 +388,8 @@ int count = 0;
|
||||
isPassword = 0;
|
||||
strcpy(name, buffer);
|
||||
retValue = ReadLine(buffer, bufferLength);
|
||||
}
|
||||
}
|
||||
count++;
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n\n name = %s and value = %s ", name, buffer);
|
||||
|
||||
@ -390,8 +409,28 @@ int count = 0;
|
||||
if( ((retValue = cryptManager.DecryptString(buffer, &clearData)) == FPM_TRUE) && (clearData != NULL) )
|
||||
{
|
||||
// Add the name/value pair to the existing store....
|
||||
retValue = dataManager.AddHostElement(hostName, name, clearData, isPassword);
|
||||
if (count == 1)
|
||||
{
|
||||
uname = (char *) malloc(strlen(clearData)*sizeof(char));
|
||||
strcpy(uname, clearData);
|
||||
}
|
||||
|
||||
if (count>2)
|
||||
{
|
||||
if(count%2==1)
|
||||
{
|
||||
newHostName = (char *)malloc((strlen(hostName)+strlen(clearData)+4)*sizeof(char));
|
||||
strcpy(newHostName,hostName);
|
||||
strncat(newHostName, " (", 2);
|
||||
strncat(newHostName,clearData, strlen(clearData));
|
||||
strncat(newHostName, ")", 1);
|
||||
dataManager.AddHost(newHostName);
|
||||
}
|
||||
retValue = dataManager.AddHostElement(newHostName, name, clearData, isPassword);
|
||||
}
|
||||
else
|
||||
retValue = dataManager.AddHostElement(hostName, name, clearData, isPassword);
|
||||
|
||||
if( retValue != FPM_TRUE )
|
||||
{
|
||||
CloseSignonFile();
|
||||
@ -409,13 +448,20 @@ int count = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (count >2)
|
||||
{
|
||||
newHostName = (char *)malloc((strlen(hostName)+strlen(uname)+4)*sizeof(char));
|
||||
strcpy(newHostName,hostName);
|
||||
strncat(newHostName, " (", 2);
|
||||
strncat(newHostName, uname, strlen(uname));
|
||||
strncat(newHostName, ")", 1);
|
||||
dataManager.ModifyHost(hostName, newHostName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Now close the signon file
|
||||
CloseSignonFile();
|
||||
|
||||
// Print data for cross checking
|
||||
#ifdef DEBUG
|
||||
dataManager.PrintAllRejectHosts();
|
||||
@ -434,9 +480,11 @@ char *signonFilePath = NULL;
|
||||
char *tempFilePath = NULL;
|
||||
char fileName[256];
|
||||
|
||||
Host *t;
|
||||
HostElement *h;
|
||||
Host *writeList, *newHost;
|
||||
HostElement *h, *temp;
|
||||
RejectHost *r;
|
||||
char *hn2;
|
||||
int len;
|
||||
|
||||
// TODO : If signon data has not changed since last write then return...
|
||||
/* // There may be requirement to write empty data...
|
||||
@ -499,9 +547,55 @@ RejectHost *r;
|
||||
* if type is password, name is preceded by an asterisk (*)
|
||||
*/
|
||||
|
||||
//copy list
|
||||
writeList = NULL;
|
||||
temp = NULL;
|
||||
newHost = NULL;
|
||||
for(Host *host=dataManager.hostList;host;host=host->next)
|
||||
{
|
||||
if(writeList == NULL)
|
||||
{
|
||||
writeList = dataManager.DuplicateHost(host);
|
||||
newHost = writeList;
|
||||
newHost->next = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
newHost->next = dataManager.DuplicateHost(host);
|
||||
newHost = newHost->next;
|
||||
newHost->next = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// create list to write
|
||||
hn2 = (char *) malloc(sizeof(char)*100);
|
||||
Host *t1;
|
||||
Host *pre;
|
||||
for(Host *t=writeList; t; t=t->next)
|
||||
{
|
||||
if((hn2=strstr(t->hostName," ("))!=NULL)
|
||||
{
|
||||
len = strlen(t->hostName);
|
||||
t->hostName[len-strlen(hn2)]='\0';
|
||||
pre = t;
|
||||
for(t1=t->next; t1; t1=t1->next)
|
||||
{
|
||||
if(strncmp(t->hostName, t1->hostName, strlen(t->hostName))==0)
|
||||
{
|
||||
for(temp=t->child; temp->next!=NULL; temp=temp->next);
|
||||
|
||||
temp->next = t1->child;
|
||||
pre->next = t1->next;
|
||||
t1 = pre;
|
||||
}
|
||||
pre=t1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// write out each URL node
|
||||
for(t=dataManager.hostList; t ; t=t->next)
|
||||
for(Host *t=writeList; t ; t=t->next)
|
||||
{
|
||||
PrintMessage(MESG_DEBUG, "\n\nWriteSignonData : Adding name/value pairs for host %s", t->hostName);
|
||||
|
||||
|
@ -916,11 +916,12 @@ namespace Novell.CASA.GUI
|
||||
case Common.STORE_FIREFOX:
|
||||
if( 0 != objFirefox.tvSecretIDFirefox.Selection.CountSelectedRows() )
|
||||
{
|
||||
mmiNew.Sensitive = mmiNewKey.Sensitive = false;
|
||||
mmiNew.Sensitive = true;
|
||||
mmiNewKey.Sensitive = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mmiNew.Sensitive = mmiNewKey.Sensitive = false;
|
||||
mmiNewKey.Sensitive = false;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1194,6 +1195,7 @@ namespace Novell.CASA.GUI
|
||||
break;
|
||||
|
||||
case Common.STORE_FIREFOX:
|
||||
objFirefox.OnNewSecretActivated(obj, args);
|
||||
break;
|
||||
|
||||
case Common.STORE_MOZILLA:
|
||||
@ -1232,6 +1234,7 @@ namespace Novell.CASA.GUI
|
||||
break;
|
||||
|
||||
case Common.STORE_FIREFOX:
|
||||
objFirefox.OnNewKeyActivated(obj, args);
|
||||
break;
|
||||
|
||||
case Common.STORE_MOZILLA:
|
||||
@ -2305,7 +2308,7 @@ namespace Novell.CASA.GUI
|
||||
{
|
||||
DbgFileChooser dbf = new DbgFileChooser();
|
||||
dbf.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,8 @@ public class Common
|
||||
OPERATION_ADD_KEY = 1,
|
||||
OPERATION_MODIFY_KEY = 2,
|
||||
OPERATION_DELETE_SECRET = 3,
|
||||
OPERATION_DELETE_KEY = 4;
|
||||
OPERATION_DELETE_KEY = 4,
|
||||
OPERATION_MODIFY_SECRET = 5;
|
||||
|
||||
//Limits
|
||||
public static int MAX_ARRAY_ELEMENTS = 10;
|
||||
|
@ -38,12 +38,18 @@ public class Firefox : Store
|
||||
tsKeyValue;
|
||||
|
||||
CellRendererText cellEditable;
|
||||
|
||||
CellRendererToggle cellToggle;
|
||||
|
||||
ArrayList arrDeletedKeys = null;
|
||||
bool isPasswordToggled;
|
||||
|
||||
public bool IS_STORE_AGGREGATED = false;
|
||||
|
||||
private int m_iRememberSeconds = 5;
|
||||
private String m_sRememberFor = "5";
|
||||
private Config m_config = null;
|
||||
private Config m_config = null;
|
||||
static Char[] SpecialCharacters = new Char[]{ '*', '\'', '\\', '&', '=', '<', '>' };
|
||||
|
||||
#region Glade Widgets
|
||||
|
||||
[Glade.Widget]
|
||||
@ -60,6 +66,7 @@ public class Firefox : Store
|
||||
dialogManageSecret,
|
||||
dialogLogin,
|
||||
dialogConfirmDelete,
|
||||
dialogInvalidSecret,
|
||||
dialogSpecialCharacter;
|
||||
|
||||
[Glade.Widget]
|
||||
@ -112,7 +119,7 @@ public class Firefox : Store
|
||||
m_config = config;
|
||||
/// SecretID TreeStore
|
||||
tvSecretIDFirefox = (Gtk.TreeView)CasaMain.gxmlMain.GetWidget("tvSecretIDFirefox");
|
||||
tsSecretIDFirefox = new TreeStore(typeof(string), typeof(string[]), typeof(string[]), typeof(string), typeof(string[]), typeof(string[]));
|
||||
tsSecretIDFirefox = new TreeStore(typeof(string), typeof(string[]), typeof(string[]), typeof(string), typeof(string[]), typeof(string[]), typeof(bool[]));
|
||||
tvSecretIDFirefox.AppendColumn("Secret ID",new CellRendererText(),"text",0);
|
||||
tvSecretIDFirefox.Model = tsSecretIDFirefox;
|
||||
tvSecretIDFirefox.RowActivated += new RowActivatedHandler(OntvSecretIDFirefoxRowActivated);
|
||||
@ -213,9 +220,15 @@ public class Firefox : Store
|
||||
menuRightClick.Popup(null, null, null, IntPtr.Zero, 3, Gtk.Global.CurrentEventTime);
|
||||
|
||||
if( 0 != tvSecretIDFirefox.Selection.CountSelectedRows() )
|
||||
cmiNewSecret.Sensitive = cmiNewKey.Sensitive = cmiLink.Sensitive = cmiCopy.Sensitive = false;
|
||||
else
|
||||
cmiNewSecret.Sensitive = cmiNewKey.Sensitive = cmiDelete.Sensitive = cmiLink.Sensitive = cmiCopy.Sensitive = cmiView.Sensitive = false;
|
||||
{
|
||||
cmiNewSecret.Sensitive = cmiNewKey.Sensitive = true;
|
||||
cmiLink.Sensitive = cmiCopy.Sensitive = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
cmiNewSecret.Sensitive = true;
|
||||
cmiNewKey.Sensitive = cmiDelete.Sensitive = cmiLink.Sensitive = cmiCopy.Sensitive = cmiView.Sensitive = false;
|
||||
}
|
||||
}
|
||||
catch(Exception exp)
|
||||
{
|
||||
@ -240,14 +253,22 @@ public class Firefox : Store
|
||||
string selected= null;
|
||||
string[] keys = null,
|
||||
values = null;
|
||||
bool[] ispassword = null;
|
||||
isPasswordToggled = false;
|
||||
try
|
||||
{
|
||||
|
||||
if( null == arrDeletedKeys )
|
||||
arrDeletedKeys = new ArrayList();
|
||||
else
|
||||
arrDeletedKeys.Clear();
|
||||
|
||||
if( tvSecretIDFirefox.Selection.GetSelected (out model, out iter) )
|
||||
{
|
||||
selected = (string) model.GetValue(iter, 0);
|
||||
keys = (string[]) model.GetValue(iter, 1);
|
||||
values = (string[]) model.GetValue(iter, 2);
|
||||
ispassword = (bool[]) model.GetValue(iter, 6);
|
||||
|
||||
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "dialogManageSecret", null);
|
||||
gxmlTemp.Autoconnect (this);
|
||||
@ -256,24 +277,27 @@ public class Firefox : Store
|
||||
|
||||
cellEditable = new CellRendererText();
|
||||
cellEditable.Editable = true;
|
||||
cellEditable.Edited += new EditedHandler(OnKeyValueEdited);
|
||||
//cellEditable.Edited += new EditedHandler(OnKeyValueEdited);
|
||||
/// KEY:0 VALUE:1 VALUE-DUP:2 DIRTY-BIT:3 LINK:4
|
||||
tsKeyValue = new TreeStore(typeof(string),typeof(string), typeof(string), typeof(bool), typeof(string));
|
||||
cellEditable.Edited += new EditedHandler(OnKeyValueEdited);
|
||||
|
||||
cellToggle = new CellRendererToggle();
|
||||
cellToggle.Activatable = true;
|
||||
cellToggle.Toggled += OnIsPasswordToggled;
|
||||
|
||||
/// KEY:0 VALUE:1 VALUE-DUP:2 DIRTY-BIT:3 LINK:4 ISPASSWORD:5
|
||||
tsKeyValue = new TreeStore(typeof(string),typeof(string), typeof(string), typeof(bool), typeof(string),typeof(bool));
|
||||
tvKeyValue.AppendColumn("Key",new CellRendererText(),"text",0);
|
||||
tvKeyValue.AppendColumn("Value",cellEditable,"text",2);
|
||||
tvKeyValue.AppendColumn("Password", cellToggle, "active", 5);
|
||||
tvKeyValue.AppendColumn("Linked", new CellRendererText(), "text", 4);
|
||||
|
||||
entrySecretID.MaxLength=1028;
|
||||
entrySecretID.Text=selected;
|
||||
|
||||
|
||||
for( int i=0; i< keys.Length; i++ )
|
||||
{
|
||||
if( (null != keys[i]) && (null != values[i]) )
|
||||
tsKeyValue.AppendValues(keys[i], values[i], "********", false, "No");
|
||||
tsKeyValue.AppendValues(keys[i], values[i], "********", false, "No", ispassword[i]);
|
||||
}
|
||||
tvKeyValue.Model = tsKeyValue;
|
||||
//entryKey.HasFocus = true;
|
||||
entryKey.Sensitive = entryValue.Sensitive = buttonNewAdd.Sensitive = buttonNewRemove.Sensitive = false;
|
||||
}
|
||||
}
|
||||
catch(Exception exp)
|
||||
@ -284,6 +308,46 @@ public class Firefox : Store
|
||||
Logger.DbgLog("GUI:Firefox.ViewKeyValues() - END");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TOGGLE ISPASSWORD
|
||||
///</summary>
|
||||
public void OnIsPasswordToggled(object obj, ToggledArgs args)
|
||||
{
|
||||
Logger.DbgLog("GUI:Firefox.OnIsPasswordToggled() - BEGIN");
|
||||
|
||||
TreeIter iter;
|
||||
bool old;
|
||||
string keyID;
|
||||
|
||||
try
|
||||
{
|
||||
if (tsKeyValue.GetIter (out iter, new TreePath(args.Path)))
|
||||
{
|
||||
isPasswordToggled = true;
|
||||
old = (bool)tsKeyValue.GetValue(iter,5);
|
||||
keyID = tsKeyValue.GetValue(iter,0).ToString();
|
||||
tsKeyValue.SetValue(iter, 5, !old);
|
||||
if (tsKeyValue.IterNChildren()==2)
|
||||
{
|
||||
tsKeyValue.GetIterFirst(out iter);
|
||||
do
|
||||
{
|
||||
if(!(tsKeyValue.GetValue(iter,0).ToString().Equals(keyID)))
|
||||
tsKeyValue.SetValue(iter, 5, old);
|
||||
}while (tsKeyValue.IterNext(ref iter));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch(Exception exp)
|
||||
{
|
||||
Logger.DbgLog("GUI:Firefox.OnIsPasswordToggled() - EXCEPTION:" + exp.ToString());
|
||||
}
|
||||
|
||||
Logger.DbgLog("GUI:Firefox.OnIsPasswordToggled() - END");
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EDIT KEY-VALUE
|
||||
/// </summary>
|
||||
@ -296,6 +360,7 @@ public class Firefox : Store
|
||||
object val;
|
||||
string KeyName = null,
|
||||
KeyValue = null;
|
||||
bool KeyIsPassword;
|
||||
string[] Keys = null,
|
||||
Values = null;
|
||||
|
||||
@ -309,6 +374,7 @@ public class Firefox : Store
|
||||
else
|
||||
val = tsKeyValue.GetValue(iter,2);
|
||||
KeyValue = val.ToString();
|
||||
KeyIsPassword = (bool)tsKeyValue.GetValue(iter,5);
|
||||
|
||||
tvSecretIDFirefox.Selection.GetSelected (out model, out iter);
|
||||
|
||||
@ -316,6 +382,21 @@ public class Firefox : Store
|
||||
{
|
||||
if( ("" != args.NewText) && (Common.MAX_LEN >= args.NewText.Length) && (KeyValue != args.NewText) )
|
||||
{
|
||||
//check for duplicate secret name
|
||||
if (KeyIsPassword == false && entrySecretID.Text.EndsWith(")") == true)
|
||||
{
|
||||
string sname = entrySecretID.Text;
|
||||
sname = sname.Remove ((sname.LastIndexOf(" (") + 2),sname.Length - (sname.LastIndexOf(" (") +2));
|
||||
sname = String.Concat ( sname, args.NewText, ")");
|
||||
if (sname != entrySecretID.Text && checkDuplicateSecretName(sname, null, ref tsSecretIDFirefox, 1))
|
||||
{
|
||||
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "dialogInvalidSecret", null);
|
||||
gxmlTemp.Autoconnect (this);
|
||||
dialogInvalidSecret.Show();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
if( Common.STATUS_SUCCESS == StoreDataInterface.UpdateStore(Common.STORE_FIREFOX, Common.OPERATION_MODIFY_KEY, KeyName, args.NewText, ref model, ref iter) )
|
||||
{
|
||||
Logger.DbgLog("GUI:Firefox.OnKeyValueEdited() - StoreDataInterface.UpdateStore() succeeded");
|
||||
@ -362,25 +443,282 @@ public class Firefox : Store
|
||||
/// </summary>
|
||||
public void on_buttonNewAdd_clicked(object obj, EventArgs args)
|
||||
{
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonNewAdd_clicked() - BEGIN");
|
||||
|
||||
if( ("" != entryKey.Text) && ("" != entryValue.Text) )
|
||||
{
|
||||
TreeIter iterKey;
|
||||
ArrayList arrKeys = null,
|
||||
arrValues = null,
|
||||
arrIsPassword = null;
|
||||
object val = null;
|
||||
arrKeys = new ArrayList();
|
||||
arrValues = new ArrayList();
|
||||
arrIsPassword = new ArrayList();
|
||||
bool ispass = false;
|
||||
|
||||
if (tvKeyValue.Model.IterNChildren() == 2)
|
||||
{
|
||||
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "dialogInvalidSecret", null);
|
||||
gxmlTemp.Autoconnect (this);
|
||||
dialogInvalidSecret.Show();
|
||||
return;
|
||||
}
|
||||
|
||||
if(tsKeyValue.GetIterFirst(out iterKey))
|
||||
{
|
||||
do
|
||||
{
|
||||
val = tsKeyValue.GetValue(iterKey,0);
|
||||
arrKeys.Add(val.ToString());
|
||||
val = tsKeyValue.GetValue(iterKey,1);
|
||||
arrValues.Add(val.ToString());
|
||||
ispass = (bool)tsKeyValue.GetValue(iterKey,5);
|
||||
if (ispass)
|
||||
{
|
||||
ispass = false;
|
||||
arrIsPassword.Add(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
ispass = true;
|
||||
arrIsPassword.Add(false);
|
||||
}
|
||||
}
|
||||
while( tsKeyValue.IterNext(ref iterKey) );
|
||||
}
|
||||
if( -1 == arrKeys.IndexOf(entryKey.Text) )
|
||||
if( true == Common.ValidateString(entryKey.Text) )
|
||||
{
|
||||
iterKey = tsKeyValue.AppendValues(entryKey.Text, entryValue.Text, "********", true, "No",ispass);
|
||||
entryKey.Text = entryValue.Text = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "dialogSpecialCharacter", null);
|
||||
gxmlTemp.Autoconnect (this);
|
||||
//dialogSpecialCharacter.TransientFor = (Gtk.Window)CasaMain.gxmlMain.GetWidget("dialogNewSecret");
|
||||
}
|
||||
//tvKeyValue.Selection.SelectIter(iterKey);
|
||||
entryKey.HasFocus = true;
|
||||
}
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonNewAdd_clicked() - END");
|
||||
|
||||
}
|
||||
|
||||
public void on_buttonSCClose_clicked(object obj, EventArgs args)
|
||||
{
|
||||
dialogSpecialCharacter.Destroy();
|
||||
}
|
||||
|
||||
public void on_buttonISClose_clicked(object obj, EventArgs args)
|
||||
{
|
||||
dialogInvalidSecret.Destroy();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// REMOVE BUTTON CLICKED
|
||||
/// </summary>
|
||||
public void on_buttonNewRemove_clicked(object obj, EventArgs args)
|
||||
{
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonNewRemove_clicked() - BEGIN");
|
||||
|
||||
TreeModel modelKey;
|
||||
TreeIter iterKey;
|
||||
|
||||
if(tvKeyValue.Selection.GetSelected (out modelKey, out iterKey)){
|
||||
if( false == (bool)tsKeyValue.GetValue(iterKey,3) )
|
||||
arrDeletedKeys.Add(tsKeyValue.GetValue(iterKey,0));
|
||||
}
|
||||
|
||||
if( 0 != tvKeyValue.Selection.CountSelectedRows() )
|
||||
{
|
||||
TreeModel model;
|
||||
TreeIter iter;
|
||||
|
||||
tvKeyValue.Selection.GetSelected (out model, out iter);
|
||||
tsKeyValue.Remove(ref iter);
|
||||
tvKeyValue.ColumnsAutosize();
|
||||
}
|
||||
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonNewRemove_clicked() - END");
|
||||
}
|
||||
|
||||
public bool checkDuplicateSecretName(String secretID, String uname, ref TreeStore model, int method)
|
||||
{
|
||||
TreeIter iter;
|
||||
switch(method)
|
||||
{
|
||||
case 1:
|
||||
if(model.GetIterFirst(out iter))
|
||||
{
|
||||
do
|
||||
{
|
||||
if(String.Compare((string)model.GetValue(iter,0),secretID,true) == 0)
|
||||
return true;
|
||||
}while(model.IterNext(ref iter));
|
||||
}
|
||||
return false;
|
||||
case 2:
|
||||
if(model.GetIterFirst(out iter))
|
||||
{
|
||||
secretID = String.Concat(secretID, " (");
|
||||
do
|
||||
{
|
||||
if(((string)model.GetValue(iter,0)).StartsWith(secretID))
|
||||
return true;
|
||||
}while(model.IterNext(ref iter));
|
||||
}
|
||||
return false;
|
||||
case 3:
|
||||
bool[] ispassarr;
|
||||
string[] valarr;
|
||||
if(model.GetIterFirst(out iter))
|
||||
{
|
||||
do
|
||||
{
|
||||
if(String.Compare((string)model.GetValue(iter,0),secretID,true) == 0)
|
||||
{
|
||||
ispassarr = (bool[])model.GetValue(iter, 6);
|
||||
valarr = (string[])model.GetValue(iter, 2);
|
||||
for(int i=0;i<ispassarr.Length;i++)
|
||||
{
|
||||
if(!ispassarr[i])
|
||||
{
|
||||
if(String.Compare(valarr[i],uname,true) == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}while(model.IterNext(ref iter));
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// MANAGE SECRET ID DIALOG OK-BUTTON CLICKED
|
||||
/// </summary>
|
||||
public void on_buttonManageOk_clicked(object obj, EventArgs args)
|
||||
{
|
||||
TreeModel modelSecret;
|
||||
TreeIter iterSecret,
|
||||
iterKey;
|
||||
string NewKey = null,
|
||||
NewValue = null;
|
||||
bool NewIsPassword;
|
||||
string[] strDeletedKeys = null;
|
||||
bool dirtyBit = false;
|
||||
bool doCheck = false;
|
||||
//ArrayList arrKeys = null,
|
||||
// arrValues = null;
|
||||
String sname = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (tvKeyValue.Model.IterNChildren() == 1)
|
||||
{
|
||||
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "dialogInvalidSecret", null);
|
||||
gxmlTemp.Autoconnect (this);
|
||||
dialogInvalidSecret.Show();
|
||||
return;
|
||||
}
|
||||
|
||||
if( (0 == tvKeyValue.Model.IterNChildren()) && tvSecretIDFirefox.Selection.GetSelected (out modelSecret, out iterSecret) )
|
||||
{
|
||||
if( Common.STATUS_SUCCESS == StoreDataInterface.UpdateStore(Common.STORE_FIREFOX, Common.OPERATION_DELETE_SECRET, "", "", ref modelSecret, ref iterSecret) )
|
||||
{
|
||||
tsSecretIDFirefox.Remove(ref iterSecret);
|
||||
tvSecretIDFirefox.ColumnsAutosize();
|
||||
tsNativeInfoFirefox.Clear();
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonManageOk_clicked() - DELETE_SECRET_SUCCEEDED");
|
||||
}
|
||||
else
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonManageOk_clicked() - DELETE_SECRET_FAILED");
|
||||
AggregateStore();
|
||||
}
|
||||
else
|
||||
{
|
||||
//check for duplicate secret names before updating the store
|
||||
tvSecretIDFirefox.Selection.GetSelected (out modelSecret, out iterSecret);
|
||||
sname = (string)modelSecret.GetValue(iterSecret, 0);
|
||||
doCheck = sname.EndsWith(")");
|
||||
if( tsKeyValue.GetIterFirst(out iterKey) && doCheck == true)
|
||||
{
|
||||
do
|
||||
{
|
||||
NewValue = (string) tsKeyValue.GetValue(iterKey,1);
|
||||
NewIsPassword = (bool) tsKeyValue.GetValue(iterKey,5);
|
||||
dirtyBit = (bool) tsKeyValue.GetValue(iterKey,3);
|
||||
|
||||
if((true == dirtyBit && false == NewIsPassword) || ( false == NewIsPassword && true == isPasswordToggled))
|
||||
{
|
||||
sname = sname.Remove ((sname.LastIndexOf(" (") + 2),sname.Length - (sname.LastIndexOf(" (") +2));
|
||||
sname = String.Concat ( sname, NewValue, ")");
|
||||
if (sname != entrySecretID.Text && checkDuplicateSecretName(sname, null, ref tsSecretIDFirefox, 1))
|
||||
{
|
||||
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "dialogInvalidSecret", null);
|
||||
gxmlTemp.Autoconnect (this);
|
||||
dialogInvalidSecret.Show();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}while(tsKeyValue.IterNext(ref iterKey));
|
||||
}
|
||||
|
||||
if( (null != arrDeletedKeys) && (arrDeletedKeys.Count > 0) )
|
||||
{
|
||||
tvSecretIDFirefox.Selection.GetSelected (out modelSecret, out iterSecret);
|
||||
strDeletedKeys = (string[])arrDeletedKeys.ToArray(typeof(string));
|
||||
|
||||
for( int i=0; i < strDeletedKeys.Length; i++)
|
||||
{
|
||||
if( Common.STATUS_SUCCESS == StoreDataInterface.UpdateStore(Common.STORE_FIREFOX, Common.OPERATION_DELETE_KEY, strDeletedKeys[i], null, ref modelSecret, ref iterSecret) )
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonManageOk_clicked() - DELETE_KEY_SUCCEEDED.");
|
||||
else
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonManageOk_clicked() - DELETE_KEY_FAILED.");
|
||||
}
|
||||
arrDeletedKeys.Clear();
|
||||
}
|
||||
|
||||
if( tsKeyValue.GetIterFirst(out iterKey) && tvSecretIDFirefox.Selection.GetSelected (out modelSecret, out iterSecret) )
|
||||
{
|
||||
do
|
||||
{
|
||||
NewKey = (string) tsKeyValue.GetValue(iterKey,0);
|
||||
NewValue = (string) tsKeyValue.GetValue(iterKey,1);
|
||||
NewIsPassword = (bool) tsKeyValue.GetValue(iterKey,5);
|
||||
dirtyBit = (bool) tsKeyValue.GetValue(iterKey,3);
|
||||
|
||||
if( true == dirtyBit )
|
||||
{
|
||||
if( Common.STATUS_SUCCESS == StoreDataInterface.UpdateStore(Common.STORE_FIREFOX, Common.OPERATION_ADD_KEY, NewKey, NewValue, NewIsPassword, ref modelSecret, ref iterSecret) )
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonManageOk_clicked() - ADD_KEY_VALUE_SUCCEEDED.");
|
||||
else
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonManageOk_clicked() - ADD_KEY_VALUE_FAILED.");
|
||||
}
|
||||
else if(true == isPasswordToggled)
|
||||
{
|
||||
if( Common.STATUS_SUCCESS == StoreDataInterface.UpdateStore(Common.STORE_FIREFOX, Common.OPERATION_MODIFY_KEY, NewKey, NewValue, NewIsPassword, ref modelSecret, ref iterSecret))
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonManageOk_clicked() - SET_PASSWORD_STATE_SUCCEEDED.");
|
||||
else
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonManageOk_clicked() - SET_PASSWORD_STATE_FAILED.");
|
||||
}
|
||||
}
|
||||
while( tsKeyValue.IterNext(ref iterKey) );
|
||||
}
|
||||
AggregateStore();
|
||||
}
|
||||
}
|
||||
catch(Exception exp)
|
||||
{
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonManageOk_clicked() - EXCEPTION:" + exp.ToString());
|
||||
}
|
||||
tsKeyValue.Dispose();
|
||||
dialogManageSecret.Destroy();
|
||||
}
|
||||
@ -584,11 +922,155 @@ public class Firefox : Store
|
||||
ViewKeyValues();
|
||||
}
|
||||
|
||||
public void on_buttonNewOk_clicked(object obj, EventArgs args)
|
||||
{
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonNewOk_clicked() - BEGIN");
|
||||
|
||||
TreeModel modelSecret;
|
||||
TreeIter iterSecret,
|
||||
iterKey;
|
||||
string NewKey = null,
|
||||
NewValue = null;
|
||||
bool NewIsPassword;
|
||||
string[] Keys = null,
|
||||
Values = null,
|
||||
NativeKeys = null,
|
||||
NativeValues = null;
|
||||
bool[] IsPassword =null;
|
||||
object val = null;
|
||||
string sname = null;
|
||||
ArrayList arrKeys = null,
|
||||
arrValues = null,
|
||||
arrIsPassword = null;
|
||||
if (tvKeyValue.Model.IterNChildren() == 1)
|
||||
{
|
||||
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "dialogInvalidSecret", null);
|
||||
gxmlTemp.Autoconnect (this);
|
||||
dialogInvalidSecret.Show();
|
||||
return;
|
||||
}
|
||||
if ( true == entrySecretID.Editable && false == ValidateString(entrySecretID.Text) )
|
||||
{
|
||||
/*// prompt user
|
||||
MessageDialog md=new MessageDialog(this.windowMain,Gtk.DialogFlags.Modal,
|
||||
Gtk.MessageType.Warning,
|
||||
Gtk.ButtonsType.Ok,
|
||||
"Secret ID may not contain \"*\"");
|
||||
|
||||
md.Response += new ResponseHandler(md_Response);
|
||||
md.SetPosition(Gtk.WindowPosition.CenterOnParent);
|
||||
md.Modal = true;
|
||||
md.Show();*/
|
||||
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "dialogSpecialCharacter", null);
|
||||
gxmlTemp.Autoconnect (this);
|
||||
entrySecretID.HasFocus = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if( (true == entrySecretID.Editable) && ("" != entrySecretID.Text) && (tvKeyValue.Model.IterNChildren() > 0) )
|
||||
{
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonNewOk_clicked() - Adding New Secrets and KeyValues.");
|
||||
|
||||
arrKeys = new ArrayList();
|
||||
arrValues = new ArrayList();
|
||||
arrIsPassword = new ArrayList();
|
||||
try
|
||||
{
|
||||
if(tsKeyValue.GetIterFirst(out iterKey))
|
||||
{
|
||||
do
|
||||
{
|
||||
val = tsKeyValue.GetValue(iterKey,0);
|
||||
NewKey = val.ToString();
|
||||
val = tsKeyValue.GetValue(iterKey,1);
|
||||
NewValue = val.ToString();
|
||||
NewIsPassword = (bool)tsKeyValue.GetValue(iterKey,5);
|
||||
if( -1 == (arrKeys.IndexOf(NewKey)) )
|
||||
{
|
||||
arrKeys.Add(NewKey);
|
||||
arrValues.Add(NewValue);
|
||||
arrIsPassword.Add(NewIsPassword);
|
||||
}
|
||||
if(NewIsPassword == false)
|
||||
{
|
||||
sname = entrySecretID.Text;
|
||||
if (checkDuplicateSecretName(entrySecretID.Text, null, ref tsSecretIDFirefox, 1))
|
||||
{
|
||||
if (checkDuplicateSecretName(entrySecretID.Text, NewValue, ref tsSecretIDFirefox, 3))
|
||||
{
|
||||
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "dialogInvalidSecret", null);
|
||||
gxmlTemp.Autoconnect (this);
|
||||
dialogInvalidSecret.Show();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
else if(checkDuplicateSecretName(entrySecretID.Text, null, ref tsSecretIDFirefox, 2))
|
||||
{
|
||||
sname = String.Concat ( sname, " (", NewValue, ")");
|
||||
|
||||
if (checkDuplicateSecretName(sname, null, ref tsSecretIDFirefox, 1))
|
||||
{
|
||||
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "dialogInvalidSecret", null);
|
||||
gxmlTemp.Autoconnect (this);
|
||||
dialogInvalidSecret.Show();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while( tsKeyValue.IterNext(ref iterKey) );
|
||||
|
||||
Keys = (string[])arrKeys.ToArray(typeof(string));
|
||||
Values = (string[])arrValues.ToArray(typeof(string));
|
||||
IsPassword = (bool[])arrIsPassword.ToArray(typeof(bool));
|
||||
|
||||
NativeKeys = new string[Common.MAX_NATIVE_ELEMENTS];
|
||||
NativeValues = new string[Common.MAX_NATIVE_ELEMENTS];
|
||||
NativeKeys[Common.INDEX_NATIVEINFO_FOLDERNAME] = Common.NATIVEINFO_FOLDERNAME;
|
||||
NativeKeys[Common.INDEX_NATIVEINFO_TYPEID] = Common.NATIVEINFO_TYPEID;
|
||||
NativeKeys[Common.INDEX_NATIVEINFO_SYNC] = Common.NATIVEINFO_SYNC;
|
||||
NativeKeys[Common.INDEX_NATIVEINFO_SYNCTYPE] = Common.NATIVEINFO_SYNCTYPE;
|
||||
NativeKeys[Common.INDEX_NATIVEINFO_MODIFIEDTIME] = Common.NATIVEINFO_MODIFIEDTIME;
|
||||
NativeValues[Common.INDEX_NATIVEINFO_FOLDERNAME] = null;
|
||||
NativeValues[Common.INDEX_NATIVEINFO_TYPEID] = "Signon";
|
||||
NativeValues[Common.INDEX_NATIVEINFO_SYNC] = null;
|
||||
NativeValues[Common.INDEX_NATIVEINFO_SYNCTYPE] = null;
|
||||
NativeValues[Common.INDEX_NATIVEINFO_MODIFIEDTIME] = null;
|
||||
iterSecret = tsSecretIDFirefox.AppendValues(sname, Keys, Values, DataEngines.AD.GetDefaultProfileName(Common.STORE_FIREFOX), NativeKeys, NativeValues, IsPassword);
|
||||
modelSecret = tvSecretIDFirefox.Model;
|
||||
|
||||
if( Common.STATUS_SUCCESS == StoreDataInterface.UpdateStore(Common.STORE_FIREFOX, Common.OPERATION_ADD_SECRET, "", "", ref modelSecret, ref iterSecret) )
|
||||
{
|
||||
AggregateStore();
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonNewOk_clicked() - ADD_NEW_SECRET_SUCCEEDED.");
|
||||
}
|
||||
else
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonNewOk_clicked() - ERROR: ADD_NEW_SECRET_FAILED");
|
||||
}
|
||||
}
|
||||
catch(Exception exp)
|
||||
{
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonNewOk_clicked() - EXCEPTION:" + exp.ToString());
|
||||
}
|
||||
tsKeyValue.Dispose();
|
||||
dialogNewSecret.Destroy();
|
||||
}
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonNewOk_clicked() - END");
|
||||
}
|
||||
|
||||
public void on_buttonNewCancel_clicked(object obj, EventArgs args)
|
||||
{
|
||||
dialogNewSecret.Destroy();
|
||||
}
|
||||
|
||||
public void on_helpbuttonNewSecret_clicked(object obj, EventArgs args)
|
||||
{
|
||||
Common.ShowHelpUrl("AddNewSecrets.htm");
|
||||
}
|
||||
|
||||
///#######################################################################
|
||||
/// ADD NEW SECRET
|
||||
/// <summary>
|
||||
@ -596,6 +1078,33 @@ public class Firefox : Store
|
||||
/// </summary>
|
||||
public void OnNewSecretActivated(object obj, EventArgs args)
|
||||
{
|
||||
Logger.DbgLog("GUI:Firefox.OnNewSecretActivated() - BEGIN");
|
||||
|
||||
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "dialogNewSecret", null);
|
||||
gxmlTemp.Autoconnect (this);
|
||||
dialogNewSecret.TransientFor = (Gtk.Window)CasaMain.gxmlMain.GetWidget("windowMain");
|
||||
dialogNewSecret.Title = "Firefox - New Secret";
|
||||
|
||||
cellEditable = new CellRendererText();
|
||||
cellEditable.Editable = true;
|
||||
cellEditable.Edited += new EditedHandler(OnKeyValueEdited);
|
||||
|
||||
cellToggle = new CellRendererToggle();
|
||||
cellToggle.Activatable = true;
|
||||
cellToggle.Toggled += OnIsPasswordToggled;
|
||||
|
||||
/// KEY:0 VALUE:1 VALUE-DUP:2 DIRTY-BIT:3 LINK:4 ISPASSWORD:5
|
||||
tsKeyValue = new TreeStore(typeof(string),typeof(string), typeof(string), typeof(bool), typeof(string),typeof(bool));
|
||||
tvKeyValue.AppendColumn("Key",new CellRendererText(),"text",0);
|
||||
tvKeyValue.AppendColumn("Value",cellEditable,"text",2);
|
||||
tvKeyValue.AppendColumn("Password", cellToggle,"active",5);
|
||||
tvKeyValue.AppendColumn("Linked",new CellRendererText(),"text",4);
|
||||
tvKeyValue.Model = tsKeyValue;
|
||||
tsKeyValue.Clear();
|
||||
entrySecretID.HasFocus = true;
|
||||
entrySecretID.Text = "";
|
||||
|
||||
Logger.DbgLog("GUI:Firefox.OnNewSecretActivated() - END");
|
||||
}
|
||||
|
||||
///#######################################################################
|
||||
@ -604,7 +1113,12 @@ public class Firefox : Store
|
||||
///
|
||||
/// </summary>
|
||||
public void OnNewKeyActivated(object obj, EventArgs args)
|
||||
{
|
||||
{
|
||||
Logger.DbgLog("GUI:Firefox.OnNewKeyActivated() - BEGIN");
|
||||
|
||||
ViewKeyValues();
|
||||
|
||||
Logger.DbgLog("GUI:Firefox.OnNewKeyActivated() - END");
|
||||
}
|
||||
|
||||
///#######################################################################
|
||||
@ -652,6 +1166,7 @@ public class Firefox : Store
|
||||
tvSecretIDFirefox.ColumnsAutosize();
|
||||
tsNativeInfoFirefox.Clear();
|
||||
dialogConfirmDelete.Destroy();
|
||||
AggregateStore();
|
||||
Logger.DbgLog("GUI:Firefox.on_buttonYes_clicked() - DELETE_SECRET_SUCCEEDED");
|
||||
|
||||
}
|
||||
@ -691,7 +1206,20 @@ public class Firefox : Store
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
///#######################################################################
|
||||
/// VALIDATE STRINGS FOR SPECIAL CHARACTERS
|
||||
|
||||
/// <summary>
|
||||
/// Validate strings for special characters
|
||||
/// </summary>
|
||||
public static bool ValidateString(string sString)
|
||||
{
|
||||
if( -1 == sString.IndexOfAny(SpecialCharacters) )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
///##################################################################
|
||||
|
@ -53,6 +53,8 @@ namespace Novell.CASA.GUI {
|
||||
CCFXML_ELEMENT_TIME_ZONE = "Zone",
|
||||
CCFXML_ELEMENT_TIME_CREATION = "Creation",
|
||||
CCFXML_ELEMENT_TIME_MODIFIED = "Modified",
|
||||
CCFXML_ATTRIBUTE_PASSWDSTATUS = "PasswordStatus",
|
||||
CCFXML_ATTRIBUTE_FFOX_TYPE = "Signon",
|
||||
CCFXML_ELEMENT_TIME_ACCESSED = "Accessed",
|
||||
CCFXML_ATTRIBUTE_ID = "ID",
|
||||
CCFXML_ATTRIBUTE_MICASA_SYNCH = "Synch",
|
||||
@ -171,6 +173,7 @@ namespace Novell.CASA.GUI {
|
||||
string secretID = null;
|
||||
string[] strKeyArray = null;
|
||||
string[] strValueArray = null;
|
||||
bool[] boolIsPassArray = null;
|
||||
string storeID = null;
|
||||
string[] strNativeKeyArray = new string[Common.MAX_NATIVE_ELEMENTS];
|
||||
string[] strNativeValueArray = new string[Common.MAX_NATIVE_ELEMENTS];
|
||||
@ -303,6 +306,7 @@ namespace Novell.CASA.GUI {
|
||||
//Reinit arrays to the no of keys for this secret
|
||||
strKeyArray = new string[noOfKeys];
|
||||
strValueArray = new string[noOfKeys];
|
||||
boolIsPassArray = new bool[noOfKeys];
|
||||
|
||||
//Get Last Modified Time for the secret
|
||||
ccfExtPath = CCFXML_ELEMENT_TIME + "/" + CCFXML_ELEMENT_TIME_MODIFIED;
|
||||
@ -334,6 +338,14 @@ namespace Novell.CASA.GUI {
|
||||
bKey = true;
|
||||
strKeyArray[noOfKeysFound] = iterSecret.Current.Value; //KeyName
|
||||
}
|
||||
if( (iterSecret.Current.LocalName.Equals(CCFXML_ATTRIBUTE_PASSWDSTATUS )) && (noOfKeysFound<=noOfKeys) )
|
||||
{
|
||||
if(iterSecret.Current.Value.Equals("1"))
|
||||
boolIsPassArray[noOfKeysFound] = true; //KeyName
|
||||
else
|
||||
boolIsPassArray[noOfKeysFound] = false; //KeyName
|
||||
}
|
||||
|
||||
}while( iterSecret.Current.MoveToNextAttribute() );
|
||||
iterSecret.Current.MoveToParent();
|
||||
|
||||
@ -391,8 +403,10 @@ namespace Novell.CASA.GUI {
|
||||
strNativeValueArray[Common.INDEX_NATIVEINFO_SYNCTYPE] = synchType;
|
||||
strNativeValueArray[Common.INDEX_NATIVEINFO_MODIFIEDTIME] = modifiedTime;
|
||||
//Console.WriteLine("folderName="+folderName+"\n"+"typeID="+typeID+"\n"+"synch="+synch+"\n"+"synchType="+synchType+"\n"+"modifiedTime="+modifiedTime);
|
||||
|
||||
ls.AppendValues(secretID,strKeyArray,strValueArray,storeID,strNativeKeyArray,strNativeValueArray);
|
||||
if ( storeIDentifier == Common.STORE_FIREFOX)
|
||||
ls.AppendValues(secretID,strKeyArray,strValueArray,storeID,strNativeKeyArray,strNativeValueArray,boolIsPassArray);
|
||||
else
|
||||
ls.AppendValues(secretID,strKeyArray,strValueArray,storeID,strNativeKeyArray,strNativeValueArray);
|
||||
|
||||
//Re-Initialize for next iteration
|
||||
secretID = "";
|
||||
@ -415,7 +429,106 @@ namespace Novell.CASA.GUI {
|
||||
return( Common.STATUS_SUCCESS );
|
||||
}
|
||||
|
||||
///#######################################################################
|
||||
/// UPDATE STORE: ADD NEW secret/keyvalue, MODIFY keyvalue, DELETE secret
|
||||
|
||||
/// <summary>
|
||||
/// Supported Update Functionalities - on miCASA Store only
|
||||
/// </summary>
|
||||
public static int UpdateStore(int storeIDentifier,int operation,string keyID,string valueToBeModfied,bool isPassword,ref TreeModel model,ref TreeIter iter)
|
||||
{
|
||||
Logger.DbgLog("GUI:StoreDataInterface.UpdateStore()");
|
||||
|
||||
//TreeStore row elements
|
||||
string SecretID = null;
|
||||
string keyChainID = null;
|
||||
|
||||
//XPATH query strings
|
||||
string ccfKeyChainPath = null;
|
||||
string ccfSecretPath = null;
|
||||
string ccfKeyPath = null;
|
||||
|
||||
//Reading and Initialzing from the passed iter object
|
||||
SecretID = (string) model.GetValue (iter, 0);
|
||||
keyChainID = (string) model.GetValue (iter, 3);
|
||||
|
||||
if (storeIDentifier != Common.STORE_FIREFOX && (operation != Common.OPERATION_ADD_KEY || operation!=Common.OPERATION_MODIFY_KEY || operation!=Common.OPERATION_MODIFY_SECRET))
|
||||
return Common.STATUS_FAILURE;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if( Common.OPERATION_ADD_KEY == operation )
|
||||
{
|
||||
ccfKeyChainPath = "//CCF/FireFox/Profile[@ID='" + keyChainID + "']/Secret[@ID='" + SecretID + "']";
|
||||
ccfSecretPath = "";
|
||||
|
||||
//Create the Key element
|
||||
XmlElement newKeyElement = ccfDoc.CreateElement(CCFXML_ELEMENT_KEY);
|
||||
newKeyElement.SetAttribute(CCFXML_ATTRIBUTE_ID,keyID);
|
||||
if(isPassword)
|
||||
newKeyElement.SetAttribute(CCFXML_ATTRIBUTE_PASSWDSTATUS,"1");
|
||||
else
|
||||
newKeyElement.SetAttribute(CCFXML_ATTRIBUTE_PASSWDSTATUS,"0");
|
||||
|
||||
XmlElement newValue = ccfDoc.CreateElement(CCFXML_ELEMENT_VALUE);
|
||||
newValue.InnerText = valueToBeModfied;
|
||||
newKeyElement.AppendChild(newValue);
|
||||
|
||||
XmlNode root = ccfDoc.DocumentElement;
|
||||
XmlNodeList keyNodeList = root.SelectNodes(ccfKeyChainPath);
|
||||
XmlNode keyNode=keyNodeList.Item(0);
|
||||
XmlNode lastChild = keyNode.LastChild;
|
||||
|
||||
if(isPassword)
|
||||
keyNode.InsertAfter(newKeyElement,lastChild);
|
||||
else
|
||||
keyNode.InsertBefore(newKeyElement,lastChild);
|
||||
|
||||
ad.SetSecret(keyNode,Common.OPERATION_MODIFY_KEY,storeIDentifier);
|
||||
}
|
||||
else if(Common.OPERATION_MODIFY_KEY == operation)
|
||||
{
|
||||
ccfKeyPath = "//CCF/FireFox/Profile[@ID='" + keyChainID + "']/Secret[@ID='" + SecretID + "']/Key[@ID='" + keyID + "']";
|
||||
ccfSecretPath = "//CCF/FireFox/Profile[@ID='" + keyChainID + "']/Secret[@ID='" + SecretID + "']";
|
||||
|
||||
XmlElement newKeyElement = ccfDoc.CreateElement(CCFXML_ELEMENT_KEY);
|
||||
newKeyElement.SetAttribute(CCFXML_ATTRIBUTE_ID,keyID);
|
||||
if(isPassword)
|
||||
newKeyElement.SetAttribute(CCFXML_ATTRIBUTE_PASSWDSTATUS,"1");
|
||||
else
|
||||
newKeyElement.SetAttribute(CCFXML_ATTRIBUTE_PASSWDSTATUS,"0");
|
||||
XmlElement newValue = ccfDoc.CreateElement(CCFXML_ELEMENT_VALUE);
|
||||
newValue.InnerText = valueToBeModfied;
|
||||
newKeyElement.AppendChild(newValue);
|
||||
|
||||
XmlNode root = ccfDoc.DocumentElement;
|
||||
XmlNode secretNode = root.SelectSingleNode(ccfSecretPath);
|
||||
XmlNode keyNode = root.SelectSingleNode(ccfKeyPath);
|
||||
|
||||
if(keyNode!=null)
|
||||
secretNode.RemoveChild(keyNode);
|
||||
|
||||
if (isPassword)
|
||||
secretNode.InsertAfter(newKeyElement,secretNode.LastChild);
|
||||
else
|
||||
secretNode.InsertBefore(newKeyElement,secretNode.LastChild);
|
||||
|
||||
ad.SetSecret(secretNode,Common.OPERATION_MODIFY_KEY,storeIDentifier);
|
||||
}
|
||||
}
|
||||
catch(Exception exp)
|
||||
{
|
||||
//Console.WriteLine("Exception"+exp.ToString());//FIXME:Remove this line
|
||||
Logger.DbgLog("GUI:StoreDataInterface.UpdateStore() - EXCEPTION" + exp.ToString());
|
||||
return( Common.STATUS_STORE_UPDATEFAILED );
|
||||
}
|
||||
|
||||
return( Common.STATUS_SUCCESS );
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
///#######################################################################
|
||||
/// UPDATE STORE: ADD NEW secret/keyvalue, MODIFY keyvalue, DELETE secret
|
||||
@ -433,6 +546,7 @@ namespace Novell.CASA.GUI {
|
||||
string keyChainID = null;
|
||||
string[] strKeyArray = new string[Common.MAX_ARRAY_ELEMENTS];
|
||||
string[] strValueArray = new string[Common.MAX_ARRAY_ELEMENTS];
|
||||
bool[] boolIsPassArray = new bool[Common.MAX_ARRAY_ELEMENTS];
|
||||
string[] strNativeValueArray = new string[Common.MAX_NATIVE_ELEMENTS];
|
||||
|
||||
//XPATH query strings
|
||||
@ -452,6 +566,8 @@ namespace Novell.CASA.GUI {
|
||||
strValueArray = (string[]) model.GetValue (iter, 2);
|
||||
keyChainID = (string) model.GetValue (iter, 3);
|
||||
strNativeValueArray = (string[]) model.GetValue (iter, 5);
|
||||
if (storeIDentifier == Common.STORE_FIREFOX)
|
||||
boolIsPassArray = (bool[]) model.GetValue (iter, 6);
|
||||
|
||||
|
||||
try
|
||||
@ -656,6 +772,43 @@ namespace Novell.CASA.GUI {
|
||||
//Console.WriteLine("OPERATION_DELETE_SECRET:ccfKeyChainPath:"+ccfKeyChainPath);//FIXME:Remove this line
|
||||
//Console.WriteLine("OPERATION_DELETE_SECRET:ccfSecretPath:"+ccfSecretPath);//FIXME:Remove this line
|
||||
}
|
||||
else if( Common.OPERATION_ADD_SECRET == operation )
|
||||
{
|
||||
XmlElement newUser, newPass;
|
||||
//keyChainID = ad.GetDefaultProfileName(Common.STORE_FIREFOX);
|
||||
ccfKeyChainPath = "//CCF/FireFox/Profile[@ID='" + keyChainID + "']";
|
||||
ccfSecretPath = "//CCF/FireFox/Profile[@ID='" + keyChainID + "']/Secret[@ID='" + SecretID + "']";
|
||||
newSecretElement = ccfDoc.CreateElement(CCFXML_ELEMENT_SECRET);
|
||||
newSecretElement.SetAttribute(CCFXML_ATTRIBUTE_ID,SecretID);
|
||||
newSecretElement.SetAttribute(CCFXML_ELEMENT_TYPE,CCFXML_ATTRIBUTE_FFOX_TYPE);
|
||||
newUser = ccfDoc.CreateElement(CCFXML_ELEMENT_KEY);
|
||||
newPass = ccfDoc.CreateElement(CCFXML_ELEMENT_KEY);
|
||||
|
||||
for( int i=0; i< strKeyArray.Length; i++)
|
||||
{
|
||||
if(boolIsPassArray[i])
|
||||
{
|
||||
newPass.SetAttribute(CCFXML_ATTRIBUTE_ID,strKeyArray[i]);
|
||||
XmlElement newValue = ccfDoc.CreateElement(CCFXML_ELEMENT_VALUE);
|
||||
newValue.InnerText = strValueArray[i];
|
||||
newPass.AppendChild(newValue);
|
||||
newPass.SetAttribute(CCFXML_ATTRIBUTE_PASSWDSTATUS,"1");
|
||||
}
|
||||
else
|
||||
{
|
||||
newUser.SetAttribute(CCFXML_ATTRIBUTE_ID,strKeyArray[i]);
|
||||
XmlElement newValue = ccfDoc.CreateElement(CCFXML_ELEMENT_VALUE);
|
||||
newValue.InnerText = strValueArray[i];
|
||||
newUser.AppendChild(newValue);
|
||||
newUser.SetAttribute(CCFXML_ATTRIBUTE_PASSWDSTATUS,"0");
|
||||
}
|
||||
}
|
||||
newSecretElement.AppendChild(newUser);
|
||||
newSecretElement.AppendChild(newPass);
|
||||
newKeychainElement = ccfDoc.CreateElement(storeChainKey);
|
||||
newKeychainElement.SetAttribute(CCFXML_ATTRIBUTE_ID,keyChainID);
|
||||
newKeychainElement.AppendChild(newSecretElement);
|
||||
}
|
||||
}
|
||||
else
|
||||
return( Common.STATUS_STORE_UNSUPPORTEDOPERATION );
|
||||
@ -670,7 +823,7 @@ namespace Novell.CASA.GUI {
|
||||
XmlNodeList keylist = root.SelectNodes(ccfSecretPath);
|
||||
foreach ( XmlNode key in keylist )
|
||||
{
|
||||
key.ChildNodes[0].InnerText=valueToBeModfied ;
|
||||
key.ChildNodes[0].InnerText=valueToBeModfied ;
|
||||
//Console.WriteLine("EXECUTING OPERATION_MODIFY_KEY:Modifying"+ccfSecretPath);//FIXME:Remove this line
|
||||
ad.SetSecret(key.ParentNode,operation,storeIDentifier);
|
||||
}
|
||||
@ -710,7 +863,7 @@ namespace Novell.CASA.GUI {
|
||||
{
|
||||
//ShowDocOnConsole("BEFORE CALL TO SETSECRET");//FIXME:Remove this
|
||||
|
||||
if(( Common.STORE_MICASA == storeIDentifier )||( Common.STORE_GNOMEKEYRING == storeIDentifier ))
|
||||
if(( Common.STORE_MICASA == storeIDentifier )||( Common.STORE_GNOMEKEYRING == storeIDentifier ) || (Common.STORE_FIREFOX == storeIDentifier ))
|
||||
{
|
||||
//Add a new secret to the keychain
|
||||
XmlNode root = ccfDoc.DocumentElement;
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user