Changeset 3956


Ignore:
Timestamp:
01/25/08 18:16:24 (5 years ago)
Author:
thomas
Message:

opkg: initial implementation of package list signature verification

Location:
trunk/src/target/opkg
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/target/opkg/opkg_cmd.c

    r3934 r3956  
    266266          } 
    267267          free(url); 
     268 
     269          /* download detached signitures to verify the package lists */ 
     270          /* get the url for the sig file */ 
     271          if (src->extra_data)  /* debian style? */ 
     272              sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data, 
     273                            "Packages.sig"); 
     274          else 
     275              sprintf_alloc(&url, "%s/%s", src->value, "Packages.sig"); 
     276 
     277          /* create temporary dir for it */ 
     278          char *tmp, *tmp_file_name; 
     279          tmp = strdup ("/tmp/opkg.XXXXXX"); 
     280          if (mkdtemp (tmp) == NULL) { 
     281                perror ("mkdtemp"); 
     282                failures++; 
     283                continue; 
     284          } 
     285          sprintf_alloc (&tmp_file_name, "%s/%s", tmp, "Packages.sig"); 
     286 
     287          err = opkg_download(conf, url, tmp_file_name); 
     288          if (err) { 
     289            failures++; 
     290          } else { 
     291            int err; 
     292            err = opkg_verify_file (list_file_name, tmp_file_name); 
     293            if (err == 0) 
     294                opkg_message (conf, OPKG_NOTICE, "Signature check passed\n"); 
     295            else 
     296                opkg_message (conf, OPKG_NOTICE, "Signature check failed\n"); 
     297          } 
     298          unlink (tmp_file_name); 
     299          free (tmp_file_name); 
     300 
     301          free (url); 
    268302          free(list_file_name); 
    269303     } 
  • trunk/src/target/opkg/opkg_download.c

    r3933 r3956  
    1919 
    2020#include <curl/curl.h> 
     21#include <gpgme.h> 
    2122 
    2223#include "opkg.h" 
     
    153154        curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, src); 
    154155        curl_easy_setopt (curl, CURLOPT_PROGRESSFUNCTION, curl_progress_func); 
     156        curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1); 
    155157        if (conf->http_proxy || conf->ftp_proxy) 
    156158        { 
     
    164166        curl_easy_cleanup (curl); 
    165167        fclose (file); 
     168        if (res) 
     169            return res; 
    166170 
    167171    } 
     
    272276     return 0; 
    273277} 
     278 
     279int 
     280opkg_verify_file (char *text_file, char *sig_file) 
     281{ 
     282    int status = -1; 
     283    gpgme_ctx_t ctx; 
     284    gpgme_data_t sig, text; 
     285    gpgme_error_t err = -1; 
     286    gpgme_verify_result_t result; 
     287    gpgme_signature_t s; 
     288     
     289    err = gpgme_new (&ctx); 
     290 
     291    if (err) 
     292        return -1; 
     293 
     294    err = gpgme_data_new_from_file (&sig, sig_file, 1);  
     295    if (err) 
     296        return -1; 
     297 
     298    err = gpgme_data_new_from_file (&text, text_file, 1);  
     299    if (err) 
     300        return -1; 
     301 
     302    err = gpgme_op_verify (ctx, sig, text, NULL); 
     303 
     304    result = gpgme_op_verify_result (ctx); 
     305 
     306    /* see if any of the signitures matched */ 
     307    s = result->signatures; 
     308    while (s) 
     309    { 
     310        status = gpg_err_code (s->status); 
     311        if (status == GPG_ERR_NO_ERROR) 
     312            break; 
     313        s = s->next; 
     314    } 
     315 
     316    gpgme_data_release (sig); 
     317    gpgme_data_release (text); 
     318    gpgme_release (ctx); 
     319 
     320    return status; 
     321} 
  • trunk/src/target/opkg/opkg_download.h

    r3880 r3956  
    2828int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **namep); 
    2929 
     30int opkg_verify_file (char *text_file, char *sig_file); 
    3031#endif 
Note: See TracChangeset for help on using the changeset viewer.