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 #if defined(HAVE_SSLCURL)
25 #include <curl/curl.h>
29 #include "opkg_message.h"
31 #if defined(HAVE_SSLCURL) || defined(HAVE_OPENSSL)
33 * This callback is called instead of X509_verify_cert to perform path
34 * validation on a certificate using pathfinder.
37 static int pathfinder_verify_callback(X509_STORE_CTX *ctx, void *arg)
40 const char *hex = "0123456789ABCDEF";
41 size_t size = i2d_X509(ctx->cert, NULL);
42 unsigned char *keybuf, *iend;
43 iend = keybuf = malloc(size);
44 i2d_X509(ctx->cert, &iend);
45 char *certdata_str = malloc(size * 2 + 1);
46 unsigned char *cp = keybuf;
47 char *certdata_str_i = certdata_str;
50 unsigned char ch = *cp++;
51 *certdata_str_i++ = hex[(ch >> 4) & 0xf];
52 *certdata_str_i++ = hex[ch & 0xf];
57 const char *policy = "2.5.29.32.0"; // anyPolicy
58 int validated = pathfinder_dbus_verify(certdata_str, policy, 0, 0, &errmsg);
61 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;
74 int i, ret = 1; /* signers are verified by default */
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)){
84 /* Signer isn't verified ! goto jail; */
90 sk_X509_free(signers);
95 #if defined(HAVE_SSLCURL)
96 CURLcode curl_ssl_ctx_function(CURL * curl, void * sslctx, void * parm) {
98 SSL_CTX * ctx = (SSL_CTX *) sslctx;
99 SSL_CTX_set_cert_verify_callback(ctx, pathfinder_verify_callback, parm);