8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.security.provider.certpath; 27 28 import sun.security.util.Debug; 29 30 import java.util.Collections; 31 import java.util.List; 32 import java.util.Set; 33 import java.util.StringJoiner; 34 import java.security.cert.CertPath; 35 import java.security.cert.CertPathValidatorException; 36 import java.security.cert.PKIXCertPathChecker; 37 import java.security.cert.PKIXReason; 38 import java.security.cert.X509Certificate; 39 40 /** 41 * This class is initialized with a list of <code>PKIXCertPathChecker</code>s 42 * and is used to verify the certificates in a <code>CertPath</code> by 43 * feeding each certificate to each <code>PKIXCertPathChecker</code>. 44 * 45 * @since 1.4 46 * @author Yassir Elley 47 */ 48 class PKIXMasterCertPathValidator { 49 50 private static final Debug debug = Debug.getInstance("certpath"); 51 52 /** 53 * Validates a certification path consisting exclusively of 54 * <code>X509Certificate</code>s using the specified 55 * <code>PKIXCertPathChecker</code>s. It is assumed that the 56 * <code>PKIXCertPathChecker</code>s 57 * have been initialized with any input parameters they may need. 58 * 127 if (debug != null) { 128 debug.println("-checker" + (j + 1) + 129 " validation succeeded"); 130 } 131 132 } catch (CertPathValidatorException cpve) { 133 throw new CertPathValidatorException(cpve.getMessage(), 134 (cpve.getCause() != null) ? cpve.getCause() : cpve, 135 cpOriginal, cpSize - (i + 1), cpve.getReason()); 136 } 137 } 138 139 if (!unresCritExts.isEmpty()) { 140 throw new CertPathValidatorException("unrecognized " + 141 "critical extension(s)", null, cpOriginal, cpSize-(i+1), 142 PKIXReason.UNRECOGNIZED_CRIT_EXT); 143 } 144 145 if (debug != null) 146 debug.println("\ncert" + (i+1) + " validation succeeded.\n"); 147 } 148 149 if (debug != null) { 150 debug.println("Cert path validation succeeded. (PKIX validation " 151 + "algorithm)"); 152 debug.println("-------------------------------------------------" 153 + "-------------"); 154 } 155 } 156 } | 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.security.provider.certpath; 27 28 import jdk.internal.event.CertificateChainEvent; 29 import jdk.internal.event.EventHelper; 30 import sun.security.util.Debug; 31 32 import java.util.Collections; 33 import java.util.List; 34 import java.util.Set; 35 import java.util.StringJoiner; 36 import java.security.cert.CertPath; 37 import java.security.cert.CertPathValidatorException; 38 import java.security.cert.PKIXCertPathChecker; 39 import java.security.cert.PKIXReason; 40 import java.security.cert.X509Certificate; 41 import java.util.stream.Collectors; 42 43 /** 44 * This class is initialized with a list of <code>PKIXCertPathChecker</code>s 45 * and is used to verify the certificates in a <code>CertPath</code> by 46 * feeding each certificate to each <code>PKIXCertPathChecker</code>. 47 * 48 * @since 1.4 49 * @author Yassir Elley 50 */ 51 class PKIXMasterCertPathValidator { 52 53 private static final Debug debug = Debug.getInstance("certpath"); 54 55 /** 56 * Validates a certification path consisting exclusively of 57 * <code>X509Certificate</code>s using the specified 58 * <code>PKIXCertPathChecker</code>s. It is assumed that the 59 * <code>PKIXCertPathChecker</code>s 60 * have been initialized with any input parameters they may need. 61 * 130 if (debug != null) { 131 debug.println("-checker" + (j + 1) + 132 " validation succeeded"); 133 } 134 135 } catch (CertPathValidatorException cpve) { 136 throw new CertPathValidatorException(cpve.getMessage(), 137 (cpve.getCause() != null) ? cpve.getCause() : cpve, 138 cpOriginal, cpSize - (i + 1), cpve.getReason()); 139 } 140 } 141 142 if (!unresCritExts.isEmpty()) { 143 throw new CertPathValidatorException("unrecognized " + 144 "critical extension(s)", null, cpOriginal, cpSize-(i+1), 145 PKIXReason.UNRECOGNIZED_CRIT_EXT); 146 } 147 148 if (debug != null) 149 debug.println("\ncert" + (i+1) + " validation succeeded.\n"); 150 151 CertificateChainEvent cce = new CertificateChainEvent(); 152 if(cce.isEnabled() || EventHelper.isLoggingSecurity()) { 153 String c = reversedCertList.stream() 154 .map(x -> x.getSerialNumber().toString(16)) 155 .collect(Collectors.joining(", ")); 156 EventHelper.commitCertChainEvent(cce, c); 157 } 158 } 159 160 if (debug != null) { 161 debug.println("Cert path validation succeeded. (PKIX validation " 162 + "algorithm)"); 163 debug.println("-------------------------------------------------" 164 + "-------------"); 165 } 166 } 167 } |