Bug 1503348 - (1/3) remove obsolete SignedTreeHead definitions and tests r=jcj
authorDana Keeler <dkeeler@mozilla.com>
Tue, 27 Nov 2018 18:58:07 +0000
changeset 504832 9ef08b4eeea6096d4687a5f957da9f35909d461d
parent 504831 093960021b8b20b3c1963c9d1b1fc6809f60fd6b
child 504833 129e0faf881363698dd884916e4601d68c6d71c3
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjcj
bugs1503348
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1503348 - (1/3) remove obsolete SignedTreeHead definitions and tests r=jcj The original implementation of Certificate Transparency included a definition for the first version of the Signed Tree Head data structure but it was never actually used. Now that we're implementing Binary Transparency, we need to implement support for Signed Tree Head V2. Because the focus and approach are different, the first step is to remove the original implementation. Differential Revision: https://phabricator.services.mozilla.com/D11810
security/ct/CTLogVerifier.cpp
security/ct/CTLogVerifier.h
security/ct/CTSerialization.cpp
security/ct/CTSerialization.h
security/ct/SignedTreeHead.h
security/ct/moz.build
security/ct/tests/gtest/CTLogVerifierTest.cpp
security/ct/tests/gtest/CTSerializationTest.cpp
security/ct/tests/gtest/CTTestUtils.cpp
security/ct/tests/gtest/CTTestUtils.h
--- a/security/ct/CTLogVerifier.cpp
+++ b/security/ct/CTLogVerifier.cpp
@@ -233,31 +233,16 @@ CTLogVerifier::Verify(const LogEntry& en
   rv = EncodeV1SCTSignedData(sct.timestamp, logEntryInput, sctExtensionsInput,
                              serializedData);
   if (rv != Success) {
     return rv;
   }
   return VerifySignature(serializedData, sct.signature.signatureData);
 }
 
-Result
-CTLogVerifier::VerifySignedTreeHead(const SignedTreeHead& sth)
-{
-  if (!SignatureParametersMatch(sth.signature)) {
-    return Result::FATAL_ERROR_INVALID_ARGS;
-  }
-
-  Buffer serializedData;
-  Result rv = EncodeTreeHeadSignature(sth, serializedData);
-  if (rv != Success) {
-    return rv;
-  }
-  return VerifySignature(serializedData, sth.signature.signatureData);
-}
-
 bool
 CTLogVerifier::SignatureParametersMatch(const DigitallySigned& signature)
 {
   return signature.SignatureParametersMatch(
     DigitallySigned::HashAlgorithm::SHA256, mSignatureAlgorithm);
 }
 
 static Result
--- a/security/ct/CTLogVerifier.h
+++ b/security/ct/CTLogVerifier.h
@@ -7,17 +7,16 @@
 #ifndef CTLogVerifier_h
 #define CTLogVerifier_h
 
 #include <memory>
 
 #include "CTLog.h"
 #include "CTUtils.h"
 #include "SignedCertificateTimestamp.h"
-#include "SignedTreeHead.h"
 #include "mozpkix/Input.h"
 #include "mozpkix/Result.h"
 #include "mozpkix/pkix.h"
 
 namespace mozilla { namespace ct {
 
 // Verifies Signed Certificate Timestamps (SCTs) provided by a specific log
 // using the public key of that log. Assumes the SCT being verified
@@ -53,20 +52,16 @@ public:
   bool isDisqualified() const { return mDisqualified; }
   uint64_t disqualificationTime() const { return mDisqualificationTime; }
 
   // Verifies that |sct| contains a valid signature for |entry|.
   // |sct| must be signed by the verifier's log.
   pkix::Result Verify(const LogEntry& entry,
                       const SignedCertificateTimestamp& sct);
 
-  // Verifies the signature in |sth|.
-  // |sth| must be signed by the verifier's log.
-  pkix::Result VerifySignedTreeHead(const SignedTreeHead& sth);
-
   // Returns true if the signature and hash algorithms in |signature|
   // match those of the log.
   bool SignatureParametersMatch(const DigitallySigned& signature);
 
 private:
   // Performs the underlying verification using the log's public key. Note
   // that |signature| contains the raw signature data (i.e. without any
   // DigitallySigned struct encoding).
--- a/security/ct/CTSerialization.cpp
+++ b/security/ct/CTSerialization.cpp
@@ -391,45 +391,16 @@ EncodeV1SCTSignedData(uint64_t timestamp
   }
   // NOTE: serializedLogEntry must already be serialized and contain the
   // length as the prefix.
   WriteEncodedBytes(serializedLogEntry, output);
   return WriteVariableBytes<kExtensionsLengthBytes>(extensions, output);
 }
 
 Result
-EncodeTreeHeadSignature(const SignedTreeHead& signedTreeHead,
-                        Buffer& output)
-{
-  Result rv = WriteUint<kVersionLength>(
-    static_cast<unsigned int>(signedTreeHead.version), output);
-  if (rv != Success) {
-    return rv;
-  }
-  rv = WriteUint<kSignatureTypeLength>(
-    static_cast<unsigned int>(SignatureType::TreeHash), output);
-  if (rv != Success) {
-    return rv;
-  }
-  rv = WriteTimeSinceEpoch(signedTreeHead.timestamp, output);
-  if (rv != Success) {
-    return rv;
-  }
-  rv = WriteUint<kTreeSizeLength>(signedTreeHead.treeSize, output);
-  if (rv != Success) {
-    return rv;
-  }
-  if (signedTreeHead.sha256RootHash.size() != kSthRootHashLength) {
-    return Result::FATAL_ERROR_INVALID_ARGS;
-  }
-  WriteEncodedBytes(signedTreeHead.sha256RootHash, output);
-  return Success;
-}
-
-Result
 DecodeSCTList(Input input, Reader& listReader)
 {
   Reader inputReader(input);
   Input listData;
   Result rv = ReadVariableBytes<kSCTListLengthBytes>(inputReader, listData);
   if (rv != Success) {
     return rv;
   }
--- a/security/ct/CTSerialization.h
+++ b/security/ct/CTSerialization.h
@@ -7,17 +7,16 @@
 #ifndef CTSerialization_h
 #define CTSerialization_h
 
 #include <vector>
 
 #include "mozpkix/Input.h"
 #include "mozpkix/Result.h"
 #include "SignedCertificateTimestamp.h"
-#include "SignedTreeHead.h"
 
 // Utility functions for encoding/decoding structures used by Certificate
 // Transparency to/from the TLS wire format encoding.
 namespace mozilla { namespace ct {
 
 // Encodes the DigitallySigned |data| to |output|.
 pkix::Result EncodeDigitallySigned(const DigitallySigned& data,
                                    Buffer& output);
@@ -37,22 +36,16 @@ pkix::Result EncodeLogEntry(const LogEnt
 // |timestamp| timestamp from the SCT.
 // |serializedLogEntry| the log entry signed by the SCT.
 // |extensions| CT extensions.
 pkix::Result EncodeV1SCTSignedData(uint64_t timestamp,
                                    pkix::Input serializedLogEntry,
                                    pkix::Input extensions,
                                    Buffer& output);
 
-// Encodes the data signed by a Signed Tree Head (STH) |signedTreeHead| into
-// |output|. The signature included in the |signedTreeHead| can then be
-// verified over these bytes.
-pkix::Result EncodeTreeHeadSignature(const SignedTreeHead& signedTreeHead,
-                                     Buffer& output);
-
 // Decodes a list of Signed Certificate Timestamps
 // (SignedCertificateTimestampList as defined in RFC6962). This list
 // is typically obtained from the CT extension in a certificate.
 // To extract the individual items of the list, call ReadSCTListItem on
 // the returned reader until the reader reaches its end.
 // Note that the validity of each extracted SCT should be checked separately.
 pkix::Result DecodeSCTList(pkix::Input input, pkix::Reader& listReader);
 
deleted file mode 100644
--- a/security/ct/SignedTreeHead.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef SignedTreeHead_h
-#define SignedTreeHead_h
-
-#include "SignedCertificateTimestamp.h"
-
-namespace mozilla { namespace ct {
-
-// Signed Tree Head as defined in section 3.5. of RFC-6962.
-struct SignedTreeHead
-{
-  // Version enum in RFC 6962, Section 3.2. Note that while in the current
-  // RFC the STH and SCT share the versioning scheme, there are plans in
-  // RFC-6962-bis to use separate versions, so using a separate scheme here.
-  enum class Version { V1 = 0, };
-
-  Version version;
-  uint64_t timestamp;
-  uint64_t treeSize;
-  Buffer sha256RootHash;
-  DigitallySigned signature;
-};
-
-} } // namespace mozilla::ct
-
-#endif // SignedTreeHead_h
--- a/security/ct/moz.build
+++ b/security/ct/moz.build
@@ -10,17 +10,16 @@ with Files("**"):
 EXPORTS += [
     'BTInclusionProof.h',
     'BTVerifier.h',
     'Buffer.h',
     'CTLog.h',
     'CTPolicyEnforcer.h',
     'CTVerifyResult.h',
     'SignedCertificateTimestamp.h',
-    'SignedTreeHead.h',
 ]
 
 UNIFIED_SOURCES += [
     'BTVerifier.cpp',
     'Buffer.cpp',
     'CTDiversityPolicy.cpp',
     'CTLogVerifier.cpp',
     'CTObjectsExtractor.cpp',
--- a/security/ct/tests/gtest/CTLogVerifierTest.cpp
+++ b/security/ct/tests/gtest/CTLogVerifierTest.cpp
@@ -104,31 +104,16 @@ TEST_F(CTLogVerifierTest, FailsInvalidLo
   // Mangle the log ID, which should cause it to match a different log before
   // attempting signature validation.
   certSct.logId.push_back('\x0');
 
   EXPECT_EQ(pkix::Result::FATAL_ERROR_INVALID_ARGS, mLog.Verify(certEntry,
                                                                 certSct));
 }
 
-TEST_F(CTLogVerifierTest, VerifiesValidSTH)
-{
-  SignedTreeHead sth;
-  GetSampleSignedTreeHead(sth);
-  EXPECT_EQ(Success, mLog.VerifySignedTreeHead(sth));
-}
-
-TEST_F(CTLogVerifierTest, DoesNotVerifyInvalidSTH)
-{
-  SignedTreeHead sth;
-  GetSampleSignedTreeHead(sth);
-  sth.sha256RootHash[0] ^= '\xFF';
-  EXPECT_EQ(pkix::Result::ERROR_BAD_SIGNATURE, mLog.VerifySignedTreeHead(sth));
-}
-
 // Test that excess data after the public key is rejected.
 TEST_F(CTLogVerifierTest, ExcessDataInPublicKey)
 {
   Buffer key = GetTestPublicKey();
   std::string extra = "extra";
   key.insert(key.end(), extra.begin(), extra.end());
 
   CTLogVerifier log;
--- a/security/ct/tests/gtest/CTSerializationTest.cpp
+++ b/security/ct/tests/gtest/CTSerializationTest.cpp
@@ -225,35 +225,9 @@ TEST_F(CTSerializationTest, FailsDecodin
   // Valid version, invalid length (missing data)
   const uint8_t INVALID_LENGTH_BYTES[] = { 0x00, 0x0a, 0x0b, 0x0c };
   Input invalidLengthSctInput(INVALID_LENGTH_BYTES);
   Reader invalidLengthSctReader(invalidLengthSctInput);
   EXPECT_EQ(pkix::Result::ERROR_BAD_DER,
     DecodeSignedCertificateTimestamp(invalidLengthSctReader, sct));
 }
 
-TEST_F(CTSerializationTest, EncodesValidSignedTreeHead)
-{
-  SignedTreeHead signedTreeHead;
-  GetSampleSignedTreeHead(signedTreeHead);
-
-  Buffer encoded;
-  ASSERT_EQ(Success,
-    EncodeTreeHeadSignature(signedTreeHead, encoded));
-  // Expected size is 50 bytes:
-  // Byte 0 is version, byte 1 is signature type
-  // Bytes 2-9 are timestamp
-  // Bytes 10-17 are tree size
-  // Bytes 18-49 are sha256 root hash
-  ASSERT_EQ(50u, encoded.size());
-  Buffer expectedBuffer = {
-    0x00, // version
-    0x01, // signature type
-    0x00, 0x00, 0x01, 0x45, 0x3c, 0x5f, 0xb8, 0x35, // timestamp
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15  // tree size
-    // sha256 root hash should follow
-  };
-  Buffer hash = GetSampleSTHSHA256RootHash();
-  expectedBuffer.insert(expectedBuffer.end(), hash.begin(),
-                        hash.begin() + hash.size());
-  EXPECT_EQ(expectedBuffer, encoded);
-}
 } } // namespace mozilla::ct
--- a/security/ct/tests/gtest/CTTestUtils.cpp
+++ b/security/ct/tests/gtest/CTTestUtils.cpp
@@ -15,17 +15,16 @@
 #include "mozpkix/Input.h"
 #include "mozpkix/pkix.h"
 #include "mozpkix/pkixnss.h"
 #include "mozpkix/pkixtypes.h"
 #include "mozpkix/Result.h"
 #include "mozpkix/pkixcheck.h"
 #include "mozpkix/pkixutil.h"
 #include "SignedCertificateTimestamp.h"
-#include "SignedTreeHead.h"
 
 namespace mozilla { namespace ct {
 
 using namespace mozilla::pkix;
 
 // The following test vectors are from the CT test data repository at
 // https://github.com/google/certificate-transparency/tree/master/test/testdata
 
@@ -102,26 +101,16 @@ const char kTestSCTSignatureData[] =
     "30450220606e10ae5c2d5a1b0aed49dc4937f48de71a4e9784e9c208dfbfe9ef536cf7f202"
     "2100beb29c72d7d06d61d06bdb38a069469aa86fe12e18bb7cc45689a2c0187ef5a5";
 
 // signature field of DigitallySigned from test-embedded-pre-cert.proof
 const char kTestSCTPrecertSignatureData[] =
     "30450220482f6751af35dba65436be1fd6640f3dbf9a41429495924530288fa3e5e23e0602"
     "2100e4edc0db3ac572b1e2f5e8ab6a680653987dcf41027dfeffa105519d89edbf08";
 
-// For the sample STH
-const char kSampleSTHSHA256RootHash[] =
-    "726467216167397babca293dca398e4ce6b621b18b9bc42f30c900d1f92ac1e4";
-const char kSampleSTHTreeHeadSignature[] =
-    "0403004730450220365a91a2a88f2b9332f41d8959fa7086da7e6d634b7b089bc9da066426"
-    "6c7a20022100e38464f3c0fd066257b982074f7ac87655e0c8f714768a050b4be9a7b441cb"
-    "d3";
-const size_t kSampleSTHTreeSize = 21u;
-const uint64_t kSampleSTHTimestamp = 1396877277237u;
-
 // test-embedded-cert.pem
 const char kTestEmbeddedCertData[] =
   "30820359308202c2a003020102020107300d06092a864886f70d01010505"
   "003055310b300906035504061302474231243022060355040a131b436572"
   "7469666963617465205472616e73706172656e6379204341310e300c0603"
   "550408130557616c65733110300e060355040713074572772057656e301e"
   "170d3132303630313030303030305a170d3232303630313030303030305a"
   "3052310b30090603550406130247423121301f060355040a131843657274"
@@ -628,50 +617,16 @@ GetPrecertSCT(SignedCertificateTimestamp
 }
 
 Buffer
 GetDefaultIssuerKeyHash()
 {
   return HexToBytes(kDefaultIssuerKeyHash);
 }
 
-// A sample, valid STH
-void
-GetSampleSignedTreeHead(SignedTreeHead& sth)
-{
-  sth.version = SignedTreeHead::Version::V1;
-  sth.timestamp = kSampleSTHTimestamp;
-  sth.treeSize = kSampleSTHTreeSize;
-  sth.sha256RootHash = GetSampleSTHSHA256RootHash();
-  GetSampleSTHTreeHeadDecodedSignature(sth.signature);
-}
-
-Buffer
-GetSampleSTHSHA256RootHash()
-{
-  return HexToBytes(kSampleSTHSHA256RootHash);
-}
-
-Buffer
-GetSampleSTHTreeHeadSignature()
-{
-  return HexToBytes(kSampleSTHTreeHeadSignature);
-}
-
-void
-GetSampleSTHTreeHeadDecodedSignature(DigitallySigned& signature)
-{
-  Buffer ths = HexToBytes(kSampleSTHTreeHeadSignature);
-  Input thsInput;
-  ASSERT_EQ(Success, thsInput.Init(ths.data(), ths.size()));
-  Reader thsReader(thsInput);
-  ASSERT_EQ(Success, DecodeDigitallySigned(thsReader, signature));
-  ASSERT_TRUE(thsReader.AtEnd());
-}
-
 Buffer
 GetDEREncodedTestEmbeddedCert()
 {
   return HexToBytes(kTestEmbeddedCertData);
 }
 
 Buffer
 GetDEREncodedTestTbsCert()
--- a/security/ct/tests/gtest/CTTestUtils.h
+++ b/security/ct/tests/gtest/CTTestUtils.h
@@ -8,17 +8,16 @@
 #define CTTestUtils_h
 
 #include <iostream>
 
 #include "mozpkix/Input.h"
 #include "mozpkix/Time.h"
 #include "seccomon.h"
 #include "SignedCertificateTimestamp.h"
-#include "SignedTreeHead.h"
 
 namespace mozilla { namespace ct {
 
 Buffer HexToBytes(const char* hexData);
 
 // Note: unless specified otherwise, all test data is taken from
 // Certificate Transparency test data repository at
 // https://github.com/google/certificate-transparency/tree/master/test/testdata
@@ -70,19 +69,16 @@ Buffer GetTestPublicKeyId();
 void GetX509CertSCT(SignedCertificateTimestamp& sct);
 
 // SCT for the Precertificate log entry provided above.
 void GetPrecertSCT(SignedCertificateTimestamp& sct);
 
 // Issuer key hash.
 Buffer GetDefaultIssuerKeyHash();
 
-// A sample, valid STH.
-void GetSampleSignedTreeHead(SignedTreeHead& sth);
-
 // The SHA256 root hash for the sample STH.
 Buffer GetSampleSTHSHA256RootHash();
 
 // The tree head signature for the sample STH.
 Buffer GetSampleSTHTreeHeadSignature();
 
 // The same signature as GetSampleSTHTreeHeadSignature, decoded.
 void GetSampleSTHTreeHeadDecodedSignature(DigitallySigned& signature);