~andreserl/ubuntu/lucid/bind9/bind9-apport-533601

« back to all changes in this revision

Viewing changes to lib/bind/dst/hmac_link.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones, LaMont Jones, Internet Software Consortium, Inc, localization folks
  • Date: 2008-08-02 14:20:20 UTC
  • mfrom: (1.2.1 upstream) (6.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080802142020-l1hon9jy8lbbjxmg
[LaMont Jones]

* default to using resolvconf if it is installed
* fix sonames and dependencies.  Closes: #149259, #492418
* Do not build-depend libcap2-dev on non-linux.  Closes: #493392
* drop unused query-loc manpage.  Closes: #492564
* lwresd: Deliver /etc/bind directory.  Closes: #490027
* fix query-source comment in default install

[Internet Software Consortium, Inc]

* 9.5.0-P2.  Closes: #492949

[localization folks]

* l10n: Spanish debconf translation.  Closes: #492425 (Ignacio Mondino)
* l10n: Swedish debconf templates.  Closes: #491369 (Martin Ågren)
* l10n: Japanese debconf translations.  Closes: #492048 (Hideki Yamane
  (Debian-JP))
* l10n: Finnish translation.  Closes: #490630 (Esko Arajärvi)
* l10n: Italian debconf translations.  Closes: #492587 (Alessandro Vietta)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#ifdef HMAC_MD5
2
2
#ifndef LINT
3
 
static const char rcsid[] = "$Header: /proj/cvs/prod/bind9/lib/bind/dst/hmac_link.c,v 1.2.2.1.4.1 2005/07/28 07:43:16 marka Exp $";
 
3
static const char rcsid[] = "$Header: /proj/cvs/prod/bind9/lib/bind/dst/hmac_link.c,v 1.8 2007/09/24 17:18:25 each Exp $";
4
4
#endif
5
5
/*
6
6
 * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
19
19
 * WITH THE USE OR PERFORMANCE OF THE SOFTWARE.
20
20
 */
21
21
 
22
 
/* 
 
22
/*%
23
23
 * This file contains an implementation of the HMAC-MD5 algorithm.
24
24
 */
25
25
#include "port_before.h"
46
46
#  endif
47
47
# endif
48
48
# ifndef _MD5_H_
49
 
#  define _MD5_H_ 1     /* make sure we do not include rsaref md5.h file */
 
49
#  define _MD5_H_ 1     /*%< make sure we do not include rsaref md5.h file */
50
50
# endif
51
51
#endif
52
52
 
93
93
        int sign_len = 0;
94
94
        MD5_CTX *ctx = NULL;
95
95
 
 
96
        if (d_key == NULL || d_key->dk_KEY_struct == NULL)
 
97
                return (-1);
 
98
 
96
99
        if (mode & SIG_MODE_INIT) 
97
100
                ctx = (MD5_CTX *) malloc(sizeof(*ctx));
98
101
        else if (context)
100
103
        if (ctx == NULL) 
101
104
                return (-1);
102
105
 
103
 
        if (d_key == NULL || d_key->dk_KEY_struct == NULL)
104
 
                return (-1);
105
106
        key = (HMAC_Key *) d_key->dk_KEY_struct;
106
107
 
107
108
        if (mode & SIG_MODE_INIT) {
160
161
        HMAC_Key *key;
161
162
        MD5_CTX *ctx = NULL;
162
163
 
 
164
        if (d_key == NULL || d_key->dk_KEY_struct == NULL)
 
165
                return (-1);
 
166
 
163
167
        if (mode & SIG_MODE_INIT) 
164
168
                ctx = (MD5_CTX *) malloc(sizeof(*ctx));
165
169
        else if (context)
167
171
        if (ctx == NULL) 
168
172
                return (-1);
169
173
 
170
 
        if (d_key == NULL || d_key->dk_KEY_struct == NULL)
171
 
                return (-1);
172
 
 
173
174
        key = (HMAC_Key *) d_key->dk_KEY_struct;
174
175
        if (mode & SIG_MODE_INIT) {
175
176
                MD5Init(ctx);
222
223
        HMAC_Key *hkey = NULL;
223
224
        MD5_CTX ctx;
224
225
        int local_keylen = keylen;
 
226
        u_char tk[MD5_LEN];
225
227
 
226
228
        if (dkey == NULL || key == NULL || keylen < 0)
227
229
                return (-1);
234
236
 
235
237
        /* if key is longer than HMAC_LEN bytes reset it to key=MD5(key) */
236
238
        if (keylen > HMAC_LEN) {
237
 
                u_char tk[MD5_LEN];
238
239
                MD5Init(&ctx);
239
240
                MD5Update(&ctx, key, keylen);
240
241
                MD5Final(tk, &ctx);
272
273
 
273
274
static int
274
275
dst_hmac_md5_key_to_file_format(const DST_KEY *dkey, char *buff,
275
 
                            const int buff_len)
 
276
                                const int buff_len)
276
277
{
277
278
        char *bp;
278
 
        int len, b_len, i, key_len;
 
279
        int len, i, key_len;
279
280
        u_char key[HMAC_LEN];
280
281
        HMAC_Key *hkey;
281
282
 
282
283
        if (dkey == NULL || dkey->dk_KEY_struct == NULL) 
283
284
                return (0);
284
 
        if (buff == NULL || buff_len <= (int) strlen(key_file_fmt_str))
285
 
                return (-1);    /* no OR not enough space in output area */
286
 
 
 
285
        /*
 
286
         * Using snprintf() would be so much simpler here.
 
287
         */
 
288
        if (buff == NULL ||
 
289
            buff_len <= (int)(strlen(key_file_fmt_str) +
 
290
                              strlen(KEY_FILE_FORMAT) + 4))
 
291
                return (-1);    /*%< no OR not enough space in output area */
287
292
        hkey = (HMAC_Key *) dkey->dk_KEY_struct;
288
 
        memset(buff, 0, buff_len);      /* just in case */
 
293
        memset(buff, 0, buff_len);      /*%< just in case */
289
294
        /* write file header */
290
295
        sprintf(buff, key_file_fmt_str, KEY_FILE_FORMAT, KEY_HMAC_MD5, "HMAC");
291
296
 
292
 
        bp = (char *) strchr(buff, '\0');
293
 
        b_len = buff_len - (bp - buff);
 
297
        bp = buff + strlen(buff);
294
298
 
295
299
        memset(key, 0, HMAC_LEN);
296
300
        for (i = 0; i < HMAC_LEN; i++)
300
304
                        break;
301
305
        key_len = i + 1;
302
306
 
 
307
        if (buff_len - (bp - buff) < 6)
 
308
                return (-1);
303
309
        strcat(bp, "Key: ");
304
310
        bp += strlen("Key: ");
305
 
        b_len = buff_len - (bp - buff);
306
311
 
307
 
        len = b64_ntop(key, key_len, bp, b_len);
 
312
        len = b64_ntop(key, key_len, bp, buff_len - (bp - buff));
308
313
        if (len < 0) 
309
314
                return (-1);
310
315
        bp += len;
 
316
        if (buff_len - (bp - buff) < 2)
 
317
                return (-1);
311
318
        *(bp++) = '\n';
312
319
        *bp = '\0';
313
 
        b_len = buff_len - (bp - buff);
314
320
 
315
 
        return (buff_len - b_len);
 
321
        return (bp - buff);
316
322
}
317
323
 
318
324
 
334
340
{
335
341
        const char *p = buff, *eol;
336
342
        u_char key[HMAC_LEN+1]; /* b64_pton needs more than 64 bytes do decode
337
 
                                                         * it should probably be fixed rather than doing
338
 
                                                         * this
339
 
                                                         */
 
343
                                 * it should probably be fixed rather than doing
 
344
                                 * this
 
345
                                 */
340
346
        u_char *tmp;
341
347
        int key_len, len;
342
348
 
355
361
                return (-4);
356
362
        len = eol - p;
357
363
        tmp = malloc(len + 2);
 
364
        if (tmp == NULL)
 
365
                return (-5);
358
366
        memcpy(tmp, p, len);
359
367
        *(tmp + len) = 0x0;
360
 
        key_len = b64_pton((char *)tmp, key, HMAC_LEN+1);       /* see above */
 
368
        key_len = b64_pton((char *)tmp, key, HMAC_LEN+1);       /*%< see above */
361
369
        SAFE_FREE2(tmp, len + 2);
362
370
 
363
371
        if (dst_buffer_to_hmac_md5(dkey, key, key_len) < 0) {
366
374
        return (0);
367
375
}
368
376
 
369
 
/*
 
377
/*%
370
378
 * dst_hmac_md5_to_dns_key() 
371
379
 *         function to extract hmac key from DST_KEY structure 
372
380
 * intput: 
440
448
        return (-1);
441
449
}
442
450
 
443
 
/*
 
451
/*%
444
452
 * dst_hmac_md5_init()  Function to answer set up function pointers for HMAC
445
453
 *         related functions 
446
454
 */
477
485
        return (0);
478
486
}
479
487
#endif
 
488
 
 
489
/*! \file */