summaryrefslogtreecommitdiffstats
path: root/net/base
diff options
context:
space:
mode:
Diffstat (limited to 'net/base')
-rw-r--r--net/base/crl_set.cc54
-rw-r--r--net/base/crl_set.h5
-rw-r--r--net/base/crl_set_unittest.cc46
3 files changed, 78 insertions, 27 deletions
diff --git a/net/base/crl_set.cc b/net/base/crl_set.cc
index 43d9204..f4e9fa7 100644
--- a/net/base/crl_set.cc
+++ b/net/base/crl_set.cc
@@ -3,9 +3,12 @@
// found in the LICENSE file.
#include "base/base64.h"
+#include "base/format_macros.h"
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/stl_util.h"
+#include "base/string_util.h"
+#include "base/stringprintf.h"
#include "base/values.h"
#include "crypto/sha2.h"
#include "net/base/crl_set.h"
@@ -310,7 +313,7 @@ bool ReadDeltaCRL(base::StringPiece* data,
bool CRLSet::ApplyDelta(base::StringPiece data,
scoped_refptr<CRLSet>* out_crl_set) {
- scoped_ptr<DictionaryValue> header_dict(ReadHeader(&data));
+ scoped_ptr<DictionaryValue> header_dict(ReadHeader(&data));
if (!header_dict.get())
return false;
@@ -389,6 +392,55 @@ bool CRLSet::ApplyDelta(base::StringPiece data,
return true;
}
+std::string CRLSet::Serialize() const {
+ std::string header = StringPrintf(
+ "{"
+ "\"Version\":0,"
+ "\"ContentType\":\"CRLSet\","
+ "\"Sequence\":%u,"
+ "\"DeltaFrom\":0,"
+ "\"NumParents\":%u"
+ "}",
+ static_cast<unsigned>(sequence_),
+ static_cast<unsigned>(crls_.size()));
+
+ size_t len = 2 /* header len */ + header.size();
+
+ for (CRLList::const_iterator i = crls_.begin(); i != crls_.end(); ++i) {
+ len += i->first.size() + 4 /* num serials */;
+ for (std::vector<std::string>::const_iterator j = i->second.begin();
+ j != i->second.end(); j++) {
+ len += 1 /* serial length */ + j->size();
+ }
+ }
+
+ std::string ret;
+ char* out = WriteInto(&ret, len + 1 /* to include final NUL */);
+ size_t off = 0;
+ out[off++] = header.size();
+ out[off++] = header.size() >> 8;
+ memcpy(out + off, header.data(), header.size());
+ off += header.size();
+
+ for (CRLList::const_iterator i = crls_.begin(); i != crls_.end(); ++i) {
+ memcpy(out + off, i->first.data(), i->first.size());
+ off += i->first.size();
+ const uint32 num_serials = i->second.size();
+ memcpy(out + off, &num_serials, sizeof(num_serials));
+ off += sizeof(num_serials);
+
+ for (std::vector<std::string>::const_iterator j = i->second.begin();
+ j != i->second.end(); j++) {
+ out[off++] = j->size();
+ memcpy(out + off, j->data(), j->size());
+ off += j->size();
+ }
+ }
+
+ CHECK_EQ(off, len);
+ return ret;
+}
+
CRLSet::Result CRLSet::CheckCertificate(
const base::StringPiece& serial_number,
const base::StringPiece& parent_spki) const {
diff --git a/net/base/crl_set.h b/net/base/crl_set.h
index 586a264..f9f0cb8 100644
--- a/net/base/crl_set.h
+++ b/net/base/crl_set.h
@@ -51,6 +51,11 @@ class NET_EXPORT CRLSet : public base::RefCountedThreadSafe<CRLSet> {
bool ApplyDelta(base::StringPiece delta_bytes,
scoped_refptr<CRLSet>* out_crl_set);
+ // Serialize returns a string of bytes suitable for passing to Parse. Parsing
+ // and serializing a CRLSet is a lossless operation - the resulting bytes
+ // will be equal.
+ std::string Serialize() const;
+
// sequence returns the sequence number of this CRL set. CRL sets generated
// by the same source are given strictly monotonically increasing sequence
// numbers.
diff --git a/net/base/crl_set_unittest.cc b/net/base/crl_set_unittest.cc
index cb5365a..160c020 100644
--- a/net/base/crl_set_unittest.cc
+++ b/net/base/crl_set_unittest.cc
@@ -8,35 +8,26 @@
// These data blocks were generated using a lot of code that is still in
// development. For now, if you need to update them, you have to contact agl.
static const uint8 kGIACRLSet[] = {
- 0xbe, 0x00, 0x7b, 0x22, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a,
+ 0x4e, 0x00, 0x7b, 0x22, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3a,
0x30, 0x2c, 0x22, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70,
0x65, 0x22, 0x3a, 0x22, 0x43, 0x52, 0x4c, 0x53, 0x65, 0x74, 0x22, 0x2c, 0x22,
0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x30, 0x2c, 0x22,
- 0x4e, 0x65, 0x78, 0x74, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x22, 0x3a, 0x31,
- 0x33, 0x31, 0x31, 0x31, 0x32, 0x34, 0x36, 0x35, 0x34, 0x2c, 0x22, 0x57, 0x69,
- 0x6e, 0x64, 0x6f, 0x77, 0x53, 0x65, 0x63, 0x73, 0x22, 0x3a, 0x34, 0x33, 0x32,
- 0x30, 0x30, 0x2c, 0x22, 0x44, 0x65, 0x6c, 0x74, 0x61, 0x46, 0x72, 0x6f, 0x6d,
- 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x4e, 0x75, 0x6d, 0x50, 0x61, 0x72, 0x65, 0x6e,
- 0x74, 0x73, 0x22, 0x3a, 0x31, 0x2c, 0x22, 0x53, 0x69, 0x67, 0x6e, 0x69, 0x6e,
- 0x67, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x22, 0x3a, 0x22,
- 0x22, 0x2c, 0x22, 0x53, 0x69, 0x67, 0x6e, 0x69, 0x6e, 0x67, 0x4b, 0x65, 0x79,
- 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x22, 0x3a, 0x22, 0x22,
- 0x2c, 0x22, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x53, 0x69, 0x67, 0x6e,
- 0x61, 0x74, 0x75, 0x72, 0x65, 0x22, 0x3a, 0x22, 0x22, 0x7d, 0xb6, 0xb9, 0x54,
- 0x32, 0xab, 0xae, 0x57, 0xfe, 0x02, 0x0c, 0xb2, 0xb7, 0x4f, 0x4f, 0x9f, 0x91,
- 0x73, 0xc8, 0xc7, 0x08, 0xaf, 0xc9, 0xe7, 0x32, 0xac, 0xe2, 0x32, 0x79, 0x04,
- 0x7c, 0x6d, 0x05, 0x0d, 0x00, 0x00, 0x00, 0x0a, 0x10, 0x0d, 0x7f, 0x30, 0x00,
- 0x03, 0x00, 0x00, 0x23, 0xb0, 0x0a, 0x10, 0x0e, 0x37, 0x06, 0x00, 0x03, 0x00,
- 0x00, 0x23, 0xb1, 0x0a, 0x16, 0x25, 0x42, 0x54, 0x00, 0x03, 0x00, 0x00, 0x14,
- 0x51, 0x0a, 0x16, 0x69, 0xd1, 0xd7, 0x00, 0x03, 0x00, 0x00, 0x14, 0x52, 0x0a,
- 0x16, 0x70, 0x8c, 0x22, 0x00, 0x03, 0x00, 0x00, 0x14, 0x53, 0x0a, 0x16, 0x71,
- 0x31, 0x2c, 0x00, 0x03, 0x00, 0x00, 0x14, 0x54, 0x0a, 0x16, 0x7d, 0x75, 0x9d,
- 0x00, 0x03, 0x00, 0x00, 0x14, 0x55, 0x0a, 0x1f, 0xee, 0xf9, 0x49, 0x00, 0x03,
- 0x00, 0x00, 0x23, 0xae, 0x0a, 0x1f, 0xfc, 0xd1, 0x89, 0x00, 0x03, 0x00, 0x00,
- 0x23, 0xaf, 0x0a, 0x61, 0xdd, 0xc7, 0x48, 0x00, 0x03, 0x00, 0x00, 0x18, 0x0e,
- 0x0a, 0x61, 0xe6, 0x12, 0x64, 0x00, 0x03, 0x00, 0x00, 0x18, 0x0f, 0x0a, 0x61,
- 0xe9, 0x46, 0x56, 0x00, 0x03, 0x00, 0x00, 0x18, 0x10, 0x0a, 0x64, 0x63, 0x49,
- 0xd2, 0x00, 0x03, 0x00, 0x00, 0x1d, 0x77,
+ 0x44, 0x65, 0x6c, 0x74, 0x61, 0x46, 0x72, 0x6f, 0x6d, 0x22, 0x3a, 0x30, 0x2c,
+ 0x22, 0x4e, 0x75, 0x6d, 0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x3a,
+ 0x31, 0x7d, 0xb6, 0xb9, 0x54, 0x32, 0xab, 0xae, 0x57, 0xfe, 0x02, 0x0c, 0xb2,
+ 0xb7, 0x4f, 0x4f, 0x9f, 0x91, 0x73, 0xc8, 0xc7, 0x08, 0xaf, 0xc9, 0xe7, 0x32,
+ 0xac, 0xe2, 0x32, 0x79, 0x04, 0x7c, 0x6d, 0x05, 0x0d, 0x00, 0x00, 0x00, 0x0a,
+ 0x10, 0x0d, 0x7f, 0x30, 0x00, 0x03, 0x00, 0x00, 0x23, 0xb0, 0x0a, 0x10, 0x0e,
+ 0x37, 0x06, 0x00, 0x03, 0x00, 0x00, 0x23, 0xb1, 0x0a, 0x16, 0x25, 0x42, 0x54,
+ 0x00, 0x03, 0x00, 0x00, 0x14, 0x51, 0x0a, 0x16, 0x69, 0xd1, 0xd7, 0x00, 0x03,
+ 0x00, 0x00, 0x14, 0x52, 0x0a, 0x16, 0x70, 0x8c, 0x22, 0x00, 0x03, 0x00, 0x00,
+ 0x14, 0x53, 0x0a, 0x16, 0x71, 0x31, 0x2c, 0x00, 0x03, 0x00, 0x00, 0x14, 0x54,
+ 0x0a, 0x16, 0x7d, 0x75, 0x9d, 0x00, 0x03, 0x00, 0x00, 0x14, 0x55, 0x0a, 0x1f,
+ 0xee, 0xf9, 0x49, 0x00, 0x03, 0x00, 0x00, 0x23, 0xae, 0x0a, 0x1f, 0xfc, 0xd1,
+ 0x89, 0x00, 0x03, 0x00, 0x00, 0x23, 0xaf, 0x0a, 0x61, 0xdd, 0xc7, 0x48, 0x00,
+ 0x03, 0x00, 0x00, 0x18, 0x0e, 0x0a, 0x61, 0xe6, 0x12, 0x64, 0x00, 0x03, 0x00,
+ 0x00, 0x18, 0x0f, 0x0a, 0x61, 0xe9, 0x46, 0x56, 0x00, 0x03, 0x00, 0x00, 0x18,
+ 0x10, 0x0a, 0x64, 0x63, 0x49, 0xd2, 0x00, 0x03, 0x00, 0x00, 0x1d, 0x77,
};
static const uint8 kNoopDeltaCRL[] = {
@@ -202,6 +193,9 @@ TEST(CRLSetTest, NoOpDeltaUpdate) {
sizeof(kNoopDeltaCRL));
EXPECT_TRUE(set->ApplyDelta(delta, &delta_set));
ASSERT_TRUE(delta_set.get() != NULL);
+
+ std::string out = delta_set->Serialize();
+ EXPECT_EQ(s.as_string(), out);
}
TEST(CRLSetTest, AddCRLDelta) {