зеркало из https://github.com/mozilla/gecko-dev.git
getting ready to support encrytion, r=jar
This commit is contained in:
Родитель
f4077f3663
Коммит
951d85c300
|
@ -56,11 +56,15 @@ interface nsIWalletService : nsISupports {
|
|||
void WALLET_FetchFromNetCenter();
|
||||
|
||||
boolean PromptUsernameAndPasswordURL(in wstring text, out wstring user, out wstring pwd, in string urlname, in nsIPrompt dialog);
|
||||
|
||||
boolean PromptPasswordURL(in wstring text, out wstring pwd, in string urlname, in nsIPrompt dialog);
|
||||
boolean PromptURL(in wstring text, in wstring defaultText, out wstring result, in string urlname, in nsIPrompt dialog);
|
||||
void SI_RemoveUser(in string URLName, in wstring userName);
|
||||
|
||||
boolean PromptUsernameAndPasswordURLNostrip(in wstring text, out wstring user, out wstring pwd, in string urlname, in nsIPrompt dialog);
|
||||
boolean PromptPasswordURLNostrip(in wstring text, out wstring pwd, in string urlname, in nsIPrompt dialog);
|
||||
boolean PromptURLNostrip(in wstring text, in wstring defaultText, out wstring result, in string urlname, in nsIPrompt dialog);
|
||||
void SI_RemoveUserNostrip(in string URLName, in wstring userName);
|
||||
|
||||
[noscript] void WALLET_GetNopreviewListForViewer(in nsAutoStringRef aNopreviewList);
|
||||
[noscript] void WALLET_GetNocaptureListForViewer(in nsAutoStringRef aNocaptureList);
|
||||
[noscript] void WALLET_GetPrefillListForViewer(in nsAutoStringRef aPrefillList);
|
||||
|
|
|
@ -130,6 +130,30 @@ NS_IMETHODIMP nsWalletlibService::SI_RemoveUser(const char *URLName, const PRUni
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWalletlibService::PromptUsernameAndPasswordURLNostrip
|
||||
(const PRUnichar *text, PRUnichar **user, PRUnichar **pwd,
|
||||
const char *urlname, nsIPrompt* dialog, PRBool *returnValue) {
|
||||
return ::SINGSIGN_PromptUsernameAndPassword
|
||||
(text, user, pwd, urlname, dialog, returnValue, PR_FALSE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWalletlibService::PromptPasswordURLNostrip
|
||||
(const PRUnichar *text, PRUnichar **pwd, const char *urlname,
|
||||
nsIPrompt* dialog, PRBool *returnValue) {
|
||||
return ::SINGSIGN_PromptPassword(text, pwd, urlname, dialog, returnValue, PR_FALSE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWalletlibService::PromptURLNostrip
|
||||
(const PRUnichar *text, const PRUnichar *defaultText, PRUnichar **resultText,
|
||||
const char *urlname, nsIPrompt* dialog, PRBool *returnValue) {
|
||||
return ::SINGSIGN_Prompt
|
||||
(text, defaultText, resultText, urlname, dialog, returnValue, PR_FALSE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWalletlibService::SI_RemoveUserNostrip(const char *URLName, const PRUnichar *userName) {
|
||||
::SINGSIGN_RemoveUser(URLName, userName, PR_FALSE);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWalletlibService::WALLET_GetNopreviewListForViewer(nsAutoString& aNopreviewList){
|
||||
::WLLT_GetNopreviewListForViewer(aNopreviewList);
|
||||
|
|
|
@ -60,6 +60,17 @@ public:
|
|||
|
||||
NS_IMETHOD SI_RemoveUser(const char *URLName, const PRUnichar *userName);
|
||||
|
||||
NS_IMETHOD PromptUsernameAndPasswordURLNostrip
|
||||
(const PRUnichar *text, PRUnichar **user, PRUnichar **pwd,
|
||||
const char *urlname, nsIPrompt* dialog, PRBool *_retval);
|
||||
NS_IMETHOD PromptPasswordURLNostrip
|
||||
(const PRUnichar *text, PRUnichar **pwd, const char *urlname, nsIPrompt* dialog, PRBool *_retval);
|
||||
NS_IMETHOD PromptURLNostrip
|
||||
(const PRUnichar *text, const PRUnichar *defaultText, PRUnichar **result,
|
||||
const char *urlname, nsIPrompt* dialog, PRBool *_retval);
|
||||
|
||||
NS_IMETHOD SI_RemoveUserNostrip(const char *URLName, const PRUnichar *userName);
|
||||
|
||||
|
||||
NS_IMETHOD WALLET_GetNopreviewListForViewer(nsAutoString& aNopreviewList);
|
||||
NS_IMETHOD WALLET_GetNocaptureListForViewer(nsAutoString& aNocaptureList);
|
||||
|
|
|
@ -245,8 +245,7 @@ si_CheckGetUsernamePassword
|
|||
* Key Management *
|
||||
******************/
|
||||
|
||||
extern void Wallet_RestartKey();
|
||||
extern PRUnichar Wallet_GetKey();
|
||||
extern PRUnichar Wallet_GetKey(PRInt64 saveCount, PRInt64 writeCount);
|
||||
extern PRBool Wallet_KeySet();
|
||||
extern void Wallet_KeyResetTime();
|
||||
extern PRBool Wallet_KeyTimedOut();
|
||||
|
@ -254,16 +253,12 @@ extern PRBool Wallet_SetKey(PRBool newkey);
|
|||
extern PRInt32 Wallet_KeySize();
|
||||
extern PRBool Wallet_CancelKey();
|
||||
|
||||
char* signonFileName = nsnull;
|
||||
|
||||
PRIVATE void
|
||||
si_RestartKey() {
|
||||
Wallet_RestartKey();
|
||||
}
|
||||
char* signonFileNameP = nsnull;
|
||||
char* signonFileNameU = nsnull;
|
||||
|
||||
PRIVATE PRUnichar
|
||||
si_GetKey() {
|
||||
return Wallet_GetKey();
|
||||
si_GetKey(PRInt64 saveCount, PRInt64 writeCount) {
|
||||
return Wallet_GetKey(saveCount, writeCount);
|
||||
}
|
||||
|
||||
PRIVATE PRBool
|
||||
|
@ -404,7 +399,10 @@ static const char *pref_rememberSignons = "signon.rememberSignons";
|
|||
#ifdef DefaultIsOff
|
||||
static const char *pref_Notified = "signon.Notified";
|
||||
#endif
|
||||
static const char *pref_SignonFileName = "signon.SignonFileName";
|
||||
static const char *pref_SignonFileName = "signon.SignonFileName"; /* for old format only */
|
||||
static const char *pref_SignonFileNameP = "signon.SignonPasswordFileName";
|
||||
static const char *pref_SignonFileNameU = "signon.SignonURLFileName";
|
||||
static PRBool si_oldFormat = PR_FALSE;
|
||||
|
||||
PRIVATE PRBool si_RememberSignons = PR_FALSE;
|
||||
#ifdef DefaultIsOff
|
||||
|
@ -510,10 +508,41 @@ extern char* Wallet_RandomName(char* suffix);
|
|||
|
||||
PUBLIC void
|
||||
SI_InitSignonFileName() {
|
||||
SI_GetCharPref(pref_SignonFileName, &signonFileName);
|
||||
if (!signonFileName) {
|
||||
signonFileName = Wallet_RandomName("psw");
|
||||
SI_SetCharPref(pref_SignonFileName, signonFileName);
|
||||
/*
|
||||
* All files created by wallet and single signon will have a format designation number
|
||||
* in the first line of the file. However the original files did not do that. So we
|
||||
* go to great pains to maintain backwards compatibility with these old files. We
|
||||
* accomplish this by changing the names of the old files.
|
||||
*
|
||||
* The original and new names of the files are:
|
||||
*
|
||||
* old names new names
|
||||
* key file: xxxxxxxx.key xxxxxxxx.k
|
||||
* wallet data: xxxxxxxx.wlt xxxxxxxx.w
|
||||
* ss passwords: xxxxxxxx.psw xxxxxxxx.p
|
||||
* ss urls: signon.tab xxxxxxxx.u
|
||||
*
|
||||
* Furtherore, the names of the first three files were stored in prefs.js for the old
|
||||
* files but all four are stored there for the new ones.
|
||||
*/
|
||||
SI_GetCharPref(pref_SignonFileNameP, &signonFileNameP);
|
||||
|
||||
if (!signonFileNameP) {
|
||||
SI_GetCharPref(pref_SignonFileName, &signonFileNameP);
|
||||
if (!signonFileNameP) {
|
||||
signonFileNameP = Wallet_RandomName("p");
|
||||
SI_SetCharPref(pref_SignonFileNameP, signonFileNameP);
|
||||
} else {
|
||||
si_oldFormat = PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!si_oldFormat) {
|
||||
SI_GetCharPref(pref_SignonFileNameU, &signonFileNameU);
|
||||
if (!signonFileNameU) {
|
||||
signonFileNameU = Wallet_RandomName("u");
|
||||
SI_SetCharPref(pref_SignonFileNameU, signonFileNameU);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -720,7 +749,7 @@ si_GetURL(char * URLName) {
|
|||
|
||||
/* Remove a user node from a given URL node */
|
||||
PRIVATE PRBool
|
||||
si_RemoveUser(char *URLName, nsAutoString userName, PRBool save) {
|
||||
si_RemoveUser(char *URLName, nsAutoString userName, PRBool save, PRBool strip = PR_TRUE) {
|
||||
nsresult res;
|
||||
si_SignonURLStruct * url;
|
||||
si_SignonUserStruct * user;
|
||||
|
@ -733,36 +762,40 @@ si_RemoveUser(char *URLName, nsAutoString userName, PRBool save) {
|
|||
|
||||
/* convert URLName to a uri so we can parse out the username and hostname */
|
||||
char* host = nsnull;
|
||||
if (URLName) {
|
||||
nsCOMPtr<nsIURL> uri;
|
||||
nsComponentManager::CreateInstance(kStandardUrlCID, nsnull, NS_GET_IID(nsIURL), (void **) getter_AddRefs(uri));
|
||||
uri->SetSpec((char *)URLName);
|
||||
if (strip) {
|
||||
if (URLName) {
|
||||
nsCOMPtr<nsIURL> uri;
|
||||
nsComponentManager::CreateInstance(kStandardUrlCID, nsnull, NS_GET_IID(nsIURL), (void **) getter_AddRefs(uri));
|
||||
uri->SetSpec((char *)URLName);
|
||||
|
||||
/* uri is of the form <scheme>://<username>:<password>@<host>:<portnumber>/<pathname>) */
|
||||
/* uri is of the form <scheme>://<username>:<password>@<host>:<portnumber>/<pathname>) */
|
||||
|
||||
/* get host part of the uri */
|
||||
res = uri->GetHost(&host);
|
||||
if (NS_FAILED(res)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
/* if no username given, extract it from uri -- note: prehost is <username>:<password> */
|
||||
if (userName.Length() == 0) {
|
||||
char * userName2 = nsnull;
|
||||
res = uri->GetPreHost(&userName2);
|
||||
/* get host part of the uri */
|
||||
res = uri->GetHost(&host);
|
||||
if (NS_FAILED(res)) {
|
||||
PR_FREEIF(host);
|
||||
return PR_FALSE;
|
||||
}
|
||||
if (userName2) {
|
||||
userName = nsAutoString(userName2);
|
||||
PR_FREEIF(userName2);
|
||||
PRInt32 colon = userName.FindChar(':');
|
||||
if (colon != -1) {
|
||||
userName.Truncate(colon);
|
||||
|
||||
/* if no username given, extract it from uri -- note: prehost is <username>:<password> */
|
||||
if (userName.Length() == 0) {
|
||||
char * userName2 = nsnull;
|
||||
res = uri->GetPreHost(&userName2);
|
||||
if (NS_FAILED(res)) {
|
||||
PR_FREEIF(host);
|
||||
return PR_FALSE;
|
||||
}
|
||||
if (userName2) {
|
||||
userName = nsAutoString(userName2);
|
||||
PR_FREEIF(userName2);
|
||||
PRInt32 colon = userName.FindChar(':');
|
||||
if (colon != -1) {
|
||||
userName.Truncate(colon);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
host = (nsAutoString(":") + URLName).ToNewCString();
|
||||
}
|
||||
|
||||
si_lock_signon_list();
|
||||
|
@ -826,8 +859,8 @@ si_RemoveUser(char *URLName, nsAutoString userName, PRBool save) {
|
|||
}
|
||||
|
||||
PUBLIC PRBool
|
||||
SINGSIGN_RemoveUser(const char *URLName, const PRUnichar *userName) {
|
||||
return si_RemoveUser((char *)URLName, userName, PR_TRUE);
|
||||
SINGSIGN_RemoveUser(const char *URLName, const PRUnichar *userName, PRBool strip) {
|
||||
return si_RemoveUser((char *)URLName, userName, PR_TRUE, strip);
|
||||
}
|
||||
|
||||
/* Determine if a specified url/user exists */
|
||||
|
@ -1161,6 +1194,9 @@ si_GetURLAndUserForChangeForm(nsAutoString password)
|
|||
return user;
|
||||
}
|
||||
|
||||
PRIVATE void
|
||||
si_FreeReject(si_Reject * reject);
|
||||
|
||||
/*
|
||||
* Remove all the signons and free everything
|
||||
*/
|
||||
|
@ -1174,8 +1210,17 @@ si_RemoveAllSignonData() {
|
|||
}
|
||||
si_PartiallyLoaded = PR_FALSE;
|
||||
si_FullyLoaded = PR_FALSE;
|
||||
}
|
||||
|
||||
si_Reject * reject;
|
||||
PRInt32 rejectCount = LIST_COUNT(si_reject_list);
|
||||
while (LIST_COUNT(si_reject_list)>0) {
|
||||
reject = NS_STATIC_CAST(si_Reject*, si_reject_list->ElementAt(0));
|
||||
if (reject) {
|
||||
si_FreeReject(reject);
|
||||
si_signon_list_changed = PR_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************
|
||||
* Managing the Reject List *
|
||||
|
@ -1540,6 +1585,8 @@ si_PutData(char * URLName, nsVoidArray * signonData, PRBool save) {
|
|||
* Managing the Signon Files *
|
||||
*****************************/
|
||||
|
||||
#define HEADER_VERSION_1 "#1"
|
||||
|
||||
extern void
|
||||
Wallet_UTF8Put(nsOutputFileStream strm, PRUnichar c);
|
||||
|
||||
|
@ -1555,22 +1602,34 @@ Wallet_UTF8Get(nsInputFileStream strm);
|
|||
*/
|
||||
PRIVATE PRInt32
|
||||
si_ReadLine
|
||||
(nsInputFileStream strm, nsInputFileStream strmx, nsAutoString& lineBuffer, PRBool obscure) {
|
||||
(nsInputFileStream strmu, nsInputFileStream strmp, nsAutoString& lineBuffer,PRBool obscure,
|
||||
PRInt64 saveCount = 0, PRInt64 * readCount = 0, PRBool inHeader = PR_FALSE) {
|
||||
|
||||
lineBuffer = nsAutoString("");
|
||||
|
||||
/* read the line */
|
||||
PRUnichar c;
|
||||
PRUnichar c, c2;
|
||||
for (;;) {
|
||||
if (obscure) {
|
||||
c = Wallet_UTF8Get(strm); /* get past the asterisk */
|
||||
c = Wallet_UTF8Get(strmx)^si_GetKey(); /* get the real character */
|
||||
if (inHeader) {
|
||||
c = Wallet_UTF8Get(strmu);
|
||||
if (obscure) {
|
||||
c2 = Wallet_UTF8Get(strmp);
|
||||
if (c != c2) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} else if (obscure) {
|
||||
c = Wallet_UTF8Get(strmu); /* get past the asterisk */
|
||||
if ((c != '*') && (c != '\n') && (c != '\r')) {
|
||||
return -1;
|
||||
}
|
||||
c = Wallet_UTF8Get(strmp)^si_GetKey(saveCount, (*readCount)++); /* get the real character */
|
||||
} else {
|
||||
c = Wallet_UTF8Get(strm);
|
||||
c = Wallet_UTF8Get(strmu);
|
||||
}
|
||||
|
||||
/* note that eof is not set until we read past the end of the file */
|
||||
if (strm.eof()) {
|
||||
if (strmu.eof()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1603,7 +1662,10 @@ SI_LoadSignonData(PRBool fullLoad) {
|
|||
*/
|
||||
char * URLName;
|
||||
nsAutoString buffer;
|
||||
PRBool badInput;
|
||||
PRBool badInput = PR_FALSE;
|
||||
|
||||
PRInt64 readCount = 0;
|
||||
PRInt64 saveCount = 0;
|
||||
|
||||
if (si_FullyLoaded && fullLoad) {
|
||||
return 0;
|
||||
|
@ -1622,15 +1684,20 @@ SI_LoadSignonData(PRBool fullLoad) {
|
|||
if (NS_FAILED(rv)) {
|
||||
return -1;
|
||||
}
|
||||
nsInputFileStream strm(dirSpec + "signon.tbl");
|
||||
if (!strm.is_open()) {
|
||||
|
||||
SI_InitSignonFileName();
|
||||
nsInputFileStream strmu(dirSpec+"signon.tbl");
|
||||
if (!si_oldFormat) {
|
||||
strmu = nsInputFileStream(dirSpec+signonFileNameU);
|
||||
}
|
||||
|
||||
if (!strmu.is_open()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
si_RemoveAllSignonData();
|
||||
|
||||
if (fullLoad) {
|
||||
si_RestartKey();
|
||||
PRUnichar * message = Wallet_Localize("IncorrectKey_TryAgain?");
|
||||
if (si_KeyTimedOut()) {
|
||||
si_RemoveAllSignonData();
|
||||
|
@ -1645,31 +1712,91 @@ SI_LoadSignonData(PRBool fullLoad) {
|
|||
si_KeyResetTime();
|
||||
}
|
||||
|
||||
nsInputFileStream strmx(fullLoad ? (dirSpec+signonFileName) : dirSpec); // not used if !fullLoad
|
||||
if (fullLoad && !strmx.is_open()) {
|
||||
nsInputFileStream strmp(fullLoad ? (dirSpec+signonFileNameP) : dirSpec); // not used if !fullLoad
|
||||
if (fullLoad && !strmp.is_open()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* read the header information */
|
||||
nsAutoString format;
|
||||
PRInt64 temp;
|
||||
PRInt32 error;
|
||||
|
||||
if (!si_oldFormat) {
|
||||
|
||||
/* format */
|
||||
|
||||
if (NS_FAILED(si_ReadLine(strmu, strmp, format, fullLoad, 0, 0, PR_TRUE))) {
|
||||
return -1;
|
||||
}
|
||||
if (format != HEADER_VERSION_1) {
|
||||
/* something's wrong */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* saveCount */
|
||||
|
||||
if (NS_FAILED(si_ReadLine(strmu, strmp, buffer, fullLoad, 0, 0, PR_TRUE))) {
|
||||
return -1;
|
||||
}
|
||||
temp = (PRInt64)(buffer.ToInteger(&error));
|
||||
if (error) {
|
||||
return -1;
|
||||
}
|
||||
saveCount = temp<<32;
|
||||
|
||||
if (NS_FAILED(si_ReadLine(strmu, strmp, buffer, fullLoad, 0, 0, PR_TRUE))) {
|
||||
return -1;
|
||||
}
|
||||
temp = (PRInt64)(buffer.ToInteger(&error));
|
||||
if (error) {
|
||||
return -1;
|
||||
}
|
||||
saveCount += temp;
|
||||
|
||||
/* readCount */
|
||||
|
||||
if (NS_FAILED(si_ReadLine(strmu, strmp, buffer, fullLoad, 0, 0, PR_TRUE))) {
|
||||
return -1;
|
||||
}
|
||||
temp = (PRInt64)(buffer.ToInteger(&error));
|
||||
if (error) {
|
||||
return -1;
|
||||
}
|
||||
readCount = temp<<32;
|
||||
|
||||
if (NS_FAILED(si_ReadLine(strmu, strmp, buffer, fullLoad, 0, 0, PR_TRUE))) {
|
||||
return -1;
|
||||
}
|
||||
temp = (PRInt64)(buffer.ToInteger(&error));
|
||||
if (error) {
|
||||
return -1;
|
||||
}
|
||||
readCount += temp;
|
||||
}
|
||||
|
||||
/* read the reject list */
|
||||
si_lock_signon_list();
|
||||
while(!NS_FAILED(si_ReadLine(strm, strmx, buffer, PR_FALSE))) {
|
||||
while (!NS_FAILED(si_ReadLine(strmu, strmp, buffer, PR_FALSE))) {
|
||||
if (buffer.CharAt(0) == '.') {
|
||||
break; /* end of reject list */
|
||||
}
|
||||
si_StripLF(buffer);
|
||||
URLName = buffer.ToNewCString();
|
||||
if (NS_FAILED(si_ReadLine(strm, strmx, buffer, PR_FALSE))) {
|
||||
/* error in input file so give up */
|
||||
badInput = PR_TRUE;
|
||||
break;
|
||||
if (si_oldFormat) {
|
||||
if (NS_FAILED(si_ReadLine(strmu, strmp, buffer, PR_FALSE))) {
|
||||
/* error in input file so give up */
|
||||
badInput = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
si_StripLF(buffer);
|
||||
}
|
||||
si_StripLF(buffer);
|
||||
si_PutReject(URLName, buffer, PR_FALSE);
|
||||
si_PutReject(URLName, buffer, PR_FALSE); /* middle parameter is obsolete */
|
||||
Recycle (URLName);
|
||||
}
|
||||
|
||||
/* read the URL line */
|
||||
while(!NS_FAILED(si_ReadLine(strm, strmx, buffer, PR_FALSE))) {
|
||||
while(!NS_FAILED(si_ReadLine(strmu, strmp, buffer, PR_FALSE))) {
|
||||
si_StripLF(buffer);
|
||||
URLName = buffer.ToNewCString();
|
||||
|
||||
|
@ -1678,7 +1805,7 @@ SI_LoadSignonData(PRBool fullLoad) {
|
|||
|
||||
nsVoidArray * signonData = new nsVoidArray();
|
||||
si_SignonDataStruct * data;
|
||||
while(!NS_FAILED(si_ReadLine(strm, strmx, buffer, PR_FALSE))) {
|
||||
while(!NS_FAILED(si_ReadLine(strmu, strmp, buffer, PR_FALSE))) {
|
||||
|
||||
/* line starting with . terminates the pairs for this URL entry */
|
||||
if (buffer.CharAt(0) == '.') {
|
||||
|
@ -1697,11 +1824,15 @@ SI_LoadSignonData(PRBool fullLoad) {
|
|||
isPassword = PR_TRUE;
|
||||
nsAutoString temp;
|
||||
buffer.Mid(name, 1, buffer.Length()-1);
|
||||
ret = si_ReadLine(strm, strmx, buffer, fullLoad);
|
||||
ret = si_ReadLine(strmu, strmp, buffer, fullLoad, saveCount, &readCount);
|
||||
} else {
|
||||
isPassword = PR_FALSE;
|
||||
name = buffer;
|
||||
ret = si_ReadLine(strm, strmx, buffer, PR_FALSE);
|
||||
if (si_oldFormat) {
|
||||
ret = si_ReadLine(strmu, strmp, buffer, PR_FALSE);
|
||||
} else {
|
||||
ret = si_ReadLine(strmu, strmp, buffer, fullLoad, saveCount, &readCount);
|
||||
}
|
||||
}
|
||||
|
||||
/* read in and save the value part */
|
||||
|
@ -1764,20 +1895,30 @@ si_WriteChar(nsOutputFileStream strm, PRUnichar c) {
|
|||
}
|
||||
|
||||
PRIVATE void
|
||||
si_WriteLine(nsOutputFileStream strm, nsOutputFileStream strmx, nsAutoString lineBuffer, PRBool obscure, PRBool fullSave) {
|
||||
si_WriteLine(nsOutputFileStream strmu, nsOutputFileStream strmp,
|
||||
nsAutoString lineBuffer, PRBool obscure, PRBool fullSave,
|
||||
PRInt64 saveCount = 0, PRInt64 *writeCount = 0, PRBool inHeader = PR_FALSE) {
|
||||
|
||||
for (int i=0; i<lineBuffer.Length(); i++) {
|
||||
if (obscure) {
|
||||
Wallet_UTF8Put(strm, '*');
|
||||
if (inHeader) {
|
||||
Wallet_UTF8Put(strmu, lineBuffer.CharAt(i));
|
||||
if (fullSave) {
|
||||
Wallet_UTF8Put(strmx, lineBuffer.CharAt(i)^si_GetKey());
|
||||
Wallet_UTF8Put(strmp, lineBuffer.CharAt(i));
|
||||
}
|
||||
} else if (obscure) {
|
||||
Wallet_UTF8Put(strmu, '*');
|
||||
if (fullSave) {
|
||||
Wallet_UTF8Put(strmp, lineBuffer.CharAt(i)^si_GetKey(saveCount, (*writeCount)++));
|
||||
}
|
||||
} else {
|
||||
Wallet_UTF8Put(strm, lineBuffer.CharAt(i));
|
||||
Wallet_UTF8Put(strmu, lineBuffer.CharAt(i));
|
||||
}
|
||||
}
|
||||
Wallet_UTF8Put(strm, '\n');
|
||||
if (obscure && fullSave) {
|
||||
Wallet_UTF8Put(strmx, '\n'^si_GetKey());
|
||||
Wallet_UTF8Put(strmu, '\n');
|
||||
if (inHeader && fullSave) {
|
||||
Wallet_UTF8Put(strmp, '\n');
|
||||
} else if (obscure && fullSave) {
|
||||
Wallet_UTF8Put(strmp, '\n'^si_GetKey(saveCount, (*writeCount)++));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1787,14 +1928,16 @@ si_SaveSignonDataLocked(PRBool fullSave) {
|
|||
si_SignonUserStruct * user;
|
||||
si_SignonDataStruct * data;
|
||||
si_Reject * reject;
|
||||
PRInt64 saveCount = 0;
|
||||
PRInt64 writeCount = 0;
|
||||
PRBool fullSave2 = fullSave || si_oldFormat;
|
||||
|
||||
/* do nothing if signon list has not changed */
|
||||
if(!si_signon_list_changed) {
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if (fullSave) {
|
||||
si_RestartKey();
|
||||
if (fullSave2) {
|
||||
PRUnichar * message = Wallet_Localize("IncorrectKey_TryAgain?");
|
||||
if (si_KeyTimedOut()) {
|
||||
si_RemoveAllSignonData();
|
||||
|
@ -1826,19 +1969,64 @@ si_SaveSignonDataLocked(PRBool fullSave) {
|
|||
if (NS_FAILED(rv)) {
|
||||
return 0;
|
||||
}
|
||||
nsOutputFileStream strm(dirSpec + "signon.tbl");
|
||||
if (!strm.is_open()) {
|
||||
return 0;
|
||||
}
|
||||
nsOutputFileStream strmx(dirSpec + signonFileName);
|
||||
if (fullSave) {
|
||||
if (!strmx.is_open()) {
|
||||
return 0;
|
||||
}
|
||||
si_RestartKey();
|
||||
|
||||
if (si_oldFormat) {
|
||||
|
||||
/* change name of signonFileNameP from "xxxxxxxx.psw" to "xxxxxxxx.p" */
|
||||
signonFileNameP[10] = '\0';
|
||||
SI_SetCharPref(pref_SignonFileNameP, signonFileNameP);
|
||||
|
||||
/* create signonFileNameU and set it to "xxxxxxxx.u" */
|
||||
signonFileNameU = PL_strdup(signonFileNameP); /* set it to "xxxxxxxx.p" */
|
||||
signonFileNameU[9] = 'u'; /* change .p to .u */
|
||||
SI_SetCharPref(pref_SignonFileNameU, signonFileNameU);
|
||||
|
||||
si_oldFormat = PR_FALSE;
|
||||
}
|
||||
|
||||
nsOutputFileStream strmu(dirSpec + signonFileNameU);
|
||||
if (!strmu.is_open()) {
|
||||
return 0;
|
||||
}
|
||||
nsOutputFileStream strmp
|
||||
(fullSave2 ? (dirSpec+signonFileNameP) : dirSpec); // not used if !fullSave
|
||||
if (fullSave2 && !strmp.is_open()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* format for head of file shall be:
|
||||
* format revision number
|
||||
* saveCount
|
||||
* writeCount
|
||||
*/
|
||||
|
||||
/* write out the header info */
|
||||
|
||||
/* format revision number */
|
||||
|
||||
si_WriteLine(strmu, strmp, nsAutoString(HEADER_VERSION_1), PR_FALSE, fullSave2, 0, 0, PR_TRUE);
|
||||
|
||||
/* saveCount */
|
||||
|
||||
nsAutoString buffer;
|
||||
buffer = "";
|
||||
buffer.Append(PRInt32(saveCount>>32),10);
|
||||
si_WriteLine(strmu, strmp, buffer, PR_FALSE, fullSave2, 0, 0, PR_TRUE);
|
||||
buffer = "";
|
||||
buffer.Append(PRInt32((saveCount<<32)>>32),10);
|
||||
si_WriteLine(strmu, strmp, buffer, PR_FALSE, fullSave2, 0, 0, PR_TRUE);
|
||||
|
||||
/* writeCount */
|
||||
|
||||
buffer = "";
|
||||
buffer.Append(PRInt32(writeCount>>32),10);
|
||||
si_WriteLine(strmu, strmp, buffer, PR_FALSE, fullSave2, 0, 0, PR_TRUE);
|
||||
buffer = "";
|
||||
buffer.Append(PRInt32((writeCount<<32)>>32),10);
|
||||
si_WriteLine(strmu, strmp, buffer, PR_FALSE, fullSave2, 0, 0, PR_TRUE);
|
||||
|
||||
/* format for next part of file shall be:
|
||||
* URLName -- first url/username on reject list
|
||||
* userName
|
||||
* URLName -- second url/username on reject list
|
||||
|
@ -1852,11 +2040,10 @@ si_SaveSignonDataLocked(PRBool fullSave) {
|
|||
PRInt32 rejectCount = LIST_COUNT(si_reject_list);
|
||||
for (PRInt32 i=0; i<rejectCount; i++) {
|
||||
reject = NS_STATIC_CAST(si_Reject*, si_reject_list->ElementAt(i));
|
||||
si_WriteLine(strm, strmx, nsAutoString(reject->URLName), PR_FALSE, fullSave);
|
||||
si_WriteLine(strm, strmx, nsAutoString(reject->userName), PR_FALSE, fullSave);
|
||||
si_WriteLine(strmu, strmp, nsAutoString(reject->URLName), PR_FALSE, fullSave2);
|
||||
}
|
||||
}
|
||||
si_WriteLine(strm, strmx, nsAutoString("."), PR_FALSE, fullSave);
|
||||
si_WriteLine(strmu, strmp, nsAutoString("."), PR_FALSE, fullSave2);
|
||||
|
||||
/* format for cached logins shall be:
|
||||
* url LINEBREAK {name LINEBREAK value LINEBREAK}* . LINEBREAK
|
||||
|
@ -1873,31 +2060,30 @@ si_SaveSignonDataLocked(PRBool fullSave) {
|
|||
PRInt32 userCount = LIST_COUNT(url->signonUser_list);
|
||||
for (PRInt32 i3=0; i3<userCount; i3++) {
|
||||
user = NS_STATIC_CAST(si_SignonUserStruct*, url->signonUser_list->ElementAt(i3));
|
||||
si_WriteLine(strm, strmx, nsAutoString(url->URLName), PR_FALSE, fullSave);
|
||||
si_WriteLine
|
||||
(strmu, strmp, nsAutoString(url->URLName), PR_FALSE, fullSave2);
|
||||
|
||||
/* write out each data node of the user node */
|
||||
PRInt32 dataCount = LIST_COUNT(user->signonData_list);
|
||||
for (PRInt32 i4=0; i4<dataCount; i4++) {
|
||||
data = NS_STATIC_CAST(si_SignonDataStruct*, user->signonData_list->ElementAt(i4));
|
||||
if (data->isPassword) {
|
||||
si_WriteChar(strm, '*');
|
||||
si_WriteLine(strm, strmx, nsAutoString(data->name), PR_FALSE, fullSave);
|
||||
si_WriteLine(strm, strmx, nsAutoString(data->value), PR_TRUE, fullSave);
|
||||
} else {
|
||||
si_WriteLine(strm, strmx, nsAutoString(data->name), PR_FALSE, fullSave);
|
||||
si_WriteLine(strm, strmx, nsAutoString(data->value), PR_FALSE, fullSave);
|
||||
si_WriteChar(strmu, '*');
|
||||
}
|
||||
si_WriteLine(strmu, strmp, nsAutoString(data->name), PR_FALSE, fullSave2);
|
||||
si_WriteLine(strmu, strmp, nsAutoString(data->value), PR_TRUE,
|
||||
fullSave2, saveCount, &writeCount);
|
||||
}
|
||||
si_WriteLine(strm, strmx, nsAutoString("."), PR_FALSE, fullSave);
|
||||
si_WriteLine(strmu, strmp, nsAutoString("."), PR_FALSE, fullSave2);
|
||||
}
|
||||
}
|
||||
}
|
||||
si_signon_list_changed = PR_FALSE;
|
||||
strm.flush();
|
||||
strm.close();
|
||||
if (fullSave) {
|
||||
strmx.flush();
|
||||
strmx.close();
|
||||
strmu.flush();
|
||||
strmu.close();
|
||||
if (fullSave2) {
|
||||
strmp.flush();
|
||||
strmp.close();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -2255,7 +2441,7 @@ si_RestoreOldSignonDataFromBrowser
|
|||
PUBLIC nsresult
|
||||
SINGSIGN_PromptUsernameAndPassword
|
||||
(const PRUnichar *text, PRUnichar **user, PRUnichar **pwd,
|
||||
const char *urlname, nsIPrompt* dialog, PRBool *returnValue) {
|
||||
const char *urlname, nsIPrompt* dialog, PRBool *returnValue, PRBool strip) {
|
||||
|
||||
nsresult res;
|
||||
|
||||
|
@ -2273,9 +2459,13 @@ SINGSIGN_PromptUsernameAndPassword
|
|||
|
||||
/* get host part of the uri */
|
||||
char* host = nsnull;
|
||||
res = uri->GetHost(&host);
|
||||
if (NS_FAILED(res)) {
|
||||
return res;
|
||||
if (strip) {
|
||||
res = uri->GetHost(&host);
|
||||
if (NS_FAILED(res)) {
|
||||
return res;
|
||||
}
|
||||
} else {
|
||||
host = (nsAutoString(":") + urlname).ToNewCString();
|
||||
}
|
||||
|
||||
/* prefill with previous username/password if any */
|
||||
|
@ -2305,7 +2495,8 @@ SINGSIGN_PromptUsernameAndPassword
|
|||
|
||||
PUBLIC nsresult
|
||||
SINGSIGN_PromptPassword
|
||||
(const PRUnichar *text, PRUnichar **pwd, const char *urlname, nsIPrompt* dialog, PRBool *returnValue) {
|
||||
(const PRUnichar *text, PRUnichar **pwd, const char *urlname,
|
||||
nsIPrompt* dialog, PRBool *returnValue, PRBool strip) {
|
||||
|
||||
nsresult res;
|
||||
nsAutoString password, username;
|
||||
|
@ -2324,9 +2515,13 @@ SINGSIGN_PromptPassword
|
|||
|
||||
/* get host part of the uri */
|
||||
char* host;
|
||||
res = uri->GetHost(&host);
|
||||
if (NS_FAILED(res)) {
|
||||
return res;
|
||||
if (strip) {
|
||||
res = uri->GetHost(&host);
|
||||
if (NS_FAILED(res)) {
|
||||
return res;
|
||||
}
|
||||
} else {
|
||||
host = (nsAutoString(":") + urlname).ToNewCString();
|
||||
}
|
||||
|
||||
/* extract username from uri -- note: prehost is <username>:<password> */
|
||||
|
@ -2378,8 +2573,8 @@ SINGSIGN_PromptPassword
|
|||
|
||||
PUBLIC nsresult
|
||||
SINGSIGN_Prompt
|
||||
(const PRUnichar *text, const PRUnichar *defaultText,
|
||||
PRUnichar **resultText, const char *urlname,nsIPrompt* dialog, PRBool *returnValue) {
|
||||
(const PRUnichar *text, const PRUnichar *defaultText, PRUnichar **resultText,
|
||||
const char *urlname, nsIPrompt* dialog, PRBool *returnValue, PRBool strip) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -2497,6 +2692,10 @@ SINGSIGN_SignonViewerReturn (nsAutoString results) {
|
|||
PUBLIC void
|
||||
SINGSIGN_GetSignonListForViewer(nsAutoString& aSignonList)
|
||||
{
|
||||
/* force loading of the signons file */
|
||||
si_RegisterSignonPrefCallbacks();
|
||||
|
||||
/* unlock the database */
|
||||
if (SI_LoadSignonData(PR_TRUE) != 0) {
|
||||
/* don't display saved signons if user couldn't unlock the database */
|
||||
return;
|
||||
|
@ -2507,9 +2706,6 @@ SINGSIGN_GetSignonListForViewer(nsAutoString& aSignonList)
|
|||
si_SignonUserStruct * user;
|
||||
si_SignonDataStruct* data = nsnull;
|
||||
|
||||
/* force loading of the signons file */
|
||||
si_RegisterSignonPrefCallbacks();
|
||||
|
||||
PRInt32 urlCount = LIST_COUNT(si_signon_list);
|
||||
for (PRInt32 i=0; i<urlCount; i++) {
|
||||
url = NS_STATIC_CAST(si_SignonURLStruct*, si_signon_list->ElementAt(i));
|
||||
|
|
|
@ -49,19 +49,21 @@ SINGSIGN_RestoreSignonData(char* URLName, PRUnichar* name, PRUnichar** value, PR
|
|||
extern nsresult
|
||||
SINGSIGN_PromptUsernameAndPassword
|
||||
(const PRUnichar *text, PRUnichar **user, PRUnichar **pwd,
|
||||
const char *urlname,nsIPrompt* dialog, PRBool *returnValue);
|
||||
const char *urlname,nsIPrompt* dialog, PRBool *returnValue, PRBool strip = PR_TRUE);
|
||||
|
||||
extern nsresult
|
||||
SINGSIGN_PromptPassword
|
||||
(const PRUnichar *text, PRUnichar **pwd, const char *urlname,nsIPrompt* dialog, PRBool *returnValue);
|
||||
(const PRUnichar *text, PRUnichar **pwd, const char *urlname,
|
||||
nsIPrompt* dialog, PRBool *returnValue, PRBool strip = PR_TRUE);
|
||||
|
||||
extern nsresult
|
||||
SINGSIGN_Prompt
|
||||
(const PRUnichar *text, const PRUnichar *defaultText, PRUnichar **resultText,
|
||||
const char *urlname,nsIPrompt* dialog, PRBool *returnValue);
|
||||
const char *urlname,nsIPrompt* dialog, PRBool *returnValue, PRBool strip = PR_TRUE);
|
||||
|
||||
extern PRBool
|
||||
SINGSIGN_RemoveUser(const char *URLName, const PRUnichar *userName);
|
||||
SINGSIGN_RemoveUser
|
||||
(const char *URLName, const PRUnichar *userName, PRBool strip = PR_TRUE);
|
||||
|
||||
XP_END_PROTOS
|
||||
|
||||
|
|
|
@ -55,6 +55,12 @@
|
|||
#include "nsIContent.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
#ifdef DEBUG_morse
|
||||
#define morseAssert NS_ASSERTION
|
||||
#else
|
||||
#define morseAssert(x,y) 0
|
||||
#endif
|
||||
|
||||
static NS_DEFINE_IID(kIDOMHTMLDocumentIID, NS_IDOMHTMLDOCUMENT_IID);
|
||||
static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID);
|
||||
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
|
||||
|
@ -336,6 +342,8 @@ typedef struct _wallet_PrefillElement {
|
|||
|
||||
nsIURI * wallet_lastUrl = NULL;
|
||||
|
||||
static PRBool wallet_oldFormat = PR_FALSE;
|
||||
|
||||
/***********************************************************/
|
||||
/* The following routines are for diagnostic purposes only */
|
||||
/***********************************************************/
|
||||
|
@ -1283,7 +1291,6 @@ Wallet_SimpleGet(nsInputFileStream strm) {
|
|||
/************************************************************/
|
||||
|
||||
nsAutoString key;
|
||||
PRInt32 keyPosition = 0;
|
||||
PRBool keyCancel = PR_FALSE;
|
||||
PRBool keySet = PR_FALSE;
|
||||
time_t keyExpiresTime;
|
||||
|
@ -1293,17 +1300,9 @@ time_t keyExpiresTime;
|
|||
char* keyFileName = nsnull;
|
||||
char* schemaValueFileName = nsnull;
|
||||
|
||||
PUBLIC void
|
||||
Wallet_RestartKey() {
|
||||
keyPosition = 0;
|
||||
}
|
||||
|
||||
PUBLIC PRUnichar
|
||||
Wallet_GetKey() {
|
||||
if (keyPosition >= key.Length()) {
|
||||
keyPosition = 0;
|
||||
}
|
||||
return key.CharAt(keyPosition++);
|
||||
Wallet_GetKey(PRInt64 saveCount, PRInt64 writeCount) {
|
||||
return key.CharAt((PRInt32)(writeCount % key.Length()));
|
||||
}
|
||||
|
||||
PUBLIC PRBool
|
||||
|
@ -1377,19 +1376,29 @@ Wallet_RandomName(char* suffix)
|
|||
return PL_strdup(name);
|
||||
}
|
||||
|
||||
PRIVATE PRBool
|
||||
wallet_IsOldKeyFormat() {
|
||||
/* old format: key filename = xxxxxxxx.key (12 characters)
|
||||
* new format: key filename = xxxxxxxx.k (10 characters)
|
||||
*/
|
||||
return (PL_strlen(keyFileName) == 12);
|
||||
}
|
||||
|
||||
PRIVATE void
|
||||
wallet_InitKeyFileName() {
|
||||
static PRBool namesInitialized = PR_FALSE;
|
||||
if (!namesInitialized) {
|
||||
SI_GetCharPref(pref_WalletKeyFileName, &keyFileName);
|
||||
if (!keyFileName) {
|
||||
keyFileName = Wallet_RandomName("key");
|
||||
keyFileName = Wallet_RandomName("k");
|
||||
SI_SetCharPref(pref_WalletKeyFileName, keyFileName);
|
||||
}
|
||||
SI_GetCharPref(pref_WalletSchemaValueFileName, &schemaValueFileName);
|
||||
if (!schemaValueFileName) {
|
||||
schemaValueFileName = Wallet_RandomName("wlt");
|
||||
schemaValueFileName = Wallet_RandomName("w");
|
||||
SI_SetCharPref(pref_WalletSchemaValueFileName, schemaValueFileName);
|
||||
} else if (PL_strstr(schemaValueFileName, ".wlt")) {
|
||||
wallet_oldFormat = PR_TRUE;
|
||||
}
|
||||
SI_InitSignonFileName();
|
||||
namesInitialized = PR_TRUE;
|
||||
|
@ -1399,7 +1408,6 @@ wallet_InitKeyFileName() {
|
|||
/* returns -1 if key does not exist, 0 if key is of length 0, 1 otherwise */
|
||||
PUBLIC PRInt32
|
||||
Wallet_KeySize() {
|
||||
|
||||
wallet_InitKeyFileName();
|
||||
nsFileSpec dirSpec;
|
||||
nsresult rv = Wallet_ProfileDirectory(dirSpec);
|
||||
|
@ -1410,20 +1418,144 @@ Wallet_KeySize() {
|
|||
if (!strm.is_open()) {
|
||||
return -1;
|
||||
} else {
|
||||
Wallet_UTF8Get(strm);
|
||||
PRInt32 ret = (strm.eof() ? 0 : 1);
|
||||
#define BUFSIZE 128
|
||||
char buffer[BUFSIZE];
|
||||
PRInt32 count;
|
||||
count = strm.read(buffer, BUFSIZE);
|
||||
strm.close();
|
||||
return ret;
|
||||
if (wallet_IsOldKeyFormat()) {
|
||||
return ((count == 0) ? 0 : 1);
|
||||
}
|
||||
nsAutoString temp(buffer);
|
||||
PRInt32 start = 0;
|
||||
for (PRInt32 i=0; i<5; i++) { /* skip over the five lines of the header */
|
||||
start = temp.FindChar('\n', PR_FALSE, start);
|
||||
if (start == -1) {
|
||||
return -1; /* this should never happen, but just in case */
|
||||
}
|
||||
start++;
|
||||
}
|
||||
return ((start < count) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
wallet_GetHeader(nsInputFileStream strm, PRInt64& saveCount, PRInt64& readCount);
|
||||
|
||||
void
|
||||
wallet_PutHeader(nsOutputFileStream strm, PRInt64 saveCount, PRInt64 writeCount);
|
||||
|
||||
PRBool
|
||||
wallet_ReadKeyFile(PRBool useDefaultKey) {
|
||||
PRInt64 saveCount = 0;
|
||||
PRInt64 writeCount = 0;
|
||||
|
||||
if (useDefaultKey && (Wallet_KeySize() == 0) ) {
|
||||
keySet = PR_TRUE;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsFileSpec dirSpec;
|
||||
nsresult rval = Wallet_ProfileDirectory(dirSpec);
|
||||
if (NS_FAILED(rval)) {
|
||||
keyCancel = PR_TRUE;
|
||||
return PR_FALSE;
|
||||
}
|
||||
nsInputFileStream strm(dirSpec + keyFileName);
|
||||
saveCount = writeCount = 0;
|
||||
if (!wallet_IsOldKeyFormat()) {
|
||||
wallet_GetHeader(strm, saveCount, writeCount);
|
||||
}
|
||||
|
||||
/*
|
||||
* Note that eof() is not set until after we read past the end of the file. That
|
||||
* is why the following code reads a character and immediately after the read
|
||||
* checks for eof()
|
||||
*/
|
||||
|
||||
for (PRInt32 j = 1; j < key.Length(); j++) {
|
||||
if (Wallet_UTF8Get(strm) != ((key.CharAt(j))^Wallet_GetKey(saveCount, writeCount++))
|
||||
|| strm.eof()) {
|
||||
strm.close();
|
||||
key = nsAutoString("");
|
||||
keyCancel = PR_FALSE;
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
if (Wallet_UTF8Get(strm) != ((key.CharAt(0))^Wallet_GetKey(saveCount, writeCount++))
|
||||
|| strm.eof()) {
|
||||
strm.close();
|
||||
key = nsAutoString("");
|
||||
keyCancel = PR_FALSE;
|
||||
return PR_FALSE;
|
||||
}
|
||||
Wallet_UTF8Get(strm); /* to get past the end of the file so eof() will get set */
|
||||
PRBool rv = strm.eof();
|
||||
strm.close();
|
||||
if (rv) {
|
||||
keySet = PR_TRUE;
|
||||
keyExpiresTime = time(NULL) + keyDuration;
|
||||
return PR_TRUE;
|
||||
} else {
|
||||
key = nsAutoString("");
|
||||
keyCancel = PR_TRUE;
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
PRBool
|
||||
wallet_WriteKeyFile(PRBool useDefaultKey) {
|
||||
PRInt64 saveCount = 0;
|
||||
PRInt64 writeCount = 0;
|
||||
|
||||
nsFileSpec dirSpec;
|
||||
nsresult rval = Wallet_ProfileDirectory(dirSpec);
|
||||
if (NS_FAILED(rval)) {
|
||||
keyCancel = PR_TRUE;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
if (wallet_IsOldKeyFormat()) {
|
||||
/* change name of key file from "xxxxxxxx.key" to "xxxxxxxx.k" */
|
||||
keyFileName[10] = '\0';
|
||||
SI_SetCharPref(pref_WalletKeyFileName, keyFileName);
|
||||
}
|
||||
|
||||
nsOutputFileStream strm2(dirSpec + keyFileName);
|
||||
if (!strm2.is_open()) {
|
||||
key = nsAutoString("");
|
||||
keyCancel = PR_TRUE;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
/* write out the header information */
|
||||
wallet_PutHeader(strm2, saveCount, writeCount);
|
||||
|
||||
/* If we store the key obscured by the key itself, then the result will be zero
|
||||
* for all keys (since we are using XOR to obscure). So instead we store
|
||||
* key[1..n],key[0] obscured by the actual key.
|
||||
*/
|
||||
|
||||
if (!useDefaultKey && (key.Length() != 0)) {
|
||||
for (PRInt32 i = 1; i < key.Length(); i++) {
|
||||
Wallet_UTF8Put(strm2, (key.CharAt(i))^Wallet_GetKey(saveCount, writeCount++));
|
||||
}
|
||||
Wallet_UTF8Put(strm2, (key.CharAt(0))^Wallet_GetKey(saveCount, writeCount++));
|
||||
}
|
||||
strm2.flush();
|
||||
strm2.close();
|
||||
keySet = PR_TRUE;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PUBLIC PRBool
|
||||
Wallet_SetKey(PRBool isNewkey) {
|
||||
nsresult res;
|
||||
if (Wallet_KeySet() && !isNewkey) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
Wallet_RestartKey();
|
||||
PRInt64 saveCount = 0;
|
||||
PRInt64 writeCount = 0;
|
||||
|
||||
nsAutoString newkey;
|
||||
PRBool useDefaultKey = PR_FALSE;
|
||||
|
@ -1511,98 +1643,22 @@ Wallet_SetKey(PRBool isNewkey) {
|
|||
}
|
||||
|
||||
key = newkey;
|
||||
Wallet_RestartKey();
|
||||
saveCount = writeCount = 0;
|
||||
|
||||
/* verify this with the saved key */
|
||||
if (isNewkey || (Wallet_KeySize() < 0)) {
|
||||
|
||||
/*
|
||||
* Either key is to be changed or the file containing the saved key doesn' exist.
|
||||
* In either case we need to (re)create and re(write) the file.
|
||||
*/
|
||||
|
||||
nsFileSpec dirSpec;
|
||||
nsresult rval = Wallet_ProfileDirectory(dirSpec);
|
||||
if (NS_FAILED(rval)) {
|
||||
keyCancel = PR_TRUE;
|
||||
return PR_FALSE;
|
||||
}
|
||||
nsOutputFileStream strm2(dirSpec + keyFileName);
|
||||
if (!strm2.is_open()) {
|
||||
key = nsAutoString("");
|
||||
keyCancel = PR_TRUE;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
/* If we store the key obscured by the key itself, then the result will be zero
|
||||
* for all keys (since we are using XOR to obscure). So instead we store
|
||||
* key[1..n],key[0] obscured by the actual key.
|
||||
*/
|
||||
|
||||
if (!useDefaultKey && (key.Length() != 0)) {
|
||||
for (PRInt32 i = 1; i < key.Length(); i++) {
|
||||
Wallet_UTF8Put(strm2, (key.CharAt(i))^Wallet_GetKey());
|
||||
}
|
||||
Wallet_UTF8Put(strm2, (key.CharAt(0))^Wallet_GetKey());
|
||||
}
|
||||
strm2.flush();
|
||||
strm2.close();
|
||||
Wallet_RestartKey();
|
||||
keySet = PR_TRUE;
|
||||
return PR_TRUE;
|
||||
|
||||
/* Either key is to be changed or the file containing the saved key doesn't exist */
|
||||
/* In either case we need to (re)create and re(write) the file */
|
||||
return wallet_WriteKeyFile(useDefaultKey);
|
||||
} else {
|
||||
|
||||
/* file of saved key existed so see if it matches the key the user typed in */
|
||||
|
||||
/*
|
||||
* Note that eof() is not set until after we read past the end of the file. That
|
||||
* is why the following code reads a character and immediately after the read
|
||||
* checks for eof()
|
||||
*/
|
||||
|
||||
/* test for a null key */
|
||||
if (useDefaultKey && (Wallet_KeySize() == 0) ) {
|
||||
Wallet_RestartKey();
|
||||
keySet = PR_TRUE;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsFileSpec dirSpec;
|
||||
nsresult rval = Wallet_ProfileDirectory(dirSpec);
|
||||
if (NS_FAILED(rval)) {
|
||||
keyCancel = PR_TRUE;
|
||||
if (!wallet_ReadKeyFile(useDefaultKey)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
nsInputFileStream strm(dirSpec + keyFileName);
|
||||
Wallet_RestartKey();
|
||||
|
||||
for (PRInt32 j = 1; j < key.Length(); j++) {
|
||||
if (Wallet_UTF8Get(strm) != ((key.CharAt(j))^Wallet_GetKey()) || strm.eof()) {
|
||||
strm.close();
|
||||
key = nsAutoString("");
|
||||
keyCancel = PR_FALSE;
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
if (Wallet_UTF8Get(strm) != ((key.CharAt(0))^Wallet_GetKey()) || strm.eof()) {
|
||||
strm.close();
|
||||
key = nsAutoString("");
|
||||
keyCancel = PR_FALSE;
|
||||
return PR_FALSE;
|
||||
}
|
||||
Wallet_UTF8Get(strm); /* to get past the end of the file so eof() will get set */
|
||||
PRBool rv = strm.eof();
|
||||
strm.close();
|
||||
if (rv) {
|
||||
Wallet_RestartKey();
|
||||
keySet = PR_TRUE;
|
||||
keyExpiresTime = time(NULL) + keyDuration;
|
||||
return PR_TRUE;
|
||||
} else {
|
||||
key = nsAutoString("");
|
||||
keyCancel = PR_TRUE;
|
||||
return PR_FALSE;
|
||||
/* it matched so migrate old keyfile if necessary */
|
||||
if (wallet_IsOldKeyFormat()) {
|
||||
return wallet_WriteKeyFile(useDefaultKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1611,19 +1667,27 @@ Wallet_SetKey(PRBool isNewkey) {
|
|||
/* The following routines are for accessing the files */
|
||||
/******************************************************/
|
||||
|
||||
#define HEADER_VERSION_1 "#1"
|
||||
|
||||
/*
|
||||
* get a line from a file
|
||||
* return -1 if end of file reached
|
||||
* strip carriage returns and line feeds from end of line
|
||||
*/
|
||||
PRInt32
|
||||
wallet_GetLine(nsInputFileStream strm, nsAutoString& line, PRBool obscure) {
|
||||
wallet_GetLine(nsInputFileStream strm, nsAutoString& line, PRBool obscure,
|
||||
PRInt64 saveCount = 0, PRInt64 *readCount = 0, PRBool inHeader = PR_FALSE) {
|
||||
|
||||
/* read the line */
|
||||
line = "";
|
||||
PRUnichar c;
|
||||
for (;;) {
|
||||
c = Wallet_UTF8Get(strm)^(obscure ? Wallet_GetKey() : (PRUnichar)0);
|
||||
if (inHeader) {
|
||||
c = Wallet_UTF8Get(strm);
|
||||
} else {
|
||||
c = Wallet_UTF8Get(strm)^
|
||||
(obscure ? Wallet_GetKey(saveCount, (*readCount)++) : (PRUnichar)0);
|
||||
}
|
||||
if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
|
@ -1641,16 +1705,100 @@ wallet_GetLine(nsInputFileStream strm, nsAutoString& line, PRBool obscure) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
wallet_GetHeader(nsInputFileStream strm, PRInt64& saveCount, PRInt64& readCount){
|
||||
nsAutoString format;
|
||||
nsAutoString buffer;
|
||||
PRInt64 temp;
|
||||
PRInt32 error;
|
||||
|
||||
/* format revision number */
|
||||
if (NS_FAILED(wallet_GetLine(strm, format, PR_FALSE, 0, 0, PR_TRUE))) {
|
||||
return;
|
||||
}
|
||||
if (format != HEADER_VERSION_1) {
|
||||
/* something's wrong */
|
||||
return;
|
||||
}
|
||||
|
||||
/* saveCount */
|
||||
if (NS_FAILED(wallet_GetLine(strm, buffer, PR_FALSE, 0, 0, PR_TRUE))) {
|
||||
return;
|
||||
}
|
||||
temp = (PRInt64)(buffer.ToInteger(&error));
|
||||
if (error) {
|
||||
return;
|
||||
}
|
||||
saveCount = temp<<32;
|
||||
|
||||
if (NS_FAILED(wallet_GetLine(strm, buffer, PR_FALSE, 0, 0, PR_TRUE))) {
|
||||
return;
|
||||
}
|
||||
temp = (PRInt64)(buffer.ToInteger(&error));
|
||||
if (error) {
|
||||
return;
|
||||
}
|
||||
saveCount += (PRInt64)(buffer.ToInteger(&error));
|
||||
|
||||
/* readCount */
|
||||
if (NS_FAILED(wallet_GetLine(strm, buffer, PR_FALSE, 0, 0, PR_TRUE))) {
|
||||
return;
|
||||
}
|
||||
temp = (PRInt64)(buffer.ToInteger(&error));
|
||||
if (error) {
|
||||
return;
|
||||
}
|
||||
readCount = temp<<32;
|
||||
|
||||
if (NS_FAILED(wallet_GetLine(strm, buffer, PR_FALSE, 0, 0, PR_TRUE))) {
|
||||
return;
|
||||
}
|
||||
temp = (PRInt64)(buffer.ToInteger(&error));
|
||||
if (error) {
|
||||
return;
|
||||
}
|
||||
readCount += (PRInt64)(buffer.ToInteger(&error));
|
||||
}
|
||||
|
||||
/*
|
||||
* Write a line to a file
|
||||
*/
|
||||
void
|
||||
wallet_PutLine(nsOutputFileStream strm, const nsAutoString& line, PRBool obscure)
|
||||
wallet_PutLine(nsOutputFileStream strm, const nsAutoString& line, PRBool obscure,
|
||||
PRInt64 saveCount = 0, PRInt64 *writeCount = 0, PRBool inHeader = PR_FALSE)
|
||||
{
|
||||
for (int i=0; i<line.Length(); i++) {
|
||||
Wallet_UTF8Put(strm, line.CharAt(i)^(obscure ? Wallet_GetKey() : (PRUnichar)0));
|
||||
if (inHeader) {
|
||||
Wallet_UTF8Put(strm, line.CharAt(i));
|
||||
} else {
|
||||
Wallet_UTF8Put(strm, line.CharAt(i)^(obscure ? Wallet_GetKey(saveCount, (*writeCount)++) : (PRUnichar)0));
|
||||
}
|
||||
}
|
||||
Wallet_UTF8Put(strm, '\n'^(obscure ? Wallet_GetKey() : (PRUnichar)0));
|
||||
Wallet_UTF8Put(strm, '\n'^(obscure ? Wallet_GetKey(saveCount, (*writeCount)++) : (PRUnichar)0));
|
||||
}
|
||||
|
||||
void
|
||||
wallet_PutHeader(nsOutputFileStream strm, PRInt64 saveCount, PRInt64 writeCount){
|
||||
|
||||
/* format revision number */
|
||||
wallet_PutLine(strm, nsAutoString(HEADER_VERSION_1), PR_FALSE, 0, 0, PR_TRUE);
|
||||
|
||||
/* saveCount */
|
||||
nsAutoString buffer;
|
||||
buffer = "";
|
||||
buffer.Append(PRInt32(saveCount>>32),10);
|
||||
wallet_PutLine(strm, buffer, PR_FALSE, 0, 0, PR_TRUE);
|
||||
buffer = "";
|
||||
buffer.Append(PRInt32((saveCount<<32)>>32),10);
|
||||
wallet_PutLine(strm, buffer, PR_FALSE, 0, 0, PR_TRUE);
|
||||
|
||||
/* writeCount */
|
||||
buffer = "";
|
||||
buffer.Append(PRInt32(writeCount>>32),10);
|
||||
wallet_PutLine(strm, buffer, PR_FALSE, 0, 0, PR_TRUE);
|
||||
buffer = "";
|
||||
buffer.Append(PRInt32((writeCount<<32)>>32),10);
|
||||
wallet_PutLine(strm, buffer, PR_FALSE, 0, 0, PR_TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1670,6 +1818,14 @@ wallet_WriteToFile(char* filename, nsVoidArray* list, PRBool obscure) {
|
|||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (filename == schemaValueFileName && wallet_oldFormat) {
|
||||
/* change name of schemaValueFileName file from "xxxxxxxx.wlt" to "xxxxxxxx.w" */
|
||||
schemaValueFileName[10] = '\0';
|
||||
SI_SetCharPref(pref_WalletSchemaValueFileName, schemaValueFileName);
|
||||
wallet_oldFormat = PR_FALSE;
|
||||
}
|
||||
|
||||
nsOutputFileStream strm(dirSpec + filename);
|
||||
if (!strm.is_open()) {
|
||||
NS_ERROR("unable to open file");
|
||||
|
@ -1680,24 +1836,30 @@ wallet_WriteToFile(char* filename, nsVoidArray* list, PRBool obscure) {
|
|||
if(!list) {
|
||||
return;
|
||||
}
|
||||
Wallet_RestartKey();
|
||||
PRInt64 saveCount = 0;
|
||||
PRInt64 writeCount = 0;
|
||||
|
||||
/* put out the header */
|
||||
if (filename == schemaValueFileName) {
|
||||
wallet_PutHeader(strm, saveCount, writeCount);
|
||||
}
|
||||
|
||||
/* traverse the list */
|
||||
PRInt32 count = LIST_COUNT(list);
|
||||
for (PRInt32 i=0; i<count; i++) {
|
||||
ptr = NS_STATIC_CAST(wallet_MapElement*, list->ElementAt(i));
|
||||
wallet_PutLine(strm, (*ptr).item1, obscure);
|
||||
wallet_PutLine(strm, (*ptr).item1, obscure, saveCount, &writeCount);
|
||||
if ((*ptr).item2 != "") {
|
||||
wallet_PutLine(strm, (*ptr).item2, obscure);
|
||||
wallet_PutLine(strm, (*ptr).item2, obscure, saveCount, &writeCount);
|
||||
} else {
|
||||
wallet_Sublist * ptr1;
|
||||
PRInt32 count2 = LIST_COUNT(ptr->itemList);
|
||||
for (PRInt32 j=0; j<count2; j++) {
|
||||
ptr1 = NS_STATIC_CAST(wallet_Sublist*, ptr->itemList->ElementAt(j));
|
||||
wallet_PutLine(strm, (*ptr1).item, obscure);
|
||||
wallet_PutLine(strm, (*ptr1).item, obscure, saveCount, &writeCount);
|
||||
}
|
||||
}
|
||||
wallet_PutLine(strm, "", obscure);
|
||||
wallet_PutLine(strm, "", obscure, saveCount, &writeCount);
|
||||
}
|
||||
|
||||
/* close the stream */
|
||||
|
@ -1728,23 +1890,29 @@ wallet_ReadFromFile
|
|||
/* file doesn't exist -- that's not an error */
|
||||
return;
|
||||
}
|
||||
Wallet_RestartKey();
|
||||
PRInt64 saveCount = 0;
|
||||
PRInt64 readCount = 0;
|
||||
|
||||
/* read in the header */
|
||||
if (filename == schemaValueFileName && !wallet_oldFormat) {
|
||||
wallet_GetHeader(strm, saveCount, readCount);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
nsAutoString item1;
|
||||
if (NS_FAILED(wallet_GetLine(strm, item1, obscure))) {
|
||||
if (NS_FAILED(wallet_GetLine(strm, item1, obscure, saveCount, &readCount))) {
|
||||
/* end of file reached */
|
||||
break;
|
||||
}
|
||||
|
||||
nsAutoString item2;
|
||||
if (NS_FAILED(wallet_GetLine(strm, item2, obscure))) {
|
||||
if (NS_FAILED(wallet_GetLine(strm, item2, obscure, saveCount, &readCount))) {
|
||||
/* unexpected end of file reached */
|
||||
break;
|
||||
}
|
||||
|
||||
nsAutoString item3;
|
||||
if (NS_FAILED(wallet_GetLine(strm, item3, obscure))) {
|
||||
if (NS_FAILED(wallet_GetLine(strm, item3, obscure, saveCount, &readCount))) {
|
||||
/* end of file reached */
|
||||
nsVoidArray* dummy = NULL;
|
||||
wallet_WriteToList(item1, item2, dummy, list, placement);
|
||||
|
@ -1779,7 +1947,7 @@ wallet_ReadFromFile
|
|||
for (;;) {
|
||||
/* get next item for sublist */
|
||||
item3 = "";
|
||||
if (NS_FAILED(wallet_GetLine(strm, item3, obscure))) {
|
||||
if (NS_FAILED(wallet_GetLine(strm, item3, obscure, saveCount, &readCount))) {
|
||||
/* end of file reached */
|
||||
wallet_WriteToList(item1, dummy2, itemList, list, placement);
|
||||
strm.close();
|
||||
|
@ -1821,7 +1989,6 @@ wallet_ReadFromURLFieldToSchemaFile
|
|||
/* file doesn't exist -- that's not an error */
|
||||
return;
|
||||
}
|
||||
/* Wallet_RestartKey(); not needed since file is not encoded */
|
||||
|
||||
/* make sure the list exists */
|
||||
if(!list) {
|
||||
|
@ -2453,7 +2620,6 @@ wallet_Initialize(PRBool fetchTables) {
|
|||
}
|
||||
|
||||
if (!wallet_keyInitialized) {
|
||||
Wallet_RestartKey();
|
||||
PRUnichar * message = Wallet_Localize("IncorrectKey_TryAgain?");
|
||||
while (!Wallet_SetKey(PR_FALSE)) {
|
||||
if (Wallet_CancelKey() || (Wallet_KeySize() < 0) || !Wallet_Confirm(message)) {
|
||||
|
@ -2923,15 +3089,24 @@ WLLT_PostEdit(nsAutoString walletList) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (wallet_oldFormat) {
|
||||
/* change name of schemaValueFileName file from "xxxxxxxx.wlt" to "xxxxxxxx.w" */
|
||||
schemaValueFileName[10] = '\0';
|
||||
SI_SetCharPref(pref_WalletSchemaValueFileName, schemaValueFileName);
|
||||
wallet_oldFormat = PR_FALSE;
|
||||
}
|
||||
|
||||
/* open SchemaValue file */
|
||||
nsOutputFileStream strm(dirSpec + schemaValueFileName);
|
||||
if (!strm.is_open()) {
|
||||
NS_ERROR("unable to open file");
|
||||
return;
|
||||
}
|
||||
Wallet_RestartKey();
|
||||
PRInt64 saveCount = 0;
|
||||
PRInt64 writeCount = 0;
|
||||
|
||||
/* write the values in the walletList to the file */
|
||||
wallet_PutHeader(strm, saveCount, writeCount);
|
||||
for (;;) {
|
||||
separator = tail.FindChar(BREAK);
|
||||
if (-1 == separator) {
|
||||
|
@ -2941,7 +3116,7 @@ WLLT_PostEdit(nsAutoString walletList) {
|
|||
tail.Mid(temp, separator+1, tail.Length() - (separator+1));
|
||||
tail = temp;
|
||||
|
||||
wallet_PutLine(strm, head, PR_TRUE);
|
||||
wallet_PutLine(strm, head, PR_TRUE, saveCount, &writeCount);
|
||||
}
|
||||
|
||||
/* close the file and read it back into the SchemaToValue list */
|
||||
|
|
Загрузка…
Ссылка в новой задаче