xref: /netbsd-src/crypto/external/bsd/openssh/dist/readpassphrase.3 (revision 41768fc151975edf5da042dafee95bcbf07f4525)
1*41768fc1Schristos.\"	$NetBSD: readpassphrase.3,v 1.5 2017/04/18 18:41:46 christos Exp $
2313c6c94Schristos.\"	$OpenBSD: readpassphrase.3,v 1.3 2001/08/06 10:42:25 mpech Exp $
3313c6c94Schristos.\"
4313c6c94Schristos.\" Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com>
5313c6c94Schristos.\" All rights reserved.
6313c6c94Schristos.\"
7313c6c94Schristos.\" Redistribution and use in source and binary forms, with or without
8313c6c94Schristos.\" modification, are permitted provided that the following conditions
9313c6c94Schristos.\" are met:
10313c6c94Schristos.\" 1. Redistributions of source code must retain the above copyright
11313c6c94Schristos.\"    notice, this list of conditions and the following disclaimer.
12313c6c94Schristos.\" 2. Redistributions in binary form must reproduce the above copyright
13313c6c94Schristos.\"    notice, this list of conditions and the following disclaimer in the
14313c6c94Schristos.\"    documentation and/or other materials provided with the distribution.
15313c6c94Schristos.\" 3. The name of the author may not be used to endorse or promote products
16313c6c94Schristos.\"    derived from this software without specific prior written permission.
17313c6c94Schristos.\"
18313c6c94Schristos.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19313c6c94Schristos.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20313c6c94Schristos.\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
21313c6c94Schristos.\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22313c6c94Schristos.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23313c6c94Schristos.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24313c6c94Schristos.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25313c6c94Schristos.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26313c6c94Schristos.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27313c6c94Schristos.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28313c6c94Schristos.\"
29313c6c94Schristos.Dd November 20, 2000
30313c6c94Schristos.Dt READPASSPHRASE 3
31313c6c94Schristos.Os
32313c6c94Schristos.Sh NAME
33313c6c94Schristos.Nm readpassphrase
34313c6c94Schristos.Nd get a passphrase from the user
35313c6c94Schristos.Sh SYNOPSIS
36313c6c94Schristos.In readpassphrase.h
37313c6c94Schristos.Ft char *
38313c6c94Schristos.Fn readpassphrase "const char *prompt" "char *buf" "size_t bufsiz" "int flags"
39313c6c94Schristos.Sh DESCRIPTION
40313c6c94SchristosThe
41313c6c94Schristos.Fn readpassphrase
42313c6c94Schristosfunction displays a prompt to, and reads in a passphrase from,
43313c6c94Schristos.Pa /dev/tty .
44313c6c94SchristosIf this file is inaccessible
45313c6c94Schristosand the
46313c6c94Schristos.Dv RPP_REQUIRE_TTY
47313c6c94Schristosflag is not set,
48313c6c94Schristos.Fn readpassphrase
49313c6c94Schristosdisplays the prompt on the standard error output and reads from the standard
50313c6c94Schristosinput.
51313c6c94SchristosIn this case it is generally not possible to turn off echo.
52313c6c94Schristos.Pp
53313c6c94SchristosUp to
54313c6c94Schristos.Fa bufsiz
55313c6c94Schristos- 1 characters (one is for the NUL) are read into the provided buffer
56313c6c94Schristos.Fa buf .
57313c6c94SchristosAny additional
58313c6c94Schristoscharacters and the terminating newline (or return) character are discarded.
59313c6c94Schristos.Pp
60313c6c94Schristos.Fn readpassphrase
61313c6c94Schristostakes the following optional
62313c6c94Schristos.Fa flags :
63313c6c94Schristos.Pp
64313c6c94Schristos.Bd -literal -offset indent -compact
65313c6c94SchristosRPP_ECHO_OFF		turn off echo (default behavior)
66313c6c94SchristosRPP_ECHO_ON		leave echo on
67313c6c94SchristosRPP_REQUIRE_TTY		fail if there is no tty
68313c6c94SchristosRPP_FORCELOWER		force input to lower case
69313c6c94SchristosRPP_FORCEUPPER		force input to upper case
70313c6c94SchristosRPP_SEVENBIT		strip the high bit from input
71313c6c94Schristos.Ed
72313c6c94Schristos.Pp
73313c6c94SchristosThe calling process should zero the passphrase as soon as possible to
74313c6c94Schristosavoid leaving the cleartext passphrase visible in the process's address
75313c6c94Schristosspace.
76313c6c94Schristos.Sh RETURN VALUES
77313c6c94SchristosOn success,
78313c6c94Schristos.Fn readpassphrase
79313c6c94Schristosreturns a pointer to the null-terminated passphrase.
80313c6c94SchristosIf the
81313c6c94Schristos.Dv RPP_REQUIRE_TTY
82313c6c94Schristosflag is set and
83313c6c94Schristos.Pa /dev/tty
84313c6c94Schristosis inaccessible,
85313c6c94Schristos.Fn readpassphrase
86313c6c94Schristosreturns a null pointer.
87313c6c94Schristos.Sh FILES
88313c6c94Schristos.Bl -tag -width /dev/tty -compact
89313c6c94Schristos.It Pa /dev/tty
90313c6c94Schristos.El
91313c6c94Schristos.Sh EXAMPLES
92313c6c94SchristosThe following code fragment will read a passphrase from
93313c6c94Schristos.Pa /dev/tty
94313c6c94Schristosinto the buffer
95313c6c94Schristos.Fa passbuf .
96313c6c94Schristos.Bd -literal -offset indent
97313c6c94Schristoschar passbuf[1024];
98313c6c94Schristos
99313c6c94Schristos\&...
100313c6c94Schristos
101313c6c94Schristosif (readpassphrase("Response: ", passbuf, sizeof(passbuf),
102313c6c94Schristos    RPP_REQUIRE_TTY) == NULL)
103313c6c94Schristos	errx(1, "unable to read passphrase");
104313c6c94Schristos
105313c6c94Schristosif (compare(transform(passbuf), epass) != 0)
106313c6c94Schristos	errx(1, "bad passphrase");
107313c6c94Schristos
108313c6c94Schristos\&...
109313c6c94Schristos
110313c6c94Schristosmemset(passbuf, 0, sizeof(passbuf));
111313c6c94Schristos.Ed
112313c6c94Schristos.Sh SEE ALSO
113313c6c94Schristos.Xr getpass 3
114313c6c94Schristos.Sh HISTORY
115313c6c94SchristosThe
116313c6c94Schristos.Fn readpassphrase
117313c6c94Schristosfunction first appeared in
118313c6c94Schristos.Ox 2.9 .
119