2017-10-27 01:08:41 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2016-03-14 13:56:35 +03:00
|
|
|
/* 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 mozilla_dom_ContentVerifier_h
|
|
|
|
#define mozilla_dom_ContentVerifier_h
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2016-05-19 11:59:48 +03:00
|
|
|
#include "nsIContentSignatureVerifier.h"
|
2016-03-14 13:56:35 +03:00
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mediator intercepting OnStartRequest in nsHttpChannel, blocks until all
|
|
|
|
* data is read from the input stream, verifies the content signature and
|
|
|
|
* releases the request to the next listener if the verification is successful.
|
|
|
|
* If the verification fails or anything else goes wrong, a
|
|
|
|
* NS_ERROR_INVALID_SIGNATURE is thrown.
|
|
|
|
*/
|
|
|
|
class ContentVerifier : public nsIStreamListener
|
2016-05-19 11:59:48 +03:00
|
|
|
, public nsIContentSignatureReceiverCallback
|
2016-03-14 13:56:35 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
2016-05-19 11:59:48 +03:00
|
|
|
NS_DECL_NSICONTENTSIGNATURERECEIVERCALLBACK
|
2016-03-14 13:56:35 +03:00
|
|
|
|
|
|
|
explicit ContentVerifier(nsIStreamListener* aMediatedListener,
|
|
|
|
nsISupports* aMediatedContext)
|
|
|
|
: mNextListener(aMediatedListener)
|
2016-05-19 11:59:48 +03:00
|
|
|
, mContextCreated(false)
|
|
|
|
, mContentRead(false) {}
|
2016-03-14 13:56:35 +03:00
|
|
|
|
2016-05-19 11:59:48 +03:00
|
|
|
nsresult Init(const nsACString& aContentSignatureHeader, nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext);
|
2016-03-14 13:56:35 +03:00
|
|
|
|
|
|
|
protected:
|
2016-05-19 11:59:48 +03:00
|
|
|
virtual ~ContentVerifier() {}
|
2016-03-14 13:56:35 +03:00
|
|
|
|
|
|
|
private:
|
2016-05-19 11:59:48 +03:00
|
|
|
void FinishSignature();
|
2016-03-14 13:56:35 +03:00
|
|
|
|
2016-07-20 21:16:37 +03:00
|
|
|
// buffered content to verify
|
|
|
|
FallibleTArray<nsCString> mContent;
|
2016-05-19 11:59:48 +03:00
|
|
|
// content and next listener for nsIStreamListener
|
|
|
|
nsCOMPtr<nsIStreamListener> mNextListener;
|
|
|
|
// the verifier
|
|
|
|
nsCOMPtr<nsIContentSignatureVerifier> mVerifier;
|
|
|
|
// holding a pointer to the content request and context to resume/cancel it
|
|
|
|
nsCOMPtr<nsIRequest> mContentRequest;
|
|
|
|
nsCOMPtr<nsISupports> mContentContext;
|
|
|
|
// Semaphors to indicate that the verifying context was created, the entire
|
|
|
|
// content was read resp. The context gets created by ContentSignatureVerifier
|
|
|
|
// and mContextCreated is set in the ContextCreated callback. The content is
|
|
|
|
// read, i.e. mContentRead is set, when the content OnStopRequest is called.
|
|
|
|
bool mContextCreated;
|
|
|
|
bool mContentRead;
|
2016-03-14 13:56:35 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_ContentVerifier_h */
|