2 * Copyright (C) 2012 Lucas Fisher *lucas.fisher [at] gmail.com*
3 * Copyright (C) 2012 Free Software Foundation, Inc.
5 * This file is part of GnuTLS.
7 * GnuTLS is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * GnuTLS is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see
19 * <http://www.gnu.org/licenses/>.
24 #include <gnutls/gnutls.h>
25 #include <gnutls/x509.h>
26 #include <gnutls/openpgp.h>
27 #include <gnutls/pkcs12.h>
28 #include <gnutls/pkcs11.h>
29 #include <gnutls/abstract.h>
38 #include <sys/types.h>
42 #include "certtool-common.h"
43 #include "certtool-cfg.h"
48 /* Loads a x509 private key list
50 gnutls_x509_privkey_t
*
51 load_privkey_list (int mand
, size_t * privkey_size
, common_info_st
* info
)
53 static gnutls_x509_privkey_t key
[MAX_KEYS
];
56 gnutls_datum_t dat
, file_data
;
60 fprintf (stderr
, "Loading private key list...\n");
62 if (info
->privkey
== NULL
)
65 error (EXIT_FAILURE
, 0, "missing --load-privkey");
70 ret
= gnutls_load_file(info
->privkey
, &file_data
);
72 error (EXIT_FAILURE
, errno
, "%s", info
->privkey
);
74 ptr
= (void*)file_data
.data
;
75 ptr_size
= file_data
.size
;
77 for (i
= 0; i
< MAX_KEYS
; i
++)
79 ret
= gnutls_x509_privkey_init (&key
[i
]);
81 error (EXIT_FAILURE
, 0, "privkey_init: %s", gnutls_strerror (ret
));
83 dat
.data
= (void*)ptr
;
86 ret
= gnutls_x509_privkey_import (key
[i
], &dat
, info
->incert_format
);
87 if (ret
< 0 && *privkey_size
> 0)
90 error (EXIT_FAILURE
, 0, "privkey_import: %s", gnutls_strerror (ret
));
92 ptr
= strstr (ptr
, "---END");
97 ptr_size
= file_data
.size
;
99 (unsigned int) ((unsigned char *) ptr
- (unsigned char *) buffer
);
107 gnutls_free(file_data
.data
);
108 fprintf (stderr
, "Loaded %d private keys.\n", (int) *privkey_size
);