/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* The base class used by client and server implementations of SASL
* mechanisms to process properties passed in the props argument
* and strings with the same format (e.g., used in digest-md5).
*
* Also contains utilities for doing int to network-byte-order
* transformations.
*
* @author Rosanna Lee
*/
public abstract class AbstractSaslImpl {
protected boolean completed = false;
protected boolean privacy = false;
protected boolean integrity = false;
// These are relevant only when privacy or integray have been negotiated
// Parse properties to set desired context options
// "auth", "auth-int", "auth-conf"
"SASLIMPL01:Preferred qop property: {0}", prop);
}
}
}
// "low", "medium", "high"
"SASLIMPL04:Preferred strength property: {0}", prop);
}
}
// Max receive buffer size
try {
"SASLIMPL06:Max receive buffer size: {0}", prop);
} catch (NumberFormatException e) {
throw new SaslException(
"Property must be string representation of integer: " +
}
}
// Max send buffer size
try {
"SASLIMPL07:Max send buffer size: {0}", prop);
} catch (NumberFormatException e) {
throw new SaslException(
"Property must be string representation of integer: " +
}
}
} else {
qop = DEFAULT_QOP;
}
}
/**
* Determines whether this mechanism has completed.
*
* @return true if has completed; false otherwise;
*/
public boolean isComplete() {
return completed;
}
/**
* Retrieves the negotiated property.
* @exception SaslException if this authentication exchange has not completed
*/
if (!completed) {
throw new IllegalStateException("SASL authentication not completed");
}
if (privacy) {
return "auth-conf";
} else if (integrity) {
return "auth-int";
} else {
return "auth";
}
} else {
return null;
}
}
byte answer = 0;
}
return answer;
}
return in[i];
}
}
return (byte)0;
}
}
boolean ignore) throws SaslException {
return DEFAULT_QOP; // default
}
}
throws SaslException {
return DEFAULT_STRENGTH; // default
}
STRENGTH_MASKS, null, false);
}
throws SaslException {
int i = 0;
boolean found;
found = false;
found = true;
}
}
}
throw new SaslException(
}
}
// Initialize rest of array with 0
answer[j] = 0;
}
return answer;
}
/**
* Outputs a byte array. Can be null.
*/
}
try {
} else {
}
new HexDumpEncoder().encodeBuffer(
} else {
content = "NULL";
}
// Message id supplied by caller as part of traceTag
} catch (Exception e) {
"SASLIMPL09:Error generating trace output: {0}", e);
}
}
/**
* Returns the integer represented by 4 bytes in network byte order.
*/
int count) {
if (count > 4) {
throw new IllegalArgumentException("Cannot handle more than 4 bytes");
}
int answer = 0;
for (int i = 0; i < count; i++) {
answer <<= 8;
}
return answer;
}
/**
* Encodes an integer into 4 bytes in network byte order in the buffer
* supplied.
*/
if (count > 4) {
throw new IllegalArgumentException("Cannot handle more than 4 bytes");
}
num >>>= 8;
}
}
// ---------------- Constants -----------------
/**
* Logger for debug messages
*/
// default 0 (no protection); 1 (integrity only)
"auth-int",
"auth"};
private static final byte[] DEFAULT_STRENGTH = new byte[]{
"medium",
"high"};
}