1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

Avoid caches to get the most recent copy of the key. This is bug #1061

This commit is contained in:
David Shaw 2009-05-28 16:20:49 +00:00
parent a7205a080c
commit bcf540f2d0
8 changed files with 148 additions and 14 deletions

View file

@ -1,3 +1,15 @@
2009-05-28 David Shaw <dshaw@jabberwocky.com>
From 1.4:
* curl-shim.c (curl_slist_append, curl_slist_free_all): New.
Simple wrappers around strlist_t to emulate the curl way of doing
string lists.
(curl_easy_setopt): Handle the curl HTTPHEADER option.
* gpgkeys_curl.c, gpgkeys_hkp.c (main): Avoid caches to get the
most recent copy of the key. This is bug #1061.
2009-05-27 David Shaw <dshaw@jabberwocky.com>
From 1.4:

View file

@ -1,7 +1,7 @@
/* curl-shim.c - Implement a small subset of the curl API in terms of
* the iobuf HTTP API
*
* Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
* Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@ -26,8 +26,8 @@
#include <stdio.h>
#include <errno.h>
#include "http.h"
#include "util.h"
#include "http.h"
#include "ksutil.h"
#include "curl-shim.h"
@ -156,6 +156,9 @@ curl_easy_setopt(CURL *curl,CURLoption option,...)
case CURLOPT_STDERR:
curl->errors=va_arg(ap,FILE *);
break;
case CURLOPT_HTTPHEADER:
curl->headers=va_arg(ap,struct curl_slist *);
break;
default:
/* We ignore the huge majority of curl options */
break;
@ -196,7 +199,8 @@ curl_easy_perform(CURL *curl)
if(curl->flags.post)
{
rc = http_open (&curl->hd, HTTP_REQ_POST, curl->url, curl->auth,
0, proxy, NULL, curl->srvtag);
0, proxy, NULL, curl->srvtag,
curl->headers?curl->headers->list:NULL);
if (!rc)
{
unsigned int post_len = strlen(curl->postfields);
@ -219,7 +223,8 @@ curl_easy_perform(CURL *curl)
else
{
rc = http_open (&curl->hd, HTTP_REQ_GET, curl->url, curl->auth,
0, proxy, NULL, curl->srvtag);
0, proxy, NULL, curl->srvtag,
curl->headers?curl->headers->list:NULL);
if (!rc)
{
rc = http_wait_response (curl->hd);
@ -350,3 +355,28 @@ curl_version_info(int type)
return &data;
}
struct curl_slist *
curl_slist_append(struct curl_slist *list,const char *string)
{
if(!list)
{
list=calloc(1,sizeof(*list));
if(!list)
return NULL;
}
add_to_strlist(&list->list,string);
return list;
}
void
curl_slist_free_all(struct curl_slist *list)
{
if(list)
{
free_strlist(list->list);
free(list);
}
}

View file

@ -1,5 +1,5 @@
/* curl-shim.h
* Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
* Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
*
* This file is part of GNUPG.
*
@ -20,6 +20,7 @@
#ifndef _CURL_SHIM_H_
#define _CURL_SHIM_H_
#include "util.h"
#include "http.h"
typedef enum
@ -49,6 +50,7 @@ typedef enum
CURLOPT_POST,
CURLOPT_POSTFIELDS,
CURLOPT_FAILONERROR,
CURLOPT_HTTPHEADER,
CURLOPT_SRVTAG_GPG_HACK
} CURLoption;
@ -67,6 +69,7 @@ typedef struct
char *srvtag;
unsigned int status;
FILE *errors;
struct curl_slist *headers;
struct
{
unsigned int post:1;
@ -96,4 +99,13 @@ char *curl_escape(char *str,int len);
#define curl_version() "GnuPG curl-shim"
curl_version_info_data *curl_version_info(int type);
struct curl_slist
{
strlist_t list;
};
struct curl_slist *curl_slist_append(struct curl_slist *list,
const char *string);
void curl_slist_free_all(struct curl_slist *list);
#endif /* !_CURL_SHIM_H_ */

View file

@ -117,6 +117,7 @@ main(int argc,char *argv[])
long follow_redirects=5;
char *proxy=NULL;
curl_version_info_data *curldata;
struct curl_slist *headers=NULL;
console=stderr;
@ -305,6 +306,26 @@ main(int argc,char *argv[])
curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,(long)opt->flags.check_cert);
curl_easy_setopt(curl,CURLOPT_CAINFO,opt->ca_cert_file);
/* Avoid caches to get the most recent copy of the key. This is bug
#1061. In pre-curl versions of the code, we didn't do it. Then
we did do it (as a curl default) until curl changed the default.
Now we're doing it again, but in such a way that changing
defaults in the future won't impact us. We set both the Pragma
and Cache-Control versions of the header, so we're good with both
HTTP 1.0 and 1.1. */
headers=curl_slist_append(headers,"Pragma: no-cache");
if(headers)
headers=curl_slist_append(headers,"Cache-Control: no-cache");
if(!headers)
{
fprintf(console,"gpgkeys: out of memory when building HTTP headers\n");
ret=KEYSERVER_NO_MEMORY;
goto fail;
}
curl_easy_setopt(curl,CURLOPT_HTTPHEADER,headers);
if(proxy)
curl_easy_setopt(curl,CURLOPT_PROXY,proxy);
@ -385,6 +406,8 @@ main(int argc,char *argv[])
free_ks_options(opt);
curl_slist_free_all(headers);
if(curl)
curl_easy_cleanup(curl);

View file

@ -547,6 +547,7 @@ main(int argc,char *argv[])
int failed=0;
struct keylist *keylist=NULL,*keyptr=NULL;
char *proxy=NULL;
struct curl_slist *headers=NULL;
console=stderr;
@ -742,6 +743,26 @@ main(int argc,char *argv[])
curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,(long)opt->flags.check_cert);
curl_easy_setopt(curl,CURLOPT_CAINFO,opt->ca_cert_file);
/* Avoid caches to get the most recent copy of the key. This is bug
#1061. In pre-curl versions of the code, we didn't do it. Then
we did do it (as a curl default) until curl changed the default.
Now we're doing it again, but in such a way that changing
defaults in the future won't impact us. We set both the Pragma
and Cache-Control versions of the header, so we're good with both
HTTP 1.0 and 1.1. */
headers=curl_slist_append(headers,"Pragma: no-cache");
if(headers)
headers=curl_slist_append(headers,"Cache-Control: no-cache");
if(!headers)
{
fprintf(console,"gpgkeys: out of memory when building HTTP headers\n");
ret=KEYSERVER_NO_MEMORY;
goto fail;
}
curl_easy_setopt(curl,CURLOPT_HTTPHEADER,headers);
if(proxy)
curl_easy_setopt(curl,CURLOPT_PROXY,proxy);
@ -919,6 +940,8 @@ main(int argc,char *argv[])
free_ks_options(opt);
curl_slist_free_all(headers);
if(curl)
curl_easy_cleanup(curl);