Home | History | Annotate | Download | only in browser
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef EXTENSIONS_BROWSER_CONTENT_VERIFIER_DELEGATE_H_
      6 #define EXTENSIONS_BROWSER_CONTENT_VERIFIER_DELEGATE_H_
      7 
      8 #include <set>
      9 
     10 #include "extensions/browser/content_verify_job.h"
     11 #include "url/gurl.h"
     12 
     13 namespace base {
     14 class FilePath;
     15 class Version;
     16 }
     17 
     18 namespace extensions {
     19 
     20 class Extension;
     21 
     22 // A pointer to the bytes of a public key, and the number of bytes.
     23 struct ContentVerifierKey {
     24   const uint8* data;
     25   int size;
     26 
     27   ContentVerifierKey() : data(NULL), size(0) {}
     28 
     29   ContentVerifierKey(const uint8* data, int size) {
     30     this->data = data;
     31     this->size = size;
     32   }
     33 };
     34 
     35 // This is an interface for clients that want to use a ContentVerifier.
     36 class ContentVerifierDelegate {
     37  public:
     38   // Note that it is important for these to appear in increasing "severity"
     39   // order, because we use this to let command line flags increase, but not
     40   // decrease, the mode you're running in compared to the experiment group.
     41   enum Mode {
     42     // Do not try to fetch content hashes if they are missing, and do not
     43     // enforce them if they are present.
     44     NONE = 0,
     45 
     46     // If content hashes are missing, try to fetch them, but do not enforce.
     47     BOOTSTRAP,
     48 
     49     // If hashes are present, enforce them. If they are missing, try to fetch
     50     // them.
     51     ENFORCE,
     52 
     53     // Treat the absence of hashes the same as a verification failure.
     54     ENFORCE_STRICT
     55   };
     56 
     57   virtual ~ContentVerifierDelegate() {}
     58 
     59   // This should return what verification mode is appropriate for the given
     60   // extension, if any.
     61   virtual Mode ShouldBeVerified(const Extension& extension) = 0;
     62 
     63   // Should return the public key to use for validating signatures via the two
     64   // out parameters. NOTE: the pointer returned *must* remain valid for the
     65   // lifetime of this object.
     66   virtual const ContentVerifierKey& PublicKey() = 0;
     67 
     68   // This should return a URL that can be used to fetch the
     69   // verified_contents.json containing signatures for the given extension
     70   // id/version pair.
     71   virtual GURL GetSignatureFetchUrl(const std::string& extension_id,
     72                                     const base::Version& version) = 0;
     73 
     74   // This should return the set of file paths for images used within the
     75   // browser process. (These may get transcoded during the install process).
     76   virtual std::set<base::FilePath> GetBrowserImagePaths(
     77       const extensions::Extension* extension) = 0;
     78 
     79   // Called when the content verifier detects that a read of a file inside
     80   // an extension did not match its expected hash.
     81   virtual void VerifyFailed(const std::string& extension_id,
     82                             ContentVerifyJob::FailureReason reason) = 0;
     83 };
     84 
     85 }  // namespace extensions
     86 
     87 #endif  // EXTENSIONS_BROWSER_CONTENT_VERIFIER_DELEGATE_H_
     88