openssl.py 1022 B

1234567891011121314151617181920212223242526272829303132
  1. # *****************************************************************************
  2. # \file openssl.py
  3. # \project bee2evp [EVP-interfaces over bee2 / engine of OpenSSL]
  4. # \brief A python wrapper over openssl commmands
  5. # \created 2019.07.10
  6. # \version 2020.02.17
  7. # \license This program is released under the GNU General Public License
  8. # version 3 with the additional exemption that compiling, linking,
  9. # and/or using OpenSSL is allowed. See Copyright Notices in bee2evp/info.h.
  10. # *****************************************************************************
  11. import subprocess
  12. import os
  13. os.environ['OPENSSL_CONF'] = '/usr/local/openssl.cnf'
  14. OPENSSL_EXE_PATH = '/usr/local/bin/openssl'
  15. def openssl(cmd, prefix='', echo=False):
  16. cmd = '{} {} {}'.format(prefix, OPENSSL_EXE_PATH, cmd)
  17. if echo:
  18. print(cmd)
  19. p = subprocess.Popen(cmd,
  20. stdout=subprocess.PIPE,
  21. stderr=subprocess.PIPE,
  22. stdin=subprocess.PIPE,
  23. shell=True)
  24. out, err_out = p.communicate()
  25. retcode = p.poll()
  26. return retcode^1, out, err_out