Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: components/crx_file/crx2_file.h

Issue 2874503002: Refactor CRX verification in preparation to support CRX₃ files. (Closed)
Patch Set: through #51 Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/crx_file/BUILD.gn ('k') | components/crx_file/crx2_file.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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 COMPONENTS_CRX_FILE_CRX2_FILE_H_
6 #define COMPONENTS_CRX_FILE_CRX2_FILE_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10 #include <sys/types.h>
11
12 #include <memory>
13 #include <string>
14 #include <vector>
15
16 namespace crx_file {
17
18 // The magic string embedded in the header.
19 constexpr char kCrx2FileHeaderMagic[] = "Cr24";
20 constexpr char kCrxDiffFileHeaderMagic[] = "CrOD";
21 constexpr int kCrx2FileHeaderMagicSize = 4;
22
23 // CRX files have a header that includes a magic key, version number, and
24 // some signature sizing information. Use Crx2File object to validate whether
25 // the header is valid or not.
26 class Crx2File {
27 public:
28 // This header is the first data at the beginning of an extension. Its
29 // contents are purposely 32-bit aligned so that it can just be slurped into
30 // a struct without manual parsing.
31 struct Header {
32 char magic[kCrx2FileHeaderMagicSize];
33 uint32_t version;
34 uint32_t key_size; // The size of the public key, in bytes.
35 uint32_t signature_size; // The size of the signature, in bytes.
36 // An ASN.1-encoded PublicKeyInfo structure follows.
37 // The signature follows.
38 };
39
40 enum Error {
41 kWrongMagic,
42 kInvalidVersion,
43 kInvalidKeyTooLarge,
44 kInvalidKeyTooSmall,
45 kInvalidSignatureTooLarge,
46 kInvalidSignatureTooSmall,
47 kMaxValue,
48 };
49
50 // Construct a new header for the given key and signature sizes.
51 // Returns null if erroneous values of |key_size| and/or
52 // |signature_size| are provided. |error| contains an error code with
53 // additional information.
54 // Use this constructor and then .header() to obtain the Header
55 // for writing out to a CRX file.
56 static std::unique_ptr<Crx2File> Create(const uint32_t key_size,
57 const uint32_t signature_size,
58 Error* error);
59
60 // Returns the header structure for writing out to a CRX file.
61 const Header& header() const { return header_; }
62
63 private:
64 Header header_;
65
66 // Constructor is private. Clients should use static factory methods above.
67 explicit Crx2File(const Header& header);
68
69 // Checks the |header| for validity and returns true if the values are valid.
70 // If false is returned, more detailed error code is returned in |error|.
71 static bool HeaderIsValid(const Header& header, Error* error);
72 };
73
74 } // namespace crx_file
75
76 #endif // COMPONENTS_CRX_FILE_CRX2_FILE_H_
OLDNEW
« no previous file with comments | « components/crx_file/BUILD.gn ('k') | components/crx_file/crx2_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698