3 use Test::More tests => 3;
9 my $debug = $config{debug};
10 my $stderr = '2>/dev/null';
15 print STDERR "OpenXPKI::Client::SCEP: Create certificates for the SCEP server / CA\n";
17 use OpenXPKI qw( read_file );
18 use OpenXPKI::Crypto::TokenManager;
19 use OpenXPKI::Crypto::Profile::Certificate;
24 # create SCEP certificate
26 if (! (`$config{openssl} version` =~ m{\A OpenSSL\ 0\.9\.8 }xms)) {
27 skip "OpenSSL 0.9.8 not available.", 3;
29 diag("Creating SCEP certificate");
30 my $openssl = $config{'openssl'};
31 `mkdir -p t/instance/etc/openxpki/ca/scepdummyserver1/`;
32 `pwd=1234567890 $openssl genrsa -des -passout env:pwd -out t/instance/etc/openxpki/ca/scepdummyserver1/key.pem 1024 $stderr`;
33 `(echo '.'; echo '.'; echo '.'; echo 'OpenXPKI'; echo 'SCEP test server'; echo 'SCEP test server'; echo '.'; echo '.'; echo '.')|pwd=1234567890 openssl req -new -x509 -key t/instance/etc/openxpki/ca/scepdummyserver1/key.pem -passin env:pwd -out t/instance/etc/openxpki/ca/scepdummyserver1/cert.pem $stderr`;
34 my $identifier = `openxpkiadm certificate import --config t/instance/etc/openxpki/config.xml --file t/instance/etc/openxpki/ca/scepdummyserver1/cert.pem|tail -1|sed -e 's/ Identifier: //' $stderr`;
35 `openxpkiadm certificate alias --config t/instance/etc/openxpki/config.xml --realm I18N_OPENXPKI_DEPLOYMENT_TEST_DUMMY_CA --alias testscepserver1 --identifier $identifier $stderr`;
38 # create CA certificate
39 diag("Creating CA certificate");
40 `mkdir -p t/instance/etc/openxpki/ca/testdummyca1/`;
41 `pwd=1234567890 $openssl genrsa -des -passout env:pwd -out t/instance/etc/openxpki/ca/testdummyca1/cakey.pem 1024 $stderr`;
42 `(echo '.'; echo '.'; echo '.'; echo 'OpenXPKI'; echo 'SCEP testing CA'; echo 'SCEP testing CA'; echo '.'; echo '.'; echo '.')|pwd=1234567890 $openssl req -new -key t/instance/etc/openxpki/ca/testdummyca1/cakey.pem -passin env:pwd -out t/instance/csr.pem $stderr`;
43 `mkdir t/instance/demoCA`;
44 `touch t/instance/demoCA/index.txt`;
45 `echo 01 > t/instance/demoCA/serial`;
46 `cd t/instance; pwd=1234567890 $openssl ca -selfsign -in csr.pem -keyfile etc/openxpki/ca/testdummyca1/cakey.pem -passin env:pwd -utf8 -outdir . -policy policy_anything -batch -extensions v3_ca -preserveDN -out cacert.pem $stderr`;
47 open CACERT_IN, "<", "t/instance/cacert.pem";
48 open CACERT_OUT, ">", "t/instance/etc/openxpki/ca/testdummyca1/cert.pem";
51 if ($_ =~ /^-----BEGIN/) {
59 $identifier = `openxpkiadm certificate import --config t/instance/etc/openxpki/config.xml --file t/instance/etc/openxpki/ca/testdummyca1/cert.pem|tail -1|sed -e 's/ Identifier: //' $stderr`;
60 `openxpkiadm certificate alias --config t/instance/etc/openxpki/config.xml --realm I18N_OPENXPKI_DEPLOYMENT_TEST_DUMMY_CA --alias testdummyca1 --identifier $identifier $stderr`;
63 `patch -p0 < t/config.xml.diff`;
65 diag("Starting OpenXPKI Server.");
67 $args = "--debug 150" if ($debug);
68 if (system("openxpkictl --config $config{config_file} $args start $stderr >/dev/null") != 0) {
69 unlink $config{socket_file};
70 BAIL_OUT("Could not start OpenXPKI.");
73 if (! ok(-e $config{socket_file})) {
74 unlink $config{socket_file};
75 BAIL_OUT("Server did not start (no socket file)");