2 * Copyright (C) Ilari Liusvaara 2009-2010
4 * This code is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
10 #include "certificate.h"
13 #include <gnutls/openpgp.h>
15 #include "git-compat-util.h"
17 int select_keypair_int(gnutls_certificate_credentials_t creds
,
20 char keypath
[PATH_MAX
+ 1];
22 struct certificate cert
;
25 r
= snprintf(keypath
, PATH_MAX
+ 1, "$XDG_CONFIG_HOME/gits/keys/%s",
27 if (r
< 0 || r
> PATH_MAX
) {
28 die("Username too long");
31 keypath2
= expand_path(keypath
);
32 cert
= parse_certificate(keypath2
, &r
);
34 if (r
== CERTERR_NOCERT
)
36 if (r
== CERTERR_CANTREAD
)
37 die_errno("Can't read keypair");
39 die("Can't read keypair: %s",
40 cert_parse_strerr(r
));
43 r
= gnutls_certificate_set_openpgp_keyring_mem(creds
,
44 cert
.public_key
.data
, cert
.public_key
.size
,
45 GNUTLS_OPENPGP_FMT_RAW
);
47 die("Can't load public key: %s", gnutls_strerror(r
));
49 r
= gnutls_certificate_set_openpgp_key_mem(creds
, &cert
.public_key
,
50 &cert
.private_key
, GNUTLS_OPENPGP_FMT_RAW
);
52 die("Can't load keypair: %s", gnutls_strerror(r
));