1.\" $NetBSD: libnetpgp.3,v 1.15 2013/07/20 21:39:55 wiz 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 June 17, 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"
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 stored in the
179.Dv netpgp_t
180structure, and set using the
181.Fn netpgp_setvar
182function.
183If no public key ring file is set, initial values will be taken from those
184in the
185.Pa .gnupg/pubring.gpg
186file in the user's home directory.
187Similarily, if no secret key ring file is set,
188initial values will be taken from those
189in the
190.Pa .gnupg/secring.gpg
191file in the user's home directory.
192The
193.Fn netpgp_init
194returns 1 on sucess, 0 on failure.
195.Pp
196To list all the keys in a keyring, the
197.Fn netpgp_list_keys
198function is used.
199The signature subkey fields can also be displayed
200using this function.
201The
202.Fn netpgp_match_list_keys
203function is used to match (via regular expression)
204a subset of the keys in the keyring.
205If the expression to match is NULL,
206the search will degenerate into a
207listing of all keys in the keyring.
208.Pp
209The home directory is specified as an internal variable,
210and its existence is checked using the
211.Fn netpgp_set_homedir
212function.
213This function can operate in a verbose or quiet
214manner, depending on the value of the argument provided.
215If the subdirectory argument is provided, this subdirectory
216is appended to the home directory in order to search for
217the keyrings.
218.Pp
219To export a key, the
220.Fn netpgp_export_key
221is used.
222Output is sent to the standard output.
223.Pp
224To import a key onto the public keyring, the
225.Fn netpgp_import_key
226is used.
227The name of the file containing the key to be imported is provided
228as the filename argument.
229.Pp
230To generate a key, the
231.Fn netpgp_generate_key
232is used.
233It takes an argument of the number of bits to use in the key.
234At the time that this manual page was created (April 2009),
235the recommendations are that the bare minimum key size
236of at least 2048 bits is used, and it would be much better
237to use at least 4096 or 8192 bits.
238This situation should be monitored to ensure that it does
239not go out of date.
240.Pp
241Encryption, decryption, signing and verification of
242files are the lifeblood of the
243.Nm
244library.
245To encrypt a file, the
246.Fn netpgp_encrypt_file
247and the
248.Fn netpgp_decrypt_file
249is used to decrypt the results of the encryption.
250To sign a file, the
251.Fn netpgp_sign_file
252is used, and the resulting signed file can be verified
253using the
254.Fn netpgp_verify_file
255function.
256.Pp
257.Fn netpgp_sign_memory
258is a function which can sign an area
259of memory, and
260.Fn netpgp_verify_memory
261verifies the digital signature produced.
262.Pp
263Internally, an encrypted or signed file
264is made up of
265.Dq packets
266which hold information pertaining to the signature,
267encryption method, and the data which is being protected.
268This information can be displayed in a verbose manner using
269the
270.Fn netpgp_list_packets
271function.
272.Pp
273The
274.Fn netpgp_setvar
275and
276.Fn netpgp_getvar
277functions are used to manage the hash algorithm that
278is used with RSA signatures.
279These functions are general purpose functions, and
280are used to set and retrieve values for internal variables.
281For example, they
282can be used to set and to retrieve the
283value of the user id
284which has been set,
285the home directory from which to find the keyrings,
286the verbosity settings, and many more.
287The
288.Fn netpgp_incvar
289function is used to add a numeric increment to the
290internal variable.
291This incremental value can be negative.
292It is primarily used to increase the verbosity settings.
293.Pp
294In
295.Nm
296files are encrypted using the public key of the userid.
297The secret key is used to decrypt the results of that encryption.
298Files are signed using the secret key of the userid.
299The public key is used to verify that the file was signed,
300who signed the file, and the date and time at which it was signed.
301.Pp
302Some utility functions are also provided for debugging, and for
303finding out version and maintainer information from calling programs.
304These are the
305.Fn netpgp_set_debug
306and the
307.Fn netpgp_get_debug
308functions (for getting verbose debugging information on a per-source
309file basis).
310.Pp
311The
312.Fn netpgp_get_info
313returns the version or maintainer information depending upon the
314.Ar type
315argument.
316At the present time, two types are defined:
317.Dq version
318and
319.Dq maintainer .
320A failure to present a known
321.Ar type
322argument to
323.Fn netpgp_get_info
324will result in the string
325.Dq [unknown]
326being returned.
327.Sh SEE ALSO
328.Xr netpgp 1 ,
329.Xr ssl 3
330.Sh HISTORY
331The
332.Nm
333library first appeared in
334.Nx 6.0 .
335.Sh AUTHORS
336.An Ben Laurie ,
337.An Rachel Willmer .
338.An Alistair Crooks Aq Mt agc@NetBSD.org
339wrote this high-level interface.
340.Pp
341This manual page was written by
342.An Alistair Crooks .
343