1 /* vi: set noexpandtab sw=4 sts=4: */
2 /* opkg_download.c - the opkg package management system
6 Copyright (C) 2001 University of Southern California
7 Copyright (C) 2008 OpenMoko Inc
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2, or (at
12 your option) any later version.
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
21 #include <openssl/ssl.h>
22 #include <libpathfinder.h>
24 #include "opkg_message.h"
26 #if defined(HAVE_SSLCURL)
27 #include <curl/curl.h>
30 #if defined(HAVE_SSLCURL) || defined(HAVE_OPENSSL)
32 * This callback is called instead of X509_verify_cert to perform path
33 * validation on a certificate using pathfinder.
36 static int pathfinder_verify_callback(X509_STORE_CTX *ctx, void *arg)
39 const char *hex = "0123456789ABCDEF";
40 size_t size = i2d_X509(ctx->cert, NULL);
41 unsigned char *keybuf, *iend;
42 iend = keybuf = malloc(size);
43 i2d_X509(ctx->cert, &iend);
44 char *certdata_str = malloc(size * 2 + 1);
45 unsigned char *cp = keybuf;
46 char *certdata_str_i = certdata_str;
49 unsigned char ch = *cp++;
50 *certdata_str_i++ = hex[(ch >> 4) & 0xf];
51 *certdata_str_i++ = hex[ch & 0xf];
56 const char *policy = "2.5.29.32.0"; // anyPolicy
57 int validated = pathfinder_dbus_verify(certdata_str, policy, 0, 0, &errmsg);
60 fprintf(stderr, "curlcb_pathfinder: Path verification failed: %s", errmsg);
70 #if defined(HAVE_OPENSSL)
71 int pkcs7_pathfinder_verify_signers(PKCS7* p7)
73 STACK_OF(X509) *signers;
76 signers = PKCS7_get0_signers(p7, NULL, 0);
78 for(i = 0; i < sk_X509_num(signers); i++){
79 X509_STORE_CTX ctx = {
80 .cert = sk_X509_value(signers, i),
83 if(!pathfinder_verify_callback(&ctx, NULL))
91 #if defined(HAVE_SSLCURL)
92 CURLcode curl_ssl_ctx_function(CURL * curl, void * sslctx, void * parm) {
94 SSL_CTX * ctx = (SSL_CTX *) sslctx;
95 SSL_CTX_set_cert_verify_callback(ctx, pathfinder_verify_callback, parm);