1.\" $NetBSD: libnetpgp.3,v 1.12 2010/03/14 00:55:32 agc 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 March 13, 2010 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" "char *userid" "char *pubringfile" "char *secringfile" 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.Pp 83The following function sets the home directory: 84.Ft int 85.Fo netpgp_set_homedir 86.Fa "netpgp_t *netpgp" "char *homedir" "char *subdir" "const int quiet" 87.Fc 88.Pp 89The following functions are used for key management: 90.Ft int 91.Fo netpgp_list_keys 92.Fa "netpgp_t *netpgp" "const int printsigs" 93.Fc 94.Ft int 95.Fo netpgp_match_list_keys 96.Fa "netpgp_t *netpgp" "char *pattern" 97.Fc 98.Ft int 99.Fo netpgp_find_key 100.Fa "netpgp_t *netpgp" "char *userid" 101.Fc 102.Ft char * 103.Fo netpgp_get_key 104.Fa "netpgp_t *netpgp" "const char *id" 105.Fc 106.Ft int 107.Fo netpgp_export_key 108.Fa "netpgp_t *netpgp" "char *userid" 109.Fc 110.Ft int 111.Fo netpgp_import_key 112.Fa "netpgp_t *netpgp" "char *file" 113.Fc 114.Ft int 115.Fo netpgp_generate_key 116.Fa "netpgp_t *netpgp" "char *userid" "int numbits" 117.Fc 118.Pp 119The following functions are used for file management: 120.Ft int 121.Fo netpgp_encrypt_file 122.Fa "netpgp_t *netpgp" "char *userid" "char *filename" "char *out" 123.Fa "int armored" 124.Fc 125.Ft int 126.Fo netpgp_decrypt_file 127.Fa "netpgp_t *netpgp" "char *filename" "char *out" "int armored" 128.Fc 129.Ft int 130.Fo netpgp_sign_file 131.Fa "netpgp_t *netpgp" "char *userid" "char *filename" "char *out" 132.Fa "int armored" "int cleartext" "int detached" 133.Fc 134.Ft int 135.Fo netpgp_verify_file 136.Fa "netpgp_t *netpgp" "char *f" "int armored" 137.Fc 138.Pp 139The following functions are used for memory signing and encryption: 140.Ft int 141.Fo netpgp_encrypt_memory 142.Fa "netpgp_t *netpgp" "char *userid" "void *in" "const size_t insize" 143.Fa "char *out" "size_t outsize" "int armored" 144.Fc 145.Ft int 146.Fo netpgp_decrypt_memory 147.Fa "netpgp_t *netpgp" "const void *input" "const size_t insize" 148.Fa "char *out" "size_t outsize" "const int armored" 149.Fc 150.Ft int 151.Fo netpgp_sign_memory 152.Fa "netpgp_t *netpgp" "const char *userid" "char *mem" 153.Fa "size_t size" "char *out" "size_t outsize" 154.Fa "const unsigned armored" "const unsigned cleartext" 155.Fc 156.Ft int 157.Fo netpgp_verify_memory 158.Fa "netpgp_t *netpgp" "const void *in" "const size_t insize" 159.Fa "void *out" "size_t outsize" "const int armored" 160.Fc 161.Sh DESCRIPTION 162.Nm 163is a library interface to enable digital signatures to be created and 164verified, and also for files and memory to be encrypted and decrypted. 165Functions are also provided for management of user keys. 166.Pp 167The library uses functions from the openssl library for multi-precision 168integer arithmetic, and for RSA and DSA key signing and verification, 169encryption and decryption. 170.Pp 171Normal operation sees the 172.Nm 173process be initialised using the 174.Fn netpgp_init 175function, which will set up the public and private keyrings, and set the 176user identity to the 177.Ar userid 178argument passed to the function. 179If no public key ring file is provided, initial values will be taken from those 180in the 181.Pa .gnupg/pubring.gpg 182file in the user's home directory. 183Similarily, if no secret key ring file is provided, 184initial values will be taken from those 185in the 186.Pa .gnupg/secring.gpg 187file in the user's home directory. 188The 189.Fn netpgp_init 190returns 1 on sucess, 0 on failure. 191.Pp 192To list all the keys in a keyring, the 193.Fn netpgp_list_keys 194function is used. 195The signature subkey fields can also be displayed 196using this function. 197The 198.Fn netpgp_match_list_keys 199function is used to match (via regular expression) 200a subset of the keys in the keyring. 201If the expression to match is NULL, 202the search will degenerate into a 203listing of all keys in the keyring. 204.Pp 205The home directory is specified as an internal variable, 206and its existence is checked using the 207.Fn netpgp_set_homedir 208function. 209This function can operate in a verbose or quiet 210manner, depending on the value of the argument provided. 211If the subdirectory argument is provided, this subdirectory 212is appended to the home directory in order to search for 213the keyrings. 214.Pp 215To export a key, the 216.Fn netpgp_export_key 217is used. 218Output is sent to the standard output. 219.Pp 220To import a key onto the public keyring, the 221.Fn netpgp_import_key 222is used. 223The name of the file containing the key to be imported is provided 224as the filename argument. 225.Pp 226To generate a key, the 227.Fn netpgp_generate_key 228is used. 229It takes an argument of the number of bits to use in the key. 230At the time that this manual page was created (April 2009), 231the recommendations are that the bare minimum key size 232of at least 2048 bits is used, and it would be much better 233to use at least 4096 or 8192 bits. 234This situation should be monitored to ensure that it does 235not go out of date. 236.Pp 237Encryption, decryption, signing and verification of 238files are the lifeblood of the 239.Nm 240library. 241To encrypt a file, the 242.Fn netpgp_encrypt_file 243and the 244.Fn netpgp_decrypt_file 245is used to decrypt the results of the encryption. 246To sign a file, the 247.Fn netpgp_sign_file 248is used, and the resulting signed file can be verified 249using the 250.Fn netpgp_verify_file 251function. 252.Pp 253.Fn netpgp_sign_memory 254is a function which can sign an area 255of memory, and 256.Fn netpgp_verify_memory 257verifies the digital signature produced. 258.Pp 259Internally, an encrypted or signed file 260is made up of 261.Dq packets 262which hold information pertaining to the signature, 263encryption method, and the data which is being protected. 264This information can be displayed in a verbose manner using 265the 266.Fn netpgp_list_packets 267function. 268.Pp 269The 270.Fn netpgp_setvar 271and 272.Fn netpgp_getvar 273functions are used to manage the hash algorithm that 274is used with RSA signatures. 275These functions are general purpose functions, and 276are used to set and retrieve values for internal variables. 277For example, they 278can be used to set and to retrieve the 279value of the user id 280which has been set, 281the home directory from which to find the keyrings, 282the verbosity settings, and many more. 283The 284.Fn netpgp_incvar 285function is used to add a numeric increment to the 286internal variable. 287This incremental value can be negative. 288It is primarily used to increase the verbosity settings. 289.Pp 290In 291.Nm 292files are encrypted using the public key of the userid. 293The secret key is used to decrypt the results of that encryption. 294Files are signed using the secret key of the userid. 295The public key is used to verify that the file was signed, 296who signed the file, and the date and time at which it was signed. 297.Pp 298Some utility functions are also provided for debugging, and for 299finding out version and maintainer information from calling programs. 300These are the 301.Fn netpgp_set_debug 302and the 303.Fn netpgp_get_debug 304functions (for getting verbose debugging information on a per-source 305file basis). 306.Pp 307The 308.Fn netpgp_get_info 309returns the information depending upon the 310.Ar type 311argument. 312.Sh SEE ALSO 313.Xr netpgp 1 , 314.Xr ssl 3 315.Sh HISTORY 316The 317.Nm 318library first appeared in 319.Nx 6.0 . 320.Sh AUTHORS 321.An Ben Laurie , 322.An Rachel Willmer . 323.An Alistair Crooks Aq agc@NetBSD.org 324wrote this high-level interface. 325.Pp 326This manual page was written by 327.An Alistair Crooks . 328