diff options
author | Thomas Roessler <roessler@does-not-exist.org> | 1998-06-16 10:47:52 +0000 |
---|---|---|
committer | Thomas Roessler <roessler@does-not-exist.org> | 1998-06-16 10:47:52 +0000 |
commit | 1a7ec5c051d1d9ba5c9b5d28b0420d3878a54c26 (patch) | |
tree | 437a3671de8aff6de9a0b98c78fe098b2938636e | |
parent | 60f9c49775bd1f09b930718d928bf9143ec319a0 (diff) |
Include part of Werner Koch's latest GPG patches.
-rw-r--r-- | gnupgparse.c | 83 | ||||
-rw-r--r-- | pgpinvoke.c | 34 |
2 files changed, 80 insertions, 37 deletions
diff --git a/gnupgparse.c b/gnupgparse.c index 38972823..6f928e88 100644 --- a/gnupgparse.c +++ b/gnupgparse.c @@ -99,13 +99,15 @@ static short get_abilities(unsigned char type) */ static KEYINFO * -parse_pub_line( char *buf ) +parse_pub_line( char *buf, int *is_subkey ) { KEYINFO *k=NULL; PGPUID *uid = NULL; int field = 0; char *pend, *p; + int trust = 0; + *is_subkey = 0; if( !*buf ) return NULL; for( p = buf; p; p = pend ) { @@ -117,17 +119,28 @@ parse_pub_line( char *buf ) switch( field ) { case 1: /* record type */ - if( strcmp(p,"pub") ) + if( !strcmp(p,"pub") ) + ; + else if( !strcmp(p,"sub") ) + *is_subkey = 1; + else if( !strcmp(p,"sec") ) + ; + else if( !strcmp(p,"ssb") ) + *is_subkey = 1; + else return NULL; k = safe_malloc( sizeof(KEYINFO) ); - k->keyid = NULL; - k->address = NULL; - k->flags = 0; - k->next = NULL; - k->keylen = 0; + memset(k, 0, sizeof(KEYINFO) ); break; case 2: /* trust info */ - /* k_>flags |= KEYFLAG_EXPIRED */ + switch( *p ) { /* look only at the first letter */ + case 'e': k->flags |= KEYFLAG_EXPIRED; break; + case 'n': trust = 1; break; + case 'm': trust = 2; break; + case 'f': trust = 3; break; + case 'u': trust = 3; break; + case 'r': k->flags |= KEYFLAG_REVOKED; break; + } break; case 3: /* key length */ k->keylen = atoi(p); /* fixme: add validation checks */ @@ -142,18 +155,22 @@ parse_pub_line( char *buf ) break; case 6: /* timestamp (1998-02-28) */ break; - case 7: /* Local id */ + case 7: /* valid for n days */ break; - case 8: /* ownertrust */ + case 8: /* Local id */ break; - case 9: /* name */ + case 9: /* ownertrust */ + break; + case 10: /* name */ + if( !pend || !*p ) + break; /* empty field or no trailing colon */ k->address = mutt_new_list(); k->address->data = safe_malloc( sizeof(PGPUID) ); uid = (PGPUID *)k->address->data; uid->addr = safe_strdup(p); - uid->trust = 0; + uid->trust = trust; break; - case 10: /* signature class */ + case 11: /* signature class */ break; default: break; @@ -165,7 +182,7 @@ parse_pub_line( char *buf ) static pid_t gpg_invoke_list_keys(struct pgp_vinfo *pgp, FILE **pgpin, FILE **pgpout, FILE **pgperr, int pgpinfd, int pgpoutfd, int pgperrfd, - const char *uids) + const char *uids, int secret) { char cmd[HUGE_STRING]; char tmpcmd[HUGE_STRING]; @@ -174,8 +191,8 @@ static pid_t gpg_invoke_list_keys(struct pgp_vinfo *pgp, /* we use gpgm here */ snprintf(cmd, sizeof(cmd), - "%sm --no-verbose --batch --with-colons --list-keys ", - NONULL(*pgp->binary)); + "%sm --no-verbose --batch --with-colons --list-%skeys ", + NONULL(*pgp->binary), secret? "secret-":""); keylist = safe_strdup(uids); for(cp = strtok(keylist, " "); cp ; cp = strtok(NULL, " ")) @@ -185,29 +202,43 @@ static pid_t gpg_invoke_list_keys(struct pgp_vinfo *pgp, strcpy(cmd, tmpcmd); } safe_free((void **) &keylist); - return mutt_create_filter_fd(cmd, pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd); } -KEYINFO *gpg_read_pubring(struct pgp_vinfo *pgp) +static KEYINFO * +read_ring(struct pgp_vinfo *pgp, int secret ) { FILE *fp; pid_t thepid; char buf[LONG_STRING]; - KEYINFO *db = NULL, **kend, *k = NULL; + KEYINFO *db = NULL, **kend, *k = NULL, *kk, *mainkey=NULL; + int is_sub; - thepid = gpg_invoke_list_keys(pgp, NULL, &fp, NULL, -1, -1, -1, NULL); + thepid = gpg_invoke_list_keys(pgp, NULL, &fp, NULL, -1, -1, -1, + NULL, secret); if( thepid == -1 ) return NULL; kend = &db; k = NULL; while( fgets( buf, sizeof(buf)-1, fp ) ) { + kk = parse_pub_line(buf, &is_sub ); + if( !kk ) + continue; if( k ) kend = &k->next; - *kend = k = parse_pub_line(buf); + *kend = k = kk; + + if( is_sub ) { + k->flags |= KEYFLAG_SUBKEY; + k->mainkey = mainkey; } + else + mainkey = k; + } + if( ferror(fp) ) + mutt_perror("fgets"); fclose( fp ); mutt_wait_filter( thepid ); @@ -216,9 +247,13 @@ KEYINFO *gpg_read_pubring(struct pgp_vinfo *pgp) } +KEYINFO *gpg_read_pubring(struct pgp_vinfo *pgp) +{ + return read_ring( pgp, 0 ); +} + + KEYINFO *gpg_read_secring(struct pgp_vinfo *pgp) { - mutt_error("gpg_read_secring() has not yet been implemented."); - sleep(1); - return NULL; + return read_ring( pgp, 1 ); } diff --git a/pgpinvoke.c b/pgpinvoke.c index d69c3800..d210eb0b 100644 --- a/pgpinvoke.c +++ b/pgpinvoke.c @@ -330,8 +330,7 @@ pid_t pgp_gpg_invoke_decode(struct pgp_vinfo *pgp, char cmd[HUGE_STRING]; snprintf(cmd, sizeof(cmd), - "%s%s --no-verbose -v --batch --status-fd 2 -o - " - "--decrypt %s", + "%s%s --no-verbose --batch --status-fd 2 -o - %s", NONULL(*pgp->binary), need_passphrase? " --passphrase-fd 0":"", fname); @@ -363,7 +362,7 @@ pid_t pgp_gpg_invoke_decrypt(struct pgp_vinfo *pgp, char cmd[HUGE_STRING]; snprintf(cmd, sizeof(cmd), - "%s --passphrase-fd 0 --no-verbose -v --batch --status-fd 2 -o - " + "%s --passphrase-fd 0 --no-verbose --batch --status-fd 2 -o - " "--decrypt %s", NONULL(*pgp->binary), fname ); @@ -396,13 +395,13 @@ pid_t pgp_gpg_invoke_sign(struct pgp_vinfo *pgp, char cmd[HUGE_STRING]; snprintf(cmd, sizeof(cmd), - "%s --no-verbose -vv --batch --status-fd 2 -o - " + "%s --no-verbose --batch --status-fd 2 -o - " "--passphrase-fd 0 --digest-algo %s " "--detach-sign --textmode --armor %s%s %s", NONULL(*pgp->binary), gpg_digalg(), - *PgpSignAs? "-u " : "", - *PgpSignAs? PgpSignAs : "", fname ); + PgpSignAs? "-u " : "", + PgpSignAs? PgpSignAs : "", fname ); return mutt_create_filter_fd(cmd, pgpin, pgpout, pgperr, @@ -422,15 +421,15 @@ pid_t pgp_gpg_invoke_encrypt(struct pgp_vinfo *pgp, char *keylist; snprintf(cmd, sizeof(cmd), - "%s%s --no-verbose --batch --status-fd 2 -o - " + "%s%s --no-verbose -v --batch --status-fd 2 -o - " "--digest-algo %s " - "--encrypt%s --textmode --armor %s%s", + "--encrypt%s --textmode --armor --always-trust %s%s", NONULL(*pgp->binary), sign? " --passphrase-fd 0":"", gpg_digalg(), sign? " --sign":"", - *PgpSignAs? "-u " : "", - *PgpSignAs? PgpSignAs : "" ); + PgpSignAs? "-u " : "", + PgpSignAs? PgpSignAs : "" ); keylist = safe_strdup(uids); @@ -450,15 +449,24 @@ pid_t pgp_gpg_invoke_encrypt(struct pgp_vinfo *pgp, void pgp_gpg_invoke_import(struct pgp_vinfo *pgp, const char *fname) { - mutt_error("pgp_gpg_invoke_import() has not yet been implemented."); + char cmd[HUGE_STRING]; + + snprintf(cmd, sizeof(cmd), "%sm --no-verbose --import -v %s", + NONULL (*pgp->binary), fname); + mutt_system(cmd); } pid_t pgp_gpg_invoke_export(struct pgp_vinfo *pgp, FILE **pgpin, FILE **pgpout, FILE **pgperr, int pgpinfd, int pgpoutfd, int pgperrfd, const char *id) { - mutt_error("pgp_gpg_invoke_export() has not yet been implemented."); - return -1; + char cmd[HUGE_STRING]; + + snprintf(cmd, sizeof(cmd), "%sm --no-verbose --export --armor 0x%8s", + NONULL (*pgp->binary), id); + + return mutt_create_filter_fd(cmd, pgpin, pgpout, pgperr, + pgpinfd, pgpoutfd, pgperrfd); } |