Tue Feb 23 01:24:45 2010 UTC ()
fix a bug in verifying memory.

add two examples to the netpgp(1) manual page outlining how to sign
and encrypt via a pipeline, and how to decrypt and verify/cat using a
pipeline.


(agc)
diff -r1.39 -r1.40 src/crypto/external/bsd/netpgp/dist/src/lib/netpgp.c
diff -r1.29 -r1.30 src/crypto/external/bsd/netpgp/dist/src/lib/validate.c
diff -r1.7 -r1.8 src/crypto/external/bsd/netpgp/dist/src/netpgp/netpgp.1

cvs diff -r1.39 -r1.40 src/crypto/external/bsd/netpgp/dist/src/lib/netpgp.c (expand / switch to unified diff)

--- src/crypto/external/bsd/netpgp/dist/src/lib/netpgp.c 2010/02/12 03:38:48 1.39
+++ src/crypto/external/bsd/netpgp/dist/src/lib/netpgp.c 2010/02/23 01:24:44 1.40
@@ -24,27 +24,27 @@ @@ -24,27 +24,27 @@
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE. 27 * POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29#include "config.h" 29#include "config.h"
30 30
31#ifdef HAVE_SYS_CDEFS_H 31#ifdef HAVE_SYS_CDEFS_H
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#endif 33#endif
34 34
35#if defined(__NetBSD__) 35#if defined(__NetBSD__)
36__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved."); 36__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
37__RCSID("$NetBSD: netpgp.c,v 1.39 2010/02/12 03:38:48 agc Exp $"); 37__RCSID("$NetBSD: netpgp.c,v 1.40 2010/02/23 01:24:44 agc Exp $");
38#endif 38#endif
39 39
40#include <sys/types.h> 40#include <sys/types.h>
41#include <sys/stat.h> 41#include <sys/stat.h>
42#include <sys/param.h> 42#include <sys/param.h>
43#include <sys/mman.h> 43#include <sys/mman.h>
44 44
45#ifdef HAVE_SYS_RESOURCE_H 45#ifdef HAVE_SYS_RESOURCE_H
46#include <sys/resource.h> 46#include <sys/resource.h>
47#endif 47#endif
48 48
49#ifdef HAVE_FCNTL_H 49#ifdef HAVE_FCNTL_H
50#include <fcntl.h> 50#include <fcntl.h>
@@ -1004,26 +1004,29 @@ netpgp_verify_memory(netpgp_t *netpgp, c @@ -1004,26 +1004,29 @@ netpgp_verify_memory(netpgp_t *netpgp, c
1004 __ops_io_t *io; 1004 __ops_io_t *io;
1005 size_t m; 1005 size_t m;
1006 int ret; 1006 int ret;
1007 1007
1008 (void) memset(&result, 0x0, sizeof(result)); 1008 (void) memset(&result, 0x0, sizeof(result));
1009 io = netpgp->io; 1009 io = netpgp->io;
1010 if (in == NULL) { 1010 if (in == NULL) {
1011 (void) fprintf(io->errs, 1011 (void) fprintf(io->errs,
1012 "netpgp_verify_memory: no memory to verify\n"); 1012 "netpgp_verify_memory: no memory to verify\n");
1013 return 0; 1013 return 0;
1014 } 1014 }
1015 signedmem = __ops_memory_new(); 1015 signedmem = __ops_memory_new();
1016 __ops_memory_add(signedmem, in, size); 1016 __ops_memory_add(signedmem, in, size);
 1017 if (out) {
 1018 cat = __ops_memory_new();
 1019 }
1017 ret = __ops_validate_mem(io, &result, signedmem, 1020 ret = __ops_validate_mem(io, &result, signedmem,
1018 (out) ? &cat : NULL, 1021 (out) ? &cat : NULL,
1019 armored, netpgp->pubring); 1022 armored, netpgp->pubring);
1020 __ops_memory_free(signedmem); 1023 __ops_memory_free(signedmem);
1021 if (ret) { 1024 if (ret) {
1022 resultp(io, "<stdin>", &result, netpgp->pubring); 1025 resultp(io, "<stdin>", &result, netpgp->pubring);
1023 if (out) { 1026 if (out) {
1024 m = MIN(__ops_mem_len(cat), outsize); 1027 m = MIN(__ops_mem_len(cat), outsize);
1025 (void) memcpy(out, __ops_mem_data(cat), m); 1028 (void) memcpy(out, __ops_mem_data(cat), m);
1026 __ops_memory_free(cat); 1029 __ops_memory_free(cat);
1027 } else { 1030 } else {
1028 m = 1; 1031 m = 1;
1029 } 1032 }

cvs diff -r1.29 -r1.30 src/crypto/external/bsd/netpgp/dist/src/lib/validate.c (expand / switch to unified diff)

--- src/crypto/external/bsd/netpgp/dist/src/lib/validate.c 2010/02/12 03:38:48 1.29
+++ src/crypto/external/bsd/netpgp/dist/src/lib/validate.c 2010/02/23 01:24:44 1.30
@@ -44,27 +44,27 @@ @@ -44,27 +44,27 @@
44 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 44 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45 * 45 *
46 * See the License for the specific language governing permissions and 46 * See the License for the specific language governing permissions and
47 * limitations under the License. 47 * limitations under the License.
48 */ 48 */
49#include "config.h" 49#include "config.h"
50 50
51#ifdef HAVE_SYS_CDEFS_H 51#ifdef HAVE_SYS_CDEFS_H
52#include <sys/cdefs.h> 52#include <sys/cdefs.h>
53#endif 53#endif
54 54
55#if defined(__NetBSD__) 55#if defined(__NetBSD__)
56__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved."); 56__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
57__RCSID("$NetBSD: validate.c,v 1.29 2010/02/12 03:38:48 agc Exp $"); 57__RCSID("$NetBSD: validate.c,v 1.30 2010/02/23 01:24:44 agc Exp $");
58#endif 58#endif
59 59
60#include <sys/types.h> 60#include <sys/types.h>
61#include <sys/param.h> 61#include <sys/param.h>
62#include <sys/stat.h> 62#include <sys/stat.h>
63 63
64#include <string.h> 64#include <string.h>
65#include <stdio.h> 65#include <stdio.h>
66 66
67#ifdef HAVE_UNISTD_H 67#ifdef HAVE_UNISTD_H
68#include <unistd.h> 68#include <unistd.h>
69#endif 69#endif
70 70
@@ -939,22 +939,22 @@ __ops_validate_mem(__ops_io_t *io, @@ -939,22 +939,22 @@ __ops_validate_mem(__ops_io_t *io,
939 __ops_reader_push_dearmour(stream); 939 __ops_reader_push_dearmour(stream);
940 } 940 }
941 941
942 /* Do the verification */ 942 /* Do the verification */
943 __ops_parse(stream, !printerrors); 943 __ops_parse(stream, !printerrors);
944 944
945 /* Tidy up */ 945 /* Tidy up */
946 if (armoured) { 946 if (armoured) {
947 __ops_reader_pop_dearmour(stream); 947 __ops_reader_pop_dearmour(stream);
948 } 948 }
949 __ops_teardown_memory_read(stream, mem); 949 __ops_teardown_memory_read(stream, mem);
950 950
951 /* this is triggered only for --cat output */ 951 /* this is triggered only for --cat output */
952 if (*cat) { 952 if (cat) {
953 /* need to send validated output somewhere */ 953 /* need to send validated output somewhere */
954 *cat = validation.mem; 954 *cat = validation.mem;
955 } else { 955 } else {
956 __ops_memory_free(validation.mem); 956 __ops_memory_free(validation.mem);
957 } 957 }
958 958
959 return validate_result_status(io->errs, NULL, result); 959 return validate_result_status(io->errs, NULL, result);
960} 960}

cvs diff -r1.7 -r1.8 src/crypto/external/bsd/netpgp/dist/src/netpgp/netpgp.1 (expand / switch to unified diff)

--- src/crypto/external/bsd/netpgp/dist/src/netpgp/netpgp.1 2010/02/06 02:24:34 1.7
+++ src/crypto/external/bsd/netpgp/dist/src/netpgp/netpgp.1 2010/02/23 01:24:45 1.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: netpgp.1,v 1.7 2010/02/06 02:24:34 agc Exp $ 1.\" $NetBSD: netpgp.1,v 1.8 2010/02/23 01:24:45 agc Exp $
2.\" 2.\"
3.\" Copyright (c) 2009 The NetBSD Foundation, Inc. 3.\" Copyright (c) 2009 The NetBSD Foundation, Inc.
4.\" All rights reserved. 4.\" All rights reserved.
5.\" 5.\"
6.\" This manual page is derived from software contributed to 6.\" This manual page is derived from software contributed to
7.\" The NetBSD Foundation by Alistair Crooks (agc@NetBSD.org). 7.\" The NetBSD Foundation by Alistair Crooks (agc@NetBSD.org).
8.\" 8.\"
9.\" Redistribution and use in source and binary forms, with or without 9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions 10.\" modification, are permitted provided that the following conditions
11.\" are met: 11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright 12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer. 13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" 2. Redistributions in binary form must reproduce the above copyright
@@ -396,48 +396,89 @@ and displayed on standard output: @@ -396,48 +396,89 @@ and displayed on standard output:
396.Bd -literal 396.Bd -literal
397% netpgp --encrypt \*[Lt] a | netpgp --decrypt \*[Gt] b 397% netpgp --encrypt \*[Lt] a | netpgp --decrypt \*[Gt] b
398netpgp: default key set to "C0596823" 398netpgp: default key set to "C0596823"
399netpgp: default key set to "C0596823" 399netpgp: default key set to "C0596823"
400pub 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12 400pub 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12
401Key fingerprint: d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823 401Key fingerprint: d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823
402uid Alistair Crooks \*[Lt]agc@netbsd.org\*[Gt] 402uid Alistair Crooks \*[Lt]agc@netbsd.org\*[Gt]
403uid Alistair Crooks \*[Lt]agc@pkgsrc.org\*[Gt] 403uid Alistair Crooks \*[Lt]agc@pkgsrc.org\*[Gt]
404uid Alistair Crooks \*[Lt]agc@alistaircrooks.com\*[Gt] 404uid Alistair Crooks \*[Lt]agc@alistaircrooks.com\*[Gt]
405uid Alistair Crooks \*[Lt]alistair@hockley-crooks.com\*[Gt] 405uid Alistair Crooks \*[Lt]alistair@hockley-crooks.com\*[Gt]
406netpgp passphrase: 406netpgp passphrase:
407% 407%
408.Ed 408.Ed
 409.Pp
 410This simple (and contrived) example shows that
 411.Nm
 412commands can be used together in a pipeline to produce the desired effect.
409.Bd -literal 413.Bd -literal
410% netpgp --sign \*[Lt] a | netpgp --cat \*[Gt] b  414% netpgp --sign \*[Lt] a | netpgp --cat \*[Gt] b
411netpgp: default key set to "C0596823" 415netpgp: default key set to "C0596823"
412netpgp: default key set to "C0596823" 416netpgp: default key set to "C0596823"
413pub 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12 417pub 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12
414Key fingerprint: d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823  418Key fingerprint: d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823
415uid Alistair Crooks \*[Lt]agc@netbsd.org\*[Gt] 419uid Alistair Crooks \*[Lt]agc@netbsd.org\*[Gt]
416uid Alistair Crooks \*[Lt]agc@pkgsrc.org\*[Gt] 420uid Alistair Crooks \*[Lt]agc@pkgsrc.org\*[Gt]
417uid Alistair Crooks \*[Lt]agc@alistaircrooks.com\*[Gt] 421uid Alistair Crooks \*[Lt]agc@alistaircrooks.com\*[Gt]
418uid Alistair Crooks \*[Lt]alistair@hockley-crooks.com\*[Gt] 422uid Alistair Crooks \*[Lt]alistair@hockley-crooks.com\*[Gt]
419netpgp passphrase:  423netpgp passphrase:
420Good signature for \*[Lt]stdin\*[Gt] made Mon Dec 21 18:25:02 2009 424Good signature for \*[Lt]stdin\*[Gt] made Mon Dec 21 18:25:02 2009
421using RSA (Encrypt or Sign) key 1b68dcfcc0596823 425using RSA (Encrypt or Sign) key 1b68dcfcc0596823
422pub 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12 426pub 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12
423Key fingerprint: d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823  427Key fingerprint: d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823
424uid Alistair Crooks \*[Lt]alistair@hockley-crooks.com\*[Gt] 428uid Alistair Crooks \*[Lt]alistair@hockley-crooks.com\*[Gt]
425uid Alistair Crooks \*[Lt]agc@pkgsrc.org\*[Gt] 429uid Alistair Crooks \*[Lt]agc@pkgsrc.org\*[Gt]
426uid Alistair Crooks \*[Lt]agc@netbsd.org\*[Gt] 430uid Alistair Crooks \*[Lt]agc@netbsd.org\*[Gt]
427uid Alistair Crooks \*[Lt]agc@alistaircrooks.com\*[Gt] 431uid Alistair Crooks \*[Lt]agc@alistaircrooks.com\*[Gt]
428uid Alistair Crooks (Yahoo!) \*[Lt]agcrooks@yahoo-inc.com\*[Gt] 432uid Alistair Crooks (Yahoo!) \*[Lt]agcrooks@yahoo-inc.com\*[Gt]
429% 433%
430.Ed 434.Ed
 435.Pp
 436For operations like signing and encrypting a file at the same time,
 437the best way is to make use of pipelines:
 438.Bd -literal
 439% netpgp --sign \*[Lt] example | netpgp --encrypt --userid=c0596823 \*[Gt] example.gpg
 440netpgp: default key set to "C0596823"
 441pub 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12
 442Key fingerprint: d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823
 443uid Alistair Crooks \*[Lt]alistair@hockley-crooks.com\*[Gt]
 444uid Alistair Crooks \*[Lt]agc@pkgsrc.org\*[Gt]
 445uid Alistair Crooks \*[Lt]agc@netbsd.org\*[Gt]
 446uid Alistair Crooks \*[Lt]agc@alistaircrooks.com\*[Gt]
 447uid Alistair Crooks (Yahoo!) \*[Lt]agcrooks@yahoo-inc.com\*[Gt]
 448netpgp passphrase:
 449% netpgp --decrypt \*[Lt] example.gpg | netpgp --cat
 450netpgp: default key set to "C0596823"
 451netpgp: default key set to "C0596823"
 452pub 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12
 453Key fingerprint: d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823
 454uid Alistair Crooks \*[Lt]alistair@hockley-crooks.com\*[Gt]
 455uid Alistair Crooks \*[Lt]agc@pkgsrc.org\*[Gt]
 456uid Alistair Crooks \*[Lt]agc@netbsd.org\*[Gt]
 457uid Alistair Crooks \*[Lt]agc@alistaircrooks.com\*[Gt]
 458uid Alistair Crooks (Yahoo!) \*[Lt]agcrooks@yahoo-inc.com\*[Gt]
 459netpgp passphrase:
 460Good signature for \*[Lt]stdin\*[Gt] made Mon Feb 22 07:21:19 2010
 461using RSA (Encrypt or Sign) key 1b68dcfcc0596823
 462pub 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12
 463Key fingerprint: d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823
 464uid Alistair Crooks \*[Lt]alistair@hockley-crooks.com\*[Gt]
 465uid Alistair Crooks \*[Lt]agc@pkgsrc.org\*[Gt]
 466uid Alistair Crooks \*[Lt]agc@netbsd.org\*[Gt]
 467uid Alistair Crooks \*[Lt]agc@alistaircrooks.com\*[Gt]
 468uid Alistair Crooks (Yahoo!) \*[Lt]agcrooks@yahoo-inc.com\*[Gt]
 469...contents of original file...
 470%
 471.Ed
431.Sh RETURN VALUES 472.Sh RETURN VALUES
432The 473The
433.Nm 474.Nm
434utility will return 0 for success, 475utility will return 0 for success,
4351 if the file's signature does not match what was expected, 4761 if the file's signature does not match what was expected,
436or 2 if any other error occurs. 477or 2 if any other error occurs.
437.Sh SEE ALSO 478.Sh SEE ALSO
438.Xr netpgpkeys 1 , 479.Xr netpgpkeys 1 ,
439.Xr ssh 1 , 480.Xr ssh 1 ,
440.Xr getpass 3 , 481.Xr getpass 3 ,
441.\" .Xr libbz2 3 , 482.\" .Xr libbz2 3 ,
442.Xr libnetpgp 3 , 483.Xr libnetpgp 3 ,
443.Xr ssl 3 , 484.Xr ssl 3 ,