public static short[] readUint8Array(int count, InputStream input) throws IOException { short[] uints = new short[count]; for (int i = 0; i < count; ++i) { uints[i] = readUint8(input); } return uints; }
public static short[] readNegotiatedDHEGroupsClientExtension(byte[] extensionData) throws IOException { if (extensionData == null) { throw new IllegalArgumentException("'extensionData' cannot be null"); } ByteArrayInputStream buf = new ByteArrayInputStream(extensionData); short length = TlsUtils.readUint8(buf); if (length < 1) { throw new TlsFatalAlert(AlertDescription.decode_error); } short[] dheGroups = TlsUtils.readUint8Array(length, buf); TlsProtocol.assertEmpty(buf); return dheGroups; }
public static short[] readUint8Array(int count, InputStream input) throws IOException { short[] uints = new short[count]; for (int i = 0; i < count; ++i) { uints[i] = readUint8(input); } return uints; }
public static short[] readNegotiatedDHEGroupsClientExtension(byte[] extensionData) throws IOException { if (extensionData == null) { throw new IllegalArgumentException("'extensionData' cannot be null"); } ByteArrayInputStream buf = new ByteArrayInputStream(extensionData); short length = TlsUtils.readUint8(buf); if (length < 1) { throw new TlsFatalAlert(AlertDescription.decode_error); } short[] dheGroups = TlsUtils.readUint8Array(length, buf); TlsProtocol.assertEmpty(buf); return dheGroups; }
/** * Parse a {@link SignatureAndHashAlgorithm} from an {@link InputStream}. * * @param input the {@link InputStream} to parse from. * @return a {@link SignatureAndHashAlgorithm} object. * @throws IOException */ public static SignatureAndHashAlgorithm parse(InputStream input) throws IOException { short hash = TlsUtils.readUint8(input); short signature = TlsUtils.readUint8(input); return new SignatureAndHashAlgorithm(hash, signature); } }
public static short[] readSupportedPointFormatsExtension(byte[] extensionData) throws IOException { if (extensionData == null) { throw new IllegalArgumentException("'extensionData' cannot be null"); } ByteArrayInputStream buf = new ByteArrayInputStream(extensionData); short length = TlsUtils.readUint8(buf); if (length < 1) { throw new TlsFatalAlert(AlertDescription.decode_error); } short[] ecPointFormats = TlsUtils.readUint8Array(length, buf); TlsProtocol.assertEmpty(buf); if (!Arrays.contains(ecPointFormats, ECPointFormat.uncompressed)) { /* * RFC 4492 5.1. If the Supported Point Formats Extension is indeed sent, it MUST * contain the value 0 (uncompressed) as one of the items in the list of point formats. */ throw new TlsFatalAlert(AlertDescription.illegal_parameter); } return ecPointFormats; }
/** * Parse a {@link SignatureAndHashAlgorithm} from an {@link InputStream}. * * @param input the {@link InputStream} to parse from. * @return a {@link SignatureAndHashAlgorithm} object. * @throws IOException */ public static SignatureAndHashAlgorithm parse(InputStream input) throws IOException { short hash = TlsUtils.readUint8(input); short signature = TlsUtils.readUint8(input); return new SignatureAndHashAlgorithm(hash, signature); } }
public static short readNegotiatedDHEGroupsServerExtension(byte[] extensionData) throws IOException { if (extensionData == null) { throw new IllegalArgumentException("'extensionData' cannot be null"); } if (extensionData.length != 1) { throw new TlsFatalAlert(AlertDescription.decode_error); } return TlsUtils.readUint8(extensionData, 0); }
public static byte[] readOpaque8(InputStream input) throws IOException { short length = readUint8(input); return readFully(length, input); }
public static byte[] readOpaque8(InputStream input) throws IOException { short length = readUint8(input); return readFully(length, input); }
public static short readMaxFragmentLengthExtension(byte[] extensionData) throws IOException { if (extensionData == null) { throw new IllegalArgumentException("'extensionData' cannot be null"); } if (extensionData.length != 1) { throw new TlsFatalAlert(AlertDescription.decode_error); } return TlsUtils.readUint8(extensionData, 0); }
public static short readMaxFragmentLengthExtension(byte[] extensionData) throws IOException { if (extensionData == null) { throw new IllegalArgumentException("'extensionData' cannot be null"); } if (extensionData.length != 1) { throw new TlsFatalAlert(AlertDescription.decode_error); } return TlsUtils.readUint8(extensionData, 0); }
public static short readNegotiatedDHEGroupsServerExtension(byte[] extensionData) throws IOException { if (extensionData == null) { throw new IllegalArgumentException("'extensionData' cannot be null"); } if (extensionData.length != 1) { throw new TlsFatalAlert(AlertDescription.decode_error); } return TlsUtils.readUint8(extensionData, 0); }
protected static byte[] patchClientHelloWithCookie(byte[] clientHelloBody, byte[] cookie) throws IOException { int sessionIDPos = 34; int sessionIDLength = TlsUtils.readUint8(clientHelloBody, sessionIDPos); int cookieLengthPos = sessionIDPos + 1 + sessionIDLength; int cookiePos = cookieLengthPos + 1; byte[] patched = new byte[clientHelloBody.length + cookie.length]; System.arraycopy(clientHelloBody, 0, patched, 0, cookieLengthPos); TlsUtils.checkUint8(cookie.length); TlsUtils.writeUint8(cookie.length, patched, cookieLengthPos); System.arraycopy(cookie, 0, patched, cookiePos, cookie.length); System.arraycopy(clientHelloBody, cookiePos, patched, cookiePos + cookie.length, clientHelloBody.length - cookiePos); return patched; }
protected static byte[] patchClientHelloWithCookie(byte[] clientHelloBody, byte[] cookie) throws IOException { int sessionIDPos = 34; int sessionIDLength = TlsUtils.readUint8(clientHelloBody, sessionIDPos); int cookieLengthPos = sessionIDPos + 1 + sessionIDLength; int cookiePos = cookieLengthPos + 1; byte[] patched = new byte[clientHelloBody.length + cookie.length]; System.arraycopy(clientHelloBody, 0, patched, 0, cookieLengthPos); TlsUtils.checkUint8(cookie.length); TlsUtils.writeUint8(cookie.length, patched, cookieLengthPos); System.arraycopy(cookie, 0, patched, cookiePos, cookie.length); System.arraycopy(clientHelloBody, cookiePos, patched, cookiePos + cookie.length, clientHelloBody.length - cookiePos); return patched; }
protected void writeHandshakeMessage(byte[] buf, int off, int len) throws IOException { if (len < 4) { throw new TlsFatalAlert(AlertDescription.internal_error); } short type = TlsUtils.readUint8(buf, off); if (type != HandshakeType.hello_request) { recordStream.getHandshakeHashUpdater().write(buf, off, len); } int total = 0; do { // Fragment data according to the current fragment limit. int toWrite = Math.min(len - total, recordStream.getPlaintextLimit()); safeWriteRecord(ContentType.handshake, buf, off + total, toWrite); total += toWrite; } while (total < len); }
/** * Parse a {@link HeartbeatExtension} from an {@link InputStream}. * * @param input * the {@link InputStream} to parse from. * @return a {@link HeartbeatExtension} object. * @throws IOException */ public static HeartbeatExtension parse(InputStream input) throws IOException { short mode = TlsUtils.readUint8(input); if (!HeartbeatMode.isValid(mode)) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } return new HeartbeatExtension(mode); } }
/** * Parse a {@link HeartbeatExtension} from an {@link InputStream}. * * @param input * the {@link InputStream} to parse from. * @return a {@link HeartbeatExtension} object. * @throws IOException */ public static HeartbeatExtension parse(InputStream input) throws IOException { short mode = TlsUtils.readUint8(input); if (!HeartbeatMode.isValid(mode)) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } return new HeartbeatExtension(mode); } }
/** * Parse a {@link CertificateStatusRequest} from an {@link InputStream}. * * @param input * the {@link InputStream} to parse from. * @return a {@link CertificateStatusRequest} object. * @throws IOException */ public static CertificateStatusRequest parse(InputStream input) throws IOException { short status_type = TlsUtils.readUint8(input); Object result; switch (status_type) { case CertificateStatusType.ocsp: result = OCSPStatusRequest.parse(input); break; default: throw new TlsFatalAlert(AlertDescription.decode_error); } return new CertificateStatusRequest(status_type, result); }
/** * Parse a {@link CertificateStatus} from an {@link InputStream}. * * @param input * the {@link InputStream} to parse from. * @return a {@link CertificateStatus} object. * @throws IOException */ public static CertificateStatus parse(InputStream input) throws IOException { short status_type = TlsUtils.readUint8(input); Object response; switch (status_type) { case CertificateStatusType.ocsp: { byte[] derEncoding = TlsUtils.readOpaque24(input); response = OCSPResponse.getInstance(TlsUtils.readDERObject(derEncoding)); break; } default: throw new TlsFatalAlert(AlertDescription.decode_error); } return new CertificateStatus(status_type, response); }