|
1 /* |
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
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 |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 /* |
|
25 * @test |
|
26 * @bug 8035986 |
|
27 * @summary KerberosKey algorithm names are not specified |
|
28 */ |
|
29 |
|
30 import sun.security.krb5.EncryptedData; |
|
31 |
|
32 import javax.crypto.Cipher; |
|
33 import javax.security.auth.kerberos.KerberosKey; |
|
34 import javax.security.auth.kerberos.KerberosPrincipal; |
|
35 import java.util.Locale; |
|
36 |
|
37 public class StandardNames { |
|
38 static KerberosPrincipal kp = new KerberosPrincipal("user@REALM"); |
|
39 static char[] pass = "secret".toCharArray(); |
|
40 static byte[] keyBytes = new byte[1]; |
|
41 |
|
42 public static void main(String[] args) throws Exception { |
|
43 for (EncType e: EncType.values()) { |
|
44 if (e == EncType.e18) { |
|
45 if (Cipher.getMaxAllowedKeyLength("AES") < 256) { |
|
46 System.out.println("Skipping aes256-cts-hmac-sha1-96"); |
|
47 continue; |
|
48 } |
|
49 } |
|
50 checkByName(e.name, e); |
|
51 checkByName(e.name.toUpperCase(Locale.US), e); |
|
52 for (String n: e.oldnames) { |
|
53 checkByName(n, e); |
|
54 if (n != null) { |
|
55 checkByName(n.toLowerCase(Locale.US), e); |
|
56 } |
|
57 } |
|
58 checkByEType(e.etype, e.name); |
|
59 } |
|
60 checkByEType(100, "unknown"); |
|
61 checkByEType(-1, "private"); |
|
62 |
|
63 try { |
|
64 System.out.println("unsupported"); |
|
65 new KerberosKey(kp, pass, "unsupported"); |
|
66 throw new Exception("unsupported"); |
|
67 } catch (IllegalArgumentException iae) { |
|
68 // Expected |
|
69 } |
|
70 } |
|
71 |
|
72 private static void checkByName(String n, EncType e) throws Exception { |
|
73 System.out.println("CheckByName " + n); |
|
74 KerberosKey k = new KerberosKey(kp, pass, n); |
|
75 if (!k.getAlgorithm().equals(e.name)) throw new Exception(n); |
|
76 if (k.getKeyType() != e.etype) throw new Exception(n); |
|
77 if (k.getVersionNumber() != 0) throw new Exception(n); |
|
78 } |
|
79 |
|
80 private static void checkByEType(int i, String n) throws Exception { |
|
81 System.out.println("CheckByInt " + i); |
|
82 KerberosKey k = new KerberosKey(kp, keyBytes, i, 13); |
|
83 if (!k.getAlgorithm().equals(n)) throw new Exception("" + i); |
|
84 if (k.getKeyType() != i) throw new Exception("" + i); |
|
85 if (k.getVersionNumber() != 13) throw new Exception("" + i); |
|
86 } |
|
87 } |
|
88 |
|
89 enum EncType { |
|
90 e0("none", EncryptedData.ETYPE_NULL), |
|
91 e1("des-cbc-crc", EncryptedData.ETYPE_DES_CBC_CRC), |
|
92 e3("des-cbc-md5", EncryptedData.ETYPE_DES_CBC_MD5, "DES", null), |
|
93 e16("des3-cbc-sha1-kd", EncryptedData.ETYPE_DES3_CBC_HMAC_SHA1_KD, "DESede"), |
|
94 e17("aes128-cts-hmac-sha1-96", EncryptedData.ETYPE_AES128_CTS_HMAC_SHA1_96, "AES128"), |
|
95 e18("aes256-cts-hmac-sha1-96", EncryptedData.ETYPE_AES256_CTS_HMAC_SHA1_96, "AES256"), |
|
96 e23("rc4-hmac", EncryptedData.ETYPE_ARCFOUR_HMAC, "ArcFourHmac"), |
|
97 ; |
|
98 |
|
99 final String name; |
|
100 final int etype; |
|
101 final String[] oldnames; |
|
102 |
|
103 EncType(String name, int etype, String... oldnames) { |
|
104 this.name = name; |
|
105 this.etype = etype; |
|
106 this.oldnames = oldnames; |
|
107 } |
|
108 } |