public static byte[] createPaddingExtension(int dataLength) throws IOException { TlsUtils.checkUint16(dataLength); return new byte[dataLength]; }
public static void writeOpaque16(byte[] buf, OutputStream output) throws IOException { checkUint16(buf.length); writeUint16(buf.length, output); output.write(buf); }
void encodeTo(OutputStream output) throws IOException { // Patch actual length back in int length = count - 2; TlsUtils.checkUint16(length); TlsUtils.writeUint16(length, buf, 0); output.write(buf, 0, count); buf = null; } }
void encodeTo(OutputStream output) throws IOException { // Patch actual length back in int length = count - 2; TlsUtils.checkUint16(length); TlsUtils.writeUint16(length, buf, 0); output.write(buf, 0, count); buf = null; } }
public static void writeOpaque16(byte[] buf, OutputStream output) throws IOException { checkUint16(buf.length); writeUint16(buf.length, output); output.write(buf); }
/** * Encode this {@link ServerNameList} to an {@link OutputStream}. * * @param output * the {@link OutputStream} to encode to. * @throws IOException */ public void encode(OutputStream output) throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); for (int i = 0; i < serverNameList.size(); ++i) { ServerName entry = (ServerName)serverNameList.elementAt(i); entry.encode(buf); } TlsUtils.checkUint16(buf.size()); TlsUtils.writeUint16(buf.size(), output); buf.writeTo(output); }
protected static void writeSelectedExtensions(OutputStream output, Hashtable extensions, boolean selectEmpty) throws IOException { Enumeration keys = extensions.keys(); while (keys.hasMoreElements()) { Integer key = (Integer)keys.nextElement(); int extension_type = key.intValue(); byte[] extension_data = (byte[])extensions.get(key); if (selectEmpty == (extension_data.length == 0)) { TlsUtils.checkUint16(extension_type); TlsUtils.writeUint16(extension_type, output); TlsUtils.writeOpaque16(extension_data, output); } } }
protected static void writeExtensions(OutputStream output, Hashtable extensions) throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); Enumeration keys = extensions.keys(); while (keys.hasMoreElements()) { Integer key = (Integer)keys.nextElement(); int extension_type = key.intValue(); byte[] extension_data = (byte[])extensions.get(key); TlsUtils.checkUint16(extension_type); TlsUtils.writeUint16(extension_type, buf); TlsUtils.writeOpaque16(extension_data, buf); } byte[] extBytes = buf.toByteArray(); TlsUtils.writeOpaque16(extBytes, output); }
public static void writeUint16ArrayWithUint16Length(int[] uints, OutputStream output) throws IOException { int length = 2 * uints.length; checkUint16(length); writeUint16(length, output); writeUint16Array(uints, output); }
public static void writeUint16ArrayWithUint16Length(int[] uints, byte[] buf, int offset) throws IOException { int length = 2 * uints.length; checkUint16(length); writeUint16(length, buf, offset); writeUint16Array(uints, buf, offset + 2); }
public static void writeUint16ArrayWithUint16Length(int[] uints, OutputStream output) throws IOException { int length = 2 * uints.length; checkUint16(length); writeUint16(length, output); writeUint16Array(uints, output); }
public static void writeUint16ArrayWithUint16Length(int[] uints, byte[] buf, int offset) throws IOException { int length = 2 * uints.length; checkUint16(length); writeUint16(length, buf, offset); writeUint16Array(uints, buf, offset + 2); }
public static void encodeSupportedSignatureAlgorithms(Vector supportedSignatureAlgorithms, boolean allowAnonymous, OutputStream output) throws IOException { if (supportedSignatureAlgorithms == null || supportedSignatureAlgorithms.size() < 1 || supportedSignatureAlgorithms.size() >= (1 << 15)) { throw new IllegalArgumentException( "'supportedSignatureAlgorithms' must have length from 1 to (2^15 - 1)"); } // supported_signature_algorithms int length = 2 * supportedSignatureAlgorithms.size(); checkUint16(length); writeUint16(length, output); for (int i = 0; i < supportedSignatureAlgorithms.size(); ++i) { SignatureAndHashAlgorithm entry = (SignatureAndHashAlgorithm)supportedSignatureAlgorithms.elementAt(i); if (!allowAnonymous && entry.getSignature() == SignatureAlgorithm.anonymous) { /* * RFC 5246 7.4.1.4.1 The "anonymous" value is meaningless in this context but used * in Section 7.4.3. It MUST NOT appear in this extension. */ throw new IllegalArgumentException( "SignatureAlgorithm.anonymous MUST NOT appear in the signature_algorithms extension"); } entry.encode(output); } }
protected static void writeSupplementalData(OutputStream output, Vector supplementalData) throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); for (int i = 0; i < supplementalData.size(); ++i) { SupplementalDataEntry entry = (SupplementalDataEntry)supplementalData.elementAt(i); int supp_data_type = entry.getDataType(); TlsUtils.checkUint16(supp_data_type); TlsUtils.writeUint16(supp_data_type, buf); TlsUtils.writeOpaque16(entry.getData(), buf); } byte[] supp_data = buf.toByteArray(); TlsUtils.writeOpaque24(supp_data, output); }
protected static void writeSupplementalData(OutputStream output, Vector supplementalData) throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); for (int i = 0; i < supplementalData.size(); ++i) { SupplementalDataEntry entry = (SupplementalDataEntry)supplementalData.elementAt(i); int supp_data_type = entry.getDataType(); TlsUtils.checkUint16(supp_data_type); TlsUtils.writeUint16(supp_data_type, buf); TlsUtils.writeOpaque16(entry.getData(), buf); } byte[] supp_data = buf.toByteArray(); TlsUtils.writeOpaque24(supp_data, output); }
/** * Encode this {@link HeartbeatMessage} to an {@link OutputStream}. * * @param output * the {@link OutputStream} to encode to. * @throws IOException */ public void encode(TlsContext context, OutputStream output) throws IOException { TlsUtils.writeUint8(type, output); TlsUtils.checkUint16(payload.length); TlsUtils.writeUint16(payload.length, output); output.write(payload); byte[] padding = new byte[paddingLength]; context.getNonceRandomGenerator().nextBytes(padding); output.write(padding); }
/** * Encode this {@link HeartbeatMessage} to an {@link OutputStream}. * * @param output * the {@link OutputStream} to encode to. * @throws IOException */ public void encode(TlsContext context, OutputStream output) throws IOException { TlsUtils.writeUint8(type, output); TlsUtils.checkUint16(payload.length); TlsUtils.writeUint16(payload.length, output); output.write(payload); byte[] padding = new byte[paddingLength]; context.getNonceRandomGenerator().nextBytes(padding); output.write(padding); }
/** * Encode this {@link ServerNameList} to an {@link OutputStream}. * * @param output * the {@link OutputStream} to encode to. * @throws IOException */ public void encode(OutputStream output) throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); short[] nameTypesSeen = new short[0]; for (int i = 0; i < serverNameList.size(); ++i) { ServerName entry = (ServerName)serverNameList.elementAt(i); nameTypesSeen = checkNameType(nameTypesSeen, entry.getNameType()); if (nameTypesSeen == null) { throw new TlsFatalAlert(AlertDescription.internal_error); } entry.encode(buf); } TlsUtils.checkUint16(buf.size()); TlsUtils.writeUint16(buf.size(), output); Streams.writeBufTo(buf, output); }
public static void writeNamedECParameters(int namedCurve, OutputStream output) throws IOException { if (!NamedCurve.refersToASpecificNamedCurve(namedCurve)) { /* * RFC 4492 5.4. All those values of NamedCurve are allowed that refer to a specific * curve. Values of NamedCurve that indicate support for a class of explicitly defined * curves are not allowed here [...]. */ throw new TlsFatalAlert(AlertDescription.internal_error); } TlsUtils.writeUint8(ECCurveType.named_curve, output); TlsUtils.checkUint16(namedCurve); TlsUtils.writeUint16(namedCurve, output); } }
public static void writeNamedECParameters(int namedCurve, OutputStream output) throws IOException { if (!NamedCurve.refersToASpecificNamedCurve(namedCurve)) { /* * RFC 4492 5.4. All those values of NamedCurve are allowed that refer to a specific * curve. Values of NamedCurve that indicate support for a class of explicitly defined * curves are not allowed here [...]. */ throw new TlsFatalAlert(AlertDescription.internal_error); } TlsUtils.writeUint8(ECCurveType.named_curve, output); TlsUtils.checkUint16(namedCurve); TlsUtils.writeUint16(namedCurve, output); } }