]>
git.ipfire.org Git - thirdparty/openssl.git/blob - test/enginetest.c
2 * Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL project
5 /* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * 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
17 * the documentation and/or other materials provided with the
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
34 * 6. Redistributions of any form whatsoever must retain the following
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
61 #include <openssl/e_os2.h>
63 #ifdef OPENSSL_NO_ENGINE
64 int main(int argc
, char *argv
[])
66 printf("No ENGINE support\n");
70 # include <openssl/buffer.h>
71 # include <openssl/crypto.h>
72 # include <openssl/engine.h>
73 # include <openssl/err.h>
75 static void display_engine_list(void)
80 h
= ENGINE_get_first();
82 printf("listing available engine types\n");
84 printf("engine %i, id = \"%s\", name = \"%s\"\n",
85 loop
++, ENGINE_get_id(h
), ENGINE_get_name(h
));
86 h
= ENGINE_get_next(h
);
88 printf("end of list\n");
90 * ENGINE_get_first() increases the struct_ref counter, so we must call
91 * ENGINE_free() to decrease it again
96 int main(int argc
, char *argv
[])
100 const char *id
, *name
, *p
;
104 ENGINE
*new_h1
= NULL
;
105 ENGINE
*new_h2
= NULL
;
106 ENGINE
*new_h3
= NULL
;
107 ENGINE
*new_h4
= NULL
;
109 p
= getenv("OPENSSL_DEBUG_MEMORY");
110 if (p
!= NULL
&& strcmp(p
, "on") == 0)
111 CRYPTO_set_mem_debug(1);
112 ERR_load_crypto_strings();
114 memset(block
, 0, sizeof(block
));
115 if (((new_h1
= ENGINE_new()) == NULL
) ||
116 !ENGINE_set_id(new_h1
, "test_id0") ||
117 !ENGINE_set_name(new_h1
, "First test item") ||
118 ((new_h2
= ENGINE_new()) == NULL
) ||
119 !ENGINE_set_id(new_h2
, "test_id1") ||
120 !ENGINE_set_name(new_h2
, "Second test item") ||
121 ((new_h3
= ENGINE_new()) == NULL
) ||
122 !ENGINE_set_id(new_h3
, "test_id2") ||
123 !ENGINE_set_name(new_h3
, "Third test item") ||
124 ((new_h4
= ENGINE_new()) == NULL
) ||
125 !ENGINE_set_id(new_h4
, "test_id3") ||
126 !ENGINE_set_name(new_h4
, "Fourth test item")) {
127 printf("Couldn't set up test ENGINE structures\n");
130 printf("\nenginetest beginning\n\n");
131 display_engine_list();
132 if (!ENGINE_add(new_h1
)) {
133 printf("Add failed!\n");
136 display_engine_list();
137 ptr
= ENGINE_get_first();
138 if (!ENGINE_remove(ptr
)) {
139 printf("Remove failed!\n");
143 display_engine_list();
144 if (!ENGINE_add(new_h3
) || !ENGINE_add(new_h2
)) {
145 printf("Add failed!\n");
148 display_engine_list();
149 if (!ENGINE_remove(new_h2
)) {
150 printf("Remove failed!\n");
153 display_engine_list();
154 if (!ENGINE_add(new_h4
)) {
155 printf("Add failed!\n");
158 display_engine_list();
159 if (ENGINE_add(new_h3
)) {
160 printf("Add *should* have failed but didn't!\n");
163 printf("Add that should fail did.\n");
165 if (ENGINE_remove(new_h2
)) {
166 printf("Remove *should* have failed but didn't!\n");
169 printf("Remove that should fail did.\n");
171 if (!ENGINE_remove(new_h3
)) {
172 printf("Remove failed!\n");
175 display_engine_list();
176 if (!ENGINE_remove(new_h4
)) {
177 printf("Remove failed!\n");
180 display_engine_list();
182 * Depending on whether there's any hardware support compiled in, this
183 * remove may be destined to fail.
185 ptr
= ENGINE_get_first();
187 if (!ENGINE_remove(ptr
))
188 printf("Remove failed!i - probably no hardware "
189 "support present.\n");
191 display_engine_list();
192 if (!ENGINE_add(new_h1
) || !ENGINE_remove(new_h1
)) {
193 printf("Couldn't add and remove to an empty list!\n");
196 printf("Successfully added and removed to an empty list!\n");
197 printf("About to beef up the engine-type list\n");
198 for (loop
= 0; loop
< 512; loop
++) {
199 sprintf(buf
, "id%i", loop
);
200 id
= OPENSSL_strdup(buf
);
201 sprintf(buf
, "Fake engine type %i", loop
);
202 name
= OPENSSL_strdup(buf
);
203 if (((block
[loop
] = ENGINE_new()) == NULL
) ||
204 !ENGINE_set_id(block
[loop
], id
) ||
205 !ENGINE_set_name(block
[loop
], name
)) {
206 printf("Couldn't create block of ENGINE structures.\n"
207 "I'll probably also core-dump now, damn.\n");
211 for (loop
= 0; loop
< 512; loop
++) {
212 if (!ENGINE_add(block
[loop
])) {
213 printf("\nAdding stopped at %i, (%s,%s)\n",
214 loop
, ENGINE_get_id(block
[loop
]),
215 ENGINE_get_name(block
[loop
]));
222 printf("\nAbout to empty the engine-type list\n");
223 while ((ptr
= ENGINE_get_first()) != NULL
) {
224 if (!ENGINE_remove(ptr
)) {
225 printf("\nRemove failed!\n");
232 for (loop
= 0; loop
< 512; loop
++) {
233 OPENSSL_free((void *)ENGINE_get_id(block
[loop
]));
234 OPENSSL_free((void *)ENGINE_get_name(block
[loop
]));
236 printf("\nTests completed happily\n");
240 ERR_print_errors_fp(stderr
);
245 for (loop
= 0; loop
< 512; loop
++)
246 ENGINE_free(block
[loop
]);
248 CRYPTO_cleanup_all_ex_data();
250 ERR_remove_thread_state(NULL
);
251 #ifndef OPENSSL_NO_CRYPTO_MDEBUG
252 CRYPTO_mem_leaks_fp(stderr
);