1#! /usr/bin/env perl
2# Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
3#
4# Licensed under the Apache License 2.0 (the "License").  You may not use
5# this file except in compliance with the License.  You can obtain a copy
6# in the file LICENSE in the source distribution or at
7# https://www.openssl.org/source/license.html
8
9
10use OpenSSL::Test qw/:DEFAULT srctop_file/;
11use OpenSSL::Test::Utils;
12
13setup("test_x509_check_cert_pkey");
14
15plan tests => 11;
16
17sub src_file {
18    return srctop_file("test", "certs", shift);
19}
20
21sub test_PEM_X509_INFO_read {
22    my $file = shift;
23    my $num = shift;
24    ok(run(test(["x509_check_cert_pkey_test", src_file($file), $num])),
25        "test_PEM_X509_INFO_read $file");
26}
27
28# rsa
29ok(run(test(["x509_check_cert_pkey_test",
30             src_file("servercert.pem"),
31             src_file("serverkey.pem"), "cert", "ok"])));
32# mismatched rsa
33ok(run(test(["x509_check_cert_pkey_test",
34             src_file("servercert.pem"),
35             src_file("wrongkey.pem"), "cert", "failed"])));
36SKIP: {
37    skip "DSA disabled", 1, if disabled("dsa");
38    # dsa
39    ok(run(test(["x509_check_cert_pkey_test",
40                 src_file("server-dsa-cert.pem"),
41                 src_file("server-dsa-key.pem"), "cert", "ok"])));
42}
43# ecc
44SKIP: {
45    skip "EC disabled", 2 if disabled("ec");
46    ok(run(test(["x509_check_cert_pkey_test",
47                 src_file("server-ecdsa-cert.pem"),
48                 src_file("server-ecdsa-key.pem"), "cert", "ok"])));
49
50    test_PEM_X509_INFO_read("ec_privkey_with_chain.pem", "5");
51
52}
53# certificate request (rsa)
54ok(run(test(["x509_check_cert_pkey_test",
55             src_file("x509-check.csr"),
56             src_file("x509-check-key.pem"), "req", "ok"])));
57# mismatched certificate request (rsa)
58ok(run(test(["x509_check_cert_pkey_test",
59             src_file("x509-check.csr"),
60             src_file("wrongkey.pem"), "req", "failed"])));
61
62test_PEM_X509_INFO_read("root-cert.pem", "1");
63test_PEM_X509_INFO_read("root-key.pem", "1");
64test_PEM_X509_INFO_read("key-pass-12345.pem", "1");
65test_PEM_X509_INFO_read("cyrillic_crl.utf8", "1");
66