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