Path: blob/master/test/jdk/javax/security/auth/kerberos/StandardNames.java
41152 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 803598626* @summary KerberosKey algorithm names are not specified27* @modules java.security.jgss/sun.security.krb528*/2930import sun.security.krb5.EncryptedData;3132import javax.crypto.Cipher;33import javax.security.auth.kerberos.KerberosKey;34import javax.security.auth.kerberos.KerberosPrincipal;35import java.util.Locale;3637public class StandardNames {38static KerberosPrincipal kp = new KerberosPrincipal("user@REALM");39static char[] pass = "secret".toCharArray();40static byte[] keyBytes = new byte[1];4142public static void main(String[] args) throws Exception {43for (EncType e: EncType.values()) {44if (e == EncType.e18) {45if (Cipher.getMaxAllowedKeyLength("AES") < 256) {46System.out.println("Skipping aes256-cts-hmac-sha1-96");47continue;48}49}50checkByName(e.name, e);51checkByName(e.name.toUpperCase(Locale.US), e);52for (String n: e.oldnames) {53checkByName(n, e);54if (n != null) {55checkByName(n.toLowerCase(Locale.US), e);56}57}58checkByEType(e.etype, e.name);59}60checkByEType(100, "unknown");61checkByEType(-1, "private");6263try {64System.out.println("unsupported");65new KerberosKey(kp, pass, "unsupported");66throw new Exception("unsupported");67} catch (IllegalArgumentException iae) {68// Expected69}70}7172private static void checkByName(String n, EncType e) throws Exception {73System.out.println("CheckByName " + n);74KerberosKey k = new KerberosKey(kp, pass, n);75if (!k.getAlgorithm().equals(e.name)) throw new Exception(n);76if (k.getKeyType() != e.etype) throw new Exception(n);77if (k.getVersionNumber() != 0) throw new Exception(n);78}7980private static void checkByEType(int i, String n) throws Exception {81System.out.println("CheckByInt " + i);82KerberosKey k = new KerberosKey(kp, keyBytes, i, 13);83if (!k.getAlgorithm().equals(n)) throw new Exception("" + i);84if (k.getKeyType() != i) throw new Exception("" + i);85if (k.getVersionNumber() != 13) throw new Exception("" + i);86}87}8889enum EncType {90e0("none", EncryptedData.ETYPE_NULL),91e1("des-cbc-crc", EncryptedData.ETYPE_DES_CBC_CRC),92e3("des-cbc-md5", EncryptedData.ETYPE_DES_CBC_MD5, "DES", null),93e16("des3-cbc-sha1-kd", EncryptedData.ETYPE_DES3_CBC_HMAC_SHA1_KD, "DESede"),94e17("aes128-cts-hmac-sha1-96", EncryptedData.ETYPE_AES128_CTS_HMAC_SHA1_96, "AES128"),95e18("aes256-cts-hmac-sha1-96", EncryptedData.ETYPE_AES256_CTS_HMAC_SHA1_96, "AES256"),96e23("rc4-hmac", EncryptedData.ETYPE_ARCFOUR_HMAC, "ArcFourHmac"),97;9899final String name;100final int etype;101final String[] oldnames;102103EncType(String name, int etype, String... oldnames) {104this.name = name;105this.etype = etype;106this.oldnames = oldnames;107}108}109110111