Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
wangweij committed Oct 7, 2024
1 parent 699381e commit f1d3866
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions test/jdk/sun/security/krb5/GetSessionKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.security.Security;
import java.util.Arrays;
import java.util.HexFormat;
import java.util.Locale;

public class GetSessionKey {

Expand All @@ -49,7 +50,7 @@ public static class CB implements CallbackHandler {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (var cb : callbacks) {
if (cb instanceof NameCallback ncb) {
ncb.setName("Administrator");
ncb.setName(System.getenv("USER"));
} else if (cb instanceof PasswordCallback pcb) {
pcb.setPassword(System.getenv("PASSADMIN").toCharArray());
}
Expand All @@ -59,19 +60,27 @@ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallback

public static void main(String[] args) throws Exception {

if (args.length == 0) {
System.out.println("""
Usage:
java GetSessionKey peer
java GetSessionKey peer inf
""");
return;
}
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
Security.setProperty("auth.login.defaultCallbackHandler", CB.class.getName());

var peer = "host/"
+ System.getenv("LOGONSERVER").substring(2).toLowerCase(Locale.ROOT);

var inf = false;
if (args.length > 0) {
var pos = 0;
if (args[0].equals("-inf")) {
inf = true;
pos = 1;
}
if (args.length > pos) {
peer = args[pos];
}
}
System.out.println("Connecting to " + peer + "...");

var man = GSSManager.getInstance();
var name = man.createName(args[0], GSSName.NT_USER_NAME, GSSUtil.GSS_KRB5_MECH_OID);
var name = man.createName(peer, GSSName.NT_USER_NAME, GSSUtil.GSS_KRB5_MECH_OID);
var ctx = man.createContext(name, null, null, GSSContext.DEFAULT_LIFETIME);
ctx.requestMutualAuth(false);
ctx.initSecContext(new byte[0], 0, 0);
Expand All @@ -85,7 +94,7 @@ public static void main(String[] args) throws Exception {
System.arraycopy(token, 16, nt, token.length - rrc, rrc);
var ct = Arrays.copyOfRange(nt, 16, nt.length - 12);

if (args.length > 1) {
if (inf) {
for (int i = 0; i < Integer.MAX_VALUE; i++) {
((ExtendedGSSContext)ctx)
.inquireSecContext(InquireType.KRB5_GET_SESSION_KEY_EX);
Expand Down

0 comments on commit f1d3866

Please sign in to comment.