~ubuntu-branches/ubuntu/precise/gnutls28/precise

« back to all changes in this revision

Viewing changes to lib/x509/verify-high.c

  • Committer: Package Import Robot
  • Author(s): Andreas Metzler
  • Date: 2011-09-20 19:37:06 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20110920193706-a9phjijvddzg3nkl
Tags: 3.0.3-1
* New upstream version. (Includes a fix for #640639)
* Bump shlibs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#define INIT_HASH 0x33a1
38
38
 
39
39
struct named_cert_st {
40
 
  gnutls_x509_crt_t cert;
41
 
  uint8_t name[MAX_NAME_SIZE];
42
 
  unsigned int name_size;
 
40
    gnutls_x509_crt_t cert;
 
41
    uint8_t name[MAX_NAME_SIZE];
 
42
    unsigned int name_size;
43
43
};
44
44
 
45
45
struct node_st {
46
 
  /* The trusted certificates */
47
 
  gnutls_x509_crt_t * trusted_cas;
48
 
  unsigned int trusted_ca_size;
49
 
 
50
 
  struct named_cert_st *named_certs;
51
 
  unsigned int named_cert_size;
52
 
 
53
 
  /* The trusted CRLs */
54
 
  gnutls_x509_crl_t * crls;
55
 
  unsigned int crl_size;
 
46
    /* The trusted certificates */
 
47
    gnutls_x509_crt_t *trusted_cas;
 
48
    unsigned int trusted_ca_size;
 
49
 
 
50
    struct named_cert_st *named_certs;
 
51
    unsigned int named_cert_size;
 
52
 
 
53
    /* The trusted CRLs */
 
54
    gnutls_x509_crl_t *crls;
 
55
    unsigned int crl_size;
56
56
};
57
57
 
58
58
struct gnutls_x509_trust_list_st {
59
 
  int size;
60
 
  struct node_st *node;
 
59
    int size;
 
60
    struct node_st *node;
61
61
};
62
62
 
63
63
/**
73
73
 * Since: 3.0.0
74
74
 **/
75
75
int
76
 
gnutls_x509_trust_list_init (gnutls_x509_trust_list_t * list, unsigned int size)
 
76
gnutls_x509_trust_list_init(gnutls_x509_trust_list_t * list,
 
77
                            unsigned int size)
77
78
{
78
 
  gnutls_x509_trust_list_t tmp = gnutls_calloc (1, sizeof (struct gnutls_x509_trust_list_st));
79
 
 
80
 
  if (!tmp)
81
 
    return GNUTLS_E_MEMORY_ERROR;
82
 
 
83
 
  if (size == 0) size = DEFAULT_SIZE;
84
 
  tmp->size = size;
85
 
  
86
 
  tmp->node = gnutls_calloc(1, tmp->size * sizeof(tmp->node[0]));
87
 
  if (tmp->node == NULL)
88
 
    {
89
 
      gnutls_assert();
90
 
      gnutls_free(tmp);
91
 
      return GNUTLS_E_MEMORY_ERROR;
 
79
    gnutls_x509_trust_list_t tmp =
 
80
        gnutls_calloc(1, sizeof(struct gnutls_x509_trust_list_st));
 
81
 
 
82
    if (!tmp)
 
83
        return GNUTLS_E_MEMORY_ERROR;
 
84
 
 
85
    if (size == 0)
 
86
        size = DEFAULT_SIZE;
 
87
    tmp->size = size;
 
88
 
 
89
    tmp->node = gnutls_calloc(1, tmp->size * sizeof(tmp->node[0]));
 
90
    if (tmp->node == NULL) {
 
91
        gnutls_assert();
 
92
        gnutls_free(tmp);
 
93
        return GNUTLS_E_MEMORY_ERROR;
92
94
    }
93
95
 
94
 
  *list = tmp;
 
96
    *list = tmp;
95
97
 
96
 
  return 0;                     /* success */
 
98
    return 0;                   /* success */
97
99
}
98
100
 
99
101
/**
106
108
 * Since: 3.0.0
107
109
 **/
108
110
void
109
 
gnutls_x509_trust_list_deinit (gnutls_x509_trust_list_t list, unsigned int all)
 
111
gnutls_x509_trust_list_deinit(gnutls_x509_trust_list_t list,
 
112
                              unsigned int all)
110
113
{
111
 
int i, j;
112
 
 
113
 
  if (!list)
114
 
    return;
115
 
 
116
 
  if (all)
117
 
    {
118
 
      for (i=0;i<list->size;i++)
119
 
        {
120
 
          for (j=0;j<list->node[i].trusted_ca_size;j++)
121
 
            {
122
 
              gnutls_x509_crt_deinit(list->node[i].trusted_cas[j]);
123
 
            }
124
 
          gnutls_free(list->node[i].trusted_cas);
125
 
          for (j=0;j<list->node[i].crl_size;j++)
126
 
            {
127
 
              gnutls_x509_crl_deinit(list->node[i].crls[j]);
128
 
            }
129
 
          gnutls_free(list->node[i].crls);
130
 
        }
 
114
    int i, j;
 
115
 
 
116
    if (!list)
 
117
        return;
 
118
 
 
119
    for (i = 0; i < list->size; i++) {
 
120
        if (all)
 
121
            for (j = 0; j < list->node[i].trusted_ca_size; j++) {
 
122
                gnutls_x509_crt_deinit(list->node[i].trusted_cas[j]);
 
123
            }
 
124
        gnutls_free(list->node[i].trusted_cas);
 
125
 
 
126
        if (all)
 
127
            for (j = 0; j < list->node[i].crl_size; j++) {
 
128
                gnutls_x509_crl_deinit(list->node[i].crls[j]);
 
129
            }
 
130
        gnutls_free(list->node[i].crls);
 
131
        gnutls_free(list->node[i].named_certs);
131
132
    }
132
133
 
133
 
  gnutls_free (list->node);
134
 
  gnutls_free (list);
 
134
    gnutls_free(list->node);
 
135
    gnutls_free(list);
135
136
}
136
137
 
137
138
/**
150
151
 * Since: 3.0.0
151
152
 **/
152
153
int
153
 
gnutls_x509_trust_list_add_cas (gnutls_x509_trust_list_t list, 
154
 
  const gnutls_x509_crt_t * clist, int clist_size, unsigned int flags)
 
154
gnutls_x509_trust_list_add_cas(gnutls_x509_trust_list_t list,
 
155
                               const gnutls_x509_crt_t * clist,
 
156
                               int clist_size, unsigned int flags)
155
157
{
156
 
gnutls_datum_t dn;
157
 
int ret, i;
158
 
uint32_t hash;
 
158
    gnutls_datum_t dn;
 
159
    int ret, i;
 
160
    uint32_t hash;
159
161
 
160
 
  for (i=0;i<clist_size;i++)
161
 
    {
 
162
    for (i = 0; i < clist_size; i++) {
162
163
        ret = gnutls_x509_crt_get_raw_dn(clist[i], &dn);
163
 
        if (ret < 0)
164
 
          {
 
164
        if (ret < 0) {
165
165
            gnutls_assert();
166
166
            return i;
167
 
          }
 
167
        }
168
168
 
169
169
        hash = _gnutls_bhash(dn.data, dn.size, INIT_HASH);
170
170
        hash %= list->size;
171
171
 
172
172
        _gnutls_free_datum(&dn);
173
 
 
174
 
        list->node[hash].trusted_cas = gnutls_realloc_fast( list->node[hash].trusted_cas, (list->node[hash].trusted_ca_size+1)*sizeof(list->node[hash].trusted_cas[0]));
175
 
        if (list->node[hash].trusted_cas == NULL)
176
 
          {
 
173
        list->node[hash].trusted_cas =
 
174
            gnutls_realloc_fast(list->node[hash].trusted_cas,
 
175
                                (list->node[hash].trusted_ca_size +
 
176
                                 1) *
 
177
                                sizeof(list->node[hash].trusted_cas[0]));
 
178
        if (list->node[hash].trusted_cas == NULL) {
177
179
            gnutls_assert();
178
180
            return i;
179
 
          }
 
181
        }
180
182
 
181
 
        list->node[hash].trusted_cas[list->node[hash].trusted_ca_size] = clist[i];
 
183
        list->node[hash].trusted_cas[list->node[hash].trusted_ca_size] =
 
184
            clist[i];
182
185
        list->node[hash].trusted_ca_size++;
183
186
    }
184
187
 
185
 
  return i;
 
188
    return i;
186
189
}
187
190
 
188
191
/**
211
214
 * Since: 3.0.0
212
215
 **/
213
216
int
214
 
gnutls_x509_trust_list_add_named_crt (gnutls_x509_trust_list_t list, 
215
 
  gnutls_x509_crt_t cert, const void* name, size_t name_size, unsigned int flags)
 
217
gnutls_x509_trust_list_add_named_crt(gnutls_x509_trust_list_t list,
 
218
                                     gnutls_x509_crt_t cert,
 
219
                                     const void *name, size_t name_size,
 
220
                                     unsigned int flags)
216
221
{
217
 
gnutls_datum_t dn;
218
 
int ret;
219
 
uint32_t hash;
220
 
 
221
 
  if (name_size >= MAX_NAME_SIZE)
222
 
    return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
223
 
 
224
 
  ret = gnutls_x509_crt_get_raw_issuer_dn(cert, &dn);
225
 
  if (ret < 0)
226
 
    {
227
 
      gnutls_assert();
228
 
      return ret;
 
222
    gnutls_datum_t dn;
 
223
    int ret;
 
224
    uint32_t hash;
 
225
 
 
226
    if (name_size >= MAX_NAME_SIZE)
 
227
        return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
 
228
 
 
229
    ret = gnutls_x509_crt_get_raw_issuer_dn(cert, &dn);
 
230
    if (ret < 0) {
 
231
        gnutls_assert();
 
232
        return ret;
229
233
    }
230
234
 
231
 
  hash = _gnutls_bhash(dn.data, dn.size, INIT_HASH);
232
 
  hash %= list->size;
233
 
 
234
 
  _gnutls_free_datum(&dn);
235
 
 
236
 
  list->node[hash].named_certs = gnutls_realloc_fast( list->node[hash].named_certs, (list->node[hash].named_cert_size+1)*sizeof(list->node[hash].named_certs[0]));
237
 
  if (list->node[hash].named_certs == NULL)
238
 
    return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
239
 
 
240
 
  list->node[hash].named_certs[list->node[hash].named_cert_size].cert = cert;
241
 
  memcpy(list->node[hash].named_certs[list->node[hash].named_cert_size].name, name, name_size);
242
 
  list->node[hash].named_certs[list->node[hash].named_cert_size].name_size = name_size;
243
 
 
244
 
  list->node[hash].named_cert_size++;
245
 
 
246
 
  return 0;
 
235
    hash = _gnutls_bhash(dn.data, dn.size, INIT_HASH);
 
236
    hash %= list->size;
 
237
 
 
238
    _gnutls_free_datum(&dn);
 
239
 
 
240
    list->node[hash].named_certs =
 
241
        gnutls_realloc_fast(list->node[hash].named_certs,
 
242
                            (list->node[hash].named_cert_size +
 
243
                             1) * sizeof(list->node[hash].named_certs[0]));
 
244
    if (list->node[hash].named_certs == NULL)
 
245
        return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
 
246
 
 
247
    list->node[hash].named_certs[list->node[hash].named_cert_size].cert =
 
248
        cert;
 
249
    memcpy(list->node[hash].named_certs[list->node[hash].named_cert_size].
 
250
           name, name, name_size);
 
251
    list->node[hash].named_certs[list->node[hash].named_cert_size].
 
252
        name_size = name_size;
 
253
 
 
254
    list->node[hash].named_cert_size++;
 
255
 
 
256
    return 0;
247
257
}
248
258
 
249
259
/**
266
276
 * Since: 3.0.0
267
277
 **/
268
278
int
269
 
gnutls_x509_trust_list_add_crls (gnutls_x509_trust_list_t list, 
270
 
  const gnutls_x509_crl_t * crl_list, int crl_size, unsigned int flags,
271
 
  unsigned int verification_flags)
 
279
gnutls_x509_trust_list_add_crls(gnutls_x509_trust_list_t list,
 
280
                                const gnutls_x509_crl_t * crl_list,
 
281
                                int crl_size, unsigned int flags,
 
282
                                unsigned int verification_flags)
272
283
{
273
 
int ret, i, j = 0;
274
 
gnutls_datum_t dn;
275
 
unsigned int vret = 0;
276
 
uint32_t hash;
277
 
 
278
 
  /* Probably we can optimize things such as removing duplicates
279
 
   * etc.
280
 
   */
281
 
 
282
 
  if (crl_size == 0 || crl_list == NULL)
283
 
    return 0;
284
 
 
285
 
  for (i=0;i<crl_size;i++)
286
 
    {
 
284
    int ret, i, j = 0;
 
285
    gnutls_datum_t dn;
 
286
    unsigned int vret = 0;
 
287
    uint32_t hash;
 
288
 
 
289
    /* Probably we can optimize things such as removing duplicates
 
290
     * etc.
 
291
     */
 
292
 
 
293
    if (crl_size == 0 || crl_list == NULL)
 
294
        return 0;
 
295
 
 
296
    for (i = 0; i < crl_size; i++) {
287
297
        ret = gnutls_x509_crl_get_raw_issuer_dn(crl_list[i], &dn);
288
 
        if (ret < 0)
289
 
          {
 
298
        if (ret < 0) {
290
299
            gnutls_assert();
291
300
            return i;
292
 
          }
 
301
        }
293
302
 
294
303
        hash = _gnutls_bhash(dn.data, dn.size, INIT_HASH);
295
304
        hash %= list->size;
296
305
 
297
306
        _gnutls_free_datum(&dn);
298
307
 
299
 
        if (flags & GNUTLS_TL_VERIFY_CRL)
300
 
          {
 
308
        if (flags & GNUTLS_TL_VERIFY_CRL) {
301
309
 
302
 
            ret = gnutls_x509_crl_verify(crl_list[i], list->node[hash].trusted_cas,
303
 
              list->node[hash].trusted_ca_size, verification_flags, &vret);
 
310
            ret =
 
311
                gnutls_x509_crl_verify(crl_list[i],
 
312
                                       list->node[hash].trusted_cas,
 
313
                                       list->node[hash].trusted_ca_size,
 
314
                                       verification_flags, &vret);
304
315
            if (ret < 0 || vret != 0)
305
 
              continue;
306
 
          }
 
316
                continue;
 
317
        }
307
318
 
308
 
        list->node[hash].crls = gnutls_realloc_fast( list->node[hash].crls, (list->node[hash].crl_size+1)*sizeof(list->node[hash].trusted_cas[0]));
309
 
        if (list->node[hash].crls == NULL)
310
 
          {
 
319
        list->node[hash].crls =
 
320
            gnutls_realloc_fast(list->node[hash].crls,
 
321
                                (list->node[hash].crl_size +
 
322
                                 1) *
 
323
                                sizeof(list->node[hash].trusted_cas[0]));
 
324
        if (list->node[hash].crls == NULL) {
311
325
            gnutls_assert();
312
326
            return i;
313
 
          }
 
327
        }
314
328
 
315
329
        list->node[hash].crls[list->node[hash].crl_size] = crl_list[i];
316
330
        list->node[hash].crl_size++;
317
331
        j++;
318
332
    }
319
333
 
320
 
  return j;
 
334
    return j;
321
335
}
322
336
 
323
337
/* Takes a certificate list and shortens it if there are
328
342
 * Returns the new size of the list or a negative number on error.
329
343
 */
330
344
static int shorten_clist(gnutls_x509_trust_list_t list,
331
 
  gnutls_x509_crt_t* certificate_list, int clist_size)
 
345
                         gnutls_x509_crt_t * certificate_list,
 
346
                         int clist_size)
332
347
{
333
 
int i, ret;
334
 
uint32_t hash;
335
 
gnutls_datum_t dn;
 
348
    int i, ret;
 
349
    uint32_t hash;
 
350
    gnutls_datum_t dn;
336
351
 
337
 
  if (clist_size > 1)
338
 
    {
339
 
      /* Check if the last certificate in the path is self signed.
340
 
       * In that case ignore it (a certificate is trusted only if it
341
 
       * leads to a trusted party by us, not the server's).
342
 
       *
343
 
       * This prevents from verifying self signed certificates against
344
 
       * themselves. This (although not bad) caused verification
345
 
       * failures on some root self signed certificates that use the
346
 
       * MD2 algorithm.
347
 
       */
348
 
      if (gnutls_x509_crt_check_issuer (certificate_list[clist_size - 1],
349
 
                                        certificate_list[clist_size - 1]) > 0)
350
 
        {
351
 
          clist_size--;
 
352
    if (clist_size > 1) {
 
353
        /* Check if the last certificate in the path is self signed.
 
354
         * In that case ignore it (a certificate is trusted only if it
 
355
         * leads to a trusted party by us, not the server's).
 
356
         *
 
357
         * This prevents from verifying self signed certificates against
 
358
         * themselves. This (although not bad) caused verification
 
359
         * failures on some root self signed certificates that use the
 
360
         * MD2 algorithm.
 
361
         */
 
362
        if (gnutls_x509_crt_check_issuer(certificate_list[clist_size - 1],
 
363
                                         certificate_list[clist_size -
 
364
                                                          1]) > 0) {
 
365
            clist_size--;
352
366
        }
353
367
    }
354
368
 
355
 
  /* We want to shorten the chain by removing the cert that matches
356
 
   * one of the certs we trust and all the certs after that i.e. if
357
 
   * cert chain is A signed-by B signed-by C signed-by D (signed-by
358
 
   * self-signed E but already removed above), and we trust B, remove
359
 
   * B, C and D. */
360
 
  for (i=1; i < clist_size; i++)
361
 
    {
362
 
      int j;
 
369
    /* We want to shorten the chain by removing the cert that matches
 
370
     * one of the certs we trust and all the certs after that i.e. if
 
371
     * cert chain is A signed-by B signed-by C signed-by D (signed-by
 
372
     * self-signed E but already removed above), and we trust B, remove
 
373
     * B, C and D. */
 
374
    for (i = 1; i < clist_size; i++) {
 
375
        int j;
363
376
 
364
 
      ret = gnutls_x509_crt_get_raw_issuer_dn(certificate_list[i], &dn);
365
 
      if (ret < 0)
366
 
        {
367
 
          gnutls_assert();
368
 
          return ret;
 
377
        ret = gnutls_x509_crt_get_raw_issuer_dn(certificate_list[i], &dn);
 
378
        if (ret < 0) {
 
379
            gnutls_assert();
 
380
            return ret;
369
381
        }
370
382
 
371
 
      hash = _gnutls_bhash(dn.data, dn.size, INIT_HASH);
372
 
      hash %= list->size;
373
 
 
374
 
      _gnutls_free_datum(&dn);
375
 
 
376
 
      for (j = 0; j < list->node[hash].trusted_ca_size; j++)
377
 
        {
378
 
          if (check_if_same_cert (certificate_list[i], list->node[hash].trusted_cas[j]) == 0)
379
 
            {
380
 
              /* cut the list at the point of first the trusted certificate */
381
 
              clist_size = i+1;
382
 
              break;
 
383
        hash = _gnutls_bhash(dn.data, dn.size, INIT_HASH);
 
384
        hash %= list->size;
 
385
 
 
386
        _gnutls_free_datum(&dn);
 
387
 
 
388
        for (j = 0; j < list->node[hash].trusted_ca_size; j++) {
 
389
            if (check_if_same_cert
 
390
                (certificate_list[i],
 
391
                 list->node[hash].trusted_cas[j]) == 0) {
 
392
                /* cut the list at the point of first the trusted certificate */
 
393
                clist_size = i + 1;
 
394
                break;
383
395
            }
384
396
        }
385
 
      /* clist_size may have been changed which gets out of loop */
 
397
        /* clist_size may have been changed which gets out of loop */
386
398
    }
387
399
 
388
 
  return clist_size;
 
400
    return clist_size;
389
401
}
390
402
 
391
403
/**
404
416
 * Since: 3.0.0
405
417
 **/
406
418
int gnutls_x509_trust_list_get_issuer(gnutls_x509_trust_list_t list,
407
 
  gnutls_x509_crt_t cert, gnutls_x509_crt_t* issuer, unsigned int flags)
 
419
                                      gnutls_x509_crt_t cert,
 
420
                                      gnutls_x509_crt_t * issuer,
 
421
                                      unsigned int flags)
408
422
{
409
 
gnutls_datum_t dn;
410
 
int ret, i;
411
 
uint32_t hash;
 
423
    gnutls_datum_t dn;
 
424
    int ret, i;
 
425
    uint32_t hash;
412
426
 
413
 
  ret = gnutls_x509_crt_get_raw_issuer_dn(cert, &dn);
414
 
  if (ret < 0)
415
 
    {
416
 
      gnutls_assert();
417
 
      return ret;
 
427
    ret = gnutls_x509_crt_get_raw_issuer_dn(cert, &dn);
 
428
    if (ret < 0) {
 
429
        gnutls_assert();
 
430
        return ret;
418
431
    }
419
432
 
420
 
  hash = _gnutls_bhash(dn.data, dn.size, INIT_HASH);
421
 
  hash %= list->size;
422
 
 
423
 
  _gnutls_free_datum(&dn);
424
 
 
425
 
  for (i=0;i<list->node[hash].trusted_ca_size;i++)
426
 
    {
427
 
      ret = gnutls_x509_crt_check_issuer (cert, list->node[hash].trusted_cas[i]);
428
 
      if (ret > 0)
429
 
        {
430
 
          *issuer = list->node[hash].trusted_cas[i];
431
 
          return 0;
 
433
    hash = _gnutls_bhash(dn.data, dn.size, INIT_HASH);
 
434
    hash %= list->size;
 
435
 
 
436
    _gnutls_free_datum(&dn);
 
437
 
 
438
    for (i = 0; i < list->node[hash].trusted_ca_size; i++) {
 
439
        ret =
 
440
            gnutls_x509_crt_check_issuer(cert,
 
441
                                         list->node[hash].trusted_cas[i]);
 
442
        if (ret > 0) {
 
443
            *issuer = list->node[hash].trusted_cas[i];
 
444
            return 0;
432
445
        }
433
446
    }
434
447
 
435
 
  return GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE;
 
448
    return GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE;
436
449
}
437
450
 
438
451
/**
453
466
 * Since: 3.0.0
454
467
 **/
455
468
int
456
 
gnutls_x509_trust_list_verify_crt (
457
 
  gnutls_x509_trust_list_t list,
458
 
  gnutls_x509_crt_t *cert_list,
459
 
  unsigned int cert_list_size,
460
 
  unsigned int flags,
461
 
  unsigned int *verify,
462
 
  gnutls_verify_output_function func)
 
469
gnutls_x509_trust_list_verify_crt(gnutls_x509_trust_list_t list,
 
470
                                  gnutls_x509_crt_t * cert_list,
 
471
                                  unsigned int cert_list_size,
 
472
                                  unsigned int flags,
 
473
                                  unsigned int *verify,
 
474
                                  gnutls_verify_output_function func)
463
475
{
464
 
gnutls_datum_t dn;
465
 
int ret, i;
466
 
uint32_t hash;
467
 
 
468
 
  if (cert_list == NULL || cert_list_size < 1)
469
 
    return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
470
 
 
471
 
  cert_list_size = shorten_clist(list, cert_list, cert_list_size);
472
 
  if (cert_list_size <= 0)
473
 
    return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
474
 
 
475
 
  ret = gnutls_x509_crt_get_raw_issuer_dn(cert_list[cert_list_size-1], &dn);
476
 
  if (ret < 0)
477
 
    {
478
 
      gnutls_assert();
479
 
      return ret;
480
 
    }
481
 
 
482
 
  hash = _gnutls_bhash(dn.data, dn.size, INIT_HASH);
483
 
  hash %= list->size;
484
 
 
485
 
  _gnutls_free_datum(&dn);
486
 
 
487
 
  *verify = _gnutls_x509_verify_certificate(cert_list, cert_list_size, 
488
 
    list->node[hash].trusted_cas, list->node[hash].trusted_ca_size, 
489
 
    flags, func);
490
 
 
491
 
  if (*verify != 0 || (flags & GNUTLS_VERIFY_DISABLE_CRL_CHECKS)) return 0;
492
 
 
493
 
  /* Check revocation of individual certificates.
494
 
   * start with the last one that we already have its hash
495
 
   */
496
 
  ret = _gnutls_x509_crt_check_revocation (cert_list[cert_list_size-1],
497
 
                                        list->node[hash].crls, 
498
 
                                        list->node[hash].crl_size, func);
499
 
  if (ret == 1)
500
 
    { /* revoked */
501
 
      *verify |= GNUTLS_CERT_REVOKED;
502
 
      *verify |= GNUTLS_CERT_INVALID;
503
 
      return 0;
504
 
    }
505
 
 
506
 
  for (i=0;i<cert_list_size-1;i++)
507
 
    {
508
 
      ret = gnutls_x509_crt_get_raw_issuer_dn(cert_list[i], &dn);
509
 
      if (ret < 0)
510
 
        {
511
 
          gnutls_assert();
512
 
          return ret;
513
 
        }
514
 
 
515
 
      hash = _gnutls_bhash(dn.data, dn.size, INIT_HASH);
516
 
      hash %= list->size;
517
 
 
518
 
      _gnutls_free_datum(&dn);
519
 
 
520
 
      ret = _gnutls_x509_crt_check_revocation (cert_list[i],
521
 
                                            list->node[hash].crls, 
522
 
                                            list->node[hash].crl_size, func);
523
 
      if (ret == 1)
524
 
        { /* revoked */
525
 
          *verify |= GNUTLS_CERT_REVOKED;
526
 
          *verify |= GNUTLS_CERT_INVALID;
527
 
          return 0;
528
 
        }
529
 
    }
530
 
 
531
 
  return 0;
 
476
    gnutls_datum_t dn;
 
477
    int ret, i;
 
478
    uint32_t hash;
 
479
 
 
480
    if (cert_list == NULL || cert_list_size < 1)
 
481
        return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
 
482
 
 
483
    cert_list_size = shorten_clist(list, cert_list, cert_list_size);
 
484
    if (cert_list_size <= 0)
 
485
        return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
 
486
 
 
487
    ret =
 
488
        gnutls_x509_crt_get_raw_issuer_dn(cert_list[cert_list_size - 1],
 
489
                                          &dn);
 
490
    if (ret < 0) {
 
491
        gnutls_assert();
 
492
        return ret;
 
493
    }
 
494
 
 
495
    hash = _gnutls_bhash(dn.data, dn.size, INIT_HASH);
 
496
    hash %= list->size;
 
497
 
 
498
    _gnutls_free_datum(&dn);
 
499
 
 
500
    *verify = _gnutls_x509_verify_certificate(cert_list, cert_list_size,
 
501
                                              list->node[hash].trusted_cas,
 
502
                                              list->node[hash].
 
503
                                              trusted_ca_size, flags,
 
504
                                              func);
 
505
 
 
506
    if (*verify != 0 || (flags & GNUTLS_VERIFY_DISABLE_CRL_CHECKS))
 
507
        return 0;
 
508
 
 
509
    /* Check revocation of individual certificates.
 
510
     * start with the last one that we already have its hash
 
511
     */
 
512
    ret = _gnutls_x509_crt_check_revocation(cert_list[cert_list_size - 1],
 
513
                                            list->node[hash].crls,
 
514
                                            list->node[hash].crl_size,
 
515
                                            func);
 
516
    if (ret == 1) {             /* revoked */
 
517
        *verify |= GNUTLS_CERT_REVOKED;
 
518
        *verify |= GNUTLS_CERT_INVALID;
 
519
        return 0;
 
520
    }
 
521
 
 
522
    for (i = 0; i < cert_list_size - 1; i++) {
 
523
        ret = gnutls_x509_crt_get_raw_issuer_dn(cert_list[i], &dn);
 
524
        if (ret < 0) {
 
525
            gnutls_assert();
 
526
            return ret;
 
527
        }
 
528
 
 
529
        hash = _gnutls_bhash(dn.data, dn.size, INIT_HASH);
 
530
        hash %= list->size;
 
531
 
 
532
        _gnutls_free_datum(&dn);
 
533
 
 
534
        ret = _gnutls_x509_crt_check_revocation(cert_list[i],
 
535
                                                list->node[hash].crls,
 
536
                                                list->node[hash].crl_size,
 
537
                                                func);
 
538
        if (ret == 1) {         /* revoked */
 
539
            *verify |= GNUTLS_CERT_REVOKED;
 
540
            *verify |= GNUTLS_CERT_INVALID;
 
541
            return 0;
 
542
        }
 
543
    }
 
544
 
 
545
    return 0;
532
546
}
533
547
 
534
548
/**
551
565
 * Since: 3.0.0
552
566
 **/
553
567
int
554
 
gnutls_x509_trust_list_verify_named_crt (
555
 
  gnutls_x509_trust_list_t list,
556
 
  gnutls_x509_crt_t cert,
557
 
  const void * name,
558
 
  size_t name_size,
559
 
  unsigned int flags,
560
 
  unsigned int *verify,
561
 
  gnutls_verify_output_function func)
 
568
gnutls_x509_trust_list_verify_named_crt(gnutls_x509_trust_list_t list,
 
569
                                        gnutls_x509_crt_t cert,
 
570
                                        const void *name,
 
571
                                        size_t name_size,
 
572
                                        unsigned int flags,
 
573
                                        unsigned int *verify,
 
574
                                        gnutls_verify_output_function func)
562
575
{
563
 
gnutls_datum_t dn;
564
 
int ret, i;
565
 
uint32_t hash;
 
576
    gnutls_datum_t dn;
 
577
    int ret, i;
 
578
    uint32_t hash;
566
579
 
567
 
  ret = gnutls_x509_crt_get_raw_issuer_dn(cert, &dn);
568
 
  if (ret < 0)
569
 
    {
570
 
      gnutls_assert();
571
 
      return ret;
 
580
    ret = gnutls_x509_crt_get_raw_issuer_dn(cert, &dn);
 
581
    if (ret < 0) {
 
582
        gnutls_assert();
 
583
        return ret;
572
584
    }
573
585
 
574
 
  hash = _gnutls_bhash(dn.data, dn.size, INIT_HASH);
575
 
  hash %= list->size;
576
 
 
577
 
  _gnutls_free_datum(&dn);
578
 
 
579
 
  *verify = GNUTLS_CERT_INVALID;
580
 
 
581
 
  for (i=0;i<list->node[hash].named_cert_size;i++)
582
 
    {
583
 
      if (check_if_same_cert(cert, list->node[hash].named_certs[i].cert)==0)
584
 
        { /* check if name matches */
585
 
          if (list->node[hash].named_certs[i].name_size==name_size &&
586
 
              memcmp(list->node[hash].named_certs[i].name, name, name_size) == 0)
587
 
              {
 
586
    hash = _gnutls_bhash(dn.data, dn.size, INIT_HASH);
 
587
    hash %= list->size;
 
588
 
 
589
    _gnutls_free_datum(&dn);
 
590
 
 
591
    *verify = GNUTLS_CERT_INVALID;
 
592
 
 
593
    for (i = 0; i < list->node[hash].named_cert_size; i++) {
 
594
        if (check_if_same_cert(cert, list->node[hash].named_certs[i].cert) == 0) {      /* check if name matches */
 
595
            if (list->node[hash].named_certs[i].name_size == name_size &&
 
596
                memcmp(list->node[hash].named_certs[i].name, name,
 
597
                       name_size) == 0) {
588
598
                *verify = 0;
589
599
                break;
590
 
              }
 
600
            }
591
601
        }
592
602
    }
593
603
 
594
 
  if (*verify != 0 || (flags & GNUTLS_VERIFY_DISABLE_CRL_CHECKS)) return 0;
 
604
    if (*verify != 0 || (flags & GNUTLS_VERIFY_DISABLE_CRL_CHECKS))
 
605
        return 0;
595
606
 
596
 
  /* Check revocation of individual certificates.
597
 
   * start with the last one that we already have its hash
598
 
   */
599
 
  ret = _gnutls_x509_crt_check_revocation (cert,
600
 
                                        list->node[hash].crls, 
601
 
                                        list->node[hash].crl_size, func);
602
 
  if (ret == 1)
603
 
    { /* revoked */
604
 
      *verify |= GNUTLS_CERT_REVOKED;
605
 
      *verify |= GNUTLS_CERT_INVALID;
606
 
      return 0;
 
607
    /* Check revocation of individual certificates.
 
608
     * start with the last one that we already have its hash
 
609
     */
 
610
    ret = _gnutls_x509_crt_check_revocation(cert,
 
611
                                            list->node[hash].crls,
 
612
                                            list->node[hash].crl_size,
 
613
                                            func);
 
614
    if (ret == 1) {             /* revoked */
 
615
        *verify |= GNUTLS_CERT_REVOKED;
 
616
        *verify |= GNUTLS_CERT_INVALID;
 
617
        return 0;
607
618
    }
608
619
 
609
 
  return 0;
 
620
    return 0;
610
621
}