test/jdk/sun/security/ssl/X509TrustManagerImpl/CheckNullEntity.java
changeset 53972 43c2ab1bdfd3
parent 47216 71c04702a3d5
equal deleted inserted replaced
53971:1019c97e1bde 53972:43c2ab1bdfd3
     1 /*
     1 /*
     2  * Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    25  * @test
    25  * @test
    26  * @bug 5053815
    26  * @bug 5053815
    27  * @summary unspecified exceptions in X509TrustManager.checkClient[Server]Truste
    27  * @summary unspecified exceptions in X509TrustManager.checkClient[Server]Truste
    28 d
    28 d
    29  * @author Xuelei Fan
    29  * @author Xuelei Fan
    30  * @modules java.base/com.sun.net.ssl.internal.ssl
       
    31  */
    30  */
    32 
    31 
    33 import java.io.*;
    32 import java.io.*;
    34 import java.net.*;
    33 import java.net.*;
    35 import javax.net.ssl.*;
    34 import javax.net.ssl.*;
    36 import java.security.cert.X509Certificate;
    35 import java.security.cert.X509Certificate;
    37 import java.security.*;
    36 import java.security.*;
    38 import java.util.Enumeration;
    37 import java.util.Enumeration;
    39 
    38 
    40 import com.sun.net.ssl.internal.ssl.X509ExtendedTrustManager;
       
    41 
       
    42 public class CheckNullEntity {
    39 public class CheckNullEntity {
    43 
    40 
    44     /*
    41     /*
    45      * =============================================================
    42      * =============================================================
    46      * Set the various variables needed for the tests, then
    43      * Set the various variables needed for the tests, then
   155             }
   152             }
   156 
   153 
   157             if (trustManager instanceof X509ExtendedTrustManager) {
   154             if (trustManager instanceof X509ExtendedTrustManager) {
   158                 try {
   155                 try {
   159                     ((X509ExtendedTrustManager)trustManager).checkClientTrusted(
   156                     ((X509ExtendedTrustManager)trustManager).checkClientTrusted(
   160                         certChain, (String)null, "localhost", null);
   157                         certChain, (String)null, (Socket)null);
   161                 } catch (IllegalArgumentException iae) {
   158                 } catch (IllegalArgumentException iae) {
   162                     // get the right exception
   159                     // get the right exception
   163                     extFailed >>= 1;
   160                     extFailed >>= 1;
   164                 }
   161                 }
   165 
   162 
   166                 try {
   163                 try {
   167                     ((X509ExtendedTrustManager)trustManager).checkServerTrusted(
   164                     ((X509ExtendedTrustManager)trustManager).checkServerTrusted(
   168                         certChain, (String)null, "localhost", null);
   165                         certChain, (String)null, (Socket)null);
   169                 } catch (IllegalArgumentException iae) {
   166                 } catch (IllegalArgumentException iae) {
   170                     // get the right exception
   167                     // get the right exception
   171                     extFailed >>= 1;
   168                     extFailed >>= 1;
   172                 }
   169                 }
   173 
   170 
   174                 try {
   171                 try {
   175                     ((X509ExtendedTrustManager)trustManager).checkClientTrusted(
   172                     ((X509ExtendedTrustManager)trustManager).checkClientTrusted(
   176                         certChain, "", "localhost", null);
   173                         certChain, "", (Socket)null);
   177                 } catch (IllegalArgumentException iae) {
   174                 } catch (IllegalArgumentException iae) {
   178                     // get the right exception
   175                     // get the right exception
   179                     extFailed >>= 1;
   176                     extFailed >>= 1;
   180                 }
   177                 }
   181 
   178 
   182                 try {
   179                 try {
   183                     ((X509ExtendedTrustManager)trustManager).checkServerTrusted(
   180                     ((X509ExtendedTrustManager)trustManager).checkServerTrusted(
   184                         certChain, "", "localhost", null);
   181                         certChain, "", (Socket)null);
   185                 } catch (IllegalArgumentException iae) {
   182                 } catch (IllegalArgumentException iae) {
   186                     // get the right exception
   183                     // get the right exception
   187                     extFailed >>= 1;
   184                     extFailed >>= 1;
   188                 }
   185                 }
   189 
   186 
   190                 try {
   187                 try {
   191                     ((X509ExtendedTrustManager)trustManager).checkClientTrusted(
   188                     ((X509ExtendedTrustManager)trustManager).checkClientTrusted(
   192                         null, authType, "localhost", null);
   189                         null, authType, (Socket)null);
   193                 } catch (IllegalArgumentException iae) {
   190                 } catch (IllegalArgumentException iae) {
   194                     // get the right exception
   191                     // get the right exception
   195                     extFailed >>= 1;
   192                     extFailed >>= 1;
   196                 }
   193                 }
   197 
   194 
   198                 try {
   195                 try {
   199                     ((X509ExtendedTrustManager)trustManager).checkServerTrusted(
   196                     ((X509ExtendedTrustManager)trustManager).checkServerTrusted(
   200                         null, authType, "localhost", null);
   197                         null, authType, (Socket)null);
   201                 } catch (IllegalArgumentException iae) {
   198                 } catch (IllegalArgumentException iae) {
   202                     // get the right exception
   199                     // get the right exception
   203                     extFailed >>= 1;
   200                     extFailed >>= 1;
   204                 }
   201                 }
   205             } else {
   202             } else {