4 http://git.openssl.org/gitweb/?p=openssl.git;a=commit;h=2dabd822366df7b2608b55d5ca5f31d5d484cbaf |
4 http://git.openssl.org/gitweb/?p=openssl.git;a=commit;h=2dabd822366df7b2608b55d5ca5f31d5d484cbaf |
5 |
5 |
6 Index: openssl/crypto/x509/x509_trs.c |
6 Index: openssl/crypto/x509/x509_trs.c |
7 ============================================================================ |
7 ============================================================================ |
8 $ diff -ru crypto/x509/x509_trs.c crypto/x509/x509_trs.c |
8 $ diff -ru crypto/x509/x509_trs.c crypto/x509/x509_trs.c |
9 --- openssl/crypto/x509/x509_trs.c.orig 4 Dec 2012 17:26:04 -0000 1.133.2.11.2.6.2.3 |
9 --- openssl/crypto/x509/x509_trs.c.orig 4 Dec 2012 17:26:04 -0000 1.133.2.11.2.6.2.3 |
10 +++ openssl/crypto/x509/x509_trs.c 14 Dec 2012 14:30:45 -0000 1.133.2.11.2.6.2.4 |
10 +++ openssl/crypto/x509/x509_trs.c 14 Dec 2012 14:30:45 -0000 1.133.2.11.2.6.2.4 |
11 @@ -114,6 +114,15 @@ int X509_check_trust(X509 *x, int id, int flags) |
11 @@ -119,6 +119,14 @@ int X509_check_trust(X509 *x, int id, int flags) |
12 X509_TRUST *pt; |
12 int idx; |
13 int idx; |
13 if (id == -1) |
14 if(id == -1) return 1; |
14 return 1; |
15 + /* We get this as a default value */ |
15 + /* We get this as a default value */ |
16 + if (id == 0) |
16 + if (id == 0) { |
17 + { |
17 + int rv; |
18 + int rv; |
18 + rv = obj_trust(NID_anyExtendedKeyUsage, x, 0); |
19 + rv = obj_trust(NID_anyExtendedKeyUsage, x, 0); |
19 + if (rv != X509_TRUST_UNTRUSTED) |
20 + if (rv != X509_TRUST_UNTRUSTED) |
20 + return rv; |
21 + return rv; |
21 + return trust_compat(NULL, x, 0); |
22 + return trust_compat(NULL, x, 0); |
22 + } |
23 + } |
23 idx = X509_TRUST_get_by_id(id); |
24 idx = X509_TRUST_get_by_id(id); |
24 if (idx == -1) |
25 if(idx == -1) return default_trust(id, x, flags); |
25 return default_trust(id, x, flags); |
26 pt = X509_TRUST_get0(idx); |
|
27 Index: openssl/crypto/x509/x509_vfy.c |
26 Index: openssl/crypto/x509/x509_vfy.c |
28 ============================================================================ |
27 ============================================================================ |
29 $ cvs diff -u -r1.105.2.9.2.4.2.3 -r1.105.2.9.2.4.2.4 x509_vfy.c |
28 $ cvs diff -u -r1.105.2.9.2.4.2.3 -r1.105.2.9.2.4.2.4 x509_vfy.c |
30 --- openssl/crypto/x509/x509_vfy.c 14 Dec 2012 12:53:48 -0000 1.105.2.9.2.4.2.3 |
29 --- openssl/crypto/x509/x509_vfy.c 14 Dec 2012 12:53:48 -0000 1.105.2.9.2.4.2.3 |
31 +++ openssl/crypto/x509/x509_vfy.c 14 Dec 2012 14:30:46 -0000 1.105.2.9.2.4.2.4 |
30 +++ openssl/crypto/x509/x509_vfy.c 14 Dec 2012 14:30:46 -0000 1.105.2.9.2.4.2.4 |
32 @@ -150,6 +150,33 @@ |
31 @@ -149,6 +149,33 @@ |
33 } |
32 } |
34 #endif |
33 #endif |
35 |
34 |
36 +/* Given a certificate try and find an exact match in the store */ |
35 +/* Given a certificate try and find an exact match in the store */ |
37 + |
36 + |
38 +static X509 *lookup_cert_match(X509_STORE_CTX *ctx, X509 *x) |
37 +static X509 *lookup_cert_match(X509_STORE_CTX *ctx, X509 *x) |
39 + { |
38 + { |
40 + STACK_OF(X509) *certs; |
39 + STACK_OF(X509) *certs; |
41 + X509 *xtmp = NULL; |
40 + X509 *xtmp = NULL; |
42 + int i; |
41 + int i; |
43 + /* Lookup all certs with matching subject name */ |
42 + /* Lookup all certs with matching subject name */ |
44 + certs = ctx->lookup_certs(ctx, X509_get_subject_name(x)); |
43 + certs = ctx->lookup_certs(ctx, X509_get_subject_name(x)); |
45 + if (certs == NULL) |
44 + if (certs == NULL) |
46 + return NULL; |
45 + return NULL; |
47 + /* Look for exact match */ |
46 + /* Look for exact match */ |
48 + for (i = 0; i < sk_X509_num(certs); i++) |
47 + for (i = 0; i < sk_X509_num(certs); i++) |
49 + { |
48 + { |
50 + xtmp = sk_X509_value(certs, i); |
49 + xtmp = sk_X509_value(certs, i); |
51 + if (!X509_cmp(xtmp, x)) |
50 + if (!X509_cmp(xtmp, x)) |
52 + break; |
51 + break; |
53 + } |
52 + } |
54 + if (i < sk_X509_num(certs)) |
53 + if (i < sk_X509_num(certs)) |
55 + CRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509); |
54 + CRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509); |
56 + else |
55 + else |
57 + xtmp = NULL; |
56 + xtmp = NULL; |
58 + sk_X509_pop_free(certs, X509_free); |
57 + sk_X509_pop_free(certs, X509_free); |
59 + return xtmp; |
58 + return xtmp; |
60 + } |
59 + } |
61 + |
60 + |
62 + |
61 + |
63 int X509_verify_cert(X509_STORE_CTX *ctx) |
62 int X509_verify_cert(X509_STORE_CTX *ctx) |
64 { |
63 { |
65 X509 *x,*xtmp,*chain_ss=NULL; |
64 X509 *x, *xtmp, *chain_ss = NULL; |
66 @@ -307,8 +307,13 @@ int X509_verify_cert(X509_STORE_CTX *ctx) |
65 @@ -304,8 +331,17 @@ int X509_verify_cert(X509_STORE_CTX *ctx) |
67 |
66 |
68 /* we now have our chain, lets check it... */ |
67 /* we now have our chain, lets check it... */ |
69 |
68 |
70 - /* Is last certificate looked up self signed? */ |
69 - /* Is last certificate looked up self signed? */ |
71 - if (!ctx->check_issued(ctx,x,x)) |
70 - if (!ctx->check_issued(ctx, x, x)) { |
72 + i = check_trust(ctx); |
71 + i = check_trust(ctx); |
73 + |
72 + |
74 + /* If explicitly rejected error */ |
73 + /* If explicitly rejected error */ |
75 + if (i == X509_TRUST_REJECTED) |
74 + if (i == X509_TRUST_REJECTED) |
76 + goto end; |
75 + goto end; |
77 + /* If not explicitly trusted then indicate error */ |
76 + /* |
78 + if (i != X509_TRUST_TRUSTED) |
77 + * If not explicitly trusted then indicate error unless it's a single |
79 { |
78 + * self signed certificate in which case we've indicated an error already |
80 if ((chain_ss == NULL) || !ctx->check_issued(ctx, x, chain_ss)) |
79 + * and set bad_chain == 1 |
81 { |
80 + */ |
82 @@ -346,12 +351,6 @@ int X509_verify_cert(X509_STORE_CTX *ctx) |
81 + if (i != X509_TRUST_TRUSTED && !bad_chain) { |
83 |
82 if ((chain_ss == NULL) || !ctx->check_issued(ctx, x, chain_ss)) { |
84 if (!ok) goto end; |
83 if (ctx->last_untrusted >= num) |
85 |
84 ctx->error = X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY; |
86 - /* The chain extensions are OK: check trust */ |
85 @@ -340,14 +376,6 @@ int X509_verify_cert(X509_STORE_CTX *ctx) |
|
86 ok = check_name_constraints(ctx); |
|
87 |
|
88 if (!ok) |
|
89 - goto end; |
87 - |
90 - |
88 - if (param->trust > 0) ok = check_trust(ctx); |
91 - /* The chain extensions are OK: check trust */ |
89 - |
92 - |
90 - if (!ok) goto end; |
93 - if (param->trust > 0) |
|
94 - ok = check_trust(ctx); |
91 - |
95 - |
92 /* We may as well copy down any DSA parameters that are required */ |
96 - if (!ok) |
93 X509_get_pubkey_parameters(NULL,ctx->chain); |
97 goto end; |
94 |
98 |
95 @@ -642,28 +641,54 @@ static int check_name_constraints(X509_STORE_CTX *ctx) |
99 /* We may as well copy down any DSA parameters that are required */ |
|
100 @@ -630,28 +658,53 @@ static int check_name_constraints(X509_STORE_CTX *ctx) |
96 |
101 |
97 static int check_trust(X509_STORE_CTX *ctx) |
102 static int check_trust(X509_STORE_CTX *ctx) |
98 { |
103 { |
99 -#ifdef OPENSSL_NO_CHAIN_VERIFY |
104 -#ifdef OPENSSL_NO_CHAIN_VERIFY |
100 - return 1; |
105 - return 1; |
101 -#else |
106 -#else |
102 int i, ok; |
107 int i, ok; |
103 - X509 *x; |
108 - X509 *x; |
104 + X509 *x = NULL; |
109 + X509 *x = NULL; |
105 int (*cb)(int xok,X509_STORE_CTX *xctx); |
110 int (*cb) (int xok, X509_STORE_CTX *xctx); |
106 cb=ctx->verify_cb; |
111 cb = ctx->verify_cb; |
107 -/* For now just check the last certificate in the chain */ |
112 -/* For now just check the last certificate in the chain */ |
108 - i = sk_X509_num(ctx->chain) - 1; |
113 - i = sk_X509_num(ctx->chain) - 1; |
109 - x = sk_X509_value(ctx->chain, i); |
114 - x = sk_X509_value(ctx->chain, i); |
110 - ok = X509_check_trust(x, ctx->param->trust, 0); |
115 - ok = X509_check_trust(x, ctx->param->trust, 0); |
111 - if (ok == X509_TRUST_TRUSTED) |
116 - if (ok == X509_TRUST_TRUSTED) |
112 - return 1; |
117 - return 1; |
113 - ctx->error_depth = i; |
118 - ctx->error_depth = i; |
114 - ctx->current_cert = x; |
119 - ctx->current_cert = x; |
115 - if (ok == X509_TRUST_REJECTED) |
120 - if (ok == X509_TRUST_REJECTED) |
116 - ctx->error = X509_V_ERR_CERT_REJECTED; |
121 - ctx->error = X509_V_ERR_CERT_REJECTED; |
117 - else |
122 - else |
118 - ctx->error = X509_V_ERR_CERT_UNTRUSTED; |
123 - ctx->error = X509_V_ERR_CERT_UNTRUSTED; |
119 - ok = cb(0, ctx); |
124 - ok = cb(0, ctx); |
120 - return ok; |
125 - return ok; |
121 -#endif |
126 -#endif |
122 + /* Check all trusted certificates in chain */ |
127 + /* Check all trusted certificates in chain */ |
123 + for (i = ctx->last_untrusted; i < sk_X509_num(ctx->chain); i++) |
128 + for (i = ctx->last_untrusted; i < sk_X509_num(ctx->chain); i++) { |
124 + { |
129 + x = sk_X509_value(ctx->chain, i); |
125 + x = sk_X509_value(ctx->chain, i); |
130 + ok = X509_check_trust(x, ctx->param->trust, 0); |
126 + ok = X509_check_trust(x, ctx->param->trust, 0); |
131 + /* If explicitly trusted return trusted */ |
127 + /* If explicitly trusted return trusted */ |
132 + if (ok == X509_TRUST_TRUSTED) |
128 + if (ok == X509_TRUST_TRUSTED) |
133 + return X509_TRUST_TRUSTED; |
129 + return X509_TRUST_TRUSTED; |
134 + /* |
130 + /* If explicitly rejected notify callback and reject if |
135 + * If explicitly rejected notify callback and reject if not |
131 + * not overridden. |
136 + * overridden. |
132 + */ |
137 + */ |
133 + if (ok == X509_TRUST_REJECTED) |
138 + if (ok == X509_TRUST_REJECTED) { |
134 + { |
139 + ctx->error_depth = i; |
135 + ctx->error_depth = i; |
140 + ctx->current_cert = x; |
136 + ctx->current_cert = x; |
141 + ctx->error = X509_V_ERR_CERT_REJECTED; |
137 + ctx->error = X509_V_ERR_CERT_REJECTED; |
142 + ok = cb(0, ctx); |
138 + ok = cb(0, ctx); |
143 + if (!ok) |
139 + if (!ok) |
144 + return X509_TRUST_REJECTED; |
140 + return X509_TRUST_REJECTED; |
145 + } |
141 + } |
146 + } |
142 + } |
147 + /* |
143 + /* If we accept partial chains and have at least one trusted |
148 + * If we accept partial chains and have at least one trusted certificate |
144 + * certificate return success. |
149 + * return success. |
145 + */ |
150 + */ |
146 + if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN) |
151 + if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN) { |
147 + { |
152 + X509 *mx; |
148 + X509 *mx; |
153 + if (ctx->last_untrusted < sk_X509_num(ctx->chain)) |
149 + if (ctx->last_untrusted < sk_X509_num(ctx->chain)) |
154 + return X509_TRUST_TRUSTED; |
150 + return X509_TRUST_TRUSTED; |
155 + x = sk_X509_value(ctx->chain, 0); |
151 + x = sk_X509_value(ctx->chain, 0); |
156 + mx = lookup_cert_match(ctx, x); |
152 + mx = lookup_cert_match(ctx, x); |
157 + if (mx) { |
153 + if (mx) |
158 + (void)sk_X509_set(ctx->chain, 0, mx); |
154 + { |
159 + X509_free(x); |
155 + (void)sk_X509_set(ctx->chain, 0, mx); |
160 + ctx->last_untrusted = 0; |
156 + X509_free(x); |
161 + return X509_TRUST_TRUSTED; |
157 + ctx->last_untrusted = 0; |
162 + } |
158 + return X509_TRUST_TRUSTED; |
163 + } |
159 + } |
164 + |
160 + } |
165 + /* |
161 + |
166 + * If no trusted certs in chain at all return untrusted and allow |
162 + /* If no trusted certs in chain at all return untrusted and |
167 + * standard (no issuer cert) etc errors to be indicated. |
163 + * allow standard (no issuer cert) etc errors to be indicated. |
168 + */ |
164 + */ |
169 + return X509_TRUST_UNTRUSTED; |
165 + return X509_TRUST_UNTRUSTED; |
|
166 } |
170 } |
167 |
171 |
168 static int check_revocation(X509_STORE_CTX *ctx) |
172 static int check_revocation(X509_STORE_CTX *ctx) |
169 @@ -1602,6 +1641,8 @@ static int internal_verify(X509_STORE_CTX *ctx) |
173 @@ -1526,6 +1579,8 @@ static int internal_verify(X509_STORE_CTX *ctx) |
170 xs=xi; |
174 if (ctx->check_issued(ctx, xi, xi)) |
171 else |
175 xs = xi; |
172 { |
176 else { |
173 + if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN && n == 0) |
177 + if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN && n == 0) |
174 + return check_cert_time(ctx, xi); |
178 + return check_cert_time(ctx, xi); |
175 if (n <= 0) |
179 if (n <= 0) { |
176 { |
180 ctx->error = X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE; |
177 ctx->error=X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE; |
181 ctx->current_cert = xi; |
178 Index: openssl/crypto/x509/x509_vfy.h |
182 Index: openssl/crypto/x509/x509_vfy.h |
179 ============================================================================ |
183 ============================================================================ |
180 $ cvs diff -u -r1.67.2.3.4.1 -r1.67.2.3.4.2 x509_vfy.h |
184 $ cvs diff -u -r1.67.2.3.4.1 -r1.67.2.3.4.2 x509_vfy.h |
181 --- openssl/crypto/x509/x509_vfy.h 26 Sep 2012 13:50:42 -0000 1.67.2.3.4.1 |
185 --- openssl/crypto/x509/x509_vfy.h 26 Sep 2012 13:50:42 -0000 1.67.2.3.4.1 |
182 +++ openssl/crypto/x509/x509_vfy.h 14 Dec 2012 14:30:46 -0000 1.67.2.3.4.2 |
186 +++ openssl/crypto/x509/x509_vfy.h 14 Dec 2012 14:30:46 -0000 1.67.2.3.4.2 |
183 @@ -390,6 +390,8 @@ |
187 @@ -406,6 +406,9 @@ |
184 /* Check selfsigned CA signature */ |
188 /* Check selfsigned CA signature */ |
185 #define X509_V_FLAG_CHECK_SS_SIGNATURE 0x4000 |
189 # define X509_V_FLAG_CHECK_SS_SIGNATURE 0x4000 |
186 |
190 |
187 +/* Allow partial chains if at least one certificate is in trusted store */ |
191 +/* Allow partial chains if at least one certificate is in trusted store */ |
188 +#define X509_V_FLAG_PARTIAL_CHAIN 0x80000 |
192 +# define X509_V_FLAG_PARTIAL_CHAIN 0x80000 |
189 |
193 + |
190 #define X509_VP_FLAG_DEFAULT 0x1 |
194 # define X509_VP_FLAG_DEFAULT 0x1 |
191 #define X509_VP_FLAG_OVERWRITE 0x2 |
195 # define X509_VP_FLAG_OVERWRITE 0x2 |
|
196 # define X509_VP_FLAG_RESET_FLAGS 0x4 |
192 Index: openssl/apps/apps.c |
197 Index: openssl/apps/apps.c |
193 ============================================================================ |
198 ============================================================================ |
194 $ cvs diff -u -r1.133.2.11.2.6.2.3 -r1.133.2.11.2.6.2.4 apps.c |
199 $ cvs diff -u -r1.133.2.11.2.6.2.3 -r1.133.2.11.2.6.2.4 apps.c |
195 --- openssl/apps/apps.c 4 Dec 2012 17:26:04 -0000 1.133.2.11.2.6.2.3 |
200 --- openssl/apps/apps.c 4 Dec 2012 17:26:04 -0000 1.133.2.11.2.6.2.3 |
196 +++ openssl/apps/apps.c 14 Dec 2012 14:30:45 -0000 1.133.2.11.2.6.2.4 |
201 +++ openssl/apps/apps.c 14 Dec 2012 14:30:45 -0000 1.133.2.11.2.6.2.4 |
197 @@ -2361,6 +2361,8 @@ |
202 @@ -2238,6 +2238,8 @@ |
198 flags |= X509_V_FLAG_NOTIFY_POLICY; |
203 flags |= X509_V_FLAG_NOTIFY_POLICY; |
199 else if (!strcmp(arg, "-check_ss_sig")) |
204 else if (!strcmp(arg, "-check_ss_sig")) |
200 flags |= X509_V_FLAG_CHECK_SS_SIGNATURE; |
205 flags |= X509_V_FLAG_CHECK_SS_SIGNATURE; |
201 + else if (!strcmp(arg, "-partial_chain")) |
206 + else if (!strcmp(arg, "-partial_chain")) |
202 + flags |= X509_V_FLAG_PARTIAL_CHAIN; |
207 + flags |= X509_V_FLAG_PARTIAL_CHAIN; |
203 else |
208 else |
204 return 0; |
209 return 0; |
205 |
210 |