Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/security/certverifier/SignedCertificateTimestamp.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef SignedCertificateTimestamp_h
8
#define SignedCertificateTimestamp_h
9
10
#include "Buffer.h"
11
#include "mozilla/Vector.h"
12
#include "pkix/Input.h"
13
#include "pkix/Result.h"
14
15
// Structures related to Certificate Transparency (RFC 6962).
16
namespace mozilla { namespace ct {
17
18
// LogEntry struct in RFC 6962, Section 3.1.
19
struct LogEntry
20
{
21
22
  // LogEntryType enum in RFC 6962, Section 3.1.
23
  enum class Type {
24
    X509 = 0,
25
    Precert = 1
26
  };
27
28
  void Reset();
29
30
  Type type;
31
32
  // Set if type == X509.
33
  Buffer leafCertificate;
34
35
  // Set if type == Precert.
36
  Buffer issuerKeyHash;
37
  Buffer tbsCertificate;
38
};
39
40
// Helper structure to represent Digitally Signed data, as described in
41
// Sections 4.7 and 7.4.1.4.1 of RFC 5246.
42
struct DigitallySigned
43
{
44
  enum class HashAlgorithm {
45
    None = 0,
46
    MD5 = 1,
47
    SHA1 = 2,
48
    SHA224 = 3,
49
    SHA256 = 4,
50
    SHA384 = 5,
51
    SHA512 = 6,
52
  };
53
54
  enum class SignatureAlgorithm {
55
    Anonymous = 0,
56
    RSA = 1,
57
    DSA = 2,
58
    ECDSA = 3
59
  };
60
61
  // Returns true if |aHashAlgorithm| and |aSignatureAlgorithm|
62
  // match this DigitallySigned hash and signature algorithms.
63
  bool SignatureParametersMatch(HashAlgorithm aHashAlgorithm,
64
                                SignatureAlgorithm aSignatureAlgorithm) const;
65
66
  HashAlgorithm hashAlgorithm;
67
  SignatureAlgorithm signatureAlgorithm;
68
  // 'signature' field.
69
  Buffer signatureData;
70
};
71
72
// SignedCertificateTimestamp struct in RFC 6962, Section 3.2.
73
struct SignedCertificateTimestamp
74
{
75
  // Version enum in RFC 6962, Section 3.2.
76
  enum class Version {
77
    V1 = 0,
78
  };
79
80
  Version version;
81
  Buffer logId;
82
  // "timestamp" is the current time in milliseconds, measured since the epoch,
83
  // ignoring leap seconds. See RFC 6962, Section 3.2.
84
  uint64_t timestamp;
85
  Buffer extensions;
86
  DigitallySigned signature;
87
};
88
89
inline pkix::Result BufferToInput(const Buffer& buffer, pkix::Input& input)
90
0
{
91
0
  if (buffer.length() == 0) {
92
0
    return pkix::Result::FATAL_ERROR_LIBRARY_FAILURE;
93
0
  }
94
0
  return input.Init(buffer.begin(), buffer.length());
95
0
}
96
97
inline pkix::Result InputToBuffer(pkix::Input input, Buffer& buffer)
98
0
{
99
0
  buffer.clear();
100
0
  if (!buffer.append(input.UnsafeGetData(), input.GetLength())) {
101
0
    return pkix::Result::FATAL_ERROR_NO_MEMORY;
102
0
  }
103
0
  return pkix::Success;
104
0
}
105
106
} } // namespace mozilla::ct
107
108
#endif // SignedCertificateTimestamp_h