#79153. Giving feedback during crypto key generation.

For now, checking in only new files, not yet referenced by any existing code.
Other parts of check in delayed until Mac project files are adjusted.
r=javi@netscape.com sr=blizzard@mozilla.org
You reach me at kai.engert@gmx.de
This commit is contained in:
kaie%netscape.com 2001-08-15 01:53:53 +00:00
Родитель 91fe05f2ce
Коммит 85b356e352
5 изменённых файлов: 392 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,43 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*/
var keygenThread;
function onLoad()
{
keygenThread = window.arguments[0].QueryInterface(Components.interfaces.nsIKeygenThread);
if (!keygenThread) {
window.close();
return;
}
setCursor("wait");
keygenThread.startKeyGeneration(window);
}
function onClose()
{
setCursor("default");
var alreadyClosed = new Object();
keygenThread.userCanceled(alreadyClosed);
}

Просмотреть файл

@ -0,0 +1,39 @@
<?xml version="1.0"?>
<!--
- 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.
-->
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<!DOCTYPE window SYSTEM "chrome://pippki/locale/pippki.dtd">
<window
id="domainMismatch" title="&createCertInfo.title;"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
debug="false"
onload="onLoad();"
onclose="onClose();"
>
<script type="application/x-javascript" src="chrome://global/content/strres.js" />
<script type="application/x-javascript" src="pippki.js" />
<script type="application/x-javascript" src="createCertInfo.js" />
<script type="application/x-javascript" src="chrome://help/content/help.js" />
<box orient="vertical" style="margin: 5px; max-width: 50em;">
<html>&createCertInfo.msg1;</html>
<separator/>
<html style="font-weight: bold; text-align: center; text-decoration: blink;">&createCertInfo.msg2;</html>
<separator/>
</box>
</window>

Просмотреть файл

@ -0,0 +1,57 @@
/*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*/
// make sure to include all the required file headers
#include "nsISupports.idl"
#include "nsIDOMWindowInternal.idl"
/**
* nsIKeygenThread
* This is used to communicate with the thread generating a key pair,
* to be used by the dialog displaying status information.
*/
[scriptable, uuid(195763b8-1dd2-11b2-a843-eb44e44aaa37)]
interface nsIKeygenThread : nsISupports
{
/**
* startKeyGeneration - run the thread
* A user interface implementing this interface needs to
* call this method as soon as the status information
* is displaying. This will trigger key generation.
* To allow the closure of the status information,
* the thread needs a handle to the displayed window.
*/
void startKeyGeneration(in nsIDOMWindowInternal statusDialog);
/**
* userCanceled - notify the thread
* If the user canceled, the thread is no longer allowed to
* close the dialog. However, if the thread already closed
* it, we are not allowed to close it.
*/
void userCanceled(out boolean threadAlreadyClosedDialog);
};
%{ C++
// {195763b8-1dd2-11b2-a843-eb44e44aaa37}
#define NS_KEYGENTHREAD_CID \
{ 0x195763b8, 0x1dd2, 0x11b2, { 0xa8, 0x43, 0xeb, 0x44, 0xe4, 0x4a, 0xaa, 0x37 } }
#define NS_KEYGENTHREAD_CONTRACTID "@mozilla.org/security/keygenthread;1"
%}

Просмотреть файл

@ -0,0 +1,183 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*/
#include "pk11func.h"
#include "nsCOMPtr.h"
#include "nsProxiedService.h"
#include "nsKeygenThread.h"
#include "nsIWidget.h"
NS_IMPL_THREADSAFE_ISUPPORTS1(nsKeygenThread, nsIKeygenThread)
nsKeygenThread::nsKeygenThread()
:mutex(nsnull),
statusDialogPtr(nsnull),
iAmRunning(PR_FALSE),
keygenReady(PR_FALSE),
statusDialogClosed(PR_FALSE),
threadHandle(nsnull),
params(nsnull)
{
mutex = PR_NewLock();
}
nsKeygenThread::~nsKeygenThread()
{
if (mutex)
PR_DestroyLock(mutex);
}
void nsKeygenThread::SetParams(GenerateKeypairParameters *p)
{
PR_Lock(mutex);
params = p;
PR_Unlock(mutex);
}
nsresult nsKeygenThread::StartKeyGeneration(nsIDOMWindowInternal *statusDialog)
{
if (!mutex)
return NS_OK;
if (!statusDialog )
return NS_OK;
nsCOMPtr<nsIProxyObjectManager> proxyman(do_GetService(NS_XPCOMPROXY_CONTRACTID));
if (!proxyman)
return NS_OK;
nsCOMPtr<nsIDOMWindowInternal> wi;
proxyman->GetProxyForObject( NS_UI_THREAD_EVENTQ,
nsIDOMWindowInternal::GetIID(),
statusDialog,
PROXY_SYNC | PROXY_ALWAYS,
getter_AddRefs(wi));
PR_Lock(mutex);
statusDialogPtr = wi;
NS_ADDREF(statusDialogPtr);
wi = 0;
if (iAmRunning || keygenReady) {
PR_Unlock(mutex);
return NS_OK;
}
iAmRunning = PR_TRUE;
threadHandle = PR_CreateThread(PR_USER_THREAD, run, NS_STATIC_CAST(void*, this),
PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
// bool thread_started_ok = (threadHandle != nsnull);
// we might want to return "thread started ok" to caller in the future
PR_Unlock(mutex);
return NS_OK;
}
nsresult nsKeygenThread::UserCanceled(PRBool *threadAlreadyClosedDialog)
{
threadAlreadyClosedDialog = PR_FALSE;
if (!mutex)
return NS_OK;
PR_Lock(mutex);
if (keygenReady)
*threadAlreadyClosedDialog = statusDialogClosed;
// User somehow closed the dialog, but we will not cancel.
// Bad luck, we told him not do, and user still has to wait.
// However, we remember that it's closed and will not close
// it again to avoid problems.
statusDialogClosed = PR_TRUE;
NS_RELEASE(statusDialogPtr);
PR_Unlock(mutex);
return NS_OK;
}
void nsKeygenThread::run(void *args)
{
if (!args)
return;
nsKeygenThread *self = NS_STATIC_CAST(nsKeygenThread *, args);
if (!self)
return;
GenerateKeypairParameters *p = 0;
PR_Lock(self->mutex);
if (self->params) {
p = self->params;
// Make sure it's impossible that will use the same parameters again.
self->params = 0;
}
PR_Unlock(self->mutex);
if (p)
p->privateKey = PK11_GenerateKeyPair(p->slot, p->keyGenMechanism,
p->params, &p->publicKey,
PR_TRUE, PR_TRUE, nsnull);
// This call gave us ownership over privateKey and publicKey.
// But as the params structure is owner by our caller,
// we effectively transferred ownership to the caller.
// As long as key generation can't be canceled, we don't need
// to care for cleaning this up.
nsIDOMWindowInternal *windowToClose = 0;
PR_Lock(self->mutex);
self->keygenReady = PR_TRUE;
self->iAmRunning = PR_FALSE;
if (!self->statusDialogClosed)
windowToClose = self->statusDialogPtr;
self->statusDialogPtr = 0;
self->statusDialogClosed = PR_TRUE;
PR_Unlock(self->mutex);
if (windowToClose)
windowToClose->Close();
}
void nsKeygenThread::Join()
{
if (!threadHandle)
return;
PR_JoinThread(threadHandle);
threadHandle = nsnull;
return;
}

Просмотреть файл

@ -0,0 +1,70 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*/
#ifndef _NSKEYGENTHREAD_H_
#define _NSKEYGENTHREAD_H_
#include "keyhi.h"
#include "nspr.h"
#include "nsIKeygenThread.h"
struct GenerateKeypairParameters
{
SECKEYPrivateKey *privateKey;
SECKEYPublicKey *publicKey;
PK11SlotInfo *slot;
PRUint32 keyGenMechanism;
void *params;
};
class nsKeygenThread : public nsIKeygenThread
{
private:
PRLock *mutex;
nsIDOMWindowInternal* statusDialogPtr;
PRBool iAmRunning;
PRBool keygenReady;
PRBool statusDialogClosed;
static void run(void *args);
PRThread *threadHandle;
GenerateKeypairParameters *params;
public:
nsKeygenThread();
virtual ~nsKeygenThread();
NS_DECL_NSIKEYGENTHREAD
NS_DECL_ISUPPORTS
// This transfers a reference of parameters to the thread
// The parameters will not be copied, the caller keeps ownership.
// Once the thread is finished, the original instance will be accessed
void SetParams(GenerateKeypairParameters *p);
void Join(void);
};
#endif //_NSKEYGENTHREAD_H_