Skip to content

Commit 1650221

Browse files
alexeybakhtingnu-andrew
authored andcommittedOct 5, 2024
8328726: Better Kerberos support
Reviewed-by: mbalao, andrew Backport-of: 7325899a11f17bf4516d39495a12796385e459ed
1 parent 0405894 commit 1650221

File tree

9 files changed

+34
-55
lines changed

9 files changed

+34
-55
lines changed
 

‎jdk/src/share/classes/com/sun/security/auth/module/Krb5LoginModule.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import sun.security.krb5.*;
4242
import sun.security.jgss.krb5.Krb5Util;
4343
import sun.security.krb5.Credentials;
44-
import sun.misc.HexDumpEncoder;
4544

4645
/**
4746
* <p> This <code>LoginModule</code> authenticates users using
@@ -786,15 +785,11 @@ private void attemptAuthentication(boolean getPasswdFromSharedState)
786785

787786
if (debug) {
788787
System.out.println("principal is " + principal);
789-
HexDumpEncoder hd = new HexDumpEncoder();
790788
if (ktab != null) {
791789
System.out.println("Will use keytab");
792790
} else if (storeKey) {
793791
for (int i = 0; i < encKeys.length; i++) {
794-
System.out.println("EncryptionKey: keyType=" +
795-
encKeys[i].getEType() +
796-
" keyBytes (hex dump)=" +
797-
hd.encodeBuffer(encKeys[i].getBytes()));
792+
System.out.println(encKeys[i].toString());
798793
}
799794
}
800795
}
@@ -895,7 +890,7 @@ private void promptForPass(boolean getPasswdFromSharedState)
895890
}
896891
if (debug) {
897892
System.out.println
898-
("password is " + new String(password));
893+
("Get password from shared state");
899894
}
900895
return;
901896
}

‎jdk/src/share/classes/javax/security/auth/kerberos/KerberosKey.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -233,9 +233,9 @@ public String toString() {
233233
if (destroyed) {
234234
return "Destroyed Principal";
235235
}
236-
return "Kerberos Principal " + principal.toString() +
237-
"Key Version " + versionNum +
238-
"key " + key.toString();
236+
return "KerberosKey: principal " + principal +
237+
", version " + versionNum +
238+
", key " + key.toString();
239239
}
240240

241241
/**

‎jdk/src/share/classes/javax/security/auth/kerberos/KeyImpl.java

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,7 +30,8 @@
3030
import javax.crypto.SecretKey;
3131
import javax.security.auth.Destroyable;
3232
import javax.security.auth.DestroyFailedException;
33-
import sun.misc.HexDumpEncoder;
33+
34+
import sun.security.jgss.krb5.Krb5Util;
3435
import sun.security.krb5.Asn1Exception;
3536
import sun.security.krb5.PrincipalName;
3637
import sun.security.krb5.EncryptionKey;
@@ -200,15 +201,8 @@ private void readObject(ObjectInputStream ois)
200201
}
201202

202203
public String toString() {
203-
HexDumpEncoder hd = new HexDumpEncoder();
204-
return "EncryptionKey: keyType=" + keyType
205-
+ " keyBytes (hex dump)="
206-
+ (keyBytes == null || keyBytes.length == 0 ?
207-
" Empty Key" :
208-
'\n' + hd.encodeBuffer(keyBytes)
209-
+ '\n');
210-
211-
204+
return "keyType=" + keyType
205+
+ ", " + Krb5Util.keyInfo(keyBytes);
212206
}
213207

214208
public int hashCode() {

‎jdk/src/share/classes/sun/security/jgss/krb5/Krb5Context.java

+6-16
Original file line numberDiff line numberDiff line change
@@ -908,15 +908,11 @@ public final int getWrapSizeLimit(int qop, boolean confReq,
908908

909909
public final byte[] wrap(byte inBuf[], int offset, int len,
910910
MessageProp msgProp) throws GSSException {
911-
if (DEBUG) {
912-
System.out.println("Krb5Context.wrap: data=["
913-
+ getHexBytes(inBuf, offset, len)
914-
+ "]");
915-
}
916911

917-
if (state != STATE_DONE)
918-
throw new GSSException(GSSException.NO_CONTEXT, -1,
919-
"Wrap called in invalid state!");
912+
if (state != STATE_DONE) {
913+
throw new GSSException(GSSException.NO_CONTEXT, -1,
914+
"Wrap called in invalid state!");
915+
}
920916

921917
byte[] encToken = null;
922918
try {
@@ -1061,12 +1057,6 @@ public final byte[] unwrap(byte inBuf[], int offset, int len,
10611057
setSequencingAndReplayProps(token, msgProp);
10621058
}
10631059

1064-
if (DEBUG) {
1065-
System.out.println("Krb5Context.unwrap: data=["
1066-
+ getHexBytes(data, 0, data.length)
1067-
+ "]");
1068-
}
1069-
10701060
return data;
10711061
}
10721062

@@ -1412,8 +1402,8 @@ public byte[] getEncoded() {
14121402

14131403
@Override
14141404
public String toString() {
1415-
return "Kerberos session key: etype: " + key.getEType() + "\n" +
1416-
new sun.misc.HexDumpEncoder().encodeBuffer(key.getBytes());
1405+
return "Kerberos session key: etype=" + key.getEType()
1406+
+ ", " + Krb5Util.keyInfo(key.getBytes());
14171407
}
14181408
}
14191409

‎jdk/src/share/classes/sun/security/jgss/krb5/Krb5Util.java

+15
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,19 @@ public static EncryptionKey[] keysFromJavaxKeyTab(
301301
KeyTab ktab, PrincipalName cname) {
302302
return snapshotFromJavaxKeyTab(ktab).readServiceKeys(cname);
303303
}
304+
305+
public static String keyInfo(byte[] data) {
306+
if (data == null) {
307+
return "null key";
308+
} else if (data.length == 0) {
309+
return "empty key";
310+
} else {
311+
for (byte b : data) {
312+
if (b != 0) {
313+
return data.length + "-byte key";
314+
}
315+
}
316+
return data.length + "-byte zero key";
317+
}
318+
}
304319
}

‎jdk/src/share/classes/sun/security/krb5/EncryptionKey.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
package sun.security.krb5;
3333

34+
import sun.security.jgss.krb5.Krb5Util;
3435
import sun.security.util.*;
3536
import sun.security.krb5.internal.*;
3637
import sun.security.krb5.internal.crypto.*;
@@ -476,12 +477,7 @@ public synchronized void writeKey(CCacheOutputStream cos)
476477

477478
public String toString() {
478479
return new String("EncryptionKey: keyType=" + keyType
479-
+ " kvno=" + kvno
480-
+ " keyValue (hex dump)="
481-
+ (keyValue == null || keyValue.length == 0 ?
482-
" Empty Key" : '\n'
483-
+ Krb5.hexDumper.encodeBuffer(keyValue)
484-
+ '\n'));
480+
+ ", kvno=" + kvno + ", " + Krb5Util.keyInfo(keyValue));
485481
}
486482

487483
/**

‎jdk/src/share/classes/sun/security/krb5/internal/Krb5.java

-2
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,6 @@ public static String getErrorMessage(int i) {
312312
public static final boolean DEBUG =
313313
java.security.AccessController.doPrivileged(
314314
new sun.security.action.GetBooleanAction("sun.security.krb5.debug"));
315-
public static final sun.misc.HexDumpEncoder hexDumper =
316-
new sun.misc.HexDumpEncoder();
317315

318316
static {
319317
errMsgList = new Hashtable<Integer,String> ();

‎jdk/src/share/classes/sun/security/pkcs11/wrapper/CK_PBE_PARAMS.java

-5
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,6 @@ public String toString() {
121121
buffer.append(pPassword.length);
122122
buffer.append(Constants.NEWLINE);
123123

124-
buffer.append(Constants.INDENT);
125-
buffer.append("pPassword: ");
126-
buffer.append(pPassword);
127-
buffer.append(Constants.NEWLINE);
128-
129124
buffer.append(Constants.INDENT);
130125
buffer.append("ulSaltLen: ");
131126
buffer.append(pSalt.length);

‎jdk/src/windows/classes/sun/security/krb5/internal/tools/Kinit.java

-4
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,6 @@ private void acquire()
192192
System.out.print("Password for " + princName + ":");
193193
System.out.flush();
194194
psswd = Password.readPassword(System.in);
195-
if (DEBUG) {
196-
System.out.println(">>> Kinit console input " +
197-
new String(psswd));
198-
}
199195
}
200196
builder = new KrbAsReqBuilder(principal, psswd);
201197
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.