зеркало из https://github.com/mozilla/pjs.git
use thayes encryption routines
This commit is contained in:
Родитель
cf392312f9
Коммит
aa4dffcef8
|
@ -24,6 +24,7 @@
|
||||||
/* universal global variables */
|
/* universal global variables */
|
||||||
|
|
||||||
var walleteditor = null; // walleteditor interface
|
var walleteditor = null; // walleteditor interface
|
||||||
|
var walletservice = null; // walletservices interface
|
||||||
var walletList = []; // input stream
|
var walletList = []; // input stream
|
||||||
var bundle = null; // string bundle
|
var bundle = null; // string bundle
|
||||||
var JS_STRINGS_FILE = "chrome://communicator/locale/wallet/WalletEditor.properties";
|
var JS_STRINGS_FILE = "chrome://communicator/locale/wallet/WalletEditor.properties";
|
||||||
|
@ -49,13 +50,49 @@ function ViewSynonymsFromXul(){
|
||||||
|
|
||||||
/*** =================== STARTING AND STOPPING =================== ***/
|
/*** =================== STARTING AND STOPPING =================== ***/
|
||||||
|
|
||||||
|
/* decrypt a value */
|
||||||
|
function Decrypt(crypt) {
|
||||||
|
try {
|
||||||
|
return walletservice.WALLET_Decrypt(crypt);
|
||||||
|
} catch (ex) {
|
||||||
|
return bundle.GetStringFromName("EncryptionFailure");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* encrypt a value */
|
||||||
|
function Encrypt(text) {
|
||||||
|
try {
|
||||||
|
return walletservice.WALLET_Encrypt(text);
|
||||||
|
} catch (ex) {
|
||||||
|
alert(bundle.GetStringFromName("UnableToUnlockDatabase"));
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* see if user was able to unlock the database */
|
||||||
|
function EncryptionTest() {
|
||||||
|
try {
|
||||||
|
walletservice.WALLET_Encrypt("dummy");
|
||||||
|
} catch (ex) {
|
||||||
|
alert(bundle.GetStringFromName("UnableToUnlockDatabase"));
|
||||||
|
window.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* initializes the wallet editor dialog */
|
/* initializes the wallet editor dialog */
|
||||||
function Startup()
|
function Startup()
|
||||||
{
|
{
|
||||||
walleteditor = Components.classes["component://netscape/walleteditor/walleteditor-world"].createInstance();
|
walleteditor = Components.classes["component://netscape/walleteditor/walleteditor-world"].createInstance();
|
||||||
walleteditor = walleteditor.QueryInterface(Components.interfaces.nsIWalletEditor);
|
walleteditor = walleteditor.QueryInterface(Components.interfaces.nsIWalletEditor);
|
||||||
|
|
||||||
|
walletservice = Components.classes['component://netscape/wallet'];
|
||||||
|
walletservice = walletservice.getService();
|
||||||
|
walletservice = walletservice.QueryInterface(Components.interfaces.nsIWalletService);
|
||||||
|
|
||||||
bundle = srGetStrBundle(JS_STRINGS_FILE); /* initialize string bundle */
|
bundle = srGetStrBundle(JS_STRINGS_FILE); /* initialize string bundle */
|
||||||
|
|
||||||
|
EncryptionTest(); /* abort if user failed to unlock the database */
|
||||||
|
|
||||||
if (!FetchInput()) {
|
if (!FetchInput()) {
|
||||||
return; /* user failed to unlock the database */
|
return; /* user failed to unlock the database */
|
||||||
}
|
}
|
||||||
|
@ -121,7 +158,7 @@ function FetchInput()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entries[j] = stringsLength;
|
entries[j] = stringsLength-1;
|
||||||
j = 0;
|
j = 0;
|
||||||
for (i=0; i<entriesLength; i++) {
|
for (i=0; i<entriesLength; i++) {
|
||||||
if (i == 0 || (strings[entries[i]] != strings[entries[i-1]])) {
|
if (i == 0 || (strings[entries[i]] != strings[entries[i-1]])) {
|
||||||
|
@ -381,7 +418,8 @@ function ViewEntries()
|
||||||
var lastPlusOne = schemas[FirstSelectedSchema()+1];
|
var lastPlusOne = schemas[FirstSelectedSchema()+1];
|
||||||
for (i=first; i<lastPlusOne; i++) {
|
for (i=first; i<lastPlusOne; i++) {
|
||||||
if (strings[entries[i]+1] != "") {
|
if (strings[entries[i]+1] != "") {
|
||||||
AddItem("entrieslist", [strings[entries[i]+1]], "tree_", i-first);
|
var text = Decrypt(strings[entries[i]+1]);
|
||||||
|
AddItem("entrieslist", [text], "tree_", i-first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SchemaSelected();
|
SchemaSelected();
|
||||||
|
@ -401,7 +439,8 @@ function ViewSynonyms()
|
||||||
var first = entries[schemas[FirstSelectedSchema()]+FirstSelectedEntry()]+2;
|
var first = entries[schemas[FirstSelectedSchema()]+FirstSelectedEntry()]+2;
|
||||||
var lastPlusOne = entries[schemas[FirstSelectedSchema()]+FirstSelectedEntry()+1]-1;
|
var lastPlusOne = entries[schemas[FirstSelectedSchema()]+FirstSelectedEntry()+1]-1;
|
||||||
for (i=first; i<lastPlusOne; i++) {
|
for (i=first; i<lastPlusOne; i++) {
|
||||||
AddItem("synonymslist", [strings[i]], "tree_", i-first);
|
var text = Decrypt(strings[i]);
|
||||||
|
AddItem("synonymslist", [text], "tree_", i-first);
|
||||||
}
|
}
|
||||||
EntrySelected();
|
EntrySelected();
|
||||||
}
|
}
|
||||||
|
@ -532,14 +571,19 @@ function AddEntry0() {
|
||||||
if (text == "") {
|
if (text == "") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var crypt = Encrypt(text);
|
||||||
|
if (crypt == "") {
|
||||||
|
/* user failed to unlock the database */
|
||||||
|
return;
|
||||||
|
}
|
||||||
stringIndex = entries[schemas[FirstSelectedSchema()]+FirstSelectedEntry()];
|
stringIndex = entries[schemas[FirstSelectedSchema()]+FirstSelectedEntry()];
|
||||||
if(strings[entries[schemas[FirstSelectedSchema()]+FirstSelectedEntry()]+1]=="") {
|
if(strings[entries[schemas[FirstSelectedSchema()]+FirstSelectedEntry()]+1]=="") {
|
||||||
addString(entries[schemas[FirstSelectedSchema()]+FirstSelectedEntry()]+1, text);
|
addString(entries[schemas[FirstSelectedSchema()]+FirstSelectedEntry()]+1, crypt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addString(stringIndex, strings[entries[schemas[FirstSelectedSchema()]]]);
|
addString(stringIndex, strings[entries[schemas[FirstSelectedSchema()]]]);
|
||||||
addString(stringIndex+1, text);
|
addString(stringIndex+1, crypt);
|
||||||
addString(stringIndex+2, "");
|
addString(stringIndex+2, "");
|
||||||
|
|
||||||
entriesLength++;
|
entriesLength++;
|
||||||
|
@ -559,7 +603,12 @@ function AddSynonym0() {
|
||||||
if (text == "") {
|
if (text == "") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
addString(entries[schemas[FirstSelectedSchema()]+FirstSelectedEntry()]+2, text);
|
var crypt = Encrypt(text);
|
||||||
|
if (crypt == "") {
|
||||||
|
/* user failed to unlock the database */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
addString(entries[schemas[FirstSelectedSchema()]+FirstSelectedEntry()]+2, crypt);
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteString(stringToDelete) {
|
function deleteString(stringToDelete) {
|
||||||
|
|
|
@ -21,3 +21,5 @@
|
||||||
EnterNewSchema=Enter a new field name
|
EnterNewSchema=Enter a new field name
|
||||||
EnterNewEntry=Enter a new value for the field
|
EnterNewEntry=Enter a new value for the field
|
||||||
EnterNewSynonym=Enter another value that means the same thing
|
EnterNewSynonym=Enter another value that means the same thing
|
||||||
|
EncryptionFailure=Encryption Failure
|
||||||
|
UnableToUnlockDatabase=Unable to unlock database
|
|
@ -70,4 +70,7 @@ interface nsIWalletService : nsISupports {
|
||||||
[noscript] void SI_GetSignonListForViewer(in nsAutoStringRef aSignonList);
|
[noscript] void SI_GetSignonListForViewer(in nsAutoStringRef aSignonList);
|
||||||
[noscript] void SI_GetRejectListForViewer(in nsAutoStringRef aRejectList);
|
[noscript] void SI_GetRejectListForViewer(in nsAutoStringRef aRejectList);
|
||||||
[noscript] void SI_SignonViewerReturn(in nsAutoString results);
|
[noscript] void SI_SignonViewerReturn(in nsAutoString results);
|
||||||
|
|
||||||
|
string WALLET_Encrypt(in wstring text);
|
||||||
|
wstring WALLET_Decrypt(in string crypt);
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,19 +25,15 @@
|
||||||
#include "nsIModule.h"
|
#include "nsIModule.h"
|
||||||
#include "nsIGenericFactory.h"
|
#include "nsIGenericFactory.h"
|
||||||
#include "nsWalletService.h"
|
#include "nsWalletService.h"
|
||||||
#include "nsBasicStreamGenerator.h"
|
|
||||||
|
|
||||||
// Define the constructor function for the nsWalletlibService
|
// Define the constructor function for the nsWalletlibService
|
||||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWalletlibService)
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWalletlibService)
|
||||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBasicStreamGenerator)
|
|
||||||
|
|
||||||
|
|
||||||
// The list of components we register
|
// The list of components we register
|
||||||
static nsModuleComponentInfo components[] = {
|
static nsModuleComponentInfo components[] = {
|
||||||
{ NS_WALLETSERVICE_CLASSNAME, NS_WALLETSERVICE_CID,
|
{ NS_WALLETSERVICE_CLASSNAME, NS_WALLETSERVICE_CID,
|
||||||
NS_WALLETSERVICE_PROGID, nsWalletlibServiceConstructor },
|
NS_WALLETSERVICE_PROGID, nsWalletlibServiceConstructor },
|
||||||
{ NS_BASIC_STREAM_GENERATOR_CLASSNAME, NS_BASIC_STREAM_GENERATOR_CID,
|
|
||||||
NS_BASIC_STREAM_GENERATOR_PROGID, nsBasicStreamGeneratorConstructor },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_IMPL_NSGETMODULE("nsWalletModule", components)
|
NS_IMPL_NSGETMODULE("nsWalletModule", components)
|
||||||
|
|
|
@ -43,9 +43,6 @@
|
||||||
|
|
||||||
static NS_DEFINE_IID(kDocLoaderServiceCID, NS_DOCUMENTLOADER_SERVICE_CID);
|
static NS_DEFINE_IID(kDocLoaderServiceCID, NS_DOCUMENTLOADER_SERVICE_CID);
|
||||||
|
|
||||||
// Defined and used in wallet.cpp
|
|
||||||
extern nsIKeyedStreamGenerator *gKeyedStreamGenerator;
|
|
||||||
|
|
||||||
nsWalletlibService::nsWalletlibService()
|
nsWalletlibService::nsWalletlibService()
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
|
@ -59,16 +56,13 @@ nsWalletlibService::~nsWalletlibService()
|
||||||
#ifdef DEBUG_dp
|
#ifdef DEBUG_dp
|
||||||
printf("Wallet Service destroyed successfully.\n");
|
printf("Wallet Service destroyed successfully.\n");
|
||||||
#endif /* DEBUG_dp */
|
#endif /* DEBUG_dp */
|
||||||
// Release the keyed stream generator that we might have acquired
|
|
||||||
NS_IF_RELEASE(gKeyedStreamGenerator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_THREADSAFE_ISUPPORTS6(nsWalletlibService,
|
NS_IMPL_THREADSAFE_ISUPPORTS5(nsWalletlibService,
|
||||||
nsIWalletService,
|
nsIWalletService,
|
||||||
nsIObserver,
|
nsIObserver,
|
||||||
nsIFormSubmitObserver,
|
nsIFormSubmitObserver,
|
||||||
nsIDocumentLoaderObserver,
|
nsIDocumentLoaderObserver,
|
||||||
nsIPasswordSink,
|
|
||||||
nsISupportsWeakReference)
|
nsISupportsWeakReference)
|
||||||
|
|
||||||
NS_IMETHODIMP nsWalletlibService::WALLET_PreEdit(nsAutoString& walletList) {
|
NS_IMETHODIMP nsWalletlibService::WALLET_PreEdit(nsAutoString& walletList) {
|
||||||
|
@ -391,7 +385,7 @@ nsWalletlibService::OnEndURLLoad
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsWalletlibService::GetPassword(PRUnichar **password)
|
nsWalletlibService::GetPassword(PRUnichar **password)
|
||||||
{
|
{
|
||||||
return Wallet_GetMasterPassword(password);
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -399,3 +393,21 @@ nsWalletlibService::HaveData(const char *url, const PRUnichar *userName, PRBool
|
||||||
{
|
{
|
||||||
return ::SINGSIGN_HaveData(url, userName, stripUrl, _retval);
|
return ::SINGSIGN_HaveData(url, userName, stripUrl, _retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsWalletlibService::WALLET_Encrypt (const PRUnichar *text, char **crypt) {
|
||||||
|
nsAutoString textAutoString = text;
|
||||||
|
nsAutoString cryptAutoString;
|
||||||
|
PRBool rv = ::Wallet_Encrypt(textAutoString, cryptAutoString);
|
||||||
|
*crypt = cryptAutoString.ToNewCString();
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsWalletlibService::WALLET_Decrypt (const char *crypt, PRUnichar **text) {
|
||||||
|
nsAutoString cryptAutoString = crypt;
|
||||||
|
nsAutoString textAutoString;
|
||||||
|
PRBool rv = ::Wallet_Decrypt(cryptAutoString, textAutoString);
|
||||||
|
*text = textAutoString.ToNewUnicode();
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
|
@ -75,6 +75,9 @@ public:
|
||||||
NS_IMETHOD SI_GetRejectListForViewer(nsAutoString& aRejectList);
|
NS_IMETHOD SI_GetRejectListForViewer(nsAutoString& aRejectList);
|
||||||
NS_IMETHOD SI_SignonViewerReturn(nsAutoString results);
|
NS_IMETHOD SI_SignonViewerReturn(nsAutoString results);
|
||||||
|
|
||||||
|
NS_IMETHOD WALLET_Encrypt (const PRUnichar *text, char **crypt);
|
||||||
|
NS_IMETHOD WALLET_Decrypt (const char *crypt, PRUnichar **text);
|
||||||
|
|
||||||
// nsIObserver
|
// nsIObserver
|
||||||
NS_DECL_NSIOBSERVER
|
NS_DECL_NSIOBSERVER
|
||||||
NS_IMETHOD Notify(nsIContent* formNode, nsIDOMWindow* window, nsIURI* actionURL);
|
NS_IMETHOD Notify(nsIContent* formNode, nsIDOMWindow* window, nsIURI* actionURL);
|
||||||
|
|
|
@ -73,8 +73,11 @@ WLLT_FetchFromNetCenter();
|
||||||
extern void
|
extern void
|
||||||
WLLT_ExpirePassword();
|
WLLT_ExpirePassword();
|
||||||
|
|
||||||
extern NS_METHOD
|
extern nsresult
|
||||||
Wallet_GetMasterPassword(PRUnichar **password);
|
Wallet_Encrypt (nsAutoString text, nsAutoString& crypt);
|
||||||
|
|
||||||
|
extern nsresult
|
||||||
|
Wallet_Decrypt (nsAutoString crypt, nsAutoString& text);
|
||||||
|
|
||||||
XP_END_PROTOS
|
XP_END_PROTOS
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче