|
Packit Service |
4684c1 |
/*
|
|
Packit Service |
4684c1 |
* Copyright (C) 2007-2012 Free Software Foundation, Inc.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Author: Simon Josefsson
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This file is part of GnuTLS.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* GnuTLS is free software; you can redistribute it and/or modify it
|
|
Packit Service |
4684c1 |
* under the terms of the GNU General Public License as published by
|
|
Packit Service |
4684c1 |
* the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
4684c1 |
* (at your option) any later version.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* GnuTLS is distributed in the hope that it will be useful, but
|
|
Packit Service |
4684c1 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
4684c1 |
* General Public License for more details.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
4684c1 |
* along with GnuTLS; if not, write to the Free Software Foundation,
|
|
Packit Service |
4684c1 |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
4684c1 |
#include <config.h>
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include <stdio.h>
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include "../lib/gnutls_int.h"
|
|
Packit Service |
4684c1 |
#include "../lib/x509/x509_int.h"
|
|
Packit Service |
4684c1 |
#include "../lib/debug.h"
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* utils.h must be loaded after gnutls_int.h, as it redefines some
|
|
Packit Service |
4684c1 |
* macros from gnulib */
|
|
Packit Service |
4684c1 |
#include <utils.h>
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static void tls_log_func(int level, const char *str)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
fprintf(stderr, "|<%d>| %s", level, str);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static const unsigned char *salt[3] =
|
|
Packit Service |
4684c1 |
{ (void *) "salt1", (void *) "ltsa22", (void *) "balt33" };
|
|
Packit Service |
4684c1 |
static const char *pw[3] = { "secret1", "verysecret2", "veryverysecret3" };
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static const char *values[] = {
|
|
Packit Service |
4684c1 |
/* 1.0 */
|
|
Packit Service |
4684c1 |
"85a3c676a66f0960f4807144a28c8d61a0001b81846f301a1ac164289879972f",
|
|
Packit Service |
4684c1 |
/* 1.2 */
|
|
Packit Service |
4684c1 |
"e659da7d5989733a3d268e0bf7752c35c116e5c75919449a98f6812f82a15b16",
|
|
Packit Service |
4684c1 |
/* 1.2 */
|
|
Packit Service |
4684c1 |
"878b8a88bf6166ce803b7498822205b1ac82870d3aec20807148779375a61f1e",
|
|
Packit Service |
4684c1 |
/* 2.0 */
|
|
Packit Service |
4684c1 |
"1c845be764371d633c7fd1056967a9940385e110e85b58f826d39ae8561a0019",
|
|
Packit Service |
4684c1 |
/* 2.1 */
|
|
Packit Service |
4684c1 |
"de8dd3ffd59b65d3d5f59a1f71d7add582741f7752a786c045953e727e4465c0",
|
|
Packit Service |
4684c1 |
/* 2.2 */
|
|
Packit Service |
4684c1 |
#ifndef PKCS12_BROKEN_KEYGEN
|
|
Packit Service |
4684c1 |
"9dd7f19e5e6aee5c5008b5deefd35889ab75193594ed49a605df4e93e7c2a155",
|
|
Packit Service |
4684c1 |
#else
|
|
Packit Service |
4684c1 |
"9dd7f19e5e6aee5c5008b5deefd35889ab7519356f13478ecdee593c5ed689b1",
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
/* 3.0 */
|
|
Packit Service |
4684c1 |
"1c165e5a291a1539f3dbcf82a3e6ed566eb9d50ad4b0b3b57b599b08f0531236",
|
|
Packit Service |
4684c1 |
/* 3.1 */
|
|
Packit Service |
4684c1 |
"5c9abee3cde31656eedfc131b7c2f8061032a3c705961ee2306a826c8b4b1a76",
|
|
Packit Service |
4684c1 |
/* 3.2 */
|
|
Packit Service |
4684c1 |
"a9c94e0acdaeaea54d1b1b681c3b64916396a352dea7ffe635fb2c11d8502e98"
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Values derived from
|
|
Packit Service |
4684c1 |
http://www.drh-consultancy.demon.co.uk/test.txt */
|
|
Packit Service |
4684c1 |
static struct {
|
|
Packit Service |
4684c1 |
int id;
|
|
Packit Service |
4684c1 |
const char *password;
|
|
Packit Service |
4684c1 |
const unsigned char *salt;
|
|
Packit Service |
4684c1 |
size_t iter;
|
|
Packit Service |
4684c1 |
size_t keylen;
|
|
Packit Service |
4684c1 |
const char *key;
|
|
Packit Service |
4684c1 |
} tv[] = {
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
1, "smeg", (void *) "\x0A\x58\xCF\x64\x53\x0D\x82\x3F", 1,
|
|
Packit Service |
4684c1 |
24,
|
|
Packit Service |
4684c1 |
"8aaae6297b6cb04642ab5b077851284eb7128f1a2a7fbca3"}, {
|
|
Packit Service |
4684c1 |
2, "smeg", (void *) "\x0A\x58\xCF\x64\x53\x0D\x82\x3F", 1,
|
|
Packit Service |
4684c1 |
8, "79993dfe048d3b76"}, {
|
|
Packit Service |
4684c1 |
1, "smeg", (void *) "\x64\x2B\x99\xAB\x44\xFB\x4B\x1F", 1,
|
|
Packit Service |
4684c1 |
24,
|
|
Packit Service |
4684c1 |
"f3a95fec48d7711e985cfe67908c5ab79fa3d7c5caa5d966"}, {
|
|
Packit Service |
4684c1 |
2, "smeg", (void *) "\x64\x2B\x99\xAB\x44\xFB\x4B\x1F", 1,
|
|
Packit Service |
4684c1 |
8, "c0a38d64a79bea1d"}, {
|
|
Packit Service |
4684c1 |
3, "smeg", (void *) "\x3D\x83\xC0\xE4\x54\x6A\xC1\x40", 1,
|
|
Packit Service |
4684c1 |
20, "8d967d88f6caa9d714800ab3d48051d63f73a312"}, {
|
|
Packit Service |
4684c1 |
1, "queeg", (void *) "\x05\xDE\xC9\x59\xAC\xFF\x72\xF7",
|
|
Packit Service |
4684c1 |
1000, 24,
|
|
Packit Service |
4684c1 |
"ed2034e36328830ff09df1e1a07dd357185dac0d4f9eb3d4"}, {
|
|
Packit Service |
4684c1 |
2, "queeg", (void *) "\x05\xDE\xC9\x59\xAC\xFF\x72\xF7",
|
|
Packit Service |
4684c1 |
1000, 8, "11dedad7758d4860"}, {
|
|
Packit Service |
4684c1 |
1, "queeg", (void *) "\x16\x82\xC0\xFC\x5B\x3F\x7E\xC5",
|
|
Packit Service |
4684c1 |
1000, 24,
|
|
Packit Service |
4684c1 |
"483dd6e919d7de2e8e648ba8f862f3fbfbdc2bcb2c02957f"}, {
|
|
Packit Service |
4684c1 |
2, "queeg", (void *) "\x16\x82\xC0\xFC\x5B\x3F\x7E\xC5",
|
|
Packit Service |
4684c1 |
1000, 8, "9d461d1b00355c50"}, {
|
|
Packit Service |
4684c1 |
3, "queeg", (void *) "\x26\x32\x16\xFC\xC2\xFA\xB3\x1C",
|
|
Packit Service |
4684c1 |
1000, 20, "5ec4c7a80df652294c3925b6489a7ab857c83476"}
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void doit(void)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
int rc;
|
|
Packit Service |
4684c1 |
unsigned int i, j, x;
|
|
Packit Service |
4684c1 |
unsigned char key[32];
|
|
Packit Service |
4684c1 |
char tmp[1024];
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
global_init();
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_global_set_log_function(tls_log_func);
|
|
Packit Service |
4684c1 |
if (debug)
|
|
Packit Service |
4684c1 |
gnutls_global_set_log_level(99);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
x = 0;
|
|
Packit Service |
4684c1 |
for (i = 1; i < 4; i++) {
|
|
Packit Service |
4684c1 |
for (j = 0; j < 3; j++) {
|
|
Packit Service |
4684c1 |
rc = _gnutls_pkcs12_string_to_key(mac_to_entry(GNUTLS_MAC_SHA1), i, salt[j],
|
|
Packit Service |
4684c1 |
strlen((char *)
|
|
Packit Service |
4684c1 |
salt[j]),
|
|
Packit Service |
4684c1 |
j + i + 15,
|
|
Packit Service |
4684c1 |
pw[j],
|
|
Packit Service |
4684c1 |
sizeof(key),
|
|
Packit Service |
4684c1 |
key);
|
|
Packit Service |
4684c1 |
if (rc < 0)
|
|
Packit Service |
4684c1 |
fail("_gnutls_pkcs12_string_to_key failed[0]: %d\n", rc);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (strcmp(_gnutls_bin2hex(key, sizeof(key),
|
|
Packit Service |
4684c1 |
tmp, sizeof(tmp), NULL),
|
|
Packit Service |
4684c1 |
values[x]) != 0)
|
|
Packit Service |
4684c1 |
fail("_gnutls_pkcs12_string_to_key failed[1]\n");
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (debug)
|
|
Packit Service |
4684c1 |
printf("ij: %d.%d: %s\n", i, j,
|
|
Packit Service |
4684c1 |
_gnutls_bin2hex(key, sizeof(key),
|
|
Packit Service |
4684c1 |
tmp, sizeof(tmp),
|
|
Packit Service |
4684c1 |
NULL));
|
|
Packit Service |
4684c1 |
x++;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
if (debug)
|
|
Packit Service |
4684c1 |
printf("\n");
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
for (i = 0; i < sizeof(tv) / sizeof(tv[0]); i++) {
|
|
Packit Service |
4684c1 |
rc = _gnutls_pkcs12_string_to_key(mac_to_entry(GNUTLS_MAC_SHA1), tv[i].id, tv[i].salt, 8,
|
|
Packit Service |
4684c1 |
tv[i].iter,
|
|
Packit Service |
4684c1 |
tv[i].password,
|
|
Packit Service |
4684c1 |
tv[i].keylen, key);
|
|
Packit Service |
4684c1 |
if (rc < 0)
|
|
Packit Service |
4684c1 |
fail("_gnutls_pkcs12_string_to_key failed[2]: %d\n", rc);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (memcmp(_gnutls_bin2hex(key, tv[i].keylen,
|
|
Packit Service |
4684c1 |
tmp, sizeof(tmp), NULL),
|
|
Packit Service |
4684c1 |
tv[i].key, tv[i].keylen) != 0)
|
|
Packit Service |
4684c1 |
fail("_gnutls_pkcs12_string_to_key failed[3]\n");
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (debug)
|
|
Packit Service |
4684c1 |
printf("tv[%d]: %s\n", i,
|
|
Packit Service |
4684c1 |
_gnutls_bin2hex(key, tv[i].keylen, tmp,
|
|
Packit Service |
4684c1 |
sizeof(tmp), NULL));
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
if (debug)
|
|
Packit Service |
4684c1 |
printf("\n");
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_global_deinit();
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (debug)
|
|
Packit Service |
4684c1 |
success("_gnutls_pkcs12_string_to_key ok\n");
|
|
Packit Service |
4684c1 |
}
|