Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
first unit test for verifycert
  • Loading branch information
Fabian Mauchle committed Sep 29, 2020
1 parent 3188e98 commit 59e488f
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -29,5 +29,6 @@ tests/t_fticks
tests/t_rewrite
tests/t_rewrite_config
tests/t_resizeattr
tests/t_verify_cert
tests/*.log
tests/*.trs
2 changes: 1 addition & 1 deletion tests/Makefile.am
Expand Up @@ -4,7 +4,7 @@ AUTOMAKE_OPTIONS = foreign
LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
$(top_srcdir)/build-aux/tap-driver.sh

check_PROGRAMS = t_fticks t_rewrite t_resizeattr t_rewrite_config
check_PROGRAMS = t_fticks t_rewrite t_resizeattr t_rewrite_config t_verify_cert
AM_CFLAGS = -g -Wall -Werror @SSL_CFLAGS@ @TARGET_CFLAGS@
LDADD = $(top_builddir)/librsp.a @SSL_LIBS@
LDFLAGS = @SSL_LDFLAGS@ @TARGET_LDFLAGS@ @LDFLAGS@
Expand Down
68 changes: 68 additions & 0 deletions tests/t_verify_cert.c
@@ -0,0 +1,68 @@
/* Copyright (C) 2020, SWITCH */
/* See LICENSE for licensing information. */

#include <openssl/x509v3.h>
#include <string.h>
#include <stdio.h>
#include "../radsecproxy.h"
#include "../debug.h"
#include "../hostport.h"

/* /CN=test */
char *simplecert = "-----BEGIN CERTIFICATE-----\n\
MIHAMIGMAgkAx2VNeC1d5FswCQYHKoZIzj0EATAPMQ0wCwYDVQQDDAR0ZXN0MB4X\n\
DTIwMDkyODE0MTEzMloXDTIwMTAwODE0MTEzMlowDzENMAsGA1UEAwwEdGVzdDAy\n\
MBAGByqGSM49AgEGBSuBBAAGAx4ABJxnszX24oQMNcK0IZozUpupFkD/dWBC37qI\n\
QW4wCQYHKoZIzj0EAQMkADAhAg8Ajl0dHSkadggaqZiD72ACDjWHqYhaIAWTstBv\n\
g/Q5\n\
-----END CERTIFICATE-----";

X509 *getcert(char *pem) {
X509* certX509;
BIO* certBio;

certBio = BIO_new(BIO_s_mem());
BIO_write(certBio, pem , strlen(pem));
certX509 = PEM_read_bio_X509(certBio, NULL, NULL, NULL);

BIO_free(certBio);

return certX509;
}

int
main (int argc, char *argv[])
{
int numtests = 1;

struct clsrvconf conf;
X509 *cert;

debug_init("t_verify_cert");
debug_set_level(5);

printf("1..%d\n", numtests);

{
struct hostportres hp;

conf.name = "test";
conf.certnamecheck = 1;
conf.matchcertattrs = NULL;
conf.hostports = list_create();
hp.host = "test";
hp.prefixlen = 0;
list_push(conf.hostports, &hp);

cert = getcert(simplecert);

if (verifyconfcert(cert, &conf)) {
printf("ok %d - simple cert cn\n", numtests++);
} else {
printf("not ok %d - simple cert cn\n", numtests++);
}
X509_free(cert);
}

return 0;
}

0 comments on commit 59e488f

Please sign in to comment.