1*0a6a1f1dSLionel Sambuc.\" $NetBSD: libnetpgpverify.3,v 1.3 2015/02/05 01:26:54 agc Exp $ 2*0a6a1f1dSLionel Sambuc.\" 3*0a6a1f1dSLionel Sambuc.\" Copyright (c) 2014 Alistair Crooks <agc@NetBSD.org> 4*0a6a1f1dSLionel Sambuc.\" All rights reserved. 5*0a6a1f1dSLionel Sambuc.\" 6*0a6a1f1dSLionel Sambuc.\" Redistribution and use in source and binary forms, with or without 7*0a6a1f1dSLionel Sambuc.\" modification, are permitted provided that the following conditions 8*0a6a1f1dSLionel Sambuc.\" are met: 9*0a6a1f1dSLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright 10*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer. 11*0a6a1f1dSLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright 12*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer in the 13*0a6a1f1dSLionel Sambuc.\" documentation and/or other materials provided with the distribution. 14*0a6a1f1dSLionel Sambuc.\" 15*0a6a1f1dSLionel Sambuc.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16*0a6a1f1dSLionel Sambuc.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17*0a6a1f1dSLionel Sambuc.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18*0a6a1f1dSLionel Sambuc.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19*0a6a1f1dSLionel Sambuc.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20*0a6a1f1dSLionel Sambuc.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21*0a6a1f1dSLionel Sambuc.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22*0a6a1f1dSLionel Sambuc.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23*0a6a1f1dSLionel Sambuc.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24*0a6a1f1dSLionel Sambuc.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25*0a6a1f1dSLionel Sambuc.\" 26*0a6a1f1dSLionel Sambuc.Dd January 15, 2015 27*0a6a1f1dSLionel Sambuc.Dt LIBNETPGPVERIFY 3 28*0a6a1f1dSLionel Sambuc.Os 29*0a6a1f1dSLionel Sambuc.Sh NAME 30*0a6a1f1dSLionel Sambuc.Nm libnetpgpverify 31*0a6a1f1dSLionel Sambuc.Nd library to verify digital signatures 32*0a6a1f1dSLionel Sambuc.Sh LIBRARY 33*0a6a1f1dSLionel Sambuc.Lb libnetpgpverify 34*0a6a1f1dSLionel Sambuc.Sh SYNOPSIS 35*0a6a1f1dSLionel Sambuc.In netpgp/verify.h 36*0a6a1f1dSLionel Sambuc.Ft int 37*0a6a1f1dSLionel Sambuc.Fo pgpv_read_pubring 38*0a6a1f1dSLionel Sambuc.Fa "pgpv_t *pgp" "const void *keyring" "ssize_t size" 39*0a6a1f1dSLionel Sambuc.Fc 40*0a6a1f1dSLionel Sambuc.Ft int 41*0a6a1f1dSLionel Sambuc.Fo pgpv_read_ssh_pubkeys 42*0a6a1f1dSLionel Sambuc.Fa "pgpv_t *pgp" "const void *keyring" "ssize_t size" 43*0a6a1f1dSLionel Sambuc.Fc 44*0a6a1f1dSLionel Sambuc.Ft size_t 45*0a6a1f1dSLionel Sambuc.Fo pgpv_verify 46*0a6a1f1dSLionel Sambuc.Fa "pgpv_cursor_t *cursor" "pgpv_t *pgp" "const void *ptr" "ssize_t size" 47*0a6a1f1dSLionel Sambuc.Fc 48*0a6a1f1dSLionel Sambuc.Ft size_t 49*0a6a1f1dSLionel Sambuc.Fo pgpv_get_verified 50*0a6a1f1dSLionel Sambuc.Fa "pgpv_cursor_t *cursor" "size_t cookie" "char **ret" 51*0a6a1f1dSLionel Sambuc.Fc 52*0a6a1f1dSLionel Sambuc.Ft size_t 53*0a6a1f1dSLionel Sambuc.Fo pgpv_get_cursor_element 54*0a6a1f1dSLionel Sambuc.Fa "pgpv_cursor_t *cursor" "size_t element" 55*0a6a1f1dSLionel Sambuc.Fc 56*0a6a1f1dSLionel Sambuc.Ft size_t 57*0a6a1f1dSLionel Sambuc.Fo pgpv_dump 58*0a6a1f1dSLionel Sambuc.Fa "pgpv_t *pgp" "char **data" 59*0a6a1f1dSLionel Sambuc.Fc 60*0a6a1f1dSLionel Sambuc.Ft size_t 61*0a6a1f1dSLionel Sambuc.Fo pgpv_get_entry 62*0a6a1f1dSLionel Sambuc.Fa "pgpv_t *pgp" "unsigned ent" "char **ret" "const char *modifiers" 63*0a6a1f1dSLionel Sambuc.Fc 64*0a6a1f1dSLionel Sambuc.Ft int 65*0a6a1f1dSLionel Sambuc.Fo pgpv_close 66*0a6a1f1dSLionel Sambuc.Fa "pgpv_t *pgp" 67*0a6a1f1dSLionel Sambuc.Fc 68*0a6a1f1dSLionel Sambuc.Sh DESCRIPTION 69*0a6a1f1dSLionel Sambuc.Nm 70*0a6a1f1dSLionel Sambucis a small library which will verify a digital signature on a text or 71*0a6a1f1dSLionel Sambucbinary document. 72*0a6a1f1dSLionel SambucIt has been kept deliberately small and only uses compression libraries 73*0a6a1f1dSLionel Sambucto function. 74*0a6a1f1dSLionel Sambuc.Pp 75*0a6a1f1dSLionel SambucPGP messages, including key rings, are made up of PGP packets, defined 76*0a6a1f1dSLionel Sambucin RFC 4880. 77*0a6a1f1dSLionel SambucTo match a digital signature, the public key of the signer must be 78*0a6a1f1dSLionel Sambuclocated in a public key ring. 79*0a6a1f1dSLionel SambucThis library has enough functionality to parse a pubkey keyring, 80*0a6a1f1dSLionel Sambucusing 81*0a6a1f1dSLionel Sambuc.Fn pgpv_read_pubring 82*0a6a1f1dSLionel Sambucto read the public keys of trusted identities, 83*0a6a1f1dSLionel Sambucand to read files or memory which has already been signed. 84*0a6a1f1dSLionel SambucSSH public keys can also be used for signature verification 85*0a6a1f1dSLionel Sambucby using the 86*0a6a1f1dSLionel Sambuc.Fn pgpv_read_ssh_pubkeys 87*0a6a1f1dSLionel Sambucfunction. 88*0a6a1f1dSLionel SambucPlease note that the creation date of the signature key 89*0a6a1f1dSLionel Sambucwill show up as January 1st 1970, due to the fact that the 90*0a6a1f1dSLionel Sambuccreation date of the key is not encoded anywhere for an ssh 91*0a6a1f1dSLionel Sambuckey, whilst it is an inherent part of the PGP fingerprint. 92*0a6a1f1dSLionel SambucIn order that the correct fingerprint is used, the key creation 93*0a6a1f1dSLionel Sambucdate is forced to 0. 94*0a6a1f1dSLionel Sambuc.Pp 95*0a6a1f1dSLionel SambucThe 96*0a6a1f1dSLionel Sambuc.Fn pgpv_verify 97*0a6a1f1dSLionel Sambucfunction is used to verify the signature, either on data, or on memory. 98*0a6a1f1dSLionel SambucTo signal to 99*0a6a1f1dSLionel Sambuc.Fn pgpv_verify 100*0a6a1f1dSLionel Sambucto read a file and verify it, the 101*0a6a1f1dSLionel Sambuc.Dv size 102*0a6a1f1dSLionel Sambucargument should be set to 103*0a6a1f1dSLionel Sambuc.Dv -1 104*0a6a1f1dSLionel Sambucwhilst a positive size signals that the pointer value should be that 105*0a6a1f1dSLionel Sambucof signed memory. 106*0a6a1f1dSLionel Sambuc.Fn pgpv_verify 107*0a6a1f1dSLionel Sambucreturns a cookie if the ignature was verified, or 0 if it did not. 108*0a6a1f1dSLionel SambucThis cookie can subsequently be used to retrieve the data which 109*0a6a1f1dSLionel Sambucwas verified. 110*0a6a1f1dSLionel Sambuc.Pp 111*0a6a1f1dSLionel SambucIf the signature does match, then the file or memory can be considered as being 112*0a6a1f1dSLionel Sambucverified as being unmodified and unchanged, integrally sound. 113*0a6a1f1dSLionel Sambuc.Pp 114*0a6a1f1dSLionel SambucSignatures have validity dates on them, and it is possible for a signature to 115*0a6a1f1dSLionel Sambuchave expired when it is being checked. 116*0a6a1f1dSLionel SambucIf for any reason the signature does not match, then the reason for not 117*0a6a1f1dSLionel Sambucverifying the signature will be stored in the 118*0a6a1f1dSLionel Sambuc.Dv why 119*0a6a1f1dSLionel Sambucbuffer in the 120*0a6a1f1dSLionel Sambuc.Dv pgpv_cursor_t 121*0a6a1f1dSLionel Sambucstructure. 122*0a6a1f1dSLionel Sambuc.Pp 123*0a6a1f1dSLionel SambucOccasionally, the memory or contents of the file which matched the signature 124*0a6a1f1dSLionel Sambucwill be needed, rather than a boolean value of whether it was verified. 125*0a6a1f1dSLionel SambucTo do this, the 126*0a6a1f1dSLionel Sambuc.Fn pgpv_get_verified 127*0a6a1f1dSLionel Sambucfunction is used. 128*0a6a1f1dSLionel SambucArguments to 129*0a6a1f1dSLionel Sambuc.Fn pgpv_get_verified 130*0a6a1f1dSLionel Sambucare the cookie returned from the verification, and a buffer 131*0a6a1f1dSLionel Sambucallocated for the returned data and its size. 132*0a6a1f1dSLionel SambucIf an error occurs, or the signature is not verified, a zero value is returned 133*0a6a1f1dSLionel Sambucfor the size. 134*0a6a1f1dSLionel Sambuc.Nm 135*0a6a1f1dSLionel Sambucstores the starts of the data of all verified matches, and so the entry 136*0a6a1f1dSLionel Sambucnumber argument is the index of the occurrence of verification. 137*0a6a1f1dSLionel SambucThe first match will have an entry number of 0, the second 1, and so on. 138*0a6a1f1dSLionel Sambuc.Pp 139*0a6a1f1dSLionel SambucThe 140*0a6a1f1dSLionel Sambuc.Fn pgpv_close 141*0a6a1f1dSLionel Sambucfunction is used to clean up after all matching and verification has taken place. 142*0a6a1f1dSLionel SambucIt frees and de-allocates all resources used in the verification of the signature. 143*0a6a1f1dSLionel Sambuc.Pp 144*0a6a1f1dSLionel SambucThe program used for signing may encode into base64 encoding, and it may also 145*0a6a1f1dSLionel Sambucuse embedded compression to make the output smaller than it would otherwise be. 146*0a6a1f1dSLionel SambucThis is handled automatically by 147*0a6a1f1dSLionel Sambuc.Nm 148*0a6a1f1dSLionel Sambuc.Sh SEE ALSO 149*0a6a1f1dSLionel Sambuc.Xr bn 3 , 150*0a6a1f1dSLionel Sambuc.\" .Xr bzlib2 3 , 151*0a6a1f1dSLionel Sambuc.Xr zlib 3 152*0a6a1f1dSLionel Sambuc.Sh STANDARDS 153*0a6a1f1dSLionel SambucThe 154*0a6a1f1dSLionel Sambuc.Nm 155*0a6a1f1dSLionel Sambucutility is designed to conform to IETF RFC 4880. 156*0a6a1f1dSLionel Sambuc.Sh HISTORY 157*0a6a1f1dSLionel SambucThe 158*0a6a1f1dSLionel Sambuc.Nm 159*0a6a1f1dSLionel Sambuclibrary first appeared in 160*0a6a1f1dSLionel Sambuc.Nx 7.0 . 161*0a6a1f1dSLionel Sambuc.Sh AUTHORS 162*0a6a1f1dSLionel Sambuc.An Alistair Crooks Aq Mt agc@NetBSD.org 163