/usr/share/pyshared/dpkt/ssl.py is in python-dpkt 1.6+svn54-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | # $Id: ssl.py 46 2008-05-27 02:08:12Z jon.oberheide $
"""Secure Sockets Layer / Transport Layer Security."""
import dpkt
class SSL2(dpkt.Packet):
__hdr__ = (
('len', 'H', 0),
('msg', 's', ''),
('pad', 's', ''),
)
def unpack(self, buf):
dpkt.Packet.unpack(self, buf)
if self.len & 0x8000:
n = self.len = self.len & 0x7FFF
self.msg, self.data = self.data[:n], self.data[n:]
else:
n = self.len = self.len & 0x3FFF
padlen = ord(self.data[0])
self.msg = self.data[1:1+n]
self.pad = self.data[1+n:1+n+padlen]
self.data = self.data[1+n+padlen:]
# SSLv3/TLS version
SSL3_VERSION = 0x0300
TLS1_VERSION = 0x0301
# Record type
SSL3_RT_CHANGE_CIPHER_SPEC = 20
SSL3_RT_ALERT = 21
SSL3_RT_HANDSHAKE = 22
SSL3_RT_APPLICATION_DATA = 23
# Handshake message type
SSL3_MT_HELLO_REQUEST = 0
SSL3_MT_CLIENT_HELLO = 1
SSL3_MT_SERVER_HELLO = 2
SSL3_MT_CERTIFICATE = 11
SSL3_MT_SERVER_KEY_EXCHANGE = 12
SSL3_MT_CERTIFICATE_REQUEST = 13
SSL3_MT_SERVER_DONE = 14
SSL3_MT_CERTIFICATE_VERIFY = 15
SSL3_MT_CLIENT_KEY_EXCHANGE = 16
SSL3_MT_FINISHED = 20
class SSL3(dpkt.Packet):
__hdr__ = (
('type', 'B', 0),
('version', 'H', 0),
('len', 'H', 0),
)
def unpack(self, buf):
dpkt.Packet.unpack(self, buf)
if self.len <= len(self.data):
self.msg, self.data = self.data[:self.len], self.data[self.len:]
"""
Byte 0 = SSL record type = 22 (SSL3_RT_HANDSHAKE)
Bytes 1-2 = SSL version (major/minor)
Bytes 3-4 = Length of data in the record (excluding the header itself).
Byte 5 = Handshake type
Bytes 6-8 = Length of data to follow in this record
Bytes 9-n = Command-specific data
"""
class SSLFactory(object):
def __new__(cls, buf):
v = buf[1:3]
if v == '\x03\x01' or v == '\x03\x00':
return SSL3(buf)
return SSL2(buf)
|