source: rtems-libbsd/testsuite/openssl02/test_main.c @ 9ed6c971

5-freebsd-126-freebsd-12
Last change on this file since 9ed6c971 was 9ed6c971, checked in by Christian Mauderer <christian.mauderer@…>, on 03/26/19 at 10:08:47

bin/openssl: Port to RTEMS.

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * Copyright (c) 2013-2019 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <sys/param.h>
33
34#include <assert.h>
35#include <errno.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <sysexits.h>
39
40#include <machine/rtems-bsd-commands.h>
41
42#include <rtems/libcsupport.h>
43#include <rtems/bsd/modules.h>
44
45#include <sys/stat.h>
46#include <fcntl.h>
47
48#define TEST_NAME "LIBBSD OPENSSL 2"
49
50#define ARGC(x) RTEMS_BSD_ARGC(x)
51
52#ifdef RTEMS_BSD_MODULE_USR_BIN_OPENSSL
53static void
54test_cmd_gencert(void)
55{
56        int fd;
57        int rv;
58        struct stat sb;
59        char *openssl_gencert[] = {
60                "openssl",
61                "req",
62                "-config",
63                "/openssl.cfg",
64                "-nodes",
65                "-newkey",
66                "rsa:2048",
67                "-keyout",
68                "/example.key",
69                "-out",
70                "example.csr",
71                "-subj",
72                "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=example.com",
73                NULL
74        };
75
76        static const char config[] =
77                "[ req ]\n"
78                "distinguished_name = req_distinguished_name\n"
79                "[ req_distinguished_name ]\n"
80                "countryName = Country Name (2 letter code)\n"
81                "stateOrProvinceName = State or Province Name (full name)\n"
82                "localityName = Locality Name (eg, city)\n"
83                "0.organizationName = Organization Name (eg, company)\n"
84                "0.organizationName_default = Internet Widgits Pty Ltd\n"
85                "organizationalUnitName = Organizational Unit Name (eg, section)\n"
86                "organizationalUnitName_default =\n"
87                "commonName = Common Name (e.g. server FQDN or YOUR name)\n"
88                "commonName_max = 64\n"
89                "emailAddress = Email Address\n"
90                "emailAddress_max = 64\n";
91
92        /* Create config file. */
93        fd = open("/openssl.cfg", O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
94        assert(fd != -1);
95        rv = write(fd, config, sizeof(config));
96        assert(rv == sizeof(config));
97        rv = close(fd);
98        assert(rv == 0);
99
100        rtems_bsd_command_openssl(ARGC(openssl_gencert), openssl_gencert);
101
102        assert(stat("/example.key", &sb) == 0);
103        assert(stat("/example.csr", &sb) == 0);
104}
105
106static void
107test_cmd_speed(void)
108{
109        int fd;
110        int rv;
111        struct stat sb;
112        char *openssl_speed[] = {
113                "openssl",
114                "speed",
115                "sha1",
116                NULL
117        };
118
119        rtems_bsd_command_openssl(ARGC(openssl_speed), openssl_speed);
120}
121#endif /* RTEMS_BSD_MODULE_USR_BIN_OPENSSL */
122
123static void
124test_main(void)
125{
126#ifdef RTEMS_BSD_MODULE_USR_BIN_OPENSSL
127        test_cmd_gencert();
128        test_cmd_speed();
129#else /* ! RTEMS_BSD_MODULE_USR_BIN_OPENSSL */
130        puts("openssl command not enabled in the current build set");
131#endif /* RTEMS_BSD_MODULE_USR_BIN_OPENSSL */
132        exit(0);
133}
134
135#include <rtems/bsd/test/default-init.h>
Note: See TracBrowser for help on using the repository browser.