Runs the 'openssl' command with the provided args array as a subprocess. Force closes STDIN without writing any data to it which avoids openssl commands hanging due to waiting for input. Args: args: List of strings forming the arguments to the 'openssl' command. t
(args, timeout_s=3)
| 58 | |
| 59 | |
| 60 | def run_openssl_cmd(args, timeout_s=3): |
| 61 | """ |
| 62 | Runs the 'openssl' command with the provided args array as a subprocess. Force closes |
| 63 | STDIN without writing any data to it which avoids openssl commands hanging due to |
| 64 | waiting for input. |
| 65 | |
| 66 | Args: |
| 67 | args: List of strings forming the arguments to the 'openssl' command. |
| 68 | timeout_s: Optional timeout in seconds. If provided and exceeded, the process is |
| 69 | killed. |
| 70 | |
| 71 | Returns: Tuple containing the return code and the combined stdout and stderr output |
| 72 | as a string. |
| 73 | """ |
| 74 | |
| 75 | assert args[0] != "openssl", "'openssl' command must not be included in the args list." |
| 76 | args = ["openssl"] + args |
| 77 | |
| 78 | proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, |
| 79 | stderr=subprocess.STDOUT, universal_newlines=True) |
| 80 | |
| 81 | try: |
| 82 | if timeout_s is None: |
| 83 | stdout, stderr = proc.communicate(input="") |
| 84 | else: |
| 85 | stdout, stderr = proc.communicate(input="", timeout=timeout_s) |
| 86 | except subprocess.TimeoutExpired as e: |
| 87 | # TimeoutExpired exceptions usually indicate the server port does not support TLS. |
| 88 | proc.kill() |
| 89 | stdout = proc.communicate() |
| 90 | raise e |
| 91 | |
| 92 | out = stdout |
| 93 | if not isinstance(out, str): |
| 94 | out = out.decode("utf-8", "replace") |
| 95 | |
| 96 | return proc.returncode, out |
| 97 | |
| 98 | |
| 99 | def __get_openssl_supported_ciphers(tls_flag): |