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

Side by Side Diff: net/test/ct_test_util.cc

Issue 1576513002: Serialisation code for Certificate Transparency data (Closed) Base URL: ssh://caladan.lon.corp.google.com/usr/local/google/eranm/opensource_clients/chrome/src@sth_consistency_validation_2
Patch Set: Created 4 years, 11 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
« net/test/ct_test_util.h ('K') | « net/test/ct_test_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/test/ct_test_util.h" 5 #include "net/test/ct_test_util.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 198
199 std::string GetTestPublicKeyId() { 199 std::string GetTestPublicKeyId() {
200 return HexToBytes(kTestKeyId); 200 return HexToBytes(kTestKeyId);
201 } 201 }
202 202
203 void GetX509CertSCT(scoped_refptr<SignedCertificateTimestamp>* sct_ref) { 203 void GetX509CertSCT(scoped_refptr<SignedCertificateTimestamp>* sct_ref) {
204 CHECK(sct_ref != NULL); 204 CHECK(sct_ref != NULL);
205 *sct_ref = new SignedCertificateTimestamp(); 205 *sct_ref = new SignedCertificateTimestamp();
206 SignedCertificateTimestamp *const sct(sct_ref->get()); 206 SignedCertificateTimestamp *const sct(sct_ref->get());
207 sct->version = ct::SignedCertificateTimestamp::SCT_VERSION_1; 207 sct->version = ct::SignedCertificateTimestamp::SCT_VERSION_1;
208 sct->log_id = HexToBytes(kTestKeyId); 208 sct->log_id = GetTestPublicKeyId();
209 // Time the log issued a SCT for this certificate, which is 209 // Time the log issued a SCT for this certificate, which is
210 // Fri Apr 5 10:04:16.089 2013 210 // Fri Apr 5 10:04:16.089 2013
211 sct->timestamp = base::Time::UnixEpoch() + 211 sct->timestamp = base::Time::UnixEpoch() +
212 base::TimeDelta::FromMilliseconds(INT64_C(1365181456089)); 212 base::TimeDelta::FromMilliseconds(INT64_C(1365181456089));
213 sct->extensions.clear(); 213 sct->extensions.clear();
214 214
215 sct->signature.hash_algorithm = ct::DigitallySigned::HASH_ALGO_SHA256; 215 sct->signature.hash_algorithm = ct::DigitallySigned::HASH_ALGO_SHA256;
216 sct->signature.signature_algorithm = ct::DigitallySigned::SIG_ALGO_ECDSA; 216 sct->signature.signature_algorithm = ct::DigitallySigned::SIG_ALGO_ECDSA;
217 sct->signature.signature_data = HexToBytes(kTestSCTSignatureData); 217 sct->signature.signature_data = HexToBytes(kTestSCTSignatureData);
218 } 218 }
219 219
220 void GetPrecertSCT(scoped_refptr<SignedCertificateTimestamp>* sct_ref) { 220 void GetPrecertSCT(scoped_refptr<SignedCertificateTimestamp>* sct_ref) {
221 CHECK(sct_ref != NULL); 221 CHECK(sct_ref != NULL);
222 *sct_ref = new SignedCertificateTimestamp(); 222 *sct_ref = new SignedCertificateTimestamp();
223 SignedCertificateTimestamp *const sct(sct_ref->get()); 223 SignedCertificateTimestamp *const sct(sct_ref->get());
224 sct->version = ct::SignedCertificateTimestamp::SCT_VERSION_1; 224 sct->version = ct::SignedCertificateTimestamp::SCT_VERSION_1;
225 sct->log_id = HexToBytes(kTestKeyId); 225 sct->log_id = GetTestPublicKeyId();
226 // Time the log issued a SCT for this Precertificate, which is 226 // Time the log issued a SCT for this Precertificate, which is
227 // Fri Apr 5 10:04:16.275 2013 227 // Fri Apr 5 10:04:16.275 2013
228 sct->timestamp = base::Time::UnixEpoch() + 228 sct->timestamp = base::Time::UnixEpoch() +
229 base::TimeDelta::FromMilliseconds(INT64_C(1365181456275)); 229 base::TimeDelta::FromMilliseconds(INT64_C(1365181456275));
230 sct->extensions.clear(); 230 sct->extensions.clear();
231 231
232 sct->signature.hash_algorithm = ct::DigitallySigned::HASH_ALGO_SHA256; 232 sct->signature.hash_algorithm = ct::DigitallySigned::HASH_ALGO_SHA256;
233 sct->signature.signature_algorithm = ct::DigitallySigned::SIG_ALGO_ECDSA; 233 sct->signature.signature_algorithm = ct::DigitallySigned::SIG_ALGO_ECDSA;
234 sct->signature.signature_data = HexToBytes(kTestSCTPrecertSignatureData); 234 sct->signature.signature_data = HexToBytes(kTestSCTPrecertSignatureData);
235 } 235 }
(...skipping 14 matching lines...) Expand all
250 return HexToBytes(kFakeOCSPResponseCert); 250 return HexToBytes(kFakeOCSPResponseCert);
251 } 251 }
252 252
253 std::string GetDerEncodedFakeOCSPResponseIssuerCert() { 253 std::string GetDerEncodedFakeOCSPResponseIssuerCert() {
254 return HexToBytes(kFakeOCSPResponseIssuerCert); 254 return HexToBytes(kFakeOCSPResponseIssuerCert);
255 } 255 }
256 256
257 // A sample, valid STH 257 // A sample, valid STH
258 void GetSampleSignedTreeHead(SignedTreeHead* sth) { 258 void GetSampleSignedTreeHead(SignedTreeHead* sth) {
259 sth->version = SignedTreeHead::V1; 259 sth->version = SignedTreeHead::V1;
260 sth->log_id = GetTestPublicKeyId();
260 sth->timestamp = base::Time::UnixEpoch() + 261 sth->timestamp = base::Time::UnixEpoch() +
261 base::TimeDelta::FromMilliseconds(kSampleSTHTimestamp); 262 base::TimeDelta::FromMilliseconds(kSampleSTHTimestamp);
262 sth->tree_size = kSampleSTHTreeSize; 263 sth->tree_size = kSampleSTHTreeSize;
263 std::string sha256_root_hash = GetSampleSTHSHA256RootHash(); 264 std::string sha256_root_hash = GetSampleSTHSHA256RootHash();
264 memcpy(sth->sha256_root_hash, sha256_root_hash.c_str(), kSthRootHashLength); 265 memcpy(sth->sha256_root_hash, sha256_root_hash.c_str(), kSthRootHashLength);
265 266
266 GetSampleSTHTreeHeadDecodedSignature(&(sth->signature)); 267 GetSampleSTHTreeHeadDecodedSignature(&(sth->signature));
267 } 268 }
268 269
269 std::string GetSampleSTHSHA256RootHash() { 270 std::string GetSampleSTHSHA256RootHash() {
270 return HexToBytes(kSampleSTHSHA256RootHash); 271 return HexToBytes(kSampleSTHSHA256RootHash);
271 } 272 }
272 273
273 std::string GetSampleSTHTreeHeadSignature() { 274 std::string GetSampleSTHTreeHeadSignature() {
274 return HexToBytes(kSampleSTHTreeHeadSignature); 275 return HexToBytes(kSampleSTHTreeHeadSignature);
275 } 276 }
276 277
277 void GetSampleSTHTreeHeadDecodedSignature(DigitallySigned* signature) { 278 void GetSampleSTHTreeHeadDecodedSignature(DigitallySigned* signature) {
278 std::string tree_head_signature = HexToBytes(kSampleSTHTreeHeadSignature); 279 std::string tree_head_signature = HexToBytes(kSampleSTHTreeHeadSignature);
279 base::StringPiece sp(tree_head_signature); 280 base::StringPiece sp(tree_head_signature);
280 CHECK(DecodeDigitallySigned(&sp, signature)); 281 CHECK(DecodeDigitallySigned(&sp, signature));
281 CHECK(sp.empty()); 282 CHECK(sp.empty());
282 } 283 }
283 284
285 std::string GetSampleSTH() {
286 const std::string log_id = ct::GetTestPublicKeyId();
287 const std::string timestamp("\x0\x0\x1\x45\x3c\x5f\xb8\x35", 8);
Eran Messeri 2016/01/14 12:46:45 Why not use the encoding functions you've added to
288 const std::string tree_size("\x0\x0\x0\x0\x0\x0\x0\x15", 8);
289
290 std::string expected_output;
291 expected_output += log_id;
292 expected_output += timestamp;
293 expected_output += tree_size;
294 expected_output += ct::GetSampleSTHSHA256RootHash();
295 expected_output += ct::GetSampleSTHTreeHeadSignature();
296
297 return expected_output;
298 }
299
284 std::string GetSampleSTHAsJson() { 300 std::string GetSampleSTHAsJson() {
285 return CreateSignedTreeHeadJsonString(kSampleSTHTreeSize, kSampleSTHTimestamp, 301 return CreateSignedTreeHeadJsonString(kSampleSTHTreeSize, kSampleSTHTimestamp,
286 GetSampleSTHSHA256RootHash(), 302 GetSampleSTHSHA256RootHash(),
287 GetSampleSTHTreeHeadSignature()); 303 GetSampleSTHTreeHeadSignature());
288 } 304 }
289 305
290 std::string CreateSignedTreeHeadJsonString(size_t tree_size, 306 std::string CreateSignedTreeHeadJsonString(size_t tree_size,
291 int64_t timestamp, 307 int64_t timestamp,
292 std::string sha256_root_hash, 308 std::string sha256_root_hash,
293 std::string tree_head_signature) { 309 std::string tree_head_signature) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 consistency_proof_json += std::string(","); 341 consistency_proof_json += std::string(",");
326 } 342 }
327 consistency_proof_json += std::string("]}"); 343 consistency_proof_json += std::string("]}");
328 344
329 return consistency_proof_json; 345 return consistency_proof_json;
330 } 346 }
331 347
332 } // namespace ct 348 } // namespace ct
333 349
334 } // namespace net 350 } // namespace net
OLDNEW
« net/test/ct_test_util.h ('K') | « net/test/ct_test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698