/work/obj-fuzz/dist/include/mozilla/dom/ContentVerifier.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
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 | | |
7 | | #ifndef mozilla_dom_ContentVerifier_h |
8 | | #define mozilla_dom_ContentVerifier_h |
9 | | |
10 | | #include "nsCOMPtr.h" |
11 | | #include "nsIContentSignatureVerifier.h" |
12 | | #include "nsIObserver.h" |
13 | | #include "nsIStreamListener.h" |
14 | | #include "nsString.h" |
15 | | #include "nsTArray.h" |
16 | | |
17 | | /** |
18 | | * Mediator intercepting OnStartRequest in nsHttpChannel, blocks until all |
19 | | * data is read from the input stream, verifies the content signature and |
20 | | * releases the request to the next listener if the verification is successful. |
21 | | * If the verification fails or anything else goes wrong, a |
22 | | * NS_ERROR_INVALID_SIGNATURE is thrown. |
23 | | */ |
24 | | class ContentVerifier : public nsIStreamListener |
25 | | , public nsIContentSignatureReceiverCallback |
26 | | { |
27 | | public: |
28 | | NS_DECL_ISUPPORTS |
29 | | NS_DECL_NSISTREAMLISTENER |
30 | | NS_DECL_NSIREQUESTOBSERVER |
31 | | NS_DECL_NSICONTENTSIGNATURERECEIVERCALLBACK |
32 | | |
33 | | explicit ContentVerifier(nsIStreamListener* aMediatedListener, |
34 | | nsISupports* aMediatedContext) |
35 | | : mNextListener(aMediatedListener) |
36 | | , mContextCreated(false) |
37 | 0 | , mContentRead(false) {} |
38 | | |
39 | | nsresult Init(const nsACString& aContentSignatureHeader, nsIRequest* aRequest, |
40 | | nsISupports* aContext); |
41 | | |
42 | | protected: |
43 | | virtual ~ContentVerifier() {} |
44 | | |
45 | | private: |
46 | | void FinishSignature(); |
47 | | |
48 | | // buffered content to verify |
49 | | FallibleTArray<nsCString> mContent; |
50 | | // content and next listener for nsIStreamListener |
51 | | nsCOMPtr<nsIStreamListener> mNextListener; |
52 | | // the verifier |
53 | | nsCOMPtr<nsIContentSignatureVerifier> mVerifier; |
54 | | // holding a pointer to the content request and context to resume/cancel it |
55 | | nsCOMPtr<nsIRequest> mContentRequest; |
56 | | nsCOMPtr<nsISupports> mContentContext; |
57 | | // Semaphors to indicate that the verifying context was created, the entire |
58 | | // content was read resp. The context gets created by ContentSignatureVerifier |
59 | | // and mContextCreated is set in the ContextCreated callback. The content is |
60 | | // read, i.e. mContentRead is set, when the content OnStopRequest is called. |
61 | | bool mContextCreated; |
62 | | bool mContentRead; |
63 | | }; |
64 | | |
65 | | #endif /* mozilla_dom_ContentVerifier_h */ |