Skip to content

Commit 406f109

Browse files
classabbyampDuncaen
authored andcommitted
lib/, bin/: fix signature type, now called *.sig2
Since 8d5c48b, xbps has used a sha1 ASN1 prefix with a sha256 hash, and as of openssl v3, openssl cares about this. This works around that in a compatible way by moving to a second sig file, binpkg.sig2. For xbps-remove -O and xbps-rindex -r, also clean up obselete .sig files.
1 parent e2ab720 commit 406f109

File tree

7 files changed

+31
-21
lines changed

7 files changed

+31
-21
lines changed

bin/xbps-remove/clean-cache.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj,
7575
bool *done UNUSED)
7676
{
7777
char buf[PATH_MAX];
78+
char buf2[PATH_MAX];
7879
xbps_dictionary_t pkgd;
7980
const char *binpkg, *rsha256;
8081
const char *binpkgver, *binpkgarch;
@@ -116,6 +117,7 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj,
116117
}
117118
}
118119
snprintf(buf, sizeof(buf), "%s.sig", binpkg);
120+
snprintf(buf2, sizeof(buf2), "%s.sig2", binpkg);
119121
if (!data->dry && unlink(binpkg) == -1) {
120122
xbps_error_printf("Failed to remove `%s': %s\n",
121123
binpkg, strerror(errno));
@@ -126,6 +128,10 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj,
126128
xbps_error_printf("Failed to remove `%s': %s\n",
127129
buf, strerror(errno));
128130
}
131+
if (!data->dry && unlink(buf2) == -1 && errno != ENOENT) {
132+
xbps_error_printf("Failed to remove `%s': %s\n",
133+
buf2, strerror(errno));
134+
}
129135

130136
return 0;
131137
}

bin/xbps-rindex/remove-obsoletes.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@
3939
static int
4040
remove_pkg(const char *repodir, const char *file)
4141
{
42-
char *filepath, *sigpath;
42+
char *filepath, *sigpath, *sig2path;
4343
int rv = 0;
4444

4545
filepath = xbps_xasprintf("%s/%s", repodir, file);
4646
sigpath = xbps_xasprintf("%s.sig", filepath);
47+
sig2path = xbps_xasprintf("%s.sig2", filepath);
4748
if (remove(filepath) == -1) {
4849
if (errno != ENOENT) {
4950
rv = errno;
@@ -55,10 +56,18 @@ remove_pkg(const char *repodir, const char *file)
5556
if (errno != ENOENT) {
5657
rv = errno;
5758
xbps_error_printf("xbps-rindex: failed to remove "
58-
"package signature `%s': %s\n", sigpath, strerror(rv));
59+
"legacy package signature `%s': %s\n", sigpath, strerror(rv));
60+
}
61+
}
62+
if (remove(sig2path) == -1) {
63+
if (errno != ENOENT) {
64+
rv = errno;
65+
xbps_error_printf("xbps-rindex: failed to remove "
66+
"package signature `%s': %s\n", sig2path, strerror(rv));
5967
}
6068
}
6169
free(sigpath);
70+
free(sig2path);
6271
free(filepath);
6372

6473
return rv;

bin/xbps-rindex/sign.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,7 @@ rsa_sign_file(RSA *rsa, const char *file,
101101
return false;
102102
}
103103

104-
/*
105-
* XXX: NID_sha1 is wrong, doesn't make it any weaker
106-
* but the ASN1 is wrong, OpenSSL/LibreSSL doesn't care.
107-
* Other implementations like golang fail because of this.
108-
*/
109-
if (!RSA_sign(NID_sha1, digest, XBPS_SHA256_DIGEST_SIZE,
104+
if (!RSA_sign(NID_sha256, digest, XBPS_SHA256_DIGEST_SIZE,
110105
*sigret, siglen, rsa)) {
111106
free(*sigret);
112107
return false;
@@ -257,7 +252,7 @@ sign_pkg(struct xbps_handle *xhp, const char *binpkg, const char *privkey, bool
257252
char *sigfile = NULL;
258253
int rv = 0, sigfile_fd = -1;
259254

260-
sigfile = xbps_xasprintf("%s.sig", binpkg);
255+
sigfile = xbps_xasprintf("%s.sig2", binpkg);
261256
/*
262257
* Skip pkg if file signature exists
263258
*/

include/xbps.h.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,8 +1975,8 @@ bool xbps_verify_signature(struct xbps_repo *repo, const char *sigfile,
19751975
* in \a repo.
19761976
*
19771977
* @param[in] repo Repository to use with the RSA public key associated.
1978-
* @param[in] fname The filename to verify, the signature file must have a .sig
1979-
* extension, i.e `<fname>.sig`.
1978+
* @param[in] fname The filename to verify, the signature file must have a .sig2
1979+
* extension, i.e `<fname>.sig2`.
19801980
*
19811981
* @return True if the signature is valid, false otherwise.
19821982
*/

lib/transaction_fetch.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ verify_binpkg(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
7171
xbps_set_cb_state(xhp, XBPS_STATE_VERIFY_FAIL, rv, pkgver,
7272
"%s: removed pkg archive and its signature.", pkgver);
7373
(void)remove(binfile);
74-
sigfile = xbps_xasprintf("%s.sig", binfile);
74+
sigfile = xbps_xasprintf("%s.sig2", binfile);
7575
(void)remove(sigfile);
7676
free(sigfile);
7777
goto out;
@@ -110,8 +110,8 @@ download_binpkg(struct xbps_handle *xhp, xbps_dictionary_t repo_pkgd)
110110
xbps_dictionary_get_cstring_nocopy(repo_pkgd, "pkgver", &pkgver);
111111
xbps_dictionary_get_cstring_nocopy(repo_pkgd, "architecture", &arch);
112112

113-
snprintf(buf, sizeof buf, "%s/%s.%s.xbps.sig", repoloc, pkgver, arch);
114-
sigsuffix = buf+(strlen(buf)-sizeof (".sig")+1);
113+
snprintf(buf, sizeof buf, "%s/%s.%s.xbps.sig2", repoloc, pkgver, arch);
114+
sigsuffix = buf+(strlen(buf)-sizeof (".sig2")+1);
115115

116116
xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD, 0, pkgver,
117117
"Downloading `%s' signature (from `%s')...", pkgver, repoloc);
@@ -145,8 +145,8 @@ download_binpkg(struct xbps_handle *xhp, xbps_dictionary_t repo_pkgd)
145145
xbps_set_cb_state(xhp, XBPS_STATE_VERIFY, 0, pkgver,
146146
"%s: verifying RSA signature...", pkgver);
147147

148-
snprintf(buf, sizeof buf, "%s/%s.%s.xbps.sig", xhp->cachedir, pkgver, arch);
149-
sigsuffix = buf+(strlen(buf)-sizeof (".sig")+1);
148+
snprintf(buf, sizeof buf, "%s/%s.%s.xbps.sig2", xhp->cachedir, pkgver, arch);
149+
sigsuffix = buf+(strlen(buf)-sizeof (".sig2")+1);
150150

151151
if ((repo = xbps_rpool_get_repo(repoloc)) == NULL) {
152152
rv = errno;

lib/util.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,15 +405,15 @@ xbps_remote_binpkg_exists(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
405405
"architecture", &arch))
406406
return NULL;
407407

408-
snprintf(path, sizeof(path), "%s/%s.%s.xbps.sig", xhp->cachedir,
408+
snprintf(path, sizeof(path), "%s/%s.%s.xbps.sig2", xhp->cachedir,
409409
pkgver, arch);
410410

411411
/* check if the signature file exists */
412412
if (access(path, R_OK) != 0)
413413
return false;
414414

415-
/* strip the .sig suffix and check if binpkg file exists */
416-
path[strlen(path)-sizeof (".sig")+1] = '\0';
415+
/* strip the .sig2 suffix and check if binpkg file exists */
416+
path[strlen(path)-sizeof (".sig2")+1] = '\0';
417417

418418
return access(path, R_OK) == 0;
419419
}

lib/verifysig.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ rsa_verify_hash(struct xbps_repo *repo, xbps_data_t pubkey,
6363
return false;
6464
}
6565

66-
rv = RSA_verify(NID_sha1, sha256, SHA256_DIGEST_LENGTH, sig, siglen, rsa);
66+
rv = RSA_verify(NID_sha256, sha256, SHA256_DIGEST_LENGTH, sig, siglen, rsa);
6767
RSA_free(rsa);
6868
BIO_free(bio);
6969
ERR_free_strings();
@@ -144,7 +144,7 @@ xbps_verify_file_signature(struct xbps_repo *repo, const char *fname)
144144
return false;
145145
}
146146

147-
snprintf(sig, sizeof sig, "%s.sig", fname);
147+
snprintf(sig, sizeof sig, "%s.sig2", fname);
148148
val = xbps_verify_signature(repo, sig, digest);
149149

150150
return val;

0 commit comments

Comments
 (0)