3a2169405a9b449bc80979915a057fd919c7cb75
[platform/upstream/connectedhomeip.git] / src / credentials / tests / CHIPCert_test_vectors.h
1 /*
2  *
3  *    Copyright (c) 2020-2021 Project CHIP Authors
4  *    Copyright (c) 2019 Google LLC.
5  *    Copyright (c) 2016-2017 Nest Labs, Inc.
6  *    All rights reserved.
7  *
8  *    Licensed under the Apache License, Version 2.0 (the "License");
9  *    you may not use this file except in compliance with the License.
10  *    You may obtain a copy of the License at
11  *
12  *        http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *    Unless required by applicable law or agreed to in writing, software
15  *    distributed under the License is distributed on an "AS IS" BASIS,
16  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *    See the License for the specific language governing permissions and
18  *    limitations under the License.
19  */
20
21 /**
22  *    @file
23  *      This file contains definitions of test certificates used by various unit tests.
24  *
25  */
26
27 #pragma once
28
29 #include <asn1/ASN1OID.h>
30 #include <core/CHIPConfig.h>
31 #include <support/CodeUtils.h>
32
33 namespace chip {
34 namespace TestCerts {
35
36 using namespace chip::Credentials;
37 using namespace chip::ASN1;
38
39 enum TestCertTypes
40 {
41     kNone              = 0x00,
42     kRoot              = 0x01,
43     kRootKey           = 0x02,
44     kNodeCA            = 0x03,
45     kNode01            = 0x04,
46     kFirmwareSigningCA = 0x05,
47     kFirmwareSigning   = 0x06,
48 };
49
50 // Special flags to alter how certificates are fetched/loaded.
51 enum class TestCertLoadFlags : uint8_t
52 {
53     kDERForm               = 0x01,
54     kSuppressIsCA          = 0x02,
55     kSuppressKeyUsage      = 0x04,
56     kSuppressKeyCertSign   = 0x08,
57     kSetPathLenConstZero   = 0x10,
58     kSetAppDefinedCertType = 0x20,
59 };
60
61 extern CHIP_ERROR GetTestCert(uint8_t certType, BitFlags<uint8_t, TestCertLoadFlags> certLoadFlags, const uint8_t *& certData,
62                               uint32_t & certDataLen);
63 extern const char * GetTestCertName(uint8_t certType);
64 extern CHIP_ERROR LoadTestCert(ChipCertificateSet & certSet, uint8_t certType, BitFlags<uint8_t, TestCertLoadFlags> certLoadFlags,
65                                BitFlags<uint8_t, CertDecodeFlags> decodeFlags);
66
67 extern const uint8_t gTestCerts[];
68 extern const size_t gNumTestCerts;
69
70 extern const uint8_t sTestCert_Root_Chip[];
71 extern const uint32_t sTestCert_Root_Chip_Len;
72 extern const uint8_t sTestCert_Root_DER[];
73 extern const uint32_t sTestCert_Root_DER_Len;
74 extern const uint8_t sTestCert_Root_PublicKey[];
75 extern const uint8_t sTestCert_Root_PublicKey_Len;
76 extern const uint8_t sTestCert_Root_PrivateKey[];
77 extern const uint8_t sTestCert_Root_PrivateKey_Len;
78 extern const uint8_t sTestCert_Root_SubjectKeyId[];
79 extern const uint8_t sTestCert_Root_SubjectKeyId_Len;
80 extern const uint64_t sTestCert_Root_Id;
81
82 extern const uint8_t sTestCert_NodeCA_Chip[];
83 extern const uint32_t sTestCert_NodeCA_Chip_Len;
84 extern const uint8_t sTestCert_NodeCA_DER[];
85 extern const uint32_t sTestCert_NodeCA_DER_Len;
86 extern const uint8_t sTestCert_NodeCA_PublicKey[];
87 extern const uint8_t sTestCert_NodeCA_PublicKey_Len;
88 extern const uint8_t sTestCert_NodeCA_PrivateKey[];
89 extern const uint8_t sTestCert_NodeCA_PrivateKey_Len;
90 extern const uint8_t sTestCert_NodeCA_SubjectKeyId[];
91 extern const uint8_t sTestCert_NodeCA_SubjectKeyId_Len;
92 extern const uint64_t sTestCert_NodeCA_Id;
93
94 extern const uint8_t sTestCert_Node01_Chip[];
95 extern const uint32_t sTestCert_Node01_Chip_Len;
96 extern const uint8_t sTestCert_Node01_DER[];
97 extern const uint32_t sTestCert_Node01_DER_Len;
98 extern const uint8_t sTestCert_Node01_PublicKey[];
99 extern const uint8_t sTestCert_Node01_PublicKey_Len;
100 extern const uint8_t sTestCert_Node01_PrivateKey[];
101 extern const uint8_t sTestCert_Node01_PrivateKey_Len;
102 extern const uint8_t sTestCert_Node01_SubjectKeyId[];
103 extern const uint8_t sTestCert_Node01_SubjectKeyId_Len;
104 extern const uint64_t sTestCert_Node01_Id;
105
106 extern const uint8_t sTestCert_FirmwareSigningCA_Chip[];
107 extern const uint32_t sTestCert_FirmwareSigningCA_Chip_Len;
108 extern const uint8_t sTestCert_FirmwareSigningCA_DER[];
109 extern const uint32_t sTestCert_FirmwareSigningCA_DER_Len;
110 extern const uint8_t sTestCert_FirmwareSigningCA_PublicKey[];
111 extern const uint8_t sTestCert_FirmwareSigningCA_PublicKey_Len;
112 extern const uint8_t sTestCert_FirmwareSigningCA_PrivateKey[];
113 extern const uint8_t sTestCert_FirmwareSigningCA_PrivateKey_Len;
114 extern const uint8_t sTestCert_FirmwareSigningCA_SubjectKeyId[];
115 extern const uint8_t sTestCert_FirmwareSigningCA_SubjectKeyId_Len;
116 extern const uint64_t sTestCert_FirmwareSigningCA_Id;
117
118 extern const uint8_t sTestCert_FirmwareSigning_Chip[];
119 extern const uint32_t sTestCert_FirmwareSigning_Chip_Len;
120 extern const uint8_t sTestCert_FirmwareSigning_DER[];
121 extern const uint32_t sTestCert_FirmwareSigning_DER_Len;
122 extern const uint8_t sTestCert_FirmwareSigning_PublicKey[];
123 extern const uint8_t sTestCert_FirmwareSigning_PublicKey_Len;
124 extern const uint8_t sTestCert_FirmwareSigning_PrivateKey[];
125 extern const uint8_t sTestCert_FirmwareSigning_PrivateKey_Len;
126 extern const uint8_t sTestCert_FirmwareSigning_SubjectKeyId[];
127 extern const uint8_t sTestCert_FirmwareSigning_SubjectKeyId_Len;
128 extern const uint64_t sTestCert_FirmwareSigning_Id;
129
130 } // namespace TestCerts
131 } // namespace chip