-
Notifications
You must be signed in to change notification settings - Fork 75
/
key_regeneration.py
493 lines (373 loc) · 26.6 KB
/
key_regeneration.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
#!/usr/bin/python3
import os
import shutil
import glob
import json
import subprocess
import sys
import zipfile
import argparse
import enum
import requests
import zipfile
import ldap3
import base64
import bz2
import pymysql
import re
import urllib3
import tempfile
import xml.etree.ElementTree as ET
from types import ModuleType
from urllib.parse import urlparse
from requests.auth import HTTPBasicAuth
from datetime import datetime
requests.packages.urllib3.disable_warnings()
pydes_b64 = b'QlpoOTFBWSZTWZIkrogADOB/gHxwQAB7///3P+/f77////pgJLwB7nCgOjs19VgGgAADXkHctToQAAh6dPKBoKPVrnPJerrTeh7q9OVtq5qut0e3O093c3Vsqczcq3YraGOJrrdndtSRZB6aDlKvBIkJoAmhMmjQTRoBMhNiJ6hN6ptTTGoBpk0xA0yAUUmJBkaJ6EHpMBoBoTABGTEyDTAONDQNGmRpo0yAxMEAANAaA0yAwJkCTSSJoRNU9lJpp6TT00J6EGj1GTQAYhoDQAAESUEKn7VR+JT9BqZqT09I9RlNPQyhoZMNR6QGgNAAIkSBAEBFT2anqYlP0U/SnppomT01NAGmmm1AZMnojeTnEDhogiEgIICfPQoEkDPm+HWACIAFZAJNBGKgoiCSIoIqRYwgPc0FgRVUGRkiAkjBiIggqKiMYICwRgyIgwGRIgiRRGRIsBYsQYikZIoCLGRFQiSAjFgoSevaIgsVQUiyRFQQYB5wSQKiiJEQUBAEhpESQoAMJKkgoEEEoyIgjCIkLSyFRQIQFqIk+r0cJZ3QkdmzZ7mu6PplDD13UxfCx/p/y/5iR3qCYSQcCaTDhvz65PVWg0NC5LNHnzDgwOGIJeKhoBHMR/5XwJfKRzuF+iU5DYaPi8T8oKMzhtFaRNseOUHsyjNpGRLfIUFsCe/C9kpjGMhe2y7bpbuEBiF4hZ6HTIyl+1pS2xk5O/Sf2lcWxtA2k2kfQ9JhmfzMA59OmvHp488N+RDDbiGkh6UOBsr0FvCxcGbP+yskdlYzzyj7uPTjsV/lwdYOcEoIs4uRI6wP9hAQu3+16NSKICyUd0lAWuVP3yi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=='
pyDes = ModuleType('mod')
exec(bz2.decompress(base64.b64decode(pydes_b64)).decode(), pyDes.__dict__)
_VENDOR_ = 'gluu' if os.path.exists('/etc/gluu/conf/gluu.properties') else 'jans'
_AUTH_NAME_ = 'oxAuth' if _VENDOR_ == 'gluu' else 'jans-auth'
_BAKUP_TIME_ = datetime.utcnow().isoformat()
parser = argparse.ArgumentParser('This script removes current key and creates new key for {}.'.format(_AUTH_NAME_))
ldap_group = parser.add_mutually_exclusive_group()
ldap_group.add_argument('-expiration_hours', help="Keys expire in hours", type=int)
ldap_group.add_argument('-expiration', help="Keys expire in days", default=365, type=int)
ldap_group.add_argument('-auth-client', help="Path to {}-client-jar-with-dependencies.jar".format(_AUTH_NAME_.lower()))
ldap_group.add_argument('-data-dir', help="Directory to keep keys", default='/opt/{}/keys'.format(_VENDOR_))
argsp = parser.parse_args()
def jproperties_parser(prop_fn):
def get_seperator_pos(l):
for i,c in enumerate(l):
if c in ':=':
return i
prop = {}
if os.path.exists(prop_fn):
with open(prop_fn) as f:
content = f.read()
else:
content = prop_fn
for l in content.splitlines():
ls = l.strip()
if ls and not ls.startswith('#'):
n = get_seperator_pos(ls)
if n:
key = ls[:n].strip()
val = ls[n+1:].strip()
prop[key] = val
return prop
def backup_file(fn):
if os.path.exists(fn):
target_fn = fn+'.'+_BAKUP_TIME_
print("Backing up file", fn, "as", target_fn)
shutil.move(fn, target_fn)
def run_command(args):
if type(args) == type([]):
cmd = ' '.join(args)
else:
cmd = args
print("Executing command", cmd)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
result = p.communicate()
return result
def unobscure(s, key):
cipher = pyDes.triple_des(key)
decrypted = cipher.decrypt(base64.b64decode(s), padmode=pyDes.PAD_PKCS5)
return decrypted.decode()
class PersistenceType(enum.Enum):
ldap = 1
couchbase = 2
sql = 3
spanner = 4
class CBM:
def __init__(self, host, admin, password):
self.auth = HTTPBasicAuth(admin, password)
self.n1ql_api = 'https://{}:18093/query/service'.format(host)
def exec_query(self, query):
print("Executing n1ql {}".format(query))
data = {'statement': query}
verify_ssl = False
result = requests.post(self.n1ql_api, data=data, auth=self.auth, verify=verify_ssl)
return result
class Spanner:
def __init__(self, credentials):
self.credentials = credentials
self.get_session()
def get_session(self):
emulator_host = self.credentials.get('connection.emulator-host')
if emulator_host:
host, port = emulator_host.split(':')
scheme = 'http'
spanner_base_url = '{}://{}:9020/v1/'.format(scheme, host)
session_url = os.path.join(
spanner_base_url,
'projects/{}/instances/{}/databases/{}/sessions'.format(
self.credentials['connection.project'],
self.credentials['connection.instance'],
self.credentials['connection.database']
)
)
req = requests.post(session_url)
result = req.json()
session = result['name']
self.sessioned_url = os.path.join(spanner_base_url, session)
def execute_sql(self, sql_cmd):
post_data = {"sql": sql_cmd}
req = requests.post(self.sessioned_url + ':executeSql', data=json.dumps(post_data))
row_data = req.json()
data = {}
for i, field in enumerate(row_data['metadata']['rowType']['fields']):
if field['type']['code'] == 'INT64':
data[field['name']] = int(row_data['rows'][0][i])
else:
data[field['name']] = row_data['rows'][0][i]
return data
def put_data(self, table, columns, values):
data_send = {
'singleUseTransaction': {
'readWrite': {}
},
'mutations': [
{
'update': {
"table": table,
"columns": columns,
"values": values
}
}
]
}
req = requests.post(self.sessioned_url + ':commit', data=json.dumps(data_send))
print(req.text)
def delete_session(self):
if hasattr(self, 'sessioned_url'):
requests.delete(self.sessioned_url)
def __del__(self):
self.delete_session()
class KeyRegenerator:
def __init__(self):
self.temp_dir = tempfile.mkdtemp()
self.conf_dir = os.path.join('/etc', _VENDOR_, 'conf')
# vendor specific definitions
if _VENDOR_ == 'gluu':
self.conf_dyn = 'jans_auth_conf_dynamic'
self.conf_web_keys = 'oxAuthConfWebKeys'
self.conf_rev = 'oxRevision'
self.conf_objc = 'oxAuthConfiguration'
self.dnname = 'CN=oxAuth CA Certificates'
self.prop_dn = 'oxauth_ConfigurationEntryDN'
else:
self.conf_dyn = 'jansConfDyn'
self.conf_web_keys = 'jansConfWebKeys'
self.conf_rev = 'jansRevision'
self.conf_objc = 'jansAppConf'
self.dnname = 'CN=Jans Auth CA Certificates'
self.prop_dn = 'jansAuth_ConfigurationEntryDN'
self.conf_keystore_secret = 'keyStoreSecret'
self.key_regenerator_jar = '{}-client-jar-with-dependencies.jar'.format(_AUTH_NAME_.lower())
self.java_cmd = '/opt/jre/bin/java'
self.keytool_cmd = '/opt/jre/bin/keytool'
if not os.path.exists(self.java_cmd):
self.java_cmd = shutil.which('java')
self.keytool_cmd = shutil.which('keytool')
self.data_dir = argsp.data_dir
if not os.path.exists(self.data_dir):
os.makedirs(self.data_dir)
self.keys_json_fn = os.path.join(self.temp_dir, 'keys.json')
salt_fn = os.path.join(self.conf_dir, 'salt')
salt_dict = jproperties_parser(salt_fn)
self.salt = salt_dict['encodeSalt']
self.find_auth_client_key_path()
self.get_persistence_type()
self.read_credidentials()
getattr(self, 'obtain_data_{}'.format(self.persistence_type.name))()
self.tmp_keystore_fn = os.path.join(self.temp_dir, os.path.basename(self.keystore_fn))
self.generate_keys()
self.validate_keys()
print("Updating database")
getattr(self, 'update_{}'.format(self.persistence_type.name))()
def find_auth_client_key_path(self):
if argsp.auth_client:
self.client_jar_fn = argsp.auth_client
else:
cur_dir = os.path.dirname(__file__)
cur_dir_jar = os.path.join(cur_dir, self.key_regenerator_jar)
if os.path.exists(cur_dir_jar):
self.client_jar_fn
else:
self.client_jar_fn = os.path.join('/opt/dist', _VENDOR_, self.key_regenerator_jar)
if not os.path.exists(self.client_jar_fn):
print("Can't find {}. Exiting ...".format(self.key_regenerator_jar))
sys.exit()
print("Determining {} key generator path".format(_AUTH_NAME_))
# Determine oxauth key generator path
oxauth_client_jar_zf = zipfile.ZipFile(self.client_jar_fn)
for fn in oxauth_client_jar_zf.namelist():
if os.path.basename(fn) == 'KeyGenerator.class':
fp, ext = os.path.splitext(fn)
self.key_gen_path = fp.replace('/','.')
break
else:
print("Can't determine {}-client KeyGenerator path. Exiting...".format(_AUTH_NAME_.lower()))
sys.exit()
def get_sig_enc_algs(self, web_keys):
self.sig_enc = {'sig':[], 'enc':[]}
for key in web_keys['keys']:
use = key['use']
if key['alg'] not in self.sig_enc[use]:
self.sig_enc[use].append(key['alg'])
def get_persistence_type(self):
prop_fn = os.path.join(self.conf_dir, '{}.properties'.format(_VENDOR_))
auth_properties = jproperties_parser(prop_fn)
self.auth_config_dn = auth_properties[self.prop_dn]
self.persistence_type = getattr(PersistenceType, auth_properties['persistence.type'])
dn_s = self.auth_config_dn.split(',')
self.doc_id = dn_s[0].split('=')[1]
self.key = dn_s[1].split('=')[1] + '_' + self.doc_id
def read_credidentials(self):
prop_fn = os.path.join(self.conf_dir, '{}-{}.properties'.format(_VENDOR_, self.persistence_type.name))
self.credidentials = jproperties_parser(prop_fn)
def obtain_data_spanner(self):
self.spanner = Spanner(self.credidentials)
data = self.spanner.execute_sql('SELECT dn, {}, {}, {} from {} WHERE doc_id ="{}"'.format(self.conf_dyn, self.conf_web_keys, self.conf_rev, self.conf_objc, self.doc_id))
ox_auth_conf_dynamic = json.loads(data[self.conf_dyn])
self.key_store_secret = ox_auth_conf_dynamic[self.conf_keystore_secret]
self.get_sig_enc_algs(json.loads(data[self.conf_web_keys]))
self.revision = int(data[self.conf_rev]) + 1
def obtain_data_ldap(self):
ldap_password = unobscure(self.credidentials['bindPassword'], key=self.salt)
ldap_host, ldap_port = self.credidentials['servers'].split(',')[0].split(':')
server = ldap3.Server(ldap_host, port=int(ldap_port), use_ssl=True)
self.ldap_conn = ldap3.Connection(server, user=self.credidentials['bindDN'], password=ldap_password)
self.ldap_conn.bind()
self.ldap_conn.search(
search_base=self.auth_config_dn,
search_scope=ldap3.BASE,
search_filter='(objectClass={})'.format(self.conf_objc),
attributes=[self.conf_dyn, self.conf_web_keys, self.conf_rev]
)
result = self.ldap_conn.response
attributes_s = 'attributes'
ox_auth_conf_dynamic = json.loads(result[0][attributes_s][self.conf_dyn][0])
self.key_store_secret = ox_auth_conf_dynamic[self.conf_keystore_secret]
self.keystore_fn = ox_auth_conf_dynamic['keyStoreFile']
self.get_sig_enc_algs(json.loads(result[0][attributes_s][self.conf_web_keys][0]))
self.revision = int(result[0][attributes_s][self.conf_rev][0])
def obtain_data_sql(self):
sql_type, sql_host, sql_port, sql_db = re.match(r'jdbc:(.*?):\/\/(.*?):(\d*?)\/(.*)$', self.credidentials['connection.uri']).groups()
sql_db = sql_db.split('?')[0]
sql_password = unobscure(self.credidentials['auth.userPassword'], key=self.salt)
if sql_type == 'mysql':
self.sql_conn = pymysql.connect(host=sql_host,
user=self.credidentials['auth.userName'],
password=sql_password,
database=sql_db,
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
self.cursor = self.sql_conn.cursor()
sql = 'SELECT `{}`, `{}`, `{}` from `{}` WHERE `doc_id`=%s'.format(self.conf_dyn, self.conf_web_keys, self.conf_rev, self.conf_objc)
self.cursor.execute(sql, (self.doc_id,))
result = self.cursor.fetchone()
ox_auth_conf_dynamic = json.loads(result[self.conf_dyn])
self.key_store_secret = ox_auth_conf_dynamic[self.conf_keystore_secret]
self.keystore_fn = ox_auth_conf_dynamic['keyStoreFile']
self.get_sig_enc_algs(json.loads(result[self.conf_web_keys]))
self.revision = int(result[self.conf_rev])
def obtain_data_couchbase(self):
cb_host = self.credidentials['servers'].split(',')[0]
cb_password = unobscure(self.credidentials['auth.userPassword'], key=self.salt)
self.cbm = CBM(cb_host, self.credidentials['auth.userName'], cb_password)
self.default_bucket = self.credidentials['bucket.default']
result = self.cbm.exec_query('SELECT * FROM {} USE KEYS "{}"'.format(self.default_bucket, self.key))
configuration_oxauth = result.json()
results_s = 'results'
self.key_store_secret = configuration_oxauth[results_s][0][self.default_bucket][self.conf_dyn][self.conf_keystore_secret]
self.get_sig_enc_algs(configuration_oxauth[results_s][0][self.default_bucket][self.conf_web_keys])
self.revision = configuration_oxauth[results_s][0][self.default_bucket][self.conf_rev]
def generate_keys(self):
print("Generating keys")
args = [self.java_cmd, '-Dlog4j.defaultInitOverride=true',
'-cp', self.client_jar_fn, self.key_gen_path,
'-keystore', self.tmp_keystore_fn,
'-keypasswd', self.key_store_secret,
'-sig_keys', ' '.join(self.sig_enc['sig']),
'-enc_keys', ' '.join(self.sig_enc['enc']),
'-dnname', '"{}"'.format(self.dnname)
]
if _VENDOR_ == 'jans':
args +=['-key_ops_type', 'ALL']
if self.keystore_fn.lower().endswith('jks'):
args +=['-keystore_type', 'JKS']
if argsp.expiration_hours:
args += ['-expiration_hours', str(argsp.expiration_hours)]
else:
args += ['-expiration', str(argsp.expiration)]
args += ['>', self.keys_json_fn]
run_command(args)
def validate_keys(self):
print("Validating ... ")
key_tool_cmd = [self.keytool_cmd, '-list', '-v',
'-keystore', self.tmp_keystore_fn,
'-storepass', self.key_store_secret]
if self.tmp_keystore_fn.lower().endswith(('pkcs12', 'pk12', 'p12')):
key_tool_cmd += ['-storetype', 'PKCS12']
elif self.keystore_fn.lower().endswith('jks'):
key_tool_cmd += ['-storetype', 'JKS']
key_tool_cmd += ['|', 'grep', '"Alias name:"']
output = run_command(key_tool_cmd)
jsk_aliases = []
for l in output[0].splitlines():
ls = l.decode().strip()
n = ls.find(':')
alias_name = ls[n+1:].strip()
jsk_aliases.append(alias_name)
print("Loading keys from", self.keys_json_fn)
with open(self.keys_json_fn) as f:
self.keys_json = f.read()
keys = json.loads(self.keys_json)
json_aliases = [ wkey['kid'] for wkey in keys['keys'] ]
valid1 = True
for alias_name in json_aliases:
if alias_name not in jsk_aliases:
print(self.tmp_keystore_fn, "does not contain", alias_name)
valid1 = False
valid2 = True
for alias_name in jsk_aliases:
if alias_name not in json_aliases:
print(self.oxauth_keys_json_fn, "does not contain", alias_name)
valid2 = False
if valid1 and valid2:
print("Content of {} and {} matches".format(self.keys_json_fn, self.tmp_keystore_fn))
else:
print("Validation failed, not updating db")
sys.exit(1)
# validation passed, we can copy keystore to /etc/certs
backup_file(self.keystore_fn)
backup_file(os.path.join(self.data_dir, os.path.basename(self.keys_json_fn)))
run_command(['mv', '-f', self.tmp_keystore_fn, '/etc/certs'])
run_command(['mv', '-f', self.keys_json_fn, self.data_dir])
run_command(['rm', '-r', '-f', self.temp_dir])
def update_spanner(self):
print("Updating Spanner db")
self.spanner.put_data(self.conf_objc, ['doc_id', self.conf_rev, self.conf_web_keys], [[self.doc_id, str(self.revision+1), self.keys_json]])
def update_ldap(self):
print("LDAP modify", self.auth_config_dn)
self.ldap_conn.modify(
self.auth_config_dn,
{
self.conf_web_keys: [ldap3.MODIFY_REPLACE, self.keys_json],
self.conf_rev: [ldap3.MODIFY_REPLACE, str(self.revision+1)]
}
)
self.ldap_conn.unbind()
def update_sql(self):
print("Updating SQL db")
sql = 'UPDATE `{}` SET `{}`=%s, `{}`=%s WHERE `doc_id`=%s'.format(self.conf_objc, self.conf_web_keys, self.conf_rev)
self.cursor.execute(sql, (self.keys_json, self.revision+1, self.doc_id))
self.sql_conn.commit()
self.sql_conn.close()
def update_couchbase(self):
print("Updating Couchbase db")
self.cbm.exec_query("UPDATE {0} USE KEYS '{1}' set {0}.{3}={2}".format(self.default_bucket, self.key, self.keys_json, self.conf_web_keys))
self.cbm.exec_query("UPDATE {0} USE KEYS '{1}' set {0}.{3}={2}".format(self.default_bucket, self.key, self.revision+1, self.conf_rev))
key_regenerator = KeyRegenerator()