~nutznboltz-deactivatedaccount/ubuntu/precise/gnutls26/fix-lp926350

« back to all changes in this revision

Viewing changes to lib/x509/mpi.c

  • Committer: Package Import Robot
  • Author(s): Andreas Metzler
  • Date: 2011-10-01 15:28:13 UTC
  • mfrom: (12.1.20 sid)
  • Revision ID: package-import@ubuntu.com-20111001152813-yygm1c4cxonfxhzy
Tags: 2.12.11-1
* New upstream version.
  + Allow CA importing of 0 certificates to succeed. Closes: #640639
* Add libp11-kit-dev to libgnutls-dev dependencies. (see #643811)
* [20_guiledocstring.diff] guile: Fix docstring extraction with CPP 4.5+.

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
    }
70
70
 
71
71
  if ((result = _gnutls_x509_read_int (spk, "publicExponent",
72
 
                                       &params[1])) < 0)
 
72
                                       &params[1])) < 0)
73
73
    {
74
74
      gnutls_assert ();
75
75
      _gnutls_mpi_release (&params[0]);
163
163
  /* == INTEGER */
164
164
  if ((result = asn1_create_element
165
165
       (_gnutls_get_gnutls_asn (), "GNUTLS.DSAPublicKey",
166
 
        &spk)) != ASN1_SUCCESS)
 
166
        &spk)) != ASN1_SUCCESS)
167
167
    {
168
168
      gnutls_assert ();
169
169
      return _gnutls_asn2err (result);
206
206
 
207
207
/* Extracts DSA and RSA parameters from a certificate.
208
208
 */
209
 
static int
210
 
get_mpis (int pk_algorithm, ASN1_TYPE asn, const char *root,
211
 
          bigint_t * params, int *params_size)
 
209
int
 
210
_gnutls_get_asn_mpis (ASN1_TYPE asn, const char *root,
 
211
                      bigint_t * params, int *params_size)
212
212
{
213
213
  int result;
214
214
  char name[256];
215
215
  gnutls_datum_t tmp = { NULL, 0 };
 
216
  gnutls_pk_algorithm pk_algorithm;
 
217
 
 
218
  result = _gnutls_x509_get_pk_algorithm (asn, root, NULL);
 
219
  if (result < 0)
 
220
    {
 
221
      gnutls_assert ();
 
222
      return result;
 
223
    }
 
224
 
 
225
  pk_algorithm = result;
216
226
 
217
227
  /* Read the algorithm's parameters
218
228
   */
219
 
  snprintf (name, sizeof (name), "%s.subjectPublicKey", root);
 
229
  _asnstr_append_name (name, sizeof (name), root, ".subjectPublicKey");
220
230
  result = _gnutls_x509_read_value (asn, name, &tmp, 2);
221
231
 
222
232
  if (result < 0)
223
233
    {
224
234
      gnutls_assert ();
225
 
      fprintf (stderr, "name: %s\n", name);
226
235
      return result;
227
236
    }
228
237
 
233
242
       * params[1] is the exponent
234
243
       */
235
244
      if (*params_size < RSA_PUBLIC_PARAMS)
236
 
        {
237
 
          gnutls_assert ();
238
 
          /* internal error. Increase the bigint_ts in params */
239
 
          result = GNUTLS_E_INTERNAL_ERROR;
240
 
          goto error;
241
 
        }
 
245
        {
 
246
          gnutls_assert ();
 
247
          /* internal error. Increase the bigint_ts in params */
 
248
          result = GNUTLS_E_INTERNAL_ERROR;
 
249
          goto error;
 
250
        }
242
251
 
243
252
      if ((result =
244
 
           _gnutls_x509_read_rsa_params (tmp.data, tmp.size, params)) < 0)
245
 
        {
246
 
          gnutls_assert ();
247
 
          goto error;
248
 
        }
 
253
           _gnutls_x509_read_rsa_params (tmp.data, tmp.size, params)) < 0)
 
254
        {
 
255
          gnutls_assert ();
 
256
          goto error;
 
257
        }
249
258
      *params_size = RSA_PUBLIC_PARAMS;
250
259
 
251
260
      break;
257
266
       */
258
267
 
259
268
      if (*params_size < DSA_PUBLIC_PARAMS)
260
 
        {
261
 
          gnutls_assert ();
262
 
          /* internal error. Increase the bigint_ts in params */
263
 
          result = GNUTLS_E_INTERNAL_ERROR;
264
 
          goto error;
265
 
        }
 
269
        {
 
270
          gnutls_assert ();
 
271
          /* internal error. Increase the bigint_ts in params */
 
272
          result = GNUTLS_E_INTERNAL_ERROR;
 
273
          goto error;
 
274
        }
266
275
 
267
276
      if ((result =
268
 
           _gnutls_x509_read_dsa_pubkey (tmp.data, tmp.size, params)) < 0)
269
 
        {
270
 
          gnutls_assert ();
271
 
          goto error;
272
 
        }
 
277
           _gnutls_x509_read_dsa_pubkey (tmp.data, tmp.size, params)) < 0)
 
278
        {
 
279
          gnutls_assert ();
 
280
          goto error;
 
281
        }
273
282
 
274
283
      /* Now read the parameters
275
284
       */
276
285
      _gnutls_free_datum (&tmp);
277
286
 
278
 
      snprintf (name, sizeof (name), "%s.algorithm.parameters", root);
 
287
      _asnstr_append_name (name, sizeof (name), root,
 
288
                           ".algorithm.parameters");
279
289
      result = _gnutls_x509_read_value (asn, name, &tmp, 0);
280
290
 
281
291
      /* FIXME: If the parameters are not included in the certificate
284
294
       */
285
295
 
286
296
      if (result < 0)
287
 
        {
288
 
          gnutls_assert ();
289
 
          goto error;
290
 
        }
 
297
        {
 
298
          gnutls_assert ();
 
299
          goto error;
 
300
        }
291
301
 
292
302
      if ((result =
293
 
           _gnutls_x509_read_dsa_params (tmp.data, tmp.size, params)) < 0)
294
 
        {
295
 
          gnutls_assert ();
296
 
          goto error;
297
 
        }
 
303
           _gnutls_x509_read_dsa_params (tmp.data, tmp.size, params)) < 0)
 
304
        {
 
305
          gnutls_assert ();
 
306
          goto error;
 
307
        }
298
308
      *params_size = DSA_PUBLIC_PARAMS;
299
309
 
300
310
      break;
319
329
 */
320
330
int
321
331
_gnutls_x509_crt_get_mpis (gnutls_x509_crt_t cert,
322
 
                           bigint_t * params, int *params_size)
 
332
                           bigint_t * params, int *params_size)
323
333
{
324
 
  int pk_algorithm;
325
 
 
326
334
  /* Read the algorithm's OID
327
335
   */
328
 
  pk_algorithm = gnutls_x509_crt_get_pk_algorithm (cert, NULL);
329
 
 
330
 
  return get_mpis (pk_algorithm, cert->cert,
331
 
                   "tbsCertificate.subjectPublicKeyInfo", params,
332
 
                   params_size);
 
336
  return _gnutls_get_asn_mpis (cert->cert,
 
337
                               "tbsCertificate.subjectPublicKeyInfo", params,
 
338
                               params_size);
333
339
}
334
340
 
335
341
#ifdef ENABLE_PKI
338
344
 */
339
345
int
340
346
_gnutls_x509_crq_get_mpis (gnutls_x509_crq_t cert,
341
 
                           bigint_t * params, int *params_size)
 
347
                           bigint_t * params, int *params_size)
342
348
{
343
 
  int pk_algorithm;
344
 
 
345
349
  /* Read the algorithm's OID
346
350
   */
347
 
  pk_algorithm = gnutls_x509_crq_get_pk_algorithm (cert, NULL);
348
 
 
349
 
  return get_mpis (pk_algorithm, cert->crq,
350
 
                   "certificationRequestInfo.subjectPKInfo", params,
351
 
                   params_size);
 
351
  return _gnutls_get_asn_mpis (cert->crq,
 
352
                               "certificationRequestInfo.subjectPKInfo",
 
353
                               params, params_size);
352
354
}
353
355
 
354
356
#endif
362
364
 */
363
365
int
364
366
_gnutls_x509_write_rsa_params (bigint_t * params, int params_size,
365
 
                               gnutls_datum_t * der)
 
367
                               gnutls_datum_t * der)
366
368
{
367
369
  int result;
368
370
  ASN1_TYPE spk = ASN1_TYPE_EMPTY;
421
423
 */
422
424
int
423
425
_gnutls_x509_write_sig_params (ASN1_TYPE dst, const char *dst_name,
424
 
                               gnutls_pk_algorithm_t pk_algorithm,
425
 
                               gnutls_digest_algorithm_t dig,
426
 
                               bigint_t * params, int params_size)
 
426
                               gnutls_pk_algorithm_t pk_algorithm,
 
427
                               gnutls_digest_algorithm_t dig)
427
428
{
428
429
  int result;
429
430
  char name[128];
436
437
  if (pk == NULL)
437
438
    {
438
439
      gnutls_assert ();
 
440
      _gnutls_debug_log
 
441
        ("Cannot find OID for sign algorithm pk: %d dig: %d\n",
 
442
         (int) pk_algorithm, (int) dig);
439
443
      return GNUTLS_E_INVALID_REQUEST;
440
444
    }
441
445
 
477
481
 */
478
482
int
479
483
_gnutls_x509_write_dsa_params (bigint_t * params, int params_size,
480
 
                               gnutls_datum_t * der)
 
484
                               gnutls_datum_t * der)
481
485
{
482
486
  int result;
483
487
  ASN1_TYPE spk = ASN1_TYPE_EMPTY;
543
547
 */
544
548
int
545
549
_gnutls_x509_write_dsa_public_key (bigint_t * params, int params_size,
546
 
                                   gnutls_datum_t * der)
 
550
                                   gnutls_datum_t * der)
547
551
{
548
552
  int result;
549
553
  ASN1_TYPE spk = ASN1_TYPE_EMPTY;
580
584
      goto cleanup;
581
585
    }
582
586
 
583
 
  asn1_delete_structure (&spk);
584
 
  return 0;
 
587
  result = 0;
585
588
 
586
589
cleanup:
587
590
  asn1_delete_structure (&spk);