xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/core/crypto/certificate_util.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2021 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef QUICHE_QUIC_CORE_CRYPTO_CERTIFICATE_UTIL_H_
6 #define QUICHE_QUIC_CORE_CRYPTO_CERTIFICATE_UTIL_H_
7 
8 #include <string>
9 
10 #include "absl/strings/string_view.h"
11 #include "openssl/evp.h"
12 #include "quiche/quic/core/quic_time.h"
13 #include "quiche/quic/platform/api/quic_export.h"
14 
15 namespace quic {
16 
17 struct QUICHE_EXPORT CertificateTimestamp {
18   uint16_t year;
19   uint8_t month;
20   uint8_t day;
21   uint8_t hour;
22   uint8_t minute;
23   uint8_t second;
24 };
25 
26 struct QUICHE_EXPORT CertificateOptions {
27   absl::string_view subject;
28   uint64_t serial_number;
29   CertificateTimestamp validity_start;  // a.k.a not_valid_before
30   CertificateTimestamp validity_end;    // a.k.a not_valid_after
31 };
32 
33 // Creates a ECDSA P-256 key pair.
34 QUICHE_EXPORT bssl::UniquePtr<EVP_PKEY> MakeKeyPairForSelfSignedCertificate();
35 
36 // Creates a self-signed, DER-encoded X.509 certificate.
37 // |key| must be a ECDSA P-256 key.
38 // This is mostly stolen from Chromium's net/cert/x509_util.h, with
39 // modifications to make it work in QUICHE.
40 QUICHE_EXPORT std::string CreateSelfSignedCertificate(
41     EVP_PKEY& key, const CertificateOptions& options);
42 
43 }  // namespace quic
44 
45 #endif  // QUICHE_QUIC_CORE_CRYPTO_CERTIFICATE_UTIL_H_
46