jdk/test/javax/net/ssl/GetInstance.java
author amlu
Thu, 18 Feb 2016 09:46:07 +0800
changeset 36003 6519aa869709
parent 30820 0d4717a011d3
permissions -rw-r--r--
8149922: Remove intermittent key from security tests 8150047: Remove SSLSession/SessionCacheSizeTests from ProblemList Reviewed-by: xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
8791
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
     2
 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
8791
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    26
 * @bug 4898428 7022855
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary verify getInstance() works using Provider.getService()
8791
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    28
 *          Export "PKIX" as the standard algorithm name of KeyManagerFactory
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @author Andreas Sterbenz
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 23052
diff changeset
    30
 * @modules java.base/com.sun.net.ssl
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.net.ssl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public class GetInstance {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private static void same(Provider p1, Provider p2) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        if (p1 != p2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
            throw new Exception("not same object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        long start = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        Provider p = Security.getProvider("SunJSSE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        SSLContext context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        context = SSLContext.getInstance("SSL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        same(p, context.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        context = SSLContext.getInstance("SSL", "SunJSSE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        same(p, context.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        context = SSLContext.getInstance("SSL", p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        same(p, context.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        KeyManagerFactory kmf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        kmf = KeyManagerFactory.getInstance("SunX509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        same(p, kmf.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        kmf = KeyManagerFactory.getInstance("SunX509", "SunJSSE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        same(p, kmf.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        kmf = KeyManagerFactory.getInstance("SunX509", p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        same(p, kmf.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
8791
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    66
        kmf = KeyManagerFactory.getInstance("NewSunX509");
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    67
        same(p, kmf.getProvider());
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    68
        kmf = KeyManagerFactory.getInstance("NewSunX509", "SunJSSE");
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    69
        same(p, kmf.getProvider());
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    70
        kmf = KeyManagerFactory.getInstance("NewSunX509", p);
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    71
        same(p, kmf.getProvider());
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    72
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    73
        kmf = KeyManagerFactory.getInstance("PKIX");
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    74
        same(p, kmf.getProvider());
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    75
        kmf = KeyManagerFactory.getInstance("PKIX", "SunJSSE");
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    76
        same(p, kmf.getProvider());
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    77
        kmf = KeyManagerFactory.getInstance("PKIX", p);
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    78
        same(p, kmf.getProvider());
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    79
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        TrustManagerFactory tmf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        tmf = TrustManagerFactory.getInstance("SunX509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        same(p, tmf.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        tmf = TrustManagerFactory.getInstance("SunX509", "SunJSSE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        same(p, tmf.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        tmf = TrustManagerFactory.getInstance("SunX509", p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        same(p, tmf.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
8791
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    88
        tmf = TrustManagerFactory.getInstance("PKIX");
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    89
        same(p, tmf.getProvider());
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    90
        tmf = TrustManagerFactory.getInstance("PKIX", "SunJSSE");
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    91
        same(p, tmf.getProvider());
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    92
        tmf = TrustManagerFactory.getInstance("PKIX", p);
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    93
        same(p, tmf.getProvider());
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    94
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    95
        tmf = TrustManagerFactory.getInstance("SunPKIX");
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    96
        same(p, tmf.getProvider());
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    97
        tmf = TrustManagerFactory.getInstance("SunPKIX", "SunJSSE");
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    98
        same(p, tmf.getProvider());
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
    99
        tmf = TrustManagerFactory.getInstance("SunPKIX", p);
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
   100
        same(p, tmf.getProvider());
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
   101
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
   102
        tmf = TrustManagerFactory.getInstance("X509");
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
   103
        same(p, tmf.getProvider());
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
   104
        tmf = TrustManagerFactory.getInstance("X509", "SunJSSE");
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
   105
        same(p, tmf.getProvider());
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
   106
        tmf = TrustManagerFactory.getInstance("X509", p);
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
   107
        same(p, tmf.getProvider());
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
   108
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
   109
        tmf = TrustManagerFactory.getInstance("X.509");
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
   110
        same(p, tmf.getProvider());
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
   111
        tmf = TrustManagerFactory.getInstance("X.509", "SunJSSE");
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
   112
        same(p, tmf.getProvider());
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
   113
        tmf = TrustManagerFactory.getInstance("X.509", p);
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
   114
        same(p, tmf.getProvider());
f5106bbf577d 7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents: 5506
diff changeset
   115
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        testComSun();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        long stop = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        System.out.println("Done (" + (stop - start) + " ms).");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private static void testComSun() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        Provider p = Security.getProvider("SunJSSE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        com.sun.net.ssl.SSLContext context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        context = com.sun.net.ssl.SSLContext.getInstance("SSL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        same(p, context.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        context = com.sun.net.ssl.SSLContext.getInstance("SSL", "SunJSSE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        same(p, context.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        context = com.sun.net.ssl.SSLContext.getInstance("SSL", p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        same(p, context.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        com.sun.net.ssl.KeyManagerFactory kmf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        kmf = com.sun.net.ssl.KeyManagerFactory.getInstance("SunX509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        same(p, kmf.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        kmf = com.sun.net.ssl.KeyManagerFactory.getInstance("SunX509", "SunJSSE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        same(p, kmf.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        kmf = com.sun.net.ssl.KeyManagerFactory.getInstance("SunX509", p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        same(p, kmf.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        com.sun.net.ssl.TrustManagerFactory tmf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        tmf = com.sun.net.ssl.TrustManagerFactory.getInstance("SunX509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        same(p, tmf.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        tmf = com.sun.net.ssl.TrustManagerFactory.getInstance("SunX509", "SunJSSE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        same(p, tmf.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        tmf = com.sun.net.ssl.TrustManagerFactory.getInstance("SunX509", p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        same(p, tmf.getProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
}