]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/recipes/25-test_req.t
Following the license change, modify the boilerplates in test/
[thirdparty/openssl.git] / test / recipes / 25-test_req.t
CommitLineData
596d6b7e 1#! /usr/bin/env perl
1212818e 2# Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
596d6b7e 3#
909f1a2e 4# Licensed under the Apache License 2.0 (the "License"). You may not use
596d6b7e
RS
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
4650de3e
RL
9
10use strict;
11use warnings;
12
e2ec7332 13use OpenSSL::Test::Utils;
42e0ccdf 14use OpenSSL::Test qw/:DEFAULT srctop_file/;
4650de3e
RL
15
16setup("test_req");
17
f9964863 18plan tests => 9;
4650de3e 19
42e0ccdf 20require_ok(srctop_file('test','recipes','tconversion.pl'));
4650de3e 21
e2ec7332 22open RND, ">>", ".rnd";
f367ac2b 23print RND "string to make the random number generator think it has randomness";
e2ec7332 24close RND;
2ddee136 25
f9964863
RS
26# What type of key to generate?
27my @req_new;
28if (disabled("rsa")) {
29 @req_new = ("-newkey", "dsa:".srctop_file("apps", "dsa512.pem"));
30} else {
31 @req_new = ("-new");
32 note("There should be a 2 sequences of .'s and some +'s.");
33 note("There should not be more that at most 80 per line");
34}
35
36# Check for duplicate -addext parameters, and one "working" case.
37my @addext_args = ( "openssl", "req", "-new", "-out", "testreq.pem",
38 "-config", srctop_file("test", "test.cnf"), @req_new );
2ddee136
RS
39my $val = "subjectAltName=DNS:example.com";
40my $val2 = " " . $val;
41my $val3 = $val;
42$val3 =~ s/=/ =/;
f9964863
RS
43ok( run(app([@addext_args, "-addext", $val])));
44ok(!run(app([@addext_args, "-addext", $val, "-addext", $val])));
45ok(!run(app([@addext_args, "-addext", $val, "-addext", $val2])));
46ok(!run(app([@addext_args, "-addext", $val, "-addext", $val3])));
47ok(!run(app([@addext_args, "-addext", $val2, "-addext", $val3])));
2ddee136 48
e2ec7332 49subtest "generating certificate requests" => sub {
e2ec7332
RL
50 plan tests => 2;
51
52 ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
53 @req_new, "-out", "testreq.pem"])),
54 "Generating request");
55
56 ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
57 "-verify", "-in", "testreq.pem", "-noout"])),
58 "Verifying signature on request");
59};
60
42e0ccdf 61my @openssl_args = ("req", "-config", srctop_file("apps", "openssl.cnf"));
4650de3e
RL
62
63run_conversion('req conversions',
64 "testreq.pem");
65run_conversion('req conversions -- testreq2',
e2ec7332
RL
66 srctop_file("test", "testreq2.pem"));
67
68unlink "testkey.pem", "testreq.pem";
4650de3e
RL
69
70sub run_conversion {
71 my $title = shift;
72 my $reqfile = shift;
73
74 subtest $title => sub {
75 run(app(["openssl", @openssl_args,
76 "-in", $reqfile, "-inform", "p",
77 "-noout", "-text"],
78 stderr => "req-check.err", stdout => undef));
79 open DATA, "req-check.err";
80 SKIP: {
81 plan skip_all => "skipping req conversion test for $reqfile"
85833408 82 if grep /Unknown Public Key/, map { s/\R//; } <DATA>;
4650de3e 83
e2ec7332 84 tconversion("req", $reqfile, @openssl_args);
4650de3e
RL
85 }
86 close DATA;
87 unlink "req-check.err";
88
89 done_testing();
90 };
91}