1*32d959bfSagc.\" $NetBSD: libnetpgpverify.3,v 1.4 2017/04/17 19:50:28 agc Exp $ 225f78d91Sagc.\" 3*32d959bfSagc.\" Copyright (c) 2014,2015,2016 Alistair Crooks <agc@NetBSD.org> 425f78d91Sagc.\" All rights reserved. 525f78d91Sagc.\" 625f78d91Sagc.\" Redistribution and use in source and binary forms, with or without 725f78d91Sagc.\" modification, are permitted provided that the following conditions 825f78d91Sagc.\" are met: 925f78d91Sagc.\" 1. Redistributions of source code must retain the above copyright 1025f78d91Sagc.\" notice, this list of conditions and the following disclaimer. 1125f78d91Sagc.\" 2. Redistributions in binary form must reproduce the above copyright 1225f78d91Sagc.\" notice, this list of conditions and the following disclaimer in the 1325f78d91Sagc.\" documentation and/or other materials provided with the distribution. 1425f78d91Sagc.\" 1525f78d91Sagc.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1625f78d91Sagc.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1725f78d91Sagc.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1825f78d91Sagc.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1925f78d91Sagc.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2025f78d91Sagc.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2125f78d91Sagc.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2225f78d91Sagc.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2325f78d91Sagc.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2425f78d91Sagc.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2525f78d91Sagc.\" 26*32d959bfSagc.Dd June 26, 2016 2725f78d91Sagc.Dt LIBNETPGPVERIFY 3 2825f78d91Sagc.Os 2925f78d91Sagc.Sh NAME 3025f78d91Sagc.Nm libnetpgpverify 3125f78d91Sagc.Nd library to verify digital signatures 3225f78d91Sagc.Sh LIBRARY 3325f78d91Sagc.Lb libnetpgpverify 3425f78d91Sagc.Sh SYNOPSIS 35955e2bfdSagc.In netpgp/verify.h 3625f78d91Sagc.Ft int 37*32d959bfSagc.Fo pgpv_new 38*32d959bfSagc.Fa "void" 39*32d959bfSagc.Fc 40*32d959bfSagc.Ft int 41*32d959bfSagc.Fo pgpv_new_cursor 42*32d959bfSagc.Fa "void" 43*32d959bfSagc.Fc 44*32d959bfSagc.Ft int 4525f78d91Sagc.Fo pgpv_read_pubring 4625f78d91Sagc.Fa "pgpv_t *pgp" "const void *keyring" "ssize_t size" 4725f78d91Sagc.Fc 4825f78d91Sagc.Ft int 4925f78d91Sagc.Fo pgpv_read_ssh_pubkeys 5025f78d91Sagc.Fa "pgpv_t *pgp" "const void *keyring" "ssize_t size" 5125f78d91Sagc.Fc 5225f78d91Sagc.Ft size_t 5325f78d91Sagc.Fo pgpv_verify 5425f78d91Sagc.Fa "pgpv_cursor_t *cursor" "pgpv_t *pgp" "const void *ptr" "ssize_t size" 5525f78d91Sagc.Fc 5625f78d91Sagc.Ft size_t 5725f78d91Sagc.Fo pgpv_get_verified 5825f78d91Sagc.Fa "pgpv_cursor_t *cursor" "size_t cookie" "char **ret" 5925f78d91Sagc.Fc 6025f78d91Sagc.Ft size_t 61955e2bfdSagc.Fo pgpv_get_cursor_element 62955e2bfdSagc.Fa "pgpv_cursor_t *cursor" "size_t element" 63955e2bfdSagc.Fc 64955e2bfdSagc.Ft size_t 65530ddfcbSagc.Fo pgpv_dump 66530ddfcbSagc.Fa "pgpv_t *pgp" "char **data" 67530ddfcbSagc.Fc 68530ddfcbSagc.Ft size_t 6925f78d91Sagc.Fo pgpv_get_entry 70955e2bfdSagc.Fa "pgpv_t *pgp" "unsigned ent" "char **ret" "const char *modifiers" 7125f78d91Sagc.Fc 72*32d959bfSagc.Ft int64_t 73*32d959bfSagc.Fo pgpv_get_cursor_num 74*32d959bfSagc.Fa "pgpv_t *pgp" "const char *field" 75*32d959bfSagc.Fc 76*32d959bfSagc.Ft char * 77*32d959bfSagc.Fo pgpv_get_cursor_str 78*32d959bfSagc.Fa "pgpv_t *pgp" "const char *field" 79*32d959bfSagc.Fc 8025f78d91Sagc.Ft int 8125f78d91Sagc.Fo pgpv_close 8225f78d91Sagc.Fa "pgpv_t *pgp" 8325f78d91Sagc.Fc 8425f78d91Sagc.Sh DESCRIPTION 8525f78d91Sagc.Nm 8625f78d91Sagcis a small library which will verify a digital signature on a text or 8725f78d91Sagcbinary document. 8825f78d91SagcIt has been kept deliberately small and only uses compression libraries 8925f78d91Sagcto function. 9025f78d91Sagc.Pp 9125f78d91SagcPGP messages, including key rings, are made up of PGP packets, defined 9225f78d91Sagcin RFC 4880. 9325f78d91SagcTo match a digital signature, the public key of the signer must be 9425f78d91Sagclocated in a public key ring. 9525f78d91SagcThis library has enough functionality to parse a pubkey keyring, 9625f78d91Sagcusing 9725f78d91Sagc.Fn pgpv_read_pubring 9825f78d91Sagcto read the public keys of trusted identities, 9925f78d91Sagcand to read files or memory which has already been signed. 10025f78d91SagcSSH public keys can also be used for signature verification 10125f78d91Sagcby using the 10225f78d91Sagc.Fn pgpv_read_ssh_pubkeys 10325f78d91Sagcfunction. 10425f78d91SagcPlease note that the creation date of the signature key 10525f78d91Sagcwill show up as January 1st 1970, due to the fact that the 10625f78d91Sagccreation date of the key is not encoded anywhere for an ssh 10725f78d91Sagckey, whilst it is an inherent part of the PGP fingerprint. 10825f78d91SagcIn order that the correct fingerprint is used, the key creation 10925f78d91Sagcdate is forced to 0. 11025f78d91Sagc.Pp 11125f78d91SagcThe 11225f78d91Sagc.Fn pgpv_verify 11325f78d91Sagcfunction is used to verify the signature, either on data, or on memory. 11425f78d91SagcTo signal to 11525f78d91Sagc.Fn pgpv_verify 11625f78d91Sagcto read a file and verify it, the 11725f78d91Sagc.Dv size 11825f78d91Sagcargument should be set to 11925f78d91Sagc.Dv -1 12025f78d91Sagcwhilst a positive size signals that the pointer value should be that 12125f78d91Sagcof signed memory. 12225f78d91Sagc.Fn pgpv_verify 12325f78d91Sagcreturns a cookie if the ignature was verified, or 0 if it did not. 12425f78d91SagcThis cookie can subsequently be used to retrieve the data which 12525f78d91Sagcwas verified. 12625f78d91Sagc.Pp 12725f78d91SagcIf the signature does match, then the file or memory can be considered as being 12825f78d91Sagcverified as being unmodified and unchanged, integrally sound. 12925f78d91Sagc.Pp 13025f78d91SagcSignatures have validity dates on them, and it is possible for a signature to 13125f78d91Sagchave expired when it is being checked. 13225f78d91SagcIf for any reason the signature does not match, then the reason for not 13325f78d91Sagcverifying the signature will be stored in the 13425f78d91Sagc.Dv why 13525f78d91Sagcbuffer in the 13625f78d91Sagc.Dv pgpv_cursor_t 13725f78d91Sagcstructure. 13825f78d91Sagc.Pp 13925f78d91SagcOccasionally, the memory or contents of the file which matched the signature 14025f78d91Sagcwill be needed, rather than a boolean value of whether it was verified. 14125f78d91SagcTo do this, the 14225f78d91Sagc.Fn pgpv_get_verified 14325f78d91Sagcfunction is used. 14425f78d91SagcArguments to 14525f78d91Sagc.Fn pgpv_get_verified 14625f78d91Sagcare the cookie returned from the verification, and a buffer 14725f78d91Sagcallocated for the returned data and its size. 14825f78d91SagcIf an error occurs, or the signature is not verified, a zero value is returned 14925f78d91Sagcfor the size. 15025f78d91Sagc.Nm 15125f78d91Sagcstores the starts of the data of all verified matches, and so the entry 15225f78d91Sagcnumber argument is the index of the occurrence of verification. 15325f78d91SagcThe first match will have an entry number of 0, the second 1, and so on. 15425f78d91Sagc.Pp 15525f78d91SagcThe 15625f78d91Sagc.Fn pgpv_close 15725f78d91Sagcfunction is used to clean up after all matching and verification has taken place. 15825f78d91SagcIt frees and de-allocates all resources used in the verification of the signature. 15925f78d91Sagc.Pp 16025f78d91SagcThe program used for signing may encode into base64 encoding, and it may also 16125f78d91Sagcuse embedded compression to make the output smaller than it would otherwise be. 16225f78d91SagcThis is handled automatically by 16325f78d91Sagc.Nm 16425f78d91Sagc.Sh SEE ALSO 16525f78d91Sagc.Xr bn 3 , 16625f78d91Sagc.\" .Xr bzlib2 3 , 16725f78d91Sagc.Xr zlib 3 16825f78d91Sagc.Sh STANDARDS 16925f78d91SagcThe 17025f78d91Sagc.Nm 17125f78d91Sagcutility is designed to conform to IETF RFC 4880. 17225f78d91Sagc.Sh HISTORY 17325f78d91SagcThe 17425f78d91Sagc.Nm 17525f78d91Sagclibrary first appeared in 17625f78d91Sagc.Nx 7.0 . 17725f78d91Sagc.Sh AUTHORS 17825f78d91Sagc.An Alistair Crooks Aq Mt agc@NetBSD.org 179