mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-18 01:17:57 +00:00
6844909: support allow_weak_crypto in krb5.conf
Reviewed-by: valeriep
This commit is contained in:
parent
fa7b68252b
commit
8055ab99b7
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Portions Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* Portions Copyright 2000-2010 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -36,9 +36,9 @@ import sun.security.krb5.Config;
|
||||
import sun.security.krb5.EncryptedData;
|
||||
import sun.security.krb5.EncryptionKey;
|
||||
import sun.security.krb5.KrbException;
|
||||
import sun.security.krb5.Asn1Exception;
|
||||
import sun.security.krb5.KrbCryptoException;
|
||||
import javax.crypto.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -48,6 +48,23 @@ import java.util.ArrayList;
|
||||
public abstract class EType {
|
||||
|
||||
private static final boolean DEBUG = Krb5.DEBUG;
|
||||
private static final boolean ALLOW_WEAK_CRYPTO;
|
||||
|
||||
static {
|
||||
boolean allowed = true;
|
||||
try {
|
||||
Config cfg = Config.getInstance();
|
||||
String temp = cfg.getDefault("allow_weak_crypto", "libdefaults");
|
||||
if (temp != null && temp.equals("false")) allowed = false;
|
||||
} catch (Exception exc) {
|
||||
if (DEBUG) {
|
||||
System.out.println ("Exception in getting allow_weak_crypto, " +
|
||||
"using default value " +
|
||||
exc.getMessage());
|
||||
}
|
||||
}
|
||||
ALLOW_WEAK_CRYPTO = allowed;
|
||||
}
|
||||
|
||||
public static EType getInstance (int eTypeConst)
|
||||
throws KdcErrException {
|
||||
@ -163,6 +180,10 @@ public abstract class EType {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Note: the first 2 entries of BUILTIN_ETYPES and BUILTIN_ETYPES_NOAES256
|
||||
// should be kept DES-related. They will be removed when allow_weak_crypto
|
||||
// is set to false.
|
||||
|
||||
private static final int[] BUILTIN_ETYPES = new int[] {
|
||||
EncryptedData.ETYPE_DES_CBC_MD5,
|
||||
EncryptedData.ETYPE_DES_CBC_CRC,
|
||||
@ -189,10 +210,17 @@ public abstract class EType {
|
||||
} catch (Exception e) {
|
||||
// should not happen
|
||||
}
|
||||
int[] result;
|
||||
if (allowed < 256) {
|
||||
return BUILTIN_ETYPES_NOAES256;
|
||||
result = BUILTIN_ETYPES_NOAES256;
|
||||
} else {
|
||||
result = BUILTIN_ETYPES;
|
||||
}
|
||||
return BUILTIN_ETYPES;
|
||||
if (!ALLOW_WEAK_CRYPTO) {
|
||||
// The first 2 etypes are now weak ones
|
||||
return Arrays.copyOfRange(result, 2, result.length);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -207,9 +235,7 @@ public abstract class EType {
|
||||
if (DEBUG) {
|
||||
System.out.println("Exception while getting " +
|
||||
configName + exc.getMessage());
|
||||
System.out.println("Using defaults " +
|
||||
"des-cbc-md5, des-cbc-crc, des3-cbc-sha1," +
|
||||
" aes128cts, aes256cts, rc4-hmac");
|
||||
System.out.println("Using default builtin etypes");
|
||||
}
|
||||
return getBuiltInDefaults();
|
||||
}
|
||||
|
||||
50
jdk/test/sun/security/krb5/etype/WeakCrypto.java
Normal file
50
jdk/test/sun/security/krb5/etype/WeakCrypto.java
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 6844909
|
||||
* @run main/othervm WeakCrypto
|
||||
* @summary support allow_weak_crypto in krb5.conf
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import sun.security.krb5.internal.crypto.EType;
|
||||
import sun.security.krb5.EncryptedData;
|
||||
|
||||
public class WeakCrypto {
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.setProperty("java.security.krb5.conf",
|
||||
System.getProperty("test.src", ".") +
|
||||
File.separator +
|
||||
"weakcrypto.conf");
|
||||
int[] etypes = EType.getBuiltInDefaults();
|
||||
|
||||
for (int i=0, length = etypes.length; i<length; i++) {
|
||||
if (etypes[i] == EncryptedData.ETYPE_DES_CBC_CRC ||
|
||||
etypes[i] == EncryptedData.ETYPE_DES_CBC_MD4 ||
|
||||
etypes[i] == EncryptedData.ETYPE_DES_CBC_MD5) {
|
||||
throw new Exception("DES should not appear");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
jdk/test/sun/security/krb5/etype/weakcrypto.conf
Normal file
2
jdk/test/sun/security/krb5/etype/weakcrypto.conf
Normal file
@ -0,0 +1,2 @@
|
||||
[libdefaults]
|
||||
allow_weak_crypto = false
|
||||
Loading…
x
Reference in New Issue
Block a user