them to the pixie.
/* -*-c-*-
*
- * $Id: passphrase.c,v 1.1 1999/12/22 15:58:20 mdw Exp $
+ * $Id: passphrase.c,v 1.2 2000/06/17 11:49:37 mdw Exp $
*
* Reading of passphrases (Unix-specific)
*
/*----- Revision history --------------------------------------------------*
*
* $Log: passphrase.c,v $
+ * Revision 1.2 2000/06/17 11:49:37 mdw
+ * New pixie protocol allowing application to request passphrases and send
+ * them to the pixie.
+ *
* Revision 1.1 1999/12/22 15:58:20 mdw
* Portable interface to reading passphrases.
*
int passphrase_read(const char *tag, unsigned mode, char *buf, size_t sz)
{
dstr d = DSTR_INIT;
+ int rc = 1;
/* --- Try talking to the pixie --- */
if (!pconn()) {
- if (pixie_read(fd, tag, mode, buf, sz)) {
+ rc = pixie_read(fd, tag, mode, buf, sz);
+ if (rc < 0) {
close(fd);
fd = -1;
return (-1);
}
- return (0);
+ if (rc == 0)
+ return (0);
}
/* --- Read from the terminal --- */
- dstr_putf(&d, "Passphrase %s: ", tag);
+ dstr_putf(&d, "%s %s: ",
+ mode == PMODE_READ ? "Passphrase" : "New passphrase",
+ tag);
if (pixie_getpass(d.buf, buf, sz))
goto fail;
if (mode == PMODE_VERIFY) {
}
}
dstr_destroy(&d);
+
+ /* --- If the pixie is interested, tell it the new passphrase --- */
+
+ if (fd >= 0)
+ pixie_set(fd, tag, buf);
return (0);
/* --- Tidy up after a failure --- */
/* -*-c-*-
*
- * $Id: pixie-client.c,v 1.1 1999/12/22 15:58:41 mdw Exp $
+ * $Id: pixie-client.c,v 1.2 2000/06/17 11:49:37 mdw Exp $
*
* Simple passphrase pixie client (Unix-specific)
*
/*----- Revision history --------------------------------------------------*
*
* $Log: pixie-client.c,v $
+ * Revision 1.2 2000/06/17 11:49:37 mdw
+ * New pixie protocol allowing application to request passphrases and send
+ * them to the pixie.
+ *
* Revision 1.1 1999/12/22 15:58:41 mdw
* Passphrase pixie support.
*
* @char *buf@ = pointer to destination buffer
* @size_t sz@ = size of the buffer
*
- * Returns: Zero if all went well, nonzero if the read fails.
+ * Returns: Zero if all went well, @-1@ if the read fails, @+1@ to
+ * request the passphrase from the user.
*
* Use: Reads a passphrase from the pixie.
*/
return (-1);
if (strcmp(q, "INFO") == 0)
goto again;
+ else if (strcmp(q, "MISSING") == 0)
+ return (+1);
else if (strcmp(q, "OK") != 0)
return (-1);
return (0);
}
+/* --- @pixie_set@ --- *
+ *
+ * Arguments: @int fd@ = pixie file descriptor
+ * @const char *tag@ = pointer to tag string
+ * @const char *phrase@ = pointer to passphrase string
+ *
+ * Returns: ---
+ *
+ * Use: Sends a passphrase to the passphrase pixie.
+ */
+
+void pixie_set(int fd, const char *tag, const char *phrase)
+{
+ dstr d = DSTR_INIT;
+ char buf[16];
+ size_t sz = strlen(phrase);
+ char nl = '\n';
+ char *p, *q;
+
+ /* --- Send the request --- *
+ *
+ * I didn't want to copy it out of the caller's buffer. @writev@ may
+ * produce a copy, too, so I didn't do that either.
+ */
+
+ dstr_putf(&d, "SET %s -- ", tag);
+ write(fd, d.buf, d.len);
+ write(fd, phrase, sz);
+ write(fd, &nl, 1);
+ dstr_destroy(&d);
+
+ /* --- Pick up the pieces --- */
+
+again:
+ pixie_fdline(fd, buf, sizeof(buf));
+ p = buf;
+ if ((q = str_getword(&p)) != 0 && strcmp(q, "INFO") == 0)
+ goto again;
+}
+
/* --- @pixie_cancel@ --- *
*
* Arguments: @int fd@ = pixie file descriptor
/* -*-c-*-
*
- * $Id: pixie.h,v 1.1 1999/12/22 15:58:41 mdw Exp $
+ * $Id: pixie.h,v 1.2 2000/06/17 11:49:49 mdw Exp $
*
* Passphrase pixie definitions (Unix-specific)
*
/*----- Revision history --------------------------------------------------*
*
* $Log: pixie.h,v $
+ * Revision 1.2 2000/06/17 11:49:49 mdw
+ * New pixie protocol allowing application to request passphrases and send
+ * them to the pixie.
+ *
* Revision 1.1 1999/12/22 15:58:41 mdw
* Passphrase pixie support.
*
* VERIFY tag [expire]
* Request a new passphrase, which therefore requires verification.
*
+ * SET tag [expire] -- phrase
+ * Set the value of passphrase `tag'. This will usually be a follow-up
+ * to a MISSING response.
+ *
* FLUSH [tag]
* Flush the passphrase named `tag', or all passphrases, from memory.
*
* Request completed successfully. If a passphrase was requested, it is
* returned by the pixie. This is the final response to a request.
*
+ * MISSING
+ * The passphrase requested is not known, and no requester mechanism is
+ * present. The client should request the passphrase itself and pass it
+ * back to the pixie. This is the final response to a request.
+ *
* FAIL error
* Reports an error. The message given is intended to be
* human-readable. This is the final response to a request.
* @char *buf@ = pointer to destination buffer
* @size_t sz@ = size of the buffer
*
- * Returns: Zero if all went well, nonzero if the read fails.
+ * Returns: Zero if all went well, @-1@ if the read fails, @+1@ to
+ * request the passphrase from the user.
*
* Use: Reads a passphrase from the pixie.
*/
extern int pixie_read(int /*fd*/, const char */*tag*/, unsigned /*mode*/,
char */*buf*/, size_t /*sz*/);
+/* --- @pixie_set@ --- *
+ *
+ * Arguments: @int fd@ = pixie file descriptor
+ * @const char *tag@ = pointer to tag string
+ * @const char *phrase@ = pointer to passphrase string
+ *
+ * Returns: ---
+ *
+ * Use: Sends a passphrase to the passphrase pixie.
+ */
+
+extern void pixie_set(int /*fd*/, const char */*tag*/,
+ const char */*phrase*/);
+
/* --- @pixie_cancel@ --- *
*
* Arguments: @int fd@ = pixie file descriptor