ParseChain update
[platform/upstream/iotivity.git] / resource / csdk / connectivity / test / ssladapter_test.cpp
1 //******************************************************************
2 //
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #include "gtest/gtest.h"
22 #include "time.h"
23
24 // Test function hooks
25 #define CAcloseSslConnection CAcloseSslConnectionTest
26 #define CAdecryptSsl CAdecryptSslTest
27 #define CAdeinitSslAdapter CAdeinitSslAdapterTest
28 #define CAencryptSsl CAencryptSslTest
29 #define CAinitSslAdapter CAinitSslAdapterTest
30 #define CAinitiateSslHandshake CAinitiateSslHandshakeTest
31 #define CAsetCredentialTypesCallback CAsetCredentialTypesCallbackTest
32 #define CAsetSslAdapterCallbacks CAsetSslAdapterCallbacksTest
33 #define CAsetSslHandshakeCallback CAsetSslHandshakeCallbackTest
34 #define CAsetTlsCipherSuite CAsetTlsCipherSuiteTest
35 #define CAsslGenerateOwnerPsk CAsslGenerateOwnerPskTest
36 #define CAcloseSslConnectionAll CAcloseSslConnectionAllTest
37 #ifdef MULTIPLE_OWNER
38 #define GetCASecureEndpointData GetCASecureEndpointDataTest
39 #endif
40
41 #include "../src/adapter_util/ca_adapter_net_ssl.c"
42
43 #ifdef HAVE_UNISTD_H
44 #include <unistd.h>
45 #endif
46 #ifdef HAVE_PTHREAD_H
47 #include <pthread.h>
48 #endif
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <string.h>
52 #ifdef HAVE_SYS_TYPES_H
53 #include <sys/types.h>
54 #endif
55 #ifdef HAVE_SYS_SOCKET_H
56 #include <sys/socket.h>
57 #endif
58 #ifdef HAVE_NETINET_IN_H
59 #include <netinet/in.h>
60 #endif
61 #ifdef HAVE_NETDB_H
62 #include <netdb.h>
63 #endif
64
65 #if defined(_WIN32)
66 #include "../../../../c_common/windows/include/pthread_create.h"
67 #endif
68 #ifdef HAVE_WINDOWS_H
69 #include <windows.h>
70 /** @todo stop-gap for naming issue. Windows.h does not like us to use ERROR */
71 #ifdef ERROR
72 #undef ERROR
73 #endif //ERROR
74 #endif //HAVE_WINDOWS_H
75 #include "platform_features.h"
76 #include "logger.h"
77
78 #define MBED_TLS_DEBUG_LEVEL (4) // Verbose
79
80 #define SEED "PREDICTED_SEED"
81 #define dummyHandler 0xF123
82
83 #define SERVER_PORT 4433
84 #define SERVER_NAME "localhost"
85 #define GET_REQUEST "GET / HTTP/1.0\r\n\r\n"
86
87 /* **************************
88  *
89  *
90  * Common routines
91  *
92  *
93  * *************************/
94
95 // Data blob contains 10 certificates in PEM and DER encoding
96 unsigned char certChain[] = {
97     // PEM encoded certificate
98     0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49,
99     0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x43,
100     0x6e, 0x44, 0x43, 0x43, 0x41, 0x6a, 0x2b, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49, 0x55,
101     0x44, 0x67, 0x45, 0x38, 0x4e, 0x50, 0x54, 0x4c, 0x46, 0x64, 0x6d, 0x68, 0x75, 0x72, 0x53, 0x69,
102     0x36, 0x33, 0x49, 0x31, 0x41, 0x77, 0x76, 0x37, 0x39, 0x49, 0x6b, 0x77, 0x44, 0x41, 0x59, 0x49,
103     0x4b, 0x6f, 0x5a, 0x49, 0x7a, 0x6a, 0x30, 0x45, 0x41, 0x77, 0x49, 0x46, 0x0a, 0x41, 0x44, 0x43,
104     0x42, 0x67, 0x7a, 0x45, 0x34, 0x4d, 0x44, 0x59, 0x47, 0x41, 0x31, 0x55, 0x45, 0x41, 0x78, 0x4d,
105     0x76, 0x55, 0x32, 0x46, 0x74, 0x63, 0x33, 0x56, 0x75, 0x5a, 0x79, 0x42, 0x46, 0x62, 0x47, 0x56,
106     0x6a, 0x64, 0x48, 0x4a, 0x76, 0x62, 0x6d, 0x6c, 0x6a, 0x63, 0x79, 0x42, 0x50, 0x51, 0x30, 0x59,
107     0x67, 0x54, 0x55, 0x4d, 0x67, 0x52, 0x47, 0x56, 0x32, 0x61, 0x57, 0x4e, 0x6c, 0x0a, 0x49, 0x46,
108     0x4e, 0x31, 0x59, 0x6b, 0x4e, 0x42, 0x49, 0x48, 0x59, 0x78, 0x49, 0x46, 0x52, 0x46, 0x55, 0x31,
109     0x51, 0x78, 0x48, 0x44, 0x41, 0x61, 0x42, 0x67, 0x4e, 0x56, 0x42, 0x41, 0x73, 0x54, 0x45, 0x30,
110     0x39, 0x44, 0x52, 0x69, 0x42, 0x4e, 0x51, 0x79, 0x42, 0x45, 0x5a, 0x58, 0x5a, 0x70, 0x59, 0x32,
111     0x55, 0x67, 0x55, 0x33, 0x56, 0x69, 0x51, 0x30, 0x45, 0x78, 0x48, 0x44, 0x41, 0x61, 0x0a, 0x42,
112     0x67, 0x4e, 0x56, 0x42, 0x41, 0x6f, 0x54, 0x45, 0x31, 0x4e, 0x68, 0x62, 0x58, 0x4e, 0x31, 0x62,
113     0x6d, 0x63, 0x67, 0x52, 0x57, 0x78, 0x6c, 0x59, 0x33, 0x52, 0x79, 0x62, 0x32, 0x35, 0x70, 0x59,
114     0x33, 0x4d, 0x78, 0x43, 0x7a, 0x41, 0x4a, 0x42, 0x67, 0x4e, 0x56, 0x42, 0x41, 0x59, 0x54, 0x41,
115     0x6b, 0x74, 0x53, 0x4d, 0x43, 0x41, 0x58, 0x44, 0x54, 0x45, 0x32, 0x4d, 0x54, 0x45, 0x79, 0x0a,
116     0x4e, 0x44, 0x41, 0x79, 0x4e, 0x44, 0x67, 0x78, 0x4d, 0x6c, 0x6f, 0x59, 0x44, 0x7a, 0x49, 0x77,
117     0x4e, 0x6a, 0x6b, 0x78, 0x4d, 0x6a, 0x4d, 0x78, 0x4d, 0x54, 0x51, 0x31, 0x4f, 0x54, 0x55, 0x35,
118     0x57, 0x6a, 0x43, 0x42, 0x6a, 0x54, 0x46, 0x49, 0x4d, 0x45, 0x59, 0x47, 0x41, 0x31, 0x55, 0x45,
119     0x41, 0x78, 0x4d, 0x2f, 0x54, 0x30, 0x4e, 0x47, 0x49, 0x45, 0x52, 0x6c, 0x64, 0x6d, 0x6c, 0x6a,
120     0x0a, 0x5a, 0x53, 0x42, 0x55, 0x52, 0x56, 0x4e, 0x55, 0x4f, 0x69, 0x42, 0x4f, 0x5a, 0x58, 0x52,
121     0x33, 0x62, 0x33, 0x4a, 0x72, 0x49, 0x43, 0x67, 0x77, 0x4e, 0x6a, 0x51, 0x79, 0x4e, 0x32, 0x45,
122     0x32, 0x4e, 0x53, 0x31, 0x69, 0x5a, 0x6a, 0x63, 0x30, 0x4c, 0x54, 0x51, 0x33, 0x4d, 0x7a, 0x63,
123     0x74, 0x4f, 0x54, 0x5a, 0x6d, 0x4d, 0x53, 0x30, 0x78, 0x59, 0x6d, 0x49, 0x78, 0x4f, 0x44, 0x5a,
124     0x6b, 0x0a, 0x4f, 0x47, 0x59, 0x33, 0x59, 0x6a, 0x4d, 0x70, 0x4d, 0x52, 0x59, 0x77, 0x46, 0x41,
125     0x59, 0x44, 0x56, 0x51, 0x51, 0x4c, 0x45, 0x77, 0x31, 0x50, 0x51, 0x30, 0x59, 0x67, 0x54, 0x55,
126     0x4d, 0x67, 0x52, 0x47, 0x56, 0x32, 0x61, 0x57, 0x4e, 0x6c, 0x4d, 0x52, 0x77, 0x77, 0x47, 0x67,
127     0x59, 0x44, 0x56, 0x51, 0x51, 0x4b, 0x45, 0x78, 0x4e, 0x54, 0x59, 0x57, 0x31, 0x7a, 0x64, 0x57,
128     0x35, 0x6e, 0x0a, 0x49, 0x45, 0x56, 0x73, 0x5a, 0x57, 0x4e, 0x30, 0x63, 0x6d, 0x39, 0x75, 0x61,
129     0x57, 0x4e, 0x7a, 0x4d, 0x51, 0x73, 0x77, 0x43, 0x51, 0x59, 0x44, 0x56, 0x51, 0x51, 0x47, 0x45,
130     0x77, 0x4a, 0x4c, 0x55, 0x6a, 0x42, 0x5a, 0x4d, 0x42, 0x4d, 0x47, 0x42, 0x79, 0x71, 0x47, 0x53,
131     0x4d, 0x34, 0x39, 0x41, 0x67, 0x45, 0x47, 0x43, 0x43, 0x71, 0x47, 0x53, 0x4d, 0x34, 0x39, 0x41,
132     0x77, 0x45, 0x48, 0x0a, 0x41, 0x30, 0x49, 0x41, 0x42, 0x45, 0x45, 0x77, 0x51, 0x41, 0x52, 0x73,
133     0x62, 0x67, 0x43, 0x59, 0x2b, 0x43, 0x59, 0x6b, 0x49, 0x6a, 0x6b, 0x59, 0x6f, 0x47, 0x78, 0x6f,
134     0x52, 0x33, 0x75, 0x70, 0x33, 0x38, 0x59, 0x47, 0x54, 0x32, 0x63, 0x4b, 0x30, 0x31, 0x74, 0x6d,
135     0x32, 0x70, 0x38, 0x79, 0x4c, 0x4b, 0x4e, 0x73, 0x6d, 0x69, 0x53, 0x6f, 0x76, 0x46, 0x70, 0x4a,
136     0x32, 0x35, 0x63, 0x52, 0x0a, 0x74, 0x72, 0x57, 0x34, 0x41, 0x56, 0x7a, 0x76, 0x73, 0x64, 0x67,
137     0x62, 0x74, 0x72, 0x45, 0x62, 0x6b, 0x2b, 0x37, 0x73, 0x56, 0x61, 0x58, 0x50, 0x74, 0x78, 0x43,
138     0x6a, 0x67, 0x59, 0x41, 0x77, 0x66, 0x6a, 0x41, 0x4f, 0x42, 0x67, 0x4e, 0x56, 0x48, 0x51, 0x38,
139     0x42, 0x41, 0x66, 0x38, 0x45, 0x42, 0x41, 0x4d, 0x43, 0x41, 0x38, 0x67, 0x77, 0x4c, 0x67, 0x59,
140     0x44, 0x56, 0x52, 0x30, 0x66, 0x0a, 0x42, 0x43, 0x63, 0x77, 0x4a, 0x54, 0x41, 0x6a, 0x6f, 0x43,
141     0x47, 0x67, 0x48, 0x34, 0x59, 0x64, 0x61, 0x48, 0x52, 0x30, 0x63, 0x44, 0x6f, 0x76, 0x4c, 0x32,
142     0x4e, 0x68, 0x4c, 0x6e, 0x4e, 0x68, 0x62, 0x58, 0x4e, 0x31, 0x62, 0x6d, 0x64, 0x70, 0x62, 0x33,
143     0x52, 0x7a, 0x4c, 0x6d, 0x4e, 0x76, 0x62, 0x53, 0x39, 0x6a, 0x63, 0x6d, 0x77, 0x77, 0x50, 0x41,
144     0x59, 0x49, 0x4b, 0x77, 0x59, 0x42, 0x0a, 0x42, 0x51, 0x55, 0x48, 0x41, 0x51, 0x45, 0x45, 0x4d,
145     0x44, 0x41, 0x75, 0x4d, 0x43, 0x77, 0x47, 0x43, 0x43, 0x73, 0x47, 0x41, 0x51, 0x55, 0x46, 0x42,
146     0x7a, 0x41, 0x42, 0x68, 0x69, 0x42, 0x6f, 0x64, 0x48, 0x52, 0x77, 0x4f, 0x69, 0x38, 0x76, 0x62,
147     0x32, 0x4e, 0x7a, 0x63, 0x43, 0x31, 0x30, 0x5a, 0x58, 0x4e, 0x30, 0x4c, 0x6e, 0x4e, 0x68, 0x62,
148     0x58, 0x4e, 0x31, 0x62, 0x6d, 0x64, 0x70, 0x0a, 0x62, 0x33, 0x52, 0x7a, 0x4c, 0x6d, 0x4e, 0x76,
149     0x62, 0x54, 0x41, 0x4d, 0x42, 0x67, 0x67, 0x71, 0x68, 0x6b, 0x6a, 0x4f, 0x50, 0x51, 0x51, 0x44,
150     0x41, 0x67, 0x55, 0x41, 0x41, 0x30, 0x6b, 0x41, 0x4d, 0x45, 0x59, 0x43, 0x49, 0x51, 0x43, 0x33,
151     0x58, 0x30, 0x42, 0x61, 0x4f, 0x49, 0x6f, 0x63, 0x4b, 0x4f, 0x45, 0x65, 0x44, 0x46, 0x52, 0x6b,
152     0x63, 0x66, 0x30, 0x48, 0x76, 0x68, 0x68, 0x67, 0x0a, 0x73, 0x6c, 0x65, 0x49, 0x52, 0x32, 0x49,
153     0x62, 0x6d, 0x66, 0x34, 0x6e, 0x69, 0x52, 0x52, 0x55, 0x38, 0x41, 0x49, 0x68, 0x41, 0x4f, 0x4d,
154     0x44, 0x31, 0x77, 0x45, 0x62, 0x50, 0x67, 0x34, 0x70, 0x47, 0x77, 0x49, 0x79, 0x65, 0x77, 0x63,
155     0x61, 0x6b, 0x76, 0x72, 0x4e, 0x4b, 0x66, 0x44, 0x79, 0x2b, 0x4f, 0x4e, 0x43, 0x6e, 0x4e, 0x6e,
156     0x43, 0x59, 0x57, 0x4a, 0x37, 0x39, 0x35, 0x4b, 0x49, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45,
157     0x4e, 0x44, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d,
158     0x2d, 0x2d, 0x2d,
159     // NULL terminator
160     0x00,
161     // PEM encoded certificate
162     0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49,
163     0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x43,
164     0x6e, 0x44, 0x43, 0x43, 0x41, 0x6a, 0x2b, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49, 0x55,
165     0x44, 0x67, 0x45, 0x38, 0x4e, 0x50, 0x54, 0x4c, 0x46, 0x64, 0x6d, 0x68, 0x75, 0x72, 0x53, 0x69,
166     0x36, 0x33, 0x49, 0x31, 0x41, 0x77, 0x76, 0x37, 0x39, 0x49, 0x6b, 0x77, 0x44, 0x41, 0x59, 0x49,
167     0x4b, 0x6f, 0x5a, 0x49, 0x7a, 0x6a, 0x30, 0x45, 0x41, 0x77, 0x49, 0x46, 0x0a, 0x41, 0x44, 0x43,
168     0x42, 0x67, 0x7a, 0x45, 0x34, 0x4d, 0x44, 0x59, 0x47, 0x41, 0x31, 0x55, 0x45, 0x41, 0x78, 0x4d,
169     0x76, 0x55, 0x32, 0x46, 0x74, 0x63, 0x33, 0x56, 0x75, 0x5a, 0x79, 0x42, 0x46, 0x62, 0x47, 0x56,
170     0x6a, 0x64, 0x48, 0x4a, 0x76, 0x62, 0x6d, 0x6c, 0x6a, 0x63, 0x79, 0x42, 0x50, 0x51, 0x30, 0x59,
171     0x67, 0x54, 0x55, 0x4d, 0x67, 0x52, 0x47, 0x56, 0x32, 0x61, 0x57, 0x4e, 0x6c, 0x0a, 0x49, 0x46,
172     0x4e, 0x31, 0x59, 0x6b, 0x4e, 0x42, 0x49, 0x48, 0x59, 0x78, 0x49, 0x46, 0x52, 0x46, 0x55, 0x31,
173     0x51, 0x78, 0x48, 0x44, 0x41, 0x61, 0x42, 0x67, 0x4e, 0x56, 0x42, 0x41, 0x73, 0x54, 0x45, 0x30,
174     0x39, 0x44, 0x52, 0x69, 0x42, 0x4e, 0x51, 0x79, 0x42, 0x45, 0x5a, 0x58, 0x5a, 0x70, 0x59, 0x32,
175     0x55, 0x67, 0x55, 0x33, 0x56, 0x69, 0x51, 0x30, 0x45, 0x78, 0x48, 0x44, 0x41, 0x61, 0x0a, 0x42,
176     0x67, 0x4e, 0x56, 0x42, 0x41, 0x6f, 0x54, 0x45, 0x31, 0x4e, 0x68, 0x62, 0x58, 0x4e, 0x31, 0x62,
177     0x6d, 0x63, 0x67, 0x52, 0x57, 0x78, 0x6c, 0x59, 0x33, 0x52, 0x79, 0x62, 0x32, 0x35, 0x70, 0x59,
178     0x33, 0x4d, 0x78, 0x43, 0x7a, 0x41, 0x4a, 0x42, 0x67, 0x4e, 0x56, 0x42, 0x41, 0x59, 0x54, 0x41,
179     0x6b, 0x74, 0x53, 0x4d, 0x43, 0x41, 0x58, 0x44, 0x54, 0x45, 0x32, 0x4d, 0x54, 0x45, 0x79, 0x0a,
180     0x4e, 0x44, 0x41, 0x79, 0x4e, 0x44, 0x67, 0x78, 0x4d, 0x6c, 0x6f, 0x59, 0x44, 0x7a, 0x49, 0x77,
181     0x4e, 0x6a, 0x6b, 0x78, 0x4d, 0x6a, 0x4d, 0x78, 0x4d, 0x54, 0x51, 0x31, 0x4f, 0x54, 0x55, 0x35,
182     0x57, 0x6a, 0x43, 0x42, 0x6a, 0x54, 0x46, 0x49, 0x4d, 0x45, 0x59, 0x47, 0x41, 0x31, 0x55, 0x45,
183     0x41, 0x78, 0x4d, 0x2f, 0x54, 0x30, 0x4e, 0x47, 0x49, 0x45, 0x52, 0x6c, 0x64, 0x6d, 0x6c, 0x6a,
184     0x0a, 0x5a, 0x53, 0x42, 0x55, 0x52, 0x56, 0x4e, 0x55, 0x4f, 0x69, 0x42, 0x4f, 0x5a, 0x58, 0x52,
185     0x33, 0x62, 0x33, 0x4a, 0x72, 0x49, 0x43, 0x67, 0x77, 0x4e, 0x6a, 0x51, 0x79, 0x4e, 0x32, 0x45,
186     0x32, 0x4e, 0x53, 0x31, 0x69, 0x5a, 0x6a, 0x63, 0x30, 0x4c, 0x54, 0x51, 0x33, 0x4d, 0x7a, 0x63,
187     0x74, 0x4f, 0x54, 0x5a, 0x6d, 0x4d, 0x53, 0x30, 0x78, 0x59, 0x6d, 0x49, 0x78, 0x4f, 0x44, 0x5a,
188     0x6b, 0x0a, 0x4f, 0x47, 0x59, 0x33, 0x59, 0x6a, 0x4d, 0x70, 0x4d, 0x52, 0x59, 0x77, 0x46, 0x41,
189     0x59, 0x44, 0x56, 0x51, 0x51, 0x4c, 0x45, 0x77, 0x31, 0x50, 0x51, 0x30, 0x59, 0x67, 0x54, 0x55,
190     0x4d, 0x67, 0x52, 0x47, 0x56, 0x32, 0x61, 0x57, 0x4e, 0x6c, 0x4d, 0x52, 0x77, 0x77, 0x47, 0x67,
191     0x59, 0x44, 0x56, 0x51, 0x51, 0x4b, 0x45, 0x78, 0x4e, 0x54, 0x59, 0x57, 0x31, 0x7a, 0x64, 0x57,
192     0x35, 0x6e, 0x0a, 0x49, 0x45, 0x56, 0x73, 0x5a, 0x57, 0x4e, 0x30, 0x63, 0x6d, 0x39, 0x75, 0x61,
193     0x57, 0x4e, 0x7a, 0x4d, 0x51, 0x73, 0x77, 0x43, 0x51, 0x59, 0x44, 0x56, 0x51, 0x51, 0x47, 0x45,
194     0x77, 0x4a, 0x4c, 0x55, 0x6a, 0x42, 0x5a, 0x4d, 0x42, 0x4d, 0x47, 0x42, 0x79, 0x71, 0x47, 0x53,
195     0x4d, 0x34, 0x39, 0x41, 0x67, 0x45, 0x47, 0x43, 0x43, 0x71, 0x47, 0x53, 0x4d, 0x34, 0x39, 0x41,
196     0x77, 0x45, 0x48, 0x0a, 0x41, 0x30, 0x49, 0x41, 0x42, 0x45, 0x45, 0x77, 0x51, 0x41, 0x52, 0x73,
197     0x62, 0x67, 0x43, 0x59, 0x2b, 0x43, 0x59, 0x6b, 0x49, 0x6a, 0x6b, 0x59, 0x6f, 0x47, 0x78, 0x6f,
198     0x52, 0x33, 0x75, 0x70, 0x33, 0x38, 0x59, 0x47, 0x54, 0x32, 0x63, 0x4b, 0x30, 0x31, 0x74, 0x6d,
199     0x32, 0x70, 0x38, 0x79, 0x4c, 0x4b, 0x4e, 0x73, 0x6d, 0x69, 0x53, 0x6f, 0x76, 0x46, 0x70, 0x4a,
200     0x32, 0x35, 0x63, 0x52, 0x0a, 0x74, 0x72, 0x57, 0x34, 0x41, 0x56, 0x7a, 0x76, 0x73, 0x64, 0x67,
201     0x62, 0x74, 0x72, 0x45, 0x62, 0x6b, 0x2b, 0x37, 0x73, 0x56, 0x61, 0x58, 0x50, 0x74, 0x78, 0x43,
202     0x6a, 0x67, 0x59, 0x41, 0x77, 0x66, 0x6a, 0x41, 0x4f, 0x42, 0x67, 0x4e, 0x56, 0x48, 0x51, 0x38,
203     0x42, 0x41, 0x66, 0x38, 0x45, 0x42, 0x41, 0x4d, 0x43, 0x41, 0x38, 0x67, 0x77, 0x4c, 0x67, 0x59,
204     0x44, 0x56, 0x52, 0x30, 0x66, 0x0a, 0x42, 0x43, 0x63, 0x77, 0x4a, 0x54, 0x41, 0x6a, 0x6f, 0x43,
205     0x47, 0x67, 0x48, 0x34, 0x59, 0x64, 0x61, 0x48, 0x52, 0x30, 0x63, 0x44, 0x6f, 0x76, 0x4c, 0x32,
206     0x4e, 0x68, 0x4c, 0x6e, 0x4e, 0x68, 0x62, 0x58, 0x4e, 0x31, 0x62, 0x6d, 0x64, 0x70, 0x62, 0x33,
207     0x52, 0x7a, 0x4c, 0x6d, 0x4e, 0x76, 0x62, 0x53, 0x39, 0x6a, 0x63, 0x6d, 0x77, 0x77, 0x50, 0x41,
208     0x59, 0x49, 0x4b, 0x77, 0x59, 0x42, 0x0a, 0x42, 0x51, 0x55, 0x48, 0x41, 0x51, 0x45, 0x45, 0x4d,
209     0x44, 0x41, 0x75, 0x4d, 0x43, 0x77, 0x47, 0x43, 0x43, 0x73, 0x47, 0x41, 0x51, 0x55, 0x46, 0x42,
210     0x7a, 0x41, 0x42, 0x68, 0x69, 0x42, 0x6f, 0x64, 0x48, 0x52, 0x77, 0x4f, 0x69, 0x38, 0x76, 0x62,
211     0x32, 0x4e, 0x7a, 0x63, 0x43, 0x31, 0x30, 0x5a, 0x58, 0x4e, 0x30, 0x4c, 0x6e, 0x4e, 0x68, 0x62,
212     0x58, 0x4e, 0x31, 0x62, 0x6d, 0x64, 0x70, 0x0a, 0x62, 0x33, 0x52, 0x7a, 0x4c, 0x6d, 0x4e, 0x76,
213     0x62, 0x54, 0x41, 0x4d, 0x42, 0x67, 0x67, 0x71, 0x68, 0x6b, 0x6a, 0x4f, 0x50, 0x51, 0x51, 0x44,
214     0x41, 0x67, 0x55, 0x41, 0x41, 0x30, 0x6b, 0x41, 0x4d, 0x45, 0x59, 0x43, 0x49, 0x51, 0x43, 0x33,
215     0x58, 0x30, 0x42, 0x61, 0x4f, 0x49, 0x6f, 0x63, 0x4b, 0x4f, 0x45, 0x65, 0x44, 0x46, 0x52, 0x6b,
216     0x63, 0x66, 0x30, 0x48, 0x76, 0x68, 0x68, 0x67, 0x0a, 0x73, 0x6c, 0x65, 0x49, 0x52, 0x32, 0x49,
217     0x62, 0x6d, 0x66, 0x34, 0x6e, 0x69, 0x52, 0x52, 0x55, 0x38, 0x41, 0x49, 0x68, 0x41, 0x4f, 0x4d,
218     0x44, 0x31, 0x77, 0x45, 0x62, 0x50, 0x67, 0x34, 0x70, 0x47, 0x77, 0x49, 0x79, 0x65, 0x77, 0x63,
219     0x61, 0x6b, 0x76, 0x72, 0x4e, 0x4b, 0x66, 0x44, 0x79, 0x2b, 0x4f, 0x4e, 0x43, 0x6e, 0x4e, 0x6e,
220     0x43, 0x59, 0x57, 0x4a, 0x37, 0x39, 0x35, 0x4b, 0x49, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45,
221     0x4e, 0x44, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d,
222     0x2d, 0x2d, 0x2d,
223     // garbage data
224     0x01, 0x02, 0x03, 0x04, 0x05,
225     // DER encoded certificate
226     0x30, 0x82, 0x02, 0x39, 0x30, 0x82, 0x01, 0xdf, 0x02, 0x01, 0x01, 0x30, 0x0a, 0x06, 0x08, 0x2a,
227     0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, 0x7c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
228     0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
229     0x09, 0x53, 0x6f, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x74, 0x65, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03,
230     0x55, 0x04, 0x07, 0x0c, 0x08, 0x53, 0x6f, 0x6d, 0x65, 0x63, 0x69, 0x74, 0x79, 0x31, 0x0b, 0x30,
231     0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x42, 0x42, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03,
232     0x55, 0x04, 0x0b, 0x0c, 0x0d, 0x53, 0x65, 0x71, 0x75, 0x72, 0x69, 0x74, 0x79, 0x20, 0x50, 0x61,
233     0x72, 0x74, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x02, 0x6f, 0x62, 0x31,
234     0x14, 0x30, 0x12, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x05,
235     0x6f, 0x62, 0x40, 0x62, 0x62, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x38, 0x31, 0x35, 0x31,
236     0x33, 0x31, 0x31, 0x31, 0x37, 0x5a, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x35, 0x31, 0x32, 0x31, 0x33,
237     0x31, 0x31, 0x31, 0x37, 0x5a, 0x30, 0x81, 0xd4, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
238     0x06, 0x13, 0x02, 0x55, 0x41, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x03,
239     0x41, 0x73, 0x64, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x06, 0x47, 0x6f,
240     0x74, 0x68, 0x61, 0x6d, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x5a,
241     0x5a, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x08, 0x42, 0x65, 0x61, 0x6d,
242     0x54, 0x65, 0x61, 0x6d, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
243     0x01, 0x09, 0x01, 0x16, 0x0d, 0x72, 0x61, 0x69, 0x6c, 0x40, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
244     0x6f, 0x6d, 0x31, 0x32, 0x30, 0x30, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x29, 0x75, 0x75, 0x69,
245     0x64, 0x3a, 0x33, 0x32, 0x33, 0x32, 0x33, 0x32, 0x33, 0x32, 0x2d, 0x33, 0x32, 0x33, 0x32, 0x2d,
246     0x33, 0x32, 0x33, 0x32, 0x2d, 0x33, 0x32, 0x33, 0x32, 0x2d, 0x33, 0x32, 0x33, 0x32, 0x33, 0x32,
247     0x33, 0x32, 0x33, 0x32, 0x33, 0x32, 0x31, 0x34, 0x30, 0x32, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x0c,
248     0x2b, 0x75, 0x73, 0x65, 0x72, 0x69, 0x64, 0x3a, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37,
249     0x2d, 0x36, 0x37, 0x36, 0x37, 0x2d, 0x36, 0x37, 0x36, 0x37, 0x2d, 0x36, 0x37, 0x36, 0x37, 0x2d,
250     0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x30, 0x59, 0x30, 0x13,
251     0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
252     0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0xf7, 0x13, 0x5c, 0x73, 0x72, 0xce, 0x10, 0xe5, 0x09,
253     0x97, 0x9a, 0xf8, 0xf2, 0x70, 0xa6, 0x3d, 0x89, 0xf5, 0xc5, 0xe4, 0x44, 0xe2, 0x4a, 0xb6, 0x61,
254     0xa8, 0x12, 0x8d, 0xb4, 0xdc, 0x2b, 0x47, 0x84, 0x60, 0x0c, 0x25, 0x66, 0xe9, 0xe0, 0xe5, 0xac,
255     0x22, 0xbf, 0x15, 0xdc, 0x71, 0xb1, 0x88, 0x4f, 0x16, 0xbf, 0xc2, 0x77, 0x37, 0x76, 0x3f, 0xe0,
256     0x67, 0xc6, 0x1d, 0x23, 0xfe, 0x7c, 0x8b, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
257     0x04, 0x03, 0x02, 0x03, 0x48, 0x00, 0x30, 0x45, 0x02, 0x20, 0x47, 0xcc, 0x41, 0x8a, 0x27, 0xc7,
258     0xd0, 0xaa, 0xb4, 0xab, 0x85, 0xbf, 0x09, 0x4d, 0x06, 0xd7, 0x7e, 0x0d, 0x39, 0xf9, 0x36, 0xa1,
259     0x3d, 0x96, 0x23, 0xe2, 0x24, 0x64, 0x98, 0x63, 0x21, 0xba, 0x02, 0x21, 0x00, 0xe5, 0x8f, 0x7f,
260     0xf1, 0xa6, 0x82, 0x03, 0x6a, 0x18, 0x7a, 0x54, 0xe7, 0x0e, 0x25, 0x77, 0xd8, 0x46, 0xfa, 0x96,
261     0x8a, 0x7e, 0x14, 0xc4, 0xcb, 0x21, 0x32, 0x3e, 0x89, 0xd9, 0xba, 0x8c, 0x3f,
262     // PEM encoded certificate
263     0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49,
264     0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0d, 0x0a, 0x4d, 0x49, 0x49,
265     0x45, 0x67, 0x44, 0x43, 0x43, 0x41, 0x32, 0x69, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49,
266     0x49, 0x58, 0x32, 0x37, 0x50, 0x44, 0x4d, 0x55, 0x38, 0x2b, 0x66, 0x6f, 0x77, 0x44, 0x51, 0x59,
267     0x4a, 0x4b, 0x6f, 0x5a, 0x49, 0x68, 0x76, 0x63, 0x4e, 0x41, 0x51, 0x45, 0x4c, 0x42, 0x51, 0x41,
268     0x77, 0x53, 0x54, 0x45, 0x4c, 0x4d, 0x41, 0x6b, 0x47, 0x41, 0x31, 0x55, 0x45, 0x0d, 0x0a, 0x42,
269     0x68, 0x4d, 0x43, 0x56, 0x56, 0x4d, 0x78, 0x45, 0x7a, 0x41, 0x52, 0x42, 0x67, 0x4e, 0x56, 0x42,
270     0x41, 0x6f, 0x54, 0x43, 0x6b, 0x64, 0x76, 0x62, 0x32, 0x64, 0x73, 0x5a, 0x53, 0x42, 0x4a, 0x62,
271     0x6d, 0x4d, 0x78, 0x4a, 0x54, 0x41, 0x6a, 0x42, 0x67, 0x4e, 0x56, 0x42, 0x41, 0x4d, 0x54, 0x48,
272     0x45, 0x64, 0x76, 0x62, 0x32, 0x64, 0x73, 0x5a, 0x53, 0x42, 0x4a, 0x62, 0x6e, 0x52, 0x6c, 0x0d,
273     0x0a, 0x63, 0x6d, 0x35, 0x6c, 0x64, 0x43, 0x42, 0x42, 0x64, 0x58, 0x52, 0x6f, 0x62, 0x33, 0x4a,
274     0x70, 0x64, 0x48, 0x6b, 0x67, 0x52, 0x7a, 0x49, 0x77, 0x48, 0x68, 0x63, 0x4e, 0x4d, 0x54, 0x59,
275     0x78, 0x4d, 0x6a, 0x41, 0x78, 0x4d, 0x54, 0x51, 0x78, 0x4f, 0x44, 0x55, 0x32, 0x57, 0x68, 0x63,
276     0x4e, 0x4d, 0x54, 0x63, 0x77, 0x4d, 0x6a, 0x49, 0x7a, 0x4d, 0x54, 0x51, 0x78, 0x4e, 0x6a, 0x41,
277     0x77, 0x0d, 0x0a, 0x57, 0x6a, 0x42, 0x6f, 0x4d, 0x51, 0x73, 0x77, 0x43, 0x51, 0x59, 0x44, 0x56,
278     0x51, 0x51, 0x47, 0x45, 0x77, 0x4a, 0x56, 0x55, 0x7a, 0x45, 0x54, 0x4d, 0x42, 0x45, 0x47, 0x41,
279     0x31, 0x55, 0x45, 0x43, 0x41, 0x77, 0x4b, 0x51, 0x32, 0x46, 0x73, 0x61, 0x57, 0x5a, 0x76, 0x63,
280     0x6d, 0x35, 0x70, 0x59, 0x54, 0x45, 0x57, 0x4d, 0x42, 0x51, 0x47, 0x41, 0x31, 0x55, 0x45, 0x42,
281     0x77, 0x77, 0x4e, 0x0d, 0x0a, 0x54, 0x57, 0x39, 0x31, 0x62, 0x6e, 0x52, 0x68, 0x61, 0x57, 0x34,
282     0x67, 0x56, 0x6d, 0x6c, 0x6c, 0x64, 0x7a, 0x45, 0x54, 0x4d, 0x42, 0x45, 0x47, 0x41, 0x31, 0x55,
283     0x45, 0x43, 0x67, 0x77, 0x4b, 0x52, 0x32, 0x39, 0x76, 0x5a, 0x32, 0x78, 0x6c, 0x49, 0x45, 0x6c,
284     0x75, 0x59, 0x7a, 0x45, 0x58, 0x4d, 0x42, 0x55, 0x47, 0x41, 0x31, 0x55, 0x45, 0x41, 0x77, 0x77,
285     0x4f, 0x61, 0x57, 0x31, 0x68, 0x0d, 0x0a, 0x63, 0x43, 0x35, 0x6e, 0x62, 0x57, 0x46, 0x70, 0x62,
286     0x43, 0x35, 0x6a, 0x62, 0x32, 0x30, 0x77, 0x67, 0x67, 0x45, 0x69, 0x4d, 0x41, 0x30, 0x47, 0x43,
287     0x53, 0x71, 0x47, 0x53, 0x49, 0x62, 0x33, 0x44, 0x51, 0x45, 0x42, 0x41, 0x51, 0x55, 0x41, 0x41,
288     0x34, 0x49, 0x42, 0x44, 0x77, 0x41, 0x77, 0x67, 0x67, 0x45, 0x4b, 0x41, 0x6f, 0x49, 0x42, 0x41,
289     0x51, 0x43, 0x61, 0x57, 0x66, 0x7a, 0x79, 0x0d, 0x0a, 0x75, 0x59, 0x6e, 0x66, 0x4e, 0x69, 0x54,
290     0x54, 0x61, 0x50, 0x69, 0x33, 0x6b, 0x57, 0x63, 0x6b, 0x65, 0x44, 0x4e, 0x48, 0x78, 0x6f, 0x6f,
291     0x5a, 0x71, 0x4d, 0x31, 0x36, 0x5a, 0x37, 0x5a, 0x38, 0x38, 0x5a, 0x63, 0x48, 0x69, 0x78, 0x79,
292     0x74, 0x68, 0x63, 0x38, 0x4e, 0x6c, 0x31, 0x32, 0x59, 0x45, 0x66, 0x46, 0x78, 0x66, 0x51, 0x4e,
293     0x77, 0x73, 0x2f, 0x65, 0x41, 0x4b, 0x31, 0x66, 0x6a, 0x0d, 0x0a, 0x41, 0x43, 0x59, 0x54, 0x57,
294     0x39, 0x39, 0x63, 0x45, 0x36, 0x31, 0x4e, 0x51, 0x68, 0x59, 0x48, 0x6c, 0x51, 0x67, 0x78, 0x6f,
295     0x62, 0x49, 0x39, 0x50, 0x44, 0x66, 0x61, 0x4f, 0x7a, 0x36, 0x4e, 0x6b, 0x72, 0x66, 0x62, 0x61,
296     0x79, 0x61, 0x53, 0x7a, 0x77, 0x4a, 0x39, 0x44, 0x76, 0x4b, 0x64, 0x49, 0x52, 0x4f, 0x64, 0x58,
297     0x36, 0x6d, 0x70, 0x72, 0x53, 0x2b, 0x79, 0x4c, 0x56, 0x47, 0x32, 0x0d, 0x0a, 0x2f, 0x4f, 0x49,
298     0x51, 0x37, 0x72, 0x37, 0x48, 0x32, 0x65, 0x62, 0x77, 0x48, 0x6d, 0x69, 0x58, 0x6f, 0x33, 0x5a,
299     0x30, 0x50, 0x4b, 0x62, 0x6c, 0x66, 0x4b, 0x44, 0x4b, 0x6b, 0x63, 0x67, 0x4b, 0x4c, 0x31, 0x73,
300     0x6b, 0x33, 0x42, 0x51, 0x65, 0x78, 0x49, 0x78, 0x32, 0x4a, 0x31, 0x53, 0x51, 0x4a, 0x61, 0x32,
301     0x53, 0x66, 0x55, 0x6e, 0x46, 0x6e, 0x61, 0x70, 0x62, 0x4f, 0x6a, 0x4a, 0x2b, 0x0d, 0x0a, 0x4a,
302     0x42, 0x68, 0x77, 0x4f, 0x71, 0x68, 0x67, 0x36, 0x6b, 0x43, 0x4b, 0x70, 0x2b, 0x4a, 0x4e, 0x4e,
303     0x59, 0x44, 0x53, 0x44, 0x47, 0x4b, 0x57, 0x47, 0x76, 0x49, 0x45, 0x44, 0x7a, 0x6f, 0x55, 0x7a,
304     0x66, 0x37, 0x35, 0x36, 0x2f, 0x63, 0x58, 0x57, 0x34, 0x6d, 0x36, 0x34, 0x74, 0x44, 0x78, 0x39,
305     0x54, 0x33, 0x4d, 0x66, 0x4b, 0x65, 0x55, 0x6a, 0x77, 0x31, 0x30, 0x68, 0x41, 0x72, 0x6f, 0x0d,
306     0x0a, 0x63, 0x33, 0x37, 0x62, 0x4a, 0x64, 0x69, 0x2f, 0x46, 0x66, 0x6c, 0x34, 0x7a, 0x38, 0x2f,
307     0x43, 0x75, 0x56, 0x55, 0x4f, 0x4c, 0x36, 0x76, 0x55, 0x6e, 0x75, 0x55, 0x35, 0x75, 0x6e, 0x46,
308     0x6a, 0x67, 0x6d, 0x52, 0x6a, 0x36, 0x6e, 0x65, 0x47, 0x53, 0x63, 0x33, 0x57, 0x4a, 0x31, 0x79,
309     0x76, 0x76, 0x56, 0x32, 0x6e, 0x4f, 0x37, 0x41, 0x50, 0x4b, 0x6e, 0x43, 0x4f, 0x68, 0x6c, 0x4e,
310     0x7a, 0x0d, 0x0a, 0x6e, 0x7a, 0x45, 0x6f, 0x69, 0x73, 0x73, 0x68, 0x6d, 0x6c, 0x7a, 0x78, 0x43,
311     0x62, 0x4d, 0x76, 0x41, 0x67, 0x4d, 0x42, 0x41, 0x41, 0x47, 0x6a, 0x67, 0x67, 0x46, 0x4c, 0x4d,
312     0x49, 0x49, 0x42, 0x52, 0x7a, 0x41, 0x64, 0x42, 0x67, 0x4e, 0x56, 0x48, 0x53, 0x55, 0x45, 0x46,
313     0x6a, 0x41, 0x55, 0x42, 0x67, 0x67, 0x72, 0x42, 0x67, 0x45, 0x46, 0x42, 0x51, 0x63, 0x44, 0x41,
314     0x51, 0x59, 0x49, 0x0d, 0x0a, 0x4b, 0x77, 0x59, 0x42, 0x42, 0x51, 0x55, 0x48, 0x41, 0x77, 0x49,
315     0x77, 0x47, 0x51, 0x59, 0x44, 0x56, 0x52, 0x30, 0x52, 0x42, 0x42, 0x49, 0x77, 0x45, 0x49, 0x49,
316     0x4f, 0x61, 0x57, 0x31, 0x68, 0x63, 0x43, 0x35, 0x6e, 0x62, 0x57, 0x46, 0x70, 0x62, 0x43, 0x35,
317     0x6a, 0x62, 0x32, 0x30, 0x77, 0x61, 0x41, 0x59, 0x49, 0x4b, 0x77, 0x59, 0x42, 0x42, 0x51, 0x55,
318     0x48, 0x41, 0x51, 0x45, 0x45, 0x0d, 0x0a, 0x58, 0x44, 0x42, 0x61, 0x4d, 0x43, 0x73, 0x47, 0x43,
319     0x43, 0x73, 0x47, 0x41, 0x51, 0x55, 0x46, 0x42, 0x7a, 0x41, 0x43, 0x68, 0x68, 0x39, 0x6f, 0x64,
320     0x48, 0x52, 0x77, 0x4f, 0x69, 0x38, 0x76, 0x63, 0x47, 0x74, 0x70, 0x4c, 0x6d, 0x64, 0x76, 0x62,
321     0x32, 0x64, 0x73, 0x5a, 0x53, 0x35, 0x6a, 0x62, 0x32, 0x30, 0x76, 0x52, 0x30, 0x6c, 0x42, 0x52,
322     0x7a, 0x49, 0x75, 0x59, 0x33, 0x4a, 0x30, 0x0d, 0x0a, 0x4d, 0x43, 0x73, 0x47, 0x43, 0x43, 0x73,
323     0x47, 0x41, 0x51, 0x55, 0x46, 0x42, 0x7a, 0x41, 0x42, 0x68, 0x68, 0x39, 0x6f, 0x64, 0x48, 0x52,
324     0x77, 0x4f, 0x69, 0x38, 0x76, 0x59, 0x32, 0x78, 0x70, 0x5a, 0x57, 0x35, 0x30, 0x63, 0x7a, 0x45,
325     0x75, 0x5a, 0x32, 0x39, 0x76, 0x5a, 0x32, 0x78, 0x6c, 0x4c, 0x6d, 0x4e, 0x76, 0x62, 0x53, 0x39,
326     0x76, 0x59, 0x33, 0x4e, 0x77, 0x4d, 0x42, 0x30, 0x47, 0x0d, 0x0a, 0x41, 0x31, 0x55, 0x64, 0x44,
327     0x67, 0x51, 0x57, 0x42, 0x42, 0x52, 0x75, 0x74, 0x41, 0x41, 0x45, 0x4b, 0x70, 0x75, 0x65, 0x4c,
328     0x4f, 0x4c, 0x4b, 0x33, 0x64, 0x6e, 0x56, 0x2b, 0x75, 0x59, 0x47, 0x68, 0x77, 0x68, 0x58, 0x6d,
329     0x6a, 0x41, 0x4d, 0x42, 0x67, 0x4e, 0x56, 0x48, 0x52, 0x4d, 0x42, 0x41, 0x66, 0x38, 0x45, 0x41,
330     0x6a, 0x41, 0x41, 0x4d, 0x42, 0x38, 0x47, 0x41, 0x31, 0x55, 0x64, 0x0d, 0x0a, 0x49, 0x77, 0x51,
331     0x59, 0x4d, 0x42, 0x61, 0x41, 0x46, 0x45, 0x72, 0x64, 0x42, 0x68, 0x59, 0x62, 0x76, 0x50, 0x5a,
332     0x6f, 0x74, 0x58, 0x62, 0x31, 0x67, 0x62, 0x61, 0x37, 0x59, 0x68, 0x71, 0x36, 0x57, 0x6f, 0x45,
333     0x76, 0x4d, 0x43, 0x45, 0x47, 0x41, 0x31, 0x55, 0x64, 0x49, 0x41, 0x51, 0x61, 0x4d, 0x42, 0x67,
334     0x77, 0x44, 0x41, 0x59, 0x4b, 0x4b, 0x77, 0x59, 0x42, 0x42, 0x41, 0x48, 0x57, 0x0d, 0x0a, 0x65,
335     0x51, 0x49, 0x46, 0x41, 0x54, 0x41, 0x49, 0x42, 0x67, 0x5a, 0x6e, 0x67, 0x51, 0x77, 0x42, 0x41,
336     0x67, 0x49, 0x77, 0x4d, 0x41, 0x59, 0x44, 0x56, 0x52, 0x30, 0x66, 0x42, 0x43, 0x6b, 0x77, 0x4a,
337     0x7a, 0x41, 0x6c, 0x6f, 0x43, 0x4f, 0x67, 0x49, 0x59, 0x59, 0x66, 0x61, 0x48, 0x52, 0x30, 0x63,
338     0x44, 0x6f, 0x76, 0x4c, 0x33, 0x42, 0x72, 0x61, 0x53, 0x35, 0x6e, 0x62, 0x32, 0x39, 0x6e, 0x0d,
339     0x0a, 0x62, 0x47, 0x55, 0x75, 0x59, 0x32, 0x39, 0x74, 0x4c, 0x30, 0x64, 0x4a, 0x51, 0x55, 0x63,
340     0x79, 0x4c, 0x6d, 0x4e, 0x79, 0x62, 0x44, 0x41, 0x4e, 0x42, 0x67, 0x6b, 0x71, 0x68, 0x6b, 0x69,
341     0x47, 0x39, 0x77, 0x30, 0x42, 0x41, 0x51, 0x73, 0x46, 0x41, 0x41, 0x4f, 0x43, 0x41, 0x51, 0x45,
342     0x41, 0x58, 0x31, 0x7a, 0x42, 0x4a, 0x45, 0x2b, 0x6b, 0x4e, 0x2f, 0x39, 0x50, 0x42, 0x4a, 0x48,
343     0x59, 0x0d, 0x0a, 0x35, 0x74, 0x57, 0x62, 0x44, 0x57, 0x62, 0x75, 0x44, 0x63, 0x66, 0x32, 0x72,
344     0x31, 0x49, 0x35, 0x6f, 0x6e, 0x62, 0x38, 0x5a, 0x4e, 0x35, 0x44, 0x50, 0x61, 0x69, 0x32, 0x43,
345     0x75, 0x71, 0x43, 0x66, 0x49, 0x7a, 0x46, 0x50, 0x4c, 0x75, 0x37, 0x65, 0x6a, 0x61, 0x73, 0x31,
346     0x41, 0x74, 0x67, 0x33, 0x31, 0x6e, 0x38, 0x45, 0x35, 0x38, 0x55, 0x4d, 0x31, 0x51, 0x44, 0x45,
347     0x74, 0x71, 0x54, 0x0d, 0x0a, 0x58, 0x45, 0x47, 0x48, 0x61, 0x68, 0x6d, 0x74, 0x6e, 0x52, 0x30,
348     0x6e, 0x4f, 0x71, 0x61, 0x6e, 0x35, 0x63, 0x43, 0x6c, 0x54, 0x5a, 0x46, 0x6b, 0x61, 0x59, 0x46,
349     0x47, 0x79, 0x65, 0x54, 0x75, 0x76, 0x4f, 0x33, 0x69, 0x4e, 0x54, 0x47, 0x4d, 0x50, 0x69, 0x64,
350     0x4c, 0x48, 0x47, 0x51, 0x68, 0x55, 0x4b, 0x2f, 0x63, 0x4b, 0x6b, 0x67, 0x79, 0x52, 0x54, 0x68,
351     0x75, 0x38, 0x4f, 0x78, 0x6e, 0x0d, 0x0a, 0x2b, 0x67, 0x6d, 0x65, 0x33, 0x70, 0x66, 0x76, 0x49,
352     0x58, 0x74, 0x73, 0x61, 0x42, 0x4c, 0x71, 0x4e, 0x47, 0x69, 0x42, 0x38, 0x76, 0x69, 0x59, 0x2b,
353     0x6b, 0x48, 0x75, 0x72, 0x50, 0x64, 0x53, 0x4c, 0x36, 0x53, 0x72, 0x4a, 0x57, 0x65, 0x34, 0x76,
354     0x30, 0x39, 0x79, 0x62, 0x45, 0x6f, 0x74, 0x72, 0x30, 0x72, 0x34, 0x32, 0x30, 0x51, 0x74, 0x32,
355     0x33, 0x52, 0x69, 0x4a, 0x44, 0x69, 0x41, 0x0d, 0x0a, 0x54, 0x77, 0x48, 0x53, 0x78, 0x57, 0x6a,
356     0x64, 0x2f, 0x68, 0x64, 0x64, 0x43, 0x52, 0x75, 0x4b, 0x55, 0x4f, 0x6c, 0x36, 0x52, 0x56, 0x66,
357     0x4f, 0x4a, 0x56, 0x68, 0x4a, 0x75, 0x31, 0x4b, 0x65, 0x71, 0x6b, 0x70, 0x76, 0x78, 0x44, 0x37,
358     0x4d, 0x75, 0x6f, 0x39, 0x30, 0x6a, 0x41, 0x42, 0x4e, 0x44, 0x74, 0x4f, 0x4f, 0x43, 0x79, 0x5a,
359     0x61, 0x56, 0x6a, 0x7a, 0x36, 0x2f, 0x77, 0x75, 0x42, 0x0d, 0x0a, 0x53, 0x50, 0x64, 0x54, 0x34,
360     0x64, 0x2f, 0x4d, 0x49, 0x68, 0x51, 0x78, 0x49, 0x31, 0x76, 0x6a, 0x77, 0x48, 0x59, 0x51, 0x4d,
361     0x70, 0x54, 0x76, 0x4f, 0x38, 0x68, 0x34, 0x68, 0x46, 0x36, 0x45, 0x71, 0x73, 0x58, 0x31, 0x36,
362     0x70, 0x52, 0x41, 0x4a, 0x6b, 0x6e, 0x47, 0x6e, 0x63, 0x38, 0x4a, 0x59, 0x4d, 0x76, 0x62, 0x70,
363     0x56, 0x6e, 0x79, 0x63, 0x6e, 0x4a, 0x73, 0x43, 0x68, 0x65, 0x73, 0x0d, 0x0a, 0x46, 0x4c, 0x78,
364     0x6f, 0x6c, 0x77, 0x3d, 0x3d, 0x0d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20,
365     0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d,
366     // \n NULL terminator
367     0x0a, 0x00,
368     // PEM encoded certificate
369     0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49,
370     0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x44,
371     0x38, 0x44, 0x43, 0x43, 0x41, 0x74, 0x69, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49, 0x44,
372     0x41, 0x6a, 0x71, 0x53, 0x4d, 0x41, 0x30, 0x47, 0x43, 0x53, 0x71, 0x47, 0x53, 0x49, 0x62, 0x33,
373     0x44, 0x51, 0x45, 0x42, 0x43, 0x77, 0x55, 0x41, 0x4d, 0x45, 0x49, 0x78, 0x43, 0x7a, 0x41, 0x4a,
374     0x42, 0x67, 0x4e, 0x56, 0x42, 0x41, 0x59, 0x54, 0x41, 0x6c, 0x56, 0x54, 0x0a, 0x4d, 0x52, 0x59,
375     0x77, 0x46, 0x41, 0x59, 0x44, 0x56, 0x51, 0x51, 0x4b, 0x45, 0x77, 0x31, 0x48, 0x5a, 0x57, 0x39,
376     0x55, 0x63, 0x6e, 0x56, 0x7a, 0x64, 0x43, 0x42, 0x4a, 0x62, 0x6d, 0x4d, 0x75, 0x4d, 0x52, 0x73,
377     0x77, 0x47, 0x51, 0x59, 0x44, 0x56, 0x51, 0x51, 0x44, 0x45, 0x78, 0x4a, 0x48, 0x5a, 0x57, 0x39,
378     0x55, 0x63, 0x6e, 0x56, 0x7a, 0x64, 0x43, 0x42, 0x48, 0x62, 0x47, 0x39, 0x69, 0x0a, 0x59, 0x57,
379     0x77, 0x67, 0x51, 0x30, 0x45, 0x77, 0x48, 0x68, 0x63, 0x4e, 0x4d, 0x54, 0x55, 0x77, 0x4e, 0x44,
380     0x41, 0x78, 0x4d, 0x44, 0x41, 0x77, 0x4d, 0x44, 0x41, 0x77, 0x57, 0x68, 0x63, 0x4e, 0x4d, 0x54,
381     0x63, 0x78, 0x4d, 0x6a, 0x4d, 0x78, 0x4d, 0x6a, 0x4d, 0x31, 0x4f, 0x54, 0x55, 0x35, 0x57, 0x6a,
382     0x42, 0x4a, 0x4d, 0x51, 0x73, 0x77, 0x43, 0x51, 0x59, 0x44, 0x56, 0x51, 0x51, 0x47, 0x0a, 0x45,
383     0x77, 0x4a, 0x56, 0x55, 0x7a, 0x45, 0x54, 0x4d, 0x42, 0x45, 0x47, 0x41, 0x31, 0x55, 0x45, 0x43,
384     0x68, 0x4d, 0x4b, 0x52, 0x32, 0x39, 0x76, 0x5a, 0x32, 0x78, 0x6c, 0x49, 0x45, 0x6c, 0x75, 0x59,
385     0x7a, 0x45, 0x6c, 0x4d, 0x43, 0x4d, 0x47, 0x41, 0x31, 0x55, 0x45, 0x41, 0x78, 0x4d, 0x63, 0x52,
386     0x32, 0x39, 0x76, 0x5a, 0x32, 0x78, 0x6c, 0x49, 0x45, 0x6c, 0x75, 0x64, 0x47, 0x56, 0x79, 0x0a,
387     0x62, 0x6d, 0x56, 0x30, 0x49, 0x45, 0x46, 0x31, 0x64, 0x47, 0x68, 0x76, 0x63, 0x6d, 0x6c, 0x30,
388     0x65, 0x53, 0x42, 0x48, 0x4d, 0x6a, 0x43, 0x43, 0x41, 0x53, 0x49, 0x77, 0x44, 0x51, 0x59, 0x4a,
389     0x4b, 0x6f, 0x5a, 0x49, 0x68, 0x76, 0x63, 0x4e, 0x41, 0x51, 0x45, 0x42, 0x42, 0x51, 0x41, 0x44,
390     0x67, 0x67, 0x45, 0x50, 0x41, 0x44, 0x43, 0x43, 0x41, 0x51, 0x6f, 0x43, 0x67, 0x67, 0x45, 0x42,
391     0x0a, 0x41, 0x4a, 0x77, 0x71, 0x42, 0x48, 0x64, 0x63, 0x32, 0x46, 0x43, 0x52, 0x4f, 0x67, 0x61,
392     0x6a, 0x67, 0x75, 0x44, 0x59, 0x55, 0x45, 0x69, 0x38, 0x69, 0x54, 0x2f, 0x78, 0x47, 0x58, 0x41,
393     0x61, 0x69, 0x45, 0x5a, 0x2b, 0x34, 0x49, 0x2f, 0x46, 0x38, 0x59, 0x6e, 0x4f, 0x49, 0x65, 0x35,
394     0x61, 0x2f, 0x6d, 0x45, 0x4e, 0x74, 0x7a, 0x4a, 0x45, 0x69, 0x61, 0x42, 0x30, 0x43, 0x31, 0x4e,
395     0x50, 0x0a, 0x56, 0x61, 0x54, 0x4f, 0x67, 0x6d, 0x4b, 0x56, 0x37, 0x75, 0x74, 0x5a, 0x58, 0x38,
396     0x62, 0x68, 0x42, 0x59, 0x41, 0x53, 0x78, 0x46, 0x36, 0x55, 0x50, 0x37, 0x78, 0x62, 0x53, 0x44,
397     0x6a, 0x30, 0x55, 0x2f, 0x63, 0x6b, 0x35, 0x76, 0x75, 0x52, 0x36, 0x52, 0x58, 0x45, 0x7a, 0x2f,
398     0x52, 0x54, 0x44, 0x66, 0x52, 0x4b, 0x2f, 0x4a, 0x39, 0x55, 0x33, 0x6e, 0x32, 0x2b, 0x6f, 0x47,
399     0x74, 0x76, 0x0a, 0x68, 0x38, 0x44, 0x51, 0x55, 0x42, 0x38, 0x6f, 0x4d, 0x41, 0x4e, 0x41, 0x32,
400     0x67, 0x68, 0x7a, 0x55, 0x57, 0x78, 0x2f, 0x2f, 0x7a, 0x6f, 0x38, 0x70, 0x7a, 0x63, 0x47, 0x6a,
401     0x72, 0x31, 0x4c, 0x45, 0x51, 0x54, 0x72, 0x66, 0x53, 0x54, 0x65, 0x35, 0x76, 0x6e, 0x38, 0x4d,
402     0x58, 0x48, 0x37, 0x6c, 0x4e, 0x56, 0x67, 0x38, 0x79, 0x35, 0x4b, 0x72, 0x30, 0x4c, 0x53, 0x79,
403     0x2b, 0x72, 0x45, 0x0a, 0x61, 0x68, 0x71, 0x79, 0x7a, 0x46, 0x50, 0x64, 0x46, 0x55, 0x75, 0x4c,
404     0x48, 0x38, 0x67, 0x5a, 0x59, 0x52, 0x2f, 0x4e, 0x6e, 0x61, 0x67, 0x2b, 0x59, 0x79, 0x75, 0x45,
405     0x4e, 0x57, 0x6c, 0x6c, 0x68, 0x4d, 0x67, 0x5a, 0x78, 0x55, 0x59, 0x69, 0x2b, 0x46, 0x4f, 0x56,
406     0x76, 0x75, 0x4f, 0x41, 0x53, 0x68, 0x44, 0x47, 0x4b, 0x75, 0x79, 0x36, 0x6c, 0x79, 0x41, 0x52,
407     0x78, 0x7a, 0x6d, 0x5a, 0x0a, 0x45, 0x41, 0x53, 0x67, 0x38, 0x47, 0x46, 0x36, 0x6c, 0x53, 0x57,
408     0x4d, 0x54, 0x6c, 0x4a, 0x31, 0x34, 0x72, 0x62, 0x74, 0x43, 0x4d, 0x6f, 0x55, 0x2f, 0x4d, 0x34,
409     0x69, 0x61, 0x72, 0x4e, 0x4f, 0x7a, 0x30, 0x59, 0x44, 0x6c, 0x35, 0x63, 0x44, 0x66, 0x73, 0x43,
410     0x78, 0x33, 0x6e, 0x75, 0x76, 0x52, 0x54, 0x50, 0x50, 0x75, 0x6a, 0x35, 0x78, 0x74, 0x39, 0x37,
411     0x30, 0x4a, 0x53, 0x58, 0x43, 0x0a, 0x44, 0x54, 0x57, 0x4a, 0x6e, 0x5a, 0x33, 0x37, 0x44, 0x68,
412     0x46, 0x35, 0x69, 0x52, 0x34, 0x33, 0x78, 0x61, 0x2b, 0x4f, 0x63, 0x6d, 0x6b, 0x43, 0x41, 0x77,
413     0x45, 0x41, 0x41, 0x61, 0x4f, 0x42, 0x35, 0x7a, 0x43, 0x42, 0x35, 0x44, 0x41, 0x66, 0x42, 0x67,
414     0x4e, 0x56, 0x48, 0x53, 0x4d, 0x45, 0x47, 0x44, 0x41, 0x57, 0x67, 0x42, 0x54, 0x41, 0x65, 0x70,
415     0x68, 0x6f, 0x6a, 0x59, 0x6e, 0x37, 0x0a, 0x71, 0x77, 0x56, 0x6b, 0x44, 0x42, 0x46, 0x39, 0x71,
416     0x6e, 0x31, 0x6c, 0x75, 0x4d, 0x72, 0x4d, 0x54, 0x6a, 0x41, 0x64, 0x42, 0x67, 0x4e, 0x56, 0x48,
417     0x51, 0x34, 0x45, 0x46, 0x67, 0x51, 0x55, 0x53, 0x74, 0x30, 0x47, 0x46, 0x68, 0x75, 0x38, 0x39,
418     0x6d, 0x69, 0x31, 0x64, 0x76, 0x57, 0x42, 0x74, 0x72, 0x74, 0x69, 0x47, 0x72, 0x70, 0x61, 0x67,
419     0x53, 0x38, 0x77, 0x44, 0x67, 0x59, 0x44, 0x0a, 0x56, 0x52, 0x30, 0x50, 0x41, 0x51, 0x48, 0x2f,
420     0x42, 0x41, 0x51, 0x44, 0x41, 0x67, 0x45, 0x47, 0x4d, 0x43, 0x34, 0x47, 0x43, 0x43, 0x73, 0x47,
421     0x41, 0x51, 0x55, 0x46, 0x42, 0x77, 0x45, 0x42, 0x42, 0x43, 0x49, 0x77, 0x49, 0x44, 0x41, 0x65,
422     0x42, 0x67, 0x67, 0x72, 0x42, 0x67, 0x45, 0x46, 0x42, 0x51, 0x63, 0x77, 0x41, 0x59, 0x59, 0x53,
423     0x61, 0x48, 0x52, 0x30, 0x63, 0x44, 0x6f, 0x76, 0x0a, 0x4c, 0x32, 0x63, 0x75, 0x63, 0x33, 0x6c,
424     0x74, 0x59, 0x32, 0x51, 0x75, 0x59, 0x32, 0x39, 0x74, 0x4d, 0x42, 0x49, 0x47, 0x41, 0x31, 0x55,
425     0x64, 0x45, 0x77, 0x45, 0x42, 0x2f, 0x77, 0x51, 0x49, 0x4d, 0x41, 0x59, 0x42, 0x41, 0x66, 0x38,
426     0x43, 0x41, 0x51, 0x41, 0x77, 0x4e, 0x51, 0x59, 0x44, 0x56, 0x52, 0x30, 0x66, 0x42, 0x43, 0x34,
427     0x77, 0x4c, 0x44, 0x41, 0x71, 0x6f, 0x43, 0x69, 0x67, 0x0a, 0x4a, 0x6f, 0x59, 0x6b, 0x61, 0x48,
428     0x52, 0x30, 0x63, 0x44, 0x6f, 0x76, 0x4c, 0x32, 0x63, 0x75, 0x63, 0x33, 0x6c, 0x74, 0x59, 0x32,
429     0x49, 0x75, 0x59, 0x32, 0x39, 0x74, 0x4c, 0x32, 0x4e, 0x79, 0x62, 0x48, 0x4d, 0x76, 0x5a, 0x33,
430     0x52, 0x6e, 0x62, 0x47, 0x39, 0x69, 0x59, 0x57, 0x77, 0x75, 0x59, 0x33, 0x4a, 0x73, 0x4d, 0x42,
431     0x63, 0x47, 0x41, 0x31, 0x55, 0x64, 0x49, 0x41, 0x51, 0x51, 0x0a, 0x4d, 0x41, 0x34, 0x77, 0x44,
432     0x41, 0x59, 0x4b, 0x4b, 0x77, 0x59, 0x42, 0x42, 0x41, 0x48, 0x57, 0x65, 0x51, 0x49, 0x46, 0x41,
433     0x54, 0x41, 0x4e, 0x42, 0x67, 0x6b, 0x71, 0x68, 0x6b, 0x69, 0x47, 0x39, 0x77, 0x30, 0x42, 0x41,
434     0x51, 0x73, 0x46, 0x41, 0x41, 0x4f, 0x43, 0x41, 0x51, 0x45, 0x41, 0x43, 0x45, 0x34, 0x45, 0x70,
435     0x34, 0x42, 0x2f, 0x45, 0x42, 0x5a, 0x44, 0x58, 0x67, 0x4b, 0x74, 0x0a, 0x31, 0x30, 0x4b, 0x41,
436     0x39, 0x4c, 0x43, 0x4f, 0x30, 0x71, 0x36, 0x7a, 0x36, 0x78, 0x46, 0x39, 0x6b, 0x49, 0x51, 0x59,
437     0x66, 0x65, 0x65, 0x51, 0x46, 0x66, 0x74, 0x4a, 0x66, 0x36, 0x69, 0x5a, 0x42, 0x5a, 0x47, 0x37,
438     0x65, 0x73, 0x6e, 0x57, 0x50, 0x44, 0x63, 0x59, 0x43, 0x5a, 0x71, 0x32, 0x78, 0x35, 0x49, 0x67,
439     0x42, 0x7a, 0x55, 0x7a, 0x43, 0x65, 0x51, 0x6f, 0x59, 0x33, 0x49, 0x4e, 0x0a, 0x74, 0x4f, 0x41,
440     0x79, 0x6e, 0x49, 0x65, 0x59, 0x78, 0x42, 0x74, 0x32, 0x69, 0x57, 0x66, 0x42, 0x55, 0x46, 0x69,
441     0x77, 0x45, 0x36, 0x6f, 0x54, 0x47, 0x68, 0x73, 0x79, 0x70, 0x62, 0x37, 0x71, 0x45, 0x5a, 0x56,
442     0x4d, 0x53, 0x47, 0x4e, 0x4a, 0x36, 0x5a, 0x6c, 0x64, 0x49, 0x44, 0x66, 0x4d, 0x2f, 0x69, 0x70,
443     0x70, 0x55, 0x52, 0x61, 0x56, 0x53, 0x36, 0x6e, 0x65, 0x53, 0x59, 0x4c, 0x41, 0x0a, 0x45, 0x48,
444     0x44, 0x30, 0x4c, 0x50, 0x50, 0x73, 0x76, 0x43, 0x51, 0x6b, 0x30, 0x45, 0x36, 0x73, 0x70, 0x64,
445     0x6c, 0x65, 0x48, 0x6d, 0x32, 0x53, 0x77, 0x61, 0x65, 0x73, 0x53, 0x44, 0x57, 0x42, 0x2b, 0x65,
446     0x58, 0x6b, 0x6e, 0x47, 0x56, 0x70, 0x7a, 0x59, 0x65, 0x6b, 0x51, 0x56, 0x41, 0x2f, 0x4c, 0x6c,
447     0x65, 0x6c, 0x6b, 0x56, 0x45, 0x53, 0x57, 0x41, 0x36, 0x4d, 0x43, 0x61, 0x47, 0x73, 0x0a, 0x65,
448     0x71, 0x51, 0x53, 0x70, 0x53, 0x66, 0x7a, 0x6d, 0x68, 0x43, 0x58, 0x66, 0x56, 0x55, 0x44, 0x42,
449     0x76, 0x64, 0x6d, 0x57, 0x46, 0x39, 0x66, 0x5a, 0x4f, 0x47, 0x72, 0x58, 0x57, 0x32, 0x6c, 0x4f,
450     0x55, 0x68, 0x31, 0x6d, 0x45, 0x77, 0x70, 0x57, 0x6a, 0x71, 0x4e, 0x30, 0x79, 0x76, 0x4b, 0x6e,
451     0x46, 0x55, 0x45, 0x76, 0x2f, 0x54, 0x6d, 0x46, 0x4e, 0x57, 0x41, 0x72, 0x43, 0x62, 0x74, 0x0a,
452     0x46, 0x34, 0x6d, 0x6d, 0x6b, 0x32, 0x78, 0x63, 0x70, 0x4d, 0x79, 0x34, 0x38, 0x47, 0x61, 0x4f,
453     0x5a, 0x4f, 0x4e, 0x39, 0x6d, 0x75, 0x49, 0x41, 0x73, 0x30, 0x6e, 0x48, 0x35, 0x41, 0x71, 0x71,
454     0x33, 0x56, 0x75, 0x44, 0x78, 0x33, 0x43, 0x51, 0x52, 0x6b, 0x36, 0x2b, 0x30, 0x4e, 0x74, 0x5a,
455     0x6c, 0x6d, 0x77, 0x75, 0x39, 0x52, 0x59, 0x32, 0x33, 0x6e, 0x48, 0x4d, 0x41, 0x63, 0x49, 0x53,
456     0x0a, 0x77, 0x53, 0x48, 0x47, 0x46, 0x67, 0x3d, 0x3d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45,
457     0x4e, 0x44, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d,
458     0x2d, 0x2d, 0x2d,
459     // \r \n NULL terminator
460     0x0d, 0x0a, 0x00,
461     // DER encoded certificate
462     0x30, 0x82, 0x02, 0x39, 0x30, 0x82, 0x01, 0xdf, 0x02, 0x01, 0x01, 0x30, 0x0a, 0x06, 0x08, 0x2a,
463     0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, 0x7c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
464     0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
465     0x09, 0x53, 0x6f, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x74, 0x65, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03,
466     0x55, 0x04, 0x07, 0x0c, 0x08, 0x53, 0x6f, 0x6d, 0x65, 0x63, 0x69, 0x74, 0x79, 0x31, 0x0b, 0x30,
467     0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x42, 0x42, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03,
468     0x55, 0x04, 0x0b, 0x0c, 0x0d, 0x53, 0x65, 0x71, 0x75, 0x72, 0x69, 0x74, 0x79, 0x20, 0x50, 0x61,
469     0x72, 0x74, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x02, 0x6f, 0x62, 0x31,
470     0x14, 0x30, 0x12, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x05,
471     0x6f, 0x62, 0x40, 0x62, 0x62, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x38, 0x31, 0x35, 0x31,
472     0x33, 0x31, 0x31, 0x31, 0x37, 0x5a, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x35, 0x31, 0x32, 0x31, 0x33,
473     0x31, 0x31, 0x31, 0x37, 0x5a, 0x30, 0x81, 0xd4, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
474     0x06, 0x13, 0x02, 0x55, 0x41, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x03,
475     0x41, 0x73, 0x64, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x06, 0x47, 0x6f,
476     0x74, 0x68, 0x61, 0x6d, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x5a,
477     0x5a, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x08, 0x42, 0x65, 0x61, 0x6d,
478     0x54, 0x65, 0x61, 0x6d, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
479     0x01, 0x09, 0x01, 0x16, 0x0d, 0x72, 0x61, 0x69, 0x6c, 0x40, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
480     0x6f, 0x6d, 0x31, 0x32, 0x30, 0x30, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x29, 0x75, 0x75, 0x69,
481     0x64, 0x3a, 0x33, 0x32, 0x33, 0x32, 0x33, 0x32, 0x33, 0x32, 0x2d, 0x33, 0x32, 0x33, 0x32, 0x2d,
482     0x33, 0x32, 0x33, 0x32, 0x2d, 0x33, 0x32, 0x33, 0x32, 0x2d, 0x33, 0x32, 0x33, 0x32, 0x33, 0x32,
483     0x33, 0x32, 0x33, 0x32, 0x33, 0x32, 0x31, 0x34, 0x30, 0x32, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x0c,
484     0x2b, 0x75, 0x73, 0x65, 0x72, 0x69, 0x64, 0x3a, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37,
485     0x2d, 0x36, 0x37, 0x36, 0x37, 0x2d, 0x36, 0x37, 0x36, 0x37, 0x2d, 0x36, 0x37, 0x36, 0x37, 0x2d,
486     0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x30, 0x59, 0x30, 0x13,
487     0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
488     0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0xf7, 0x13, 0x5c, 0x73, 0x72, 0xce, 0x10, 0xe5, 0x09,
489     0x97, 0x9a, 0xf8, 0xf2, 0x70, 0xa6, 0x3d, 0x89, 0xf5, 0xc5, 0xe4, 0x44, 0xe2, 0x4a, 0xb6, 0x61,
490     0xa8, 0x12, 0x8d, 0xb4, 0xdc, 0x2b, 0x47, 0x84, 0x60, 0x0c, 0x25, 0x66, 0xe9, 0xe0, 0xe5, 0xac,
491     0x22, 0xbf, 0x15, 0xdc, 0x71, 0xb1, 0x88, 0x4f, 0x16, 0xbf, 0xc2, 0x77, 0x37, 0x76, 0x3f, 0xe0,
492     0x67, 0xc6, 0x1d, 0x23, 0xfe, 0x7c, 0x8b, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
493     0x04, 0x03, 0x02, 0x03, 0x48, 0x00, 0x30, 0x45, 0x02, 0x20, 0x47, 0xcc, 0x41, 0x8a, 0x27, 0xc7,
494     0xd0, 0xaa, 0xb4, 0xab, 0x85, 0xbf, 0x09, 0x4d, 0x06, 0xd7, 0x7e, 0x0d, 0x39, 0xf9, 0x36, 0xa1,
495     0x3d, 0x96, 0x23, 0xe2, 0x24, 0x64, 0x98, 0x63, 0x21, 0xba, 0x02, 0x21, 0x00, 0xe5, 0x8f, 0x7f,
496     0xf1, 0xa6, 0x82, 0x03, 0x6a, 0x18, 0x7a, 0x54, 0xe7, 0x0e, 0x25, 0x77, 0xd8, 0x46, 0xfa, 0x96,
497     0x8a, 0x7e, 0x14, 0xc4, 0xcb, 0x21, 0x32, 0x3e, 0x89, 0xd9, 0xba, 0x8c, 0x3f,
498     // DER encoded certificate
499     0x30, 0x82, 0x02, 0x39, 0x30, 0x82, 0x01, 0xdf, 0x02, 0x01, 0x01, 0x30, 0x0a, 0x06, 0x08, 0x2a,
500     0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, 0x7c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
501     0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
502     0x09, 0x53, 0x6f, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x74, 0x65, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03,
503     0x55, 0x04, 0x07, 0x0c, 0x08, 0x53, 0x6f, 0x6d, 0x65, 0x63, 0x69, 0x74, 0x79, 0x31, 0x0b, 0x30,
504     0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x42, 0x42, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03,
505     0x55, 0x04, 0x0b, 0x0c, 0x0d, 0x53, 0x65, 0x71, 0x75, 0x72, 0x69, 0x74, 0x79, 0x20, 0x50, 0x61,
506     0x72, 0x74, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x02, 0x6f, 0x62, 0x31,
507     0x14, 0x30, 0x12, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x05,
508     0x6f, 0x62, 0x40, 0x62, 0x62, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x38, 0x31, 0x35, 0x31,
509     0x33, 0x31, 0x31, 0x31, 0x37, 0x5a, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x35, 0x31, 0x32, 0x31, 0x33,
510     0x31, 0x31, 0x31, 0x37, 0x5a, 0x30, 0x81, 0xd4, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
511     0x06, 0x13, 0x02, 0x55, 0x41, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x03,
512     0x41, 0x73, 0x64, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x06, 0x47, 0x6f,
513     0x74, 0x68, 0x61, 0x6d, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x5a,
514     0x5a, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x08, 0x42, 0x65, 0x61, 0x6d,
515     0x54, 0x65, 0x61, 0x6d, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
516     0x01, 0x09, 0x01, 0x16, 0x0d, 0x72, 0x61, 0x69, 0x6c, 0x40, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
517     0x6f, 0x6d, 0x31, 0x32, 0x30, 0x30, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x29, 0x75, 0x75, 0x69,
518     0x64, 0x3a, 0x33, 0x32, 0x33, 0x32, 0x33, 0x32, 0x33, 0x32, 0x2d, 0x33, 0x32, 0x33, 0x32, 0x2d,
519     0x33, 0x32, 0x33, 0x32, 0x2d, 0x33, 0x32, 0x33, 0x32, 0x2d, 0x33, 0x32, 0x33, 0x32, 0x33, 0x32,
520     0x33, 0x32, 0x33, 0x32, 0x33, 0x32, 0x31, 0x34, 0x30, 0x32, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x0c,
521     0x2b, 0x75, 0x73, 0x65, 0x72, 0x69, 0x64, 0x3a, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37,
522     0x2d, 0x36, 0x37, 0x36, 0x37, 0x2d, 0x36, 0x37, 0x36, 0x37, 0x2d, 0x36, 0x37, 0x36, 0x37, 0x2d,
523     0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x30, 0x59, 0x30, 0x13,
524     0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
525     0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0xf7, 0x13, 0x5c, 0x73, 0x72, 0xce, 0x10, 0xe5, 0x09,
526     0x97, 0x9a, 0xf8, 0xf2, 0x70, 0xa6, 0x3d, 0x89, 0xf5, 0xc5, 0xe4, 0x44, 0xe2, 0x4a, 0xb6, 0x61,
527     0xa8, 0x12, 0x8d, 0xb4, 0xdc, 0x2b, 0x47, 0x84, 0x60, 0x0c, 0x25, 0x66, 0xe9, 0xe0, 0xe5, 0xac,
528     0x22, 0xbf, 0x15, 0xdc, 0x71, 0xb1, 0x88, 0x4f, 0x16, 0xbf, 0xc2, 0x77, 0x37, 0x76, 0x3f, 0xe0,
529     0x67, 0xc6, 0x1d, 0x23, 0xfe, 0x7c, 0x8b, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
530     0x04, 0x03, 0x02, 0x03, 0x48, 0x00, 0x30, 0x45, 0x02, 0x20, 0x47, 0xcc, 0x41, 0x8a, 0x27, 0xc7,
531     0xd0, 0xaa, 0xb4, 0xab, 0x85, 0xbf, 0x09, 0x4d, 0x06, 0xd7, 0x7e, 0x0d, 0x39, 0xf9, 0x36, 0xa1,
532     0x3d, 0x96, 0x23, 0xe2, 0x24, 0x64, 0x98, 0x63, 0x21, 0xba, 0x02, 0x21, 0x00, 0xe5, 0x8f, 0x7f,
533     0xf1, 0xa6, 0x82, 0x03, 0x6a, 0x18, 0x7a, 0x54, 0xe7, 0x0e, 0x25, 0x77, 0xd8, 0x46, 0xfa, 0x96,
534     0x8a, 0x7e, 0x14, 0xc4, 0xcb, 0x21, 0x32, 0x3e, 0x89, 0xd9, 0xba, 0x8c, 0x3f,
535     // NULL \n terminator
536     0x00, 0x0a,
537     // PEM encoded certificate
538     0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49,
539     0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x43,
540     0x6e, 0x44, 0x43, 0x43, 0x41, 0x6a, 0x2b, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49, 0x55,
541     0x44, 0x67, 0x45, 0x38, 0x4e, 0x50, 0x54, 0x4c, 0x46, 0x64, 0x6d, 0x68, 0x75, 0x72, 0x53, 0x69,
542     0x36, 0x33, 0x49, 0x31, 0x41, 0x77, 0x76, 0x37, 0x39, 0x49, 0x6b, 0x77, 0x44, 0x41, 0x59, 0x49,
543     0x4b, 0x6f, 0x5a, 0x49, 0x7a, 0x6a, 0x30, 0x45, 0x41, 0x77, 0x49, 0x46, 0x0a, 0x41, 0x44, 0x43,
544     0x42, 0x67, 0x7a, 0x45, 0x34, 0x4d, 0x44, 0x59, 0x47, 0x41, 0x31, 0x55, 0x45, 0x41, 0x78, 0x4d,
545     0x76, 0x55, 0x32, 0x46, 0x74, 0x63, 0x33, 0x56, 0x75, 0x5a, 0x79, 0x42, 0x46, 0x62, 0x47, 0x56,
546     0x6a, 0x64, 0x48, 0x4a, 0x76, 0x62, 0x6d, 0x6c, 0x6a, 0x63, 0x79, 0x42, 0x50, 0x51, 0x30, 0x59,
547     0x67, 0x54, 0x55, 0x4d, 0x67, 0x52, 0x47, 0x56, 0x32, 0x61, 0x57, 0x4e, 0x6c, 0x0a, 0x49, 0x46,
548     0x4e, 0x31, 0x59, 0x6b, 0x4e, 0x42, 0x49, 0x48, 0x59, 0x78, 0x49, 0x46, 0x52, 0x46, 0x55, 0x31,
549     0x51, 0x78, 0x48, 0x44, 0x41, 0x61, 0x42, 0x67, 0x4e, 0x56, 0x42, 0x41, 0x73, 0x54, 0x45, 0x30,
550     0x39, 0x44, 0x52, 0x69, 0x42, 0x4e, 0x51, 0x79, 0x42, 0x45, 0x5a, 0x58, 0x5a, 0x70, 0x59, 0x32,
551     0x55, 0x67, 0x55, 0x33, 0x56, 0x69, 0x51, 0x30, 0x45, 0x78, 0x48, 0x44, 0x41, 0x61, 0x0a, 0x42,
552     0x67, 0x4e, 0x56, 0x42, 0x41, 0x6f, 0x54, 0x45, 0x31, 0x4e, 0x68, 0x62, 0x58, 0x4e, 0x31, 0x62,
553     0x6d, 0x63, 0x67, 0x52, 0x57, 0x78, 0x6c, 0x59, 0x33, 0x52, 0x79, 0x62, 0x32, 0x35, 0x70, 0x59,
554     0x33, 0x4d, 0x78, 0x43, 0x7a, 0x41, 0x4a, 0x42, 0x67, 0x4e, 0x56, 0x42, 0x41, 0x59, 0x54, 0x41,
555     0x6b, 0x74, 0x53, 0x4d, 0x43, 0x41, 0x58, 0x44, 0x54, 0x45, 0x32, 0x4d, 0x54, 0x45, 0x79, 0x0a,
556     0x4e, 0x44, 0x41, 0x79, 0x4e, 0x44, 0x67, 0x78, 0x4d, 0x6c, 0x6f, 0x59, 0x44, 0x7a, 0x49, 0x77,
557     0x4e, 0x6a, 0x6b, 0x78, 0x4d, 0x6a, 0x4d, 0x78, 0x4d, 0x54, 0x51, 0x31, 0x4f, 0x54, 0x55, 0x35,
558     0x57, 0x6a, 0x43, 0x42, 0x6a, 0x54, 0x46, 0x49, 0x4d, 0x45, 0x59, 0x47, 0x41, 0x31, 0x55, 0x45,
559     0x41, 0x78, 0x4d, 0x2f, 0x54, 0x30, 0x4e, 0x47, 0x49, 0x45, 0x52, 0x6c, 0x64, 0x6d, 0x6c, 0x6a,
560     0x0a, 0x5a, 0x53, 0x42, 0x55, 0x52, 0x56, 0x4e, 0x55, 0x4f, 0x69, 0x42, 0x4f, 0x5a, 0x58, 0x52,
561     0x33, 0x62, 0x33, 0x4a, 0x72, 0x49, 0x43, 0x67, 0x77, 0x4e, 0x6a, 0x51, 0x79, 0x4e, 0x32, 0x45,
562     0x32, 0x4e, 0x53, 0x31, 0x69, 0x5a, 0x6a, 0x63, 0x30, 0x4c, 0x54, 0x51, 0x33, 0x4d, 0x7a, 0x63,
563     0x74, 0x4f, 0x54, 0x5a, 0x6d, 0x4d, 0x53, 0x30, 0x78, 0x59, 0x6d, 0x49, 0x78, 0x4f, 0x44, 0x5a,
564     0x6b, 0x0a, 0x4f, 0x47, 0x59, 0x33, 0x59, 0x6a, 0x4d, 0x70, 0x4d, 0x52, 0x59, 0x77, 0x46, 0x41,
565     0x59, 0x44, 0x56, 0x51, 0x51, 0x4c, 0x45, 0x77, 0x31, 0x50, 0x51, 0x30, 0x59, 0x67, 0x54, 0x55,
566     0x4d, 0x67, 0x52, 0x47, 0x56, 0x32, 0x61, 0x57, 0x4e, 0x6c, 0x4d, 0x52, 0x77, 0x77, 0x47, 0x67,
567     0x59, 0x44, 0x56, 0x51, 0x51, 0x4b, 0x45, 0x78, 0x4e, 0x54, 0x59, 0x57, 0x31, 0x7a, 0x64, 0x57,
568     0x35, 0x6e, 0x0a, 0x49, 0x45, 0x56, 0x73, 0x5a, 0x57, 0x4e, 0x30, 0x63, 0x6d, 0x39, 0x75, 0x61,
569     0x57, 0x4e, 0x7a, 0x4d, 0x51, 0x73, 0x77, 0x43, 0x51, 0x59, 0x44, 0x56, 0x51, 0x51, 0x47, 0x45,
570     0x77, 0x4a, 0x4c, 0x55, 0x6a, 0x42, 0x5a, 0x4d, 0x42, 0x4d, 0x47, 0x42, 0x79, 0x71, 0x47, 0x53,
571     0x4d, 0x34, 0x39, 0x41, 0x67, 0x45, 0x47, 0x43, 0x43, 0x71, 0x47, 0x53, 0x4d, 0x34, 0x39, 0x41,
572     0x77, 0x45, 0x48, 0x0a, 0x41, 0x30, 0x49, 0x41, 0x42, 0x45, 0x45, 0x77, 0x51, 0x41, 0x52, 0x73,
573     0x62, 0x67, 0x43, 0x59, 0x2b, 0x43, 0x59, 0x6b, 0x49, 0x6a, 0x6b, 0x59, 0x6f, 0x47, 0x78, 0x6f,
574     0x52, 0x33, 0x75, 0x70, 0x33, 0x38, 0x59, 0x47, 0x54, 0x32, 0x63, 0x4b, 0x30, 0x31, 0x74, 0x6d,
575     0x32, 0x70, 0x38, 0x79, 0x4c, 0x4b, 0x4e, 0x73, 0x6d, 0x69, 0x53, 0x6f, 0x76, 0x46, 0x70, 0x4a,
576     0x32, 0x35, 0x63, 0x52, 0x0a, 0x74, 0x72, 0x57, 0x34, 0x41, 0x56, 0x7a, 0x76, 0x73, 0x64, 0x67,
577     0x62, 0x74, 0x72, 0x45, 0x62, 0x6b, 0x2b, 0x37, 0x73, 0x56, 0x61, 0x58, 0x50, 0x74, 0x78, 0x43,
578     0x6a, 0x67, 0x59, 0x41, 0x77, 0x66, 0x6a, 0x41, 0x4f, 0x42, 0x67, 0x4e, 0x56, 0x48, 0x51, 0x38,
579     0x42, 0x41, 0x66, 0x38, 0x45, 0x42, 0x41, 0x4d, 0x43, 0x41, 0x38, 0x67, 0x77, 0x4c, 0x67, 0x59,
580     0x44, 0x56, 0x52, 0x30, 0x66, 0x0a, 0x42, 0x43, 0x63, 0x77, 0x4a, 0x54, 0x41, 0x6a, 0x6f, 0x43,
581     0x47, 0x67, 0x48, 0x34, 0x59, 0x64, 0x61, 0x48, 0x52, 0x30, 0x63, 0x44, 0x6f, 0x76, 0x4c, 0x32,
582     0x4e, 0x68, 0x4c, 0x6e, 0x4e, 0x68, 0x62, 0x58, 0x4e, 0x31, 0x62, 0x6d, 0x64, 0x70, 0x62, 0x33,
583     0x52, 0x7a, 0x4c, 0x6d, 0x4e, 0x76, 0x62, 0x53, 0x39, 0x6a, 0x63, 0x6d, 0x77, 0x77, 0x50, 0x41,
584     0x59, 0x49, 0x4b, 0x77, 0x59, 0x42, 0x0a, 0x42, 0x51, 0x55, 0x48, 0x41, 0x51, 0x45, 0x45, 0x4d,
585     0x44, 0x41, 0x75, 0x4d, 0x43, 0x77, 0x47, 0x43, 0x43, 0x73, 0x47, 0x41, 0x51, 0x55, 0x46, 0x42,
586     0x7a, 0x41, 0x42, 0x68, 0x69, 0x42, 0x6f, 0x64, 0x48, 0x52, 0x77, 0x4f, 0x69, 0x38, 0x76, 0x62,
587     0x32, 0x4e, 0x7a, 0x63, 0x43, 0x31, 0x30, 0x5a, 0x58, 0x4e, 0x30, 0x4c, 0x6e, 0x4e, 0x68, 0x62,
588     0x58, 0x4e, 0x31, 0x62, 0x6d, 0x64, 0x70, 0x0a, 0x62, 0x33, 0x52, 0x7a, 0x4c, 0x6d, 0x4e, 0x76,
589     0x62, 0x54, 0x41, 0x4d, 0x42, 0x67, 0x67, 0x71, 0x68, 0x6b, 0x6a, 0x4f, 0x50, 0x51, 0x51, 0x44,
590     0x41, 0x67, 0x55, 0x41, 0x41, 0x30, 0x6b, 0x41, 0x4d, 0x45, 0x59, 0x43, 0x49, 0x51, 0x43, 0x33,
591     0x58, 0x30, 0x42, 0x61, 0x4f, 0x49, 0x6f, 0x63, 0x4b, 0x4f, 0x45, 0x65, 0x44, 0x46, 0x52, 0x6b,
592     0x63, 0x66, 0x30, 0x48, 0x76, 0x68, 0x68, 0x67, 0x0a, 0x73, 0x6c, 0x65, 0x49, 0x52, 0x32, 0x49,
593     0x62, 0x6d, 0x66, 0x34, 0x6e, 0x69, 0x52, 0x52, 0x55, 0x38, 0x41, 0x49, 0x68, 0x41, 0x4f, 0x4d,
594     0x44, 0x31, 0x77, 0x45, 0x62, 0x50, 0x67, 0x34, 0x70, 0x47, 0x77, 0x49, 0x79, 0x65, 0x77, 0x63,
595     0x61, 0x6b, 0x76, 0x72, 0x4e, 0x4b, 0x66, 0x44, 0x79, 0x2b, 0x4f, 0x4e, 0x43, 0x6e, 0x4e, 0x6e,
596     0x43, 0x59, 0x57, 0x4a, 0x37, 0x39, 0x35, 0x4b, 0x49, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45,
597     0x4e, 0x44, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d,
598     0x2d, 0x2d, 0x2d,
599     // \r terminator
600     0x0d,
601     // PEM encoded certificate
602     0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49,
603     0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x44,
604     0x38, 0x44, 0x43, 0x43, 0x41, 0x74, 0x69, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49, 0x44,
605     0x41, 0x6a, 0x71, 0x53, 0x4d, 0x41, 0x30, 0x47, 0x43, 0x53, 0x71, 0x47, 0x53, 0x49, 0x62, 0x33,
606     0x44, 0x51, 0x45, 0x42, 0x43, 0x77, 0x55, 0x41, 0x4d, 0x45, 0x49, 0x78, 0x43, 0x7a, 0x41, 0x4a,
607     0x42, 0x67, 0x4e, 0x56, 0x42, 0x41, 0x59, 0x54, 0x41, 0x6c, 0x56, 0x54, 0x0a, 0x4d, 0x52, 0x59,
608     0x77, 0x46, 0x41, 0x59, 0x44, 0x56, 0x51, 0x51, 0x4b, 0x45, 0x77, 0x31, 0x48, 0x5a, 0x57, 0x39,
609     0x55, 0x63, 0x6e, 0x56, 0x7a, 0x64, 0x43, 0x42, 0x4a, 0x62, 0x6d, 0x4d, 0x75, 0x4d, 0x52, 0x73,
610     0x77, 0x47, 0x51, 0x59, 0x44, 0x56, 0x51, 0x51, 0x44, 0x45, 0x78, 0x4a, 0x48, 0x5a, 0x57, 0x39,
611     0x55, 0x63, 0x6e, 0x56, 0x7a, 0x64, 0x43, 0x42, 0x48, 0x62, 0x47, 0x39, 0x69, 0x0a, 0x59, 0x57,
612     0x77, 0x67, 0x51, 0x30, 0x45, 0x77, 0x48, 0x68, 0x63, 0x4e, 0x4d, 0x54, 0x55, 0x77, 0x4e, 0x44,
613     0x41, 0x78, 0x4d, 0x44, 0x41, 0x77, 0x4d, 0x44, 0x41, 0x77, 0x57, 0x68, 0x63, 0x4e, 0x4d, 0x54,
614     0x63, 0x78, 0x4d, 0x6a, 0x4d, 0x78, 0x4d, 0x6a, 0x4d, 0x31, 0x4f, 0x54, 0x55, 0x35, 0x57, 0x6a,
615     0x42, 0x4a, 0x4d, 0x51, 0x73, 0x77, 0x43, 0x51, 0x59, 0x44, 0x56, 0x51, 0x51, 0x47, 0x0a, 0x45,
616     0x77, 0x4a, 0x56, 0x55, 0x7a, 0x45, 0x54, 0x4d, 0x42, 0x45, 0x47, 0x41, 0x31, 0x55, 0x45, 0x43,
617     0x68, 0x4d, 0x4b, 0x52, 0x32, 0x39, 0x76, 0x5a, 0x32, 0x78, 0x6c, 0x49, 0x45, 0x6c, 0x75, 0x59,
618     0x7a, 0x45, 0x6c, 0x4d, 0x43, 0x4d, 0x47, 0x41, 0x31, 0x55, 0x45, 0x41, 0x78, 0x4d, 0x63, 0x52,
619     0x32, 0x39, 0x76, 0x5a, 0x32, 0x78, 0x6c, 0x49, 0x45, 0x6c, 0x75, 0x64, 0x47, 0x56, 0x79, 0x0a,
620     0x62, 0x6d, 0x56, 0x30, 0x49, 0x45, 0x46, 0x31, 0x64, 0x47, 0x68, 0x76, 0x63, 0x6d, 0x6c, 0x30,
621     0x65, 0x53, 0x42, 0x48, 0x4d, 0x6a, 0x43, 0x43, 0x41, 0x53, 0x49, 0x77, 0x44, 0x51, 0x59, 0x4a,
622     0x4b, 0x6f, 0x5a, 0x49, 0x68, 0x76, 0x63, 0x4e, 0x41, 0x51, 0x45, 0x42, 0x42, 0x51, 0x41, 0x44,
623     0x67, 0x67, 0x45, 0x50, 0x41, 0x44, 0x43, 0x43, 0x41, 0x51, 0x6f, 0x43, 0x67, 0x67, 0x45, 0x42,
624     0x0a, 0x41, 0x4a, 0x77, 0x71, 0x42, 0x48, 0x64, 0x63, 0x32, 0x46, 0x43, 0x52, 0x4f, 0x67, 0x61,
625     0x6a, 0x67, 0x75, 0x44, 0x59, 0x55, 0x45, 0x69, 0x38, 0x69, 0x54, 0x2f, 0x78, 0x47, 0x58, 0x41,
626     0x61, 0x69, 0x45, 0x5a, 0x2b, 0x34, 0x49, 0x2f, 0x46, 0x38, 0x59, 0x6e, 0x4f, 0x49, 0x65, 0x35,
627     0x61, 0x2f, 0x6d, 0x45, 0x4e, 0x74, 0x7a, 0x4a, 0x45, 0x69, 0x61, 0x42, 0x30, 0x43, 0x31, 0x4e,
628     0x50, 0x0a, 0x56, 0x61, 0x54, 0x4f, 0x67, 0x6d, 0x4b, 0x56, 0x37, 0x75, 0x74, 0x5a, 0x58, 0x38,
629     0x62, 0x68, 0x42, 0x59, 0x41, 0x53, 0x78, 0x46, 0x36, 0x55, 0x50, 0x37, 0x78, 0x62, 0x53, 0x44,
630     0x6a, 0x30, 0x55, 0x2f, 0x63, 0x6b, 0x35, 0x76, 0x75, 0x52, 0x36, 0x52, 0x58, 0x45, 0x7a, 0x2f,
631     0x52, 0x54, 0x44, 0x66, 0x52, 0x4b, 0x2f, 0x4a, 0x39, 0x55, 0x33, 0x6e, 0x32, 0x2b, 0x6f, 0x47,
632     0x74, 0x76, 0x0a, 0x68, 0x38, 0x44, 0x51, 0x55, 0x42, 0x38, 0x6f, 0x4d, 0x41, 0x4e, 0x41, 0x32,
633     0x67, 0x68, 0x7a, 0x55, 0x57, 0x78, 0x2f, 0x2f, 0x7a, 0x6f, 0x38, 0x70, 0x7a, 0x63, 0x47, 0x6a,
634     0x72, 0x31, 0x4c, 0x45, 0x51, 0x54, 0x72, 0x66, 0x53, 0x54, 0x65, 0x35, 0x76, 0x6e, 0x38, 0x4d,
635     0x58, 0x48, 0x37, 0x6c, 0x4e, 0x56, 0x67, 0x38, 0x79, 0x35, 0x4b, 0x72, 0x30, 0x4c, 0x53, 0x79,
636     0x2b, 0x72, 0x45, 0x0a, 0x61, 0x68, 0x71, 0x79, 0x7a, 0x46, 0x50, 0x64, 0x46, 0x55, 0x75, 0x4c,
637     0x48, 0x38, 0x67, 0x5a, 0x59, 0x52, 0x2f, 0x4e, 0x6e, 0x61, 0x67, 0x2b, 0x59, 0x79, 0x75, 0x45,
638     0x4e, 0x57, 0x6c, 0x6c, 0x68, 0x4d, 0x67, 0x5a, 0x78, 0x55, 0x59, 0x69, 0x2b, 0x46, 0x4f, 0x56,
639     0x76, 0x75, 0x4f, 0x41, 0x53, 0x68, 0x44, 0x47, 0x4b, 0x75, 0x79, 0x36, 0x6c, 0x79, 0x41, 0x52,
640     0x78, 0x7a, 0x6d, 0x5a, 0x0a, 0x45, 0x41, 0x53, 0x67, 0x38, 0x47, 0x46, 0x36, 0x6c, 0x53, 0x57,
641     0x4d, 0x54, 0x6c, 0x4a, 0x31, 0x34, 0x72, 0x62, 0x74, 0x43, 0x4d, 0x6f, 0x55, 0x2f, 0x4d, 0x34,
642     0x69, 0x61, 0x72, 0x4e, 0x4f, 0x7a, 0x30, 0x59, 0x44, 0x6c, 0x35, 0x63, 0x44, 0x66, 0x73, 0x43,
643     0x78, 0x33, 0x6e, 0x75, 0x76, 0x52, 0x54, 0x50, 0x50, 0x75, 0x6a, 0x35, 0x78, 0x74, 0x39, 0x37,
644     0x30, 0x4a, 0x53, 0x58, 0x43, 0x0a, 0x44, 0x54, 0x57, 0x4a, 0x6e, 0x5a, 0x33, 0x37, 0x44, 0x68,
645     0x46, 0x35, 0x69, 0x52, 0x34, 0x33, 0x78, 0x61, 0x2b, 0x4f, 0x63, 0x6d, 0x6b, 0x43, 0x41, 0x77,
646     0x45, 0x41, 0x41, 0x61, 0x4f, 0x42, 0x35, 0x7a, 0x43, 0x42, 0x35, 0x44, 0x41, 0x66, 0x42, 0x67,
647     0x4e, 0x56, 0x48, 0x53, 0x4d, 0x45, 0x47, 0x44, 0x41, 0x57, 0x67, 0x42, 0x54, 0x41, 0x65, 0x70,
648     0x68, 0x6f, 0x6a, 0x59, 0x6e, 0x37, 0x0a, 0x71, 0x77, 0x56, 0x6b, 0x44, 0x42, 0x46, 0x39, 0x71,
649     0x6e, 0x31, 0x6c, 0x75, 0x4d, 0x72, 0x4d, 0x54, 0x6a, 0x41, 0x64, 0x42, 0x67, 0x4e, 0x56, 0x48,
650     0x51, 0x34, 0x45, 0x46, 0x67, 0x51, 0x55, 0x53, 0x74, 0x30, 0x47, 0x46, 0x68, 0x75, 0x38, 0x39,
651     0x6d, 0x69, 0x31, 0x64, 0x76, 0x57, 0x42, 0x74, 0x72, 0x74, 0x69, 0x47, 0x72, 0x70, 0x61, 0x67,
652     0x53, 0x38, 0x77, 0x44, 0x67, 0x59, 0x44, 0x0a, 0x56, 0x52, 0x30, 0x50, 0x41, 0x51, 0x48, 0x2f,
653     0x42, 0x41, 0x51, 0x44, 0x41, 0x67, 0x45, 0x47, 0x4d, 0x43, 0x34, 0x47, 0x43, 0x43, 0x73, 0x47,
654     0x41, 0x51, 0x55, 0x46, 0x42, 0x77, 0x45, 0x42, 0x42, 0x43, 0x49, 0x77, 0x49, 0x44, 0x41, 0x65,
655     0x42, 0x67, 0x67, 0x72, 0x42, 0x67, 0x45, 0x46, 0x42, 0x51, 0x63, 0x77, 0x41, 0x59, 0x59, 0x53,
656     0x61, 0x48, 0x52, 0x30, 0x63, 0x44, 0x6f, 0x76, 0x0a, 0x4c, 0x32, 0x63, 0x75, 0x63, 0x33, 0x6c,
657     0x74, 0x59, 0x32, 0x51, 0x75, 0x59, 0x32, 0x39, 0x74, 0x4d, 0x42, 0x49, 0x47, 0x41, 0x31, 0x55,
658     0x64, 0x45, 0x77, 0x45, 0x42, 0x2f, 0x77, 0x51, 0x49, 0x4d, 0x41, 0x59, 0x42, 0x41, 0x66, 0x38,
659     0x43, 0x41, 0x51, 0x41, 0x77, 0x4e, 0x51, 0x59, 0x44, 0x56, 0x52, 0x30, 0x66, 0x42, 0x43, 0x34,
660     0x77, 0x4c, 0x44, 0x41, 0x71, 0x6f, 0x43, 0x69, 0x67, 0x0a, 0x4a, 0x6f, 0x59, 0x6b, 0x61, 0x48,
661     0x52, 0x30, 0x63, 0x44, 0x6f, 0x76, 0x4c, 0x32, 0x63, 0x75, 0x63, 0x33, 0x6c, 0x74, 0x59, 0x32,
662     0x49, 0x75, 0x59, 0x32, 0x39, 0x74, 0x4c, 0x32, 0x4e, 0x79, 0x62, 0x48, 0x4d, 0x76, 0x5a, 0x33,
663     0x52, 0x6e, 0x62, 0x47, 0x39, 0x69, 0x59, 0x57, 0x77, 0x75, 0x59, 0x33, 0x4a, 0x73, 0x4d, 0x42,
664     0x63, 0x47, 0x41, 0x31, 0x55, 0x64, 0x49, 0x41, 0x51, 0x51, 0x0a, 0x4d, 0x41, 0x34, 0x77, 0x44,
665     0x41, 0x59, 0x4b, 0x4b, 0x77, 0x59, 0x42, 0x42, 0x41, 0x48, 0x57, 0x65, 0x51, 0x49, 0x46, 0x41,
666     0x54, 0x41, 0x4e, 0x42, 0x67, 0x6b, 0x71, 0x68, 0x6b, 0x69, 0x47, 0x39, 0x77, 0x30, 0x42, 0x41,
667     0x51, 0x73, 0x46, 0x41, 0x41, 0x4f, 0x43, 0x41, 0x51, 0x45, 0x41, 0x43, 0x45, 0x34, 0x45, 0x70,
668     0x34, 0x42, 0x2f, 0x45, 0x42, 0x5a, 0x44, 0x58, 0x67, 0x4b, 0x74, 0x0a, 0x31, 0x30, 0x4b, 0x41,
669     0x39, 0x4c, 0x43, 0x4f, 0x30, 0x71, 0x36, 0x7a, 0x36, 0x78, 0x46, 0x39, 0x6b, 0x49, 0x51, 0x59,
670     0x66, 0x65, 0x65, 0x51, 0x46, 0x66, 0x74, 0x4a, 0x66, 0x36, 0x69, 0x5a, 0x42, 0x5a, 0x47, 0x37,
671     0x65, 0x73, 0x6e, 0x57, 0x50, 0x44, 0x63, 0x59, 0x43, 0x5a, 0x71, 0x32, 0x78, 0x35, 0x49, 0x67,
672     0x42, 0x7a, 0x55, 0x7a, 0x43, 0x65, 0x51, 0x6f, 0x59, 0x33, 0x49, 0x4e, 0x0a, 0x74, 0x4f, 0x41,
673     0x79, 0x6e, 0x49, 0x65, 0x59, 0x78, 0x42, 0x74, 0x32, 0x69, 0x57, 0x66, 0x42, 0x55, 0x46, 0x69,
674     0x77, 0x45, 0x36, 0x6f, 0x54, 0x47, 0x68, 0x73, 0x79, 0x70, 0x62, 0x37, 0x71, 0x45, 0x5a, 0x56,
675     0x4d, 0x53, 0x47, 0x4e, 0x4a, 0x36, 0x5a, 0x6c, 0x64, 0x49, 0x44, 0x66, 0x4d, 0x2f, 0x69, 0x70,
676     0x70, 0x55, 0x52, 0x61, 0x56, 0x53, 0x36, 0x6e, 0x65, 0x53, 0x59, 0x4c, 0x41, 0x0a, 0x45, 0x48,
677     0x44, 0x30, 0x4c, 0x50, 0x50, 0x73, 0x76, 0x43, 0x51, 0x6b, 0x30, 0x45, 0x36, 0x73, 0x70, 0x64,
678     0x6c, 0x65, 0x48, 0x6d, 0x32, 0x53, 0x77, 0x61, 0x65, 0x73, 0x53, 0x44, 0x57, 0x42, 0x2b, 0x65,
679     0x58, 0x6b, 0x6e, 0x47, 0x56, 0x70, 0x7a, 0x59, 0x65, 0x6b, 0x51, 0x56, 0x41, 0x2f, 0x4c, 0x6c,
680     0x65, 0x6c, 0x6b, 0x56, 0x45, 0x53, 0x57, 0x41, 0x36, 0x4d, 0x43, 0x61, 0x47, 0x73, 0x0a, 0x65,
681     0x71, 0x51, 0x53, 0x70, 0x53, 0x66, 0x7a, 0x6d, 0x68, 0x43, 0x58, 0x66, 0x56, 0x55, 0x44, 0x42,
682     0x76, 0x64, 0x6d, 0x57, 0x46, 0x39, 0x66, 0x5a, 0x4f, 0x47, 0x72, 0x58, 0x57, 0x32, 0x6c, 0x4f,
683     0x55, 0x68, 0x31, 0x6d, 0x45, 0x77, 0x70, 0x57, 0x6a, 0x71, 0x4e, 0x30, 0x79, 0x76, 0x4b, 0x6e,
684     0x46, 0x55, 0x45, 0x76, 0x2f, 0x54, 0x6d, 0x46, 0x4e, 0x57, 0x41, 0x72, 0x43, 0x62, 0x74, 0x0a,
685     0x46, 0x34, 0x6d, 0x6d, 0x6b, 0x32, 0x78, 0x63, 0x70, 0x4d, 0x79, 0x34, 0x38, 0x47, 0x61, 0x4f,
686     0x5a, 0x4f, 0x4e, 0x39, 0x6d, 0x75, 0x49, 0x41, 0x73, 0x30, 0x6e, 0x48, 0x35, 0x41, 0x71, 0x71,
687     0x33, 0x56, 0x75, 0x44, 0x78, 0x33, 0x43, 0x51, 0x52, 0x6b, 0x36, 0x2b, 0x30, 0x4e, 0x74, 0x5a,
688     0x6c, 0x6d, 0x77, 0x75, 0x39, 0x52, 0x59, 0x32, 0x33, 0x6e, 0x48, 0x4d, 0x41, 0x63, 0x49, 0x53,
689     0x0a, 0x77, 0x53, 0x48, 0x47, 0x46, 0x67, 0x3d, 0x3d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45,
690     0x4e, 0x44, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d,
691     0x2d, 0x2d, 0x2d,
692     // PEM encoded certificate
693     0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49,
694     0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x43,
695     0x6e, 0x44, 0x43, 0x43, 0x41, 0x6a, 0x2b, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49, 0x55,
696     0x44, 0x67, 0x45, 0x38, 0x4e, 0x50, 0x54, 0x4c, 0x46, 0x64, 0x6d, 0x68, 0x75, 0x72, 0x53, 0x69,
697     0x36, 0x33, 0x49, 0x31, 0x41, 0x77, 0x76, 0x37, 0x39, 0x49, 0x6b, 0x77, 0x44, 0x41, 0x59, 0x49,
698     0x4b, 0x6f, 0x5a, 0x49, 0x7a, 0x6a, 0x30, 0x45, 0x41, 0x77, 0x49, 0x46, 0x0a, 0x41, 0x44, 0x43,
699     0x42, 0x67, 0x7a, 0x45, 0x34, 0x4d, 0x44, 0x59, 0x47, 0x41, 0x31, 0x55, 0x45, 0x41, 0x78, 0x4d,
700     0x76, 0x55, 0x32, 0x46, 0x74, 0x63, 0x33, 0x56, 0x75, 0x5a, 0x79, 0x42, 0x46, 0x62, 0x47, 0x56,
701     0x6a, 0x64, 0x48, 0x4a, 0x76, 0x62, 0x6d, 0x6c, 0x6a, 0x63, 0x79, 0x42, 0x50, 0x51, 0x30, 0x59,
702     0x67, 0x54, 0x55, 0x4d, 0x67, 0x52, 0x47, 0x56, 0x32, 0x61, 0x57, 0x4e, 0x6c, 0x0a, 0x49, 0x46,
703     0x4e, 0x31, 0x59, 0x6b, 0x4e, 0x42, 0x49, 0x48, 0x59, 0x78, 0x49, 0x46, 0x52, 0x46, 0x55, 0x31,
704     0x51, 0x78, 0x48, 0x44, 0x41, 0x61, 0x42, 0x67, 0x4e, 0x56, 0x42, 0x41, 0x73, 0x54, 0x45, 0x30,
705     0x39, 0x44, 0x52, 0x69, 0x42, 0x4e, 0x51, 0x79, 0x42, 0x45, 0x5a, 0x58, 0x5a, 0x70, 0x59, 0x32,
706     0x55, 0x67, 0x55, 0x33, 0x56, 0x69, 0x51, 0x30, 0x45, 0x78, 0x48, 0x44, 0x41, 0x61, 0x0a, 0x42,
707     0x67, 0x4e, 0x56, 0x42, 0x41, 0x6f, 0x54, 0x45, 0x31, 0x4e, 0x68, 0x62, 0x58, 0x4e, 0x31, 0x62,
708     0x6d, 0x63, 0x67, 0x52, 0x57, 0x78, 0x6c, 0x59, 0x33, 0x52, 0x79, 0x62, 0x32, 0x35, 0x70, 0x59,
709     0x33, 0x4d, 0x78, 0x43, 0x7a, 0x41, 0x4a, 0x42, 0x67, 0x4e, 0x56, 0x42, 0x41, 0x59, 0x54, 0x41,
710     0x6b, 0x74, 0x53, 0x4d, 0x43, 0x41, 0x58, 0x44, 0x54, 0x45, 0x32, 0x4d, 0x54, 0x45, 0x79, 0x0a,
711     0x4e, 0x44, 0x41, 0x79, 0x4e, 0x44, 0x67, 0x78, 0x4d, 0x6c, 0x6f, 0x59, 0x44, 0x7a, 0x49, 0x77,
712     0x4e, 0x6a, 0x6b, 0x78, 0x4d, 0x6a, 0x4d, 0x78, 0x4d, 0x54, 0x51, 0x31, 0x4f, 0x54, 0x55, 0x35,
713     0x57, 0x6a, 0x43, 0x42, 0x6a, 0x54, 0x46, 0x49, 0x4d, 0x45, 0x59, 0x47, 0x41, 0x31, 0x55, 0x45,
714     0x41, 0x78, 0x4d, 0x2f, 0x54, 0x30, 0x4e, 0x47, 0x49, 0x45, 0x52, 0x6c, 0x64, 0x6d, 0x6c, 0x6a,
715     0x0a, 0x5a, 0x53, 0x42, 0x55, 0x52, 0x56, 0x4e, 0x55, 0x4f, 0x69, 0x42, 0x4f, 0x5a, 0x58, 0x52,
716     0x33, 0x62, 0x33, 0x4a, 0x72, 0x49, 0x43, 0x67, 0x77, 0x4e, 0x6a, 0x51, 0x79, 0x4e, 0x32, 0x45,
717     0x32, 0x4e, 0x53, 0x31, 0x69, 0x5a, 0x6a, 0x63, 0x30, 0x4c, 0x54, 0x51, 0x33, 0x4d, 0x7a, 0x63,
718     0x74, 0x4f, 0x54, 0x5a, 0x6d, 0x4d, 0x53, 0x30, 0x78, 0x59, 0x6d, 0x49, 0x78, 0x4f, 0x44, 0x5a,
719     0x6b, 0x0a, 0x4f, 0x47, 0x59, 0x33, 0x59, 0x6a, 0x4d, 0x70, 0x4d, 0x52, 0x59, 0x77, 0x46, 0x41,
720     0x59, 0x44, 0x56, 0x51, 0x51, 0x4c, 0x45, 0x77, 0x31, 0x50, 0x51, 0x30, 0x59, 0x67, 0x54, 0x55,
721     0x4d, 0x67, 0x52, 0x47, 0x56, 0x32, 0x61, 0x57, 0x4e, 0x6c, 0x4d, 0x52, 0x77, 0x77, 0x47, 0x67,
722     0x59, 0x44, 0x56, 0x51, 0x51, 0x4b, 0x45, 0x78, 0x4e, 0x54, 0x59, 0x57, 0x31, 0x7a, 0x64, 0x57,
723     0x35, 0x6e, 0x0a, 0x49, 0x45, 0x56, 0x73, 0x5a, 0x57, 0x4e, 0x30, 0x63, 0x6d, 0x39, 0x75, 0x61,
724     0x57, 0x4e, 0x7a, 0x4d, 0x51, 0x73, 0x77, 0x43, 0x51, 0x59, 0x44, 0x56, 0x51, 0x51, 0x47, 0x45,
725     0x77, 0x4a, 0x4c, 0x55, 0x6a, 0x42, 0x5a, 0x4d, 0x42, 0x4d, 0x47, 0x42, 0x79, 0x71, 0x47, 0x53,
726     0x4d, 0x34, 0x39, 0x41, 0x67, 0x45, 0x47, 0x43, 0x43, 0x71, 0x47, 0x53, 0x4d, 0x34, 0x39, 0x41,
727     0x77, 0x45, 0x48, 0x0a, 0x41, 0x30, 0x49, 0x41, 0x42, 0x45, 0x45, 0x77, 0x51, 0x41, 0x52, 0x73,
728     0x62, 0x67, 0x43, 0x59, 0x2b, 0x43, 0x59, 0x6b, 0x49, 0x6a, 0x6b, 0x59, 0x6f, 0x47, 0x78, 0x6f,
729     0x52, 0x33, 0x75, 0x70, 0x33, 0x38, 0x59, 0x47, 0x54, 0x32, 0x63, 0x4b, 0x30, 0x31, 0x74, 0x6d,
730     0x32, 0x70, 0x38, 0x79, 0x4c, 0x4b, 0x4e, 0x73, 0x6d, 0x69, 0x53, 0x6f, 0x76, 0x46, 0x70, 0x4a,
731     0x32, 0x35, 0x63, 0x52, 0x0a, 0x74, 0x72, 0x57, 0x34, 0x41, 0x56, 0x7a, 0x76, 0x73, 0x64, 0x67,
732     0x62, 0x74, 0x72, 0x45, 0x62, 0x6b, 0x2b, 0x37, 0x73, 0x56, 0x61, 0x58, 0x50, 0x74, 0x78, 0x43,
733     0x6a, 0x67, 0x59, 0x41, 0x77, 0x66, 0x6a, 0x41, 0x4f, 0x42, 0x67, 0x4e, 0x56, 0x48, 0x51, 0x38,
734     0x42, 0x41, 0x66, 0x38, 0x45, 0x42, 0x41, 0x4d, 0x43, 0x41, 0x38, 0x67, 0x77, 0x4c, 0x67, 0x59,
735     0x44, 0x56, 0x52, 0x30, 0x66, 0x0a, 0x42, 0x43, 0x63, 0x77, 0x4a, 0x54, 0x41, 0x6a, 0x6f, 0x43,
736     0x47, 0x67, 0x48, 0x34, 0x59, 0x64, 0x61, 0x48, 0x52, 0x30, 0x63, 0x44, 0x6f, 0x76, 0x4c, 0x32,
737     0x4e, 0x68, 0x4c, 0x6e, 0x4e, 0x68, 0x62, 0x58, 0x4e, 0x31, 0x62, 0x6d, 0x64, 0x70, 0x62, 0x33,
738     0x52, 0x7a, 0x4c, 0x6d, 0x4e, 0x76, 0x62, 0x53, 0x39, 0x6a, 0x63, 0x6d, 0x77, 0x77, 0x50, 0x41,
739     0x59, 0x49, 0x4b, 0x77, 0x59, 0x42, 0x0a, 0x42, 0x51, 0x55, 0x48, 0x41, 0x51, 0x45, 0x45, 0x4d,
740     0x44, 0x41, 0x75, 0x4d, 0x43, 0x77, 0x47, 0x43, 0x43, 0x73, 0x47, 0x41, 0x51, 0x55, 0x46, 0x42,
741     0x7a, 0x41, 0x42, 0x68, 0x69, 0x42, 0x6f, 0x64, 0x48, 0x52, 0x77, 0x4f, 0x69, 0x38, 0x76, 0x62,
742     0x32, 0x4e, 0x7a, 0x63, 0x43, 0x31, 0x30, 0x5a, 0x58, 0x4e, 0x30, 0x4c, 0x6e, 0x4e, 0x68, 0x62,
743     0x58, 0x4e, 0x31, 0x62, 0x6d, 0x64, 0x70, 0x0a, 0x62, 0x33, 0x52, 0x7a, 0x4c, 0x6d, 0x4e, 0x76,
744     0x62, 0x54, 0x41, 0x4d, 0x42, 0x67, 0x67, 0x71, 0x68, 0x6b, 0x6a, 0x4f, 0x50, 0x51, 0x51, 0x44,
745     0x41, 0x67, 0x55, 0x41, 0x41, 0x30, 0x6b, 0x41, 0x4d, 0x45, 0x59, 0x43, 0x49, 0x51, 0x43, 0x33,
746     0x58, 0x30, 0x42, 0x61, 0x4f, 0x49, 0x6f, 0x63, 0x4b, 0x4f, 0x45, 0x65, 0x44, 0x46, 0x52, 0x6b,
747     0x63, 0x66, 0x30, 0x48, 0x76, 0x68, 0x68, 0x67, 0x0a, 0x73, 0x6c, 0x65, 0x49, 0x52, 0x32, 0x49,
748     0x62, 0x6d, 0x66, 0x34, 0x6e, 0x69, 0x52, 0x52, 0x55, 0x38, 0x41, 0x49, 0x68, 0x41, 0x4f, 0x4d,
749     0x44, 0x31, 0x77, 0x45, 0x62, 0x50, 0x67, 0x34, 0x70, 0x47, 0x77, 0x49, 0x79, 0x65, 0x77, 0x63,
750     0x61, 0x6b, 0x76, 0x72, 0x4e, 0x4b, 0x66, 0x44, 0x79, 0x2b, 0x4f, 0x4e, 0x43, 0x6e, 0x4e, 0x6e,
751     0x43, 0x59, 0x57, 0x4a, 0x37, 0x39, 0x35, 0x4b, 0x49, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45,
752     0x4e, 0x44, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d,
753     0x2d, 0x2d, 0x2d
754 };
755 int certChainLen = sizeof(certChain);
756
757 unsigned char serverCert[] = {
758     0x30, 0x82, 0x02, 0x39, 0x30, 0x82, 0x01, 0xdf, 0x02, 0x01, 0x01, 0x30, 0x0a, 0x06, 0x08, 0x2a,
759     0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, 0x7c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
760     0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
761     0x09, 0x53, 0x6f, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x74, 0x65, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03,
762     0x55, 0x04, 0x07, 0x0c, 0x08, 0x53, 0x6f, 0x6d, 0x65, 0x63, 0x69, 0x74, 0x79, 0x31, 0x0b, 0x30,
763     0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x42, 0x42, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03,
764     0x55, 0x04, 0x0b, 0x0c, 0x0d, 0x53, 0x65, 0x71, 0x75, 0x72, 0x69, 0x74, 0x79, 0x20, 0x50, 0x61,
765     0x72, 0x74, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x02, 0x6f, 0x62, 0x31,
766     0x14, 0x30, 0x12, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x05,
767     0x6f, 0x62, 0x40, 0x62, 0x62, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x38, 0x31, 0x35, 0x31,
768     0x33, 0x31, 0x31, 0x31, 0x37, 0x5a, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x35, 0x31, 0x32, 0x31, 0x33,
769     0x31, 0x31, 0x31, 0x37, 0x5a, 0x30, 0x81, 0xd4, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
770     0x06, 0x13, 0x02, 0x55, 0x41, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x03,
771     0x41, 0x73, 0x64, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x06, 0x47, 0x6f,
772     0x74, 0x68, 0x61, 0x6d, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x5a,
773     0x5a, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x08, 0x42, 0x65, 0x61, 0x6d,
774     0x54, 0x65, 0x61, 0x6d, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
775     0x01, 0x09, 0x01, 0x16, 0x0d, 0x72, 0x61, 0x69, 0x6c, 0x40, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
776     0x6f, 0x6d, 0x31, 0x32, 0x30, 0x30, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x29, 0x75, 0x75, 0x69,
777     0x64, 0x3a, 0x33, 0x32, 0x33, 0x32, 0x33, 0x32, 0x33, 0x32, 0x2d, 0x33, 0x32, 0x33, 0x32, 0x2d,
778     0x33, 0x32, 0x33, 0x32, 0x2d, 0x33, 0x32, 0x33, 0x32, 0x2d, 0x33, 0x32, 0x33, 0x32, 0x33, 0x32,
779     0x33, 0x32, 0x33, 0x32, 0x33, 0x32, 0x31, 0x34, 0x30, 0x32, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x0c,
780     0x2b, 0x75, 0x73, 0x65, 0x72, 0x69, 0x64, 0x3a, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37,
781     0x2d, 0x36, 0x37, 0x36, 0x37, 0x2d, 0x36, 0x37, 0x36, 0x37, 0x2d, 0x36, 0x37, 0x36, 0x37, 0x2d,
782     0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x30, 0x59, 0x30, 0x13,
783     0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
784     0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0xf7, 0x13, 0x5c, 0x73, 0x72, 0xce, 0x10, 0xe5, 0x09,
785     0x97, 0x9a, 0xf8, 0xf2, 0x70, 0xa6, 0x3d, 0x89, 0xf5, 0xc5, 0xe4, 0x44, 0xe2, 0x4a, 0xb6, 0x61,
786     0xa8, 0x12, 0x8d, 0xb4, 0xdc, 0x2b, 0x47, 0x84, 0x60, 0x0c, 0x25, 0x66, 0xe9, 0xe0, 0xe5, 0xac,
787     0x22, 0xbf, 0x15, 0xdc, 0x71, 0xb1, 0x88, 0x4f, 0x16, 0xbf, 0xc2, 0x77, 0x37, 0x76, 0x3f, 0xe0,
788     0x67, 0xc6, 0x1d, 0x23, 0xfe, 0x7c, 0x8b, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
789     0x04, 0x03, 0x02, 0x03, 0x48, 0x00, 0x30, 0x45, 0x02, 0x20, 0x47, 0xcc, 0x41, 0x8a, 0x27, 0xc7,
790     0xd0, 0xaa, 0xb4, 0xab, 0x85, 0xbf, 0x09, 0x4d, 0x06, 0xd7, 0x7e, 0x0d, 0x39, 0xf9, 0x36, 0xa1,
791     0x3d, 0x96, 0x23, 0xe2, 0x24, 0x64, 0x98, 0x63, 0x21, 0xba, 0x02, 0x21, 0x00, 0xe5, 0x8f, 0x7f,
792     0xf1, 0xa6, 0x82, 0x03, 0x6a, 0x18, 0x7a, 0x54, 0xe7, 0x0e, 0x25, 0x77, 0xd8, 0x46, 0xfa, 0x96,
793     0x8a, 0x7e, 0x14, 0xc4, 0xcb, 0x21, 0x32, 0x3e, 0x89, 0xd9, 0xba, 0x8c, 0x3f
794 };
795 int serverCertLen = sizeof(serverCert);
796
797 unsigned char serverPrivateKey[] = {
798     0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, 0x02, 0x51, 0xb5, 0x97, 0xb9, 0xe9, 0xd8, 0x8d, 0x66,
799     0x2b, 0x8a, 0xb3, 0x9c, 0x6a, 0xd2, 0xca, 0x18, 0x21, 0xb9, 0x87, 0x3d, 0xf5, 0x8e, 0xa2, 0x8d,
800     0x38, 0xf6, 0xb7, 0xd2, 0x76, 0x74, 0x99, 0xa0, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
801     0x03, 0x01, 0x07, 0xa1, 0x44, 0x03, 0x42, 0x00, 0x04, 0xf7, 0x13, 0x5c, 0x73, 0x72, 0xce, 0x10,
802     0xe5, 0x09, 0x97, 0x9a, 0xf8, 0xf2, 0x70, 0xa6, 0x3d, 0x89, 0xf5, 0xc5, 0xe4, 0x44, 0xe2, 0x4a,
803     0xb6, 0x61, 0xa8, 0x12, 0x8d, 0xb4, 0xdc, 0x2b, 0x47, 0x84, 0x60, 0x0c, 0x25, 0x66, 0xe9, 0xe0,
804     0xe5, 0xac, 0x22, 0xbf, 0x15, 0xdc, 0x71, 0xb1, 0x88, 0x4f, 0x16, 0xbf, 0xc2, 0x77, 0x37, 0x76,
805     0x3f, 0xe0, 0x67, 0xc6, 0x1d, 0x23, 0xfe, 0x7c, 0x8b
806 };
807
808 int serverPrivateKeyLen = sizeof(serverPrivateKey);
809
810 unsigned char caCert[] = {
811     0x30, 0x82, 0x02, 0x3e, 0x30, 0x82, 0x01, 0xe5, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00,
812     0x87, 0xa7, 0x68, 0x01, 0x7c, 0xe9, 0xf8, 0xf0, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce,
813     0x3d, 0x04, 0x03, 0x02, 0x30, 0x7c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
814     0x02, 0x55, 0x53, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x09, 0x53, 0x6f,
815     0x6d, 0x65, 0x73, 0x74, 0x61, 0x74, 0x65, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x07,
816     0x0c, 0x08, 0x53, 0x6f, 0x6d, 0x65, 0x63, 0x69, 0x74, 0x79, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03,
817     0x55, 0x04, 0x0a, 0x0c, 0x02, 0x42, 0x42, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0b,
818     0x0c, 0x0d, 0x53, 0x65, 0x71, 0x75, 0x72, 0x69, 0x74, 0x79, 0x20, 0x50, 0x61, 0x72, 0x74, 0x31,
819     0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x02, 0x6f, 0x62, 0x31, 0x14, 0x30, 0x12,
820     0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x05, 0x6f, 0x62, 0x40,
821     0x62, 0x62, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x37, 0x32, 0x35, 0x31, 0x31, 0x31, 0x36,
822     0x31, 0x31, 0x5a, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x35, 0x31, 0x35, 0x31, 0x31, 0x31, 0x36, 0x31,
823     0x31, 0x5a, 0x30, 0x7c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,
824     0x53, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x09, 0x53, 0x6f, 0x6d, 0x65,
825     0x73, 0x74, 0x61, 0x74, 0x65, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x08,
826     0x53, 0x6f, 0x6d, 0x65, 0x63, 0x69, 0x74, 0x79, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
827     0x0a, 0x0c, 0x02, 0x42, 0x42, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0d,
828     0x53, 0x65, 0x71, 0x75, 0x72, 0x69, 0x74, 0x79, 0x20, 0x50, 0x61, 0x72, 0x74, 0x31, 0x0b, 0x30,
829     0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x02, 0x6f, 0x62, 0x31, 0x14, 0x30, 0x12, 0x06, 0x09,
830     0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x05, 0x6f, 0x62, 0x40, 0x62, 0x62,
831     0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a,
832     0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x2e, 0xcf, 0xc3, 0xfa, 0x2e,
833     0x04, 0x11, 0x62, 0x34, 0x63, 0x6f, 0xdf, 0xb6, 0x67, 0xfb, 0x5a, 0x50, 0x8c, 0x15, 0x73, 0xc9,
834     0xc1, 0x57, 0x3a, 0x9e, 0xf8, 0xf4, 0xa8, 0x0c, 0x1a, 0xe9, 0x91, 0x51, 0x9d, 0x03, 0x26, 0x48,
835     0xaa, 0x46, 0x84, 0x12, 0x06, 0x2d, 0xfc, 0x66, 0xbe, 0x41, 0xed, 0xfd, 0xcd, 0x32, 0xa3, 0x9b,
836     0x34, 0xf2, 0xaa, 0x95, 0x1f, 0x8e, 0x5d, 0x49, 0x77, 0x80, 0xc2, 0xa3, 0x50, 0x30, 0x4e, 0x30,
837     0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x1e, 0x81, 0xc3, 0x62, 0xff, 0x8c,
838     0x5a, 0x98, 0x90, 0xac, 0x2c, 0xc3, 0x65, 0xb9, 0x3f, 0x8f, 0x04, 0x55, 0xfa, 0x7c, 0x30, 0x1f,
839     0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x1e, 0x81, 0xc3, 0x62, 0xff,
840     0x8c, 0x5a, 0x98, 0x90, 0xac, 0x2c, 0xc3, 0x65, 0xb9, 0x3f, 0x8f, 0x04, 0x55, 0xfa, 0x7c, 0x30,
841     0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0a, 0x06,
842     0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x47, 0x00, 0x30, 0x44, 0x02, 0x20,
843     0x1c, 0xa1, 0x55, 0xa8, 0x04, 0xbc, 0x5b, 0x00, 0xa8, 0xac, 0x2f, 0xe6, 0xb7, 0x3c, 0x7c, 0xf3,
844     0x7e, 0x93, 0xce, 0xe0, 0xdf, 0x6e, 0x36, 0xe4, 0x36, 0x20, 0xcb, 0x36, 0x9c, 0x13, 0x3b, 0xc4,
845     0x02, 0x20, 0x7f, 0x18, 0x13, 0x7d, 0x1b, 0x8c, 0xe3, 0x5b, 0xd9, 0xac, 0x74, 0x8c, 0xc0, 0xe9,
846     0xbf, 0x1b, 0x48, 0x6f, 0xb6, 0x6a, 0x45, 0x03, 0xa6, 0x5d, 0x4d, 0x65, 0xf7, 0x96, 0xa0, 0x08,
847     0x83, 0x7c
848 };
849 int caCertLen = sizeof(caCert);
850
851 unsigned char control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM[] = {
852     0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0x0d,
853     0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x74,
854     0x65, 0x78, 0x74, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x0d, 0x0a, 0x0d, 0x0a, 0x3c, 0x68, 0x32, 0x3e,
855     0x6d, 0x62, 0x65, 0x64, 0x20, 0x54, 0x4c, 0x53, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x65,
856     0x72, 0x76, 0x65, 0x72, 0x3c, 0x2f, 0x68, 0x32, 0x3e, 0x0d, 0x0a, 0x54, 0x45, 0x53, 0x54, 0x20,
857     0x4d, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x0d, 0x0a, 0x3c, 0x70, 0x3e, 0x53, 0x75, 0x63, 0x63,
858     0x65, 0x73, 0x73, 0x66, 0x75, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f,
859     0x6e, 0x20, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x54, 0x4c, 0x53, 0x2d, 0x45, 0x43, 0x44,
860     0x48, 0x45, 0x2d, 0x45, 0x43, 0x44, 0x53, 0x41, 0x2d, 0x57, 0x49, 0x54, 0x48, 0x2d, 0x41, 0x45,
861     0x53, 0x2d, 0x31, 0x32, 0x38, 0x2d, 0x43, 0x43, 0x4d, 0x3c, 0x2f, 0x70, 0x3e, 0x0d, 0x0a
862 };
863 int control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM);
864
865 unsigned char control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM_8[] = {
866     0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0x0d,
867     0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x74,
868     0x65, 0x78, 0x74, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x0d, 0x0a, 0x0d, 0x0a, 0x3c, 0x68, 0x32, 0x3e,
869     0x6d, 0x62, 0x65, 0x64, 0x20, 0x54, 0x4c, 0x53, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x65,
870     0x72, 0x76, 0x65, 0x72, 0x3c, 0x2f, 0x68, 0x32, 0x3e, 0x0d, 0x0a, 0x54, 0x45, 0x53, 0x54, 0x20,
871     0x4d, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x0d, 0x0a, 0x3c, 0x70, 0x3e, 0x53, 0x75, 0x63, 0x63,
872     0x65, 0x73, 0x73, 0x66, 0x75, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f,
873     0x6e, 0x20, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x54, 0x4c, 0x53, 0x2d, 0x45, 0x43, 0x44,
874     0x48, 0x45, 0x2d, 0x45, 0x43, 0x44, 0x53, 0x41, 0x2d, 0x57, 0x49, 0x54, 0x48, 0x2d, 0x41, 0x45,
875     0x53, 0x2d, 0x31, 0x32, 0x38, 0x2d, 0x43, 0x43, 0x4d, 0x2d, 0x38, 0x3c, 0x2f, 0x70, 0x3e, 0x0d,
876     0x0a
877 };
878 int control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM_8_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM_8);
879
880 unsigned char control_server_message_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256[] = {
881     0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0x0d,
882     0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x74,
883     0x65, 0x78, 0x74, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x0d, 0x0a, 0x0d, 0x0a, 0x3c, 0x68, 0x32, 0x3e,
884     0x6d, 0x62, 0x65, 0x64, 0x20, 0x54, 0x4c, 0x53, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x65,
885     0x72, 0x76, 0x65, 0x72, 0x3c, 0x2f, 0x68, 0x32, 0x3e, 0x0d, 0x0a, 0x54, 0x45, 0x53, 0x54, 0x20,
886     0x4d, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x0d, 0x0a, 0x3c, 0x70, 0x3e, 0x53, 0x75, 0x63, 0x63,
887     0x65, 0x73, 0x73, 0x66, 0x75, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f,
888     0x6e, 0x20, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x54, 0x4c, 0x53, 0x2d, 0x45, 0x43, 0x44,
889     0x48, 0x45, 0x2d, 0x45, 0x43, 0x44, 0x53, 0x41, 0x2d, 0x57, 0x49, 0x54, 0x48, 0x2d, 0x41, 0x45,
890     0x53, 0x2d, 0x31, 0x32, 0x38, 0x2d, 0x43, 0x42, 0x43, 0x2d, 0x53, 0x48, 0x41, 0x32, 0x35, 0x36,
891     0x3c, 0x2f, 0x70, 0x3e, 0x0d, 0x0a
892 };
893 int control_server_message_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256);
894
895 unsigned char control_server_message_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256[] = {
896     0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0x0d,
897     0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x74,
898     0x65, 0x78, 0x74, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x0d, 0x0a, 0x0d, 0x0a, 0x3c, 0x68, 0x32, 0x3e,
899     0x6d, 0x62, 0x65, 0x64, 0x20, 0x54, 0x4c, 0x53, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x65,
900     0x72, 0x76, 0x65, 0x72, 0x3c, 0x2f, 0x68, 0x32, 0x3e, 0x0d, 0x0a, 0x54, 0x45, 0x53, 0x54, 0x20,
901     0x4d, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x0d, 0x0a, 0x3c, 0x70, 0x3e, 0x53, 0x75, 0x63, 0x63,
902     0x65, 0x73, 0x73, 0x66, 0x75, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f,
903     0x6e, 0x20, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x54, 0x4c, 0x53, 0x2d, 0x45, 0x43, 0x44,
904     0x48, 0x45, 0x2d, 0x45, 0x43, 0x44, 0x53, 0x41, 0x2d, 0x57, 0x49, 0x54, 0x48, 0x2d, 0x41, 0x45,
905     0x53, 0x2d, 0x31, 0x32, 0x38, 0x2d, 0x47, 0x43, 0x4D, 0x2d, 0x53, 0x48, 0x41, 0x32, 0x35, 0x36,
906     0x3c, 0x2f, 0x70, 0x3e, 0x0d, 0x0a
907 };
908 int control_server_message_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256);
909
910 unsigned char control_server_message_ECDHE_ECDSA_WITH_AES_128_CBC_SHA[] = {
911     0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0x0d,
912     0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x74,
913     0x65, 0x78, 0x74, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x0d, 0x0a, 0x0d, 0x0a, 0x3c, 0x68, 0x32, 0x3e,
914     0x6d, 0x62, 0x65, 0x64, 0x20, 0x54, 0x4c, 0x53, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x65,
915     0x72, 0x76, 0x65, 0x72, 0x3c, 0x2f, 0x68, 0x32, 0x3e, 0x0d, 0x0a, 0x54, 0x45, 0x53, 0x54, 0x20,
916     0x4d, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x0d, 0x0a, 0x3c, 0x70, 0x3e, 0x53, 0x75, 0x63, 0x63,
917     0x65, 0x73, 0x73, 0x66, 0x75, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f,
918     0x6e, 0x20, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x54, 0x4c, 0x53, 0x2d, 0x45, 0x43, 0x44,
919     0x48, 0x45, 0x2d, 0x45, 0x43, 0x44, 0x53, 0x41, 0x2d, 0x57, 0x49, 0x54, 0x48, 0x2d, 0x41, 0x45,
920     0x53, 0x2d, 0x31, 0x32, 0x38, 0x2d, 0x43, 0x42, 0x43, 0x2d, 0x53, 0x48, 0x41, 0x3c, 0x2f, 0x70,
921     0x3e, 0x0d, 0x0a
922 };
923 int control_server_message_ECDHE_ECDSA_WITH_AES_128_CBC_SHA_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_128_CBC_SHA);
924
925 unsigned char control_client_message[] = {
926     0x47, 0x45, 0x54, 0x20, 0x2f, 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x0d, 0x0a,
927     0x0d, 0x0a
928 };
929 int control_client_message_len = sizeof(control_client_message);
930
931 unsigned char control_server_message_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384[] = {
932     0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0x0d,
933     0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x74,
934     0x65, 0x78, 0x74, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x0d, 0x0a, 0x0d, 0x0a, 0x3c, 0x68, 0x32, 0x3e,
935     0x6d, 0x62, 0x65, 0x64, 0x20, 0x54, 0x4c, 0x53, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x65,
936     0x72, 0x76, 0x65, 0x72, 0x3c, 0x2f, 0x68, 0x32, 0x3e, 0x0d, 0x0a, 0x54, 0x45, 0x53, 0x54, 0x20,
937     0x4d, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x0d, 0x0a, 0x3c, 0x70, 0x3e, 0x53, 0x75, 0x63, 0x63,
938     0x65, 0x73, 0x73, 0x66, 0x75, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f,
939     0x6e, 0x20, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x54, 0x4c, 0x53, 0x2d, 0x45, 0x43, 0x44,
940     0x48, 0x45, 0x2d, 0x45, 0x43, 0x44, 0x53, 0x41, 0x2d, 0x57, 0x49, 0x54, 0x48, 0x2d, 0x41, 0x45,
941     0x53, 0x2d, 0x32, 0x35, 0x36, 0x2d, 0x43, 0x42, 0x43, 0x2d, 0x53, 0x48, 0x41, 0x33, 0x38, 0x34,
942     0x3c, 0x2f, 0x70, 0x3e, 0x0d, 0x0a
943 };
944 int control_server_message_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384);
945
946 unsigned char control_server_message_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384[] = {
947     0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0x0d,
948     0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x74,
949     0x65, 0x78, 0x74, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x0d, 0x0a, 0x0d, 0x0a, 0x3c, 0x68, 0x32, 0x3e,
950     0x6d, 0x62, 0x65, 0x64, 0x20, 0x54, 0x4c, 0x53, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x65,
951     0x72, 0x76, 0x65, 0x72, 0x3c, 0x2f, 0x68, 0x32, 0x3e, 0x0d, 0x0a, 0x54, 0x45, 0x53, 0x54, 0x20,
952     0x4d, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x0d, 0x0a, 0x3c, 0x70, 0x3e, 0x53, 0x75, 0x63, 0x63,
953     0x65, 0x73, 0x73, 0x66, 0x75, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f,
954     0x6e, 0x20, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x54, 0x4c, 0x53, 0x2d, 0x45, 0x43, 0x44,
955     0x48, 0x45, 0x2d, 0x45, 0x43, 0x44, 0x53, 0x41, 0x2d, 0x57, 0x49, 0x54, 0x48, 0x2d, 0x41, 0x45,
956     0x53, 0x2d, 0x32, 0x35, 0x36, 0x2d, 0x47, 0x43, 0x4D, 0x2d, 0x53, 0x48, 0x41, 0x33, 0x38, 0x34,
957     0x3c, 0x2f, 0x70, 0x3e, 0x0d, 0x0a
958 };
959 int control_server_message_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384);
960
961 static void error(const char *msg)
962 {
963     perror(msg);
964     exit(0);
965 }
966
967 static int sockfd, newsockfd;
968
969 static void socketConnect()
970 {
971     int portno;
972     struct sockaddr_in serv_addr;
973     struct hostent *server;
974
975     portno = SERVER_PORT;
976     sockfd = socket(AF_INET, SOCK_STREAM, 0);
977     if (sockfd < 0)
978         error("ERROR opening socket");
979     server = gethostbyname(SERVER_NAME);
980     if (server == NULL) {
981         fprintf(stderr,"ERROR, no such host\n");
982         exit(0);
983     }
984     //memset((char *) &serv_addr, sizeof(serv_addr));
985     memset((void*)&serv_addr, 0, sizeof(serv_addr));
986     serv_addr.sin_family = AF_INET;
987     memcpy((char *)server->h_addr,
988          (char *)&serv_addr.sin_addr.s_addr,
989          server->h_length);
990     serv_addr.sin_port = htons(portno);
991     if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
992         error("ERROR connecting");
993 }
994
995 static ssize_t CATCPPacketSendCB(CAEndpoint_t *, const void *buf, size_t buflen)
996 {
997     int n;
998     n = write(sockfd, buf, buflen);
999     if (n < 0)
1000          error("ERROR writing to socket");
1001     return n;
1002 }
1003
1004 char msg[256] = {0}; size_t msglen = 0;
1005 static void CATCPPacketReceivedCB(const CASecureEndpoint_t *, const void *data, size_t dataLength)
1006 {
1007     memcpy(msg, data, dataLength);
1008     msglen = dataLength;
1009 }
1010
1011 static void PacketReceive(unsigned char *data, int * datalen)
1012 {
1013     int n;
1014     char buffer[2048] = {'\0'};
1015     n = read(sockfd, buffer, 5);
1016     if ((buffer[0] == 0x16 || buffer[0] == 0x14 || buffer[0] == 0x17 || buffer[0] == 0x15)
1017         && buffer[1] == 0x03 && buffer[2] == 0x03)
1018     {
1019         int tlslen = (unsigned char)buffer[3] * 0x100 + (unsigned char)buffer[4];
1020         n = read(sockfd, buffer + 5, tlslen);
1021     }
1022
1023     if (n < 0)
1024          error("ERROR reading from socket");
1025
1026     *datalen = n + 5;
1027     memcpy(data, buffer, *datalen);
1028 }
1029
1030 static void socketClose()
1031 {
1032     close(sockfd);
1033 }
1034
1035 static void infoCallback_that_loads_x509(PkiInfo_t * inf)
1036 {
1037     inf->crt.data = (uint8_t*)serverCert;
1038     inf->crt.len = sizeof(serverCert);
1039     inf->key.data = (uint8_t*)serverPrivateKey;
1040     inf->key.len = sizeof(serverPrivateKey);
1041     inf->ca.data = (uint8_t*)caCert;
1042     inf->ca.len = sizeof(caCert);
1043     inf->crl.data = NULL;
1044     inf->crl.len = 0;
1045 }
1046
1047 static void socketOpen_server()
1048 {
1049     int portno;
1050     struct sockaddr_in serv_addr, cli_addr;
1051     socklen_t clilen;
1052
1053     portno = SERVER_PORT;
1054     sockfd = socket(AF_INET, SOCK_STREAM, 0);
1055     if (sockfd < 0)
1056         error("\nERROR opening socket");
1057     //bzero((char *) &serv_addr, sizeof(serv_addr));
1058     memset((void*)&serv_addr, 0, sizeof(serv_addr));
1059     serv_addr.sin_family = AF_INET;
1060     serv_addr.sin_addr.s_addr = INADDR_ANY;
1061     serv_addr.sin_port = htons(portno);
1062     if (bind(sockfd, (struct sockaddr *) &serv_addr,
1063               sizeof(serv_addr)) < 0)
1064               error("\nERROR on binding");
1065     listen(sockfd,5);
1066     clilen = sizeof(cli_addr);
1067     newsockfd = accept(sockfd,
1068                  (struct sockaddr *) &cli_addr,
1069                  &clilen);
1070     if (newsockfd < 0)
1071           error("\nERROR on accept");
1072 }
1073
1074 static ssize_t CATCPPacketSendCB_server(CAEndpoint_t *, const void *buf, size_t buflen)
1075 {
1076     int n;
1077     n = write(newsockfd,buf,buflen);
1078     if (n < 0)
1079          error("ERROR writing to socket");
1080     return n;
1081 }
1082
1083 static void CATCPPacketReceivedCB_server(const CASecureEndpoint_t *, const void *data, size_t dataLength)
1084 {
1085     memcpy(msg, data, dataLength);
1086     msglen = dataLength;
1087 }
1088 static void PacketReceive_server(unsigned char *data, int * datalen)
1089 {
1090     int n;
1091     char buffer[2048] = {'\0'};
1092     n = read(newsockfd, buffer, 5);
1093
1094     if (buffer[0] == 0x16 || buffer[0] == 0x14 || buffer[0] == 0x17 || buffer[0] == 0x15)
1095     {
1096         int tlslen = (unsigned char)buffer[3] * 0x100 + (unsigned char)buffer[4];
1097         n = read(newsockfd, buffer + 5, tlslen);
1098     }
1099
1100     if (n < 0)
1101          error("\nERROR reading from socket");
1102
1103     *datalen = n + 5;
1104     memcpy(data, buffer, *datalen);
1105 }
1106
1107 static void socketClose_server()
1108 {
1109     close(newsockfd);
1110     close(sockfd);
1111 }
1112
1113 static void clutch(bool * list)
1114 {
1115     list[1] = true;
1116 }
1117
1118 const unsigned char IDENTITY[] = ("6767676767676767");
1119 const unsigned char RS_CLIENT_PSK[] = ("AAAAAAAAAAAAAAAA");
1120 static int32_t GetDtlsPskCredentials( CADtlsPskCredType_t,
1121               const unsigned char *, size_t,
1122               unsigned char *result, size_t)
1123 {
1124     int32_t ret = -1;
1125
1126     if (NULL == result)
1127     {
1128         return ret;
1129     }
1130     memcpy(result, IDENTITY, sizeof(IDENTITY));
1131     ret = sizeof(IDENTITY);
1132
1133     return ret;
1134 }
1135
1136 /* **************************
1137  *
1138  *
1139  * MbedTLS client routine
1140  *
1141  *
1142  * *************************/
1143
1144 #if !defined(MBEDTLS_CONFIG_FILE)
1145 #include "mbedtls/config.h"
1146 #else
1147 #include MBEDTLS_CONFIG_FILE
1148 #endif
1149
1150 #if defined(MBEDTLS_PLATFORM_C)
1151 #include "mbedtls/platform.h"
1152 #else
1153 #include <stdio.h>
1154 #include <stdlib.h>
1155 #define mbedtls_fprintf    fprintf
1156 #define mbedtls_printf     printf
1157 #endif
1158
1159 #if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) ||  \
1160     !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_CLI_C) || \
1161     !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_RSA_C) ||         \
1162     !defined(MBEDTLS_PEM_PARSE_C) ||!defined(MBEDTLS_CTR_DRBG_C) || \
1163     !defined(MBEDTLS_X509_CRT_PARSE_C)
1164 static int client( void )
1165 {
1166     mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_ENTROPY_C and/or "
1167            "MBEDTLS_SSL_TLS_C and/or MBEDTLS_SSL_CLI_C and/or "
1168            "MBEDTLS_NET_C and/or MBEDTLS_RSA_C and/or "
1169            "MBEDTLS_CTR_DRBG_C and/or MBEDTLS_X509_CRT_PARSE_C "
1170            "not defined.\n");
1171     return( 0 );
1172 }
1173 #else
1174
1175 #include "mbedtls/net_sockets.h"
1176 #include "mbedtls/debug.h"
1177 #include "mbedtls/ssl.h"
1178 #include "mbedtls/entropy.h"
1179 #include "mbedtls/ctr_drbg.h"
1180 #include "mbedtls/error.h"
1181
1182
1183 #include <string.h>
1184
1185 #define DEBUG_LEVEL (0)
1186
1187 static void my_debug_client( void *ctx, int level,
1188                       const char *file, int line,
1189                       const char *str )
1190 {
1191     ((void) level);
1192
1193     mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
1194     fflush(  (FILE *) ctx  );
1195 }
1196
1197 static void * client(void *)
1198 {
1199     int ret, len;
1200     mbedtls_net_context server_fd;
1201     uint32_t flags;
1202     unsigned char buf[1024];
1203     const char *pers = "ssl_client1";
1204
1205     mbedtls_entropy_context entropy;
1206     mbedtls_ctr_drbg_context ctr_drbg;
1207     mbedtls_ssl_context ssl;
1208     mbedtls_ssl_config conf;
1209     mbedtls_x509_crt cacert;
1210     mbedtls_x509_crt owncert;
1211     mbedtls_pk_context pkey;
1212
1213     /*
1214      * 0. Initialize the RNG and the session data
1215      */
1216     mbedtls_net_init( &server_fd );
1217     mbedtls_ssl_init( &ssl );
1218     mbedtls_ssl_config_init( &conf );
1219     mbedtls_x509_crt_init( &cacert );
1220     mbedtls_ctr_drbg_init( &ctr_drbg );
1221     mbedtls_pk_init( &pkey );
1222
1223     mbedtls_printf( "\n  . Seeding the random number generator..." );
1224     fflush( stdout );
1225
1226     mbedtls_entropy_init( &entropy );
1227     if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy,
1228                                (const unsigned char *) pers,
1229                                strlen( pers ) ) ) != 0 )
1230     {
1231         mbedtls_printf( " failed\n  ! mbedtls_ctr_drbg_seed returned %d\n", ret );
1232         goto exit;
1233     }
1234
1235     mbedtls_printf( " ok\n" );
1236
1237     /*
1238      * 0. Initialize certificates
1239      */
1240     mbedtls_printf( "  . Loading the CA root certificate ..." );
1241     fflush( stdout );
1242     ret = mbedtls_x509_crt_parse( &cacert, (const unsigned char *) caCert, caCertLen );
1243     if( ret < 0 )
1244     {
1245         mbedtls_printf( " failed\n  !  mbedtls_x509_crt_parse caCert returned -0x%x\n\n", -ret );
1246         goto exit;
1247     }
1248     ret = mbedtls_x509_crt_parse( &owncert, (const unsigned char *) serverCert, serverCertLen );
1249     if( ret < 0 )
1250     {
1251         mbedtls_printf( " failed\n  !  mbedtls_x509_crt_parse serverCert returned -0x%x\n\n", -ret );
1252         goto exit;
1253     }
1254     ret =  mbedtls_pk_parse_key( &pkey, (const unsigned char *) serverPrivateKey,
1255                                                                 serverPrivateKeyLen, NULL, 0 );
1256     if( ret < 0 )
1257     {
1258         mbedtls_printf( " failed\n  !  mbedtls_pk_parse_key returned -0x%x\n\n", -ret );
1259         goto exit;
1260     }
1261
1262     mbedtls_printf( " ok (%d skipped)\n", ret );
1263
1264     /*
1265      * 1. Start the connection
1266      */
1267     mbedtls_printf( "  . Connecting to tcp/%s/%s...", SERVER_NAME, "SERVER_PORT" );
1268     fflush( stdout );
1269
1270     if( ( ret = mbedtls_net_connect( &server_fd, "127.0.0.1",
1271                                          "4433", MBEDTLS_NET_PROTO_TCP ) ) != 0 )
1272     {
1273         mbedtls_printf( " failed\n  ! mbedtls_net_connect returned %d\n\n", ret );
1274         goto exit;
1275     }
1276
1277     mbedtls_printf( " ok\n" );
1278
1279     /*
1280      * 2. Setup stuff
1281      */
1282     mbedtls_printf( "  . Setting up the SSL/TLS structure..." );
1283     fflush( stdout );
1284
1285     if( ( ret = mbedtls_ssl_config_defaults( &conf,
1286                     MBEDTLS_SSL_IS_CLIENT,
1287                     MBEDTLS_SSL_TRANSPORT_STREAM,
1288                     MBEDTLS_SSL_PRESET_DEFAULT ) ) != 0 )
1289     {
1290         mbedtls_printf( " failed\n  ! mbedtls_ssl_config_defaults returned %d\n\n", ret );
1291         goto exit;
1292     }
1293
1294     mbedtls_printf( " ok\n" );
1295
1296     /* OPTIONAL is not optimal for security,
1297      * but makes interop easier in this simplified example */
1298     mbedtls_ssl_conf_authmode( &conf, MBEDTLS_SSL_VERIFY_OPTIONAL );
1299     mbedtls_ssl_conf_ca_chain( &conf, &cacert, NULL );
1300     mbedtls_ssl_conf_own_cert( &conf, &owncert, &pkey );
1301     mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg );
1302     mbedtls_ssl_conf_dbg( &conf, my_debug_client, stdout );
1303
1304     if( ( ret = mbedtls_ssl_setup( &ssl, &conf ) ) != 0 )
1305     {
1306         mbedtls_printf( " failed\n  ! mbedtls_ssl_setup returned %d\n\n", ret );
1307         goto exit;
1308     }
1309
1310     if( ( ret = mbedtls_ssl_set_hostname( &ssl, "mbed TLS Server 1" ) ) != 0 )
1311     {
1312         mbedtls_printf( " failed\n  ! mbedtls_ssl_set_hostname returned %d\n\n", ret );
1313         goto exit;
1314     }
1315
1316     mbedtls_ssl_set_bio( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL );
1317
1318     /*
1319      * 4. Handshake
1320      */
1321     mbedtls_printf( "  . Performing the SSL/TLS handshake..." );
1322     fflush( stdout );
1323
1324     while( ( ret = mbedtls_ssl_handshake( &ssl ) ) != 0 )
1325     {
1326         if( ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE )
1327         {
1328             mbedtls_printf( " failed\n  ! mbedtls_ssl_handshake returned -0x%x\n\n", -ret );
1329             goto exit;
1330         }
1331     }
1332
1333     mbedtls_printf( " ok\n" );
1334
1335     /*
1336      * 5. Verify the server certificate
1337      */
1338     mbedtls_printf( "  . Verifying peer X.509 certificate..." );
1339
1340     /* In real life, we probably want to bail out when ret != 0 */
1341     if( ( flags = mbedtls_ssl_get_verify_result( &ssl ) ) != 0 )
1342     {
1343         char vrfy_buf[512];
1344
1345         mbedtls_printf( " failed\n" );
1346
1347         mbedtls_x509_crt_verify_info( vrfy_buf, sizeof( vrfy_buf ), "  ! ", flags );
1348
1349         mbedtls_printf( "%s\n", vrfy_buf );
1350     }
1351     else
1352         mbedtls_printf( " ok\n" );
1353
1354     /*
1355      * 3. Write the GET request
1356      */
1357     mbedtls_printf( "  > Write to server:" );
1358     fflush( stdout );
1359
1360     len = sprintf( (char *) buf, GET_REQUEST );
1361
1362     while( ( ret = mbedtls_ssl_write( &ssl, buf, len ) ) <= 0 )
1363     {
1364         if( ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE )
1365         {
1366             mbedtls_printf( " failed\n  ! mbedtls_ssl_write returned %d\n\n", ret );
1367             goto exit;
1368         }
1369     }
1370
1371     len = ret;
1372     mbedtls_printf( " %d bytes written\n\n%s", len, (char *) buf );
1373
1374     /*
1375      * 7. Read the HTTP response
1376      */
1377     mbedtls_printf( "  < Read from server:" );
1378     fflush( stdout );
1379
1380     do
1381     {
1382         len = sizeof( buf ) - 1;
1383         memset( buf, 0, sizeof( buf ) );
1384         ret = mbedtls_ssl_read( &ssl, buf, len );
1385
1386         if( ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE )
1387             continue;
1388
1389         if( ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY )
1390             break;
1391
1392         if( ret < 0 )
1393         {
1394             mbedtls_printf( "failed\n  ! mbedtls_ssl_read returned %d\n\n", ret );
1395             break;
1396         }
1397
1398         if( ret == 0 )
1399         {
1400             mbedtls_printf( "\n\nEOF\n\n" );
1401             break;
1402         }
1403
1404         len = ret;
1405         mbedtls_printf( " %d bytes read\n\n%s", len, (char *) buf );
1406     }
1407     while( 1 );
1408
1409     mbedtls_ssl_close_notify( &ssl );
1410
1411 exit:
1412
1413 #ifdef MBEDTLS_ERROR_C
1414     if( ret != 0 )
1415     {
1416         char error_buf[100];
1417         mbedtls_strerror( ret, error_buf, 100 );
1418         mbedtls_printf("Last error was: %d - %s\n\n", ret, error_buf );
1419     }
1420 #endif
1421
1422     mbedtls_net_free( &server_fd );
1423
1424     mbedtls_x509_crt_free( &cacert );
1425     mbedtls_ssl_free( &ssl );
1426     mbedtls_ssl_config_free( &conf );
1427     mbedtls_ctr_drbg_free( &ctr_drbg );
1428     mbedtls_entropy_free( &entropy );
1429
1430     return NULL;
1431 }
1432 #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_SSL_TLS_C &&
1433           MBEDTLS_SSL_CLI_C && MBEDTLS_NET_C && MBEDTLS_RSA_C &&
1434           MBEDTLS_PEM_PARSE_C && MBEDTLS_CTR_DRBG_C &&
1435           MBEDTLS_X509_CRT_PARSE_C */
1436
1437 /* **************************
1438  *
1439  *
1440  * MbedTLS server routine
1441  *
1442  *
1443  * *************************/
1444
1445 #if !defined(MBEDTLS_CONFIG_FILE)
1446 #include "mbedtls/config.h"
1447 #else
1448 #include MBEDTLS_CONFIG_FILE
1449 #endif
1450
1451 #if defined(MBEDTLS_PLATFORM_C)
1452 #include "mbedtls/platform.h"
1453 #else
1454 #include <stdio.h>
1455 #include <stdlib.h>
1456 #define mbedtls_fprintf    fprintf
1457 #define mbedtls_printf     printf
1458 #endif
1459
1460 #if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_PEM_PARSE_C)|| \
1461     !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_SSL_TLS_C) || \
1462     !defined(MBEDTLS_SSL_SRV_C) || !defined(MBEDTLS_NET_C) ||     \
1463     !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_CTR_DRBG_C) ||    \
1464     !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_FS_IO) 
1465
1466 /* int */void * server( void )
1467 {
1468     mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_ENTROPY_C "
1469            "and/or MBEDTLS_SSL_TLS_C and/or MBEDTLS_SSL_SRV_C and/or "
1470            "MBEDTLS_NET_C and/or MBEDTLS_RSA_C and/or "
1471            "MBEDTLS_CTR_DRBG_C and/or MBEDTLS_X509_CRT_PARSE_C "
1472            "and/or MBEDTLS_PEM_PARSE_C not defined.\n");
1473     return(/* 0 */);
1474 }
1475 #else
1476
1477 #include <stdlib.h>
1478 #include <string.h>
1479
1480 #include "mbedtls/entropy.h"
1481 #include "mbedtls/ctr_drbg.h"
1482 #include "mbedtls/x509.h"
1483 #include "mbedtls/ssl.h"
1484 #include "mbedtls/net_sockets.h"
1485 #include "mbedtls/error.h"
1486 #include "mbedtls/debug.h"
1487
1488 #if defined(MBEDTLS_SSL_CACHE_C)
1489 #include "mbedtls/ssl_cache.h"
1490 #endif
1491
1492 #define HTTP_RESPONSE \
1493     "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n" \
1494     "<h2>mbed TLS Test Server</h2>\r\n" \
1495     "TEST MESSAGE\r\n" \
1496     "<p>Successful connection using: %s</p>\r\n"
1497
1498 #define DEBUG_LEVEL (0)
1499
1500 static int mbedtls_entropy_func_clutch(void *, unsigned char *output, size_t len)
1501 {
1502     for (uint32_t i = 0; i < len; i++) output[i] = 0x11;
1503     return 0;
1504 }
1505
1506 static void my_debug( void *ctx, int level,
1507                       const char *file, int line,
1508                       const char *str )
1509 {
1510     ((void) level);
1511
1512     mbedtls_fprintf((FILE *) ctx, "%s:%04d: %s", file, line, str);
1513     fflush(  (FILE *) ctx  );
1514 }
1515
1516 static void * server(void *)
1517 {
1518     int ret, len;
1519     mbedtls_net_context listen_fd, client_fd;
1520     unsigned char buf[1024];
1521     const char *pers = "ssl_server";
1522
1523     mbedtls_entropy_context entropy;
1524     mbedtls_ctr_drbg_context ctr_drbg;
1525     mbedtls_ssl_context ssl;
1526     mbedtls_ssl_config conf;
1527     mbedtls_x509_crt srvcert;
1528     mbedtls_pk_context pkey;
1529 #if defined(MBEDTLS_SSL_CACHE_C)
1530     mbedtls_ssl_cache_context cache;
1531 #endif
1532
1533     mbedtls_net_init( &listen_fd );
1534     mbedtls_net_init( &client_fd );
1535     mbedtls_ssl_init( &ssl );
1536     mbedtls_ssl_config_init( &conf );
1537 #if defined(MBEDTLS_SSL_CACHE_C)
1538     mbedtls_ssl_cache_init( &cache );
1539 #endif
1540     mbedtls_x509_crt_init( &srvcert );
1541     mbedtls_pk_init( &pkey );
1542     mbedtls_entropy_init( &entropy );
1543     mbedtls_ctr_drbg_init( &ctr_drbg );
1544
1545 #if defined(MBEDTLS_DEBUG_C)
1546     mbedtls_debug_set_threshold( DEBUG_LEVEL );
1547 #endif
1548
1549     /*
1550      * 1. Load the certificates and private RSA key
1551      */
1552     mbedtls_printf( "\n  . Loading the server cert. and key..." );
1553     fflush( stdout );
1554
1555     /*
1556      * This demonstration program uses embedded test certificates.
1557      * Instead, you may want to use mbedtls_x509_crt_parse_file() to read the
1558      * server and CA certificates, as well as mbedtls_pk_parse_keyfile().
1559      */
1560     ret = mbedtls_x509_crt_parse( &srvcert, (const unsigned char *) serverCert, serverCertLen );
1561     if( ret != 0 )
1562     {
1563         mbedtls_printf( " failed\n  !  mbedtls_x509_crt_parse returned %d\n\n", ret );
1564         goto exit;
1565     }
1566
1567     ret = mbedtls_x509_crt_parse( &srvcert, (const unsigned char *) caCert, caCertLen );
1568     if( ret != 0 )
1569     {
1570         mbedtls_printf( " failed\n  !  mbedtls_x509_crt_parse returned %d\n\n", ret );
1571         goto exit;
1572     }
1573
1574     ret =  mbedtls_pk_parse_key( &pkey, (const unsigned char *) serverPrivateKey,
1575                                                                 serverPrivateKeyLen, NULL, 0 );
1576     if( ret != 0 )
1577     {
1578         mbedtls_printf( " failed\n  !  mbedtls_pk_parse_key returned %d\n\n", ret );
1579         goto exit;
1580     }
1581
1582     mbedtls_printf( " ok\n" );
1583
1584     /*
1585      * 2. Setup the listening TCP socket
1586      */
1587     mbedtls_printf( "  . Bind on https://localhost:4433/ ..." );
1588     fflush( stdout );
1589
1590     if( ( ret = mbedtls_net_bind( &listen_fd, NULL, "4433", MBEDTLS_NET_PROTO_TCP ) ) != 0 )
1591     {
1592         mbedtls_printf( " failed\n  ! mbedtls_net_bind returned %d\n\n", ret );
1593         goto exit;
1594     }
1595
1596     mbedtls_printf( " ok\n" );
1597
1598     /*
1599      * 3. Seed the RNG
1600      */
1601     mbedtls_printf( "  . Seeding the random number generator..." );
1602     fflush( stdout );
1603
1604     if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func_clutch, &entropy,
1605                                (const unsigned char *) pers,
1606                                strlen( pers ) ) ) != 0 )
1607     {
1608         mbedtls_printf( " failed\n  ! mbedtls_ctr_drbg_seed returned %d\n", ret );
1609     }
1610
1611     mbedtls_printf( " ok\n" );
1612
1613     /*
1614      * 4. Setup stuff
1615      */
1616     mbedtls_printf( "  . Setting up the SSL data...." );
1617     fflush( stdout );
1618
1619     if( ( ret = mbedtls_ssl_config_defaults( &conf,
1620                     MBEDTLS_SSL_IS_SERVER,
1621                     MBEDTLS_SSL_TRANSPORT_STREAM,
1622                     MBEDTLS_SSL_PRESET_DEFAULT ) ) != 0 )
1623     {
1624         mbedtls_printf( " failed\n  ! mbedtls_ssl_config_defaults returned %d\n\n", ret );
1625         goto exit;
1626     }
1627
1628     mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg );
1629     mbedtls_ssl_conf_dbg( &conf, my_debug, stdout );
1630
1631 #if defined(MBEDTLS_SSL_CACHE_C)
1632     mbedtls_ssl_conf_session_cache( &conf, &cache,
1633                                    mbedtls_ssl_cache_get,
1634                                    mbedtls_ssl_cache_set );
1635 #endif
1636
1637     mbedtls_ssl_conf_ca_chain( &conf, srvcert.next, NULL );
1638     if( ( ret = mbedtls_ssl_conf_own_cert( &conf, &srvcert, &pkey ) ) != 0 )
1639     {
1640         mbedtls_printf( " failed\n  ! mbedtls_ssl_conf_own_cert returned %d\n\n", ret );
1641         goto exit;
1642     }
1643
1644     if( ( ret = mbedtls_ssl_setup( &ssl, &conf ) ) != 0 )
1645     {
1646         mbedtls_printf( " failed\n  ! mbedtls_ssl_setup returned %d\n\n", ret );
1647         goto exit;
1648     }
1649
1650     mbedtls_printf( " ok\n" );
1651
1652 reset:
1653 #ifdef MBEDTLS_ERROR_C
1654     if( ret != 0 )
1655     {
1656         char error_buf[100];
1657         mbedtls_strerror( ret, error_buf, 100 );
1658         mbedtls_printf("Last error was: %d - %s\n\n", ret, error_buf );
1659     }
1660 #endif
1661
1662     mbedtls_net_free( &client_fd );
1663
1664     mbedtls_ssl_session_reset( &ssl );
1665
1666     /*
1667      * 3. Wait until a client connects
1668      */
1669     mbedtls_printf( "  . Waiting for a remote connection ..." );
1670     fflush( stdout );
1671
1672     if( ( ret = mbedtls_net_accept( &listen_fd, &client_fd,
1673                                     NULL, 0, NULL ) ) != 0 )
1674     {
1675         mbedtls_printf( " failed\n  ! mbedtls_net_accept returned %d\n\n", ret );
1676         goto exit;
1677     }
1678
1679     mbedtls_ssl_set_bio( &ssl, &client_fd, mbedtls_net_send, mbedtls_net_recv, NULL );
1680
1681     mbedtls_printf( " ok\n" );
1682
1683     /*
1684      * 5. Handshake
1685      */
1686     mbedtls_printf( "  . Performing the SSL/TLS handshake..." );
1687     fflush( stdout );
1688
1689     while( ( ret = mbedtls_ssl_handshake( &ssl ) ) != 0 )
1690     {
1691         if( ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE )
1692         {
1693             mbedtls_printf( " failed\n  ! mbedtls_ssl_handshake returned %d\n\n", ret );
1694             goto exit;
1695         }
1696     }
1697
1698     mbedtls_printf( " ok\n" );
1699
1700     /*
1701      * 6. Read the HTTP Request
1702      */
1703     mbedtls_printf( "  < Read from client:" );
1704     fflush( stdout );
1705
1706     do
1707     {
1708         len = sizeof( buf ) - 1;
1709         memset( buf, 0, sizeof( buf ) );
1710         ret = mbedtls_ssl_read( &ssl, buf, len );
1711
1712         if( ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE )
1713             continue;
1714
1715         if( ret <= 0 )
1716         {
1717             switch( ret )
1718             {
1719                 case MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY:
1720                     mbedtls_printf( " connection was closed gracefully\n" );
1721                     break;
1722
1723                 case MBEDTLS_ERR_NET_CONN_RESET:
1724                     mbedtls_printf( " connection was reset by peer\n" );
1725                     break;
1726
1727                 default:
1728                     mbedtls_printf( " mbedtls_ssl_read returned -0x%x\n", -ret );
1729                     break;
1730             }
1731
1732             break;
1733         }
1734
1735         len = ret;
1736         mbedtls_printf( " %d bytes read\n\n%s", len, (char *) buf );
1737
1738         if( ret > 0 )
1739             break;
1740     }
1741     while( 1 );
1742
1743     /*
1744      * 7. Write the 200 Response
1745      */
1746     mbedtls_printf( "  > Write to client:" );
1747
1748     fflush( stdout );
1749
1750     len = sprintf( (char *) buf, HTTP_RESPONSE,
1751                    mbedtls_ssl_get_ciphersuite( &ssl ) );
1752
1753     while( ( ret = mbedtls_ssl_write( &ssl, buf, len ) ) <= 0 )
1754     {
1755         if( ret == MBEDTLS_ERR_NET_CONN_RESET )
1756         {
1757             mbedtls_printf( " failed\n  ! peer closed the connection\n\n" );
1758             goto reset;
1759         }
1760
1761         if( ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE )
1762         {
1763             mbedtls_printf( " failed\n  ! mbedtls_ssl_write returned %d\n\n", ret );
1764             goto exit;
1765         }
1766     }
1767
1768     len = ret;
1769     mbedtls_printf( " %d bytes written\n\n%s\n", len, (char *) buf );
1770
1771     mbedtls_printf( "  . Closing the connection..." );
1772
1773     while( ( ret = mbedtls_ssl_close_notify( &ssl ) ) < 0 )
1774     {
1775         if( ret != MBEDTLS_ERR_SSL_WANT_READ &&
1776             ret != MBEDTLS_ERR_SSL_WANT_WRITE )
1777         {
1778             mbedtls_printf( " failed\n  ! mbedtls_ssl_close_notify returned %d\n\n", ret );
1779             goto exit;
1780         }
1781     }
1782
1783     mbedtls_printf( " ok\n" );
1784
1785     ret = 0;
1786     goto exit;
1787
1788 exit:
1789
1790 #ifdef MBEDTLS_ERROR_C
1791     if( ret != 0 )
1792     {
1793         char error_buf[100];
1794         mbedtls_strerror( ret, error_buf, 100 );
1795         mbedtls_printf("Last error was: %d - %s\n\n", ret, error_buf );
1796     }
1797 #endif
1798
1799     mbedtls_net_free( &client_fd );
1800     mbedtls_net_free( &listen_fd );
1801
1802     mbedtls_x509_crt_free( &srvcert );
1803     mbedtls_pk_free( &pkey );
1804     mbedtls_ssl_free( &ssl );
1805     mbedtls_ssl_config_free( &conf );
1806 #if defined(MBEDTLS_SSL_CACHE_C)
1807     mbedtls_ssl_cache_free( &cache );
1808 #endif
1809     mbedtls_ctr_drbg_free( &ctr_drbg );
1810     mbedtls_entropy_free( &entropy );
1811
1812 #if defined(_WIN32)
1813     mbedtls_printf( "  Press Enter to exit this program.\n" );
1814     fflush( stdout );
1815 #endif
1816
1817     return NULL;
1818 }
1819 #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C &&
1820           MBEDTLS_SSL_TLS_C && MBEDTLS_SSL_SRV_C && MBEDTLS_NET_C &&
1821           MBEDTLS_RSA_C && MBEDTLS_CTR_DRBG_C && MBEDTLS_X509_CRT_PARSE_C
1822           && MBEDTLS_FS_IO && MBEDTLS_PEM_PARSE_C */
1823
1824 /* **************************
1825  *
1826  *
1827  * CAinitSslAdapter test
1828  *
1829  *
1830  * *************************/
1831
1832 static int testCAinitSslAdapter()
1833 {
1834     int ret = 0;
1835
1836     CAEndpoint_t serverAddr;
1837     serverAddr.adapter = CA_ADAPTER_IP;
1838     serverAddr.flags = CA_SECURE;
1839     serverAddr.port = 4433;
1840     char addr[] = {0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x00}; // 127.0.0.1
1841     memcpy(serverAddr.addr, addr, sizeof(addr));
1842     serverAddr.ifindex = 0;
1843
1844     ret = CAinitSslAdapter();
1845     if (ret != 0 ||
1846         &g_caSslContext == NULL ||
1847         &g_caSslContext->crt == NULL ||
1848         &g_caSslContext->pkey == NULL ||
1849         &g_caSslContext->clientTlsConf == NULL ||
1850         &g_caSslContext->serverTlsConf == NULL ||
1851         &g_caSslContext->rnd == NULL ||
1852         &g_caSslContext->entropy == NULL)
1853     {
1854         ret = 1;
1855     }
1856
1857     // CAdeinitSslAdapter
1858     oc_mutex_lock(g_sslContextMutex);
1859     DeletePeerList();
1860     mbedtls_x509_crt_free(&g_caSslContext->crt);
1861     mbedtls_pk_free(&g_caSslContext->pkey);
1862     mbedtls_ssl_config_free(&g_caSslContext->clientTlsConf);
1863     mbedtls_ssl_config_free(&g_caSslContext->serverTlsConf);
1864     mbedtls_ctr_drbg_free(&g_caSslContext->rnd);
1865     mbedtls_entropy_free(&g_caSslContext->entropy);
1866     OICFree(g_caSslContext);
1867     g_caSslContext = NULL;
1868     oc_mutex_unlock(g_sslContextMutex);
1869     oc_mutex_free(g_sslContextMutex);
1870     g_sslContextMutex = NULL;
1871
1872     return ret;
1873 }
1874
1875 // CAinitTlsAdapter()
1876 TEST(TLSAdaper, Test_1)
1877 {
1878     int ret = 0xFF;
1879     ret = testCAinitSslAdapter();
1880     EXPECT_EQ(0, ret);
1881 }
1882
1883 /* **************************
1884  *
1885  *
1886  * CAsetSslAdapterCallbacks test
1887  *
1888  *
1889  * *************************/
1890
1891 static int testCAsetSslAdapterCallbacks()
1892 {
1893     int ret = 0xFF;
1894     CAEndpoint_t serverAddr;
1895     serverAddr.adapter = CA_ADAPTER_IP;
1896     serverAddr.flags = CA_SECURE;
1897     serverAddr.port = 4433;
1898     char addr[] = {0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x00}; // 127.0.0.1
1899     memcpy(serverAddr.addr, addr, sizeof(addr));
1900     serverAddr.ifindex = 0;
1901
1902     // CAinitSslAdapter
1903     g_sslContextMutex = oc_mutex_new();
1904     oc_mutex_lock(g_sslContextMutex);
1905     g_caSslContext = (SslContext_t *)OICCalloc(1, sizeof(SslContext_t));
1906     g_caSslContext->peerList = u_arraylist_create();
1907     mbedtls_entropy_init(&g_caSslContext->entropy);
1908     mbedtls_ctr_drbg_init(&g_caSslContext->rnd);
1909     unsigned char * seed = (unsigned char*) SEED;
1910     mbedtls_ctr_drbg_seed(&g_caSslContext->rnd, mbedtls_entropy_func_clutch,
1911                                   &g_caSslContext->entropy, seed, sizeof(SEED));
1912     mbedtls_ctr_drbg_set_prediction_resistance(&g_caSslContext->rnd, MBEDTLS_CTR_DRBG_PR_OFF);
1913     mbedtls_ssl_config_init(&g_caSslContext->clientTlsConf);
1914     mbedtls_ssl_config_defaults(&g_caSslContext->clientTlsConf, MBEDTLS_SSL_IS_CLIENT,
1915                                     MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT);
1916     mbedtls_ssl_conf_psk_cb(&g_caSslContext->clientTlsConf, GetPskCredentialsCallback, NULL);
1917     mbedtls_ssl_conf_rng( &g_caSslContext->clientTlsConf, mbedtls_ctr_drbg_random,
1918                           &g_caSslContext->rnd);
1919     mbedtls_ssl_conf_curves(&g_caSslContext->clientTlsConf, curve[ADAPTER_CURVE_SECP256R1]);
1920     mbedtls_ssl_conf_min_version(&g_caSslContext->clientTlsConf, MBEDTLS_SSL_MAJOR_VERSION_3,
1921                                  MBEDTLS_SSL_MINOR_VERSION_3);
1922     mbedtls_ssl_conf_authmode(&g_caSslContext->clientTlsConf, MBEDTLS_SSL_VERIFY_REQUIRED);
1923     CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256);
1924     mbedtls_x509_crt_init(&g_caSslContext->ca);
1925     mbedtls_x509_crt_init(&g_caSslContext->crt);
1926     mbedtls_pk_init(&g_caSslContext->pkey);
1927     mbedtls_x509_crl_init(&g_caSslContext->crl);
1928     oc_mutex_unlock(g_sslContextMutex);
1929
1930     CAsetSslAdapterCallbacks(CATCPPacketReceivedCB, CATCPPacketSendCB, (CATransportAdapter_t)0);
1931     if (g_caSslContext->adapterCallbacks[0].recvCallback == NULL &&
1932         g_caSslContext->adapterCallbacks[0].sendCallback == NULL &&
1933         g_caSslContext->adapterCallbacks[1].recvCallback == NULL &&
1934         g_caSslContext->adapterCallbacks[1].sendCallback == NULL)
1935     {
1936         ret = 0;
1937     }
1938     else
1939     {
1940         ret = 1;
1941     }
1942     CAsetSslAdapterCallbacks(CATCPPacketReceivedCB, CATCPPacketSendCB, CA_ADAPTER_IP);
1943     CAsetSslAdapterCallbacks(CATCPPacketReceivedCB, CATCPPacketSendCB, CA_ADAPTER_TCP);
1944     if (g_caSslContext->adapterCallbacks[0].recvCallback == CATCPPacketReceivedCB &&
1945         g_caSslContext->adapterCallbacks[0].sendCallback == CATCPPacketSendCB &&
1946         g_caSslContext->adapterCallbacks[1].recvCallback == CATCPPacketReceivedCB &&
1947         g_caSslContext->adapterCallbacks[1].sendCallback == CATCPPacketSendCB)
1948     {
1949         ret += 0;
1950     }
1951     else
1952     {
1953         ret += 1;
1954     }
1955
1956     // CAdeinitSslAdapter
1957     oc_mutex_lock(g_sslContextMutex);
1958     DeletePeerList();
1959     mbedtls_x509_crt_free(&g_caSslContext->crt);
1960     mbedtls_pk_free(&g_caSslContext->pkey);
1961     mbedtls_ssl_config_free(&g_caSslContext->clientTlsConf);
1962     mbedtls_ssl_config_free(&g_caSslContext->serverTlsConf);
1963     mbedtls_ctr_drbg_free(&g_caSslContext->rnd);
1964     mbedtls_entropy_free(&g_caSslContext->entropy);
1965     OICFree(g_caSslContext);
1966     g_caSslContext = NULL;
1967     oc_mutex_unlock(g_sslContextMutex);
1968     oc_mutex_free(g_sslContextMutex);
1969     g_sslContextMutex = NULL;
1970
1971     return ret;
1972 }
1973
1974 // CAsetSslAdapterCallbacks()
1975 TEST(TLSAdaper, Test_2)
1976 {
1977     int ret = 0xFF;
1978     ret = testCAsetSslAdapterCallbacks();
1979     EXPECT_EQ(0, ret);
1980 }
1981
1982 /* **************************
1983  *
1984  *
1985  * CAinitiateSslHandshake test
1986  *
1987  *
1988  * *************************/
1989
1990 unsigned char predictedClientHello[] = {
1991     0x16, 0x03, 0x01, 0x00, 0x63, 0x01, 0x00, 0x00, 0x5f, 0x03, 0x03, 0x57, 0xf2, 0x5f, 0x21, 0x04,
1992     0xb1, 0x3b, 0xda, 0x55, 0xa4, 0x8e, 0xcc, 0x3f, 0xe9, 0x45, 0x5c, 0xaf, 0xcb, 0x19, 0x2e, 0x1f,
1993     0x4b, 0xd5, 0x84, 0x5c, 0x4b, 0xd7, 0x7d, 0x38, 0xa2, 0xfa, 0x3d, 0x00, 0x00, 0x06, 0xc0, 0xac,
1994     0xc0, 0xae, 0x00, 0xff, 0x01, 0x00, 0x00, 0x30, 0x00, 0x0d, 0x00, 0x16, 0x00, 0x14, 0x06, 0x03,
1995     0x06, 0x01, 0x05, 0x03, 0x05, 0x01, 0x04, 0x03, 0x04, 0x01, 0x03, 0x03, 0x03, 0x01, 0x02, 0x03,
1996     0x02, 0x01, 0x00, 0x0a, 0x00, 0x04, 0x00, 0x02, 0x00, 0x17, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00,
1997     0x00, 0x16, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00
1998 };
1999 static unsigned char controlBuf[sizeof(predictedClientHello)];
2000 static char controlBufLen = 0;
2001 static ssize_t CATCPPacketSendCB_forInitHsTest(CAEndpoint_t *, const void * buf, size_t buflen)
2002 {
2003     int n;
2004     n = write(sockfd, buf, buflen);
2005     if (n < 0)
2006          error("ERROR writing to socket");
2007
2008     memset(controlBuf, 0, sizeof(predictedClientHello));
2009     memcpy(controlBuf, buf, buflen);
2010     controlBufLen = buflen;
2011     return buflen;
2012 }
2013
2014 static void * test0CAinitiateSslHandshake(void * arg)
2015 {
2016     CAEndpoint_t serverAddr;
2017     serverAddr.adapter = CA_ADAPTER_TCP;
2018     serverAddr.flags = CA_SECURE;
2019     serverAddr.port = 4433;
2020     char addr[] = {0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x00}; // 127.0.0.1
2021     memcpy(serverAddr.addr, addr, sizeof(addr));
2022     serverAddr.ifindex = 0;
2023
2024     // CAinitSslAdapter
2025     g_sslContextMutex = oc_mutex_new();
2026     oc_mutex_lock(g_sslContextMutex);
2027     g_caSslContext = (SslContext_t *)OICCalloc(1, sizeof(SslContext_t));
2028     g_caSslContext->peerList = u_arraylist_create();
2029     mbedtls_entropy_init(&g_caSslContext->entropy);
2030     mbedtls_ctr_drbg_init(&g_caSslContext->rnd);
2031     unsigned char * seed = (unsigned char*) SEED;
2032     mbedtls_ctr_drbg_seed(&g_caSslContext->rnd, mbedtls_entropy_func_clutch,
2033                                   &g_caSslContext->entropy, seed, sizeof(SEED));
2034     mbedtls_ctr_drbg_set_prediction_resistance(&g_caSslContext->rnd, MBEDTLS_CTR_DRBG_PR_OFF);
2035     mbedtls_ssl_config_init(&g_caSslContext->clientTlsConf);
2036     mbedtls_ssl_config_defaults(&g_caSslContext->clientTlsConf, MBEDTLS_SSL_IS_CLIENT,
2037                                     MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT);
2038     mbedtls_ssl_conf_psk_cb(&g_caSslContext->clientTlsConf, GetPskCredentialsCallback, NULL);
2039     mbedtls_ssl_conf_rng( &g_caSslContext->clientTlsConf, mbedtls_ctr_drbg_random,
2040                           &g_caSslContext->rnd);
2041     mbedtls_ssl_conf_curves(&g_caSslContext->clientTlsConf, curve[ADAPTER_CURVE_SECP256R1]);
2042     mbedtls_ssl_conf_min_version(&g_caSslContext->clientTlsConf, MBEDTLS_SSL_MAJOR_VERSION_3,
2043                                  MBEDTLS_SSL_MINOR_VERSION_3);
2044     mbedtls_ssl_conf_authmode(&g_caSslContext->clientTlsConf, MBEDTLS_SSL_VERIFY_REQUIRED);
2045     mbedtls_x509_crt_init(&g_caSslContext->ca);
2046     mbedtls_x509_crt_init(&g_caSslContext->crt);
2047     mbedtls_pk_init(&g_caSslContext->pkey);
2048     mbedtls_x509_crl_init(&g_caSslContext->crl);
2049     oc_mutex_unlock(g_sslContextMutex);
2050
2051     // CAsetSslAdapterCallbacks
2052     g_caSslContext->adapterCallbacks[1].recvCallback = CATCPPacketReceivedCB;
2053     g_caSslContext->adapterCallbacks[1].sendCallback = CATCPPacketSendCB_forInitHsTest;
2054
2055     // CAsetPkixInfoCallback
2056     g_getPkixInfoCallback = infoCallback_that_loads_x509;
2057
2058     // CAsetCredentialTypesCallback
2059     g_getCredentialTypesCallback = clutch;
2060
2061     // CAsetTlsCipherSuite
2062     mbedtls_ssl_conf_ciphersuites(&g_caSslContext->clientTlsConf,
2063                                          tlsCipher[SSL_ECDHE_ECDSA_WITH_AES_128_CCM]);
2064     mbedtls_ssl_conf_ciphersuites(&g_caSslContext->serverTlsConf,
2065                                          tlsCipher[SSL_ECDHE_ECDSA_WITH_AES_128_CCM]);
2066     g_caSslContext->cipher = SSL_ECDHE_ECDSA_WITH_AES_128_CCM;
2067
2068     CAsetPskCredentialsCallback(GetDtlsPskCredentials);
2069
2070     socketConnect();
2071
2072     unsigned int unixTime = (unsigned)time(NULL);
2073     CAinitiateSslHandshake(&serverAddr);
2074     predictedClientHello[11] = unixTime >> 24;
2075     predictedClientHello[12] = (unixTime << 8) >> 24;
2076     predictedClientHello[13] = (unixTime << 16) >> 24;
2077     predictedClientHello[14] = (unixTime << 24) >> 24;
2078
2079     // CAcloseTlsConnection
2080     oc_mutex_lock(g_sslContextMutex);
2081     SslEndPoint_t * tep = GetSslPeer(&serverAddr);
2082     mbedtls_ssl_close_notify(&tep->ssl);
2083     RemovePeerFromList(&tep->sep.endpoint);
2084     oc_mutex_unlock(g_sslContextMutex);
2085
2086     // CAdeinitTlsAdapter
2087     oc_mutex_lock(g_sslContextMutex);
2088     DeletePeerList();
2089     mbedtls_x509_crt_free(&g_caSslContext->crt);
2090     mbedtls_pk_free(&g_caSslContext->pkey);
2091     mbedtls_ssl_config_free(&g_caSslContext->clientTlsConf);
2092     mbedtls_ssl_config_free(&g_caSslContext->serverTlsConf);
2093     mbedtls_ctr_drbg_free(&g_caSslContext->rnd);
2094     mbedtls_entropy_free(&g_caSslContext->entropy);
2095     OICFree(g_caSslContext);
2096     g_caSslContext = NULL;
2097     oc_mutex_unlock(g_sslContextMutex);
2098     oc_mutex_free(g_sslContextMutex);
2099     g_sslContextMutex = NULL;
2100
2101     socketClose();
2102
2103     if (controlBufLen == sizeof(predictedClientHello) &&
2104         memcmp(predictedClientHello, controlBuf, sizeof(predictedClientHello)) == 0)
2105     {
2106         *((int*)arg) = 0;
2107         return NULL;
2108     }
2109     else
2110     {
2111         *((int*)arg) = 0xFF;
2112         return (void *) 0xFF;
2113     }
2114 }
2115
2116 static int test1CAinitiateSslHandshake()
2117 {
2118     int ret = 0xff;
2119     ret = CAinitiateSslHandshake(NULL);
2120     if (CA_STATUS_INVALID_PARAM == ret)
2121     {
2122         ret = 0;
2123     }
2124     else
2125     {
2126         ret = 1;
2127     }
2128     return ret;
2129 }
2130
2131 // CAinitiateSslHandshake()
2132 TEST(TLSAdaper, Test_3_0)
2133 {
2134     pthread_t thread1, thread2;
2135     int ret = 0;
2136     int arg = 1;
2137
2138     ret = pthread_create( &thread1, NULL, server, (void*) NULL);
2139     if(ret)
2140     {
2141         fprintf(stderr, "Error - pthread_create() return code: %d\n", ret);
2142         exit(EXIT_FAILURE);
2143     }
2144
2145     sleep(5);
2146
2147     ret = pthread_create( &thread2, NULL, test0CAinitiateSslHandshake, &arg);
2148     if(ret)
2149     {
2150         fprintf(stderr, "Error - pthread_create() return code: %d\n", ret);
2151         exit(EXIT_FAILURE);
2152     }
2153
2154     sleep(5);
2155
2156     EXPECT_EQ(0, arg);
2157 }
2158
2159 TEST(TLSAdaper, Test_3_1)
2160 {
2161     int ret = 0xFF;
2162     ret = test1CAinitiateSslHandshake();
2163     EXPECT_EQ(0, ret);
2164 }
2165
2166 /* **************************
2167  *
2168  *
2169  * CAencryptSsl test
2170  *
2171  *
2172  * *************************/
2173
2174 static void * testCAencryptSsl(void * arg)
2175 {
2176     int ret = 0;
2177     CAEndpoint_t serverAddr;
2178     serverAddr.adapter = CA_ADAPTER_TCP;
2179     serverAddr.flags = CA_SECURE;
2180     serverAddr.port = 4433;
2181     char addr[] = {0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x00}; // 127.0.0.1
2182     memcpy(serverAddr.addr, addr, sizeof(addr));
2183     serverAddr.ifindex = 0;
2184
2185     // CAinitTlsAdapter
2186     g_sslContextMutex = oc_mutex_new();
2187     oc_mutex_lock(g_sslContextMutex);
2188     g_caSslContext = (SslContext_t *)OICCalloc(1, sizeof(SslContext_t));
2189     g_caSslContext->peerList = u_arraylist_create();
2190     mbedtls_entropy_init(&g_caSslContext->entropy);
2191     mbedtls_ctr_drbg_init(&g_caSslContext->rnd);
2192     unsigned char * seed = (unsigned char*) SEED;
2193     mbedtls_ctr_drbg_seed(&g_caSslContext->rnd, mbedtls_entropy_func_clutch,
2194                                   &g_caSslContext->entropy, seed, sizeof(SEED));
2195     mbedtls_ctr_drbg_set_prediction_resistance(&g_caSslContext->rnd, MBEDTLS_CTR_DRBG_PR_OFF);
2196     mbedtls_ssl_config_init(&g_caSslContext->clientTlsConf);
2197     mbedtls_ssl_config_defaults(&g_caSslContext->clientTlsConf, MBEDTLS_SSL_IS_CLIENT,
2198                                     MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT);
2199     mbedtls_ssl_conf_psk_cb(&g_caSslContext->clientTlsConf, GetPskCredentialsCallback, NULL);
2200     mbedtls_ssl_conf_rng( &g_caSslContext->clientTlsConf, mbedtls_ctr_drbg_random,
2201                           &g_caSslContext->rnd);
2202     mbedtls_ssl_conf_curves(&g_caSslContext->clientTlsConf, curve[ADAPTER_CURVE_SECP256R1]);
2203     mbedtls_ssl_conf_min_version(&g_caSslContext->clientTlsConf, MBEDTLS_SSL_MAJOR_VERSION_3,
2204                                  MBEDTLS_SSL_MINOR_VERSION_3);
2205     mbedtls_ssl_conf_authmode(&g_caSslContext->clientTlsConf, MBEDTLS_SSL_VERIFY_REQUIRED);
2206     CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256);
2207     mbedtls_x509_crt_init(&g_caSslContext->ca);
2208     mbedtls_x509_crt_init(&g_caSslContext->crt);
2209     mbedtls_pk_init(&g_caSslContext->pkey);
2210     mbedtls_x509_crl_init(&g_caSslContext->crl);
2211     oc_mutex_unlock(g_sslContextMutex);
2212
2213     CAsetSslAdapterCallbacks(CATCPPacketReceivedCB, CATCPPacketSendCB, CA_ADAPTER_TCP);
2214
2215     CAsetPkixInfoCallback(infoCallback_that_loads_x509);
2216
2217     // CAsetCredentialTypesCallback
2218     g_getCredentialTypesCallback = clutch;
2219
2220     if (*((int*)arg) == 0)
2221     {
2222         CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM);
2223     }
2224     else if (*((int*)arg) == 1)
2225     {
2226         CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8);
2227     }
2228     else if (*((int*)arg) == 2)
2229     {
2230         CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256);
2231     }
2232     else if (*((int*)arg) == 3)
2233     {
2234         CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256);
2235     }
2236     else if (*((int*)arg) == 4)
2237     {
2238         CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384);
2239     }
2240     else if (*((int*)arg) == 5)
2241     {
2242         CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384);
2243     }
2244
2245     CAsetPskCredentialsCallback(GetDtlsPskCredentials);
2246
2247     socketConnect();
2248
2249     // CAinitiateSslHandshake
2250     oc_mutex_lock(g_sslContextMutex);
2251     InitiateTlsHandshake(&serverAddr);
2252     oc_mutex_unlock(g_sslContextMutex);
2253
2254     unsigned char buffer[2048] = {'\0'};
2255     int buflen = 0;
2256     CASecureEndpoint_t * sep = (CASecureEndpoint_t *) malloc (sizeof(CASecureEndpoint_t));
2257     sep->endpoint = serverAddr;
2258
2259     for (int i = 0; i < 6; i++)
2260     {
2261         PacketReceive(buffer, &buflen);
2262         CAdecryptSsl(sep, (uint8_t *)buffer, buflen);
2263     }
2264
2265     ret = sprintf( (char*)buffer, GET_REQUEST );
2266
2267     CAencryptSsl(&serverAddr, buffer, ret);
2268
2269     PacketReceive(buffer, &buflen);
2270     CAdecryptSsl(sep, (uint8_t *)buffer, buflen);
2271
2272     CAcloseSslConnection(&serverAddr);
2273
2274     // CAdeinitSslAdapter
2275     oc_mutex_lock(g_sslContextMutex);
2276     DeletePeerList();
2277     mbedtls_x509_crt_free(&g_caSslContext->crt);
2278     mbedtls_pk_free(&g_caSslContext->pkey);
2279     mbedtls_ssl_config_free(&g_caSslContext->clientTlsConf);
2280     mbedtls_ssl_config_free(&g_caSslContext->serverTlsConf);
2281     mbedtls_ctr_drbg_free(&g_caSslContext->rnd);
2282     mbedtls_entropy_free(&g_caSslContext->entropy);
2283     OICFree(g_caSslContext);
2284     g_caSslContext = NULL;
2285     oc_mutex_unlock(g_sslContextMutex);
2286     oc_mutex_free(g_sslContextMutex);
2287     g_sslContextMutex = NULL;
2288
2289     socketClose();
2290
2291     if (*((int*)arg) == 0)
2292     {
2293         if (control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM_len == msglen &&
2294             memcmp(msg, control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM,
2295             control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM_len) == 0)
2296         {
2297             ret = 0;
2298         }
2299         else
2300         {
2301             ret = 1;
2302         }
2303     }
2304     if (*((int*)arg) == 1)
2305     {
2306         if (control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM_8_len == msglen &&
2307             memcmp(msg, control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM_8,
2308             control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM_8_len) == 0)
2309         {
2310             ret = 0;
2311         }
2312         else
2313         {
2314             ret = 1;
2315         }
2316     }
2317     else if (*((int*)arg) == 2)
2318     {
2319         if (control_server_message_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256_len == msglen &&
2320             memcmp(msg, control_server_message_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
2321             control_server_message_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256_len) == 0)
2322         {
2323             ret = 0;
2324         }
2325         else
2326         {
2327             ret = 1;
2328         }
2329     }
2330     else if (*((int*)arg) == 3)
2331     {
2332         if (control_server_message_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256_len == msglen &&
2333             memcmp(msg, control_server_message_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
2334             control_server_message_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256_len) == 0)
2335         {
2336             ret = 0;
2337         }
2338         else
2339         {
2340             ret = 1;
2341         }
2342     }
2343     else if (*((int*)arg) == 4)
2344     {
2345         if (control_server_message_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384_len == msglen &&
2346             memcmp(msg, control_server_message_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,
2347                    control_server_message_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384_len) == 0)
2348         {
2349             ret = 0;
2350         }
2351         else
2352         {
2353             ret = 1;
2354         }
2355     }
2356     else if (*((int*)arg) == 5)
2357     {
2358         if (control_server_message_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384_len == msglen &&
2359             memcmp(msg, control_server_message_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
2360                    control_server_message_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384_len) == 0)
2361         {
2362             ret = 0;
2363         }
2364         else
2365         {
2366             ret = 1;
2367         }
2368     }
2369
2370     if (ret == 0)
2371     {
2372         *((int*)arg) = 0;
2373         return NULL;
2374     }
2375     else
2376     {
2377         *((int*)arg) = 0xFF;
2378         return (void *) 0xFF;
2379     }
2380 }
2381
2382 // CAencryptSsl()
2383 TEST(TLSAdaper, Test_4_0)
2384 {
2385     pthread_t thread1, thread2;
2386     int ret = 0;
2387     int arg = 0;
2388
2389     ret = pthread_create( &thread1, NULL, server, (void*) NULL);
2390     if(ret)
2391     {
2392         fprintf(stderr,"Error - pthread_create() return code: %d\n", ret);
2393         exit(EXIT_FAILURE);
2394     }
2395
2396     sleep(5);
2397
2398     ret = pthread_create( &thread2, NULL, testCAencryptSsl, &arg);
2399     if(ret)
2400     {
2401         fprintf(stderr,"Error - pthread_create() return code: %d\n", ret);
2402         exit(EXIT_FAILURE);
2403     }
2404
2405     sleep(5);
2406
2407     EXPECT_EQ(0, arg);
2408 }
2409
2410 // CAencryptSsl()
2411 TEST(TLSAdaper, Test_4_1)
2412 {
2413     pthread_t thread1, thread2;
2414     int ret = 0;
2415     int arg = 1;
2416
2417     ret = pthread_create( &thread1, NULL, server, (void*) NULL);
2418     if(ret)
2419     {
2420         fprintf(stderr,"Error - pthread_create() return code: %d\n", ret);
2421         exit(EXIT_FAILURE);
2422     }
2423
2424     sleep(5);
2425
2426     ret = pthread_create( &thread2, NULL, testCAencryptSsl, &arg);
2427     if(ret)
2428     {
2429         fprintf(stderr,"Error - pthread_create() return code: %d\n", ret);
2430         exit(EXIT_FAILURE);
2431     }
2432
2433     sleep(5);
2434
2435     EXPECT_EQ(0, arg);
2436 }
2437
2438 // CAencryptSsl()
2439 TEST(TLSAdaper, Test_4_2)
2440 {
2441     pthread_t thread1, thread2;
2442     int ret = 0;
2443     int arg = 2;
2444
2445     ret = pthread_create( &thread1, NULL, server, (void*) NULL);
2446     if(ret)
2447     {
2448         fprintf(stderr,"Error - pthread_create() return code: %d\n", ret);
2449         exit(EXIT_FAILURE);
2450     }
2451
2452     sleep(5);
2453
2454     ret = pthread_create( &thread2, NULL, testCAencryptSsl, &arg);
2455     if(ret)
2456     {
2457         fprintf(stderr,"Error - pthread_create() return code: %d\n", ret);
2458         exit(EXIT_FAILURE);
2459     }
2460
2461     sleep(5);
2462
2463     EXPECT_EQ(0, arg);
2464 }
2465
2466 // CAencryptSsl()
2467 TEST(TLSAdaper, Test_4_3)
2468 {
2469     pthread_t thread1, thread2;
2470     int ret = 0;
2471     int arg = 3;
2472
2473     ret = pthread_create( &thread1, NULL, server, (void*) NULL);
2474     if(ret)
2475     {
2476         fprintf(stderr,"Error - pthread_create() return code: %d\n", ret);
2477         exit(EXIT_FAILURE);
2478     }
2479
2480     sleep(5);
2481
2482     ret = pthread_create( &thread2, NULL, testCAencryptSsl, &arg);
2483     if(ret)
2484     {
2485         fprintf(stderr,"Error - pthread_create() return code: %d\n", ret);
2486         exit(EXIT_FAILURE);
2487     }
2488
2489     sleep(5);
2490
2491     EXPECT_EQ(0, arg);
2492 }
2493
2494 // CAencryptSsl()
2495 TEST(TLSAdaper, Test_4_4)
2496 {
2497     pthread_t thread1, thread2;
2498     int ret = 0;
2499     int arg = 4;
2500
2501     ret = pthread_create( &thread1, NULL, server, (void*) NULL);
2502     if(ret)
2503     {
2504         fprintf(stderr,"Error - pthread_create() return code: %d\n", ret);
2505         exit(EXIT_FAILURE);
2506     }
2507
2508     sleep(5);
2509
2510     ret = pthread_create( &thread2, NULL, testCAencryptSsl, &arg);
2511     if(ret)
2512     {
2513         fprintf(stderr,"Error - pthread_create() return code: %d\n", ret);
2514         exit(EXIT_FAILURE);
2515     }
2516
2517     sleep(5);
2518
2519     EXPECT_EQ(0, arg);
2520 }
2521
2522 TEST(TLSAdaper, Test_4_5)
2523 {
2524     pthread_t thread1, thread2;
2525     int ret = 0;
2526     int arg = 5;
2527
2528     ret = pthread_create( &thread1, NULL, server, (void*) NULL);
2529     if(ret)
2530     {
2531         fprintf(stderr,"Error - pthread_create() return code: %d\n", ret);
2532         exit(EXIT_FAILURE);
2533     }
2534
2535     sleep(5);
2536
2537     ret = pthread_create( &thread2, NULL, testCAencryptSsl, &arg);
2538     if(ret)
2539     {
2540         fprintf(stderr,"Error - pthread_create() return code: %d\n", ret);
2541         exit(EXIT_FAILURE);
2542     }
2543
2544     sleep(5);
2545
2546     EXPECT_EQ(0, arg);
2547 }
2548
2549 /* **************************
2550  *
2551  *
2552  * CAdecryptSsl test
2553  *
2554  *
2555  * *************************/
2556
2557 static void * testCAdecryptSsl(void * arg)
2558 {
2559     int ret = 0;
2560     unsigned char buffer[2048] = {'\0'};
2561     int buflen = 0;
2562
2563     CAEndpoint_t serverAddr;
2564     serverAddr.adapter = CA_ADAPTER_TCP;
2565     serverAddr.flags = CA_SECURE;
2566     serverAddr.port = 4433;
2567     char addr[] = {0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x00}; // 127.0.0.1
2568     memcpy(serverAddr.addr, addr, sizeof(addr));
2569     serverAddr.ifindex = 0;
2570
2571     // CAinitTlsAdapter
2572     g_sslContextMutex = oc_mutex_new();
2573     oc_mutex_lock(g_sslContextMutex);
2574     g_caSslContext = (SslContext_t *)OICCalloc(1, sizeof(SslContext_t));
2575     g_caSslContext->peerList = u_arraylist_create();
2576     mbedtls_entropy_init(&g_caSslContext->entropy);
2577     mbedtls_ctr_drbg_init(&g_caSslContext->rnd);
2578     unsigned char * seed = (unsigned char*) SEED;
2579     mbedtls_ctr_drbg_seed(&g_caSslContext->rnd, mbedtls_entropy_func_clutch,
2580                                   &g_caSslContext->entropy, seed, sizeof(SEED));
2581     mbedtls_ctr_drbg_set_prediction_resistance(&g_caSslContext->rnd, MBEDTLS_CTR_DRBG_PR_OFF);
2582     mbedtls_ssl_config_init(&g_caSslContext->clientTlsConf);
2583     mbedtls_ssl_config_defaults(&g_caSslContext->clientTlsConf, MBEDTLS_SSL_IS_CLIENT,
2584                                     MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT);
2585     mbedtls_ssl_conf_psk_cb(&g_caSslContext->clientTlsConf, GetPskCredentialsCallback, NULL);
2586     mbedtls_ssl_conf_rng( &g_caSslContext->clientTlsConf, mbedtls_ctr_drbg_random,
2587                           &g_caSslContext->rnd);
2588     mbedtls_ssl_conf_curves(&g_caSslContext->clientTlsConf, curve[ADAPTER_CURVE_SECP256R1]);
2589     mbedtls_ssl_conf_min_version(&g_caSslContext->clientTlsConf, MBEDTLS_SSL_MAJOR_VERSION_3,
2590                                  MBEDTLS_SSL_MINOR_VERSION_3);
2591     mbedtls_ssl_conf_authmode(&g_caSslContext->clientTlsConf, MBEDTLS_SSL_VERIFY_REQUIRED);
2592     CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256);
2593     mbedtls_x509_crt_init(&g_caSslContext->ca);
2594     mbedtls_x509_crt_init(&g_caSslContext->crt);
2595     mbedtls_pk_init(&g_caSslContext->pkey);
2596     mbedtls_x509_crl_init(&g_caSslContext->crl);
2597     oc_mutex_unlock(g_sslContextMutex);
2598
2599     // CAsetTlsAdapterCallbacks
2600     CAsetSslAdapterCallbacks(CATCPPacketReceivedCB, CATCPPacketSendCB, CA_ADAPTER_TCP);
2601
2602     // CAsetPkixInfoCallback
2603     CAsetPkixInfoCallback(infoCallback_that_loads_x509);
2604
2605     // CAsetCredentialTypesCallback
2606     g_getCredentialTypesCallback = clutch;
2607
2608     CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM);
2609
2610     CAsetPskCredentialsCallback(GetDtlsPskCredentials);
2611
2612     socketConnect();
2613
2614     // CAinitiateSslHandshake
2615     oc_mutex_lock(g_sslContextMutex);
2616     InitiateTlsHandshake(&serverAddr);
2617     oc_mutex_unlock(g_sslContextMutex);
2618
2619     CASecureEndpoint_t * sep = (CASecureEndpoint_t *) malloc (sizeof(CASecureEndpoint_t));
2620     sep->endpoint = serverAddr;
2621
2622     for (int i = 0; i < 6; i++)
2623     {
2624         PacketReceive(buffer, &buflen);
2625         CAdecryptSsl(sep, (uint8_t *)buffer, buflen);
2626     }
2627
2628     ret = sprintf((char*)buffer, GET_REQUEST);
2629
2630     CAencryptSsl(&serverAddr, buffer, ret);
2631
2632     PacketReceive(buffer, &buflen);
2633     CAdecryptSsl(sep, (uint8_t *)buffer, buflen);
2634
2635     CAcloseSslConnection(&serverAddr);
2636
2637     // CAdeinitSslAdapter
2638     oc_mutex_lock(g_sslContextMutex);
2639     DeletePeerList();
2640     mbedtls_x509_crt_free(&g_caSslContext->crt);
2641     mbedtls_pk_free(&g_caSslContext->pkey);
2642     mbedtls_ssl_config_free(&g_caSslContext->clientTlsConf);
2643     mbedtls_ssl_config_free(&g_caSslContext->serverTlsConf);
2644     mbedtls_ctr_drbg_free(&g_caSslContext->rnd);
2645     mbedtls_entropy_free(&g_caSslContext->entropy);
2646     OICFree(g_caSslContext);
2647     g_caSslContext = NULL;
2648     oc_mutex_unlock(g_sslContextMutex);
2649     oc_mutex_free(g_sslContextMutex);
2650     g_sslContextMutex = NULL;
2651
2652     socketClose();
2653
2654     if (control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM_len == msglen &&
2655             memcmp(msg, control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM,
2656             control_server_message_ECDHE_ECDSA_WITH_AES_128_CCM_len) == 0)
2657     {
2658         *((int*)arg) = 0;
2659         return NULL;
2660     }
2661     else
2662     {
2663         *((int*)arg) = 0xFF;
2664         return (void *) 0xFF;
2665     }
2666 }
2667
2668 // CAdecryptTls()
2669 TEST(TLSAdaper, Test_5)
2670 {
2671     pthread_t thread1, thread2;
2672     int ret = 0;
2673     int arg = 1;
2674
2675     ret = pthread_create( &thread1, NULL, server, (void*) NULL);
2676     if(ret)
2677     {
2678         fprintf(stderr,"Error - pthread_create() return code: %d\n", ret);
2679         exit(EXIT_FAILURE);
2680     }
2681
2682     sleep(5);
2683
2684     ret = pthread_create( &thread2, NULL, testCAdecryptSsl, &arg);
2685     if(ret)
2686     {
2687         fprintf(stderr,"Error - pthread_create() return code: %d\n", ret);
2688         exit(EXIT_FAILURE);
2689     }
2690
2691     sleep(5);
2692
2693     EXPECT_EQ(0, arg);
2694 }
2695
2696 /* **************************
2697  *
2698  *
2699  * CAdeinitSslAdapter test
2700  *
2701  *
2702  * *************************/
2703
2704 static int testCAdeinitSslAdapter()
2705 {
2706     int ret = 0;
2707     CAEndpoint_t serverAddr;
2708     serverAddr.adapter = CA_ADAPTER_IP;
2709     serverAddr.flags = CA_SECURE;
2710     serverAddr.port = 4433;
2711     char addr[] = {0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x00}; // 127.0.0.1
2712     memcpy(serverAddr.addr, addr, sizeof(addr));
2713     serverAddr.ifindex = 0;
2714
2715     // CAinitTlsAdapter
2716     g_sslContextMutex = oc_mutex_new();
2717     oc_mutex_lock(g_sslContextMutex);
2718     g_caSslContext = (SslContext_t *)OICCalloc(1, sizeof(SslContext_t));
2719     g_caSslContext->peerList = u_arraylist_create();
2720     mbedtls_entropy_init(&g_caSslContext->entropy);
2721     mbedtls_ctr_drbg_init(&g_caSslContext->rnd);
2722     unsigned char * seed = (unsigned char*) SEED;
2723     mbedtls_ctr_drbg_seed(&g_caSslContext->rnd, mbedtls_entropy_func,
2724                                   &g_caSslContext->entropy, seed, sizeof(SEED));
2725     mbedtls_ctr_drbg_set_prediction_resistance(&g_caSslContext->rnd, MBEDTLS_CTR_DRBG_PR_OFF);
2726     mbedtls_ssl_config_init(&g_caSslContext->clientTlsConf);
2727     mbedtls_ssl_config_defaults(&g_caSslContext->clientTlsConf, MBEDTLS_SSL_IS_CLIENT,
2728                                     MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT);
2729     mbedtls_ssl_conf_psk_cb(&g_caSslContext->clientTlsConf, GetPskCredentialsCallback, NULL);
2730     mbedtls_ssl_conf_rng( &g_caSslContext->clientTlsConf, mbedtls_ctr_drbg_random,
2731                           &g_caSslContext->rnd);
2732     mbedtls_ssl_conf_curves(&g_caSslContext->clientTlsConf, curve[ADAPTER_CURVE_SECP256R1]);
2733     mbedtls_ssl_conf_min_version(&g_caSslContext->clientTlsConf, MBEDTLS_SSL_MAJOR_VERSION_3,
2734                                  MBEDTLS_SSL_MINOR_VERSION_3);
2735     mbedtls_ssl_conf_authmode(&g_caSslContext->clientTlsConf, MBEDTLS_SSL_VERIFY_REQUIRED);
2736     mbedtls_x509_crt_init(&g_caSslContext->ca);
2737     mbedtls_x509_crt_init(&g_caSslContext->crt);
2738     mbedtls_pk_init(&g_caSslContext->pkey);
2739     mbedtls_x509_crl_init(&g_caSslContext->crl);
2740     oc_mutex_unlock(g_sslContextMutex);
2741
2742     // CAsetTlsAdapterCallbacks
2743     g_caSslContext->adapterCallbacks[1].recvCallback = CATCPPacketReceivedCB;
2744     g_caSslContext->adapterCallbacks[1].sendCallback = CATCPPacketSendCB;
2745
2746     // CAsetPkixInfoCallback
2747     g_getPkixInfoCallback = infoCallback_that_loads_x509;
2748
2749     // CAsetTlsCipherSuite
2750     mbedtls_ssl_conf_ciphersuites(&g_caSslContext->clientTlsConf,
2751                                          tlsCipher[SSL_ECDHE_ECDSA_WITH_AES_128_CCM]);
2752     mbedtls_ssl_conf_ciphersuites(&g_caSslContext->serverTlsConf,
2753                                          tlsCipher[SSL_ECDHE_ECDSA_WITH_AES_128_CCM]);
2754     g_caSslContext->cipher = SSL_ECDHE_ECDSA_WITH_AES_128_CCM;
2755
2756     CAdeinitSslAdapter();
2757
2758     if (g_caSslContext != NULL ||
2759         g_sslContextMutex != NULL)
2760     {
2761         ret = 1;
2762     }
2763     else
2764     {
2765         ret = 0;
2766     }
2767     return ret;
2768 }
2769
2770 // CAdeinitSslAdapter()
2771 TEST(TLSAdaper, Test_6)
2772 {
2773     int ret = 0xFF;
2774     ret = testCAdeinitSslAdapter();
2775     EXPECT_EQ(0, ret);
2776 }
2777
2778 /* **************************
2779  *
2780  *
2781  * Server side test
2782  *
2783  *
2784  * *************************/
2785
2786 static void * testServer(void * arg)
2787 {
2788     CAEndpoint_t serverAddr;
2789     serverAddr.adapter = CA_ADAPTER_TCP;
2790     serverAddr.flags = CA_SECURE;
2791     serverAddr.port = 4432;
2792     char addr[] = {0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x00}; // 127.0.0.1
2793     memcpy(serverAddr.addr, addr, sizeof(addr));
2794     serverAddr.ifindex = 0;
2795     unsigned char buffer[2048] = {'\0'};
2796     int buflen = 0;
2797
2798     CAinitSslAdapter();
2799
2800     CAsetSslAdapterCallbacks(CATCPPacketReceivedCB_server, CATCPPacketSendCB_server, CA_ADAPTER_TCP);
2801     CAsetPkixInfoCallback(infoCallback_that_loads_x509);
2802
2803     // CAsetCredentialTypesCallback
2804     g_getCredentialTypesCallback = clutch;
2805
2806     CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM);
2807
2808     CAsetPskCredentialsCallback(GetDtlsPskCredentials);
2809
2810     socketOpen_server();
2811
2812     CASecureEndpoint_t * sep = (CASecureEndpoint_t *) malloc (sizeof(CASecureEndpoint_t));
2813     sep->endpoint = serverAddr;
2814
2815     for (int i = 0; i < 7; i++)
2816     {
2817         PacketReceive_server(buffer, &buflen);
2818         CAdecryptSsl(sep, (uint8_t *)buffer, buflen);
2819     }
2820
2821     CAcloseSslConnection(&serverAddr);
2822
2823     // CAdeinitSslAdapter
2824     oc_mutex_lock(g_sslContextMutex);
2825     DeletePeerList();
2826     mbedtls_x509_crt_free(&g_caSslContext->crt);
2827     mbedtls_pk_free(&g_caSslContext->pkey);
2828     mbedtls_ssl_config_free(&g_caSslContext->clientTlsConf);
2829     mbedtls_ssl_config_free(&g_caSslContext->serverTlsConf);
2830     mbedtls_ctr_drbg_free(&g_caSslContext->rnd);
2831     mbedtls_entropy_free(&g_caSslContext->entropy);
2832     OICFree(g_caSslContext);
2833     g_caSslContext = NULL;
2834     oc_mutex_unlock(g_sslContextMutex);
2835     oc_mutex_free(g_sslContextMutex);
2836     g_sslContextMutex = NULL;
2837
2838     socketClose_server();
2839
2840     if (control_client_message_len == msglen && memcmp(msg, control_client_message,
2841                                                             control_client_message_len) == 0)
2842     {
2843         *((int*)arg) = 0;
2844         return NULL;
2845     }
2846     else
2847     {
2848         *((int*)arg) = 0xFF;
2849         return (void *) 0xFF;
2850     }
2851 }
2852
2853 TEST(TLSAdaper, Test_7)
2854 {
2855     pthread_t thread1, thread2;
2856     int ret = 0;
2857     int arg = 1;
2858
2859     ret = pthread_create( &thread1, NULL, testServer, &arg);
2860     if (ret)
2861     {
2862         fprintf(stderr,"Error - pthread_create() return code: %d\n", ret);
2863         exit(EXIT_FAILURE);
2864     }
2865
2866     sleep(5);
2867
2868     ret = pthread_create( &thread2, NULL, client, (void*) NULL);
2869     if (ret)
2870     {
2871         fprintf(stderr,"Error - pthread_create() return code: %d\n", ret);
2872         exit(EXIT_FAILURE);
2873     }
2874
2875     sleep(5);
2876
2877     EXPECT_EQ(NULL, arg);
2878 }
2879
2880 /* **************************
2881  *
2882  * CAsetPskCredentialsCallback test
2883  * CAsetPkixInfoCallback test
2884  * CAsetCredentialTypesCallback test
2885  *
2886  * *************************/
2887
2888 static int testCAsetPskCredentialsCallback()
2889 {
2890     static CAgetPskCredentialsHandler credCallback = (CAgetPskCredentialsHandler)dummyHandler;
2891     CAsetPskCredentialsCallback(credCallback);
2892     if (g_getCredentialsCallback == (CAgetPskCredentialsHandler)dummyHandler)
2893     {
2894         return 0;
2895     }
2896     else
2897     {
2898         return 1;
2899     }
2900 }
2901
2902 static int testCAsetPkixInfoCallback()
2903 {
2904     static CAgetPkixInfoHandler infoCallback = (CAgetPkixInfoHandler)dummyHandler;
2905     CAsetPkixInfoCallback(infoCallback);
2906     if (g_getPkixInfoCallback == (CAgetPkixInfoHandler)dummyHandler)
2907     {
2908         return 0;
2909     }
2910     else
2911     {
2912         return 1;
2913     }
2914 }
2915
2916 static int testCAsetCredentialTypesCallback()
2917 {
2918     static CAgetCredentialTypesHandler credTypesCallback = (CAgetCredentialTypesHandler)dummyHandler;
2919     CAsetCredentialTypesCallback(credTypesCallback);
2920     if (g_getCredentialTypesCallback == (CAgetCredentialTypesHandler)dummyHandler)
2921     {
2922         return 0;
2923     }
2924     else
2925     {
2926         return 1;
2927     }
2928 }
2929
2930 // CAsetPskCredentialsCallback()
2931 TEST(TLSAdaper, Test_9_0)
2932 {
2933     int ret = 0xFF;
2934     ret = testCAsetPskCredentialsCallback();
2935     EXPECT_EQ(0, ret);
2936 }
2937 // CAsetPkixInfoCallback()
2938 TEST(TLSAdaper, Test_9_1)
2939 {
2940     int ret = 0xFF;
2941     ret = testCAsetPkixInfoCallback();
2942     EXPECT_EQ(0, ret);
2943 }
2944 // CAsetCredentialTypesCallback()
2945 TEST(TLSAdaper, Test_9_2)
2946 {
2947     int ret = 0xFF;
2948     ret = testCAsetCredentialTypesCallback();
2949     EXPECT_EQ(0, ret);
2950 }
2951
2952 /* **************************
2953  *
2954  *
2955  * CAsetTlsCipherSuite test
2956  *
2957  *
2958  * *************************/
2959
2960 static int testCAsetTlsCipherSuite()
2961 {
2962     int ret = 0, status = 0;
2963     CAEndpoint_t serverAddr;
2964     serverAddr.adapter = CA_ADAPTER_TCP;
2965     serverAddr.flags = CA_SECURE;
2966     serverAddr.port = 4433;
2967     char addr[] = {0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x00}; // 127.0.0.1
2968     memcpy(serverAddr.addr, addr, sizeof(addr));
2969     serverAddr.ifindex = 0;
2970
2971     CAinitSslAdapter();
2972
2973     // CAsetCredentialTypesCallback
2974     g_getCredentialTypesCallback = clutch;
2975
2976     status = CAsetTlsCipherSuite(MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256);
2977     if (SSL_RSA_WITH_AES_256_CBC_SHA256 != g_caSslContext->cipher || status != CA_STATUS_OK)
2978     {
2979         ret += 1;
2980     }
2981
2982     status = CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256);
2983     if (SSL_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 != g_caSslContext->cipher || status != CA_STATUS_OK)
2984     {
2985         ret += 1;
2986     }
2987     status = CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8);
2988     if (SSL_ECDHE_ECDSA_WITH_AES_128_CCM_8 != g_caSslContext->cipher || status != CA_STATUS_OK)
2989     {
2990         ret += 1;
2991     }
2992
2993     status = CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM);
2994     if (SSL_ECDHE_ECDSA_WITH_AES_128_CCM != g_caSslContext->cipher || status != CA_STATUS_OK)
2995     {
2996         ret += 1;
2997     }
2998
2999     status = CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256);
3000     if (SSL_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 != g_caSslContext->cipher || status != CA_STATUS_OK)
3001     {
3002         ret += 1;
3003     }
3004
3005     status = CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384);
3006     if (SSL_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 != g_caSslContext->cipher || status != CA_STATUS_OK)
3007     {
3008         ret += 1;
3009     }
3010
3011     status = CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384);
3012     if (SSL_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 != g_caSslContext->cipher || status != CA_STATUS_OK)
3013     {
3014         ret += 1;
3015     }
3016
3017     status = CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256);
3018     if (SSL_ECDHE_PSK_WITH_AES_128_CBC_SHA256 != g_caSslContext->cipher || status != CA_STATUS_OK)
3019     {
3020         ret += 1;
3021     }
3022
3023     status = CAsetTlsCipherSuite(MBEDTLS_TLS_ECDH_ANON_WITH_AES_128_CBC_SHA256);
3024     if (SSL_ECDH_ANON_WITH_AES_128_CBC_SHA256 != g_caSslContext->cipher || status != CA_STATUS_OK)
3025     {
3026         ret += 1;
3027     }
3028
3029     status = CAsetTlsCipherSuite(dummyHandler);
3030     if (CA_STATUS_FAILED != status)
3031     {
3032         ret += 1;
3033     }
3034
3035     // CAdeinitSslAdapter
3036     oc_mutex_lock(g_sslContextMutex);
3037     DeletePeerList();
3038     mbedtls_x509_crt_free(&g_caSslContext->crt);
3039     mbedtls_pk_free(&g_caSslContext->pkey);
3040     mbedtls_ssl_config_free(&g_caSslContext->clientTlsConf);
3041     mbedtls_ssl_config_free(&g_caSslContext->serverTlsConf);
3042     mbedtls_ctr_drbg_free(&g_caSslContext->rnd);
3043     mbedtls_entropy_free(&g_caSslContext->entropy);
3044     OICFree(g_caSslContext);
3045     g_caSslContext = NULL;
3046     oc_mutex_unlock(g_sslContextMutex);
3047     oc_mutex_free(g_sslContextMutex);
3048     g_sslContextMutex = NULL;
3049
3050     return ret;
3051 }
3052
3053 // CAinitTlsAdapter()
3054 TEST(TLSAdaper, Test_10)
3055 {
3056     int ret = 0xff;
3057     ret = testCAsetTlsCipherSuite();
3058     EXPECT_EQ(0, ret);
3059 }
3060
3061 static void * testCAsslGenerateOwnerPsk(void * arg)
3062 {
3063     int ret = 0;
3064     CAEndpoint_t serverAddr;
3065     serverAddr.adapter = CA_ADAPTER_TCP;
3066     serverAddr.flags = CA_SECURE;
3067     serverAddr.port = 4433;
3068     char addr[] = {0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x00}; // 127.0.0.1
3069     memcpy(serverAddr.addr, addr, sizeof(addr));
3070     serverAddr.ifindex = 0;
3071
3072     uint8_t label[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A};
3073     uint8_t rsrcServerDeviceId[] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A};
3074     uint8_t provServerDeviceId[] = {0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A};
3075     uint8_t ownerPsk[0x100] = {0x00};
3076     uint8_t predictedPSK[] = {
3077         0xba, 0x72, 0x16, 0xbc, 0x7f, 0x8c, 0xfe, 0xfc, 0xd0, 0xac, 0x1a, 0x37, 0xad, 0x60, 0xe8, 0x9e,
3078         0xb3, 0x31, 0xa2, 0x30, 0xaf, 0x68, 0xc9, 0xa6, 0x89, 0x8a, 0x04, 0x21, 0x6c, 0xbd, 0x04, 0x08,
3079         0x68, 0x11, 0x54, 0x9e, 0x2a, 0x10, 0x91, 0x94, 0x3c, 0x44, 0x52, 0xc7, 0xfa, 0x78, 0x44, 0x87,
3080         0xea, 0x30, 0x08, 0x5f, 0xc1, 0x64, 0xaa, 0x0d, 0xfd, 0x84, 0x16, 0x83, 0x20, 0xc9, 0x08, 0x65,
3081         0xd2, 0x4a, 0x55, 0x9e, 0x8f, 0x88, 0x3c, 0x57, 0x10, 0xbd, 0x5a, 0x30, 0x01, 0xb4, 0x59, 0x63,
3082         0x64, 0x19, 0x8d, 0xfa, 0x5c, 0x86, 0x92, 0xf7, 0x60, 0x99, 0xdb, 0xae, 0x0e, 0xad, 0x80, 0xf1,
3083         0x82, 0xaf, 0x1b, 0x14, 0x0c, 0x99, 0x13, 0x53, 0x54, 0x33, 0x6a, 0x17, 0x24, 0x5c, 0x9d, 0xdb,
3084         0x5a, 0xfb, 0x73, 0x2f, 0x41, 0xe8, 0xeb, 0x2e, 0x68, 0xfe, 0xee, 0x0b, 0xdc, 0x54, 0x50, 0xf1,
3085         0x1e, 0x16, 0x19, 0x2c, 0x4e, 0xb6, 0x97, 0x9f, 0x9c, 0x32, 0x9c, 0x0e, 0xe0, 0xe1, 0x32, 0x64,
3086         0x16, 0x34, 0x53, 0x8e, 0xc5, 0xe3, 0xe5, 0xbc, 0x2c, 0x10, 0xae, 0x81, 0x2c, 0x1a, 0xb2, 0xb7,
3087         0xa3, 0xbe, 0x0f, 0xab, 0xfd, 0xf7, 0x87, 0x53, 0xcd, 0x3e, 0x31, 0xfb, 0x2d, 0x69, 0x6a, 0xd5,
3088         0xc3, 0x27, 0x04, 0x2b, 0x37, 0x02, 0x91, 0x05, 0x0c, 0x4e, 0x2a, 0xfc, 0x6c, 0x42, 0xe8, 0x37,
3089         0x23, 0x2f, 0x60, 0x6e, 0x0c, 0xed, 0x7c, 0xe0, 0x5f, 0x47, 0xb3, 0x51, 0x86, 0x5b, 0x26, 0x08,
3090         0x2a, 0x05, 0x89, 0xb0, 0xdd, 0x6f, 0xc6, 0x76, 0xc5, 0x2a, 0x60, 0x07, 0x0e, 0xb1, 0x71, 0x67,
3091         0x21, 0x11, 0xf8, 0xb5, 0x52, 0xa3, 0xf3, 0xf0, 0xd4, 0x5f, 0xdf, 0x44, 0x66, 0x23, 0xd8, 0x4e,
3092         0xbd, 0x64, 0x39, 0x43, 0x03, 0x37, 0xaa, 0xd7, 0xea, 0xb3, 0x6d, 0x2f, 0x84, 0x9c, 0x02, 0x49
3093     };
3094
3095     // CAinitTlsAdapter
3096     g_sslContextMutex = oc_mutex_new();
3097     oc_mutex_lock(g_sslContextMutex);
3098     g_caSslContext = (SslContext_t *)OICCalloc(1, sizeof(SslContext_t));
3099     g_caSslContext->peerList = u_arraylist_create();
3100     mbedtls_entropy_init(&g_caSslContext->entropy);
3101     mbedtls_ctr_drbg_init(&g_caSslContext->rnd);
3102     unsigned char * seed = (unsigned char*) SEED;
3103     mbedtls_ctr_drbg_seed(&g_caSslContext->rnd, mbedtls_entropy_func_clutch,
3104                                   &g_caSslContext->entropy, seed, sizeof(SEED));
3105     mbedtls_ctr_drbg_set_prediction_resistance(&g_caSslContext->rnd, MBEDTLS_CTR_DRBG_PR_OFF);
3106     mbedtls_ssl_config_init(&g_caSslContext->clientTlsConf);
3107     mbedtls_ssl_config_defaults(&g_caSslContext->clientTlsConf, MBEDTLS_SSL_IS_CLIENT,
3108                                     MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT);
3109     mbedtls_ssl_conf_psk_cb(&g_caSslContext->clientTlsConf, GetPskCredentialsCallback, NULL);
3110     mbedtls_ssl_conf_rng( &g_caSslContext->clientTlsConf, mbedtls_ctr_drbg_random,
3111                           &g_caSslContext->rnd);
3112     mbedtls_ssl_conf_curves(&g_caSslContext->clientTlsConf, curve[ADAPTER_CURVE_SECP256R1]);
3113     mbedtls_ssl_conf_min_version(&g_caSslContext->clientTlsConf, MBEDTLS_SSL_MAJOR_VERSION_3,
3114                                  MBEDTLS_SSL_MINOR_VERSION_3);
3115     mbedtls_ssl_conf_authmode(&g_caSslContext->clientTlsConf, MBEDTLS_SSL_VERIFY_REQUIRED);
3116     CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256);
3117     mbedtls_x509_crt_init(&g_caSslContext->ca);
3118     mbedtls_x509_crt_init(&g_caSslContext->crt);
3119     mbedtls_pk_init(&g_caSslContext->pkey);
3120     mbedtls_x509_crl_init(&g_caSslContext->crl);
3121     oc_mutex_unlock(g_sslContextMutex);
3122
3123     // CAsetTlsAdapterCallbacks
3124     CAsetSslAdapterCallbacks(CATCPPacketReceivedCB, CATCPPacketSendCB, CA_ADAPTER_TCP);
3125
3126     // CAsetPkixInfoCallback
3127     CAsetPkixInfoCallback(infoCallback_that_loads_x509);
3128
3129     // CAsetCredentialTypesCallback
3130     g_getCredentialTypesCallback = clutch;
3131
3132     CAsetTlsCipherSuite(MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256);
3133
3134     CAsetPskCredentialsCallback(GetDtlsPskCredentials);
3135
3136     socketConnect();
3137
3138     // CAinitiateSslHandshake
3139     oc_mutex_lock(g_sslContextMutex);
3140     InitiateTlsHandshake(&serverAddr);
3141     oc_mutex_unlock(g_sslContextMutex);
3142
3143     ret = CAsslGenerateOwnerPsk(&serverAddr,
3144           label, sizeof(label),
3145           rsrcServerDeviceId, sizeof(rsrcServerDeviceId),
3146           provServerDeviceId, sizeof(provServerDeviceId),
3147           ownerPsk, 0x100);
3148
3149     // CAcloseTlsConnection
3150     oc_mutex_lock(g_sslContextMutex);
3151     SslEndPoint_t * tep = GetSslPeer(&serverAddr);
3152     mbedtls_ssl_close_notify(&tep->ssl);
3153     RemovePeerFromList(&tep->sep.endpoint);
3154     oc_mutex_unlock(g_sslContextMutex);
3155
3156     // CAdeinitTlsAdapter
3157     oc_mutex_lock(g_sslContextMutex);
3158     DeletePeerList();
3159     mbedtls_x509_crt_free(&g_caSslContext->crt);
3160     mbedtls_pk_free(&g_caSslContext->pkey);
3161     mbedtls_ssl_config_free(&g_caSslContext->clientTlsConf);
3162     mbedtls_ssl_config_free(&g_caSslContext->serverTlsConf);
3163     mbedtls_ctr_drbg_free(&g_caSslContext->rnd);
3164     mbedtls_entropy_free(&g_caSslContext->entropy);
3165     OICFree(g_caSslContext);
3166     g_caSslContext = NULL;
3167     oc_mutex_unlock(g_sslContextMutex);
3168     oc_mutex_free(g_sslContextMutex);
3169     g_sslContextMutex = NULL;
3170
3171     socketClose();
3172
3173     if (ret == 0 && memcmp(predictedPSK, ownerPsk, sizeof(predictedPSK)) == 0)
3174     {
3175         *((int*)arg) = 0;
3176         return NULL;
3177     }
3178     else
3179     {
3180         *((int*)arg) = 0xFF;
3181         return (void *) 0xFF;
3182     }
3183 }
3184
3185 TEST(TLSAdaper, Test_11)
3186 {
3187     pthread_t thread1, thread2;
3188     int ret = 0;
3189     int arg = 1;
3190
3191     ret = pthread_create( &thread1, NULL, server, (void*) NULL);
3192     if(ret)
3193     {
3194         fprintf(stderr, "Error - pthread_create() return code: %d\n", ret);
3195         exit(EXIT_FAILURE);
3196     }
3197
3198     sleep(5);
3199
3200     ret = pthread_create( &thread2, NULL, testCAsslGenerateOwnerPsk, &arg);
3201     if(ret)
3202     {
3203         fprintf(stderr, "Error - pthread_create() return code: %d\n", ret);
3204         exit(EXIT_FAILURE);
3205     }
3206
3207     sleep(5);
3208
3209     EXPECT_EQ(0, arg);
3210 }
3211
3212 TEST(TLSAdaper, Test_ParseChain)
3213 {
3214     int errNum;
3215     mbedtls_x509_crt crt;
3216     mbedtls_x509_crt_init(&crt);
3217     int ret = ParseChain(&crt, certChain, certChainLen, &errNum);
3218     mbedtls_x509_crt_free(&crt);
3219
3220     EXPECT_EQ(10, ret + errNum);
3221 }