[OpenPGP:SDK svn] r590 - openpgpsdk/trunk/src/lib

Subversion ben at links.org
Wed Aug 20 17:31:13 BST 2008


Author: rachel
Date: 2008-08-20 17:31:13 +0100 (Wed, 20 Aug 2008)
New Revision: 590

Modified:
   openpgpsdk/trunk/src/lib/readerwriter.c
Log:
Don't ask for passphrase if none is needed.


Modified: openpgpsdk/trunk/src/lib/readerwriter.c
===================================================================
--- openpgpsdk/trunk/src/lib/readerwriter.c	2008-08-19 15:15:45 UTC (rev 589)
+++ openpgpsdk/trunk/src/lib/readerwriter.c	2008-08-20 16:31:13 UTC (rev 590)
@@ -269,26 +269,20 @@
         if (!cbinfo->cryptinfo.keydata || !ops_key_is_secret(cbinfo->cryptinfo.keydata))
             return 0;
 
-        /* do we need the passphrase and not have it? if so, get it */
-        if (!cbinfo->cryptinfo.passphrase)
-            {
-            memset(&pc,'\0',sizeof pc);
-            pc.content.secret_key_passphrase.passphrase=&cbinfo->cryptinfo.passphrase;
-            CB(cbinfo,OPS_PARSER_CMD_GET_SK_PASSPHRASE,&pc);
-            if (!cbinfo->cryptinfo.passphrase)
-                {
-                fprintf(stderr,"can't get passphrase\n");
-                assert(0);
-                }
-            }
-
         /* now get the key from the data */
         secret=ops_get_secret_key_from_data(cbinfo->cryptinfo.keydata);
         while(!secret)
             {
             if (!cbinfo->cryptinfo.passphrase)
                 {
-                /* get the passphrase again?*/
+                memset(&pc,'\0',sizeof pc);
+                pc.content.secret_key_passphrase.passphrase=&cbinfo->cryptinfo.passphrase;
+                CB(cbinfo,OPS_PARSER_CMD_GET_SK_PASSPHRASE,&pc);
+                if (!cbinfo->cryptinfo.passphrase)
+                    {
+                    fprintf(stderr,"can't get passphrase\n");
+                    assert(0);
+                    }
                 }
             /* then it must be encrypted */
             secret=ops_decrypt_secret_key_from_data(cbinfo->cryptinfo.keydata,cbinfo->cryptinfo.passphrase);
@@ -305,59 +299,9 @@
     return OPS_RELEASE_MEMORY;
     }
 
-static void echo_off()
-    {
-#ifndef WIN32
-    struct termios term;
-    int r;
-
-    r=tcgetattr(0,&term);
-    if(r < 0 && errno == ENOTTY)
-	return;
-    assert(r >= 0);
-
-    term.c_lflag &= ~ECHO;
-
-    r=tcsetattr(0,TCSANOW,&term);
-    assert(r >= 0);
-#endif
-    }
-	
-static void echo_on()
-    {
-#ifndef WIN32
-    struct termios term;
-    int r;
-
-    r=tcgetattr(0,&term);
-    if(r < 0 && errno == ENOTTY)
-	return;
-    assert(r >= 0);
-
-    term.c_lflag |= ECHO;
-
-    r=tcsetattr(0,TCSANOW,&term);
-    assert(r >= 0);
-#endif
-    }
-
 char *ops_get_passphrase(void)
     {
-    char buffer[1024];
-    size_t n;
-
-    printf("Passphrase: ");
-    
-    echo_off();
-    fgets(buffer,sizeof buffer,stdin);
-    echo_on();
-
-    putchar('\n');
-
-    n=strlen(buffer);
-    if(n && buffer[n-1] == '\n')
-	buffer[--n]='\0';
-    return ops_malloc_passphrase(buffer);
+    return ops_malloc_passphrase(getpass("Passphrase: "));
     }
 
 char *ops_malloc_passphrase(char *pp)



More information about the OpenPGPsdk-svn mailing list