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

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: Moving Verify to end. 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". |revocation_time| and |has_reason| are only valid when
42 // |status| is REVOKED. |revocation_reason| is only valid when |has_reason| is
43 // true.
44 //
45 // CertStatus ::= CHOICE {
46 // good [0] IMPLICIT NULL,
47 // revoked [1] IMPLICIT RevokedInfo,
48 // unknown [2] IMPLICIT UnknownInfo
49 // }
50 //
51 // RevokedInfo ::= SEQUENCE {
52 // revocationTime GeneralizedTime,
53 // revocationReason [0] EXPLICIT CRLReason OPTIONAL
54 // }
55 //
56 // UnknownInfo ::= NULL
57 struct OCSPCertStatus {
58 enum class Status {
59 GOOD,
60 REVOKED,
61 UNKNOWN,
62 };
63
64 enum class RevocationReason {
eroman 2016/02/16 23:42:26 Please provide a reference to the RFC and section
svaldez 2016/02/17 16:46:47 Done.
65 UNSPECIFIED = 0,
66 KEY_COMPROMISE = 1,
67 CA_COMPROMISE = 2,
68 AFFILIATION_CHANGED = 3,
69 SUPERSEDED = 4,
70 CESSATION_OF_OPERATION = 5,
71 CERTIFICATE_HOLD = 6,
72 UNUSED = 7,
73 REMOVE_FROM_CRL = 8,
74 PRIVILEGE_WITHDRAWN = 9,
75 A_COMPROMISE = 10,
76
77 LAST = A_COMPROMISE,
78 };
79
80 Status status;
81 der::GeneralizedTime revocation_time;
82 bool has_reason;
83 RevocationReason revocation_reason;
84 };
85
86 // OCSPSingleResponse contains a representation of a DER-encoded RFC 6960
87 // "SingleResponse". The |cert_id_tlv| and |extensions| fields are pointers to
88 // the original object and are only valid as long as it is alive. They also
89 // aren't verified until they are parsed. |next_update| is only valid if
90 // |has_next_update| is true and |extensions| is only valid if |has_extensions|
91 // is true.
92 //
93 // SingleResponse ::= SEQUENCE {
94 // certID CertID,
95 // certStatus CertStatus,
96 // thisUpdate GeneralizedTime,
97 // nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL,
98 // singleExtensions [1] EXPLICIT Extensions OPTIONAL
99 // }
100 struct OCSPSingleResponse {
101 OCSPSingleResponse();
102 ~OCSPSingleResponse();
103
104 der::Input cert_id_tlv;
105 OCSPCertStatus cert_status;
106 der::GeneralizedTime this_update;
107 bool has_next_update;
108 der::GeneralizedTime next_update;
109 bool has_extensions;
110 der::Input extensions;
111 };
112
113 // OCSPResponseData contains a representation of a DER-encoded RFC 6960
114 // "ResponseData". The |responses| and |extensions| fields are pointers to the
115 // original object and are only valid as long as it is alive. They also aren't
116 // verified until they are parsed into OCSPSingleResponse and ParsedExtensions.
117 // |extensions| is only valid if |has_extensions| is true.
118 //
119 // ResponseData ::= SEQUENCE {
120 // version [0] EXPLICIT Version DEFAULT v1,
121 // responderID ResponderID,
122 // producedAt GeneralizedTime,
123 // responses SEQUENCE OF SingleResponse,
124 // responseExtensions [1] EXPLICIT Extensions OPTIONAL
125 // }
126 struct OCSPResponseData {
127 enum class ResponderType { NAME, KEY_HASH };
128
129 struct ResponderID {
130 ResponderType type;
131 der::Input name;
132 HashValue key_hash;
133 };
134
135 OCSPResponseData();
136 ~OCSPResponseData();
137
138 uint64_t version;
eroman 2016/02/16 23:42:26 Why change this to a uint64_t?
svaldez 2016/02/17 16:46:47 It makes the code simpler, but adding a ReadUint8
139 OCSPResponseData::ResponderID responder_id;
140 der::GeneralizedTime produced_at;
141 std::vector<der::Input> responses;
142 bool has_extensions;
143 der::Input extensions;
144 };
145
146 // OCSPResponse contains a representation of a DER-encoded RFC 6960
147 // "OCSPResponse" and the corresponding "BasicOCSPResponse". The |data| field
148 // is a pointer to the original object and are only valid as long is it is
149 // alive. The |data| field isn't verified until it is parsed into an
150 // OCSPResponseData. |data|, |signature_algorithm|, |signature|, and
151 // |has_certs| is only valid if |status| is SUCCESSFUL. |certs| is only valid
152 // if |has_certs| is true.
eroman 2016/02/16 23:42:26 Thanks, this extra comment helps.
svaldez 2016/02/17 16:46:47 Acknowledged.
153 //
154 // OCSPResponse ::= SEQUENCE {
155 // responseStatus OCSPResponseStatus,
156 // responseBytes [0] EXPLICIT ResponseBytes OPTIONAL
157 // }
158 //
159 // ResponseBytes ::= SEQUENCE {
160 // responseType OBJECT IDENTIFIER,
161 // response OCTET STRING
162 // }
163 //
164 // BasicOCSPResponse ::= SEQUENCE {
165 // tbsResponseData ResponseData,
166 // signatureAlgorithm AlgorithmIdentifier,
167 // signature BIT STRING,
168 // certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL
169 // }
170 struct NET_EXPORT OCSPResponse {
171 enum class ResponseStatus {
eroman 2016/02/16 23:42:26 Please indicate that these numbers correspond with
svaldez 2016/02/17 16:46:47 Done.
172 SUCCESSFUL = 0,
173 MALFORMED_REQUEST = 1,
174 INTERNAL_ERROR = 2,
175 TRY_LATER = 3,
176 UNUSED = 4,
177 SIG_REQUIRED = 5,
178 UNAUTHORIZED = 6,
179
180 LAST = UNAUTHORIZED,
181 };
182
183 OCSPResponse();
184 ~OCSPResponse();
185
186 ResponseStatus status;
187 der::Input data;
188 scoped_ptr<SignatureAlgorithm> signature_algorithm;
189 der::BitString signature;
190 bool has_certs;
191 std::vector<der::Input> certs;
192 };
193
194 // From RFC 6960:
195 //
196 // id-pkix-ocsp OBJECT IDENTIFIER ::= { id-ad-ocsp }
197 // id-pkix-ocsp-basic OBJECT IDENTIFIER ::= { id-pkix-ocsp 1 }
198 //
199 // In dotted notation: 1.3.6.1.5.5.7.48.1.1
200 NET_EXPORT der::Input BasicOCSPResponseOid();
201
202 // Parses a DER-encoded OCSP "CertID" as specified by RFC 6960. Returns true on
203 // success and sets the results in |out|.
204 //
205 // On failure |out| has an undefined state. Some of its fields may have been
206 // updated during parsing, whereas others may not have been changed.
207 NET_EXPORT_PRIVATE bool ParseOCSPCertID(const der::Input& raw_tlv,
208 OCSPCertID* out);
209
210 // Parses a DER-encoded OCSP "SingleResponse" as specified by RFC 6960. Returns
211 // true on success and sets the results in |out|. The resulting |out|
212 // references data from |raw_tlv| and is only valid for the lifetime of
213 // |raw_tlv|.
214 //
215 // On failure |out| has an undefined state. Some of its fields may have been
216 // updated during parsing, whereas others may not have been changed.
217 NET_EXPORT_PRIVATE bool ParseOCSPSingleResponse(const der::Input& raw_tlv,
218 OCSPSingleResponse* out);
219
220 // Parses a DER-encoded OCSP "ResponseData" as specified by RFC 6960. Returns
221 // true on success and sets the results in |out|. The resulting |out|
222 // references data from |raw_tlv| and is only valid for the lifetime of
223 // |raw_tlv|.
224 //
225 // On failure |out| has an undefined state. Some of its fields may have been
226 // updated during parsing, whereas others may not have been changed.
227 NET_EXPORT_PRIVATE bool ParseOCSPResponseData(const der::Input& raw_tlv,
228 OCSPResponseData* out);
229
230 // Parses a DER-encoded "OCSPResponse" as specified by RFC 6960. Returns true
231 // on success and sets the results in |out|. The resulting |out|
232 // references data from |raw_tlv| and is only valid for the lifetime of
233 // |raw_tlv|.
234 //
235 // On failure |out| has an undefined state. Some of its fields may have been
236 // updated during parsing, whereas others may not have been changed.
237 NET_EXPORT_PRIVATE bool ParseOCSPResponse(const der::Input& raw_tlv,
238 OCSPResponse* out);
239
240 // Checks the certificate status of |cert| based on the OCSPResponseData
241 // |response_data| and issuer |issuer| and sets the results in |out|.
242 //
243 // On failure |out| has an undefined state. Some of its fields may have been
244 // updated during parsing, whereas others may not have been changed.
245 NET_EXPORT_PRIVATE bool GetOCSPCertStatus(const OCSPResponseData& response_data,
246 const ParsedCertificate& issuer,
247 const ParsedCertificate& cert,
248 OCSPCertStatus* out);
249
250 // Verifies that the OCSP Response |response| is signed and has a valid trust
251 // path to the issuer |issuer_cert|.
252 NET_EXPORT_PRIVATE bool VerifyOCSPResponse(
253 const OCSPResponse& response,
254 const ParsedCertificate& issuer_cert);
255
256 } // namespace net
257
258 #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