Exemple #1
0
    def test_plain_ssl_attr(self):
        cmd = [
            'openssl',
            'smime',
            '-sign',
            '-md',
            'sha256',
            '-binary',
            '-CAfile',
            fixture('demo2_ca.crt.pem'),
            '-in',
            fixture('plain-unsigned.txt'),
            '-out',
            fixture('plain-ssl-signed-attr.txt'),
            '-outform',
            'der',
            '-inkey',
            fixture('demo2_user1.key.pem'),
            '-signer',
            fixture('demo2_user1.crt.pem'),
        ]
        process = Popen(cmd, stdout=PIPE, stderr=PIPE)
        stdout, stderr = process.communicate()
        assert b'' == stdout
        assert b'' == stderr

        trusted_cert_pems = (open(fixture('demo2_ca.crt.pem'), 'rt').read(), )
        datau = open(fixture('plain-unsigned.txt'), 'rb').read()
        datas = open(fixture('plain-ssl-signed-attr.txt'), 'rb').read()
        (hashok, signatureok, certok) = plain.verify(datas, datau,
                                                     trusted_cert_pems)
        assert signatureok and hashok and certok
Exemple #2
0
def main():
    trusted_cert_pems = (open('demo2_ca.crt.pem', 'rt').read(), )
    datau = open('plain-unsigned.txt', 'rb').read()
    for fname in (
            'plain-ssl-signed-attr.txt',
            'plain-ssl-signed-noattr.txt',
            'plain-signed-attr.txt',
            'plain-signed-noattr.txt',
    ):
        print('*' * 20, fname)
        try:
            datas = open(fname, 'rb').read()
        except FileNotFoundError:
            print("no such file", fname)
            continue
        (hashok, signatureok, certok) = plain.verify(datas, datau,
                                                     trusted_cert_pems)
        print('signature ok?', signatureok)
        print('hash ok?', hashok)
        print('cert ok?', certok)