Files
firefox/security/manager/ssl/nsKeygenHandler.h
T
Cykesiopka 08d7df48c9 Bug 1338897 - Avoid using NSS Base64 functions in PSM. r=keeler
The NSS Base64 functions are less safe and convenient to use than the XPCOM ones.
They're also an unnecessary dependency on NSS.

The NSS Base64 functions behave slightly differently than the XPCOM ones:
1. ATOB_ConvertAsciiToItem() / NSSBase64_DecodeBuffer() silently ignore invalid
   characters like CRLF, space and so on. Base64Decode() will return an error
   if these characters are encountered.
2. BTOA_DataToAscii() will produce output that has CRLF inserted every 64
   characters. Base64Encode() doesn't do this.

For the reasons listed below, no unexpected compatibility issues should arise:
1. AppSignatureVerification.cpp already filters out CRLF and spaces for Manifest
   and Signature values before decoding.
2. ExtendedValidation.cpp is only given what should be valid hard-coded input to
   decode.
3. ContentSignatureVerifier.cpp already splits on CRLF for when it needs to
   decode PEM certs. Spaces shouldn't be likely.
   For Content-Signature header verification, examination of real input to a
   running instance of Firefox suggests CRLF and spaces will not be present in
   the header to decode.
4. nsCryptoHash.cpp encode is affected, but we actually don't want the CRLF
   behaviour.
5. nsDataSignatureVerifier.cpp decode is affected, but we add whitespace
   stripping to maintain backwards compatibility.
6. nsKeygenHandler.cpp encode is affected, but the previous CRLF behaviour was
   arguably a bug, since neither WHATWG or W3C specs specified this.

MozReview-Commit-ID: IWMFxqVZMeX
2017-03-17 23:31:40 +08:00

84 lines
2.8 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsKeygenHandler_h
#define nsKeygenHandler_h
#include "ScopedNSSTypes.h"
#include "keythi.h"
#include "nsCOMPtr.h"
#include "nsError.h"
#include "nsIFormProcessor.h"
#include "nsIInterfaceRequestor.h"
#include "nsNSSShutDown.h"
#include "nsString.h"
#include "nsTArray.h"
#include "secmodt.h"
nsresult GetSlotWithMechanism(uint32_t mechanism,
nsIInterfaceRequestor* ctx,
PK11SlotInfo** retSlot,
nsNSSShutDownPreventionLock& /*proofOfLock*/);
#define DEFAULT_RSA_KEYGEN_PE 65537L
#define DEFAULT_RSA_KEYGEN_ALG SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION
mozilla::UniqueSECItem DecodeECParams(const char* curve);
class nsKeygenFormProcessor : public nsIFormProcessor
, public nsNSSShutDownObject
{
public:
nsKeygenFormProcessor();
nsresult Init();
virtual nsresult ProcessValue(nsIDOMHTMLElement* aElement,
const nsAString& aName,
nsAString& aValue) override;
virtual nsresult ProcessValueIPC(const nsAString& aOldValue,
const nsAString& aChallenge,
const nsAString& aKeyType,
const nsAString& aKeyParams,
nsAString& aNewValue) override;
virtual nsresult ProvideContent(const nsAString& aFormType,
nsTArray<nsString>& aContent,
nsAString& aAttribute) override;
NS_DECL_THREADSAFE_ISUPPORTS
static nsresult Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
static void ExtractParams(nsIDOMHTMLElement* aElement,
nsAString& challengeValue,
nsAString& keyTypeValue,
nsAString& keyParamsValue);
// Nothing to release.
virtual void virtualDestroyNSSReference() override {}
protected:
virtual ~nsKeygenFormProcessor();
nsresult GetPublicKey(const nsAString& aValue, const nsAString& aChallenge,
const nsAFlatString& akeyType, nsAString& aOutPublicKey,
const nsAString& aPqg);
nsresult GetSlot(uint32_t aMechanism, PK11SlotInfo** aSlot);
private:
nsCOMPtr<nsIInterfaceRequestor> m_ctx;
typedef struct SECKeySizeChoiceInfoStr {
nsString name;
int size;
} SECKeySizeChoiceInfo;
enum { number_of_key_size_choices = 2 };
SECKeySizeChoiceInfo mSECKeySizeChoiceList[number_of_key_size_choices];
};
#endif // nsKeygenHandler_h