837dd04
diff -up openssl-1.0.2c/apps/cms.c.trusted-first openssl-1.0.2c/apps/cms.c
837dd04
--- openssl-1.0.2c/apps/cms.c.trusted-first	2015-06-15 17:45:13.112279761 +0200
837dd04
+++ openssl-1.0.2c/apps/cms.c	2015-06-15 17:46:11.045611575 +0200
a1fb602
@@ -646,6 +646,8 @@ int MAIN(int argc, char **argv)
a1fb602
                    "-CApath dir    trusted certificates directory\n");
a1fb602
         BIO_printf(bio_err, "-CAfile file   trusted certificates file\n");
a1fb602
         BIO_printf(bio_err,
a1fb602
+                   "-trusted_first use trusted certificates first when building the trust chain\n");
a1fb602
+        BIO_printf(bio_err,
837dd04
                    "-no_alt_chains only ever use the first certificate chain found\n");
a1fb602
         BIO_printf(bio_err,
837dd04
                    "-crl_check     check revocation status of signer's certificate using CRLs\n");
837dd04
diff -up openssl-1.0.2c/apps/ocsp.c.trusted-first openssl-1.0.2c/apps/ocsp.c
837dd04
--- openssl-1.0.2c/apps/ocsp.c.trusted-first	2015-06-15 17:45:13.112279761 +0200
837dd04
+++ openssl-1.0.2c/apps/ocsp.c	2015-06-15 17:46:31.898090948 +0200
a1fb602
@@ -536,6 +536,8 @@ int MAIN(int argc, char **argv)
a1fb602
         BIO_printf(bio_err,
a1fb602
                    "-CAfile file         trusted certificates file\n");
a1fb602
         BIO_printf(bio_err,
a1fb602
+                   "-trusted_first       use trusted certificates first when building the trust chain\n");
a1fb602
+        BIO_printf(bio_err,
837dd04
                    "-no_alt_chains       only ever use the first certificate chain found\n");
a1fb602
         BIO_printf(bio_err,
837dd04
                    "-VAfile file         validator certificates file\n");
837dd04
diff -up openssl-1.0.2c/apps/s_client.c.trusted-first openssl-1.0.2c/apps/s_client.c
837dd04
--- openssl-1.0.2c/apps/s_client.c.trusted-first	2015-06-15 17:45:13.113279784 +0200
837dd04
+++ openssl-1.0.2c/apps/s_client.c	2015-06-15 17:47:05.645866767 +0200
a1fb602
@@ -333,6 +333,8 @@ static void sc_usage(void)
a1fb602
     BIO_printf(bio_err, " -CApath arg   - PEM format directory of CA's\n");
a1fb602
     BIO_printf(bio_err, " -CAfile arg   - PEM format file of CA's\n");
a1fb602
     BIO_printf(bio_err,
a1fb602
+               " -trusted_first - Use trusted CA's first when building the trust chain\n");
a1fb602
+    BIO_printf(bio_err,
837dd04
                " -no_alt_chains - only ever use the first certificate chain found\n");
a1fb602
     BIO_printf(bio_err,
837dd04
                " -reconnect    - Drop and re-make the connection with the same Session-ID\n");
837dd04
diff -up openssl-1.0.2c/apps/smime.c.trusted-first openssl-1.0.2c/apps/smime.c
837dd04
--- openssl-1.0.2c/apps/smime.c.trusted-first	2015-06-15 17:45:13.113279784 +0200
837dd04
+++ openssl-1.0.2c/apps/smime.c	2015-06-15 17:47:39.090635621 +0200
a1fb602
@@ -442,6 +442,8 @@ int MAIN(int argc, char **argv)
a1fb602
                    "-CApath dir    trusted certificates directory\n");
a1fb602
         BIO_printf(bio_err, "-CAfile file   trusted certificates file\n");
a1fb602
         BIO_printf(bio_err,
a1fb602
+                   "-trusted_first use trusted certificates first when building the trust chain\n");
a1fb602
+        BIO_printf(bio_err,
837dd04
                    "-no_alt_chains only ever use the first certificate chain found\n");
a1fb602
         BIO_printf(bio_err,
837dd04
                    "-crl_check     check revocation status of signer's certificate using CRLs\n");
837dd04
diff -up openssl-1.0.2c/apps/s_server.c.trusted-first openssl-1.0.2c/apps/s_server.c
837dd04
--- openssl-1.0.2c/apps/s_server.c.trusted-first	2015-06-15 17:45:13.114279807 +0200
837dd04
+++ openssl-1.0.2c/apps/s_server.c	2015-06-15 17:47:24.841308046 +0200
837dd04
@@ -572,6 +572,8 @@ static void sv_usage(void)
a1fb602
     BIO_printf(bio_err, " -CApath arg   - PEM format directory of CA's\n");
a1fb602
     BIO_printf(bio_err, " -CAfile arg   - PEM format file of CA's\n");
a1fb602
     BIO_printf(bio_err,
a1fb602
+               " -trusted_first - Use trusted CA's first when building the trust chain\n");
a1fb602
+    BIO_printf(bio_err,
837dd04
                " -no_alt_chains - only ever use the first certificate chain found\n");
a1fb602
     BIO_printf(bio_err,
837dd04
                " -nocert       - Don't use any certificates (Anon-DH)\n");
837dd04
diff -up openssl-1.0.2c/apps/s_time.c.trusted-first openssl-1.0.2c/apps/s_time.c
837dd04
--- openssl-1.0.2c/apps/s_time.c.trusted-first	2015-06-15 17:45:13.010277416 +0200
837dd04
+++ openssl-1.0.2c/apps/s_time.c	2015-06-15 17:45:13.114279807 +0200
a1fb602
@@ -182,6 +182,7 @@ static void s_time_usage(void)
a1fb602
                 file if not specified by this option\n\
a1fb602
 -CApath arg   - PEM format directory of CA's\n\
a1fb602
 -CAfile arg   - PEM format file of CA's\n\
a1fb602
+-trusted_first - Use trusted CA's first when building the trust chain\n\
a1fb602
 -cipher       - preferred cipher to use, play with 'openssl ciphers'\n\n";
a1fb602
 
a1fb602
     printf("usage: s_time <args>\n\n");
837dd04
diff -up openssl-1.0.2c/apps/ts.c.trusted-first openssl-1.0.2c/apps/ts.c
837dd04
--- openssl-1.0.2c/apps/ts.c.trusted-first	2015-06-15 17:45:13.065278681 +0200
837dd04
+++ openssl-1.0.2c/apps/ts.c	2015-06-15 17:45:13.114279807 +0200
a1fb602
@@ -352,7 +352,7 @@ int MAIN(int argc, char **argv)
a1fb602
                "ts -verify [-data file_to_hash] [-digest digest_bytes] "
a1fb602
                "[-queryfile request.tsq] "
a1fb602
                "-in response.tsr [-token_in] "
a1fb602
-               "-CApath ca_path -CAfile ca_file.pem "
a1fb602
+               "-CApath ca_path -CAfile ca_file.pem -trusted_first"
a1fb602
                "-untrusted cert_file.pem\n");
a1fb602
  cleanup:
a1fb602
     /* Clean up. */
837dd04
diff -up openssl-1.0.2c/apps/verify.c.trusted-first openssl-1.0.2c/apps/verify.c
837dd04
--- openssl-1.0.2c/apps/verify.c.trusted-first	2015-06-15 17:45:13.114279807 +0200
837dd04
+++ openssl-1.0.2c/apps/verify.c	2015-06-15 17:48:03.979207778 +0200
a1fb602
@@ -231,7 +231,7 @@ int MAIN(int argc, char **argv)
a1fb602
  end:
a1fb602
     if (ret == 1) {
a1fb602
         BIO_printf(bio_err,
a1fb602
-                   "usage: verify [-verbose] [-CApath path] [-CAfile file] [-purpose purpose] [-crl_check]");
a1fb602
+                   "usage: verify [-verbose] [-CApath path] [-CAfile file] [-trusted_first] [-purpose purpose] [-crl_check]");
837dd04
         BIO_printf(bio_err, " [-no_alt_chains] [-attime timestamp]");
a1fb602
 #ifndef OPENSSL_NO_ENGINE
a1fb602
         BIO_printf(bio_err, " [-engine e]");
837dd04
diff -up openssl-1.0.2c/doc/apps/cms.pod.trusted-first openssl-1.0.2c/doc/apps/cms.pod
837dd04
--- openssl-1.0.2c/doc/apps/cms.pod.trusted-first	2015-06-12 16:51:21.000000000 +0200
837dd04
+++ openssl-1.0.2c/doc/apps/cms.pod	2015-06-15 17:48:43.615118958 +0200
a1fb602
@@ -35,6 +35,7 @@ B<openssl> B<cms>
a1fb602
 [B<-print>]
a1fb602
 [B<-CAfile file>]
a1fb602
 [B<-CApath dir>]
a1fb602
+[B<-trusted_first>]
837dd04
 [B<-no_alt_chains>]
a1fb602
 [B<-md digest>]
a1fb602
 [B<-[cipher]>]
837dd04
@@ -245,6 +246,12 @@ B<-verify>. This directory must be a sta
a1fb602
 is a hash of each subject name (using B<x509 -hash>) should be linked
a1fb602
 to each certificate.
a1fb602
 
a1fb602
+=item B<-trusted_first>
a1fb602
+
a1fb602
+Use certificates in CA file or CA directory before untrusted certificates
a1fb602
+from the message when building the trust chain to verify certificates.
a1fb602
+This is mainly useful in environments with Bridge CA or Cross-Certified CAs.
a1fb602
+
a1fb602
 =item B<-md digest>
a1fb602
 
a1fb602
 digest algorithm to use when signing or resigning. If not present then the
837dd04
diff -up openssl-1.0.2c/doc/apps/ocsp.pod.trusted-first openssl-1.0.2c/doc/apps/ocsp.pod
837dd04
--- openssl-1.0.2c/doc/apps/ocsp.pod.trusted-first	2015-06-15 17:45:13.115279830 +0200
837dd04
+++ openssl-1.0.2c/doc/apps/ocsp.pod	2015-06-15 17:49:06.337641320 +0200
837dd04
@@ -29,7 +29,8 @@ B<openssl> B<ocsp>
a1fb602
 [B<-path>]
a1fb602
 [B<-CApath dir>]
a1fb602
 [B<-CAfile file>]
837dd04
-[B<-no_alt_chains>]]
a1fb602
+[B<-trusted_first>]
837dd04
+[B<-no_alt_chains>]
a1fb602
 [B<-VAfile file>]
a1fb602
 [B<-validity_period n>]
a1fb602
 [B<-status_age n>]
837dd04
@@ -144,6 +145,13 @@ connection timeout to the OCSP responder
a1fb602
 file or pathname containing trusted CA certificates. These are used to verify
a1fb602
 the signature on the OCSP response.
a1fb602
 
a1fb602
+=item B<-trusted_first>
a1fb602
+
a1fb602
+Use certificates in CA file or CA directory over certificates provided
a1fb602
+in the response or residing in other certificates file when building the trust
a1fb602
+chain to verify responder certificate.
a1fb602
+This is mainly useful in environments with Bridge CA or Cross-Certified CAs.
a1fb602
+
837dd04
 =item B<-no_alt_chains>
a1fb602
 
837dd04
 See L<B<verify>|verify(1)> manual page for details.
837dd04
diff -up openssl-1.0.2c/doc/apps/s_client.pod.trusted-first openssl-1.0.2c/doc/apps/s_client.pod
837dd04
--- openssl-1.0.2c/doc/apps/s_client.pod.trusted-first	2015-06-15 17:45:13.115279830 +0200
837dd04
+++ openssl-1.0.2c/doc/apps/s_client.pod	2015-06-15 17:49:23.984046989 +0200
a1fb602
@@ -19,6 +19,7 @@ B<openssl> B<s_client>
a1fb602
 [B<-pass arg>]
a1fb602
 [B<-CApath directory>]
a1fb602
 [B<-CAfile filename>]
a1fb602
+[B<-trusted_first>]
837dd04
 [B<-no_alt_chains>]
a1fb602
 [B<-reconnect>]
a1fb602
 [B<-pause>]
837dd04
@@ -124,7 +125,7 @@ also used when building the client certi
a1fb602
 A file containing trusted certificates to use during server authentication
a1fb602
 and to use when attempting to build the client certificate chain.
a1fb602
 
837dd04
-=item B<-purpose, -ignore_critical, -issuer_checks, -crl_check, -crl_check_all, -policy_check, -extended_crl, -x509_strict, -policy -check_ss_sig -no_alt_chains>
837dd04
+=item B<-purpose, -ignore_critical, -issuer_checks, -crl_check, -crl_check_all, -policy_check, -extended_crl, -x509_strict, -policy -check_ss_sig, -trusted_first -no_alt_chains>
a1fb602
 
a1fb602
 Set various certificate chain valiadition option. See the
a1fb602
 L<B<verify>|verify(1)> manual page for details.
837dd04
diff -up openssl-1.0.2c/doc/apps/smime.pod.trusted-first openssl-1.0.2c/doc/apps/smime.pod
837dd04
--- openssl-1.0.2c/doc/apps/smime.pod.trusted-first	2015-06-12 16:51:21.000000000 +0200
837dd04
+++ openssl-1.0.2c/doc/apps/smime.pod	2015-06-15 17:50:00.856894648 +0200
a1fb602
@@ -15,6 +15,9 @@ B<openssl> B<smime>
a1fb602
 [B<-pk7out>]
a1fb602
 [B<-[cipher]>]
a1fb602
 [B<-in file>]
a1fb602
+[B<-CAfile file>]
a1fb602
+[B<-CApath dir>]
a1fb602
+[B<-trusted_first>]
837dd04
 [B<-no_alt_chains>]
a1fb602
 [B<-certfile file>]
a1fb602
 [B<-signer file>]
837dd04
@@ -147,6 +150,12 @@ B<-verify>. This directory must be a sta
a1fb602
 is a hash of each subject name (using B<x509 -hash>) should be linked
a1fb602
 to each certificate.
a1fb602
 
a1fb602
+=item B<-trusted_first>
a1fb602
+
a1fb602
+Use certificates in CA file or CA directory over certificates provided
a1fb602
+in the message when building the trust chain to verify a certificate.
a1fb602
+This is mainly useful in environments with Bridge CA or Cross-Certified CAs.
a1fb602
+
a1fb602
 =item B<-md digest>
a1fb602
 
a1fb602
 digest algorithm to use when signing or resigning. If not present then the
837dd04
diff -up openssl-1.0.2c/doc/apps/s_server.pod.trusted-first openssl-1.0.2c/doc/apps/s_server.pod
837dd04
--- openssl-1.0.2c/doc/apps/s_server.pod.trusted-first	2015-06-15 17:45:13.116279853 +0200
837dd04
+++ openssl-1.0.2c/doc/apps/s_server.pod	2015-06-15 17:49:37.420355873 +0200
a1fb602
@@ -33,6 +33,7 @@ B<openssl> B<s_server>
a1fb602
 [B<-state>]
a1fb602
 [B<-CApath directory>]
a1fb602
 [B<-CAfile filename>]
a1fb602
+[B<-trusted_first>]
837dd04
 [B<-no_alt_chains>]
a1fb602
 [B<-nocert>]
a1fb602
 [B<-cipher cipherlist>]
837dd04
@@ -175,6 +176,12 @@ and to use when attempting to build the
a1fb602
 is also used in the list of acceptable client CAs passed to the client when
a1fb602
 a certificate is requested.
a1fb602
 
a1fb602
+=item B<-trusted_first>
a1fb602
+
a1fb602
+Use certificates in CA file or CA directory before other certificates 
a1fb602
+when building the trust chain to verify client certificates.
a1fb602
+This is mainly useful in environments with Bridge CA or Cross-Certified CAs.
a1fb602
+
837dd04
 =item B<-no_alt_chains>
a1fb602
 
837dd04
 See the L<B<verify>|verify(1)> manual page for details.
837dd04
diff -up openssl-1.0.2c/doc/apps/s_time.pod.trusted-first openssl-1.0.2c/doc/apps/s_time.pod
837dd04
--- openssl-1.0.2c/doc/apps/s_time.pod.trusted-first	2015-06-12 16:51:21.000000000 +0200
837dd04
+++ openssl-1.0.2c/doc/apps/s_time.pod	2015-06-15 17:45:13.116279853 +0200
a1fb602
@@ -14,6 +14,7 @@ B<openssl> B<s_time>
a1fb602
 [B<-key filename>]
a1fb602
 [B<-CApath directory>]
a1fb602
 [B<-CAfile filename>]
a1fb602
+[B<-trusted_first>]
a1fb602
 [B<-reuse>]
a1fb602
 [B<-new>]
a1fb602
 [B<-verify depth>]
a1fb602
@@ -76,6 +77,12 @@ also used when building the client certi
a1fb602
 A file containing trusted certificates to use during server authentication
a1fb602
 and to use when attempting to build the client certificate chain.
a1fb602
 
a1fb602
+=item B<-trusted_first>
a1fb602
+
a1fb602
+Use certificates in CA file or CA directory over the certificates provided
a1fb602
+by the server when building the trust chain to verify server certificate.
a1fb602
+This is mainly useful in environments with Bridge CA or Cross-Certified CAs.
a1fb602
+
a1fb602
 =item B<-new>
a1fb602
 
a1fb602
 performs the timing test using a new session ID for each connection.
837dd04
diff -up openssl-1.0.2c/doc/apps/ts.pod.trusted-first openssl-1.0.2c/doc/apps/ts.pod
837dd04
--- openssl-1.0.2c/doc/apps/ts.pod.trusted-first	2015-06-12 16:51:21.000000000 +0200
837dd04
+++ openssl-1.0.2c/doc/apps/ts.pod	2015-06-15 17:45:13.116279853 +0200
a1fb602
@@ -46,6 +46,7 @@ B<-verify>
a1fb602
 [B<-token_in>]
a1fb602
 [B<-CApath> trusted_cert_path]
a1fb602
 [B<-CAfile> trusted_certs.pem]
a1fb602
+[B<-trusted_first>]
a1fb602
 [B<-untrusted> cert_file.pem]
a1fb602
 
a1fb602
 =head1 DESCRIPTION
a1fb602
@@ -324,6 +325,12 @@ L<verify(1)|verify(1)> for additional de
a1fb602
 or B<-CApath> must be specified.
a1fb602
 (Optional)
a1fb602
 
a1fb602
+=item B<-trusted_first>
a1fb602
+
a1fb602
+Use certificates in CA file or CA directory before other certificates
a1fb602
+when building the trust chain to verify certificates.
a1fb602
+This is mainly useful in environments with Bridge CA or Cross-Certified CAs.
a1fb602
+
a1fb602
 =item B<-untrusted> cert_file.pem
a1fb602
 
a1fb602
 Set of additional untrusted certificates in PEM format which may be
837dd04
diff -up openssl-1.0.2c/doc/apps/verify.pod.trusted-first openssl-1.0.2c/doc/apps/verify.pod
837dd04
--- openssl-1.0.2c/doc/apps/verify.pod.trusted-first	2015-06-12 16:51:21.000000000 +0200
837dd04
+++ openssl-1.0.2c/doc/apps/verify.pod	2015-06-15 17:45:13.116279853 +0200
a1fb602
@@ -9,6 +9,7 @@ verify - Utility to verify certificates.
a1fb602
 B<openssl> B<verify>
a1fb602
 [B<-CApath directory>]
a1fb602
 [B<-CAfile file>]
a1fb602
+[B<-trusted_first>]
a1fb602
 [B<-purpose purpose>]
a1fb602
 [B<-policy arg>]
a1fb602
 [B<-ignore_critical>]
837dd04
@@ -79,6 +80,12 @@ If a valid CRL cannot be found an error
a1fb602
 A file of untrusted certificates. The file should contain multiple certificates
a1fb602
 in PEM format concatenated together.
a1fb602
 
a1fb602
+=item B<-trusted_first>
a1fb602
+
a1fb602
+Use certificates in CA file or CA directory before the certificates in the untrusted
a1fb602
+file when building the trust chain to verify certificates.
a1fb602
+This is mainly useful in environments with Bridge CA or Cross-Certified CAs.
a1fb602
+
a1fb602
 =item B<-purpose purpose>
a1fb602
 
a1fb602
 The intended use for the certificate. If this option is not specified,