1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/* vi: set expandtab sw=4 sts=4: */
/* opkg_verify.c - the opkg package management system
Copyright (C) 2014 Paul Barker
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
*/
#include "config.h"
#include <malloc.h>
#include <string.h>
#include "file_util.h"
#include "opkg_conf.h"
#include "opkg_message.h"
#include "opkg_verify.h"
#ifdef HAVE_GPGME
#include "opkg_gpg.h"
#else
/* Dummy gpg signature verification. */
int opkg_verify_gpg_signature(const char *file, const char *sigfile)
{
(void)file;
(void)sigfile;
opkg_msg(ERROR, "GPG signature checking not supported\n");
return -1;
}
#endif
#ifdef HAVE_OPENSSL
#include "opkg_openssl.h"
#else
/* Dummy openssl signature verification. */
int opkg_verify_openssl_signature(const char *file, const char *sigfile)
{
(void)file;
(void)sigfile;
opkg_msg(ERROR, "OpenSSL signature checking not supported\n");
return -1;
}
#endif
int opkg_verify_md5sum(const char *file, const char *md5sum)
{
int r;
char *file_md5sum;
if (!file_exists(file))
return -1;
file_md5sum = file_md5sum_alloc(file);
if (!file_md5sum)
return -1;
r = strcmp(file_md5sum, md5sum);
free(file_md5sum);
return r;
}
int opkg_verify_sha256sum(const char *file, const char *sha256sum)
{
#ifdef HAVE_SHA256
int r;
char *file_sha256sum;
if (!file_exists(file))
return -1;
file_sha256sum = file_sha256sum_alloc(file);
if (!file_sha256sum)
return -1;
r = strcmp(file_sha256sum, sha256sum);
free(file_sha256sum);
return r;
#else
(void)sha256sum;
opkg_msg(INFO, "Ignoring sha256sum for file '%s'\n", file);
return 0;
#endif
}
int opkg_verify_signature(const char *file, const char *sigfile)
{
int use_gpg = (strcmp(opkg_config->signature_type, "gpg") == 0)
|| (strcmp(opkg_config->signature_type, "gpg-asc") == 0);
if (use_gpg)
return opkg_verify_gpg_signature(file, sigfile);
else if (strcmp(opkg_config->signature_type, "openssl") == 0)
return opkg_verify_openssl_signature(file, sigfile);
opkg_msg(ERROR, "signature_type option '%s' not understood.\n",
opkg_config->signature_type);
return -1;
}
|