Skip to content
Snippets Groups Projects
Commit 6e6e3cf6 authored by Alexey Bakhtin's avatar Alexey Bakhtin Committed by Christoph Langer
Browse files

8328726: Better Kerberos support

Reviewed-by: mbalao
Backport-of: 7325899a11f17bf4516d39495a12796385e459ed
parent cdd9e7e2
No related branches found
No related tags found
No related merge requests found
Showing
with 39 additions and 62 deletions
/* /*
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -168,7 +168,7 @@ public final class EncryptionKey implements SecretKey { ...@@ -168,7 +168,7 @@ public final class EncryptionKey implements SecretKey {
if (destroyed) { if (destroyed) {
return "Destroyed EncryptionKey"; return "Destroyed EncryptionKey";
} }
return "key " + key.toString(); return "EncryptionKey: " + key.toString();
} }
/** /**
......
/* /*
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -27,7 +27,6 @@ package javax.security.auth.kerberos; ...@@ -27,7 +27,6 @@ package javax.security.auth.kerberos;
import javax.security.auth.Destroyable; import javax.security.auth.Destroyable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Base64;
import java.util.Objects; import java.util.Objects;
/** /**
...@@ -140,8 +139,7 @@ public final class KerberosCredMessage implements Destroyable { ...@@ -140,8 +139,7 @@ public final class KerberosCredMessage implements Destroyable {
if (destroyed) { if (destroyed) {
return "Destroyed KerberosCredMessage"; return "Destroyed KerberosCredMessage";
} else { } else {
return "KRB_CRED from " + sender + " to " + recipient + ":\n" return "KRB_CRED from " + sender + " to " + recipient;
+ Base64.getUrlEncoder().encodeToString(message);
} }
} }
......
/* /*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -270,9 +270,9 @@ public class KerberosKey implements SecretKey { ...@@ -270,9 +270,9 @@ public class KerberosKey implements SecretKey {
if (destroyed) { if (destroyed) {
return "Destroyed KerberosKey"; return "Destroyed KerberosKey";
} }
return "Kerberos Principal " + principal + return "KerberosKey: principal " + principal +
"Key Version " + versionNum + ", version " + versionNum +
"key " + key.toString(); ", key " + key.toString();
} }
/** /**
......
/* /*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -30,7 +30,8 @@ import java.util.Arrays; ...@@ -30,7 +30,8 @@ import java.util.Arrays;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import javax.security.auth.Destroyable; import javax.security.auth.Destroyable;
import javax.security.auth.DestroyFailedException; import javax.security.auth.DestroyFailedException;
import sun.security.util.HexDumpEncoder;
import sun.security.jgss.krb5.Krb5Util;
import sun.security.krb5.Asn1Exception; import sun.security.krb5.Asn1Exception;
import sun.security.krb5.PrincipalName; import sun.security.krb5.PrincipalName;
import sun.security.krb5.EncryptionKey; import sun.security.krb5.EncryptionKey;
...@@ -222,15 +223,8 @@ class KeyImpl implements SecretKey, Destroyable, Serializable { ...@@ -222,15 +223,8 @@ class KeyImpl implements SecretKey, Destroyable, Serializable {
} }
public String toString() { public String toString() {
HexDumpEncoder hd = new HexDumpEncoder(); return "keyType=" + keyType
return "EncryptionKey: keyType=" + keyType + ", " + Krb5Util.keyInfo(keyBytes);
+ " keyBytes (hex dump)="
+ (keyBytes == null || keyBytes.length == 0 ?
" Empty Key" :
'\n' + hd.encodeBuffer(keyBytes)
+ '\n');
} }
public int hashCode() { public int hashCode() {
......
...@@ -914,15 +914,11 @@ class Krb5Context implements GSSContextSpi { ...@@ -914,15 +914,11 @@ class Krb5Context implements GSSContextSpi {
public final byte[] wrap(byte[] inBuf, int offset, int len, public final byte[] wrap(byte[] inBuf, int offset, int len,
MessageProp msgProp) throws GSSException { MessageProp msgProp) throws GSSException {
if (DEBUG) {
System.out.println("Krb5Context.wrap: data=["
+ getHexBytes(inBuf, offset, len)
+ "]");
}
if (state != STATE_DONE) if (state != STATE_DONE) {
throw new GSSException(GSSException.NO_CONTEXT, -1, throw new GSSException(GSSException.NO_CONTEXT, -1,
"Wrap called in invalid state!"); "Wrap called in invalid state!");
}
byte[] encToken = null; byte[] encToken = null;
try { try {
...@@ -1067,12 +1063,6 @@ class Krb5Context implements GSSContextSpi { ...@@ -1067,12 +1063,6 @@ class Krb5Context implements GSSContextSpi {
setSequencingAndReplayProps(token, msgProp); setSequencingAndReplayProps(token, msgProp);
} }
if (DEBUG) {
System.out.println("Krb5Context.unwrap: data=["
+ getHexBytes(data, 0, data.length)
+ "]");
}
return data; return data;
} }
...@@ -1423,8 +1413,8 @@ class Krb5Context implements GSSContextSpi { ...@@ -1423,8 +1413,8 @@ class Krb5Context implements GSSContextSpi {
@Override @Override
public String toString() { public String toString() {
return "Kerberos session key: etype: " + key.getEType() + "\n" + return "Kerberos session key: etype=" + key.getEType()
new HexDumpEncoder().encodeBuffer(key.getBytes()); + ", " + Krb5Util.keyInfo(key.getBytes());
} }
} }
......
...@@ -201,4 +201,19 @@ public class Krb5Util { ...@@ -201,4 +201,19 @@ public class Krb5Util {
KeyTab ktab, PrincipalName cname) { KeyTab ktab, PrincipalName cname) {
return snapshotFromJavaxKeyTab(ktab).readServiceKeys(cname); return snapshotFromJavaxKeyTab(ktab).readServiceKeys(cname);
} }
public static String keyInfo(byte[] data) {
if (data == null) {
return "null key";
} else if (data.length == 0) {
return "empty key";
} else {
for (byte b : data) {
if (b != 0) {
return data.length + "-byte key";
}
}
return data.length + "-byte zero key";
}
}
} }
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
package sun.security.krb5; package sun.security.krb5;
import sun.security.jgss.krb5.Krb5Util;
import sun.security.util.*; import sun.security.util.*;
import sun.security.krb5.internal.*; import sun.security.krb5.internal.*;
import sun.security.krb5.internal.crypto.*; import sun.security.krb5.internal.crypto.*;
...@@ -498,12 +499,7 @@ public class EncryptionKey ...@@ -498,12 +499,7 @@ public class EncryptionKey
public String toString() { public String toString() {
return new String("EncryptionKey: keyType=" + keyType return new String("EncryptionKey: keyType=" + keyType
+ " kvno=" + kvno + ", kvno=" + kvno + ", " + Krb5Util.keyInfo(keyValue));
+ " keyValue (hex dump)="
+ (keyValue == null || keyValue.length == 0 ?
" Empty Key" : '\n'
+ Krb5.hexDumper.encodeBuffer(keyValue)
+ '\n'));
} }
/** /**
......
...@@ -315,9 +315,6 @@ public class Krb5 { ...@@ -315,9 +315,6 @@ public class Krb5 {
public static final boolean DEBUG = GetBooleanAction public static final boolean DEBUG = GetBooleanAction
.privilegedGetProperty("sun.security.krb5.debug"); .privilegedGetProperty("sun.security.krb5.debug");
public static final sun.security.util.HexDumpEncoder hexDumper =
new sun.security.util.HexDumpEncoder();
static { static {
errMsgList = new Hashtable<Integer,String> (); errMsgList = new Hashtable<Integer,String> ();
errMsgList.put(KDC_ERR_NONE, "No error"); errMsgList.put(KDC_ERR_NONE, "No error");
......
...@@ -192,10 +192,6 @@ public class Kinit { ...@@ -192,10 +192,6 @@ public class Kinit {
System.out.print("Password for " + princName + ":"); System.out.print("Password for " + princName + ":");
System.out.flush(); System.out.flush();
psswd = Password.readPassword(System.in); psswd = Password.readPassword(System.in);
if (DEBUG) {
System.out.println(">>> Kinit console input " +
new String(psswd));
}
} }
builder = new KrbAsReqBuilder(principal, psswd); builder = new KrbAsReqBuilder(principal, psswd);
} else { } else {
......
...@@ -121,11 +121,6 @@ public class CK_PBE_PARAMS { ...@@ -121,11 +121,6 @@ public class CK_PBE_PARAMS {
sb.append(pPassword.length); sb.append(pPassword.length);
sb.append(Constants.NEWLINE); sb.append(Constants.NEWLINE);
sb.append(Constants.INDENT);
sb.append("pPassword: ");
sb.append(pPassword);
sb.append(Constants.NEWLINE);
sb.append(Constants.INDENT); sb.append(Constants.INDENT);
sb.append("ulSaltLen: "); sb.append("ulSaltLen: ");
sb.append(pSalt.length); sb.append(pSalt.length);
......
...@@ -42,7 +42,7 @@ import javax.security.auth.spi.*; ...@@ -42,7 +42,7 @@ import javax.security.auth.spi.*;
import sun.security.krb5.*; import sun.security.krb5.*;
import sun.security.jgss.krb5.Krb5Util; import sun.security.jgss.krb5.Krb5Util;
import sun.security.krb5.Credentials; import sun.security.krb5.Credentials;
import sun.security.util.HexDumpEncoder;
import static sun.security.util.ResourcesMgr.getAuthResourceString; import static sun.security.util.ResourcesMgr.getAuthResourceString;
/** /**
...@@ -765,15 +765,11 @@ public class Krb5LoginModule implements LoginModule { ...@@ -765,15 +765,11 @@ public class Krb5LoginModule implements LoginModule {
if (debug) { if (debug) {
System.out.println("principal is " + principal); System.out.println("principal is " + principal);
HexDumpEncoder hd = new HexDumpEncoder();
if (ktab != null) { if (ktab != null) {
System.out.println("Will use keytab"); System.out.println("Will use keytab");
} else if (storeKey) { } else if (storeKey) {
for (int i = 0; i < encKeys.length; i++) { for (int i = 0; i < encKeys.length; i++) {
System.out.println("EncryptionKey: keyType=" + System.out.println(encKeys[i].toString());
encKeys[i].getEType() +
" keyBytes (hex dump)=" +
hd.encodeBuffer(encKeys[i].getBytes()));
} }
} }
} }
...@@ -874,7 +870,7 @@ public class Krb5LoginModule implements LoginModule { ...@@ -874,7 +870,7 @@ public class Krb5LoginModule implements LoginModule {
} }
if (debug) { if (debug) {
System.out.println System.out.println
("password is " + new String(password)); ("Get password from shared state");
} }
return; return;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment