rad2-enc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/python3
  2. import base64
  3. import sys
  4. import json
  5. from passlib import hash
  6. def main():
  7. if len(sys.argv) < 2:
  8. return -1
  9. if sys.argv[1] == 'list':
  10. print('{ "encrypt": { "type": "str", "plainpass": "str" } }\n')
  11. return 0
  12. if sys.argv[1] == 'call':
  13. if len(sys.argv) < 3:
  14. return -1
  15. if sys.argv[2] != 'encrypt':
  16. return -1
  17. encpass = ""
  18. try:
  19. jsonin = json.loads(sys.stdin.readline())
  20. enctype = jsonin['type'].strip()
  21. plainpass = jsonin['plainpass']
  22. if enctype == 'ssha':
  23. encpass = hash.ldap_salted_sha1.hash(plainpass)
  24. elif enctype == 'sha1':
  25. encpass = hash.ldap_sha1.hash(plainpass)
  26. elif enctype == 'plain':
  27. encpass = plainpass
  28. elif enctype == 'md5':
  29. encpass = hash.apr_md5_crypt.hash(plainpass)
  30. elif enctype == 'bcrypt':
  31. encpass = hash.bcrypt.hash(plainpass)
  32. elif enctype == 'crypt':
  33. encpass = hash.des_crypt.hash(plainpass)
  34. except:
  35. encpass = ""
  36. print(json.dumps({ "encrypted_password": encpass}))
  37. return 0
  38. main()