mirror of
https://github.com/classilla/tenfourfox.git
synced 2024-06-10 02:29:43 +00:00
#402: M1348454
This commit is contained in:
parent
7bf1baf33f
commit
b6849d2795
|
@ -75,7 +75,8 @@ public:
|
||||||
NS_DECL_THREADSAFE_ISUPPORTS
|
NS_DECL_THREADSAFE_ISUPPORTS
|
||||||
NS_DECL_NSIIDENTITYKEYPAIR
|
NS_DECL_NSIIDENTITYKEYPAIR
|
||||||
|
|
||||||
KeyPair(SECKEYPrivateKey* aPrivateKey, SECKEYPublicKey* aPublicKey);
|
KeyPair(SECKEYPrivateKey* aPrivateKey, SECKEYPublicKey* aPublicKey,
|
||||||
|
nsIEventTarget* aOperationThread);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
~KeyPair()
|
~KeyPair()
|
||||||
|
@ -103,6 +104,7 @@ private:
|
||||||
|
|
||||||
SECKEYPrivateKey * mPrivateKey;
|
SECKEYPrivateKey * mPrivateKey;
|
||||||
SECKEYPublicKey * mPublicKey;
|
SECKEYPublicKey * mPublicKey;
|
||||||
|
nsCOMPtr<nsIEventTarget> mThread;
|
||||||
|
|
||||||
KeyPair(const KeyPair &) = delete;
|
KeyPair(const KeyPair &) = delete;
|
||||||
void operator=(const KeyPair &) = delete;
|
void operator=(const KeyPair &) = delete;
|
||||||
|
@ -115,7 +117,8 @@ class KeyGenRunnable : public nsRunnable, public nsNSSShutDownObject
|
||||||
public:
|
public:
|
||||||
NS_DECL_NSIRUNNABLE
|
NS_DECL_NSIRUNNABLE
|
||||||
|
|
||||||
KeyGenRunnable(KeyType keyType, nsIIdentityKeyGenCallback * aCallback);
|
KeyGenRunnable(KeyType keyType, nsIIdentityKeyGenCallback * aCallback,
|
||||||
|
nsIEventTarget* aOperationThread);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
~KeyGenRunnable()
|
~KeyGenRunnable()
|
||||||
|
@ -141,6 +144,7 @@ private:
|
||||||
nsMainThreadPtrHandle<nsIIdentityKeyGenCallback> mCallback; // in
|
nsMainThreadPtrHandle<nsIIdentityKeyGenCallback> mCallback; // in
|
||||||
nsresult mRv; // out
|
nsresult mRv; // out
|
||||||
nsCOMPtr<nsIIdentityKeyPair> mKeyPair; // out
|
nsCOMPtr<nsIIdentityKeyPair> mKeyPair; // out
|
||||||
|
nsCOMPtr<nsIEventTarget> mThread;
|
||||||
|
|
||||||
KeyGenRunnable(const KeyGenRunnable &) = delete;
|
KeyGenRunnable(const KeyGenRunnable &) = delete;
|
||||||
void operator=(const KeyGenRunnable &) = delete;
|
void operator=(const KeyGenRunnable &) = delete;
|
||||||
|
@ -201,6 +205,12 @@ public:
|
||||||
= do_GetService("@mozilla.org/psm;1", &rv);
|
= do_GetService("@mozilla.org/psm;1", &rv);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIThread> thread;
|
||||||
|
rv = NS_NewNamedThread("IdentityCrypto", getter_AddRefs(thread));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
mThread = thread.forget();
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,6 +218,8 @@ private:
|
||||||
~IdentityCryptoService() { }
|
~IdentityCryptoService() { }
|
||||||
IdentityCryptoService(const KeyPair &) = delete;
|
IdentityCryptoService(const KeyPair &) = delete;
|
||||||
void operator=(const IdentityCryptoService &) = delete;
|
void operator=(const IdentityCryptoService &) = delete;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIEventTarget> mThread;
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS(IdentityCryptoService, nsIIdentityCryptoService)
|
NS_IMPL_ISUPPORTS(IdentityCryptoService, nsIIdentityCryptoService)
|
||||||
|
@ -225,9 +237,8 @@ IdentityCryptoService::GenerateKeyPair(
|
||||||
return NS_ERROR_UNEXPECTED;
|
return NS_ERROR_UNEXPECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIRunnable> r = new KeyGenRunnable(keyType, callback);
|
nsCOMPtr<nsIRunnable> r = new KeyGenRunnable(keyType, callback, mThread);
|
||||||
nsCOMPtr<nsIThread> thread;
|
nsresult rv = mThread->Dispatch(r.forget(), NS_DISPATCH_NORMAL);
|
||||||
nsresult rv = NS_NewThread(getter_AddRefs(thread), r);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -240,9 +251,11 @@ IdentityCryptoService::Base64UrlEncode(const nsACString & utf8Input,
|
||||||
return Base64UrlEncodeImpl(utf8Input, result);
|
return Base64UrlEncodeImpl(utf8Input, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyPair::KeyPair(SECKEYPrivateKey * privateKey, SECKEYPublicKey * publicKey)
|
KeyPair::KeyPair(SECKEYPrivateKey * privateKey, SECKEYPublicKey * publicKey,
|
||||||
|
nsIEventTarget* operationThread)
|
||||||
: mPrivateKey(privateKey)
|
: mPrivateKey(privateKey)
|
||||||
, mPublicKey(publicKey)
|
, mPublicKey(publicKey)
|
||||||
|
, mThread(operationThread)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(!NS_IsMainThread());
|
MOZ_ASSERT(!NS_IsMainThread());
|
||||||
}
|
}
|
||||||
|
@ -328,16 +341,16 @@ KeyPair::Sign(const nsACString & textToSign,
|
||||||
nsCOMPtr<nsIRunnable> r = new SignRunnable(textToSign, mPrivateKey,
|
nsCOMPtr<nsIRunnable> r = new SignRunnable(textToSign, mPrivateKey,
|
||||||
callback);
|
callback);
|
||||||
|
|
||||||
nsCOMPtr<nsIThread> thread;
|
return mThread->Dispatch(r, NS_DISPATCH_NORMAL);
|
||||||
nsresult rv = NS_NewThread(getter_AddRefs(thread), r);
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyGenRunnable::KeyGenRunnable(KeyType keyType,
|
KeyGenRunnable::KeyGenRunnable(KeyType keyType,
|
||||||
nsIIdentityKeyGenCallback * callback)
|
nsIIdentityKeyGenCallback * callback,
|
||||||
|
nsIEventTarget* operationThread)
|
||||||
: mKeyType(keyType)
|
: mKeyType(keyType)
|
||||||
, mCallback(new nsMainThreadPtrHolder<nsIIdentityKeyGenCallback>(callback))
|
, mCallback(new nsMainThreadPtrHolder<nsIIdentityKeyGenCallback>(callback))
|
||||||
, mRv(NS_ERROR_NOT_INITIALIZED)
|
, mRv(NS_ERROR_NOT_INITIALIZED)
|
||||||
|
, mThread(operationThread)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -476,7 +489,7 @@ KeyGenRunnable::Run()
|
||||||
MOZ_ASSERT(privk);
|
MOZ_ASSERT(privk);
|
||||||
MOZ_ASSERT(pubk);
|
MOZ_ASSERT(pubk);
|
||||||
// mKeyPair will take over ownership of privk and pubk
|
// mKeyPair will take over ownership of privk and pubk
|
||||||
mKeyPair = new KeyPair(privk, pubk);
|
mKeyPair = new KeyPair(privk, pubk, mThread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user