public void generateCheckSum(MessageProp prop, byte[] data, int offset, int len) throws GSSException { // generate token header createTokenHeader(prop.getPrivacy()); if (tokenType == TOKEN_MIC_V2 || !prop.getPrivacy() && tokenType == TOKEN_WRAP_V2) { checkSum = getCheckSum(data, offset, len); } if (!prop.getPrivacy() && tokenType == TOKEN_WRAP_V2) { header[4] = (byte) (checkSum.length >>> 8); header[5] = (byte) (checkSum.length & 0xFF); } }
/** * Get plain text data from token bytes * @param outBuffer * @param offset * @return plain text contained in the wrap token * @throws GSSException */ public byte[] unwrap(byte[] outBuffer, int offset) throws GSSException { int lenToCopy; if (prop.getPrivacy()) { byte[] plainText = encryptor.decryptData(tokenData, getKeyUsage()); lenToCopy = plainText.length - TOKEN_HEADER_SIZE; if (outBuffer == null) { outBuffer = new byte[lenToCopy]; offset = 0; } System.arraycopy(plainText, 0, outBuffer, offset, lenToCopy); } else { lenToCopy = tokenData.length - encryptor.getCheckSumSize(); if (outBuffer == null) { outBuffer = new byte[lenToCopy]; offset = 0; } System.arraycopy(tokenData, 0, outBuffer, offset, lenToCopy); if (!verifyCheckSum(outBuffer, offset, lenToCopy)) { throw new GSSException(GSSException.BAD_MIC, -1, "Corrupt token checksum"); } } return outBuffer; }
if (tokenType == TOKEN_WRAP_V2 && prop.getPrivacy()) { minSize = CONFOUNDER_SIZE + TOKEN_HEADER_SIZE + encryptor.getCheckSumSize(); } else { || tokenType == TOKEN_WRAP_V2 && !prop.getPrivacy()) { int checksumLen = encryptor.getCheckSumSize();
public WrapTokenV1(GssContext context, byte[] inMsg, int msgOffset, int msgLength, MessageProp prop) throws GSSException { super(TOKEN_WRAP_V1, context); paddingLen = getPaddingLength(msgLength); confounder = Random.makeBytes(CONFOUNDER_SIZE); tokenBodyLen = CONFOUNDER_SIZE + msgLength + paddingLen; calcPrivacyInfo(prop, confounder, inMsg, msgOffset, msgLength, paddingLen); if (!context.getConfState()) { prop.setPrivacy(false); } privacy = prop.getPrivacy(); inData = inMsg; inOffset = msgOffset; inLen = msgLength; }
WrapTokenV2(GssContext context, byte[] data, int dataOffset, int dataLength, MessageProp messageProp) throws GSSException { super(TOKEN_WRAP_V2, context); prop = messageProp; if (prop.getQOP() != 0) { prop.setQOP(0); } if (!context.getConfState()) { prop.setPrivacy(false); } generateCheckSum(prop, data, dataOffset, dataLength); if (prop.getPrivacy()) { byte[] toProcess = new byte[dataLength + TOKEN_HEADER_SIZE]; System.arraycopy(data, dataOffset, toProcess, 0, dataLength); encodeHeader(toProcess, dataLength); tokenData = encryptor.encryptData(toProcess, getKeyUsage()); } else { tokenData = data; // keep it for now } }
throw new GSSException(GSSException.BAD_QOP); doGSIWrap = (!prop.getPrivacy() && prop.getQOP() == GSSConstants.GSI_BIG);
throw new GSSException(GSSException.BAD_QOP); doGSIWrap = (!prop.getPrivacy() && prop.getQOP() == GSSConstants.GSI_BIG);
private void getRawData(MessageProp prop) throws GSSException { privacy = prop.getPrivacy(); tokenBodyLen = getGssHeader().getMechTokenLength() - getTokenHeaderSize(); if (bodyLen < tokenBodyLen) { throw new GSSException(GSSException.FAILURE, -1, "Insufficient data for Wrap token V1"); } if (privacy) { rawData = encryptor.encryptTokenV1(null, bodyData, bodyOffset, tokenBodyLen, 0, encryptor.isArcFourHmac() ? getPlainSequenceBytes() : null, false); paddingLen = rawData[rawData.length - 1]; rawDataOffset = CONFOUNDER_SIZE; } else { rawData = bodyData; paddingLen = bodyData[bodyOffset + tokenBodyLen - 1]; rawDataOffset = bodyOffset + CONFOUNDER_SIZE; } rawDataLength = tokenBodyLen - CONFOUNDER_SIZE - paddingLen; verifyToken(null, rawData, rawDataOffset - CONFOUNDER_SIZE, tokenBodyLen, 0); }