[svn] GnuPG - r5250 - in branches/STABLE-BRANCH-2-0: . doc g10

svn author wk cvs at cvs.gnupg.org
Mon Jan 11 17:05:27 CET 2010


Author: wk
Date: 2010-01-11 17:05:26 +0100 (Mon, 11 Jan 2010)
New Revision: 5250

Modified:
   branches/STABLE-BRANCH-2-0/NEWS
   branches/STABLE-BRANCH-2-0/doc/gpg.texi
   branches/STABLE-BRANCH-2-0/g10/ChangeLog
   branches/STABLE-BRANCH-2-0/g10/gpg.c
   branches/STABLE-BRANCH-2-0/g10/keyedit.c
   branches/STABLE-BRANCH-2-0/g10/main.h
   branches/STABLE-BRANCH-2-0/g10/options.h
   branches/STABLE-BRANCH-2-0/g10/passphrase.c
Log:
Implement command --passwd for GPG.


Modified: branches/STABLE-BRANCH-2-0/g10/ChangeLog
===================================================================
--- branches/STABLE-BRANCH-2-0/g10/ChangeLog	2010-01-10 14:06:49 UTC (rev 5249)
+++ branches/STABLE-BRANCH-2-0/g10/ChangeLog	2010-01-11 16:05:26 UTC (rev 5250)
@@ -1,3 +1,16 @@
+2010-01-11  Werner Koch  <wk at g10code.com>
+
+	* gpg.c: Add option --passwd.
+	(aPasswd): New.
+	(main): Implement.
+	* keyedit.c (keyedit_passwd): New.
+
+	* gpg.c (oPasswd, oPasswdFD, oPasswdFile, oPasswdRepeat): Change
+	to oPassphrase, oPassphraseFD, oPassphraseFile, oPassphraseRepeat.
+	* options.h (struct): s/passwd_repeat/passphrase_repeat/.
+	* gpg.c (main): Ditto.
+	* passphrase.c (passphrase_to_dek_ext): Ditto.
+
 2009-12-21  Werner Koch  <wk at g10code.com>
 
 	* gpg.c (main): Add dummy options --skip-hidden-recipients and no

Modified: branches/STABLE-BRANCH-2-0/NEWS
===================================================================
--- branches/STABLE-BRANCH-2-0/NEWS	2010-01-10 14:06:49 UTC (rev 5249)
+++ branches/STABLE-BRANCH-2-0/NEWS	2010-01-11 16:05:26 UTC (rev 5250)
@@ -1,7 +1,9 @@
 Noteworthy changes in version 2.0.15 (unreleased)
 -------------------------------------------------
 
+ * New command --passwd for GPG.
 
+
 Noteworthy changes in version 2.0.14 (2009-12-21)
 -------------------------------------------------
 

Modified: branches/STABLE-BRANCH-2-0/doc/gpg.texi
===================================================================
--- branches/STABLE-BRANCH-2-0/doc/gpg.texi	2010-01-10 14:06:49 UTC (rev 5249)
+++ branches/STABLE-BRANCH-2-0/doc/gpg.texi	2010-01-11 16:05:26 UTC (rev 5250)
@@ -586,6 +586,7 @@
 related tasks.  It expects the specification of a key on the command
 line.
 
+
 @c ******** Begin Edit-key Options **********
 @table @asis
 
@@ -888,6 +889,13 @@
 non-exportable. This is a shortcut version of the subcommand "lsign"
 from @option{--edit-key}.
 
+ at ifclear gpgone
+ at item --passwd @var{user_id}
+ at opindex passwd
+Change the passphrase of the secret key belonging to the certificate
+specified as @var{user_id}.  This is a shortcut for the sub-command
+ at code{passwd} in the edit key menu.
+ at end ifclear
 
 @end table
 

Modified: branches/STABLE-BRANCH-2-0/g10/gpg.c
===================================================================
--- branches/STABLE-BRANCH-2-0/g10/gpg.c	2010-01-10 14:06:49 UTC (rev 5249)
+++ branches/STABLE-BRANCH-2-0/g10/gpg.c	2010-01-11 16:05:26 UTC (rev 5250)
@@ -1,6 +1,6 @@
 /* gpg.c - The GnuPG utility (main for gpg)
  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
- *               2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+ *               2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -146,6 +146,7 @@
     aCardStatus,
     aCardEdit,
     aChangePIN,
+    aPasswd,
     aServer,
 
     oTextmode,
@@ -207,10 +208,10 @@
     oCompressLevel,
     oBZ2CompressLevel,
     oBZ2DecompressLowmem,
-    oPasswd,
-    oPasswdFD,
-    oPasswdFile,
-    oPasswdRepeat,
+    oPassphrase,
+    oPassphraseFD,
+    oPassphraseFile,
+    oPassphraseRepeat,
     oCommandFD,
     oCommandFile,
     oQuickRandom,
@@ -389,6 +390,7 @@
   ARGPARSE_c (oFingerprint, "fingerprint", N_("list keys and fingerprints")),
   ARGPARSE_c (aListSecretKeys, "list-secret-keys", N_("list secret keys")),
   ARGPARSE_c (aKeygen,	   "gen-key",  N_("generate a new key pair")),
+  ARGPARSE_c (aGenRevoke, "gen-revoke",N_("generate a revocation certificate")),
   ARGPARSE_c (aDeleteKeys,"delete-keys", 
               N_("remove keys from the public keyring")),
   ARGPARSE_c (aDeleteSecretKeys, "delete-secret-keys",
@@ -397,7 +399,7 @@
   ARGPARSE_c (aLSignKey, "lsign-key"  ,N_("sign a key locally")),
   ARGPARSE_c (aEditKey,  "edit-key"   ,N_("sign or edit a key")),
   ARGPARSE_c (aEditKey,  "key-edit"   ,"@"),
-  ARGPARSE_c (aGenRevoke, "gen-revoke",N_("generate a revocation certificate")),
+  ARGPARSE_c (aPasswd,   "passwd",     N_("change a passphrase")),
   ARGPARSE_c (aDesigRevoke, "desig-revoke","@" ),
   ARGPARSE_c (aExport, "export"           , N_("export keys") ),
   ARGPARSE_c (aSendKeys, "send-keys"     , N_("export keys to a key server") ),
@@ -599,10 +601,10 @@
               "delete-secret-and-public-keys", "@"),
   ARGPARSE_c (aRebuildKeydbCaches, "rebuild-keydb-caches", "@"),
 
-  ARGPARSE_s_s (oPasswd, "passphrase", "@"),
-  ARGPARSE_s_i (oPasswdFD, "passphrase-fd", "@"),
-  ARGPARSE_s_s (oPasswdFile, "passphrase-file", "@"),
-  ARGPARSE_s_i (oPasswdRepeat, "passphrase-repeat", "@"),
+  ARGPARSE_s_s (oPassphrase,      "passphrase", "@"),
+  ARGPARSE_s_i (oPassphraseFD,    "passphrase-fd", "@"),
+  ARGPARSE_s_s (oPassphraseFile,  "passphrase-file", "@"),
+  ARGPARSE_s_i (oPassphraseRepeat,"passphrase-repeat", "@"),
   ARGPARSE_s_i (oCommandFD, "command-fd", "@"),
   ARGPARSE_s_s (oCommandFile, "command-file", "@"),
   ARGPARSE_s_n (oQuickRandom, "debug-quick-random", "@"),
@@ -628,7 +630,6 @@
   ARGPARSE_s_n (aListSigs, "list-sig", "@"),   /* alias */
   ARGPARSE_s_n (aCheckKeys, "check-sig", "@"), /* alias */
   ARGPARSE_s_n (oSkipVerify, "skip-verify", "@"),
-  ARGPARSE_s_n (oSkipVerify, "skip-verify", "@"),
   ARGPARSE_s_n (oSkipHiddenRecipients, "skip-hidden-recipients", "@"),
   ARGPARSE_s_n (oNoSkipHiddenRecipients, "no-skip-hidden-recipients", "@"),
   ARGPARSE_s_n (oCompressKeys, "compress-keys", "@"),
@@ -1430,6 +1431,7 @@
 }
 
 
+/* Print the OpenPGP defined algo numbers.  */
 static void
 print_algo_numbers(int (*checker)(int))
 {
@@ -1997,7 +1999,7 @@
     opt.def_sig_expire="0";
     opt.def_cert_expire="0";
     set_homedir ( default_homedir () );
-    opt.passwd_repeat=1;
+    opt.passphrase_repeat=1;
 
     /* Check whether we have a config file on the command line.  */
     orig_argc = argc;
@@ -2179,6 +2181,7 @@
 	  case aDeleteSecretKeys:
 	  case aDeleteSecretAndPublicKeys:
 	  case aDeleteKeys:
+          case aPasswd:
             set_cmd (&cmd, pargs.r_opt);
             greeting=1;
             break;
@@ -2558,16 +2561,16 @@
 	  case oCompressLevel: opt.compress_level = pargs.r.ret_int; break;
 	  case oBZ2CompressLevel: opt.bz2_compress_level = pargs.r.ret_int; break;
 	  case oBZ2DecompressLowmem: opt.bz2_decompress_lowmem=1; break;
-	  case oPasswd:
+	  case oPassphrase:
 	    set_passphrase_from_string(pargs.r.ret_str);
 	    break;
-	  case oPasswdFD:
+	  case oPassphraseFD:
             pwfd = translate_sys2libc_fd_int (pargs.r.ret_int, 0);
             break;
-	  case oPasswdFile:
+	  case oPassphraseFile:
             pwfd = open_info_file (pargs.r.ret_str, 0, 1);
             break;
-	  case oPasswdRepeat: opt.passwd_repeat=pargs.r.ret_int; break;
+	  case oPassphraseRepeat: opt.passphrase_repeat=pargs.r.ret_int; break;
 	  case oCommandFD:
             opt.command_fd = translate_sys2libc_fd_int (pargs.r.ret_int, 0);
             break;
@@ -3621,6 +3624,17 @@
 	xfree(username);
 	break;
 
+      case aPasswd:
+        if (argc != 1)
+          wrong_args (_("--passwd <user-id>"));
+        else
+          {
+            username = make_username (fname);
+            keyedit_passwd (username);
+            xfree (username);
+          }
+        break;
+
       case aDeleteKeys:
       case aDeleteSecretKeys:
       case aDeleteSecretAndPublicKeys:

Modified: branches/STABLE-BRANCH-2-0/g10/keyedit.c
===================================================================
--- branches/STABLE-BRANCH-2-0/g10/keyedit.c	2010-01-10 14:06:49 UTC (rev 5249)
+++ branches/STABLE-BRANCH-2-0/g10/keyedit.c	2010-01-11 16:05:26 UTC (rev 5250)
@@ -1,6 +1,6 @@
 /* keyedit.c - keyedit stuff
  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
- *               2008, 2009 Free Software Foundation, Inc.
+ *               2008, 2009, 2010 Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -2299,6 +2299,72 @@
     xfree(answer);
 }
 
+
+/* Change the passphrase of the secret key identified by USERNAME.  */
+void
+keyedit_passwd (const char *username)
+{
+  gpg_error_t err;
+  PKT_public_key *pk;
+  unsigned char fpr[MAX_FINGERPRINT_LEN];
+  size_t fprlen;
+  KEYDB_HANDLE kdh = NULL;
+  KBNODE keyblock = NULL;
+
+  pk = xtrycalloc (1, sizeof *pk);
+  if (!pk)
+    {
+      err = gpg_error_from_syserror ();
+      goto leave;
+    }
+  err = get_pubkey_byname (NULL, pk, username, NULL, NULL, 1, 1);
+  if (err)
+    goto leave;
+  fingerprint_from_pk (pk, fpr, &fprlen);
+  while (fprlen < MAX_FINGERPRINT_LEN) 
+    fpr[fprlen++] = 0;
+  
+  kdh = keydb_new (1);
+  if (!kdh)
+    {
+      err = gpg_error (GPG_ERR_GENERAL);
+      goto leave;
+    }
+
+  err = keydb_search_fpr (kdh, fpr);
+  if (err == -1 || gpg_err_code (err) == GPG_ERR_EOF)
+    err = gpg_error (GPG_ERR_NO_SECKEY);
+  if (err)
+    goto leave;
+
+  err = keydb_get_keyblock (kdh, &keyblock);
+  if (err) 
+    goto leave;
+
+  if (!change_passphrase (keyblock))
+    {
+      err = gpg_error (GPG_ERR_GENERAL);
+      goto leave;
+    }
+
+  err = keydb_update_keyblock (kdh, keyblock);
+  if (err)
+    log_error( _("update secret failed: %s\n"), gpg_strerror (err));
+
+ leave:
+  release_kbnode (keyblock);
+  if (pk)
+    free_public_key (pk);
+  keydb_release (kdh);
+  if (err)
+    {
+      log_info ("error changing the passphrase for `%s': %s\n", 
+                username, gpg_strerror (err));
+      write_status_error ("keyedit.passwd", gpg_err_code (err));
+    }
+}
+
+
 static void
 tty_print_notations(int indent,PKT_signature *sig)
 {

Modified: branches/STABLE-BRANCH-2-0/g10/main.h
===================================================================
--- branches/STABLE-BRANCH-2-0/g10/main.h	2010-01-10 14:06:49 UTC (rev 5249)
+++ branches/STABLE-BRANCH-2-0/g10/main.h	2010-01-11 16:05:26 UTC (rev 5250)
@@ -213,6 +213,7 @@
 /*-- keyedit.c --*/
 void keyedit_menu( const char *username, strlist_t locusr,
 		   strlist_t commands, int quiet, int seckey_check );
+void keyedit_passwd (const char *username);
 void show_basic_key_info (KBNODE keyblock);
 
 /*-- keygen.c --*/

Modified: branches/STABLE-BRANCH-2-0/g10/options.h
===================================================================
--- branches/STABLE-BRANCH-2-0/g10/options.h	2010-01-10 14:06:49 UTC (rev 5249)
+++ branches/STABLE-BRANCH-2-0/g10/options.h	2010-01-11 16:05:26 UTC (rev 5250)
@@ -246,7 +246,7 @@
     struct akl *next;
   } *auto_key_locate;
 
-  int passwd_repeat;
+  int passphrase_repeat;
 } opt;
 
 /* CTRL is used to keep some global variables we currently can't

Modified: branches/STABLE-BRANCH-2-0/g10/passphrase.c
===================================================================
--- branches/STABLE-BRANCH-2-0/g10/passphrase.c	2010-01-10 14:06:49 UTC (rev 5249)
+++ branches/STABLE-BRANCH-2-0/g10/passphrase.c	2010-01-11 16:05:26 UTC (rev 5250)
@@ -644,7 +644,7 @@
 
       /* Divert to the gpg-agent. */
       pw = passphrase_get (keyid, mode == 2, s2k_cacheid,
-                           (mode == 2 || mode == 4)? opt.passwd_repeat : 0,
+                           (mode == 2 || mode == 4)? opt.passphrase_repeat : 0,
                            tryagain_text, custdesc, custprompt, canceled);
       if (*canceled)
         {




More information about the Gnupg-commits mailing list