Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8304264: Debug messages always show up for NativeGSS
Reviewed-by: mullan
  • Loading branch information
wangweij committed Mar 15, 2023
1 parent 1ae69e3 commit be08a25
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 32 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -105,7 +105,9 @@ static GSSLibStub getInstance(Oid mech) throws GSSException {
return s;
}
private GSSLibStub(Oid mech) throws GSSException {
SunNativeProvider.debug("Created GSSLibStub for mech " + mech);
if (SunNativeProvider.DEBUG) {
SunNativeProvider.debug("Created GSSLibStub for mech " + mech);
}
this.mech = mech;
this.pMech = getMechPtr(mech.getDER());
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -73,21 +73,27 @@ private static Oid getNativeNameType(Oid nameType, GSSLibStub stub) {
supportedNTs = stub.inquireNamesForMech();
} catch (GSSException ge2) {
// Should never happen
SunNativeProvider.debug("Name type list unavailable: " +
ge2.getMajorString());
if (SunNativeProvider.DEBUG) {
SunNativeProvider.debug("Name type list unavailable: " +
ge2.getMajorString());
}
}
} else {
SunNativeProvider.debug("Name type list unavailable: " +
ge.getMajorString());
if (SunNativeProvider.DEBUG) {
SunNativeProvider.debug("Name type list unavailable: " +
ge.getMajorString());
}
}
}
if (supportedNTs != null) {
for (int i = 0; i < supportedNTs.length; i++) {
if (supportedNTs[i].equals(nameType)) return nameType;
}
// Special handling the specified name type
SunNativeProvider.debug("Override " + nameType +
" with mechanism default(null)");
if (SunNativeProvider.DEBUG) {
SunNativeProvider.debug("Override " + nameType +
" with mechanism default(null)");
}
return null; // Use mechanism specific default
}
}
Expand Down Expand Up @@ -185,8 +191,10 @@ && new String(nameBytes).endsWith(atRealm)) {
}
}

SunNativeProvider.debug("Imported " + printableName + " w/ type " +
printableType);
if (SunNativeProvider.DEBUG) {
SunNativeProvider.debug("Imported " + printableName + " w/ type " +
printableType);
}
}

private void setPrintables() throws GSSException {
Expand All @@ -211,7 +219,9 @@ public String getKrbName() throws GSSException {
mName = stub.canonicalizeName(pName);
Object[] printables2 = stub.displayName(mName);
stub.releaseName(mName);
SunNativeProvider.debug("Got kerberized name: " + printables2[0]);
if (SunNativeProvider.DEBUG) {
SunNativeProvider.debug("Got kerberized name: " + printables2[0]);
}
return (String) printables2[0];
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -53,8 +53,10 @@ static void checkServicePermission(String target, String action) {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
SunNativeProvider.debug("Checking ServicePermission(" +
target + ", " + action + ")");
if (SunNativeProvider.DEBUG) {
SunNativeProvider.debug("Checking ServicePermission(" +
target + ", " + action + ")");
}
ServicePermission perm =
new ServicePermission(target, action);
sm.checkPermission(perm);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -148,8 +148,10 @@ private void doDelegPermCheck() throws GSSException {
String tgsStr = Krb5Util.getTGSName(targetName);
String krbPrincPair = "\"" + targetStr + "\" \"" +
tgsStr + '\"';
SunNativeProvider.debug("Checking DelegationPermission (" +
krbPrincPair + ")");
if (SunNativeProvider.DEBUG) {
SunNativeProvider.debug("Checking DelegationPermission (" +
krbPrincPair + ")");
}
DelegationPermission perm =
new DelegationPermission(krbPrincPair);
sm.checkPermission(perm);
Expand All @@ -163,8 +165,10 @@ private byte[] retrieveToken(InputStream is, int mechTokenLen)
byte[] result;
if (mechTokenLen != -1) {
// Need to add back the GSS header for a complete GSS token
SunNativeProvider.debug("Precomputed mechToken length: " +
mechTokenLen);
if (SunNativeProvider.DEBUG) {
SunNativeProvider.debug("Precomputed mechToken length: " +
mechTokenLen);
}
GSSHeader gssHeader = new GSSHeader
(ObjectIdentifier.of(cStub.getMech().toString()),
mechTokenLen);
Expand All @@ -182,8 +186,10 @@ private byte[] retrieveToken(InputStream is, int mechTokenLen)
DerValue dv = new DerValue(is);
result = dv.toByteArray();
}
SunNativeProvider.debug("Complete Token length: " +
result.length);
if (SunNativeProvider.DEBUG) {
SunNativeProvider.debug("Complete Token length: " +
result.length);
}
return result;
} catch (IOException ioe) {
throw new GSSExceptionImpl(GSSException.FAILURE, ioe);
Expand Down Expand Up @@ -273,8 +279,10 @@ public byte[] initSecContext(InputStream is, int mechTokenLen)
// Ignore the specified input stream on the first call
if (pContext != 0) {
inToken = retrieveToken(is, mechTokenLen);
SunNativeProvider.debug("initSecContext=> inToken len=" +
inToken.length);
if (SunNativeProvider.DEBUG) {
SunNativeProvider.debug("initSecContext=> inToken len=" +
inToken.length);
}
}

if (!getCredDelegState()) skipDelegPermCheck = true;
Expand All @@ -286,8 +294,10 @@ public byte[] initSecContext(InputStream is, int mechTokenLen)
long pCred = (cred == null? 0 : cred.pCred);
outToken = cStub.initContext(pCred, targetName.pName,
cb, inToken, this);
SunNativeProvider.debug("initSecContext=> outToken len=" +
(outToken == null ? 0 : outToken.length));
if (SunNativeProvider.DEBUG) {
SunNativeProvider.debug("initSecContext=> outToken len=" +
(outToken == null ? 0 : outToken.length));
}

// Only inspect the token when the permission check
// has not been performed
Expand Down Expand Up @@ -321,13 +331,17 @@ public byte[] acceptSecContext(InputStream is, int mechTokenLen)
byte[] outToken = null;
if ((!isEstablished) && (!isInitiator)) {
byte[] inToken = retrieveToken(is, mechTokenLen);
SunNativeProvider.debug("acceptSecContext=> inToken len=" +
inToken.length);
if (SunNativeProvider.DEBUG) {
SunNativeProvider.debug("acceptSecContext=> inToken len=" +
inToken.length);
}
long pCred = (cred == null? 0 : cred.pCred);
outToken = cStub.acceptContext(pCred, cb, inToken, this);
disposeDelegatedCred = delegatedCred;
SunNativeProvider.debug("acceptSecContext=> outToken len=" +
(outToken == null? 0 : outToken.length));
if (SunNativeProvider.DEBUG) {
SunNativeProvider.debug("acceptSecContext=> outToken len=" +
(outToken == null ? 0 : outToken.length));
}

if (targetName == null) {
targetName = new GSSNameElement
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -54,7 +54,8 @@ public final class SunNativeProvider extends Provider {
private static final String INFO = "Sun Native GSS provider";
private static final String MF_CLASS =
"sun.security.jgss.wrapper.NativeGSSFactory";
private static final boolean DEBUG =

static final boolean DEBUG =
GetBooleanAction.privilegedGetProperty("sun.security.nativegss.debug");

static void debug(String message) {
Expand Down

1 comment on commit be08a25

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.