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