-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsort-bundle.py
executable file
·107 lines (91 loc) · 2.71 KB
/
sort-bundle.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/python
# vim:set et sw=4:
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
# USA.
import base64
import os.path
import re
import sys
import textwrap
import urllib
import tempfile
import commands
import os
import epdb
#epdb.set_trace()
old_file = []
new_file = []
field, type, value, obj = None, None, None, dict()
def read_into_array( filename, array ):
pem = "";
in_pem = False
for line in open(filename, 'r'):
# Ignore comment lines.
if line.startswith('#'):
continue
line = line.strip()
if len(line) == 0:
continue
if not in_pem and line == "-----BEGIN CERTIFICATE-----":
in_pem = True;
pem = line + "\n";
continue
if in_pem and line == "-----END CERTIFICATE-----":
in_pem = False;
pem += line + "\n";
array.append(pem);
continue
if not in_pem:
continue;
pem += line + "\n";
def add_cert_to_file(cert_pem_string, file_handle):
tf = tempfile.NamedTemporaryFile(delete=False)
tf.write(cert_pem_string)
tf.flush()
tf.close()
output = commands.getoutput("openssl x509 -text -fingerprint -md5 -in %s" % (tf.name))
file_handle.write(output)
file_handle.write("\n")
os.unlink(tf.name)
def output_into_file( filename, array ):
f = open(filename, 'w')
for obj in array:
add_cert_to_file(obj, f)
f.close()
read_into_array('old-ca-bundle.crt', old_file)
read_into_array('trusted_all_bundle', new_file)
output_into_file('test-old', old_file)
#output_into_file('test-new', new_file)
f = open('sorted-new', 'w');
only_in_new = []
in_new_and_old = []
for new in new_file:
found = False
for old in old_file:
if old == new:
found = True
break
if found:
in_new_and_old.append(new)
else:
only_in_new.append(new)
for old in old_file:
for found_in_new in in_new_and_old:
if old == found_in_new:
add_cert_to_file(old, f)
for new in only_in_new:
add_cert_to_file(new, f)
f.close()