Skip to content

Commit feed7d8

Browse files
Alexey BakhtinRealCLanger
authored andcommitted
8328726: Better Kerberos support
Reviewed-by: mbalao Backport-of: 7325899a11f17bf4516d39495a12796385e459ed
1 parent 4dc3701 commit feed7d8

File tree

11 files changed

+39
-62
lines changed

11 files changed

+39
-62
lines changed

src/java.security.jgss/share/classes/javax/security/auth/kerberos/EncryptionKey.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 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
@@ -168,7 +168,7 @@ public String toString() {
168168
if (destroyed) {
169169
return "Destroyed EncryptionKey";
170170
}
171-
return "key " + key.toString();
171+
return "EncryptionKey: " + key.toString();
172172
}
173173

174174
/**

src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosCredMessage.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 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
@@ -27,7 +27,6 @@
2727

2828
import javax.security.auth.Destroyable;
2929
import java.util.Arrays;
30-
import java.util.Base64;
3130
import java.util.Objects;
3231

3332
/**
@@ -140,8 +139,7 @@ public String toString() {
140139
if (destroyed) {
141140
return "Destroyed KerberosCredMessage";
142141
} else {
143-
return "KRB_CRED from " + sender + " to " + recipient + ":\n"
144-
+ Base64.getUrlEncoder().encodeToString(message);
142+
return "KRB_CRED from " + sender + " to " + recipient;
145143
}
146144
}
147145

src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosKey.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2020, 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
@@ -270,9 +270,9 @@ public String toString() {
270270
if (destroyed) {
271271
return "Destroyed KerberosKey";
272272
}
273-
return "Kerberos Principal " + principal +
274-
"Key Version " + versionNum +
275-
"key " + key.toString();
273+
return "KerberosKey: principal " + principal +
274+
", version " + versionNum +
275+
", key " + key.toString();
276276
}
277277

278278
/**

src/java.security.jgss/share/classes/javax/security/auth/kerberos/KeyImpl.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2021, 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.security.util.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;
@@ -222,15 +223,8 @@ private void readObject(ObjectInputStream ois)
222223
}
223224

224225
public String toString() {
225-
HexDumpEncoder hd = new HexDumpEncoder();
226-
return "EncryptionKey: keyType=" + keyType
227-
+ " keyBytes (hex dump)="
228-
+ (keyBytes == null || keyBytes.length == 0 ?
229-
" Empty Key" :
230-
'\n' + hd.encodeBuffer(keyBytes)
231-
+ '\n');
232-
233-
226+
return "keyType=" + keyType
227+
+ ", " + Krb5Util.keyInfo(keyBytes);
234228
}
235229

236230
public int hashCode() {

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -914,15 +914,11 @@ public final int getWrapSizeLimit(int qop, boolean confReq,
914914

915915
public final byte[] wrap(byte[] inBuf, int offset, int len,
916916
MessageProp msgProp) throws GSSException {
917-
if (DEBUG) {
918-
System.out.println("Krb5Context.wrap: data=["
919-
+ getHexBytes(inBuf, offset, len)
920-
+ "]");
921-
}
922917

923-
if (state != STATE_DONE)
924-
throw new GSSException(GSSException.NO_CONTEXT, -1,
925-
"Wrap called in invalid state!");
918+
if (state != STATE_DONE) {
919+
throw new GSSException(GSSException.NO_CONTEXT, -1,
920+
"Wrap called in invalid state!");
921+
}
926922

927923
byte[] encToken = null;
928924
try {
@@ -1067,12 +1063,6 @@ public final byte[] unwrap(byte[] inBuf, int offset, int len,
10671063
setSequencingAndReplayProps(token, msgProp);
10681064
}
10691065

1070-
if (DEBUG) {
1071-
System.out.println("Krb5Context.unwrap: data=["
1072-
+ getHexBytes(data, 0, data.length)
1073-
+ "]");
1074-
}
1075-
10761066
return data;
10771067
}
10781068

@@ -1423,8 +1413,8 @@ public byte[] getEncoded() {
14231413

14241414
@Override
14251415
public String toString() {
1426-
return "Kerberos session key: etype: " + key.getEType() + "\n" +
1427-
new HexDumpEncoder().encodeBuffer(key.getBytes());
1416+
return "Kerberos session key: etype=" + key.getEType()
1417+
+ ", " + Krb5Util.keyInfo(key.getBytes());
14281418
}
14291419
}
14301420

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,19 @@ public static EncryptionKey[] keysFromJavaxKeyTab(
201201
KeyTab ktab, PrincipalName cname) {
202202
return snapshotFromJavaxKeyTab(ktab).readServiceKeys(cname);
203203
}
204+
205+
public static String keyInfo(byte[] data) {
206+
if (data == null) {
207+
return "null key";
208+
} else if (data.length == 0) {
209+
return "empty key";
210+
} else {
211+
for (byte b : data) {
212+
if (b != 0) {
213+
return data.length + "-byte key";
214+
}
215+
}
216+
return data.length + "-byte zero key";
217+
}
218+
}
204219
}

src/java.security.jgss/share/classes/sun/security/krb5/EncryptionKey.java

Lines changed: 2 additions & 6 deletions
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.*;
@@ -498,12 +499,7 @@ public synchronized void writeKey(CCacheOutputStream cos)
498499

499500
public String toString() {
500501
return new String("EncryptionKey: keyType=" + keyType
501-
+ " kvno=" + kvno
502-
+ " keyValue (hex dump)="
503-
+ (keyValue == null || keyValue.length == 0 ?
504-
" Empty Key" : '\n'
505-
+ Krb5.hexDumper.encodeBuffer(keyValue)
506-
+ '\n'));
502+
+ ", kvno=" + kvno + ", " + Krb5Util.keyInfo(keyValue));
507503
}
508504

509505
/**

src/java.security.jgss/share/classes/sun/security/krb5/internal/Krb5.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,6 @@ public static String getErrorMessage(int i) {
315315
public static final boolean DEBUG = GetBooleanAction
316316
.privilegedGetProperty("sun.security.krb5.debug");
317317

318-
public static final sun.security.util.HexDumpEncoder hexDumper =
319-
new sun.security.util.HexDumpEncoder();
320-
321318
static {
322319
errMsgList = new Hashtable<Integer,String> ();
323320
errMsgList.put(KDC_ERR_NONE, "No error");

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

Lines changed: 0 additions & 4 deletions
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 {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,6 @@ public String toString() {
121121
sb.append(pPassword.length);
122122
sb.append(Constants.NEWLINE);
123123

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

0 commit comments

Comments
 (0)