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

Side by Side Diff: net/cert/internal/parse_ocsp.h

Issue 1541213002: Adding OCSP Parser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix serial number parsing. Created 4 years, 10 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
OLDNEW
(Empty)
1 // Copyright 2016 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 NET_CERT_INTERNAL_PARSE_OCSP_H_
6 #define NET_CERT_INTERNAL_PARSE_OCSP_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/memory/scoped_ptr.h"
12 #include "net/base/hash_value.h"
13 #include "net/cert/internal/parse_certificate.h"
14 #include "net/cert/internal/signature_algorithm.h"
15 #include "net/der/input.h"
16 #include "net/der/parse_values.h"
17 #include "net/der/parser.h"
18 #include "net/der/tag.h"
19
20 namespace net {
21
22 // OCSPCertID contains a representation of a DER-encoded RFC 6960 "CertID".
23 //
24 // CertID ::= SEQUENCE {
25 // hashAlgorithm AlgorithmIdentifier,
26 // issuerNameHash OCTET STRING, -- Hash of issuer's DN
27 // issuerKeyHash OCTET STRING, -- Hash of issuer's public key
28 // serialNumber CertificateSerialNumber
29 // }
30 struct OCSPCertID {
31 OCSPCertID();
32 ~OCSPCertID();
33
34 DigestAlgorithm hash_algorithm;
35 der::Input issuer_name_hash;
36 der::Input issuer_key_hash;
37 der::Input serial_number;
38 };
39
40 // OCSPCertStatus contains a representation of a DER-encoded RFC 6960
41 // "CertStatus".
42 //
43 // CertStatus ::= CHOICE {
44 // good [0] IMPLICIT NULL,
45 // revoked [1] IMPLICIT RevokedInfo,
46 // unknown [2] IMPLICIT UnknownInfo
47 // }
48 //
49 // RevokedInfo ::= SEQUENCE {
50 // revocationTime GeneralizedTime,
51 // revocationReason [0] EXPLICIT CRLReason OPTIONAL
52 // }
53 //
54 // UnknownInfo ::= NULL
55 struct OCSPCertStatus {
56 enum class Status {
57 GOOD,
58 REVOKED,
59 UNKNOWN,
60 };
61
62 enum class RevocationReason {
eroman 2016/02/13 00:56:50 Where is this specified? Same comment as the othe
svaldez 2016/02/16 17:25:11 Done.
63 UNSPECIFIED,
64 KEY_COMPROMISE,
65 CA_COMPROMISE,
66 AFFILIATION_CHANGED,
67 SUPERSEDED,
68 CESSATION_OF_OPERATION,
69 CERTIFICATE_HOLD,
70 UNUSED,
71 REMOVE_FROM_CRL,
72 PRIVILEGE_WITHDRAWN,
73 A_COMPROMISE,
74
75 REVOCATION_REASON_MAX
76 };
77
78 Status status;
79 der::GeneralizedTime revocation_time;
80 bool has_reason;
81 RevocationReason revocation_reason;
82 };
83
84 // OCSPSingleResponse contains a representation of a DER-encoded RFC 6960
85 // "SingleResponse". The 'certID' and 'singleExtensions' fields are pointers
eroman 2016/02/13 00:56:50 Would be clearer to reference them by name |cert_i
svaldez 2016/02/16 17:25:11 Done.
86 // to the original object and are only valid as long as it is alive. They also
87 // aren't verified until they are parsed.
88 //
89 // SingleResponse ::= SEQUENCE {
90 // certID CertID,
91 // certStatus CertStatus,
92 // thisUpdate GeneralizedTime,
93 // nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL,
94 // singleExtensions [1] EXPLICIT Extensions OPTIONAL
95 // }
96 struct OCSPSingleResponse {
97 OCSPSingleResponse();
98 ~OCSPSingleResponse();
99
100 der::Input cert_id_tlv;
101 OCSPCertStatus cert_status;
102 der::GeneralizedTime this_update;
103 bool has_next_update;
104 der::GeneralizedTime next_update;
105 bool has_extensions;
106 der::Input extensions;
107 };
108
109 // OCSPResponseData contains a representation of a DER-encoded RFC 6960
110 // "ResponseData". The 'responses' and 'extensions' fields are pointers to the
eroman 2016/02/13 00:56:50 Are these referring to the RFC 6960 names, or the
svaldez 2016/02/16 17:25:11 Done.
111 // original object and are only valid as long as it is alive. They also aren't
112 // verified until they are parsed into OCSPSingleResponse and ParsedExtensions.
113 //
114 // ResponseData ::= SEQUENCE {
115 // version [0] EXPLICIT Version DEFAULT v1,
116 // responderID ResponderID,
117 // producedAt GeneralizedTime,
118 // responses SEQUENCE OF SingleResponse,
119 // responseExtensions [1] EXPLICIT Extensions OPTIONAL
120 // }
121 struct OCSPResponseData {
122 enum class ResponderType { NAME, KEY_HASH };
123
124 struct ResponderID {
125 ResponderType type;
126 der::Input name;
127 HashValue key_hash;
128 };
129
130 OCSPResponseData();
131 ~OCSPResponseData();
132
133 uint8_t version;
134 OCSPResponseData::ResponderID responder_id;
135 der::GeneralizedTime produced_at;
136 std::vector<der::Input> responses;
137 bool has_extensions;
138 der::Input extensions;
139 };
140
141 // OCSPResponse contains a representation of a DER-encoded RFC 6960
142 // "OCSPResponse" and the corresponding "BasicOCSPResponse". The 'data' field
eroman 2016/02/13 00:56:50 'data' --> |data| ?
svaldez 2016/02/16 17:25:11 Done.
143 // is a pointer to the original object and are only valid as long is it is
144 // alive. The 'data' field isn't verified until it is parsed into an
eroman 2016/02/13 00:56:50 same
svaldez 2016/02/16 17:25:11 Done.
145 // OCSPResponseData.
146 //
147 // OCSPResponse ::= SEQUENCE {
148 // responseStatus OCSPResponseStatus,
149 // responseBytes [0] EXPLICIT ResponseBytes OPTIONAL
150 // }
151 //
152 // BasicOCSPResponse ::= SEQUENCE {
153 // tbsResponseData ResponseData,
154 // signatureAlgorithm AlgorithmIdentifier,
155 // signature BIT STRING,
156 // certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL
157 // }
158 struct NET_EXPORT OCSPResponse {
159 enum class ResponseStatus {
160 SUCCESSFUL,
161 MALFORMED_REQUEST,
162 INTERNAL_ERROR,
163 TRY_LATER,
164 SIG_REQUIRED,
165 UNAUTHORIZED,
166
167 RESPONSE_STATUS_MAX,
eroman 2016/02/13 00:56:50 Several things here: (1) Since this relies on th
svaldez 2016/02/16 17:25:11 Done.
168 };
169
170 OCSPResponse();
171 ~OCSPResponse();
172
173 ResponseStatus status;
174 der::Input data;
175 scoped_ptr<SignatureAlgorithm> signature_algorithm;
176 der::BitString signature;
177 std::vector<der::Input> certs;
178 };
179
180 // From RFC 6960:
181 //
182 // id-pkix-ocsp OBJECT IDENTIFIER ::= { id-ad-ocsp }
183 // id-pkix-ocsp-basic OBJECT IDENTIFIER ::= { id-pkix-ocsp 1 }
184 //
185 // In dotted notation: 1.3.6.1.5.5.7.48.1.1
186 NET_EXPORT der::Input BasicOCSPResponseOid();
187
188 // Parses a DER-encoded OCSP "CertID" as specified by RFC 6960. Returns true on
189 // success and sets the results in |out|.
190 //
191 // On failure |out| has an undefined state. Some of its fields may have been
192 // updated during parsing, whereas others may not have been changed.
193 NET_EXPORT_PRIVATE bool ParseOCSPCertID(der::Input raw_tlv, OCSPCertID* out);
194
195 // Parses a DER-encoded OCSP "SingleResponse" as specified by RFC 6960. Returns
196 // true on success and sets the results in |out|. The resulting |out|
197 // references data from |raw_tlv| and is only valid for the lifetime of
198 // |raw_tlv|.
199 //
200 // On failure |out| has an undefined state. Some of its fields may have been
201 // updated during parsing, whereas others may not have been changed.
202 NET_EXPORT_PRIVATE bool ParseOCSPSingleResponse(der::Input raw_tlv,
eroman 2016/02/13 00:56:50 Plz change to |const der::Input&| for consistency
svaldez 2016/02/16 17:25:11 Done.
203 OCSPSingleResponse* out);
204
205 // Parses a DER-encoded OCSP "ResponseData" as specified by RFC 6960. Returns
206 // true on success and sets the results in |out|. The resulting |out|
207 // references data from |raw_tlv| and is only valid for the lifetime of
208 // |raw_tlv|.
209 //
210 // On failure |out| has an undefined state. Some of its fields may have been
211 // updated during parsing, whereas others may not have been changed.
212 NET_EXPORT_PRIVATE bool ParseOCSPResponseData(der::Input raw_tlv,
213 OCSPResponseData* out);
214
215 // Parses a DER-encoded "OCSPResponse" as specified by RFC 6960. Returns true
216 // on success and sets the results in |out|. The resulting |out|
217 // references data from |ocsp_response| and is only valid for the lifetime of
218 // |ocsp_response|.
219 //
220 // On failure |out| has an undefined state. Some of its fields may have been
221 // updated during parsing, whereas others may not have been changed.
222 NET_EXPORT_PRIVATE bool ParseOCSPResponse(der::Input ocsp_response,
223 OCSPResponse* out);
224
225 // Verifies that the OCSP Response |response| is signed and has a valid trust
226 // path to the issuer |issuer_cert|.
227 NET_EXPORT_PRIVATE bool VerifyOCSPResponse(
228 const OCSPResponse* response,
eroman 2016/02/13 00:56:50 (1) Why pointers instead of references? What is th
svaldez 2016/02/16 17:25:11 I'll split it off to a separate CL once I'm done r
eroman 2016/02/16 23:42:25 I think there can be a logical separation between
229 const ParsedCertificate* issuer_cert);
230
231 // Checks the certificate status of |cert| based on the OCSPResponseData
232 // |response_data| and sets the results in |out|.
233 //
234 // On failure |out| has an undefined state. Some of its fields may have been
235 // updated during parsing, whereas others may not have been changed.
236 NET_EXPORT_PRIVATE bool GetOCSPCertStatus(const OCSPResponseData* response_data,
eroman 2016/02/13 00:56:50 Why are the inputs pointers rather than references
svaldez 2016/02/16 17:25:11 Done.
237 const ParsedCertificate* issuer,
238 const ParsedCertificate* cert,
239 OCSPCertStatus* out);
240
241 } // namespace net
242
243 #endif // NET_CERT_INTERNAL_PARSE_OCSP_H_
OLDNEW
« no previous file with comments | « net/BUILD.gn ('k') | net/cert/internal/parse_ocsp.cc » ('j') | net/cert/internal/parse_ocsp.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698