X-Git-Url: https://the.earth.li/gitweb/?a=blobdiff_plain;f=keydb_hkp.c;h=3ec46a4f2cf7b9e9bb40ca1e806961727fa40370;hb=2039724ebd70536ad567630725f6b75b7868e486;hp=7c7b31a4a50e75bc7acc290bb6333e81c8c07cf7;hpb=8e0907be1d73011075a99a0c029c56664e12843e;p=onak.git
diff --git a/keydb_hkp.c b/keydb_hkp.c
index 7c7b31a..3ec46a4 100644
--- a/keydb_hkp.c
+++ b/keydb_hkp.c
@@ -13,16 +13,18 @@
* more details.
*
* You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * this program. If not, see .
*/
+#include
+#include
#include
#include
#include
-#include
#include
+#include "build-config.h"
+
#include "armor.h"
#include "charfuncs.h"
#include "keydb.h"
@@ -31,11 +33,11 @@
#include "mem.h"
#include "onak-conf.h"
#include "parsekey.h"
-#include "version.h"
struct onak_hkp_dbctx {
+ struct onak_db_config *config; /* Our DB config info */
CURL *curl;
- char hkpbase[1024];
+ char hkpbase[512];
};
static int hkp_parse_url(struct onak_hkp_dbctx *privctx, const char *url)
@@ -48,11 +50,11 @@ static int hkp_parse_url(struct onak_hkp_dbctx *privctx, const char *url)
proto[0] = host[0] = 0;
port = 0;
- matched = sscanf(url, "%5[a-z]://%256[a-zA-Z0-9.]:%u", proto, host,
+ matched = sscanf(url, "%5[a-z]://%256[a-zA-Z0-9.-]:%u", proto, host,
&port);
if (matched < 2) {
proto[0] = 0;
- matched = sscanf(url, "%256[a-zA-Z0-9.]:%u", host, &port);
+ sscanf(url, "%256[a-zA-Z0-9.-]:%u", host, &port);
}
if (host[0] == 0) {
@@ -163,7 +165,7 @@ static int hkp_fetch_key_id(struct onak_dbctx *dbctx,
* hkp_fetch_key_fp - Given a fingerprint fetch the key from HKP server.
*/
static int hkp_fetch_key_fp(struct onak_dbctx *dbctx,
- uint8_t *fp, size_t fpsize,
+ struct openpgp_fingerprint *fingerprint,
struct openpgp_publickey **publickey,
bool intrans)
{
@@ -171,19 +173,19 @@ static int hkp_fetch_key_fp(struct onak_dbctx *dbctx,
char keyurl[1024];
int i, ofs;
- if (fpsize > MAX_FINGERPRINT_LEN) {
+ if (fingerprint->length > MAX_FINGERPRINT_LEN) {
return 0;
}
ofs = snprintf(keyurl, sizeof(keyurl),
"%s/lookup?op=get&search=0x", privctx->hkpbase);
- if ((ofs + fpsize * 2 + 1)> sizeof(keyurl)) {
+ if ((ofs + fingerprint->length * 2 + 1)> sizeof(keyurl)) {
return 0;
}
- for (i = 0; i < fpsize; i++) {
- ofs += sprintf(&keyurl[ofs], "%02X", fp[i]);
+ for (i = 0; i < fingerprint->length; i++) {
+ ofs += sprintf(&keyurl[ofs], "%02X", fingerprint->fp[i]);
}
return (hkp_fetch_key_url(dbctx, keyurl, publickey, intrans));
@@ -346,7 +348,7 @@ static void hkp_cleanupdb(struct onak_dbctx *dbctx)
*
* We initialize CURL here.
*/
-struct onak_dbctx *keydb_hkp_init(bool readonly)
+struct onak_dbctx *keydb_hkp_init(struct onak_db_config *dbcfg, bool readonly)
{
struct onak_dbctx *dbctx;
struct onak_hkp_dbctx *privctx;
@@ -357,6 +359,7 @@ struct onak_dbctx *keydb_hkp_init(bool readonly)
return NULL;
}
+ dbctx->config = dbcfg;
dbctx->priv = privctx = malloc(sizeof(*privctx));
dbctx->cleanupdb = hkp_cleanupdb;
dbctx->starttrans = hkp_starttrans;
@@ -373,9 +376,11 @@ struct onak_dbctx *keydb_hkp_init(bool readonly)
dbctx->getfullkeyid = generic_getfullkeyid;
dbctx->iterate_keys = hkp_iterate_keys;
- if (!hkp_parse_url(privctx, config.db_dir)) {
+ if (!hkp_parse_url(privctx, dbcfg->location)) {
exit(EXIT_FAILURE);
}
+ logthing(LOGTHING_INFO, "Using %s as HKP forwarding URL.",
+ privctx->hkpbase);
curl_global_init(CURL_GLOBAL_DEFAULT);
privctx->curl = curl_easy_init();
if (privctx->curl == NULL) {