32#include "xbps_api_impl.h"
36verify_binpkg(
struct xbps_handle *xhp, xbps_dictionary_t pkgd)
38 char binfile[PATH_MAX];
40 const char *pkgver, *repoloc, *sha256;
44 xbps_dictionary_get_cstring_nocopy(pkgd,
"repository", &repoloc);
45 xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
58 "%s: %s\n", pkgver, repoloc, strerror(errno));
63 xbps_set_cb_state(
xhp, XBPS_STATE_VERIFY, 0, pkgver,
64 "%s: verifying RSA signature...", pkgver);
68 xbps_set_cb_state(
xhp, XBPS_STATE_VERIFY_FAIL, rv, pkgver,
69 "%s: the RSA signature is not valid!", pkgver);
70 xbps_set_cb_state(
xhp, XBPS_STATE_VERIFY_FAIL, rv, pkgver,
71 "%s: removed pkg archive and its signature.", pkgver);
72 (void)remove(binfile);
73 if (
xbps_strlcat(binfile,
".sig2",
sizeof(binfile)) <
sizeof(binfile))
74 (void)remove(binfile);
79 xbps_set_cb_state(
xhp, XBPS_STATE_VERIFY, 0, pkgver,
80 "%s: verifying SHA256 hash...", pkgver);
81 xbps_dictionary_get_cstring_nocopy(pkgd,
"filename-sha256", &sha256);
84 xbps_set_cb_state(
xhp, XBPS_STATE_VERIFY_FAIL,
86 "%s: checksum does not match repository index",
89 xbps_set_cb_state(
xhp, XBPS_STATE_VERIFY_FAIL,
90 rv, pkgver,
"%s: failed to checksum: %s",
91 pkgver, strerror(errno));
102download_binpkg(
struct xbps_handle *
xhp, xbps_dictionary_t repo_pkgd)
107 const char *pkgver, *
arch, *fetchstr, *repoloc;
108 unsigned char digest[XBPS_SHA256_DIGEST_SIZE] = {0};
111 xbps_dictionary_get_cstring_nocopy(repo_pkgd,
"repository", &repoloc);
115 xbps_dictionary_get_cstring_nocopy(repo_pkgd,
"pkgver", &pkgver);
116 xbps_dictionary_get_cstring_nocopy(repo_pkgd,
"architecture", &
arch);
118 snprintf(buf,
sizeof buf,
"%s/%s.%s.xbps.sig2", repoloc, pkgver,
arch);
119 sigsuffix = buf+(strlen(buf)-
sizeof (
".sig2")+1);
121 xbps_set_cb_state(
xhp, XBPS_STATE_DOWNLOAD, 0, pkgver,
122 "Downloading `%s' signature (from `%s')...", pkgver, repoloc);
125 rv = fetchLastErrCode ? fetchLastErrCode : errno;
127 xbps_set_cb_state(
xhp, XBPS_STATE_DOWNLOAD_FAIL, rv,
128 pkgver,
"[trans] failed to download `%s' signature from `%s': %s",
129 pkgver, repoloc, fetchstr ? fetchstr : strerror(rv));
135 xbps_set_cb_state(
xhp, XBPS_STATE_DOWNLOAD, 0, pkgver,
136 "Downloading `%s' package (from `%s')...", pkgver, repoloc);
139 rv = fetchLastErrCode ? fetchLastErrCode : errno;
141 xbps_set_cb_state(
xhp, XBPS_STATE_DOWNLOAD_FAIL, rv,
142 pkgver,
"[trans] failed to download `%s' package from `%s': %s",
143 pkgver, repoloc, fetchstr ? fetchstr : strerror(rv));
147 xbps_set_cb_state(
xhp, XBPS_STATE_VERIFY, 0, pkgver,
148 "%s: verifying RSA signature...", pkgver);
150 snprintf(buf,
sizeof buf,
"%s/%s.%s.xbps.sig2",
xhp->
cachedir, pkgver,
arch);
151 sigsuffix = buf+(strlen(buf)-
sizeof (
".sig2")+1);
156 "%s: %s\n", pkgver, repoloc, strerror(errno));
165 if (fetchLastErrCode == FETCH_UNCHANGED) {
187 xbps_set_cb_state(
xhp, XBPS_STATE_VERIFY_FAIL, rv, pkgver,
188 "%s: the RSA signature is not valid!", pkgver);
189 xbps_set_cb_state(
xhp, XBPS_STATE_VERIFY_FAIL, rv, pkgver,
190 "%s: removed pkg archive and its signature.", pkgver);
197xbps_transaction_fetch(
struct xbps_handle *
xhp, xbps_object_iterator_t iter)
199 xbps_array_t fetch = NULL, verify = NULL;
206 xbps_object_iterator_reset(iter);
208 while ((obj = xbps_object_iterator_next(iter)) != NULL) {
210 if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD ||
211 ttype == XBPS_TRANS_CONFIGURE) {
214 xbps_dictionary_get_cstring_nocopy(obj,
"repository", &repoloc);
222 if (!fetch && !(fetch = xbps_array_create())) {
226 xbps_array_add(fetch, obj);
233 if (!verify && !(verify = xbps_array_create())) {
237 xbps_array_add(verify, obj);
239 xbps_object_iterator_reset(iter);
245 n = xbps_array_count(fetch);
247 xbps_set_cb_state(
xhp, XBPS_STATE_TRANS_DOWNLOAD, 0, NULL, NULL);
250 for (i = 0; i < n; i++) {
251 if ((rv = download_binpkg(
xhp, xbps_array_get(fetch, i))) != 0) {
253 "%s\n", strerror(rv));
261 n = xbps_array_count(verify);
263 xbps_set_cb_state(
xhp, XBPS_STATE_TRANS_VERIFY, 0, NULL, NULL);
266 for (i = 0; i < n; i++) {
267 if ((rv = verify_binpkg(
xhp, xbps_array_get(verify, i))) != 0) {
269 "%s\n", strerror(rv));
276 xbps_object_release(fetch);
278 xbps_object_release(verify);
int xbps_fetch_file_sha256(struct xbps_handle *xhp, const char *uri, const char *flags, unsigned char *digest, size_t digestlen)
const char * xbps_fetch_error_string(void)
int xbps_fetch_file(struct xbps_handle *xhp, const char *uri, const char *flags)
char cachedir[XBPS_MAXPATH]
Generic XBPS structure handler for initialization.
void xbps_dbg_printf(const char *fmt,...)
Prints debug messages to stderr.
struct xbps_repo * xbps_rpool_get_repo(const char *url)
xbps_trans_type_t xbps_transaction_pkg_type(xbps_dictionary_t pkg_repod)
bool xbps_verify_file_signature(struct xbps_repo *repo, const char *fname)
int xbps_file_sha256_check(const char *file, const char *sha256)
bool xbps_verify_signature(struct xbps_repo *repo, const char *sigfile, unsigned char *digest)
bool xbps_remote_binpkg_exists(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
ssize_t xbps_pkg_path(struct xbps_handle *xhp, char *dst, size_t dstsz, xbps_dictionary_t pkgd)
bool xbps_repository_is_remote(const char *uri)
size_t xbps_strlcat(char *dst, const char *src, size_t dstsize)