2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
8 * Copyright (C) 2016-2018 Fox Crypto B.V. <openvpn@fox-it.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #elif defined(_MSC_VER)
27 #include "config-msvc.h"
44 static const char testtext
[] = "Dummy text to test PEM encoding";
47 crypto_pem_encode_decode_loopback(void **state
)
49 struct gc_arena gc
= gc_new();
50 struct buffer src_buf
;
51 buf_set_read(&src_buf
, (void *)testtext
, sizeof(testtext
));
53 uint8_t dec
[sizeof(testtext
)];
54 struct buffer dec_buf
;
55 buf_set_write(&dec_buf
, dec
, sizeof(dec
));
57 struct buffer pem_buf
;
59 assert_true(crypto_pem_encode("TESTKEYNAME", &pem_buf
, &src_buf
, &gc
));
60 assert_true(BLEN(&src_buf
) < BLEN(&pem_buf
));
63 assert_false(crypto_pem_decode("WRONGNAME", &dec_buf
, &pem_buf
));
65 assert_true(crypto_pem_decode("TESTKEYNAME", &dec_buf
, &pem_buf
));
66 assert_int_equal(BLEN(&src_buf
), BLEN(&dec_buf
));
67 assert_memory_equal(BPTR(&src_buf
), BPTR(&dec_buf
), BLEN(&src_buf
));
75 const struct CMUnitTest tests
[] = {
76 cmocka_unit_test(crypto_pem_encode_decode_loopback
),
79 #if defined(ENABLE_CRYPTO_OPENSSL)
80 OpenSSL_add_all_algorithms();
83 int ret
= cmocka_run_group_tests_name("crypto tests", tests
, NULL
, NULL
);
85 #if defined(ENABLE_CRYPTO_OPENSSL)