1.\" $NetBSD: libnetpgp.3,v 1.23 2018/04/29 14:21:16 sevan Exp $ 2.\" 3.\" Copyright (c) 2009,2010 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This manual page is derived from software contributed to The 7.\" NetBSD Foundation by Alistair Crooks (agc@NetBSD.org) 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" POSSIBILITY OF SUCH DAMAGE. 29.\" 30.Dd April 29, 2018 31.Dt LIBNETPGP 3 32.Os 33.Sh NAME 34.Nm libnetpgp 35.Nd digital signing and verification, encryption and decryption 36.Sh LIBRARY 37.Lb libnetpgp 38.Sh SYNOPSIS 39.In netpgp.h 40.Pp 41The following functions relate to initialisations and finalisations: 42.Ft int 43.Fo netpgp_init 44.Fa "netpgp_t *netpgp" 45.Fc 46.Ft int 47.Fo netpgp_end 48.Fa "netpgp_t *netpgp" 49.Fc 50.Pp 51The following functions are for debugging, reflection and information: 52.Ft int 53.Fo netpgp_set_debug 54.Fa "const char *filename" 55.Fc 56.Ft int 57.Fo netpgp_get_debug 58.Fa "const char *filename" 59.Fc 60.Ft int 61.Fo netpgp_get_info 62.Fa "const char *type" 63.Fc 64.Ft int 65.Fo netpgp_list_packets 66.Fa "netpgp_t *netpgp" "char *filename" "int armour" "char *pubringname" 67.Fc 68.Pp 69The following functions are for variable management: 70.Ft int 71.Fo netpgp_setvar 72.Fa "netpgp_t *netpgp" "const char *name" "const char *value" 73.Fc 74.Ft char * 75.Fo netpgp_getvar 76.Fa "netpgp_t *netpgp" "const char *name" 77.Fc 78.Ft int 79.Fo netpgp_incvar 80.Fa "netpgp_t *netpgp" "const char *name" "const int delta" 81.Fc 82.Ft int 83.Fo netpgp_unsetvar 84.Fa "netpgp_t *netpgp" "const char *name" 85.Fc 86.Pp 87The following function sets the home directory: 88.Ft int 89.Fo netpgp_set_homedir 90.Fa "netpgp_t *netpgp" "char *homedir" "char *subdir" "const int quiet" 91.Fc 92.Pp 93The following functions are used for key management: 94.Ft int 95.Fo netpgp_list_keys 96.Fa "netpgp_t *netpgp" "const int printsigs" 97.Fc 98.Ft int 99.Fo netpgp_list_keys_json 100.Fa "netpgp_t *netpgp" "char **json" "const int psigs" 101.Fc 102.Ft int 103.Fo netpgp_match_keys 104.Fa "netpgp_t *netpgp" "char *name" "const char *fmt" "void *vp" "const int psigs" 105.Fc 106.Ft int 107.Fo netpgp_match_keys_json 108.Fa "netpgp_t *netpgp" "char **json" "char *name" "const char *fmt" "const int psigs" 109.Fc 110.Ft int 111.Fo netpgp_match_pubkeys 112.Fa "netpgp_t *netpgp" "char *name" "void *vp" 113.Fc 114.Ft int 115.Fo netpgp_find_key 116.Fa "netpgp_t *netpgp" "char *userid" 117.Fc 118.Ft char * 119.Fo netpgp_get_key 120.Fa "netpgp_t *netpgp" "const char *name" "const char *fmt" 121.Fc 122.Ft int 123.Fo netpgp_export_key 124.Fa "netpgp_t *netpgp" "char *userid" 125.Fc 126.Ft int 127.Fo netpgp_import_key 128.Fa "netpgp_t *netpgp" "char *file" 129.Fc 130.Ft int 131.Fo netpgp_generate_key 132.Fa "netpgp_t *netpgp" "char *userid" "int numbits" 133.Fc 134.Ft int 135.Fo netpgp_validate_sigs 136.Fa "netpgp_t *netpgp" 137.Fc 138.Ft int 139.Fo netpgp_format_json 140.Fa "void *vp" "const char *json" "const int psigs" 141.Fc 142.Pp 143The following functions are used for file management: 144.Ft int 145.Fo netpgp_encrypt_file 146.Fa "netpgp_t *netpgp" "const char *userid" "const char *filename" "char *out" 147.Fa "int armored" 148.Fc 149.Ft int 150.Fo netpgp_decrypt_file 151.Fa "netpgp_t *netpgp" "const char *filename" "char *out" "int armored" 152.Fc 153.Ft int 154.Fo netpgp_sign_file 155.Fa "netpgp_t *netpgp" "const char *userid" "const char *filename" "char *out" 156.Fa "int armored" "int cleartext" "int detached" 157.Fc 158.Ft int 159.Fo netpgp_verify_file 160.Fa "netpgp_t *netpgp" "const char *in" "const char *out" "int armored" 161.Fc 162.Pp 163The following functions are used for memory signing and encryption: 164.Ft int 165.Fo netpgp_encrypt_memory 166.Fa "netpgp_t *netpgp" "const char *userid" "void *in" "const size_t insize" 167.Fa "char *out" "size_t outsize" "int armored" 168.Fc 169.Ft int 170.Fo netpgp_decrypt_memory 171.Fa "netpgp_t *netpgp" "const void *input" "const size_t insize" 172.Fa "char *out" "size_t outsize" "const int armored" 173.Fc 174.Ft int 175.Fo netpgp_sign_memory 176.Fa "netpgp_t *netpgp" "const char *userid" "char *mem" 177.Fa "size_t size" "char *out" "size_t outsize" 178.Fa "const unsigned armored" "const unsigned cleartext" 179.Fc 180.Ft int 181.Fo netpgp_verify_memory 182.Fa "netpgp_t *netpgp" "const void *in" "const size_t insize" 183.Fa "void *out" "size_t outsize" "const int armored" 184.Fc 185.Sh DESCRIPTION 186.Nm 187is a library interface to enable digital signatures to be created and 188verified, and also for files and memory to be encrypted and decrypted. 189Functions are also provided for management of user keys. 190.Pp 191The library uses functions from the openssl library for multi-precision 192integer arithmetic, and for RSA and DSA key signing and verification, 193encryption and decryption. 194.Pp 195Normal operation sees the 196.Nm 197process be initialised using the 198.Fn netpgp_init 199function, which will set up the public and private keyrings, as well as set the 200user identity in the 201.Ar userid 202member of the 203.Dv netpgp_t 204structure. 205These are set using the 206.Fn netpgp_setvar 207function. 208If no public key ring file is set, initial values will be taken from those 209in the 210.Pa .gnupg/pubring.gpg 211file in the user's home directory. 212Similarly, if no secret key ring file is set, 213initial values will be taken from those 214in the 215.Pa .gnupg/secring.gpg 216file in the user's home directory. 217The user identity is obtained from the 218.Ev userid 219environment variable, or failing that, the value of the 220.Dq default-key 221setting from 222.Pa .gnupg/gpg.conf 223file in the user's home directory is used. 224The 225.Fn netpgp_init 226function returns 1 on success, 0 on failure. 227.Pp 228To list all the keys in a keyring, the 229.Fn netpgp_list_keys 230function is used. 231The signature subkey fields can also be displayed 232using this function. 233.Pp 234The home directory is specified as an internal variable, 235and its existence is checked using the 236.Fn netpgp_set_homedir 237function. 238This function can operate in a verbose or quiet 239manner, depending on the value of the argument provided. 240If the subdirectory argument is provided, this subdirectory 241is appended to the home directory in order to search for 242the keyrings. 243.Pp 244To export a key, the 245.Fn netpgp_export_key 246function is used. 247Output is sent to the standard output. 248.Pp 249To import a key onto the public keyring, the 250.Fn netpgp_import_key 251function is used. 252The name of the file containing the key to be imported is provided 253as the filename argument. 254.Pp 255To generate a key, the 256.Fn netpgp_generate_key 257function is used. 258It takes an argument of the number of bits to use in the key. 259At the time that this manual page was created (April 2009), 260the recommendations are that the bare minimum key size 261of at least 2048 bits is used, and it would be much better 262to use at least 4096 or 8192 bits. 263This situation should be monitored to ensure that it does 264not go out of date. 265.Pp 266Encryption, decryption, signing and verification of 267files are the lifeblood of the 268.Nm 269library. 270To encrypt a file, the 271.Fn netpgp_encrypt_file 272function is used, and the 273.Fn netpgp_decrypt_file 274function is used to decrypt the results of the encryption. 275To sign a file, the 276.Fn netpgp_sign_file 277function is used, and the resulting signed file can be verified 278using the 279.Fn netpgp_verify_file 280function. 281.Pp 282.Fn netpgp_sign_memory 283is a function which can sign an area 284of memory, and 285.Fn netpgp_verify_memory 286verifies the digital signature produced. 287.Pp 288Internally, an encrypted or signed file 289is made up of 290.Dq packets 291which hold information pertaining to the signature, 292encryption method, and the data which is being protected. 293This information can be displayed in a verbose manner using 294the 295.Fn netpgp_list_packets 296function. 297.Pp 298The 299.Fn netpgp_setvar 300and 301.Fn netpgp_getvar 302functions are used to manage the hash algorithm that 303is used with RSA signatures. 304These functions are general purpose functions, and 305are used to set and retrieve values for internal variables. 306For example, they 307can be used to set and to retrieve the 308value of the user id 309which has been set, 310the home directory from which to find the keyrings, 311the verbosity settings, and many more. 312The 313.Fn netpgp_incvar 314function is used to add a numeric increment to the 315internal variable. 316This incremental value can be negative. 317It is primarily used to increase the verbosity settings. 318.Pp 319In 320.Nm 321files are encrypted using the public key of the userid. 322The secret key is used to decrypt the results of that encryption. 323Files are signed using the secret key of the userid. 324The public key is used to verify that the file was signed, 325who signed the file, and the date and time at which it was signed. 326.Pp 327Some utility functions are also provided for debugging, and for 328finding out version and maintainer information from calling programs. 329These are the 330.Fn netpgp_set_debug 331and the 332.Fn netpgp_get_debug 333functions (for getting verbose debugging information on a per-source 334file basis). 335.Pp 336The 337.Fn netpgp_get_info 338function returns the version or maintainer information depending upon the 339.Ar type 340argument. 341At the present time, two types are defined: 342.Dq version 343and 344.Dq maintainer . 345A failure to present a known 346.Ar type 347argument to 348.Fn netpgp_get_info 349will result in the string 350.Dq [unknown] 351being returned. 352.Sh SEE ALSO 353.Xr netpgp 1 , 354.Xr ssl 3 355.Sh HISTORY 356The 357.Nm 358library first appeared in 359.Nx 6.0 . 360.Sh AUTHORS 361.An -nosplit 362.An Ben Laurie , 363.An Rachel Willmer . 364.An Alistair Crooks Aq Mt agc@NetBSD.org 365wrote this high-level interface. 366.Pp 367This manual page was written by 368.An Alistair Crooks . 369