3 * $Id: passphrase.c,v 1.5 2002/01/13 13:41:37 mdw Exp $
5 * Reading of passphrases (Unix-specific)
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Revision history --------------------------------------------------*
32 * $Log: passphrase.c,v $
33 * Revision 1.5 2002/01/13 13:41:37 mdw
34 * Fix stupidity in passphrase verification.
36 * Revision 1.4 2001/04/19 18:26:01 mdw
37 * Re-request broken passphrases.
39 * Revision 1.3 2000/12/06 20:33:27 mdw
40 * Make flags be macros rather than enumerations, to ensure that they're
43 * Revision 1.2 2000/06/17 11:49:37 mdw
44 * New pixie protocol allowing application to request passphrases and send
47 * Revision 1.1 1999/12/22 15:58:20 mdw
48 * Portable interface to reading passphrases.
52 /*----- Header files ------------------------------------------------------*/
61 #include <mLib/dstr.h>
63 #include "passphrase.h"
66 /*----- Static variables --------------------------------------------------*/
69 static unsigned flags
= 0;
73 /*----- Main code ---------------------------------------------------------*/
79 * Returns: Zero if OK, nonzero if it failed
81 * Use: Attempts to connect to the passphrase pixie.
84 static int pconn(void)
90 if ((fd
= pixie_open(0)) < 0) {
97 /* --- @passphrase_read@ --- *
99 * Arguments: @const char *tag@ = pointer to passphrase tag string
100 * @unsigned mode@ = reading mode
101 * @char *buf@ = pointer to destination buffer
102 * @size_t sz@ = size of destination buffer
104 * Returns: Zero if successful, nonzero on failure.
106 * Use: Reads a passphrase from the user, using some system-specific
107 * secure mechanism. The mechanism may keep a cache of
108 * passphrases, so the user may not necessarily be prompted.
111 int passphrase_read(const char *tag
, unsigned mode
, char *buf
, size_t sz
)
116 /* --- Try talking to the pixie --- */
119 rc
= pixie_read(fd
, tag
, mode
, buf
, sz
);
129 /* --- Read from the terminal --- */
131 dstr_putf(&d
, "%s %s: ",
132 mode
== PMODE_READ ?
"Passphrase" : "New passphrase",
134 if (pixie_getpass(d
.buf
, buf
, sz
))
136 if (mode
== PMODE_VERIFY
) {
139 dstr_putf(&d
, "Verify passphrase %s: ", tag
);
140 if (pixie_getpass(d
.buf
, b
, sizeof(b
)) || strcmp(b
, buf
) != 0) {
141 memset(b
, 0, sizeof(b
));
147 /* --- If the pixie is interested, tell it the new passphrase --- */
150 pixie_set(fd
, tag
, buf
);
153 /* --- Tidy up after a failure --- */
161 /* --- @passphrase_cancel@ --- *
163 * Arguments: @const char *tag@ = pointer to passphrase tag string
167 * Use: Attempts to make the passphrase cache forget about a
168 * particular passphrase. This may be useful if the passphrase
169 * turns out to be wrong, or if the user is attempting to change
173 void passphrase_cancel(const char *tag
)
176 pixie_cancel(fd
, tag
);
179 /*----- That's all, folks -------------------------------------------------*/