blob: c5eaca1ef368cc297386c2c177bc80ec65b228ff (
plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
\begin {verbatim}
/* This file is actually an example of using the OpenCDK library
* to retrieve an OpenPGP key from a key server.
*/
#include <stdlib.h>
#include <gnutls/gnutls.h>
#include <gnutls/extra.h>
#include <opencdk.h>
/* A callback function that tries to connect
* to a public keyserver to get the specified key.
* The callback should be set as:
*
* gnutls_openpgp_set_recv_key_function( session, recv_openpgp_key);
*
* in the initialization of a gnutls session.
*/
static const char *hostname = "hkp://keyserver.somewhere.com";
static const short port = 11371;
int
recv_openpgp_key(gnutls_session session, const unsigned char *keyfpr,
unsigned int keyfpr_length, gnutls_datum * key)
{
int rc;
CDK_KBNODE knode = NULL;
unsigned char* buf = NULL;
/* The key fingerprint should be 20 bytes
* in v4 keys.
*/
if (keyfpr_length != 20)
return -1;
rc = cdk_keyserver_recv_key( hostname, port, keyfpr,
CDK_DBSEARCH_FPR, &knode );
if( !rc ) {
size_t len;
cdk_kbnode_write_to_mem( knode, NULL, &len);
key->data = malloc( len);
if (key->data==NULL) {
rc = -1;
goto finish;
}
cdk_kbnode_write_to_mem( knode, key->data, &len);
rc = 0; /* success */
} else {
rc = -1;
}
finish:
cdk_free( buf );
cdk_kbnode_release( knode );
return rc;
}
\end{verbatim}
|