- else if (mode == 1 )
- atext = m_strdup ( _("Enter passphrase\n") );
- else
- atext = m_strdup ( _("Repeat passphrase\n") );
-
- if ( (fd = agent_open (&prot)) == -1 )
- goto failure;
-
- if (!prot)
- { /* old style protocol */
- n = 4 + 20 + strlen (atext);
- u32tobuf (buf, n );
- u32tobuf (buf+4, GPGA_PROT_GET_PASSPHRASE );
- memcpy (buf+8, fpr, 20 );
- if ( writen ( fd, buf, 28 ) || writen ( fd, atext, strlen (atext) ) )
- goto failure;
- m_free (atext); atext = NULL;
-
- /* get response */
- if ( readn ( fd, buf, 12, &nread ) )
- goto failure;
-
- if ( nread < 8 )
- {
- log_error ( "response from agent too short\n" );
- goto failure;
- }
- n = buftou32 ( buf );
- reply = buftou32 ( buf + 4 );
- if ( reply == GPGA_PROT_GOT_PASSPHRASE )
- {
- size_t pwlen;
- size_t nn;
-
- if ( nread < 12 || n < 8 )
- {
- log_error ( "response from agent too short\n" );
- goto failure;
- }
- pwlen = buftou32 ( buf + 8 );
- nread -= 12;
- n -= 8;
- if ( pwlen > n || n > 1000 )
- {
- log_error (_("passphrase too long\n"));
- /* or protocol error */
- goto failure;
- }
- /* we read the whole block in one chunk to give no hints
- * on how long the passhrase actually is - this wastes some bytes
- * but because we already have this padding we should not loosen
- * this by issuing 2 read calls */
- pw = m_alloc_secure ( n+1 );
- if ( readn ( fd, pw, n, &nn ) )
- goto failure;
- if ( n != nn )
- {
- log_error (_("invalid response from agent\n"));
- goto failure;
- }
- pw[pwlen] = 0; /* make a C String */
- agent_close (fd);
- free_public_key( pk );
- return pw;
- }
- else if ( reply == GPGA_PROT_CANCELED )
- log_info ( _("cancelled by user\n") );
- else
- log_error ( _("problem with the agent: agent returns 0x%lx\n"),
- (ulong)reply );
- }