From d0a1fa6febaf39f100668d4dbb464953a12c0ae1 Mon Sep 17 00:00:00 2001 From: "thayes%netscape.com" Date: Thu, 11 May 2000 18:59:25 +0000 Subject: [PATCH] Land SDR changes from SDR_BRANCH. Enable calls to new interface functions in wallet. git-svn-id: svn://10.0.0.236/trunk@69226 18797224-902f-48f8-a5cc-f745e15eee43 --- .../psm-glue/public/nsISecretDecoderRing.idl | 6 ++ .../psm-glue/src/nsPSMUICallbacks.cpp | 7 +- mozilla/extensions/psm-glue/src/nsSDR.cpp | 66 +++++++++++++++++++ mozilla/extensions/wallet/src/wallet.cpp | 4 +- 4 files changed, 78 insertions(+), 5 deletions(-) diff --git a/mozilla/extensions/psm-glue/public/nsISecretDecoderRing.idl b/mozilla/extensions/psm-glue/public/nsISecretDecoderRing.idl index 0bf83da28bc..4c0dbf1ca47 100644 --- a/mozilla/extensions/psm-glue/public/nsISecretDecoderRing.idl +++ b/mozilla/extensions/psm-glue/public/nsISecretDecoderRing.idl @@ -42,6 +42,12 @@ interface nsISecretDecoderRing: nsISupports { /* Decrypt BASE64 input to nul-terminated string output */ /* There is no check for embedded nul values in the decrypted output */ string decryptString(in string crypt); + + /* Prompt the user to change the password on the SDR key */ + void changePassword(); + + /* Logout of the security device that protects the SDR key */ + void logout(); }; /* diff --git a/mozilla/extensions/psm-glue/src/nsPSMUICallbacks.cpp b/mozilla/extensions/psm-glue/src/nsPSMUICallbacks.cpp index 3386ddfda9a..d1b1e9cd789 100644 --- a/mozilla/extensions/psm-glue/src/nsPSMUICallbacks.cpp +++ b/mozilla/extensions/psm-glue/src/nsPSMUICallbacks.cpp @@ -54,7 +54,8 @@ static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID); static char * PromptUserCallback(void *arg, char *prompt, int isPasswd); static char * FilePathPromptCallback(void *arg, char *prompt, char *fileRegEx, CMUint32 shouldFileExist); static void ApplicationFreeCallback(char *userInput); -static void * CartmanUIHandler(uint32 resourceID, void* clientContext, uint32 width, uint32 height, char* urlStr, void *data); +static void * CartmanUIHandler(uint32 resourceID, void* clientContext, uint32 width, uint32 height, PRBool isModel, + char* urlStr, void *data); extern "C" void CARTMAN_UIEventLoop(void *data); @@ -265,7 +266,7 @@ PRStatus DisplayPSMUIDialog(PCMT_CONTROL control, const char *pickledStatus, con return PR_FAILURE; /* Fire the URL up in a window of its own. */ - pwin = CartmanUIHandler(advRID, nsnull, width, height, (char*)urlItem.data, NULL); + pwin = CartmanUIHandler(advRID, nsnull, width, height, PR_FALSE, (char*)urlItem.data, NULL); //allocated by cmt, we can free with free: free(urlItem.data); @@ -275,7 +276,7 @@ PRStatus DisplayPSMUIDialog(PCMT_CONTROL control, const char *pickledStatus, con -void* CartmanUIHandler(uint32 resourceID, void* clientContext, uint32 width, uint32 height, char* urlStr, void *data) +void* CartmanUIHandler(uint32 resourceID, void* clientContext, uint32 width, uint32 height, PRBool isModal, char* urlStr, void *data) { nsresult rv = NS_OK; diff --git a/mozilla/extensions/psm-glue/src/nsSDR.cpp b/mozilla/extensions/psm-glue/src/nsSDR.cpp index 79d421996d1..28b3265fe0a 100644 --- a/mozilla/extensions/psm-glue/src/nsSDR.cpp +++ b/mozilla/extensions/psm-glue/src/nsSDR.cpp @@ -26,6 +26,8 @@ #include "nsIAllocator.h" #include "nsIServiceManager.h" +#include "plbase64.h" + #include "nsISecretDecoderRing.h" #include "cmtcmn.h" @@ -195,10 +197,53 @@ loser: return rv; } +/* void changePassword(); */ +NS_IMETHODIMP nsSecretDecoderRing:: +ChangePassword() +{ + return NS_OK; +} + +/* void logout(); */ +NS_IMETHODIMP nsSecretDecoderRing:: +Logout() +{ + nsresult rv = NS_OK; + CMTStatus status; + CMT_CONTROL *control; + + /* Check object initialization */ + NS_ASSERTION(mPSM != nsnull, "SDR object not initialized"); + if (mPSM == nsnull) { rv = NS_ERROR_NOT_INITIALIZED; goto loser; } + + /* Get the control connection */ + rv = mPSM->GetControlConnection(&control); + if (rv != NS_OK) { rv = NS_ERROR_NOT_AVAILABLE; goto loser; } + + /* Call PSM to decrypt the value */ + status = CMT_LogoutAllTokens(control); + if (status != CMTSuccess) { rv = NS_ERROR_FAILURE; goto loser; } /* Promote? */ + +loser: + return rv; +} + + +// Support routines + nsresult nsSecretDecoderRing:: encode(const unsigned char *data, PRInt32 dataLen, char **_retval) { nsresult rv = NS_OK; + + *_retval = PL_Base64Encode((const char *)data, dataLen, NULL); + if (!*_retval) { rv = NS_ERROR_OUT_OF_MEMORY; goto loser; } + +loser: + return rv; + +#if 0 + nsresult rv = NS_OK; char *r = 0; // Allocate space for encoded string (with NUL) @@ -215,11 +260,31 @@ loser: if (r) nsAllocator::Free(r); return rv; +#endif } nsresult nsSecretDecoderRing:: decode(const char *data, unsigned char **result, PRInt32 * _retval) { + nsresult rv = NS_OK; + PRUint32 len = PL_strlen(data); + int adjust = 0; + + /* Compute length adjustment */ + if (data[len-1] == '=') { + adjust++; + if (data[len-2] == '=') adjust++; + } + + *result = (unsigned char *)PL_Base64Decode(data, len, NULL); + if (!*result) { rv = NS_ERROR_ILLEGAL_VALUE; goto loser; } + + *_retval = (len*3)/4 - adjust; + +loser: + return rv; + +#if 0 nsresult rv = NS_OK; unsigned char *r = 0; PRInt32 rLen; @@ -239,6 +304,7 @@ loser: if (r) nsAllocator::Free(r); return rv; +#endif } const char * nsSecretDecoderRing::kPSMComponentProgID = PSM_COMPONENT_PROGID; diff --git a/mozilla/extensions/wallet/src/wallet.cpp b/mozilla/extensions/wallet/src/wallet.cpp index 353254923ae..b7bf303a50a 100644 --- a/mozilla/extensions/wallet/src/wallet.cpp +++ b/mozilla/extensions/wallet/src/wallet.cpp @@ -1092,7 +1092,7 @@ PUBLIC void WLLT_ExpirePassword() { nsresult rv = wallet_CryptSetup(); if (NS_SUCCEEDED(rv)) { -// rv = gSecretDecoderRing->Logout(); + rv = gSecretDecoderRing->Logout(); } PRUnichar * message; if (NS_FAILED(rv)) { @@ -1108,7 +1108,7 @@ PUBLIC void WLLT_ChangePassword() { nsresult rv = wallet_CryptSetup(); if (NS_SUCCEEDED(rv)) { -// rv = gSecretDecoderRing->ChangePassword(); + rv = gSecretDecoderRing->ChangePassword(); } if (NS_FAILED(rv)) { PRUnichar * message = Wallet_Localize("PasswordNotChanged");