]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/pem_read_depr_test.c
Deprecate EC_KEY + Update ec apps to use EVP_PKEY
[thirdparty/openssl.git] / test / pem_read_depr_test.c
CommitLineData
cdbd27ba
MC
1/*
2 * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10/*
11 * This file tests deprecated APIs. Therefore we need to suppress deprecation
12 * warnings.
13 */
14#define OPENSSL_SUPPRESS_DEPRECATED
15
16#include <openssl/pem.h>
17#include <openssl/bio.h>
18
19#include "testutil.h"
20
21static const char *datadir;
22
23static BIO *getfile(const char *filename)
24{
25 char *paramsfile = test_mk_file_path(datadir, filename);
26 BIO *infile = NULL;
27
28 if (!TEST_ptr(paramsfile))
29 goto err;
30 infile = BIO_new_file(paramsfile, "r");
31
32 err:
33 OPENSSL_free(paramsfile);
34 return infile;
35}
36
37#ifndef OPENSSL_NO_DH
38static int test_read_dh_params(void)
39{
40 int testresult = 0;
41 BIO *infile = getfile("dhparams.pem");
42 DH *dh = NULL;
43
44 if (!TEST_ptr(infile))
45 goto err;
46
47 dh = PEM_read_bio_DHparams(infile, NULL, NULL, NULL);
48 if (!TEST_ptr(dh))
49 goto err;
50
51 testresult = 1;
52
53 err:
54 BIO_free(infile);
55 DH_free(dh);
56 return testresult;
57}
58
59static int test_read_dh_x942_params(void)
60{
61 int testresult = 0;
62 BIO *infile = getfile("x942params.pem");
63 DH *dh = NULL;
64
65 if (!TEST_ptr(infile))
66 goto err;
67
68 dh = PEM_read_bio_DHparams(infile, NULL, NULL, NULL);
69 if (!TEST_ptr(dh))
70 goto err;
71
72 testresult = 1;
73
74 err:
75 BIO_free(infile);
76 DH_free(dh);
77 return testresult;
78}
79#endif
80
81#ifndef OPENSSL_NO_DSA
82static int test_read_dsa_params(void)
83{
84 int testresult = 0;
85 BIO *infile = getfile("dsaparams.pem");
86 DSA *dsa = NULL;
87
88 if (!TEST_ptr(infile))
89 goto err;
90
91 dsa = PEM_read_bio_DSAparams(infile, NULL, NULL, NULL);
92 if (!TEST_ptr(dsa))
93 goto err;
94
95 testresult = 1;
96
97 err:
98 BIO_free(infile);
99 DSA_free(dsa);
100 return testresult;
101}
102
103static int test_read_dsa_private(void)
104{
105 int testresult = 0;
106 BIO *infile = getfile("dsaprivatekey.pem");
107 DSA *dsa = NULL;
108
109 if (!TEST_ptr(infile))
110 goto err;
111
112 dsa = PEM_read_bio_DSAPrivateKey(infile, NULL, NULL, NULL);
113 if (!TEST_ptr(dsa))
114 goto err;
115
116 testresult = 1;
117
118 err:
119 BIO_free(infile);
120 DSA_free(dsa);
121 return testresult;
122}
123
124static int test_read_dsa_public(void)
125{
126 int testresult = 0;
127 BIO *infile = getfile("dsapublickey.pem");
128 DSA *dsa = NULL;
129
130 if (!TEST_ptr(infile))
131 goto err;
132
133 dsa = PEM_read_bio_DSA_PUBKEY(infile, NULL, NULL, NULL);
134 if (!TEST_ptr(dsa))
135 goto err;
136
137 testresult = 1;
138
139 err:
140 BIO_free(infile);
141 DSA_free(dsa);
142 return testresult;
143}
144#endif
145
146static int test_read_rsa_private(void)
147{
148 int testresult = 0;
149 BIO *infile = getfile("rsaprivatekey.pem");
150 RSA *rsa = NULL;
151
152 if (!TEST_ptr(infile))
153 goto err;
154
155 rsa = PEM_read_bio_RSAPrivateKey(infile, NULL, NULL, NULL);
156 if (!TEST_ptr(rsa))
157 goto err;
158
159 testresult = 1;
160
161 err:
162 BIO_free(infile);
163 RSA_free(rsa);
164 return testresult;
165}
166
167static int test_read_rsa_public(void)
168{
169 int testresult = 0;
170 BIO *infile = getfile("rsapublickey.pem");
171 RSA *rsa = NULL;
172
173 if (!TEST_ptr(infile))
174 goto err;
175
176 rsa = PEM_read_bio_RSA_PUBKEY(infile, NULL, NULL, NULL);
177 if (!TEST_ptr(rsa))
178 goto err;
179
180 testresult = 1;
181
182 err:
183 BIO_free(infile);
184 RSA_free(rsa);
185 return testresult;
186}
187
188int setup_tests(void)
189{
190 if (!test_skip_common_options()) {
191 TEST_error("Error parsing test options\n");
192 return 0;
193 }
194
195 if (!TEST_ptr(datadir = test_get_argument(0))) {
196 TEST_error("Error getting data dir\n");
197 return 0;
198 }
199
200#ifndef OPENSSL_NO_DH
201 ADD_TEST(test_read_dh_params);
202 ADD_TEST(test_read_dh_x942_params);
203#endif
204#ifndef OPENSSL_NO_DSA
205 ADD_TEST(test_read_dsa_params);
206 ADD_TEST(test_read_dsa_private);
207 ADD_TEST(test_read_dsa_public);
208#endif
209 ADD_TEST(test_read_rsa_private);
210 ADD_TEST(test_read_rsa_public);
211
212 return 1;
213}