2015-08-28 83 views
1

BouncyCastle的org.bouncycastle.crypto.tls.TlsUtils有以下几种方法BouncyCastle的tlsutils checkVersion

protected static void checkVersion(InputStream inputstream, TlsProtocolHandler tlsprotocolhandler) 
    throws IOException 
{ 
    int i = inputstream.read(); 
    int j = inputstream.read(); 
    if (i != 3 || j != 1) 
    { 
     tlsprotocolhandler.failWithError((short)2, (short)70); 
    } 
} 

protected static void checkVersion(byte abyte0[], TlsProtocolHandler tlsprotocolhandler) 
    throws IOException 
{ 
    if (abyte0[0] != 3 || abyte0[1] != 1) 
    { 
     tlsprotocolhandler.failWithError((short)2, (short)70); 
    } 
} 

什么是3 & 1正在这里检查?

回答

2

这是一件坏事叫“幻数”从InputStream.read()的Javadoc :-) 摘录一个很好的例子:

读取数据从输入流的下一个字节。值字节为 ,返回范围为0到255之间的整数。如果由于已到达流的末尾而没有可用字节 ,则返回值-1为 。

这意味着ij是从流中读取的版本号。他们只需要版本3和版本1。另外failWithError方法获得魔法数字。该TlsProtocolHandler有他们的常量,我不知道为什么作者没有使用这些

2: AL_fatal 
70: AP_protocol_version 

source

看代码checkVersion叫,而握手阶段(ServerHello)。在这里检查协议版本。请参阅此wikipedia article的版本章节以查找版本号。主要版本3,次要版本1是TLS 1.0

+0

什么是3&1的版本号? – user93353

+0

好的,那是缺少的。我已经添加了更多信息。 – Kai

+0

谢谢。你知道这是否意味着充气城堡不支持TLS 1.1和TLS 1.2? – user93353