~ubuntu-branches/ubuntu/quantal/gnutls26/quantal-security

« back to all changes in this revision

Viewing changes to lib/x509/x509_write.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-05-20 13:07:18 UTC
  • mfrom: (12.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110520130718-db41dybbanzfvlji
Tags: 2.10.5-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Fix build failure with --no-add-needed.
  - Build for multiarch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation
 
2
 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
 
3
 * Software Foundation, Inc.
3
4
 *
4
5
 * Author: Nikos Mavrogiannopoulos
5
6
 *
6
 
 * This file is part of GNUTLS.
 
7
 * This file is part of GnuTLS.
7
8
 *
8
 
 * The GNUTLS library is free software; you can redistribute it and/or
 
9
 * The GnuTLS is free software; you can redistribute it and/or
9
10
 * modify it under the terms of the GNU Lesser General Public License
10
11
 * as published by the Free Software Foundation; either version 2.1 of
11
12
 * the License, or (at your option) any later version.
41
42
static void disable_optional_stuff (gnutls_x509_crt_t cert);
42
43
 
43
44
/**
44
 
 * gnutls_x509_crt_set_dn_by_oid - Set the Certificate request subject's distinguished name
 
45
 * gnutls_x509_crt_set_dn_by_oid:
45
46
 * @crt: a certificate of type #gnutls_x509_crt_t
46
47
 * @oid: holds an Object Identifier in a null terminated string
47
48
 * @raw_flag: must be 0, or 1 if the data are DER encoded
76
77
}
77
78
 
78
79
/**
79
 
 * gnutls_x509_crt_set_issuer_dn_by_oid - Set the Certificate request issuer's distinguished name
 
80
 * gnutls_x509_crt_set_issuer_dn_by_oid:
80
81
 * @crt: a certificate of type #gnutls_x509_crt_t
81
82
 * @oid: holds an Object Identifier in a null terminated string
82
83
 * @raw_flag: must be 0, or 1 if the data are DER encoded
117
118
}
118
119
 
119
120
/**
120
 
 * gnutls_x509_crt_set_proxy_dn - Set Proxy Certificate subject's distinguished name 
 
121
 * gnutls_x509_crt_set_proxy_dn:
121
122
 * @crt: a gnutls_x509_crt_t structure with the new proxy cert
122
123
 * @eecrt: the end entity certificate that will be issuing the proxy
123
124
 * @raw_flag: must be 0, or 1 if the CN is DER encoded
164
165
}
165
166
 
166
167
/**
167
 
 * gnutls_x509_crt_set_version - Set the Certificate request version
 
168
 * gnutls_x509_crt_set_version:
168
169
 * @crt: a certificate of type #gnutls_x509_crt_t
169
170
 * @version: holds the version number. For X.509v1 certificates must be 1.
170
171
 *
206
207
}
207
208
 
208
209
/**
209
 
  * gnutls_x509_crt_set_key - This function will associate the Certificate with a key
210
 
  * @crt: a certificate of type #gnutls_x509_crt_t
211
 
  * @key: holds a private key
212
 
  *
213
 
  * This function will set the public parameters from the given
214
 
  * private key to the certificate. Only RSA keys are currently
215
 
  * supported.
216
 
  *
217
 
  * Returns: On success, %GNUTLS_E_SUCCESS is returned, otherwise a
218
 
  *   negative error value.
219
 
  *
220
 
  **/
 
210
 * gnutls_x509_crt_set_key:
 
211
 * @crt: a certificate of type #gnutls_x509_crt_t
 
212
 * @key: holds a private key
 
213
 *
 
214
 * This function will set the public parameters from the given
 
215
 * private key to the certificate. Only RSA keys are currently
 
216
 * supported.
 
217
 *
 
218
 * Returns: On success, %GNUTLS_E_SUCCESS is returned, otherwise a
 
219
 *   negative error value.
 
220
 *
 
221
 **/
221
222
int
222
223
gnutls_x509_crt_set_key (gnutls_x509_crt_t crt, gnutls_x509_privkey_t key)
223
224
{
245
246
}
246
247
 
247
248
/**
248
 
 * gnutls_x509_crt_set_crq - Associate the Certificate with a request
 
249
 * gnutls_x509_crt_set_crq:
249
250
 * @crt: a certificate of type #gnutls_x509_crt_t
250
251
 * @crq: holds a certificate request
251
252
 *
288
289
}
289
290
 
290
291
/**
291
 
 * gnutls_x509_crt_set_crq_extensions - Associate the Certificate with a request
 
292
 * gnutls_x509_crt_set_crq_extensions:
292
293
 * @crt: a certificate of type #gnutls_x509_crt_t
293
294
 * @crq: holds a certificate request
294
295
 *
304
305
gnutls_x509_crt_set_crq_extensions (gnutls_x509_crt_t crt,
305
306
                                    gnutls_x509_crq_t crq)
306
307
{
307
 
  int result, i;
308
 
  char oid[MAX_OID_SIZE];
309
 
  size_t oid_size;
310
 
  opaque extensions[MAX_CRQ_EXTENSIONS_SIZE];
311
 
  size_t extensions_size = sizeof (extensions);
312
 
  unsigned int critical;
313
 
  gnutls_datum ext;
 
308
  size_t i;
314
309
 
315
310
  if (crt == NULL || crq == NULL)
316
311
    {
320
315
 
321
316
  for (i = 0;; i++)
322
317
    {
 
318
      int result;
 
319
      char oid[MAX_OID_SIZE];
 
320
      size_t oid_size;
 
321
      opaque *extensions;
 
322
      size_t extensions_size;
 
323
      unsigned int critical;
 
324
      gnutls_datum_t ext;
 
325
 
323
326
      oid_size = sizeof (oid);
324
 
      result =
325
 
        gnutls_x509_crq_get_extension_info (crq, i, oid, &oid_size,
326
 
                                            &critical);
 
327
      result = gnutls_x509_crq_get_extension_info (crq, i, oid,
 
328
                                                   &oid_size, &critical);
327
329
      if (result < 0)
328
330
        {
329
331
          if (result == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE)
333
335
          return result;
334
336
        }
335
337
 
336
 
      extensions_size = sizeof (extensions);
337
 
      result =
338
 
        gnutls_x509_crq_get_extension_data (crq, i, extensions,
339
 
                                            &extensions_size);
340
 
 
341
 
      if (result < 0)
342
 
        {
343
 
          gnutls_assert ();
 
338
      extensions_size = 0;
 
339
      result = gnutls_x509_crq_get_extension_data (crq, i, NULL,
 
340
                                                   &extensions_size);
 
341
      if (result < 0)
 
342
        {
 
343
          gnutls_assert ();
 
344
          return result;
 
345
        }
 
346
 
 
347
      extensions = gnutls_malloc (extensions_size);
 
348
      if (extensions == NULL)
 
349
        {
 
350
          gnutls_assert ();
 
351
          return GNUTLS_E_MEMORY_ERROR;
 
352
        }
 
353
 
 
354
      result = gnutls_x509_crq_get_extension_data (crq, i, extensions,
 
355
                                                   &extensions_size);
 
356
      if (result < 0)
 
357
        {
 
358
          gnutls_assert ();
 
359
          gnutls_free (extensions);
344
360
          return result;
345
361
        }
346
362
 
348
364
      ext.size = extensions_size;
349
365
 
350
366
      result = _gnutls_x509_crt_set_extension (crt, oid, &ext, critical);
 
367
      gnutls_free (extensions);
351
368
      if (result < 0)
352
369
        {
353
370
          gnutls_assert ();
354
371
          return result;
355
372
        }
356
 
 
357
373
    }
358
374
 
359
375
  if (i > 0)
363
379
}
364
380
 
365
381
/**
366
 
 * gnutls_x509_crt_set_extension_by_oid - Set an arbitrary extension
 
382
 * gnutls_x509_crt_set_extension_by_oid:
367
383
 * @crt: a certificate of type #gnutls_x509_crt_t
368
384
 * @oid: holds an Object Identified in null terminated string
369
385
 * @buf: a pointer to a DER encoded data
375
391
 * encoded.
376
392
 *
377
393
 * Returns: On success, %GNUTLS_E_SUCCESS is returned, otherwise a
378
 
 *   negative error value.and a negative value in case of an error.
 
394
 *   negative error value.
379
395
 **/
380
396
int
381
397
gnutls_x509_crt_set_extension_by_oid (gnutls_x509_crt_t crt,
409
425
}
410
426
 
411
427
/**
412
 
 * gnutls_x509_crt_set_basic_constraints - Set the basicConstraints extension
 
428
 * gnutls_x509_crt_set_basic_constraints:
413
429
 * @crt: a certificate of type #gnutls_x509_crt_t
414
430
 * @ca: true(1) or false(0). Depending on the Certificate authority status.
415
431
 * @pathLenConstraint: non-negative values indicate maximum length of path,
460
476
}
461
477
 
462
478
/**
463
 
 * gnutls_x509_crt_set_ca_status - Set the basicConstraints extension
 
479
 * gnutls_x509_crt_set_ca_status:
464
480
 * @crt: a certificate of type #gnutls_x509_crt_t
465
481
 * @ca: true(1) or false(0). Depending on the Certificate authority status.
466
482
 *
478
494
}
479
495
 
480
496
/**
481
 
 * gnutls_x509_crt_set_key_usage - Set the keyUsage extension
 
497
 * gnutls_x509_crt_set_key_usage:
482
498
 * @crt: a certificate of type #gnutls_x509_crt_t
483
499
 * @usage: an ORed sequence of the GNUTLS_KEY_* elements.
484
500
 *
524
540
}
525
541
 
526
542
/**
527
 
 * gnutls_x509_crt_set_subject_alternative_name - Set the subject Alternative Name
 
543
 * gnutls_x509_crt_set_subject_alternative_name:
528
544
 * @crt: a certificate of type #gnutls_x509_crt_t
529
545
 * @type: is one of the gnutls_x509_subject_alt_name_t enumerations
530
546
 * @data_string: The data to be set, a zero terminated string
541
557
 **/
542
558
int
543
559
gnutls_x509_crt_set_subject_alternative_name (gnutls_x509_crt_t crt,
544
 
                                              gnutls_x509_subject_alt_name_t type,
545
 
                                              const char *data_string)
 
560
                                              gnutls_x509_subject_alt_name_t
 
561
                                              type, const char *data_string)
546
562
{
547
563
  if (crt == NULL)
548
564
    {
564
580
}
565
581
 
566
582
/**
567
 
 * gnutls_x509_crt_set_subject_alt_name - Set the subject Alternative Name
 
583
 * gnutls_x509_crt_set_subject_alt_name:
568
584
 * @crt: a certificate of type #gnutls_x509_crt_t
569
585
 * @type: is one of the gnutls_x509_subject_alt_name_t enumerations
570
586
 * @data: The data to be set
656
672
}
657
673
 
658
674
/**
659
 
 * gnutls_x509_crt_set_proxy - Set the proxyCertInfo extension
 
675
 * gnutls_x509_crt_set_proxy:
660
676
 * @crt: a certificate of type #gnutls_x509_crt_t
661
677
 * @pathLenConstraint: non-negative values indicate maximum length of path,
662
678
 *   and negative values indicate that the pathLenConstraints field should
714
730
}
715
731
 
716
732
/**
717
 
 * gnutls_x509_crt_sign2 - Sign a certificate with a key
 
733
 * gnutls_x509_crt_sign2:
718
734
 * @crt: a certificate of type #gnutls_x509_crt_t
719
735
 * @issuer: is the certificate of the certificate issuer
720
736
 * @issuer_key: holds the issuer's private key
759
775
}
760
776
 
761
777
/**
762
 
 * gnutls_x509_crt_sign - Sign a certificate with a key
 
778
 * gnutls_x509_crt_sign:
763
779
 * @crt: a certificate of type #gnutls_x509_crt_t
764
780
 * @issuer: is the certificate of the certificate issuer
765
781
 * @issuer_key: holds the issuer's private key
778
794
}
779
795
 
780
796
/**
781
 
 * gnutls_x509_crt_set_activation_time - Set the Certificate's activation time
 
797
 * gnutls_x509_crt_set_activation_time:
782
798
 * @cert: a certificate of type #gnutls_x509_crt_t
783
799
 * @act_time: The actual time
784
800
 *
803
819
}
804
820
 
805
821
/**
806
 
 * gnutls_x509_crt_set_expiration_time - Set the Certificate's expiration time
 
822
 * gnutls_x509_crt_set_expiration_time:
807
823
 * @cert: a certificate of type #gnutls_x509_crt_t
808
824
 * @exp_time: The actual time
809
825
 *
825
841
}
826
842
 
827
843
/**
828
 
 * gnutls_x509_crt_set_serial - Set the certificate's serial number
 
844
 * gnutls_x509_crt_set_serial:
829
845
 * @cert: a certificate of type #gnutls_x509_crt_t
830
846
 * @serial: The serial number
831
847
 * @serial_size: Holds the size of the serial field.
884
900
}
885
901
 
886
902
/**
887
 
 * gnutls_x509_crt_set_crl_dist_points - Set the CRL dist points
 
903
 * gnutls_x509_crt_set_crl_dist_points:
888
904
 * @crt: a certificate of type #gnutls_x509_crt_t
889
905
 * @type: is one of the gnutls_x509_subject_alt_name_t enumerations
890
906
 * @data_string: The data to be set
907
923
}
908
924
 
909
925
/**
910
 
 * gnutls_x509_crt_set_crl_dist_points2 - Set the CRL dist points
 
926
 * gnutls_x509_crt_set_crl_dist_points2:
911
927
 * @crt: a certificate of type #gnutls_x509_crt_t
912
928
 * @type: is one of the gnutls_x509_subject_alt_name_t enumerations
913
929
 * @data: The data to be set
980
996
}
981
997
 
982
998
/**
983
 
 * gnutls_x509_crt_cpy_crl_dist_points - Copy the CRL dist points
 
999
 * gnutls_x509_crt_cpy_crl_dist_points:
984
1000
 * @dst: a certificate of type #gnutls_x509_crt_t
985
1001
 * @src: the certificate where the dist points will be copied from
986
1002
 *
1032
1048
}
1033
1049
 
1034
1050
/**
1035
 
 * gnutls_x509_crt_set_subject_key_id - Set the certificate's subject key id
 
1051
 * gnutls_x509_crt_set_subject_key_id:
1036
1052
 * @cert: a certificate of type #gnutls_x509_crt_t
1037
1053
 * @id: The key ID
1038
1054
 * @id_size: Holds the size of the serial field.
1095
1111
}
1096
1112
 
1097
1113
/**
1098
 
 * gnutls_x509_crt_set_authority_key_id - Set the certificate authority's key id
 
1114
 * gnutls_x509_crt_set_authority_key_id:
1099
1115
 * @cert: a certificate of type #gnutls_x509_crt_t
1100
1116
 * @id: The key ID
1101
1117
 * @id_size: Holds the size of the serial field.
1158
1174
}
1159
1175
 
1160
1176
/**
1161
 
 * gnutls_x509_crt_set_key_purpose_oid - Sets the Certificate's key purpose OIDs
 
1177
 * gnutls_x509_crt_set_key_purpose_oid:
1162
1178
 * @cert: a certificate of type #gnutls_x509_crt_t
1163
1179
 * @oid: a pointer to a null terminated string that holds the OID
1164
1180
 * @critical: Whether this extension will be critical or not
1174
1190
 **/
1175
1191
int
1176
1192
gnutls_x509_crt_set_key_purpose_oid (gnutls_x509_crt_t cert,
1177
 
                                     const void *oid,
1178
 
                                     unsigned int critical)
 
1193
                                     const void *oid, unsigned int critical)
1179
1194
{
1180
1195
  int result;
1181
1196
  gnutls_datum_t old_id, der_data;