mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Adding native SDR. wince/minimo only.
This commit is contained in:
parent
b95ecf558f
commit
66e5923060
@ -59,7 +59,7 @@ REQUIRES = xpcom \
|
||||
windowwatcher \
|
||||
profile \
|
||||
necko \
|
||||
caps \
|
||||
caps \
|
||||
docshell \
|
||||
dom \
|
||||
widget \
|
||||
@ -83,7 +83,7 @@ REQUIRES = xpcom \
|
||||
|
||||
LOCAL_INCLUDES = -I$(srcdir) -I$(topsrcdir)/security/manager/boot/src
|
||||
|
||||
CPPSRCS = nsSecureBrowserUIImpl.cpp nsNativeSSL.cpp
|
||||
CPPSRCS = nsSecureBrowserUIImpl.cpp nsNativeSSL.cpp nsNativeSDR.cpp
|
||||
|
||||
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS)
|
||||
|
||||
|
228
minimo/components/ssl/nsNativeSDR.cpp
Executable file
228
minimo/components/ssl/nsNativeSDR.cpp
Executable file
@ -0,0 +1,228 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Minimo.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Doug Turner <dougt@meer.net>.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsNativeSDR.h"
|
||||
#include "plbase64.h"
|
||||
|
||||
#include <Wincrypt.h>
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsNativeSDR, nsISecretDecoderRing)
|
||||
|
||||
nsNativeSDR::nsNativeSDR()
|
||||
{
|
||||
}
|
||||
|
||||
nsNativeSDR::~nsNativeSDR()
|
||||
{
|
||||
}
|
||||
|
||||
static nsresult 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;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static nsresult decode(const char *data, unsigned char **result, PRInt32 * _retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
PRUint32 len = 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;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsNativeSDR::Encrypt(unsigned char * data,
|
||||
PRInt32 dataLen,
|
||||
unsigned char * *result,
|
||||
PRInt32 *_retval)
|
||||
{
|
||||
DATA_BLOB DataIn;
|
||||
DATA_BLOB DataOut;
|
||||
|
||||
DataIn.pbData = data;
|
||||
DataIn.cbData = dataLen;
|
||||
|
||||
DataOut.pbData = nsnull;
|
||||
DataOut.cbData = 0;
|
||||
|
||||
BOOL b = CryptProtectData( &DataIn,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
&DataOut);
|
||||
|
||||
|
||||
if (!b)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
unsigned char* out = (unsigned char*) malloc(DataOut.cbData);
|
||||
if (!out)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
memcpy(out, DataOut.pbData, DataOut.cbData);
|
||||
LocalFree(DataOut.pbData);
|
||||
|
||||
*result = out;
|
||||
*_retval = DataOut.cbData;
|
||||
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsNativeSDR::Decrypt(unsigned char * data,
|
||||
PRInt32 dataLen,
|
||||
unsigned char * *result,
|
||||
PRInt32 *_retval)
|
||||
{
|
||||
DATA_BLOB DataIn;
|
||||
DATA_BLOB DataOut;
|
||||
|
||||
DataIn.pbData = data;
|
||||
DataIn.cbData = dataLen;
|
||||
|
||||
DataOut.pbData = nsnull;
|
||||
DataOut.cbData = 0;
|
||||
|
||||
BOOL b = CryptUnprotectData(&DataIn,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
&DataOut);
|
||||
|
||||
if (!b)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
unsigned char* out = (unsigned char*) malloc(DataOut.cbData);
|
||||
if (!out)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
memcpy(out, DataOut.pbData, DataOut.cbData);
|
||||
LocalFree(DataOut.pbData);
|
||||
|
||||
*result = out;
|
||||
*_retval = DataOut.cbData;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsNativeSDR::EncryptString(const char *text, char **_retval)
|
||||
{
|
||||
unsigned char *encrypted = 0;
|
||||
PRInt32 eLen;
|
||||
|
||||
nsresult rv = Encrypt((unsigned char *)text, strlen(text), &encrypted, &eLen);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = encode(encrypted, eLen, _retval);
|
||||
|
||||
if (encrypted)
|
||||
free(encrypted);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsNativeSDR::DecryptString(const char *crypt, char **_retval)
|
||||
{
|
||||
unsigned char *decoded = 0;
|
||||
PRInt32 decodedLen;
|
||||
unsigned char *decrypted = 0;
|
||||
PRInt32 decryptedLen;
|
||||
|
||||
nsresult rv = decode(crypt, &decoded, &decodedLen);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = Decrypt(decoded, decodedLen, &decrypted, &decryptedLen);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
free(decoded);
|
||||
return rv;
|
||||
}
|
||||
|
||||
char *r = (char *)malloc(decryptedLen+1);
|
||||
if (!r)
|
||||
{
|
||||
free(decoded);
|
||||
free(decrypted);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
memcpy(r, decrypted, decryptedLen);
|
||||
r[decryptedLen] = 0;
|
||||
|
||||
*_retval = r;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsNativeSDR::ChangePassword()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsNativeSDR::Logout()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsNativeSDR::LogoutAndTeardown()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
51
minimo/components/ssl/nsNativeSDR.h
Executable file
51
minimo/components/ssl/nsNativeSDR.h
Executable file
@ -0,0 +1,51 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Minimo.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Doug Turner <dougt@meer.net>.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISecretDecoderRing.h"
|
||||
|
||||
class nsNativeSDR : public nsISecretDecoderRing
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISECRETDECODERRING
|
||||
|
||||
nsNativeSDR();
|
||||
|
||||
private:
|
||||
~nsNativeSDR();
|
||||
|
||||
protected:
|
||||
};
|
@ -1,3 +1,39 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Minimo.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Doug Turner <dougt@meer.net>.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
|
||||
@ -19,6 +55,8 @@
|
||||
|
||||
#include "nsSecureBrowserUIImpl.h"
|
||||
|
||||
#include "nsNativeSDR.h"
|
||||
|
||||
#include <Winsock2.h>
|
||||
#include <sslsock.h>
|
||||
#include <Wincrypt.h>
|
||||
@ -470,8 +508,18 @@ nsWINCESSLSocketProvider::AddToSocket(PRInt32 family,
|
||||
{0xbc, 0xa9, 0xda, 0x81, 0x70, 0xfd, 0x8b, 0x58} \
|
||||
}
|
||||
|
||||
|
||||
#define NS_WINCENATIVESDR_CID \
|
||||
{ 0xcba2f351, \
|
||||
0x1993, \
|
||||
0x4b27, \
|
||||
{0xbf, 0x60, 0x4e, 0xbf, 0xce, 0x9a, 0xa3, 0x58} \
|
||||
}
|
||||
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWINCESSLSocketProvider)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSecureBrowserUIImpl)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeSDR)
|
||||
|
||||
static const nsModuleComponentInfo components[] =
|
||||
{
|
||||
@ -488,6 +536,13 @@ static const nsModuleComponentInfo components[] =
|
||||
nsSecureBrowserUIImplConstructor
|
||||
},
|
||||
|
||||
{
|
||||
"Native SDR",
|
||||
NS_WINCENATIVESDR_CID,
|
||||
"@mozilla.org/security/sdr;1",
|
||||
nsNativeSDRConstructor
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE(nsNativeSSLModule, components)
|
||||
|
Loading…
Reference in New Issue
Block a user