empty password for kerberos
# HG changeset patch
# User weijun
# Date 1254482766 -28800
# Node ID a294a748ac80c27cebbbdf38992098a9761cebec
# Parent 2c247f14034adf4662221dfb46b45ca292ebfb15
6879540: enable empty password for kerberos 5
Reviewed-by: nobody
--- a/src/share/classes/com/sun/crypto/provider/HmacCore.java Fri Oct 02 19:26:03 2009 +0800
+++ b/src/share/classes/com/sun/crypto/provider/HmacCore.java Fri Oct 02 19:26:06 2009 +0800
@@ -116,7 +116,7 @@
}
byte[] secret = key.getEncoded();
- if (secret == null || secret.length == 0) {
+ if (secret == null) {
throw new InvalidKeyException("Missing key data");
}
--- a/src/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java Fri Oct 02 19:26:03 2009 +0800
+++ b/src/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java Fri Oct 02 19:26:06 2009 +0800
@@ -1,5 +1,5 @@
/*
- * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 2005-2009 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
@@ -25,21 +25,19 @@
package com.sun.crypto.provider;
-import java.io.*;
+import java.io.ObjectStreamException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.security.KeyRep;
import java.security.GeneralSecurityException;
-import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.PBEKeySpec;
-import javax.crypto.spec.SecretKeySpec;
/**
* This class represents a PBE key derived using PBKDF2 defined
@@ -123,7 +121,7 @@
this.key = deriveKey(prf, passwdBytes, salt, iterCount, keyLength);
}
- private static byte[] deriveKey(Mac prf, byte[] password, byte[] salt,
+ private static byte[] deriveKey(final Mac prf, final byte[] password, byte[] salt,
int iterCount, int keyLengthInBit) {
int keyLength = keyLengthInBit/8;
byte[] key = new byte[keyLength];
@@ -133,7 +131,18 @@
int intR = keyLength - (intL - 1)*hlen; // residue
byte[] ui = new byte[hlen];
byte[] ti = new byte[hlen];
- SecretKey macKey = new SecretKeySpec(password, prf.getAlgorithm());
+ // SecretKeySpec cannot be used, since password can be empty here.
+ SecretKey macKey = new SecretKey() {
+ public String getAlgorithm() {
+ return prf.getAlgorithm();
+ }
+ public String getFormat() {
+ return "RAW";
+ }
+ public byte[] getEncoded() {
+ return password;
+ }
+ };
prf.init(macKey);
byte[] ibytes = new byte[4];
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/security/krb5/auto/EmptyPassword.java Fri Oct 02 19:26:06 2009 +0800
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2009 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 6879540
+ * @summary enable empty password for kerberos 5
+ */
+
+public class EmptyPassword {
+
+ public static void main(String[] args)
+ throws Exception {
+
+ OneKDC kdc = new OneKDC("aes128-cts");
+ kdc.addPrincipal("empty", "".toCharArray());
+
+ Context c = Context.fromUserPass("empty", "".toCharArray(), false);
+ c.status();
+ }
+}