1.\" $NetBSD: libnetpgpverify.3,v 1.6 2014/02/17 07:23:18 agc Exp $ 2.\" 3.\" Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org> 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25.\" 26.Dd February 16, 2014 27.Dt LIBNETPGPVERIFY 3 28.Os 29.Sh NAME 30.Nm libnetpgpverify 31.Nd library to verify digital signatures 32.Sh LIBRARY 33.Lb libnetpgpverify 34.Sh SYNOPSIS 35.In netpgp/verify.h 36.Ft int 37.Fo pgpv_read_pubring 38.Fa "pgpv_t *pgp" "const void *keyring" "ssize_t size" 39.Fc 40.Ft size_t 41.Fo pgpv_verify 42.Fa "pgpv_cursor_t *cursor" "pgpv_t *pgp" "const void *ptr" "ssize_t size" 43.Fc 44.Ft size_t 45.Fo pgpv_get_verified 46.Fa "pgpv_cursor_t *cursor" "size_t cookie" "char **ret" 47.Fc 48.Ft size_t 49.Fo pgpv_get_entry 50.Fa "pgpv_t *pgp" "unsigned ent" "char **ret" 51.Fc 52.Ft int 53.Fo pgpv_close 54.Fa "pgpv_t *pgp" 55.Fc 56.Sh DESCRIPTION 57.Nm 58is a small library which will verify a digital signature on a text or 59binary document. 60It has been kept deliberately small and only uses compression libraries 61to function. 62.Pp 63PGP messages, including key rings, are made up of PGP packets, defined 64in RFC 4880. 65To match a digital signature, the public key of the signer must be 66located in a public key ring. 67This library has enough functionality to parse a pubkey keyring, 68using 69.Fn pgpv_read_pubring 70to read the public keys of trusted identities, 71and to read files or memory which has already been signed. 72The 73.Fn pgpv_verify 74function is used to verify the signature, either on data, or on memory. 75To signal to 76.Fn pgpv_verify 77to read a file and verify it, the 78.Dv size 79argument should be set to 80.Dv -1 81whilst a positive size signals that the pointer value should be that 82of signed memory. 83.Fn pgpv_verify 84returns a cookie if the ignature was verified, or 0 if it did not. 85This cookie can subsequently be used to retrieve the data which 86was verified. 87.Pp 88If the signature does match, then the file or memory can be considered as being 89verified as being unmodified and unchanged, integrally sound. 90.Pp 91Signatures have validity dates on them, and it is possible for a signature to 92have expired when it is being checked. 93If for any reason the signature does not match, then the reason for not 94verifying the signature will be stored in the 95.Dv why 96buffer in the 97.Dv pgpv_cursor_t 98structure. 99.Pp 100Occasionally, the memory or contents of the file which matched the signature 101will be needed, rather than a boolean value of whether it was verified. 102To do this, the 103.Fn pgpv_get_verified 104function is used. 105Arguments to 106.Fn pgpv_get_verified 107are the cookie returned from the verification, and a buffer 108allocated for the returned data and its size. 109If an error occurs, or the signature is not verified, a zero value is returned 110for the size. 111.Nm 112stores the starts of the data of all verified matches, and so the entry 113number argument is the index of the occurrence of verification. 114The first match will have an entry number of 0, the second 1, and so on. 115.Pp 116The 117.Fn pgpv_close 118function is used to clean up after all matching and verification has taken place. 119It frees and de-allocates all resources used in the verification of the signature. 120.Pp 121The program used for signing may encode into base64 encoding, and it may also 122use embedded compression to make the output smaller than it would otherwise be. 123This is handled automatically by 124.Nm . 125.Sh SEE ALSO 126.Xr bn 3 , 127.\" .Xr bzlib2 3 , 128.Xr zlib 3 129.Sh STANDARDS 130.Rs 131.%A J. Callas 132.%A L. Donnerhacke 133.%A H. Finney 134.%A D. Shaw 135.%A R. Thayer 136.%D November 2007 137.%R RFC 4880 138.%T OpenPGP Message Format 139.Re 140.Sh HISTORY 141The 142.Nm 143library first appeared in 144.Nx 7.0 . 145.Sh AUTHORS 146.An Alistair Crooks Aq Mt agc@NetBSD.org 147