ContentSignatureVerifier.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef ContentSignatureVerifier_h
  6. #define ContentSignatureVerifier_h
  7. #include "cert.h"
  8. #include "CSTrustDomain.h"
  9. #include "nsIContentSignatureVerifier.h"
  10. #include "nsIStreamListener.h"
  11. #include "nsNSSShutDown.h"
  12. #include "ScopedNSSTypes.h"
  13. // 45a5fe2f-c350-4b86-962d-02d5aaaa955a
  14. #define NS_CONTENTSIGNATUREVERIFIER_CID \
  15. { 0x45a5fe2f, 0xc350, 0x4b86, \
  16. { 0x96, 0x2d, 0x02, 0xd5, 0xaa, 0xaa, 0x95, 0x5a } }
  17. #define NS_CONTENTSIGNATUREVERIFIER_CONTRACTID \
  18. "@mozilla.org/security/contentsignatureverifier;1"
  19. class ContentSignatureVerifier final : public nsIContentSignatureVerifier
  20. , public nsIStreamListener
  21. , public nsNSSShutDownObject
  22. , public nsIInterfaceRequestor
  23. {
  24. public:
  25. NS_DECL_ISUPPORTS
  26. NS_DECL_NSICONTENTSIGNATUREVERIFIER
  27. NS_DECL_NSIINTERFACEREQUESTOR
  28. NS_DECL_NSISTREAMLISTENER
  29. NS_DECL_NSIREQUESTOBSERVER
  30. ContentSignatureVerifier()
  31. : mCx(nullptr)
  32. , mInitialised(false)
  33. , mHasCertChain(false)
  34. {
  35. }
  36. // nsNSSShutDownObject
  37. virtual void virtualDestroyNSSReference() override
  38. {
  39. destructorSafeDestroyNSSReference();
  40. }
  41. private:
  42. ~ContentSignatureVerifier();
  43. nsresult UpdateInternal(const nsACString& aData,
  44. const nsNSSShutDownPreventionLock& /*proofOfLock*/);
  45. nsresult DownloadCertChain();
  46. nsresult CreateContextInternal(const nsACString& aData,
  47. const nsACString& aCertChain,
  48. const nsACString& aName);
  49. void destructorSafeDestroyNSSReference()
  50. {
  51. mCx = nullptr;
  52. mKey = nullptr;
  53. }
  54. nsresult ParseContentSignatureHeader(const nsACString& aContentSignatureHeader);
  55. // verifier context for incremental verifications
  56. mozilla::UniqueVFYContext mCx;
  57. bool mInitialised;
  58. // Indicates whether we hold a cert chain to verify the signature or not.
  59. // It's set by default in CreateContext or when the channel created in
  60. // DownloadCertChain finished. Update and End must only be called after
  61. // mHashCertChain is set.
  62. bool mHasCertChain;
  63. // signature to verify
  64. nsCString mSignature;
  65. // x5u (X.509 URL) value pointing to pem cert chain
  66. nsCString mCertChainURL;
  67. // the downloaded cert chain to verify against
  68. FallibleTArray<nsCString> mCertChain;
  69. // verification key
  70. mozilla::UniqueSECKEYPublicKey mKey;
  71. // name of the verifying context
  72. nsCString mName;
  73. // callback to notify when finished
  74. nsCOMPtr<nsIContentSignatureReceiverCallback> mCallback;
  75. // channel to download the cert chain
  76. nsCOMPtr<nsIChannel> mChannel;
  77. };
  78. #endif // ContentSignatureVerifier_h