2 * Copyright (C) 2015 Red Hat, Inc.
4 * Author: Daniel Berrange
6 * This file is part of GnuTLS.
8 * GnuTLS is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * GnuTLS is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with GnuTLS; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <gnutls/gnutls.h>
24 #include <gnutls/x509.h>
32 "-----BEGIN ENCRYPTED PRIVATE KEY-----\n" \
33 "MIHeMEkGCSqGSIb3DQEFDTA8MBsGCSqGSIb3DQEFDDAOBAiebBrnqPv4owICCAAw\n" \
34 "HQYJYIZIAWUDBAEqBBBykFR6i1My/DYFBYrz1lmABIGQ3XGpp3+v/ENC1S+X7Ay6\n" \
35 "JoquYKuMw6yUmWoGFvPIPA9UWqMve2Uj4l2l96Sywd6iNFP63ow6pIq4wUP6REuY\n" \
36 "ZhCgoAOQomeFqhAhkw6QJCygp5vw2rh9OZ5tiP/Ko6IDTA2rSas91nepHpQOb247\n" \
37 "zta5XzXb5TRkBsVU8tAPADP+wS/vBCS05ne1wmhdD6c6\n" \
38 "-----END ENCRYPTED PRIVATE KEY-----\n"
41 static int test_decode(void)
43 gnutls_x509_privkey_t key;
44 const gnutls_datum_t data = {
45 (unsigned char *)PRIVATE_KEY,
50 if ((err = gnutls_x509_privkey_init(&key)) < 0) {
51 fail("Failed to init key %s\n", gnutls_strerror(err));
54 err = gnutls_x509_privkey_import_pkcs8(key, &data,
55 GNUTLS_X509_FMT_PEM, "", 0);
56 if (err != GNUTLS_E_DECRYPTION_FAILED) {
57 fail("Unexpected error code: %s/%d\n", gnutls_strerror(err), err);
60 err = gnutls_x509_privkey_import_pkcs8(key, &data,
61 GNUTLS_X509_FMT_PEM, "password", 0);
63 fail("Unexpected error code: %s\n", gnutls_strerror(err));
66 success("Loaded key\n%s", PRIVATE_KEY);
68 gnutls_x509_privkey_deinit(key);