File: set_pkcs12_cred.c

package info (click to toggle)
gnutls13 1.4.4-3%2Betch5
  • links: PTS
  • area: main
  • in suites: etch
  • size: 24,052 kB
  • ctags: 12,507
  • sloc: ansic: 94,474; xml: 17,016; sh: 9,652; perl: 628; makefile: 607; sed: 16
file content (44 lines) | stat: -rw-r--r-- 893 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <stdlib.h>
#include <gnutls/gnutls.h>

int
main (int argc, char *argv[])
{
  gnutls_certificate_credentials_t x509cred;
  char *file, *password;
  int ret;

  ret = gnutls_global_init ();
  if (ret < 0)
    return 1;

  ret = gnutls_certificate_allocate_credentials (&x509cred);
  if (ret < 0)
    return 1;

  file = getenv ("PKCS12FILE");
  password = getenv ("PKCS12PASSWORD");

  if (!file)
    file = "client.p12";
  if (!password)
    password = "foobar";

  printf ("Reading PKCS#12 blob from `%s' using password `%s'.\n",
	  file, password);
  ret = gnutls_certificate_set_x509_simple_pkcs12_file (x509cred,
							file,
							GNUTLS_X509_FMT_DER,
							password);
  if (ret < 0)
    {
      printf ("x509_pkcs12 (%d): %s\n", ret, gnutls_strerror (ret));
    }

  gnutls_certificate_free_credentials (x509cred);

  gnutls_global_deinit ();

  return 0;
}