-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathparse.py
65 lines (39 loc) · 1.29 KB
/
parse.py
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
import io
import struct
import sys
import base64
from OpenSSL import crypto
infile = open(sys.argv[1],'rb')
# MerkleTreeLeaf -> Version, MerkleLeafType, TimestampedEntry
rawbytes = base64.b64decode(infile.read())
leaf = io.BytesIO(rawbytes)
version = leaf.read(1)
ver = struct.unpack(">B",version)
print ver[0]
ltype = leaf.read(1)
lt = struct.unpack(">B",ltype)
print lt[0]
timestamp = leaf.read(8)
ts = struct.unpack(">Q",timestamp)
print ts[0]
entrytype = leaf.read(2)
etype = struct.unpack(">H",entrytype)
print etype[0]
certlength = leaf.read(3)
clen = struct.unpack(">I",'\x00' + certlength)
print clen[0]
cert = leaf.read(clen[0])
try:
certobj = crypto.load_certificate(crypto.FILETYPE_ASN1,cert)
subject = certobj.get_subject()
print 'CN={},OU={},O={},L={},S={},C={}'.format(subject.commonName,
subject.organizationalUnitName,
subject.organizationName,
subject.localityName,
subject.stateOrProvinceName,
subject.countryName)
except:
print subject.get_components()
#print rawbytes
print len(rawbytes)
infile.close()