10f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 20f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 30f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// found in the LICENSE file. 40f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 50f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "net/cert/signed_certificate_timestamp.h" 60f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 7a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/pickle.h" 8a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 90f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)namespace net { 100f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 110f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)namespace ct { 120f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)bool SignedCertificateTimestamp::LessThan::operator()( 14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const scoped_refptr<SignedCertificateTimestamp>& lhs, 15f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const scoped_refptr<SignedCertificateTimestamp>& rhs) const { 16f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (lhs.get() == rhs.get()) 17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return false; 18f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (lhs->signature.signature_data != rhs->signature.signature_data) 19f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return lhs->signature.signature_data < rhs->signature.signature_data; 20f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (lhs->log_id != rhs->log_id) 21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return lhs->log_id < rhs->log_id; 22f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (lhs->timestamp != rhs->timestamp) 23f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return lhs->timestamp < rhs->timestamp; 24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (lhs->extensions != rhs->extensions) 25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return lhs->extensions < rhs->extensions; 26f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return lhs->version < rhs->version; 27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 28f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 290f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)SignedCertificateTimestamp::SignedCertificateTimestamp() {} 300f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 310f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)SignedCertificateTimestamp::~SignedCertificateTimestamp() {} 320f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 33a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void SignedCertificateTimestamp::Persist(Pickle* pickle) { 34a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) CHECK(pickle->WriteInt(version)); 35a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) CHECK(pickle->WriteString(log_id)); 36a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) CHECK(pickle->WriteInt64(timestamp.ToInternalValue())); 37a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) CHECK(pickle->WriteString(extensions)); 38a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) CHECK(pickle->WriteInt(signature.hash_algorithm)); 39a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) CHECK(pickle->WriteInt(signature.signature_algorithm)); 40a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) CHECK(pickle->WriteString(signature.signature_data)); 41a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) CHECK(pickle->WriteInt(origin)); 42a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) CHECK(pickle->WriteString(log_description)); 43a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 44a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 45a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// static 46a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)scoped_refptr<SignedCertificateTimestamp> 47a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)SignedCertificateTimestamp::CreateFromPickle(PickleIterator* iter) { 48a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) int version; 49a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) int64 timestamp; 50a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) int hash_algorithm; 51a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) int sig_algorithm; 52a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) scoped_refptr<SignedCertificateTimestamp> sct( 53a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) new SignedCertificateTimestamp()); 54a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) int origin; 55a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // string values are set directly 56a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (!(iter->ReadInt(&version) && 57a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) iter->ReadString(&sct->log_id) && 58a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) iter->ReadInt64(×tamp) && 59a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) iter->ReadString(&sct->extensions) && 60a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) iter->ReadInt(&hash_algorithm) && 61a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) iter->ReadInt(&sig_algorithm) && 62a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) iter->ReadString(&sct->signature.signature_data) && 63a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) iter->ReadInt(&origin) && 64a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) iter->ReadString(&sct->log_description))) { 65a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return NULL; 66a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 67a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Now set the rest of the member variables: 68a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) sct->version = static_cast<Version>(version); 69a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) sct->timestamp = base::Time::FromInternalValue(timestamp); 70a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) sct->signature.hash_algorithm = 71a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) static_cast<DigitallySigned::HashAlgorithm>(hash_algorithm); 72a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) sct->signature.signature_algorithm = 73a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) static_cast<DigitallySigned::SignatureAlgorithm>(sig_algorithm); 74a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) sct->origin = static_cast<Origin>(origin); 75a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return sct; 76a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 77a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 780f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)LogEntry::LogEntry() {} 790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 800f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)LogEntry::~LogEntry() {} 810f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 820f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)void LogEntry::Reset() { 830f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) type = LogEntry::LOG_ENTRY_TYPE_X509; 840f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) leaf_certificate.clear(); 850f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) tbs_certificate.clear(); 860f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 870f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 880f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)DigitallySigned::DigitallySigned() {} 890f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 900f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)DigitallySigned::~DigitallySigned() {} 910f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 920f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} // namespace ct 930f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 940f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} // namespace net 95