blob: 43bc49325c14e515865a84258422d01c3b7262f8 (
plain)
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
|
#!/usr/bin/python3
import base64
import sys
import json
from passlib import hash
def main():
if len(sys.argv) < 2:
return -1
if sys.argv[1] == 'list':
print('{ "encrypt": { "type": "str", "plainpass": "str" } }\n')
return 0
if sys.argv[1] == 'call':
if len(sys.argv) < 3:
return -1
if sys.argv[2] != 'encrypt':
return -1
encpass = ""
try:
jsonin = json.loads(sys.stdin.readline())
enctype = jsonin['type'].strip()
plainpass = jsonin['plainpass']
if enctype == 'ssha':
encpass = hash.ldap_salted_sha1.hash(plainpass)
elif enctype == 'sha1':
encpass = hash.ldap_sha1.hash(plainpass)
elif enctype == 'plain':
encpass = plainpass
elif enctype == 'md5':
encpass = hash.apr_md5_crypt.hash(plainpass)
elif enctype == 'bcrypt':
encpass = hash.bcrypt.hash(plainpass)
elif enctype == 'crypt':
encpass = hash.des_crypt.hash(plainpass)
except:
encpass = ""
print(json.dumps({ "encrypted_password": encpass}))
return 0
main()
|