/src/mozilla-central/security/certverifier/BTVerifier.cpp
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 | | #include "BTVerifier.h" |
8 | | #include "CTUtils.h" |
9 | | #include "SignedCertificateTimestamp.h" |
10 | | |
11 | | #include <stdint.h> |
12 | | |
13 | | #include "mozilla/Assertions.h" |
14 | | #include "mozilla/Move.h" |
15 | | #include "mozilla/TypeTraits.h" |
16 | | |
17 | | namespace mozilla { namespace ct { |
18 | | |
19 | | using namespace mozilla::pkix; |
20 | | |
21 | | typedef mozilla::pkix::Result Result; |
22 | | |
23 | | // Members of a Inclusion Proof struct |
24 | | static const size_t kLogIdPrefixLengthBytes = 1; |
25 | | static const size_t kProofTreeSizeLength = 8; |
26 | | static const size_t kLeafIndexLength = 8; |
27 | | static const size_t kInclusionPathLengthBytes = 2; |
28 | | static const size_t kNodeHashPrefixLengthBytes = 1; |
29 | | |
30 | | Result |
31 | | DecodeInclusionProof(pkix::Reader& reader, InclusionProofDataV2& output) |
32 | 0 | { |
33 | 0 | InclusionProofDataV2 result; |
34 | 0 |
|
35 | 0 | Input logId; |
36 | 0 | Result rv = ReadVariableBytes<kLogIdPrefixLengthBytes>(reader, logId); |
37 | 0 | if (rv != Success) { |
38 | 0 | return rv; |
39 | 0 | } |
40 | 0 | |
41 | 0 | rv = ReadUint<kProofTreeSizeLength>(reader, result.treeSize); |
42 | 0 | if (rv != Success) { |
43 | 0 | return rv; |
44 | 0 | } |
45 | 0 | |
46 | 0 | if (result.treeSize < 1) { |
47 | 0 | return pkix::Result::ERROR_BAD_DER; |
48 | 0 | } |
49 | 0 | |
50 | 0 | rv = ReadUint<kLeafIndexLength>(reader, result.leafIndex); |
51 | 0 | if (rv != Success) { |
52 | 0 | return rv; |
53 | 0 | } |
54 | 0 | |
55 | 0 | if (result.leafIndex >= result.treeSize) { |
56 | 0 | return pkix::Result::ERROR_BAD_DER; |
57 | 0 | } |
58 | 0 | |
59 | 0 | Input pathInput; |
60 | 0 | rv = ReadVariableBytes<kInclusionPathLengthBytes>(reader, pathInput); |
61 | 0 | if (rv != Success) { |
62 | 0 | return rv; |
63 | 0 | } |
64 | 0 | |
65 | 0 | if (pathInput.GetLength() < 1) { |
66 | 0 | return pkix::Result::ERROR_BAD_DER; |
67 | 0 | } |
68 | 0 | |
69 | 0 | Reader pathReader(pathInput); |
70 | 0 | Vector<Buffer, kInitialPathLengthCapacity> inclusionPath; |
71 | 0 |
|
72 | 0 | while (!pathReader.AtEnd()) { |
73 | 0 | Input hash; |
74 | 0 | rv = ReadVariableBytes<kNodeHashPrefixLengthBytes>(pathReader, hash); |
75 | 0 | if (rv != Success) { |
76 | 0 | return rv; |
77 | 0 | } |
78 | 0 | |
79 | 0 | Buffer hashBuffer; |
80 | 0 | rv = InputToBuffer(hash, hashBuffer); |
81 | 0 | if (rv != Success) { |
82 | 0 | return rv; |
83 | 0 | } |
84 | 0 | |
85 | 0 | if (!inclusionPath.append(std::move(hashBuffer))) { |
86 | 0 | return pkix::Result::FATAL_ERROR_NO_MEMORY; |
87 | 0 | } |
88 | 0 | } |
89 | 0 |
|
90 | 0 | if (!reader.AtEnd()){ |
91 | 0 | return pkix::Result::ERROR_BAD_DER; |
92 | 0 | } |
93 | 0 | |
94 | 0 | rv = InputToBuffer(logId, result.logId); |
95 | 0 | if (rv != Success) { |
96 | 0 | return rv; |
97 | 0 | } |
98 | 0 | |
99 | 0 | result.inclusionPath = std::move(inclusionPath); |
100 | 0 |
|
101 | 0 | output = std::move(result); |
102 | 0 | return Success; |
103 | 0 | } |
104 | | } } //namespace mozilla::ct |