#!/usr/bin/perl

=head1 NAME

pf-ssl

=cut

=head1 DESCRIPTION

unit test for pf::ssl

=cut

use strict;
use warnings;
#
BEGIN {
    #include test libs
    use lib qw(/usr/local/pf/t);
    #Module for overriding configuration paths
    use setup_test_config;
}

use Test::More tests => 20;
use Test::NoWarnings;

use pf::constants qw($TRUE $FALSE);

# bash recipe to generate:
# * a new CA with a private key
# * a new CSR + private key for a radius cert
#
# and sign radius cert with x509 extensions
#
# CANAME=perl-tests-2
# MYCERT=radius
# # optional
# mkdir $CANAME
# cd $CANAME
# # generate aes encrypted private key
# openssl genrsa -out $CANAME.key 4096
# openssl req -x509 -new -nodes -key $CANAME.key -sha256 -days 7500 -out $CANAME.crt -subj '/C=CA/ST=QC/L=Montreal/O=Inverse/CN=Azure_Test'
# openssl req -new -nodes -out $MYCERT.csr -newkey rsa:4096 -keyout $MYCERT.key -subj "/CN=$MYCERT"
# cat > $MYCERT.v3.ext << EOF
# authorityKeyIdentifier=keyid,issuer
# basicConstraints=CA:FALSE
# subjectAltName = @alt_names
# extendedKeyUsage = serverAuth, clientAuth
# [alt_names]
# email.1 = jsemaan@inverse.ca
# EOF
# openssl x509 -req -in $MYCERT.csr -CA $CANAME.crt -CAkey $CANAME.key -CAcreateserial -out $MYCERT.crt -days 7300 -sha256 -extfile $MYCERT.v3.ext

use_ok("pf::ssl");

my $ss_test_cert = <<EOF;
-----BEGIN CERTIFICATE-----
MIIDxTCCAq2gAwIBAgIUbd9+L7odGykXt46UzTdGkxd0CQ0wDQYJKoZIhvcNAQEL
BQAwcjELMAkGA1UEBhMCTVgxEjAQBgNVBAgMCUN1Y2FyYWNoYTEbMBkGA1UEBwwS
VmlsbGEgZGUgbG9zIFRhY29zMRUwEwYDVQQKDAxaYW1taXRvY29ycG8xGzAZBgNV
BAMMEnBmLnphbW1pdG9jb3Jwby5teDAeFw0yMjA4MDIwODMwMzBaFw00MzAyMTMw
ODMwMzBaMHIxCzAJBgNVBAYTAk1YMRIwEAYDVQQIDAlD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wI6Ihk+IaV+dOTZJhkA7/XkHncRXUNiS32qCA==
-----END RSA PRIVATE KEY-----
EOF

my $rsa = pf::ssl::rsa_from_string($ss_test_key);
is(ref($rsa), "Crypt::OpenSSL::RSA", "rsa_from_string returns a Crypt::OpenSSL::RSA");

my $rsa_bad_cert = pf::ssl::rsa_from_string($ss_test_key2);
is(ref($rsa), "Crypt::OpenSSL::RSA", "rsa_from_string returns a Crypt::OpenSSL::RSA");

my $x509 = pf::ssl::x509_from_string($ss_test_cert);
is(ref($x509), "Crypt::OpenSSL::X509", "x509_from_string returns a Crypt::OpenSSL::X509");

is($x509->subject, "C=MX, ST=Cucaracha, L=Villa de los Tacos, O=Zammitocorpo, CN=pf.zammitocorpo.mx", "certificate has the right subject");

is(pf::ssl::validate_cert_key_match($x509, $rsa), $TRUE, "Cert/key that are matching should match");

{
    my ($res, $msg) = pf::ssl::validate_cert_key_match($x509, $rsa_bad_cert);
    is($res, $FALSE, "Cert/key that aren't matching shouldn't match");
}

{
    my ($res, $inter) = pf::ssl::fetch_all_intermediates($x509);
    is(scalar(@$inter), 0, "Self-signed cert shouldn't yield any intermediates");

    ($res, undef) = pf::ssl::verify_chain($x509, $inter);
    is($res, $TRUE, "Self-signed certificate should be a valid chain");

}

my $packetfence_org_cert = <<EOF;
-----BEGIN CERTIFICATE-----
MIIGVzCCBT+gAwIBAgISA3hObDhC0sjQ6D3btc+eq772MA0GCSqGSIb3DQEBCwUA
MEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQD
ExpMZXQncyBFbmNyeXB0IEF1dGhvcml0eSBYMzAeFw0xOTAxMTkwOTU1MDlaFw0x
OTA0MTkwOTU1MDlaMBoxGDAWBgNVBAMTD3BhY2tldGZlbmNlLm9yZzCCAiIwDQYJ
KoZIhvcNAQEBBQADggIPADCCAgoCggIBAL82/5rsndzRbZEm3WoDECplQEEKlGRB
l2a5UAsTTq0OcGQ6cwHLYD+FLFgu51ww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BQUH
AgEWGmh0dHA6Ly9jcHMubGV0c2VuY3J5cHQub3JnMIIBBQYKKwYBBAHWeQIEAgSB
9gSB8wDxAHYA4mlLribo6UAJ6IYbtjuD1D7n/nSI+6SPKJMBnd3x2/4AAAFoZcAI
VQAABAMARzBFAiATLYjWgASyQG9Z91lp0VXOuKRggtRtI3MExp2KXUftIgIhAM/Y
bBQyI7YxFuvRAwwlWsN6PkguACuNbwIwCwHgy/noAHcAY/Lbzeg7zCzPC3KEJ1dr
M6SNYXePvXWmOLHHaFRL2I0AAAFoZcAGaQAABAMASDBGAiEA+SVkISEdAv+B3x5y
uCYfnntpLk2HWm9bBn/K/Rcv7PwCIQCMVl8lkvEO1TW+zRars2oMM5tBxCKodwT5
VOJAuagVODANBgkqhkiG9w0BAQsFAAOCAQEAILgClshZb3WOajEAompucIlwaNKS
zo+DXRORIv1gZjqJqbglQhsf1WMM2x8iaCkF6ZC80U12NWe+ihmYKKKoan1aVL9t
HQGec0pjijF4EyXmP5tJj3x8vVzxOqWqmW1x6vaG9LxRQ6vEEqvqLVwZGerfAoFU
X5YdOmKJH1HA9R/w6Ok5jOTBGvxN36VPw0YlBzE3ry6Fg79oscLeusNiGQrn7lwS
xhCotd4ONf45lQeS2ZRP7sk8upAJ001ZRVCYeFrmcikN+M7qTzvzcOK5VKjb6GYZ
qKGW2Exn2hIuVy0bl7qHsX4++PJ3bsyET9tJ7EuXR+n89DM4lkfhCEiZsg==
-----END CERTIFICATE-----
EOF

$x509 = pf::ssl::x509_from_string($packetfence_org_cert);
is(ref($x509), "Crypt::OpenSSL::X509", "x509_from_string returns a Crypt::OpenSSL::X509");

is($x509->subject, "CN=packetfence.org", "certificate has the right subject");

my $cert_with_chain_cert = <<EOF;
-----BEGIN CERTIFICATE-----
MIIFXzCCA0egAwIBAgIUHjf4TrkEME68u86k8NE2ErLl7dgwDQYJKoZIhvcNAQEL
BQAwVDELMAkGA1UEBhMCQ0ExCzAJBgNVBAgMAlFDMREwDwYDVQQHDAh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3D7pzHOkeT6W/QQPbSenuZf+BuNq+VbMFQadvmJZ5F8I9qCTQcHswVd
L3UloMpgXDXEUSfoHBW83P6QlcsiEkPMeXP2lIgVbdyiNwMyAzTU2aAJA3fE87zS
LRGsaruPAVM2ioLr1QHmKzQgD1qW/2hVX6CV/pqQ3cDiH69e1QTkEKmq/f98RY6r
hAGs+aWV4dE/wnKbVphUoYb8hdU2ftRJ3b6Q6R8z/C7f0qTAIJVEHY3zKEvoONXd
81JYyt4zT87zeTg63MLdvvPycGaxb5YoBFpbKtmQEacfptbjYzr8qj+VosrDzX60
YQ8Y5UfF48aet5n3Xrvao60br+bDrkNKei+6zbBwrlePbb4RMrLM9MGEeHpy6esg
9FsSDwvh0Urwl+mhKvpUpdWyaxvwbUuCXzcB1OBYIk38C6k6omwqKWGMQ5dSao0z
CSSpoc1ewaO8MflKfmbnCTGynse2Ocd4ntVybB81gQlsHM2vwgIFWeUztpQJw5cR
kjWumFkPeu2Tbt87PCdbGjedWlwuJMw/Y2VuTRzJ379EgIPpmCHECUTgX0cDaOpp
a/CtmbBrniL00p8QHGTSOa0gy2N0c1UtBUQ4DUqVUGgxtti1FLcQVFGrZBzm3VRd
MZCaBywssJqm5DO76L4rckZ3GKTyU8NZMu9HP1+CEdasDIQ=
-----END CERTIFICATE-----
EOF

# only to simplify changes later, not used during tests
my $cert_with_chain_cert_private_key= <<EOF;
-----BEGIN PRIVATE KEY-----
MIIJRQIBADANBgkqhkiG9w0BAQEFAASCCS8wggkrAgEAAoICAQCvTxi+8/jXi76i
2Q2cwxFRt412KkbAZXWK/bUY/kNwn7AZJ1djaZQCnZssTf6EMEJR4tsQrjec4J3K
ZD34W/tjdrA4UYV9QmSzCa2yo0GEDOTRJMl4yGBZpH9ON2AbR7dMtBeYsI0l/pKs
xcSdwHuIOl20q2DB6tpJjhVi8MasLwo2KC05L6ydchZQrU0zIbNS9MyDhJo/IR2P
6STXTFO3Sg22hUjF2ud/SybHH/+fhwXM9K+UNHwJnx75Wk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NH89AcPAX4LY1UaK7ELkRUAbkrC2JP/v1cwJJqpKlcpLyF
0WReAU5CwCyYr5qMMrwlpd1xULRIil3gZSQvXsNmM0aTDL80eiIW8ulTpQkpJlX2
QwApRlFFmuCDVqfe//fwHTLQOt15F2ew+upiNadCHyZ+Le85tuo05t6Cv5xcJimZ
C1gT7QPHNYz8ZuodXgzTIoo7cMpTt1izs9zjQahdEmIXYp/eSyUf15Og/2V9lLH0
0vJFItgInAlpNysGiHzBNKOF/CL2FZ2zs/5tS/lAI4RBd6WE0m7cTsh33jRwyh3Q
t8WsCqGvztafrufjNJl0/OtDyzdsJdtwv2isBRG4yIQFX/uxo6Jt0r++RiAiIY8D
vyi20T1iU8/9iMRa1m/BQ+3DD9c5PY5iObitF/Qz68cSU1s/D0mAVduK3uyocYgZ
L9M4wLwK+NzyuNaYsSk6OGBmrC8s1cYDCDYeQDc4+0nGH840/K2MP140TzyFB5as
998aryJd27ZB6poYVh5nf7eCnKeHHLUZkqVmgj9O0yoOlGsp/afM+n3L4KSUwMBJ
WR/tuhrVRvjoc5MQZHlBby6jOaUGmXsp3OQq08U=
-----END CERTIFICATE-----
EOF

# only to simplify changes later, not used during tests
my $cert_with_chain_ca_private_key = <<EOF;
-----BEGIN RSA PRIVATE KEY-----
MIIJJwIBAAKCAgEAydyS49ki18ZMTIX44QbgalBX6/71Nfg5LT05Okx9PLnRVs4p
SQmWW1rmlxK2HW/tQmUMKs17lZfjmM3iMLu47svuVDf4aXDsk149xwJ5XQr5jIPq
ZKMMbiIVAnirVL4eJfPwsnAbEHMxlyY0qeScDX+OiGF6tbuztmureVJPe0pqm4EC
KLu7gtoKu4G4vl4EEESvnqmuEucyygvHnVzIeBKVI1PtOHOXMRI53He2kG8w1kfh
bFdBdNwM9YJdldTpRgBzP8G+4639VMkjQVAyMWam8nXR16oSLrDDDAdv4CdlKB1C
f2Zn5YfezF9k8u1MYj6pBK1/dVsXhpqli2FeOAEi94xWBVbkyQxqNkfs7yxQhEgK
fGtte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JVKx5/AneOjq1qjSHkCaq6wfU45amLgxF1zslW4OMSR
ufUE9C1kZ6dM5ubJAVw8llFa080qS7UH/66v7XQ5YkdFstuk/LGP+5E5eDZ14XB5
gfZajm+6mmhOGM/5vvWrlfgpQp4SaO+1MML2U4fx0bWofrkaaqqQFSYRuaiJge/a
EQFiWbVbgJrzsubVPTQc0GYymq7AhX4KUJaUyK7IrAe9tGSmD2VKnWxoIbfn9WCn
Lyu6luxb8LVFO6nqTVCU7kI+Bl3xm80CggEAQkCeUpwSjmgDSGxtDwN4GVme2/wB
vwJT+tvCBemyrX7QuwTMYxIt9xyXHStH0d8l6E2KJi3dDd7RNcAdBoH774uuCnRM
vN1zohqP523Cg6tSHOEA5TSm4CLT80FcR4/+fVda3/CBBXEWV1Z9Fibfp7lw2q28
1NYMJ7wnNB3Ajv8Iov0xWmsf+8pB6Ov3La9P82+8tpzUWnV7rz9tdWGWEmy6at+B
kyyhpfiuj9QXReZZT9+Xrpsd4SJkB2RAjY5TQbygd0AE1xTF9smoZ8UP2sNIHieT
zf/2eafREnFEuBfwkVF49W86rcPhH+urnKnbEyNxRsmbkyykcN9q+yeFng==
-----END RSA PRIVATE KEY-----
EOF

$x509 = pf::ssl::x509_from_string($cert_with_chain_cert);
is(ref($x509), "Crypt::OpenSSL::X509", "x509_from_string returns a Crypt::OpenSSL::X509");

is($x509->subject, "CN=radius", "certificate has the right subject");

my $x509_ca = pf::ssl::x509_from_string($cert_with_chain_ca);
is(ref($x509_ca), "Crypt::OpenSSL::X509", "x509_from_string returns a Crypt::OpenSSL::X509");

{
    my $res;
    is($x509_ca->subject(), "C=CA, ST=QC, L=Montreal, O=Inverse, CN=Azure_Test", "right intermediate subject was found");

    ($res, undef) = pf::ssl::verify_chain($x509, [$x509_ca]);
    is($res, $TRUE, "Cert with custom chain should be valid");
    
    ($res, undef) = pf::ssl::verify_chain($x509, []);
    is($res, $FALSE, "Cert with custom chain shouldn't be valid unless all certs are passed");
}

my $multi_san_cert = <<EOF;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WkerxhsVYWHjQmQQeohuoMGlwVFMA0GCSqGSIb3DQEB
CwUAA4IBAQBNhSbcp9YgU1xcz4wIY38l95jBChUveHZ/9xSDSw8iGcqE2f98x+Xq
MkaPp1mpYKhKPzsbMeNGSn6veMKSPoIRh0OH0Oi55lxff1QnmDsWW2XmmgOOR8Is
lMSEXh7L3m71/tp5qzqQPkOnOyNs3BSXsoLJOFoa0HJimJCIAxeIOZTjn4+XBEUY
9fKl7PuL/G89yQ3l9wvvSvI53DulG2/RbJgnSmZUyhnw1SrjU1fRJ2zR9glH8A7M
vApr8fkrLMKOqDEiMKs+1iZLm0KWcdzkyxTV+IiJMkS0HEvf64I9clss/A9OspSU
nGmJe3LRdsNx7P7pu57GY8lEv1tWkAO9
-----END CERTIFICATE-----
EOF

$x509= pf::ssl::x509_from_string($multi_san_cert);
my $x509_info = pf::ssl::x509_info($x509);

is($x509_info->{common_name}, "www.inverse.ca", "Common name is properly read in x509_info");
is_deeply($x509_info->{subject_alt_name},['DNS:api.fingerbank.org','DNS:chat.inverse.ca','DNS:demo.sogo.nu','DNS:fingerbank.org','DNS:git.inverse.ca','DNS:help.inverse.ca','DNS:inverse.ca','DNS:jollyjumper.inverse.ca','DNS:kimai.inverse.ca','DNS:lists.inverse.ca','DNS:monitoring.inverse.ca','DNS:packages.inverse.ca','DNS:packetfence.org','DNS:psono.inverse.ca','DNS:sogo-demo.inverse.ca','DNS:sogo.inverse.ca','DNS:sogo.nu','DNS:wiki.inverse.ca','DNS:www.fingerbank.org','DNS:www.inverse.ca','DNS:www.packetfence.org','DNS:www.sogo.nu'],"Subject alternative name is properly read from the x509_info");

=head1 AUTHOR

Inverse inc. <info@inverse.ca>

=head1 COPYRIGHT

Copyright (C) 2005-2023 Inverse inc.

=head1 LICENSE

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
USA.

=cut

1;
