def stamp_request(self, request): openssl_command = ['openssl', 'ts', '-reply'] if self.use_token: openssl_command.append('-token_out') if self.human: openssl_command.append('-text') options = ['policy', 'config', 'signer', 'inkey', 'chain', 'passin'] for option in options: if getattr(self, option): openssl_command.extend(['-' + option, getattr(self, option)]) openssl_command.extend(['-queryfile', '/dev/stdin', '-out', '/dev/stdout']) openssl = Popen(openssl_command, stdin=PIPE, stdout=PIPE, stderr=PIPE) openssl.stdin.write(request) openssl.stdin.close() error = openssl.wait() if error: msg = "Received error code {} while signing data" err = OpenSSLError(msg.format(error), request) err.data = request err.stdout = openssl.stdout.read() err.stderr = openssl.stderr.read() err.command = openssl_command raise err return openssl.stdout.read()
def read_stamp(self, stamp, text=True): """read_stamp(stamp) -> token_data in text format read_stamp(stamp, text=False) -> token data """ openssl_command = ['openssl', 'ts', '-reply', '-token_out'] if self.use_token: openssl_command.append('-token_in') if text: openssl_command.append('-text') openssl_command.extend(['-in', '/dev/stdin']) openssl = Popen(openssl_command, stdin=PIPE, stdout=PIPE, stderr=PIPE) openssl.stdin.write(stamp) openssl.stdin.close() error = openssl.wait() if not error: return openssl.stdout.read() msg = "Received error code {} while trying to read stamp" err = OpenSSLError(msg.format(error), stamp) err.stdout = openssl.stdout.read() err.stderr = openssl.stderr.read() err.command = openssl_command err.data = stamp raise err