Debian Codegraph @

lib_pypy/_cffi_ssl/osx-roots.diff

raw
1 diff -Naur libressl-2.6.2.orig/crypto/Makefile.am libressl-2.6.2/crypto/Makefile.am
2 --- libressl-2.6.2.orig/crypto/Makefile.am 2017-09-02 01:49:55.000000000 +0200
3 +++ libressl-2.6.2/crypto/Makefile.am 2017-10-07 14:05:16.000000000 +0200
4 @@ -92,7 +92,7 @@
5 -mv crypto_portable.sym.tmp crypto_portable.sym
6 endif
7
8 -libcrypto_la_LDFLAGS = -version-info @LIBCRYPTO_VERSION@ -no-undefined -export-symbols crypto_portable.sym
9 +libcrypto_la_LDFLAGS = -version-info @LIBCRYPTO_VERSION@ -no-undefined -export-symbols crypto_portable.sym -framework Security -framework CoreFoundation
10 libcrypto_la_LIBADD = libcompat.la
11 if !HAVE_EXPLICIT_BZERO
12 libcrypto_la_LIBADD += libcompatnoopt.la
13 @@ -863,6 +863,7 @@
14 libcrypto_la_SOURCES += x509/x509_txt.c
15 libcrypto_la_SOURCES += x509/x509_v3.c
16 libcrypto_la_SOURCES += x509/x509_vfy.c
17 +libcrypto_la_SOURCES += x509/x509_vfy_apple.c
18 libcrypto_la_SOURCES += x509/x509_vpm.c
19 libcrypto_la_SOURCES += x509/x509cset.c
20 libcrypto_la_SOURCES += x509/x509name.c
21 diff -Naur libressl-2.6.2.orig/crypto/Makefile.in libressl-2.6.2/crypto/Makefile.in
22 --- libressl-2.6.2.orig/crypto/Makefile.in 2017-09-26 06:07:03.000000000 +0200
23 +++ libressl-2.6.2/crypto/Makefile.in 2017-10-07 14:05:24.000000000 +0200
24 @@ -426,20 +426,20 @@
25 x509/x509_err.c x509/x509_ext.c x509/x509_lu.c x509/x509_obj.c \
26 x509/x509_r2x.c x509/x509_req.c x509/x509_set.c \
27 x509/x509_trs.c x509/x509_txt.c x509/x509_v3.c x509/x509_vfy.c \
28 - x509/x509_vpm.c x509/x509cset.c x509/x509name.c \
29 - x509/x509rset.c x509/x509spki.c x509/x509type.c x509/x_all.c \
30 - x509v3/pcy_cache.c x509v3/pcy_data.c x509v3/pcy_lib.c \
31 - x509v3/pcy_map.c x509v3/pcy_node.c x509v3/pcy_tree.c \
32 - x509v3/v3_akey.c x509v3/v3_akeya.c x509v3/v3_alt.c \
33 - x509v3/v3_bcons.c x509v3/v3_bitst.c x509v3/v3_conf.c \
34 - x509v3/v3_cpols.c x509v3/v3_crld.c x509v3/v3_enum.c \
35 - x509v3/v3_extku.c x509v3/v3_genn.c x509v3/v3_ia5.c \
36 - x509v3/v3_info.c x509v3/v3_int.c x509v3/v3_lib.c \
37 - x509v3/v3_ncons.c x509v3/v3_ocsp.c x509v3/v3_pci.c \
38 - x509v3/v3_pcia.c x509v3/v3_pcons.c x509v3/v3_pku.c \
39 - x509v3/v3_pmaps.c x509v3/v3_prn.c x509v3/v3_purp.c \
40 - x509v3/v3_skey.c x509v3/v3_sxnet.c x509v3/v3_utl.c \
41 - x509v3/v3err.c
42 + x509/x509_vfy_apple.c x509/x509_vpm.c x509/x509cset.c \
43 + x509/x509name.c x509/x509rset.c x509/x509spki.c \
44 + x509/x509type.c x509/x_all.c x509v3/pcy_cache.c \
45 + x509v3/pcy_data.c x509v3/pcy_lib.c x509v3/pcy_map.c \
46 + x509v3/pcy_node.c x509v3/pcy_tree.c x509v3/v3_akey.c \
47 + x509v3/v3_akeya.c x509v3/v3_alt.c x509v3/v3_bcons.c \
48 + x509v3/v3_bitst.c x509v3/v3_conf.c x509v3/v3_cpols.c \
49 + x509v3/v3_crld.c x509v3/v3_enum.c x509v3/v3_extku.c \
50 + x509v3/v3_genn.c x509v3/v3_ia5.c x509v3/v3_info.c \
51 + x509v3/v3_int.c x509v3/v3_lib.c x509v3/v3_ncons.c \
52 + x509v3/v3_ocsp.c x509v3/v3_pci.c x509v3/v3_pcia.c \
53 + x509v3/v3_pcons.c x509v3/v3_pku.c x509v3/v3_pmaps.c \
54 + x509v3/v3_prn.c x509v3/v3_purp.c x509v3/v3_skey.c \
55 + x509v3/v3_sxnet.c x509v3/v3_utl.c x509v3/v3err.c
56 am__objects_27 = aes/libcrypto_la-aes-elf-x86_64.lo \
57 aes/libcrypto_la-bsaes-elf-x86_64.lo \
58 aes/libcrypto_la-vpaes-elf-x86_64.lo \
59 @@ -759,11 +759,12 @@
60 x509/libcrypto_la-x509_r2x.lo x509/libcrypto_la-x509_req.lo \
61 x509/libcrypto_la-x509_set.lo x509/libcrypto_la-x509_trs.lo \
62 x509/libcrypto_la-x509_txt.lo x509/libcrypto_la-x509_v3.lo \
63 - x509/libcrypto_la-x509_vfy.lo x509/libcrypto_la-x509_vpm.lo \
64 - x509/libcrypto_la-x509cset.lo x509/libcrypto_la-x509name.lo \
65 - x509/libcrypto_la-x509rset.lo x509/libcrypto_la-x509spki.lo \
66 - x509/libcrypto_la-x509type.lo x509/libcrypto_la-x_all.lo \
67 - x509v3/libcrypto_la-pcy_cache.lo \
68 + x509/libcrypto_la-x509_vfy.lo \
69 + x509/libcrypto_la-x509_vfy_apple.lo \
70 + x509/libcrypto_la-x509_vpm.lo x509/libcrypto_la-x509cset.lo \
71 + x509/libcrypto_la-x509name.lo x509/libcrypto_la-x509rset.lo \
72 + x509/libcrypto_la-x509spki.lo x509/libcrypto_la-x509type.lo \
73 + x509/libcrypto_la-x_all.lo x509v3/libcrypto_la-pcy_cache.lo \
74 x509v3/libcrypto_la-pcy_data.lo x509v3/libcrypto_la-pcy_lib.lo \
75 x509v3/libcrypto_la-pcy_map.lo x509v3/libcrypto_la-pcy_node.lo \
76 x509v3/libcrypto_la-pcy_tree.lo x509v3/libcrypto_la-v3_akey.lo \
77 @@ -1000,7 +1001,7 @@
78 $(ASM_X86_64_ELF) $(ASM_X86_64_MACOSX)
79 BUILT_SOURCES = crypto_portable.sym
80 CLEANFILES = crypto_portable.sym
81 -libcrypto_la_LDFLAGS = -version-info @LIBCRYPTO_VERSION@ -no-undefined -export-symbols crypto_portable.sym
82 +libcrypto_la_LDFLAGS = -version-info @LIBCRYPTO_VERSION@ -no-undefined -export-symbols crypto_portable.sym -framework Security -framework CoreFoundation
83 libcrypto_la_LIBADD = libcompat.la $(am__append_1)
84 libcrypto_la_CPPFLAGS = $(AM_CPPFLAGS) -DLIBRESSL_INTERNAL \
85 -DOPENSSL_NO_HW_PADLOCK $(am__append_2) $(am__append_3) \
86 @@ -1272,20 +1273,20 @@
87 x509/x509_err.c x509/x509_ext.c x509/x509_lu.c x509/x509_obj.c \
88 x509/x509_r2x.c x509/x509_req.c x509/x509_set.c \
89 x509/x509_trs.c x509/x509_txt.c x509/x509_v3.c x509/x509_vfy.c \
90 - x509/x509_vpm.c x509/x509cset.c x509/x509name.c \
91 - x509/x509rset.c x509/x509spki.c x509/x509type.c x509/x_all.c \
92 - x509v3/pcy_cache.c x509v3/pcy_data.c x509v3/pcy_lib.c \
93 - x509v3/pcy_map.c x509v3/pcy_node.c x509v3/pcy_tree.c \
94 - x509v3/v3_akey.c x509v3/v3_akeya.c x509v3/v3_alt.c \
95 - x509v3/v3_bcons.c x509v3/v3_bitst.c x509v3/v3_conf.c \
96 - x509v3/v3_cpols.c x509v3/v3_crld.c x509v3/v3_enum.c \
97 - x509v3/v3_extku.c x509v3/v3_genn.c x509v3/v3_ia5.c \
98 - x509v3/v3_info.c x509v3/v3_int.c x509v3/v3_lib.c \
99 - x509v3/v3_ncons.c x509v3/v3_ocsp.c x509v3/v3_pci.c \
100 - x509v3/v3_pcia.c x509v3/v3_pcons.c x509v3/v3_pku.c \
101 - x509v3/v3_pmaps.c x509v3/v3_prn.c x509v3/v3_purp.c \
102 - x509v3/v3_skey.c x509v3/v3_sxnet.c x509v3/v3_utl.c \
103 - x509v3/v3err.c
104 + x509/x509_vfy_apple.c x509/x509_vpm.c x509/x509cset.c \
105 + x509/x509name.c x509/x509rset.c x509/x509spki.c \
106 + x509/x509type.c x509/x_all.c x509v3/pcy_cache.c \
107 + x509v3/pcy_data.c x509v3/pcy_lib.c x509v3/pcy_map.c \
108 + x509v3/pcy_node.c x509v3/pcy_tree.c x509v3/v3_akey.c \
109 + x509v3/v3_akeya.c x509v3/v3_alt.c x509v3/v3_bcons.c \
110 + x509v3/v3_bitst.c x509v3/v3_conf.c x509v3/v3_cpols.c \
111 + x509v3/v3_crld.c x509v3/v3_enum.c x509v3/v3_extku.c \
112 + x509v3/v3_genn.c x509v3/v3_ia5.c x509v3/v3_info.c \
113 + x509v3/v3_int.c x509v3/v3_lib.c x509v3/v3_ncons.c \
114 + x509v3/v3_ocsp.c x509v3/v3_pci.c x509v3/v3_pcia.c \
115 + x509v3/v3_pcons.c x509v3/v3_pku.c x509v3/v3_pmaps.c \
116 + x509v3/v3_prn.c x509v3/v3_purp.c x509v3/v3_skey.c \
117 + x509v3/v3_sxnet.c x509v3/v3_utl.c x509v3/v3err.c
118
119 # chacha
120
121 @@ -2808,6 +2809,8 @@
122 x509/$(DEPDIR)/$(am__dirstamp)
123 x509/libcrypto_la-x509_vfy.lo: x509/$(am__dirstamp) \
124 x509/$(DEPDIR)/$(am__dirstamp)
125 +x509/libcrypto_la-x509_vfy_apple.lo: x509/$(am__dirstamp) \
126 + x509/$(DEPDIR)/$(am__dirstamp)
127 x509/libcrypto_la-x509_vpm.lo: x509/$(am__dirstamp) \
128 x509/$(DEPDIR)/$(am__dirstamp)
129 x509/libcrypto_la-x509cset.lo: x509/$(am__dirstamp) \
130 @@ -3583,6 +3586,7 @@
131 @AMDEP_TRUE@@am__include@ @am__quote@x509/$(DEPDIR)/libcrypto_la-x509_txt.Plo@am__quote@
132 @AMDEP_TRUE@@am__include@ @am__quote@x509/$(DEPDIR)/libcrypto_la-x509_v3.Plo@am__quote@
133 @AMDEP_TRUE@@am__include@ @am__quote@x509/$(DEPDIR)/libcrypto_la-x509_vfy.Plo@am__quote@
134 +@AMDEP_TRUE@@am__include@ @am__quote@x509/$(DEPDIR)/libcrypto_la-x509_vfy_apple.Plo@am__quote@
135 @AMDEP_TRUE@@am__include@ @am__quote@x509/$(DEPDIR)/libcrypto_la-x509_vpm.Plo@am__quote@
136 @AMDEP_TRUE@@am__include@ @am__quote@x509/$(DEPDIR)/libcrypto_la-x509cset.Plo@am__quote@
137 @AMDEP_TRUE@@am__include@ @am__quote@x509/$(DEPDIR)/libcrypto_la-x509name.Plo@am__quote@
138 @@ -7460,6 +7464,13 @@
139 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
140 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcrypto_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o x509/libcrypto_la-x509_vfy.lo `test -f 'x509/x509_vfy.c' || echo '$(srcdir)/'`x509/x509_vfy.c
141
142 +x509/libcrypto_la-x509_vfy_apple.lo: x509/x509_vfy_apple.c
143 +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcrypto_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT x509/libcrypto_la-x509_vfy_apple.lo -MD -MP -MF x509/$(DEPDIR)/libcrypto_la-x509_vfy_apple.Tpo -c -o x509/libcrypto_la-x509_vfy_apple.lo `test -f 'x509/x509_vfy_apple.c' || echo '$(srcdir)/'`x509/x509_vfy_apple.c
144 +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) x509/$(DEPDIR)/libcrypto_la-x509_vfy_apple.Tpo x509/$(DEPDIR)/libcrypto_la-x509_vfy_apple.Plo
145 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='x509/x509_vfy_apple.c' object='x509/libcrypto_la-x509_vfy_apple.lo' libtool=yes @AMDEPBACKSLASH@
146 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
147 +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcrypto_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o x509/libcrypto_la-x509_vfy_apple.lo `test -f 'x509/x509_vfy_apple.c' || echo '$(srcdir)/'`x509/x509_vfy_apple.c
148 +
149 x509/libcrypto_la-x509_vpm.lo: x509/x509_vpm.c
150 @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcrypto_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT x509/libcrypto_la-x509_vpm.lo -MD -MP -MF x509/$(DEPDIR)/libcrypto_la-x509_vpm.Tpo -c -o x509/libcrypto_la-x509_vpm.lo `test -f 'x509/x509_vpm.c' || echo '$(srcdir)/'`x509/x509_vpm.c
151 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) x509/$(DEPDIR)/libcrypto_la-x509_vpm.Tpo x509/$(DEPDIR)/libcrypto_la-x509_vpm.Plo
152 diff -Naur libressl-2.6.2.orig/crypto/x509/x509_vfy.c libressl-2.6.2/crypto/x509/x509_vfy.c
153 --- libressl-2.6.2.orig/crypto/x509/x509_vfy.c 2017-09-02 14:01:08.000000000 +0200
154 +++ libressl-2.6.2/crypto/x509/x509_vfy.c 2017-10-07 14:05:16.000000000 +0200
155 @@ -115,6 +115,13 @@
156
157 #define CRL_SCORE_TIME_DELTA 0x002
158
159 +/*
160 + * If we are using Trust Evaluation Agent, rename the original function
161 + */
162 +#ifdef __APPLE__
163 +#define X509_verify_cert X509_verify_cert_orig
164 +#endif
165 +
166 static int null_callback(int ok, X509_STORE_CTX *e);
167 static int check_issued(X509_STORE_CTX *ctx, X509 *x, X509 *issuer);
168 static X509 *find_issuer(X509_STORE_CTX *ctx, STACK_OF(X509) *sk, X509 *x);
169 diff -Naur libressl-2.6.2.orig/crypto/x509/x509_vfy_apple.c libressl-2.6.2/crypto/x509/x509_vfy_apple.c
170 --- libressl-2.6.2.orig/crypto/x509/x509_vfy_apple.c 1970-01-01 01:00:00.000000000 +0100
171 +++ libressl-2.6.2/crypto/x509/x509_vfy_apple.c 2017-10-07 14:05:16.000000000 +0200
172 @@ -0,0 +1,225 @@
173 +/*
174 + * Copyright (c) 2009 Apple Inc. All Rights Reserved.
175 + *
176 + * @APPLE_LICENSE_HEADER_START@
177 + *
178 + * This file contains Original Code and/or Modifications of Original Code
179 + * as defined in and that are subject to the Apple Public Source License
180 + * Version 2.0 (the 'License'). You may not use this file except in
181 + * compliance with the License. Please obtain a copy of the License at
182 + * http://www.opensource.apple.com/apsl/ and read it before using this
183 + * file.
184 + *
185 + * The Original Code and all software distributed under the License are
186 + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
187 + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
188 + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
189 + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
190 + * Please see the License for the specific language governing rights and
191 + * limitations under the License.
192 + *
193 + * @APPLE_LICENSE_HEADER_END@
194 + *
195 + */
196 +
197 +#include <stdint.h>
198 +#include <inttypes.h>
199 +#include <syslog.h>
200 +
201 +#include <Security/Security.h>
202 +
203 +#include <openssl/opensslconf.h>
204 +
205 +#include <openssl/crypto.h>
206 +#include <openssl/x509.h>
207 +#include <openssl/x509v3.h>
208 +
209 +#include "cryptlib.h"
210 +#include "vpm_int.h"
211 +#include "x509_vfy_apple.h"
212 +
213 +#define TEA_might_correct_error(err) (err == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY || err == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT || err == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN)
214 +
215 +
216 +static bool add_cert_to_array(CFMutableArrayRef array, X509 *x509)
217 +{
218 + unsigned char *asn1_cert_data = NULL;
219 + int asn1_cert_len = i2d_X509(x509, &asn1_cert_data);
220 +
221 + CFDataRef data = CFDataCreate(kCFAllocatorDefault, asn1_cert_data, asn1_cert_len);
222 +
223 + if (data == NULL) {
224 + return false;
225 + }
226 +
227 + SecCertificateRef cert = SecCertificateCreateWithData(NULL, data);
228 +
229 + free(asn1_cert_data);
230 +
231 + if (cert == NULL) {
232 + CFRelease(data);
233 + return false;
234 + }
235 +
236 + CFArrayAppendValue(array, cert);
237 + CFRelease(data);
238 +
239 + return true;
240 +}
241 +
242 +static CFStringRef to_string(const char *s) {
243 + if (s == NULL)
244 + return NULL;
245 + return CFStringCreateWithCString(kCFAllocatorDefault, s,
246 + kCFStringEncodingASCII);
247 +}
248 +
249 +static SecPolicyRef get_policy(X509_VERIFY_PARAM *param) {
250 + switch (param->purpose) {
251 + case X509_PURPOSE_SSL_CLIENT:
252 + case X509_PURPOSE_SSL_SERVER: {
253 +
254 + if (!param->id) {
255 + fprintf(stderr, "got no ID!\n");
256 + return NULL;
257 + }
258 +
259 + CFStringRef hostname;
260 + int nhosts = sk_OPENSSL_STRING_num(param->id->hosts);
261 +
262 + if (nhosts != 1) {
263 + hostname = NULL;
264 +
265 + } else {
266 + hostname = to_string(sk_OPENSSL_STRING_value(param->id->hosts, 0));
267 + CFShow(hostname);
268 + }
269 +
270 + return SecPolicyCreateSSL(param->purpose == X509_PURPOSE_SSL_SERVER,
271 + hostname);
272 + }
273 +
274 + case X509_PURPOSE_NS_SSL_SERVER:
275 + case X509_PURPOSE_SMIME_SIGN:
276 + case X509_PURPOSE_SMIME_ENCRYPT:
277 + case X509_PURPOSE_CRL_SIGN:
278 + case X509_PURPOSE_ANY:
279 + case X509_PURPOSE_OCSP_HELPER:
280 + case X509_PURPOSE_TIMESTAMP_SIGN:
281 + default:
282 + fprintf(stderr, "unsupported purpose %d", param->purpose);
283 + return NULL;
284 + }
285 +}
286 +
287 +/*
288 + * Please see comment in x509_vfy_apple.h
289 + */
290 +int
291 +X509_verify_cert(X509_STORE_CTX *ctx)
292 +{
293 + uint64_t certLastIndex = 0;
294 + uint64_t i = 0;
295 +
296 + /* Try OpenSSL, if we get a local certificate issue verify against trusted roots */
297 + int ret = X509_verify_cert_orig(ctx);
298 +
299 + /* Verify TEA is enabled and should be used. */
300 + if (0 == X509_TEA_is_enabled() ||
301 + ret == 1 || !TEA_might_correct_error(ctx->error)) {
302 + return ret;
303 + }
304 +
305 + /* Verify that the certificate chain exists, otherwise make it. */
306 + if (ctx->chain == NULL && (ctx->chain = sk_X509_new_null()) == NULL) {
307 + fprintf(stderr, "Could not create the certificate chain");
308 + ctx->error = X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY;
309 + return -1;
310 + }
311 +
312 + /* Verify chain depth */
313 + certLastIndex = sk_X509_num(ctx->untrusted);
314 + if (certLastIndex > ctx->param->depth) {
315 + fprintf(stderr, "Pruning certificate chain to %" PRIu64, certLastIndex);
316 + certLastIndex = ctx->param->depth;
317 + }
318 +
319 + CFMutableArrayRef certArray = CFArrayCreateMutable(NULL, certLastIndex + 1, NULL);
320 + CFRetain(certArray);
321 +
322 + if (!add_cert_to_array(certArray, ctx->cert)) {
323 + fprintf(stderr, "Failed to add certificate to array");
324 + CFRelease(certArray);
325 + ctx->error = X509_V_ERR_UNSPECIFIED;
326 + return -1;
327 + }
328 +
329 + for (i = 0; i < certLastIndex; ++i) {
330 + X509 *t = sk_X509_value(ctx->untrusted, i);
331 + if (!add_cert_to_array(certArray, t)) {
332 + fprintf(stderr, "Failed to add chain certificate %lld to array", i);
333 + CFRelease(certArray);
334 + ctx->error = X509_V_ERR_UNSPECIFIED;
335 + return 0;
336 + }
337 + }
338 +
339 + // We put ASN.1 encoded X509 on the CertificateChain, so we don't call TEACertificateChainSetEncodingHandler
340 + SecPolicyRef policy = get_policy(ctx->param);
341 +
342 + if (policy == NULL) {
343 + fprintf(stderr, "Failed to create policy!\n");
344 + CFRelease(certArray);
345 + ctx->error = X509_V_ERR_UNSPECIFIED;
346 + return -1;
347 + }
348 +
349 + SecTrustRef trust = NULL;
350 +
351 + if (SecTrustCreateWithCertificates(certArray, policy, &trust) != errSecSuccess) {
352 + fprintf(stderr, "Failed to create trust!\n");
353 + CFRelease(certArray);
354 + ctx->error = X509_V_ERR_CERT_UNTRUSTED;
355 + return -1;
356 + }
357 +
358 + if (ctx->param->flags & X509_V_FLAG_USE_CHECK_TIME) {
359 + fprintf(stderr, "Setting time not supported yet?\n");
360 + SecTrustSetVerifyDate(trust, CFDateCreate(NULL, ctx->param->check_time));
361 + }
362 +
363 + SecTrustResultType result = 0;
364 +
365 + if (SecTrustEvaluate(trust, &result) != errSecSuccess || result != kSecTrustResultUnspecified) {
366 + CFRelease(certArray);
367 + ctx->error = X509_V_ERR_CERT_UNTRUSTED;
368 + return 0;
369 + }
370 +
371 + CFRelease(certArray);
372 + ctx->error = 0;
373 + return 1;
374 +}
375 +
376 +#pragma mark Trust Evaluation Agent
377 +
378 +/* -1: not set
379 + * 0: set to false
380 + * 1: set to true
381 + */
382 +static int tea_enabled = -1;
383 +
384 +void
385 +X509_TEA_set_state(int change)
386 +{
387 + tea_enabled = (change) ? 1 : 0;
388 +}
389 +
390 +int
391 +X509_TEA_is_enabled()
392 +{
393 + if (tea_enabled < 0)
394 + tea_enabled = (NULL == getenv(X509_TEA_ENV_DISABLE));
395 +
396 + return tea_enabled != 0;
397 +}
398 diff -Naur libressl-2.6.2.orig/crypto/x509/x509_vfy_apple.h libressl-2.6.2/crypto/x509/x509_vfy_apple.h
399 --- libressl-2.6.2.orig/crypto/x509/x509_vfy_apple.h 1970-01-01 01:00:00.000000000 +0100
400 +++ libressl-2.6.2/crypto/x509/x509_vfy_apple.h 2017-10-07 14:05:16.000000000 +0200
401 @@ -0,0 +1,74 @@
402 +/*
403 + * Copyright (c) 2009 Apple Inc. All Rights Reserved.
404 + *
405 + * @APPLE_LICENSE_HEADER_START@
406 + *
407 + * This file contains Original Code and/or Modifications of Original Code
408 + * as defined in and that are subject to the Apple Public Source License
409 + * Version 2.0 (the 'License'). You may not use this file except in
410 + * compliance with the License. Please obtain a copy of the License at
411 + * http://www.opensource.apple.com/apsl/ and read it before using this
412 + * file.
413 + *
414 + * The Original Code and all software distributed under the License are
415 + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
416 + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
417 + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
418 + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
419 + * Please see the License for the specific language governing rights and
420 + * limitations under the License.
421 + *
422 + * @APPLE_LICENSE_HEADER_END@
423 + *
424 + */
425 +
426 +#ifndef HEADER_X509_H
427 +#include <openssl/x509.h>
428 +#endif
429 +
430 +#ifndef HEADER_X509_VFY_APPLE_H
431 +#define HEADER_X509_VFY_APPLE_H
432 +
433 +/* Environment variable name to disable TEA. */
434 +#define X509_TEA_ENV_DISABLE "OPENSSL_X509_TEA_DISABLE"
435 +
436 +/*
437 + * X509_verify_cert
438 + *
439 + * Originally located in x509_vfy.c.
440 + *
441 + * Verify certificate with OpenSSL created X509_verify_cert. If and only if
442 + * OpenSSL cannot get certificate issuer locally then OS X security API will
443 + * verify the certificate, using Trust Evaluation Agent.
444 + *
445 + * Return values:
446 + * --------------
447 + * -1: Null was passed for either ctx or ctx->cert.
448 + * 0: Certificate is trusted.
449 + * 1: Certificate is not trusted.
450 + */
451 +int X509_verify_cert(X509_STORE_CTX *ctx);
452 +
453 +/*
454 + * X509_TEA_is_enabled
455 + *
456 + * Is the Trust Evaluation Agent (TEA) used for certificate verification when
457 + * the issuer cannot be verified.
458 + *
459 + * Returns 0 if TEA is disabled and 1 if TEA is enabled.
460 + */
461 +int X509_TEA_is_enabled();
462 +
463 +/*
464 + * X509_TEA_set_state
465 + *
466 + * Enables/disables certificate verification with Trust Evaluation Agent (TEA)
467 + * when the issuer cannot be verified.
468 + *
469 + * Pass 0 to disable TEA and non-zero to enable TEA.
470 + */
471 +void X509_TEA_set_state(int change);
472 +
473 +int X509_verify_cert_orig(X509_STORE_CTX *ctx);
474 +
475 +#endif /* HEADER_X509_VFY_APPLE_H */