Skip to content

Commit 5cf0c65

Browse files
committed
Merge pull request #3764 from lucab/lucab/to-upstream/pull-3
Use gpgv for signature verification in cargo
2 parents f5e71f5 + 01aaeef commit 5cf0c65

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed

src/cargo/cargo.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,20 +1162,20 @@ fn sync_one_file(c: &Cargo, dir: &Path, src: @Source) -> bool {
11621162
}
11631163
match (src.key, src.keyfp) {
11641164
(Some(_), Some(f)) => {
1165-
let r = pgp::verify(&c.root, &pkgfile, &sigfile, f);
1165+
let r = pgp::verify(&c.root, &pkgfile, &sigfile);
11661166

11671167
if !r {
1168-
error(fmt!("signature verification failed for source %s",
1169-
name));
1168+
error(fmt!("signature verification failed for source %s with key %s",
1169+
name, f));
11701170
return false;
11711171
}
11721172

11731173
if has_src_file {
1174-
let e = pgp::verify(&c.root, &srcfile, &srcsigfile, f);
1174+
let e = pgp::verify(&c.root, &srcfile, &srcsigfile);
11751175

11761176
if !e {
1177-
error(fmt!("signature verification failed for source %s",
1178-
name));
1177+
error(fmt!("signature verification failed for source %s with key %s",
1178+
name, f));
11791179
return false;
11801180
}
11811181
}
@@ -1273,21 +1273,21 @@ fn sync_one_git(c: &Cargo, dir: &Path, src: @Source) -> bool {
12731273
}
12741274
match (src.key, src.keyfp) {
12751275
(Some(_), Some(f)) => {
1276-
let r = pgp::verify(&c.root, &pkgfile, &sigfile, f);
1276+
let r = pgp::verify(&c.root, &pkgfile, &sigfile);
12771277

12781278
if !r {
1279-
error(fmt!("signature verification failed for source %s",
1280-
name));
1279+
error(fmt!("signature verification failed for source %s with key %s",
1280+
name, f));
12811281
rollback(name, dir, false);
12821282
return false;
12831283
}
12841284

12851285
if has_src_file {
1286-
let e = pgp::verify(&c.root, &srcfile, &srcsigfile, f);
1286+
let e = pgp::verify(&c.root, &srcfile, &srcsigfile);
12871287

12881288
if !e {
1289-
error(fmt!("signature verification failed for source %s",
1290-
name));
1289+
error(fmt!("signature verification failed for source %s with key %s",
1290+
name, f));
12911291
rollback(name, dir, false);
12921292
return false;
12931293
}
@@ -1370,11 +1370,11 @@ fn sync_one_curl(c: &Cargo, dir: &Path, src: @Source) -> bool {
13701370
return false;
13711371
}
13721372

1373-
let r = pgp::verify(&c.root, &pkgfile, &sigfile, f);
1373+
let r = pgp::verify(&c.root, &pkgfile, &sigfile);
13741374

13751375
if !r {
1376-
error(fmt!("signature verification failed for source %s",
1377-
name));
1376+
error(fmt!("signature verification failed for source %s with key %s",
1377+
name, f));
13781378
return false;
13791379
}
13801380

@@ -1390,11 +1390,11 @@ fn sync_one_curl(c: &Cargo, dir: &Path, src: @Source) -> bool {
13901390
return false;
13911391
}
13921392

1393-
let e = pgp::verify(&c.root, &srcfile, &srcsigfile, f);
1393+
let e = pgp::verify(&c.root, &srcfile, &srcsigfile);
13941394

13951395
if !e {
13961396
error(~"signature verification failed for " +
1397-
~"source " + name);
1397+
~"source " + name + ~" with key " + f);
13981398
return false;
13991399
}
14001400
}
@@ -1463,8 +1463,7 @@ fn cmd_init(c: &Cargo) {
14631463
return;
14641464
}
14651465

1466-
let r = pgp::verify(&c.root, &srcfile, &sigfile,
1467-
pgp::signing_key_fp());
1466+
let r = pgp::verify(&c.root, &srcfile, &sigfile);
14681467
if !r {
14691468
error(fmt!("signature verification failed for '%s'",
14701469
srcfile.to_str()));

src/cargo/pgp.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
fn gpg(args: ~[~str]) -> { status: int, out: ~str, err: ~str } {
2-
return run::program_output(~"gpg", args);
1+
fn gpgv(args: ~[~str]) -> { status: int, out: ~str, err: ~str } {
2+
return run::program_output(~"gpgv", args);
33
}
44

55
fn signing_key() -> ~str {
@@ -59,7 +59,7 @@ fn signing_key_fp() -> ~str {
5959
}
6060

6161
fn supported() -> bool {
62-
let r = gpg(~[~"--version"]);
62+
let r = gpgv(~[~"--version"]);
6363
r.status == 0
6464
}
6565

@@ -88,15 +88,14 @@ fn add(root: &Path, key: &Path) {
8888
}
8989
}
9090
91-
fn verify(root: &Path, data: &Path, sig: &Path, keyfp: ~str) -> bool {
91+
fn verify(root: &Path, data: &Path, sig: &Path) -> bool {
9292
let path = root.push("gpg");
93-
let p = gpg(~[~"--homedir", path.to_str(),
94-
~"--with-fingerprint",
95-
~"--verify", sig.to_str(),
96-
data.to_str()]);
97-
let res = ~"Primary key fingerprint: " + keyfp;
98-
for str::split_char_each(p.err, '\n') |line| {
99-
if line == res { return true; }
93+
let res = gpgv(~[~"--homedir", path.to_str(),
94+
~"--keyring", ~"pubring.gpg",
95+
~"--verbose",
96+
sig.to_str(), data.to_str()]);
97+
if res.status != 0 {
98+
return false;
10099
}
101-
return false;
100+
return true;
102101
}

0 commit comments

Comments
 (0)