1.\" $NetBSD: libnetpgpverify.3,v 1.1 2014/03/09 00:15:45 agc Exp $ 2.\" 3.\" Copyright (c) 2014 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 netpgpverify.h 36.Ft int 37.Fo pgpv_read_pubring 38.Fa "pgpv_t *pgp" "const void *keyring" "ssize_t size" 39.Fc 40.Ft int 41.Fo pgpv_read_ssh_pubkeys 42.Fa "pgpv_t *pgp" "const void *keyring" "ssize_t size" 43.Fc 44.Ft size_t 45.Fo pgpv_verify 46.Fa "pgpv_cursor_t *cursor" "pgpv_t *pgp" "const void *ptr" "ssize_t size" 47.Fc 48.Ft size_t 49.Fo pgpv_get_verified 50.Fa "pgpv_cursor_t *cursor" "size_t cookie " "char **ret" 51.Fc 52.Ft size_t 53.Fo pgpv_get_entry 54.Fa "pgpv_t *pgp" "unsigned ent" "char **ret" 55.Fc 56.Ft int 57.Fo pgpv_close 58.Fa "pgpv_t *pgp" 59.Fc 60.Sh DESCRIPTION 61.Nm 62is a small library which will verify a digital signature on a text or 63binary document. 64It has been kept deliberately small and only uses compression libraries 65to function. 66.Pp 67PGP messages, including key rings, are made up of PGP packets, defined 68in RFC 4880. 69To match a digital signature, the public key of the signer must be 70located in a public key ring. 71This library has enough functionality to parse a pubkey keyring, 72using 73.Fn pgpv_read_pubring 74to read the public keys of trusted identities, 75and to read files or memory which has already been signed. 76SSH public keys can also be used for signature verification 77by using the 78.Fn pgpv_read_ssh_pubkeys 79function. 80Please note that the creation date of the signature key 81will show up as January 1st 1970, due to the fact that the 82creation date of the key is not encoded anywhere for an ssh 83key, whilst it is an inherent part of the PGP fingerprint. 84In order that the correct fingerprint is used, the key creation 85date is forced to 0. 86.Pp 87The 88.Fn pgpv_verify 89function is used to verify the signature, either on data, or on memory. 90To signal to 91.Fn pgpv_verify 92to read a file and verify it, the 93.Dv size 94argument should be set to 95.Dv -1 96whilst a positive size signals that the pointer value should be that 97of signed memory. 98.Fn pgpv_verify 99returns a cookie if the ignature was verified, or 0 if it did not. 100This cookie can subsequently be used to retrieve the data which 101was verified. 102.Pp 103If the signature does match, then the file or memory can be considered as being 104verified as being unmodified and unchanged, integrally sound. 105.Pp 106Signatures have validity dates on them, and it is possible for a signature to 107have expired when it is being checked. 108If for any reason the signature does not match, then the reason for not 109verifying the signature will be stored in the 110.Dv why 111buffer in the 112.Dv pgpv_cursor_t 113structure. 114.Pp 115Occasionally, the memory or contents of the file which matched the signature 116will be needed, rather than a boolean value of whether it was verified. 117To do this, the 118.Fn pgpv_get_verified 119function is used. 120Arguments to 121.Fn pgpv_get_verified 122are the cookie returned from the verification, and a buffer 123allocated for the returned data and its size. 124If an error occurs, or the signature is not verified, a zero value is returned 125for the size. 126.Nm 127stores the starts of the data of all verified matches, and so the entry 128number argument is the index of the occurrence of verification. 129The first match will have an entry number of 0, the second 1, and so on. 130.Pp 131The 132.Fn pgpv_close 133function is used to clean up after all matching and verification has taken place. 134It frees and de-allocates all resources used in the verification of the signature. 135.Pp 136The program used for signing may encode into base64 encoding, and it may also 137use embedded compression to make the output smaller than it would otherwise be. 138This is handled automatically by 139.Nm 140.Sh SEE ALSO 141.Xr bn 3 , 142.\" .Xr bzlib2 3 , 143.Xr zlib 3 144.Sh STANDARDS 145The 146.Nm 147utility is designed to conform to IETF RFC 4880. 148.Sh HISTORY 149The 150.Nm 151library first appeared in 152.Nx 7.0 . 153.Sh AUTHORS 154.An Alistair Crooks Aq Mt agc@NetBSD.org 155