public boolean isLaterVersionOf(ProtocolVersion version) { if (getMajorVersion() != version.getMajorVersion()) { return false; } int diffMinorVersion = version.getMinorVersion() - getMinorVersion(); return isDTLS() ? diffMinorVersion > 0 : diffMinorVersion < 0; }
public boolean equals(Object other) { return this == other || (other instanceof ProtocolVersion && equals((ProtocolVersion)other)); }
public static ProtocolVersion readVersion(byte[] buf, int offset) throws IOException { return ProtocolVersion.get(buf[offset] & 0xFF, buf[offset + 1] & 0xFF); }
public static void writeVersion(ProtocolVersion version, byte[] buf, int offset) { buf[offset] = (byte)version.getMajorVersion(); buf[offset + 1] = (byte)version.getMinorVersion(); }
public static boolean isTLSv12(ProtocolVersion version) { return ProtocolVersion.TLSv12.isEqualOrEarlierVersionOf(version.getEquivalentTLSVersion()); }
if (versionNumberCheckDisabled && clientVersion.isEqualOrEarlierVersionOf(ProtocolVersion.TLSv10)) int correct = (clientVersion.getMajorVersion() ^ (M[0] & 0xff)) | (clientVersion.getMinorVersion() ^ (M[1] & 0xff)); correct |= correct >> 1; correct |= correct >> 2;
if (server_version.isDTLS()) if (!server_version.equals(this.recordStream.getReadVersion())) if (!server_version.isEqualOrEarlierVersionOf(client_version))
public void notifyServerVersion(ProtocolVersion serverVersion) throws IOException { if (!getMinimumVersion().isEqualOrEarlierVersionOf(serverVersion)) { throw new TlsFatalAlert(AlertDescription.protocol_version); } }
public ProtocolVersion getEquivalentTLSVersion() { if (!isDTLS()) { return this; } if (this == DTLSv10) { return TLSv11; } return TLSv12; }
public ProtocolVersion getServerVersion() throws IOException { if (getMinimumVersion().isEqualOrEarlierVersionOf(clientVersion)) { ProtocolVersion maximumVersion = getMaximumVersion(); if (clientVersion.isEqualOrEarlierVersionOf(maximumVersion)) { return serverVersion = clientVersion; } if (clientVersion.isLaterVersionOf(maximumVersion)) { return serverVersion = maximumVersion; } } throw new TlsFatalAlert(AlertDescription.protocol_version); }
public boolean isTLS() { return getMajorVersion() == 0x03; }
private static ProtocolVersion getUnknownVersion(int major, int minor, String prefix) throws IOException { TlsUtils.checkUint8(major); TlsUtils.checkUint8(minor); int v = (major << 8) | minor; String hex = Strings.toUpperCase(Integer.toHexString(0x10000 | v).substring(1)); return new ProtocolVersion(v, prefix + " 0x" + hex); } }
public void notifyFallback(boolean isFallback) throws IOException { /* * RFC 7507 3. If TLS_FALLBACK_SCSV appears in ClientHello.cipher_suites and the highest * protocol version supported by the server is higher than the version indicated in * ClientHello.client_version, the server MUST respond with a fatal inappropriate_fallback * alert [..]. */ if (isFallback && getMaximumVersion().isLaterVersionOf(clientVersion)) { throw new TlsFatalAlert(AlertDescription.inappropriate_fallback); } }
return TLSv12; return getUnknownVersion(major, minor, "TLS"); return DTLSv12; return getUnknownVersion(major, minor, "DTLS");
public static boolean isTLSv11(ProtocolVersion version) { return ProtocolVersion.TLSv11.isEqualOrEarlierVersionOf(version.getEquivalentTLSVersion()); }
public static void writeVersion(ProtocolVersion version, byte[] buf, int offset) { buf[offset] = (byte)version.getMajorVersion(); buf[offset + 1] = (byte)version.getMinorVersion(); }
if (versionNumberCheckDisabled && clientVersion.isEqualOrEarlierVersionOf(ProtocolVersion.TLSv10)) int correct = (clientVersion.getMajorVersion() ^ (M[0] & 0xff)) | (clientVersion.getMinorVersion() ^ (M[1] & 0xff)); correct |= correct >> 1; correct |= correct >> 2;
if (server_version.isDTLS()) if (!server_version.equals(this.recordStream.getReadVersion())) if (!server_version.isEqualOrEarlierVersionOf(client_version))