Пример #1
0
    def generate_request(self, data):
        openssl_command = ['openssl', 'ts', '-query', '-no_nonce',
                           '-' + self.algorithm,
                           ]
        if self.policy:
            openssl_command.extend(['-policy', self.policy])
#        if not self.authority_cert:
#            openssl_command.append('-cert')
        if self.human:
            openssl_command.append('-text')
        if self.config:
            openssl_command.extend(['-config', self.config])
        openssl = Popen(openssl_command, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        openssl.stdin.write(data)
        openssl.stdin.close()
        error = openssl.wait()
        if error:
            stdout = openssl.stdout.read()
            stderr = openssl.stderr.read()
            msg = "Received error code {} while generating request"
            err = OpenSSLError(msg.format(error), data, stdout, stderr)
            err.data = data
            err.out = stdout
            err.err = stderr
            print(stdout)
            print(stderr)
            raise err
        return openssl.stdout.read()
Пример #2
0
 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()
Пример #3
0
 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