/** * Generate a message integrity check for a given received message. * @param context GSSContext for which a connection has been established to the remote peer * @param prop the MessageProp used for exchanging messages * @param message the bytes of the received message * @return the bytes of the message integrity check (like a checksum) that is * sent to a peer for verifying that the message was received correctly */ @Function public static byte[] generateMIC(GSSContext context, MessageProp prop, byte[] message) { try { // Ensure the default Quality-of-Protection is applied. prop.setQOP(0); byte[] initialToken = context.getMIC(message, 0, message.length, prop); return getTokenWithLengthPrefix(initialToken); } catch (GSSException ex) { throw new RuntimeException("Exception generating MIC for message", ex); } }
protected void calcPrivacyInfo(MessageProp prop, byte[] confounder, byte[] data, int dataOffset, int dataLength, int paddingLen) throws GSSException { prop.setQOP(0); if (!confState) { prop.setPrivacy(false); } checkSum = calcCheckSum(confounder, commHeader, data, dataOffset, dataLength, paddingLen); encryptSequenceNumber(); }
private void initTokenHeader(byte[] tokenBytes, MessageProp prop) throws GSSException { int tokenIDRecv = (((int) tokenBytes[0]) << 8) + tokenBytes[1]; if (tokenType != tokenIDRecv) { throw new GSSException(GSSException.DEFECTIVE_TOKEN, -1, "Token ID should be " + tokenType + " instead of " + tokenIDRecv); } sgnAlg = (((int) tokenBytes[2]) << 8) + tokenBytes[3]; sealAlg = (((int) tokenBytes[4]) << 8) + tokenBytes[5]; if (tokenBytes[6] != (byte) 0xFF || tokenBytes[7] != (byte) 0xFF) { throw new GSSException(GSSException.DEFECTIVE_TOKEN, -1, "Invalid token head filler"); } prop.setQOP(0); prop.setPrivacy(sealAlg != SEAL_ALG_NONE); }
prop.setQOP(0);
prop.setQOP(0);
protected void doWith(GSSContext context, Transport.Connection conn) throws Exception { //if (context.getMutualAuthState()) { // System.out.println("Mutual authentication took place!"); //} MessageProp prop = new MessageProp(0, false); byte[] token = conn.recvToken(); byte[] bytes = context.unwrap(token, 0, token.length, prop); //String str = new String(bytes, StandardCharsets.UTF_8); // System.out.println("Received data \"" // + str + "\" of length " + str.length()); //System.out.println("Confidentiality applied: " // + prop.getPrivacy()); prop.setQOP(0); token = context.getMIC(bytes, 0, bytes.length, prop); //System.out.println("Will send MIC token of size " //+ token.length); conn.sendToken(token); }
prop.setQOP(0);
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 } }
prop.setQOP(0);
prop.setQOP(0); sequenceNumber = (int) BytesUtil.bytes2long(header, 0, true); } catch (IOException e) {