~ubuntu-branches/ubuntu/oneiric/gnupg2/oneiric-updates

« back to all changes in this revision

Viewing changes to agent/pksign.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *
6
6
 * GnuPG is free software; you can redistribute it and/or modify
7
7
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * the Free Software Foundation; either version 3 of the License, or
9
9
 * (at your option) any later version.
10
10
 *
11
11
 * GnuPG is distributed in the hope that it will be useful,
14
14
 * GNU General Public License for more details.
15
15
 *
16
16
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
17
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19
18
 */
20
19
 
21
20
#include <config.h>
38
37
  gcry_sexp_t hash;
39
38
  int rc;
40
39
 
41
 
  if (! raw_value)
 
40
  if (!raw_value)
42
41
    {
43
42
      const char *s;
44
43
      char tmp[16+1];
54
53
 
55
54
      rc = gcry_sexp_build (&hash, NULL,
56
55
                            "(data (flags pkcs1) (hash %s %b))",
57
 
                            tmp, mdlen, md);
 
56
                            tmp, (int)mdlen, md);
58
57
    }
59
58
  else
60
59
    {
76
75
}
77
76
 
78
77
 
 
78
/* Special version of do_encode_md to take care of pckcs#1 padding.
 
79
   For TLS-MD5SHA1 we need to do the padding ourself as Libgrypt does
 
80
   not know about this special scheme.  Fixme: We should have a
 
81
   pkcs1-only-padding flag for Libgcrypt. */
 
82
static int
 
83
do_encode_raw_pkcs1 (const byte *md, size_t mdlen, unsigned int nbits,
 
84
                     gcry_sexp_t *r_hash)
 
85
{
 
86
  int rc;
 
87
  gcry_sexp_t hash;
 
88
  unsigned char *frame;
 
89
  size_t i, n, nframe;
 
90
            
 
91
  nframe = (nbits+7) / 8;
 
92
  if ( !mdlen || mdlen + 8 + 4 > nframe )
 
93
    {
 
94
      /* Can't encode this hash into a frame of size NFRAME. */
 
95
      return gpg_error (GPG_ERR_TOO_SHORT);
 
96
    }
 
97
 
 
98
  frame = xtrymalloc (nframe);
 
99
  if (!frame)
 
100
    return gpg_error_from_syserror ();
 
101
  
 
102
  /* Assemble the pkcs#1 block type 1. */
 
103
  n = 0;
 
104
  frame[n++] = 0;
 
105
  frame[n++] = 1; /* Block type. */
 
106
  i = nframe - mdlen - 3 ;
 
107
  assert (i >= 8); /* At least 8 bytes of padding.  */
 
108
  memset (frame+n, 0xff, i );
 
109
  n += i;
 
110
  frame[n++] = 0;
 
111
  memcpy (frame+n, md, mdlen );
 
112
  n += mdlen;
 
113
  assert (n == nframe);
 
114
  
 
115
  /* Create the S-expression.  */
 
116
  rc = gcry_sexp_build (&hash, NULL,
 
117
                        "(data (flags raw) (value %b))",
 
118
                        (int)nframe, frame);
 
119
  xfree (frame);
 
120
 
 
121
  *r_hash = hash;
 
122
  return rc;   
 
123
}
 
124
 
 
125
 
 
126
 
79
127
/* SIGN whatever information we have accumulated in CTRL and return
80
128
   the signature S-Expression. */
81
129
int
132
180
 
133
181
      gcry_sexp_t s_hash = NULL;
134
182
 
135
 
      /* put the hash into a sexp */
136
 
      rc = do_encode_md (ctrl->digest.value,
137
 
                         ctrl->digest.valuelen,
138
 
                         ctrl->digest.algo,
139
 
                         &s_hash,
140
 
                         ctrl->digest.raw_value);
 
183
      /* Put the hash into a sexp */
 
184
      if (ctrl->digest.algo == GCRY_MD_USER_TLS_MD5SHA1)
 
185
        rc = do_encode_raw_pkcs1 (ctrl->digest.value,
 
186
                                  ctrl->digest.valuelen,
 
187
                                  gcry_pk_get_nbits (s_skey),
 
188
                                  &s_hash);
 
189
      else
 
190
        rc = do_encode_md (ctrl->digest.value,
 
191
                           ctrl->digest.valuelen,
 
192
                           ctrl->digest.algo,
 
193
                           &s_hash,
 
194
                           ctrl->digest.raw_value);
141
195
      if (rc)
142
196
        goto leave;
143
197