mirror of
https://github.com/QuasarApp/openssl.git
synced 2025-04-30 03:34:39 +00:00
test/[dane|evp_]test.c: BIO-fy file I/O.
Reviewed-by: Richard Levitte <levitte@openssl.org>
This commit is contained in:
parent
800b299b0a
commit
02b91dcf1c
@ -146,7 +146,7 @@ static int verify_chain(SSL *ssl, STACK_OF(X509) *chain)
|
|||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static STACK_OF(X509) *load_chain(FILE *fp, int nelem)
|
static STACK_OF(X509) *load_chain(BIO *fp, int nelem)
|
||||||
{
|
{
|
||||||
int count;
|
int count;
|
||||||
char *name = 0;
|
char *name = 0;
|
||||||
@ -164,7 +164,7 @@ static STACK_OF(X509) *load_chain(FILE *fp, int nelem)
|
|||||||
|
|
||||||
for (count = 0;
|
for (count = 0;
|
||||||
count < nelem && errtype == 0
|
count < nelem && errtype == 0
|
||||||
&& PEM_read(fp, &name, &header, &data, &len);
|
&& PEM_read_bio(fp, &name, &header, &data, &len);
|
||||||
++count) {
|
++count) {
|
||||||
const unsigned char *p = data;
|
const unsigned char *p = data;
|
||||||
|
|
||||||
@ -211,12 +211,12 @@ err:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *read_to_eol(FILE *f)
|
static char *read_to_eol(BIO *f)
|
||||||
{
|
{
|
||||||
static char buf[1024];
|
static char buf[1024];
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if (fgets(buf, sizeof(buf), f)== NULL)
|
if (!BIO_gets(f, buf, sizeof(buf)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
n = strlen(buf);
|
n = strlen(buf);
|
||||||
@ -359,7 +359,7 @@ static int allws(const char *cp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int test_tlsafile(SSL_CTX *ctx, const char *basename,
|
static int test_tlsafile(SSL_CTX *ctx, const char *basename,
|
||||||
FILE *f, const char *path)
|
BIO *f, const char *path)
|
||||||
{
|
{
|
||||||
char *line;
|
char *line;
|
||||||
int testno = 0;
|
int testno = 0;
|
||||||
@ -463,7 +463,7 @@ static int test_tlsafile(SSL_CTX *ctx, const char *basename,
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
FILE *f;
|
BIO *f;
|
||||||
BIO *bio_err;
|
BIO *bio_err;
|
||||||
SSL_CTX *ctx = NULL;
|
SSL_CTX *ctx = NULL;
|
||||||
const char *basedomain;
|
const char *basedomain;
|
||||||
@ -488,7 +488,7 @@ int main(int argc, char *argv[])
|
|||||||
CRYPTO_set_mem_debug(1);
|
CRYPTO_set_mem_debug(1);
|
||||||
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
|
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
|
||||||
|
|
||||||
f = fopen(tlsafile, "r");
|
f = BIO_new_file(tlsafile, "r");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
fprintf(stderr, "%s: Error opening tlsa record file: '%s': %s\n",
|
fprintf(stderr, "%s: Error opening tlsa record file: '%s': %s\n",
|
||||||
progname, tlsafile, strerror(errno));
|
progname, tlsafile, strerror(errno));
|
||||||
@ -523,7 +523,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
end:
|
end:
|
||||||
|
|
||||||
(void) fclose(f);
|
BIO_free(f);
|
||||||
SSL_CTX_free(ctx);
|
SSL_CTX_free(ctx);
|
||||||
|
|
||||||
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
|
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
|
||||||
|
@ -240,7 +240,7 @@ static int test_uint64(const char *value, uint64_t *pr)
|
|||||||
/* Structure holding test information */
|
/* Structure holding test information */
|
||||||
struct evp_test {
|
struct evp_test {
|
||||||
/* file being read */
|
/* file being read */
|
||||||
FILE *in;
|
BIO *in;
|
||||||
/* List of public and private keys */
|
/* List of public and private keys */
|
||||||
struct key_list *private;
|
struct key_list *private;
|
||||||
struct key_list *public;
|
struct key_list *public;
|
||||||
@ -465,8 +465,8 @@ static int process_test(struct evp_test *t, char *buf, int verbose)
|
|||||||
if (!parse_line(&keyword, &value, buf))
|
if (!parse_line(&keyword, &value, buf))
|
||||||
return 1;
|
return 1;
|
||||||
if (strcmp(keyword, "PrivateKey") == 0) {
|
if (strcmp(keyword, "PrivateKey") == 0) {
|
||||||
save_pos = ftell(t->in);
|
save_pos = BIO_tell(t->in);
|
||||||
pk = PEM_read_PrivateKey(t->in, NULL, 0, NULL);
|
pk = PEM_read_bio_PrivateKey(t->in, NULL, 0, NULL);
|
||||||
if (pk == NULL && !check_unsupported()) {
|
if (pk == NULL && !check_unsupported()) {
|
||||||
fprintf(stderr, "Error reading private key %s\n", value);
|
fprintf(stderr, "Error reading private key %s\n", value);
|
||||||
ERR_print_errors_fp(stderr);
|
ERR_print_errors_fp(stderr);
|
||||||
@ -476,8 +476,8 @@ static int process_test(struct evp_test *t, char *buf, int verbose)
|
|||||||
add_key = 1;
|
add_key = 1;
|
||||||
}
|
}
|
||||||
if (strcmp(keyword, "PublicKey") == 0) {
|
if (strcmp(keyword, "PublicKey") == 0) {
|
||||||
save_pos = ftell(t->in);
|
save_pos = BIO_tell(t->in);
|
||||||
pk = PEM_read_PUBKEY(t->in, NULL, 0, NULL);
|
pk = PEM_read_bio_PUBKEY(t->in, NULL, 0, NULL);
|
||||||
if (pk == NULL && !check_unsupported()) {
|
if (pk == NULL && !check_unsupported()) {
|
||||||
fprintf(stderr, "Error reading public key %s\n", value);
|
fprintf(stderr, "Error reading public key %s\n", value);
|
||||||
ERR_print_errors_fp(stderr);
|
ERR_print_errors_fp(stderr);
|
||||||
@ -501,8 +501,8 @@ static int process_test(struct evp_test *t, char *buf, int verbose)
|
|||||||
key->next = *lst;
|
key->next = *lst;
|
||||||
*lst = key;
|
*lst = key;
|
||||||
/* Rewind input, read to end and update line numbers */
|
/* Rewind input, read to end and update line numbers */
|
||||||
fseek(t->in, save_pos, SEEK_SET);
|
(void)BIO_seek(t->in, save_pos);
|
||||||
while (fgets(tmpbuf, sizeof(tmpbuf), t->in)) {
|
while (BIO_gets(t->in,tmpbuf, sizeof(tmpbuf))) {
|
||||||
t->line++;
|
t->line++;
|
||||||
if (strncmp(tmpbuf, "-----END", 8) == 0)
|
if (strncmp(tmpbuf, "-----END", 8) == 0)
|
||||||
return 1;
|
return 1;
|
||||||
@ -584,7 +584,7 @@ static int check_output(struct evp_test *t,
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
FILE *in = NULL;
|
BIO *in = NULL;
|
||||||
char buf[10240];
|
char buf[10240];
|
||||||
struct evp_test t;
|
struct evp_test t;
|
||||||
|
|
||||||
@ -597,9 +597,9 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
memset(&t, 0, sizeof(t));
|
memset(&t, 0, sizeof(t));
|
||||||
t.start_line = -1;
|
t.start_line = -1;
|
||||||
in = fopen(argv[1], "r");
|
in = BIO_new_file(argv[1], "r");
|
||||||
t.in = in;
|
t.in = in;
|
||||||
while (fgets(buf, sizeof(buf), in)) {
|
while (BIO_gets(in, buf, sizeof(buf))) {
|
||||||
t.line++;
|
t.line++;
|
||||||
if (!process_test(&t, buf, 0))
|
if (!process_test(&t, buf, 0))
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -611,7 +611,7 @@ int main(int argc, char **argv)
|
|||||||
t.ntests, t.errors, t.nskip);
|
t.ntests, t.errors, t.nskip);
|
||||||
free_key_list(t.public);
|
free_key_list(t.public);
|
||||||
free_key_list(t.private);
|
free_key_list(t.private);
|
||||||
fclose(in);
|
BIO_free(in);
|
||||||
|
|
||||||
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
|
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
|
||||||
if (CRYPTO_mem_leaks_fp(stderr) <= 0)
|
if (CRYPTO_mem_leaks_fp(stderr) <= 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user