1
/* ks-proto.c keyserver protocol handling
2
* Copyright (C) 1998 Free Software Foundation, Inc.
4
* This file is part of GnuPG.
6
* GnuPG is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* GnuPG is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22
* The extended HKP protocol:
24
* GET /pks/lookup[/<gnupg_user_id>][?[op=<cmd>][&armor=0][&search=<keywords>]]
26
* Default is: "armor=1", "op=get". "search" is only allowed if gnupg_user_id
27
* is not present. GET maybe replaced by HEAD in which case only some status
28
* information is returned.
30
* Hmmm, I don't like it, the better solution is to use:
32
* /pks/gnupg/get for binary lookups
33
* /pks/gnupg/upd to update a key
34
* /pks/gnupg/ins to insert a new key
36
* Optional a version string can be inserted as in:
40
* Returned HTTP options:
41
* X-Key-Hash: <rmd160 hash value of the keyblock>
42
* X-Key-MTime: <last modification time>
43
* X-Key-LID: <local_key_id_used_for_update_etc>
44
* [fixme: is X-.... allowed?]
59
do_read( int fd, char *buffer, size_t bufsize, int *ret_nread )
72
if( !(rc=select(fd+1, &rfds, NULL, NULL, &tv)) )
73
return 0; /* timeout */
75
log_error("select() error: %s\n", strerror(errno));
80
n = read(fd, buffer, bufsize );
81
if( n >= 0 && n > bufsize )
82
log_bug("bogus read from fd %d (n=%d)\n", fd, n );
83
} while( n == -1 && errno == EINTR );
85
log_error("read error on fd %d: %s\n", fd, strerror(errno) );
95
ks_get_request( int fd, KS_TRANS *req )
97
char *p, *p2, buf[500];
103
while( !do_read( fd, buf, DIM(buf)-1, &nread ) {
106
/* replace the trailing LF with a 0 */
107
for(p2=p,n=0; n < nread && *p2 != '\n'; p2++ )
110
req->err = KS_ERR_REQ_TOO_LONG;
116
/* now look at the request. Note that the isspace() will work
117
* because there is still a CR before the 0 */
118
if( (p[0] == 'G' || p[0] == 'g')
119
&& (p[1] == 'E' || p[1] == 'e')
120
&& (p[2] == 'T' || p[2] == 't') && isspace( p[3] ) ) {
121
req->cmd = KS_REQ_GET;
124
else if( (p[0] == 'H' || p[0] == 'h')
125
&& (p[1] == 'E' || p[1] == 'e')
126
&& (p[2] == 'A' || p[2] == 'a')
127
&& (p[3] == 'D' || p[3] == 'd') && isspace( p[4] ) ) {
128
req->cmd = KS_REQ_HEAD;
131
else if( (p[0] == 'H' || p[0] == 'h')
132
&& (p[1] == 'E' || p[1] == 'e')
133
&& (p[2] == 'L' || p[2] == 'l')
134
&& (p[3] == 'P' || p[3] == 'p') && isspace( p[4] ) ) {
135
req->cmd = KS_REQ_HELP;
139
req->cmd = KS_REQ_UNKNOWN;
140
/* skip spaces, store args and remaining data */
141
while( *p == ' ' || *p == '\t' )
143
/* fixme: remove trailing blanks from args */
145
p = p2; /* p now points to the remaining n bytes in the buffer */
149
/* read the option lines */