Skip to content

Commit 01f3f25

Browse files
committed
* preset-passphrase.c (preset_passphrase): Handle --passphrase.
* Makefile.am (gpg_preset_passphrase_LDADD): Reorder libs so that pwquery may use stuff from jnlib. Conditionally add -lwsock2 (gpg_protect_tool_LDADD): Ditto. * preset-passphrase.c (main): Use default_homedir(). (main) [W32]: Initialize sockets. * simple-pwquery.c (agent_open) [W32]: Implement for W32. (readline) [W32]: Use recv instead of read. (writen) [W32]: Use send instead of write. (my_stpcpy): Define a stpcpy replacement so that this file continues to be self-contained. (agent_send_all_options) [W32]: Don't call ttyname. * gnupg-badge-openpgp.eps, gnupg-badge-openpgp.jpg: New * gnupg.texi: Add a logo. * sysnotes.texi: New. * gpgsm.c (main): Use default_homedir(). (main) [W32]: Default to disabled CRL checks. * gpgconf-comp.c (get_config_pathname) [DOSISH]: Detect absolute pathnames with a drive letter.
1 parent 7b9e5a3 commit 01f3f25

25 files changed

+8986
-31
lines changed

agent/ChangeLog

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
1+
2004-12-21 Werner Koch <[email protected]>
2+
3+
* preset-passphrase.c (preset_passphrase): Handle --passphrase.
4+
5+
* Makefile.am (gpg_preset_passphrase_LDADD): Reorder libs so that
6+
pwquery may use stuff from jnlib. Conditionally add -lwsock2
7+
(gpg_protect_tool_LDADD): Ditto.
8+
9+
* preset-passphrase.c (main): Use default_homedir().
10+
(main) [W32]: Initialize sockets.
11+
12+
2004-12-21 Marcus Brinkmann <[email protected]>
13+
14+
* Makefile.am (libexec_PROGRAMS): Add gpg-preset-passphrase.
15+
(gpg_preset_passphrase_SOURCES, gpg_preset_passphrase_LDADD): New
16+
targets.
17+
* agent.h (opt): New member allow_cache_passphrase.
18+
* cache.c (housekeeping): Check if R->ttl is not negative.
19+
(agent_put_cache): Allow ttl to be negative.
20+
* command.c (parse_hexstring): Allow something to follow the
21+
hexstring.
22+
(cmd_cache_passphrase): New function.
23+
(register_commands): Add it.
24+
* gpg-agent.c: Handle --allow-preset-passphrase.
25+
* preset-passphrase.c: New file.
26+
127
2004-12-21 Werner Koch <[email protected]>
228

329
* gpg-agent.c (main): Use default_homedir().
4-
* protect-tool.c (main): Ditto.
5-
30+
* protect-tool.c (main): Ditto.
631

732
2004-12-20 Werner Koch <[email protected]>
833

agent/Makefile.am

+15-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
## Process this file with automake to produce Makefile.in
2020

2121
bin_PROGRAMS = gpg-agent
22-
libexec_PROGRAMS = gpg-protect-tool
22+
libexec_PROGRAMS = gpg-protect-tool gpg-preset-passphrase
2323

2424
AM_CPPFLAGS = -I$(top_srcdir)/common -I$(top_srcdir)/intl
2525

@@ -53,8 +53,20 @@ gpg_protect_tool_SOURCES = \
5353
protect.c \
5454
minip12.c minip12.h
5555

56-
gpg_protect_tool_LDADD = ../jnlib/libjnlib.a \
57-
../common/libcommon.a ../common/libsimple-pwquery.a \
56+
gpg_protect_tool_LDADD = ../common/libsimple-pwquery.a \
57+
../jnlib/libjnlib.a ../common/libcommon.a \
5858
$(LIBGCRYPT_LIBS) -lgpg-error @LIBINTL@
59+
if HAVE_W32_SYSTEM
60+
gpg_protect_tool_LDADD += -lwsock32
61+
endif
5962

63+
gpg_preset_passphrase_SOURCES = \
64+
preset-passphrase.c
65+
66+
gpg_preset_passphrase_LDADD = ../common/libsimple-pwquery.a \
67+
../jnlib/libjnlib.a ../common/libcommon.a \
68+
$(LIBGCRYPT_LIBS) -lgpg-error @LIBINTL@
69+
if HAVE_W32_SYSTEM
70+
gpg_preset_passphrase_LDADD += -lwsock32
71+
endif
6072

agent/agent.h

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct {
6363

6464
int ignore_cache_for_signing;
6565
int allow_mark_trusted;
66+
int allow_preset_passphrase;
6667
int keep_tty; /* don't switch the TTY (for pinentry) on request */
6768
int keep_display; /* don't switch the DISPLAY (for pinentry) on request */
6869
} opt;

agent/cache.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct cache_item_s {
3939
ITEM next;
4040
time_t created;
4141
time_t accessed;
42-
int ttl; /* max. lifetime given in seonds */
42+
int ttl; /* max. lifetime given in seonds, -1 one means infinite */
4343
int lockcount;
4444
struct secret_data_s *pw;
4545
char key[1];
@@ -88,7 +88,8 @@ housekeeping (void)
8888
/* first expire the actual data */
8989
for (r=thecache; r; r = r->next)
9090
{
91-
if (!r->lockcount && r->pw && r->accessed + r->ttl < current)
91+
if (!r->lockcount && r->pw
92+
&& r->ttl >= 0 && r->accessed + r->ttl < current)
9293
{
9394
if (DBG_CACHE)
9495
log_debug (" expired `%s' (%ds after last access)\n",
@@ -118,7 +119,7 @@ housekeeping (void)
118119
Expire old and unused entries after 30 minutes */
119120
for (rprev=NULL, r=thecache; r; )
120121
{
121-
if (!r->pw && r->accessed + 60*30 < current)
122+
if (!r->pw && r->ttl >= 0 && r->accessed + 60*30 < current)
122123
{
123124
if (r->lockcount)
124125
{
@@ -194,7 +195,7 @@ agent_put_cache (const char *key, const char *data, int ttl)
194195
log_debug ("agent_put_cache `%s'\n", key);
195196
housekeeping ();
196197

197-
if (ttl < 1)
198+
if (ttl == 1)
198199
ttl = opt.def_cache_ttl;
199200
if (!ttl)
200201
return 0;

agent/command.c

+60-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ parse_hexstring (ASSUAN_CONTEXT ctx, const char *string, size_t *len)
141141
/* parse the hash value */
142142
for (p=string, n=0; hexdigitp (p); p++, n++)
143143
;
144-
if (*p)
144+
if (*p != ' ' && *p != '\t' && *p)
145145
return set_error (Parameter_Error, "invalid hexstring");
146146
if ((n&1))
147147
return set_error (Parameter_Error, "odd number of digits");
@@ -741,6 +741,64 @@ cmd_passwd (ASSUAN_CONTEXT ctx, char *line)
741741
return map_to_assuan_status (rc);
742742
}
743743

744+
/* PRESET_PASSPHRASE <hexstring_with_keygrip> <timeout> <passwd>
745+
746+
Set the cached passphrase/PIN for the key identified by the keygrip
747+
to passwd for the given time, where -1 means infinite and 0 means
748+
the default (currently only a timeout of -1 is allowed, which means
749+
to never expire it). If passwd is not provided, ask for it via the
750+
pinentry module. */
751+
static int
752+
cmd_preset_passphrase (ASSUAN_CONTEXT ctx, char *line)
753+
{
754+
int rc;
755+
unsigned char grip[20];
756+
char *grip_clear = NULL;
757+
char *passphrase = NULL;
758+
int ttl;
759+
760+
if (!opt.allow_preset_passphrase)
761+
return gpg_error (GPG_ERR_NOT_SUPPORTED);
762+
763+
rc = parse_keygrip (ctx, line, grip);
764+
if (rc)
765+
return rc;
766+
767+
/* FIXME: parse_keygrip should return a tail pointer. */
768+
grip_clear = line;
769+
while (*line && (*line != ' ' && *line != '\t'))
770+
line++;
771+
if (!*line)
772+
return map_to_assuan_status (gpg_error (GPG_ERR_MISSING_VALUE));
773+
*line = '\0';
774+
line++;
775+
while (*line && (*line == ' ' || *line == '\t'))
776+
line++;
777+
778+
/* Currently, only infinite timeouts are allowed. */
779+
ttl = -1;
780+
if (line[0] != '-' || line[1] != '1')
781+
return map_to_assuan_status (gpg_error (GPG_ERR_NOT_IMPLEMENTED));
782+
line++;
783+
line++;
784+
while (!(*line != ' ' && *line != '\t'))
785+
line++;
786+
787+
/* If there is a passphrase, use it. Currently, a passphrase is
788+
required. */
789+
if (*line)
790+
passphrase = line;
791+
else
792+
return map_to_assuan_status (gpg_error (GPG_ERR_NOT_IMPLEMENTED));
793+
794+
rc = agent_put_cache (grip_clear, passphrase, ttl);
795+
796+
if (rc)
797+
log_error ("command preset_passwd failed: %s\n", gpg_strerror (rc));
798+
799+
return map_to_assuan_status (rc);
800+
}
801+
744802

745803
/* SCD <commands to pass to the scdaemon>
746804
@@ -837,6 +895,7 @@ register_commands (ASSUAN_CONTEXT ctx)
837895
{ "PKDECRYPT", cmd_pkdecrypt },
838896
{ "GENKEY", cmd_genkey },
839897
{ "GET_PASSPHRASE", cmd_get_passphrase },
898+
{ "PRESET_PASSPHRASE", cmd_preset_passphrase },
840899
{ "CLEAR_PASSPHRASE", cmd_clear_passphrase },
841900
{ "GET_CONFIRMATION", cmd_get_confirmation },
842901
{ "LISTTRUSTED", cmd_listtrusted },

agent/gpg-agent.c

+5
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ enum cmd_and_opt_values
8989

9090
oIgnoreCacheForSigning,
9191
oAllowMarkTrusted,
92+
oAllowPresetPassphrase,
9293
oKeepTTY,
9394
oKeepDISPLAY
9495
};
@@ -141,6 +142,8 @@ static ARGPARSE_OPTS opts[] = {
141142
N_("do not use the PIN cache when signing")},
142143
{ oAllowMarkTrusted, "allow-mark-trusted", 0,
143144
N_("allow clients to mark keys as \"trusted\"")},
145+
{ oAllowPresetPassphrase, "allow-preset-passphrase", 0,
146+
N_("allow presetting passphrase")},
144147
{0}
145148
};
146149

@@ -392,6 +395,8 @@ parse_rereadable_options (ARGPARSE_ARGS *pargs, int reread)
392395

393396
case oAllowMarkTrusted: opt.allow_mark_trusted = 1; break;
394397

398+
case oAllowPresetPassphrase: opt.allow_preset_passphrase = 1; break;
399+
395400
default:
396401
return 0; /* not handled */
397402
}

0 commit comments

Comments
 (0)