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

« back to all changes in this revision

Viewing changes to sm/fingerprint.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>
60
59
  if (r_len)
61
60
    *r_len = len;
62
61
 
 
62
  /* Fist check whether we have cached the fingerprint.  */
 
63
  if (algo == GCRY_MD_SHA1)
 
64
    {
 
65
      size_t buflen;
 
66
 
 
67
      assert (len >= 20);
 
68
      if (!ksba_cert_get_user_data (cert, "sha1-fingerprint", 
 
69
                                    array, len, &buflen)
 
70
          && buflen == 20)
 
71
        return array;
 
72
    }
 
73
 
 
74
  /* No, need to compute it.  */
63
75
  rc = gcry_md_open (&md, algo, 0);
64
76
  if (rc)
65
77
    {
78
90
    }
79
91
  gcry_md_final (md);
80
92
  memcpy (array, gcry_md_read(md, algo), len );
 
93
  gcry_md_close (md);
 
94
 
 
95
  /* Cache an SHA-1 fingerprint.  */
 
96
  if ( algo == GCRY_MD_SHA1 )
 
97
    ksba_cert_set_user_data (cert, "sha1-fingerprint", array, 20);
 
98
 
81
99
  return array;
82
100
}
83
101
 
88
106
{
89
107
  unsigned char digest[MAX_DIGEST_LEN];
90
108
  char *buf;
91
 
  int len, i;
 
109
  int len;
92
110
 
93
111
  if (!algo)
94
112
    algo = GCRY_MD_SHA1;
97
115
  assert (len <= MAX_DIGEST_LEN );
98
116
  gpgsm_get_fingerprint (cert, algo, digest, NULL);
99
117
  buf = xmalloc (len*3+1);
100
 
  *buf = 0;
101
 
  for (i=0; i < len; i++ )
102
 
    sprintf (buf+strlen(buf), i? ":%02X":"%02X", digest[i]);
 
118
  bin2hexcolon (digest, len, buf);
103
119
  return buf;
104
120
}
105
121
 
110
126
{
111
127
  unsigned char digest[MAX_DIGEST_LEN];
112
128
  char *buf;
113
 
  int len, i;
 
129
  int len;
114
130
 
115
131
  if (!algo)
116
132
    algo = GCRY_MD_SHA1;
118
134
  len = gcry_md_get_algo_dlen (algo);
119
135
  assert (len <= MAX_DIGEST_LEN );
120
136
  gpgsm_get_fingerprint (cert, algo, digest, NULL);
121
 
  buf = xmalloc (len*3+1);
122
 
  *buf = 0;
123
 
  for (i=0; i < len; i++ )
124
 
    sprintf (buf+strlen(buf), "%02X", digest[i]);
 
137
  buf = xmalloc (len*2+1);
 
138
  bin2hex (digest, len, buf);
125
139
  return buf;
126
140
}
127
141
 
188
202
gpgsm_get_keygrip_hexstring (ksba_cert_t cert)
189
203
{
190
204
  unsigned char grip[20];
191
 
  char *buf, *p;
192
 
  int i;
 
205
  char *buf;
193
206
 
194
207
  gpgsm_get_keygrip (cert, grip);
195
 
  buf = p = xmalloc (20*2+1);
196
 
  for (i=0; i < 20; i++, p += 2 )
197
 
    sprintf (p, "%02X", grip[i]);
 
208
  buf = xmalloc (20*2+1);
 
209
  bin2hex (grip, 20, buf);
198
210
  return buf;
199
211
}
200
212