nsKeygenHandler.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2. *
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. #ifndef nsKeygenHandler_h
  7. #define nsKeygenHandler_h
  8. #include "ScopedNSSTypes.h"
  9. #include "keythi.h"
  10. #include "nsCOMPtr.h"
  11. #include "nsError.h"
  12. #include "nsIFormProcessor.h"
  13. #include "nsIInterfaceRequestor.h"
  14. #include "nsNSSShutDown.h"
  15. #include "nsTArray.h"
  16. #include "secmodt.h"
  17. nsresult GetSlotWithMechanism(uint32_t mechanism,
  18. nsIInterfaceRequestor* ctx,
  19. PK11SlotInfo** retSlot,
  20. nsNSSShutDownPreventionLock& /*proofOfLock*/);
  21. #define DEFAULT_RSA_KEYGEN_PE 65537L
  22. #define DEFAULT_RSA_KEYGEN_ALG SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION
  23. mozilla::UniqueSECItem DecodeECParams(const char* curve);
  24. class nsKeygenFormProcessor : public nsIFormProcessor
  25. , public nsNSSShutDownObject
  26. {
  27. public:
  28. nsKeygenFormProcessor();
  29. nsresult Init();
  30. virtual nsresult ProcessValue(nsIDOMHTMLElement* aElement,
  31. const nsAString& aName,
  32. nsAString& aValue) override;
  33. virtual nsresult ProcessValueIPC(const nsAString& aOldValue,
  34. const nsAString& aChallenge,
  35. const nsAString& aKeyType,
  36. const nsAString& aKeyParams,
  37. nsAString& aNewValue) override;
  38. virtual nsresult ProvideContent(const nsAString& aFormType,
  39. nsTArray<nsString>& aContent,
  40. nsAString& aAttribute) override;
  41. NS_DECL_THREADSAFE_ISUPPORTS
  42. static nsresult Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
  43. static void ExtractParams(nsIDOMHTMLElement* aElement,
  44. nsAString& challengeValue,
  45. nsAString& keyTypeValue,
  46. nsAString& keyParamsValue);
  47. // Nothing to release.
  48. virtual void virtualDestroyNSSReference() override {}
  49. protected:
  50. virtual ~nsKeygenFormProcessor();
  51. nsresult GetPublicKey(const nsAString& aValue, const nsAString& aChallenge,
  52. const nsAFlatString& akeyType, nsAString& aOutPublicKey,
  53. const nsAString& aPqg);
  54. nsresult GetSlot(uint32_t aMechanism, PK11SlotInfo** aSlot);
  55. private:
  56. nsCOMPtr<nsIInterfaceRequestor> m_ctx;
  57. typedef struct SECKeySizeChoiceInfoStr {
  58. nsString name;
  59. int size;
  60. } SECKeySizeChoiceInfo;
  61. enum { number_of_key_size_choices = 2 };
  62. SECKeySizeChoiceInfo mSECKeySizeChoiceList[number_of_key_size_choices];
  63. };
  64. #endif // nsKeygenHandler_h