|
Packit |
aea12f |
/*
|
|
Packit |
aea12f |
* Copyright (C) 2005-2012 Free Software Foundation, Inc.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* Author: Simon Josefsson
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* This file is part of GnuTLS.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* GnuTLS is free software; you can redistribute it and/or modify it
|
|
Packit |
aea12f |
* under the terms of the GNU General Public License as published by
|
|
Packit |
aea12f |
* the Free Software Foundation; either version 3 of the License, or
|
|
Packit |
aea12f |
* (at your option) any later version.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* GnuTLS is distributed in the hope that it will be useful, but
|
|
Packit |
aea12f |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
aea12f |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
aea12f |
* General Public License for more details.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* You should have received a copy of the GNU General Public License
|
|
Packit |
aea12f |
* along with GnuTLS; if not, write to the Free Software Foundation,
|
|
Packit |
aea12f |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#ifdef HAVE_CONFIG_H
|
|
Packit |
aea12f |
#include <config.h>
|
|
Packit |
aea12f |
#endif
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include <stdlib.h>
|
|
Packit |
aea12f |
#include <stdio.h>
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include "utils.h"
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
static void tls_log_func(int level, const char *str)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
fprintf(stderr, "<%d>| %s", level, str);
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef struct {
|
|
Packit |
aea12f |
const char *file;
|
|
Packit |
aea12f |
const char *pass;
|
|
Packit |
aea12f |
} files_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
files_st files[] = {
|
|
Packit |
aea12f |
{"client.p12", "foobar"},
|
|
Packit |
aea12f |
{"cert-ca.p12", "1234"}, /* 2 certs, one is a CA */
|
|
Packit |
aea12f |
{"pkcs12_2certs.p12", ""}, /* 2 certs, on is unrelated */
|
|
Packit |
aea12f |
{NULL, NULL}
|
|
Packit |
aea12f |
};
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
void doit(void)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
gnutls_certificate_credentials_t x509cred;
|
|
Packit |
aea12f |
const char *path;
|
|
Packit |
aea12f |
unsigned int i;
|
|
Packit |
aea12f |
char file[512];
|
|
Packit |
aea12f |
int ret;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (gnutls_fips140_mode_enabled()) {
|
|
Packit |
aea12f |
exit(77);
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = global_init();
|
|
Packit |
aea12f |
if (ret < 0)
|
|
Packit |
aea12f |
fail("global_init failed %d\n", ret);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
gnutls_global_set_log_function(tls_log_func);
|
|
Packit |
aea12f |
if (debug)
|
|
Packit |
aea12f |
gnutls_global_set_log_level(4711);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
for (i = 0; files[i].file != NULL; i++) {
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ret = gnutls_certificate_allocate_credentials(&x509cred);
|
|
Packit |
aea12f |
if (ret < 0)
|
|
Packit |
aea12f |
fail("gnutls_certificate_allocate_credentials failed %d\n", ret);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
path = getenv("PKCS12PATH");
|
|
Packit |
aea12f |
if (!path)
|
|
Packit |
aea12f |
path = "cert-tests/data/";
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
snprintf(file, sizeof(file), "%s/%s", path, files[i].file);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (debug)
|
|
Packit |
aea12f |
success
|
|
Packit |
aea12f |
("Reading PKCS#12 blob from `%s' using password `%s'.\n",
|
|
Packit |
aea12f |
file, files[i].pass);
|
|
Packit |
aea12f |
ret =
|
|
Packit |
aea12f |
gnutls_certificate_set_x509_simple_pkcs12_file(x509cred,
|
|
Packit |
aea12f |
file,
|
|
Packit |
aea12f |
GNUTLS_X509_FMT_DER,
|
|
Packit |
aea12f |
files[i].
|
|
Packit |
aea12f |
pass);
|
|
Packit |
aea12f |
if (ret < 0)
|
|
Packit |
aea12f |
fail("x509_pkcs12 failed %d: %s\n", ret,
|
|
Packit |
aea12f |
gnutls_strerror(ret));
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (debug)
|
|
Packit |
aea12f |
success("Read file OK\n");
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
gnutls_certificate_free_credentials(x509cred);
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
gnutls_global_deinit();
|
|
Packit |
aea12f |
}
|