gnutls_datum key_id = { "\x00\x00\x07", 3 };
gnutls_global_init();
- gnutls_global_set_log_level(2);
/* Firstly we create two helper bags, which hold the certificate,
* and the (encrypted) key.
*/
gnutls_pkcs12_bag_set_key_id(bag, bag_index, &key_id);
- gnutls_pkcs12_bag_encrypt(bag, password, 0);
+ /* use weak encryption for the certificate.
+ */
+ gnutls_pkcs12_bag_encrypt(bag, password, GNUTLS_PKCS_USE_PKCS12_RC2_40);
/* Now the key.
*/
exit(1);
}
- /* Note that since the PKCS #8 key is encrypted we don't
- * bother encrypting the bag.
+ /* Note that since the PKCS #8 key is already encrypted we don't
+ * bother encrypting that bag.
*/
bag_index = ret;
a private key. A certificate request can be later be processed by a CA,
which should return a signed certificate.
+\input{ex-crq}
+
\subsection{PKCS \#12 structure generation}
\label{ex:pkcs12}
The following example is about generating a PKCS \#12 structure.
\input{ex-pkcs12}
-\input{ex-crq}
\input{openssl}
} gnutls_pkcs12_bag_type;
gnutls_pkcs12_bag_type gnutls_pkcs12_bag_get_type(gnutls_pkcs12_bag bag, int indx);
-int gnutls_pkcs12_bag_get_data(gnutls_pkcs12_bag bag, int indx, gnutls_const_datum* data);
+int gnutls_pkcs12_bag_get_data(gnutls_pkcs12_bag bag, int indx, gnutls_datum* data);
int gnutls_pkcs12_bag_set_data(gnutls_pkcs12_bag bag, gnutls_pkcs12_bag_type type,
const gnutls_datum* data);
int gnutls_pkcs12_bag_set_crl(gnutls_pkcs12_bag bag, gnutls_x509_crl crl);
} gnutls_datum;
-typedef struct {
- const unsigned char * data;
- unsigned int size;
-} gnutls_const_datum;
-
/* internal functions */
int gnutls_init(gnutls_session * session, gnutls_connection_end con_end);
unsigned int size;
} gnutls_datum;
-typedef struct {
- const opaque * data;
- unsigned int size;
-} gnutls_const_datum;
-
#include <gnutls_buffer.h>
/* This is the maximum number of algorithms (ciphers or macs etc).
* This function will return the bag's data.
*
**/
-int gnutls_pkcs12_bag_get_data(gnutls_pkcs12_bag bag, int indx, gnutls_const_datum * data)
+int gnutls_pkcs12_bag_get_data(gnutls_pkcs12_bag bag, int indx, gnutls_datum * data)
{
if (bag == NULL) {
gnutls_assert();
{
int result;
int count, i, type;
-gnutls_const_datum cdata;
+gnutls_datum cdata;
const char* str;
-gnutls_datum out, data;
+gnutls_datum out;
count = gnutls_pkcs12_bag_get_count( bag);
if (count < 0) {
str = NULL;
}
- /* we have to cast gnutls_const_datum to a
- * plain datum.
- */
- data.data = (unsigned char*)cdata.data;
- data.size = cdata.size;
-
if (str != NULL) {
- gnutls_pem_base64_encode_alloc( str, &data, &out);
+ gnutls_pem_base64_encode_alloc( str, &cdata, &out);
fprintf( outfile, "%s\n", out.data);
gnutls_free(out.data);