1*75ae0b63Ssevan.\" $NetBSD: libnetpgp.3,v 1.27 2018/05/10 15:00:36 sevan Exp $ 293bf6008Sagc.\" 366373914Sagc.\" Copyright (c) 2009,2010 The NetBSD Foundation, Inc. 493bf6008Sagc.\" All rights reserved. 593bf6008Sagc.\" 693bf6008Sagc.\" This manual page is derived from software contributed to The 793bf6008Sagc.\" NetBSD Foundation by Alistair Crooks (agc@NetBSD.org) 893bf6008Sagc.\" 993bf6008Sagc.\" Redistribution and use in source and binary forms, with or without 1093bf6008Sagc.\" modification, are permitted provided that the following conditions 1193bf6008Sagc.\" are met: 1293bf6008Sagc.\" 1. Redistributions of source code must retain the above copyright 1393bf6008Sagc.\" notice, this list of conditions and the following disclaimer. 1493bf6008Sagc.\" 2. Redistributions in binary form must reproduce the above copyright 1593bf6008Sagc.\" notice, this list of conditions and the following disclaimer in the 1693bf6008Sagc.\" documentation and/or other materials provided with the distribution. 1793bf6008Sagc.\" 1893bf6008Sagc.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1993bf6008Sagc.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2093bf6008Sagc.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2193bf6008Sagc.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2293bf6008Sagc.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2393bf6008Sagc.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2493bf6008Sagc.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2593bf6008Sagc.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2693bf6008Sagc.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2793bf6008Sagc.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2893bf6008Sagc.\" POSSIBILITY OF SUCH DAMAGE. 2993bf6008Sagc.\" 30909174d4Ssevan.Dd May 10, 2018 3193bf6008Sagc.Dt LIBNETPGP 3 3293bf6008Sagc.Os 3393bf6008Sagc.Sh NAME 3493bf6008Sagc.Nm libnetpgp 3593bf6008Sagc.Nd digital signing and verification, encryption and decryption 3693bf6008Sagc.Sh LIBRARY 3793bf6008Sagc.Lb libnetpgp 3893bf6008Sagc.Sh SYNOPSIS 39fefeeb6fSwiz.In netpgp.h 40d369874eSagc.Pp 41d369874eSagcThe following functions relate to initialisations and finalisations: 4293bf6008Sagc.Ft int 4393bf6008Sagc.Fo netpgp_init 447119252bSsevan.Fa "netpgp_t *netpgp" 4593bf6008Sagc.Fc 4693bf6008Sagc.Ft int 4793bf6008Sagc.Fo netpgp_end 487119252bSsevan.Fa "netpgp_t *netpgp" 4993bf6008Sagc.Fc 50d369874eSagc.Pp 51d369874eSagcThe following functions are for debugging, reflection and information: 52d369874eSagc.Ft int 53d369874eSagc.Fo netpgp_set_debug 54d369874eSagc.Fa "const char *filename" 55d369874eSagc.Fc 56d369874eSagc.Ft int 57d369874eSagc.Fo netpgp_get_debug 58d369874eSagc.Fa "const char *filename" 59d369874eSagc.Fc 60d369874eSagc.Ft int 61d369874eSagc.Fo netpgp_get_info 62d369874eSagc.Fa "const char *type" 63d369874eSagc.Fc 64d369874eSagc.Ft int 65d369874eSagc.Fo netpgp_list_packets 667119252bSsevan.Fa "netpgp_t *netpgp" "char *filename" "int armour" "char *pubringname" 67d369874eSagc.Fc 68d369874eSagc.Pp 69d369874eSagcThe following functions are for variable management: 70d369874eSagc.Ft int 71d369874eSagc.Fo netpgp_setvar 727119252bSsevan.Fa "netpgp_t *netpgp" "const char *name" "const char *value" 73d369874eSagc.Fc 74d369874eSagc.Ft char * 75d369874eSagc.Fo netpgp_getvar 767119252bSsevan.Fa "netpgp_t *netpgp" "const char *name" 77d369874eSagc.Fc 78d369874eSagc.Ft int 79d369874eSagc.Fo netpgp_incvar 807119252bSsevan.Fa "netpgp_t *netpgp" "const char *name" "const int delta" 81d369874eSagc.Fc 82d57d6d22Ssevan.Ft int 83d57d6d22Ssevan.Fo netpgp_unsetvar 84d57d6d22Ssevan.Fa "netpgp_t *netpgp" "const char *name" 85d57d6d22Ssevan.Fc 86d369874eSagc.Pp 87d369874eSagcThe following function sets the home directory: 88d369874eSagc.Ft int 89d369874eSagc.Fo netpgp_set_homedir 907119252bSsevan.Fa "netpgp_t *netpgp" "char *homedir" "char *subdir" "const int quiet" 91d369874eSagc.Fc 92d369874eSagc.Pp 93d369874eSagcThe following functions are used for key management: 9493bf6008Sagc.Ft int 9593bf6008Sagc.Fo netpgp_list_keys 967119252bSsevan.Fa "netpgp_t *netpgp" "const int printsigs" 9793bf6008Sagc.Fc 9893bf6008Sagc.Ft int 99d57d6d22Ssevan.Fo netpgp_list_keys_json 100d57d6d22Ssevan.Fa "netpgp_t *netpgp" "char **json" "const int psigs" 101d57d6d22Ssevan.Fc 102d57d6d22Ssevan.Ft int 103d57d6d22Ssevan.Fo netpgp_match_keys 104d57d6d22Ssevan.Fa "netpgp_t *netpgp" "char *name" "const char *fmt" "void *vp" "const int psigs" 105d57d6d22Ssevan.Fc 106d57d6d22Ssevan.Ft int 107d57d6d22Ssevan.Fo netpgp_match_keys_json 108d57d6d22Ssevan.Fa "netpgp_t *netpgp" "char **json" "char *name" "const char *fmt" "const int psigs" 109d57d6d22Ssevan.Fc 110d57d6d22Ssevan.Ft int 111d57d6d22Ssevan.Fo netpgp_match_pubkeys 112d57d6d22Ssevan.Fa "netpgp_t *netpgp" "char *name" "void *vp" 113d369874eSagc.Fc 114d369874eSagc.Ft int 11593bf6008Sagc.Fo netpgp_find_key 1167119252bSsevan.Fa "netpgp_t *netpgp" "char *userid" 11793bf6008Sagc.Fc 118d369874eSagc.Ft char * 119d369874eSagc.Fo netpgp_get_key 120d57d6d22Ssevan.Fa "netpgp_t *netpgp" "const char *name" "const char *fmt" 121d369874eSagc.Fc 12293bf6008Sagc.Ft int 12393bf6008Sagc.Fo netpgp_export_key 1247119252bSsevan.Fa "netpgp_t *netpgp" "char *userid" 12593bf6008Sagc.Fc 12693bf6008Sagc.Ft int 12793bf6008Sagc.Fo netpgp_import_key 1287119252bSsevan.Fa "netpgp_t *netpgp" "char *file" 12993bf6008Sagc.Fc 13093bf6008Sagc.Ft int 13193bf6008Sagc.Fo netpgp_generate_key 1327119252bSsevan.Fa "netpgp_t *netpgp" "char *userid" "int numbits" 13393bf6008Sagc.Fc 134d57d6d22Ssevan.Ft int 135d57d6d22Ssevan.Fo netpgp_validate_sigs 136d57d6d22Ssevan.Fa "netpgp_t *netpgp" 137d57d6d22Ssevan.Fc 138d57d6d22Ssevan.Ft int 139d57d6d22Ssevan.Fo netpgp_format_json 140d57d6d22Ssevan.Fa "void *vp" "const char *json" "const int psigs" 141d57d6d22Ssevan.Fc 142d369874eSagc.Pp 143d369874eSagcThe following functions are used for file management: 14493bf6008Sagc.Ft int 14593bf6008Sagc.Fo netpgp_encrypt_file 146d57d6d22Ssevan.Fa "netpgp_t *netpgp" "const char *userid" "const char *filename" "char *out" 14793bf6008Sagc.Fa "int armored" 14893bf6008Sagc.Fc 14993bf6008Sagc.Ft int 15093bf6008Sagc.Fo netpgp_decrypt_file 151d57d6d22Ssevan.Fa "netpgp_t *netpgp" "const char *filename" "char *out" "int armored" 15293bf6008Sagc.Fc 15393bf6008Sagc.Ft int 15493bf6008Sagc.Fo netpgp_sign_file 155d57d6d22Ssevan.Fa "netpgp_t *netpgp" "const char *userid" "const char *filename" "char *out" 1567cf9b94eSagc.Fa "int armored" "int cleartext" "int detached" 15793bf6008Sagc.Fc 15893bf6008Sagc.Ft int 15993bf6008Sagc.Fo netpgp_verify_file 160d57d6d22Ssevan.Fa "netpgp_t *netpgp" "const char *in" "const char *out" "int armored" 16193bf6008Sagc.Fc 162d369874eSagc.Pp 163d369874eSagcThe following functions are used for memory signing and encryption: 164d369874eSagc.Ft int 165d369874eSagc.Fo netpgp_encrypt_memory 166d57d6d22Ssevan.Fa "netpgp_t *netpgp" "const char *userid" "void *in" "const size_t insize" 167d369874eSagc.Fa "char *out" "size_t outsize" "int armored" 168d369874eSagc.Fc 169d369874eSagc.Ft int 170d369874eSagc.Fo netpgp_decrypt_memory 1717119252bSsevan.Fa "netpgp_t *netpgp" "const void *input" "const size_t insize" 172d369874eSagc.Fa "char *out" "size_t outsize" "const int armored" 173d369874eSagc.Fc 17493bf6008Sagc.Ft int 175ad7bc21dSagc.Fo netpgp_sign_memory 1767119252bSsevan.Fa "netpgp_t *netpgp" "const char *userid" "char *mem" 177ad7bc21dSagc.Fa "size_t size" "char *out" "size_t outsize" 178ad7bc21dSagc.Fa "const unsigned armored" "const unsigned cleartext" 179ad7bc21dSagc.Fc 180ad7bc21dSagc.Ft int 181ad7bc21dSagc.Fo netpgp_verify_memory 1827119252bSsevan.Fa "netpgp_t *netpgp" "const void *in" "const size_t insize" 183d369874eSagc.Fa "void *out" "size_t outsize" "const int armored" 1849e63cf3fSagc.Fc 18593bf6008Sagc.Sh DESCRIPTION 18693bf6008Sagc.Nm 18793bf6008Sagcis a library interface to enable digital signatures to be created and 18893bf6008Sagcverified, and also for files and memory to be encrypted and decrypted. 18993bf6008SagcFunctions are also provided for management of user keys. 19093bf6008Sagc.Pp 19193bf6008SagcThe library uses functions from the openssl library for multi-precision 19293bf6008Sagcinteger arithmetic, and for RSA and DSA key signing and verification, 19393bf6008Sagcencryption and decryption. 19493bf6008Sagc.Pp 19593bf6008SagcNormal operation sees the 19693bf6008Sagc.Nm 19793bf6008Sagcprocess be initialised using the 19893bf6008Sagc.Fn netpgp_init 199cfb13771Ssevanfunction, which will set up the public and private keyrings, as well as set the 200cfb13771Ssevanuser identity in the 201702f5adbSagc.Ar userid 202cfb13771Ssevanmember of the 2032c8603b1Sagc.Dv netpgp_t 204cfb13771Ssevanstructure. 205cfb13771SsevanThese are set using the 2062c8603b1Sagc.Fn netpgp_setvar 207909174d4Ssevanfunction and unset using the 208909174d4Ssevan.Fn netpgp_unsetvar 2092c8603b1Sagcfunction. 2102c8603b1SagcIf no public key ring file is set, initial values will be taken from those 21193bf6008Sagcin the 212fefeeb6fSwiz.Pa .gnupg/pubring.gpg 21393bf6008Sagcfile in the user's home directory. 214cdcd9578SagcSimilarly, if no secret key ring file is set, 21593bf6008Sagcinitial values will be taken from those 21693bf6008Sagcin the 217fefeeb6fSwiz.Pa .gnupg/secring.gpg 21893bf6008Sagcfile in the user's home directory. 219cfb13771SsevanThe user identity is obtained from the 220cfb13771Ssevan.Ev userid 221cfb13771Ssevanenvironment variable, or failing that, the value of the 222cfb13771Ssevan.Dq default-key 223cfb13771Ssevansetting from 224cfb13771Ssevan.Pa .gnupg/gpg.conf 225cfb13771Ssevanfile in the user's home directory is used. 22693bf6008SagcThe 22793bf6008Sagc.Fn netpgp_init 228cdcd9578Sagcfunction returns 1 on success, 0 on failure. 22993bf6008Sagc.Pp 23093bf6008SagcTo list all the keys in a keyring, the 23193bf6008Sagc.Fn netpgp_list_keys 23293bf6008Sagcfunction is used. 233909174d4SsevanTo list all the keys in a keyring as a JSON encoded string, the 234909174d4Ssevan.Fn netpgp_list_keys_json 235909174d4Ssevanfunction is used. 236*75ae0b63SsevanTo find and list keys in a keyring, the 237*75ae0b63Ssevan.Fn netpgp_match_keys 238*75ae0b63Ssevanfunction is used. 239*75ae0b63SsevanTo find and list keys in a keyring, output as a JSON encoded string, 240*75ae0b63Ssevanthe 241*75ae0b63Ssevan.Fn netpgp_match_keys_json 242*75ae0b63Ssevanfunction is used. 243*75ae0b63SsevanTo find and list keys in a better suited machine-readble format, such as for 244*75ae0b63Ssevanredirection to other parsing engines, the 245*75ae0b63Ssevan.Fn netpgp_match_pubkeys 246*75ae0b63Ssevanfunction is used. 24766373914SagcThe signature subkey fields can also be displayed 24866373914Sagcusing this function. 2499e63cf3fSagc.Pp 2509e63cf3fSagcThe home directory is specified as an internal variable, 2519e63cf3fSagcand its existence is checked using the 2529e63cf3fSagc.Fn netpgp_set_homedir 2539e63cf3fSagcfunction. 2549e63cf3fSagcThis function can operate in a verbose or quiet 2559e63cf3fSagcmanner, depending on the value of the argument provided. 2569e63cf3fSagcIf the subdirectory argument is provided, this subdirectory 2579e63cf3fSagcis appended to the home directory in order to search for 2589e63cf3fSagcthe keyrings. 25993bf6008Sagc.Pp 260*75ae0b63SsevanTo print key information from a JSON encoded string, stored in a file, the 261*75ae0b63Ssevan.Fn netpgp_format_json 262*75ae0b63Ssevanfunction is used. 263*75ae0b63Ssevan.Pp 264*75ae0b63SsevanTo validate the signature of keys in a public key keyring, the 265*75ae0b63Ssevan.Fn netpgp_validate_sigs 266*75ae0b63Ssevanfunction is used. 267*75ae0b63Ssevan.Pp 26893bf6008SagcTo export a key, the 26993bf6008Sagc.Fn netpgp_export_key 270cdcd9578Sagcfunction is used. 27193bf6008SagcOutput is sent to the standard output. 27293bf6008Sagc.Pp 27393bf6008SagcTo import a key onto the public keyring, the 27493bf6008Sagc.Fn netpgp_import_key 2759835dc7aSsevanfunction is used. 27693bf6008SagcThe name of the file containing the key to be imported is provided 27793bf6008Sagcas the filename argument. 27893bf6008Sagc.Pp 27993bf6008SagcTo generate a key, the 28093bf6008Sagc.Fn netpgp_generate_key 2819835dc7aSsevanfunction is used. 28293bf6008SagcIt takes an argument of the number of bits to use in the key. 28393bf6008SagcAt the time that this manual page was created (April 2009), 28493bf6008Sagcthe recommendations are that the bare minimum key size 28593bf6008Sagcof at least 2048 bits is used, and it would be much better 28693bf6008Sagcto use at least 4096 or 8192 bits. 28793bf6008SagcThis situation should be monitored to ensure that it does 28893bf6008Sagcnot go out of date. 28993bf6008Sagc.Pp 29093bf6008SagcEncryption, decryption, signing and verification of 29193bf6008Sagcfiles are the lifeblood of the 29293bf6008Sagc.Nm 29393bf6008Sagclibrary. 29493bf6008SagcTo encrypt a file, the 29593bf6008Sagc.Fn netpgp_encrypt_file 296cdcd9578Sagcfunction is used, and the 29793bf6008Sagc.Fn netpgp_decrypt_file 298cdcd9578Sagcfunction is used to decrypt the results of the encryption. 29993bf6008SagcTo sign a file, the 30093bf6008Sagc.Fn netpgp_sign_file 301cdcd9578Sagcfunction is used, and the resulting signed file can be verified 30293bf6008Sagcusing the 30393bf6008Sagc.Fn netpgp_verify_file 30493bf6008Sagcfunction. 30593bf6008Sagc.Pp 306ad7bc21dSagc.Fn netpgp_sign_memory 307ad7bc21dSagcis a function which can sign an area 308ad7bc21dSagcof memory, and 309ad7bc21dSagc.Fn netpgp_verify_memory 310ad7bc21dSagcverifies the digital signature produced. 311ad7bc21dSagc.Pp 312bcfd8565SagcInternally, an encrypted or signed file 313bcfd8565Sagcis made up of 314bcfd8565Sagc.Dq packets 315bcfd8565Sagcwhich hold information pertaining to the signature, 316bcfd8565Sagcencryption method, and the data which is being protected. 317bcfd8565SagcThis information can be displayed in a verbose manner using 318bcfd8565Sagcthe 319bcfd8565Sagc.Fn netpgp_list_packets 320bcfd8565Sagcfunction. 321bcfd8565Sagc.Pp 3224b3a3e18SagcThe 3234b3a3e18Sagc.Fn netpgp_setvar 3244b3a3e18Sagcand 3254b3a3e18Sagc.Fn netpgp_getvar 3264b3a3e18Sagcfunctions are used to manage the hash algorithm that 3274b3a3e18Sagcis used with RSA signatures. 3289e63cf3fSagcThese functions are general purpose functions, and 3299e63cf3fSagcare used to set and retrieve values for internal variables. 3309e63cf3fSagcFor example, they 3319e63cf3fSagccan be used to set and to retrieve the 3324b3a3e18Sagcvalue of the user id 3339e63cf3fSagcwhich has been set, 3349e63cf3fSagcthe home directory from which to find the keyrings, 3359e63cf3fSagcthe verbosity settings, and many more. 3369e63cf3fSagcThe 3379e63cf3fSagc.Fn netpgp_incvar 3389e63cf3fSagcfunction is used to add a numeric increment to the 3399e63cf3fSagcinternal variable. 3409e63cf3fSagcThis incremental value can be negative. 3419e63cf3fSagcIt is primarily used to increase the verbosity settings. 3424b3a3e18Sagc.Pp 34393bf6008SagcIn 34493bf6008Sagc.Nm 34593bf6008Sagcfiles are encrypted using the public key of the userid. 34693bf6008SagcThe secret key is used to decrypt the results of that encryption. 34793bf6008SagcFiles are signed using the secret key of the userid. 34893bf6008SagcThe public key is used to verify that the file was signed, 34993bf6008Sagcwho signed the file, and the date and time at which it was signed. 35093bf6008Sagc.Pp 35193bf6008SagcSome utility functions are also provided for debugging, and for 35293bf6008Sagcfinding out version and maintainer information from calling programs. 35393bf6008SagcThese are the 35493bf6008Sagc.Fn netpgp_set_debug 35593bf6008Sagcand the 35693bf6008Sagc.Fn netpgp_get_debug 35793bf6008Sagcfunctions (for getting verbose debugging information on a per-source 35893bf6008Sagcfile basis). 35993bf6008Sagc.Pp 36093bf6008SagcThe 36193bf6008Sagc.Fn netpgp_get_info 362cdcd9578Sagcfunction returns the version or maintainer information depending upon the 363702f5adbSagc.Ar type 36493bf6008Sagcargument. 3655d13bf32SagcAt the present time, two types are defined: 3665d13bf32Sagc.Dq version 3675d13bf32Sagcand 3685d13bf32Sagc.Dq maintainer . 3690de9c84cSwizThe maintainer information returned contains the name, email address, 3700de9c84cSwizand PGP short key id. 3715d13bf32SagcA failure to present a known 3725d13bf32Sagc.Ar type 3735d13bf32Sagcargument to 3745d13bf32Sagc.Fn netpgp_get_info 3755d13bf32Sagcwill result in the string 3765d13bf32Sagc.Dq [unknown] 3775d13bf32Sagcbeing returned. 37893bf6008Sagc.Sh SEE ALSO 37993bf6008Sagc.Xr netpgp 1 , 38093bf6008Sagc.Xr ssl 3 38193bf6008Sagc.Sh HISTORY 38293bf6008SagcThe 38393bf6008Sagc.Nm 38493bf6008Sagclibrary first appeared in 38593bf6008Sagc.Nx 6.0 . 38693bf6008Sagc.Sh AUTHORS 387cdcd9578Sagc.An -nosplit 388fefeeb6fSwiz.An Ben Laurie , 38993bf6008Sagc.An Rachel Willmer . 390a5684d07Swiz.An Alistair Crooks Aq Mt agc@NetBSD.org 39193bf6008Sagcwrote this high-level interface. 39293bf6008Sagc.Pp 39393bf6008SagcThis manual page was written by 3944b3a3e18Sagc.An Alistair Crooks . 395