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