aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/https/x509/crq.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/https/x509/crq.c')
-rw-r--r--src/daemon/https/x509/crq.c123
1 files changed, 67 insertions, 56 deletions
diff --git a/src/daemon/https/x509/crq.c b/src/daemon/https/x509/crq.c
index 147be276..88ac349d 100644
--- a/src/daemon/https/x509/crq.c
+++ b/src/daemon/https/x509/crq.c
@@ -59,8 +59,8 @@ MHD_gnutls_x509_crq_init (MHD_gnutls_x509_crq_t * crq)
59 if (*crq) 59 if (*crq)
60 { 60 {
61 int result = MHD__asn1_create_element (MHD__gnutls_get_pkix (), 61 int result = MHD__asn1_create_element (MHD__gnutls_get_pkix (),
62 "PKIX1.pkcs-10-CertificationRequest", 62 "PKIX1.pkcs-10-CertificationRequest",
63 &((*crq)->crq)); 63 &((*crq)->crq));
64 if (result != ASN1_SUCCESS) 64 if (result != ASN1_SUCCESS)
65 { 65 {
66 MHD_gnutls_assert (); 66 MHD_gnutls_assert ();
@@ -110,8 +110,8 @@ MHD_gnutls_x509_crq_deinit (MHD_gnutls_x509_crq_t crq)
110 **/ 110 **/
111int 111int
112MHD_gnutls_x509_crq_import (MHD_gnutls_x509_crq_t crq, 112MHD_gnutls_x509_crq_import (MHD_gnutls_x509_crq_t crq,
113 const MHD_gnutls_datum_t * data, 113 const MHD_gnutls_datum_t * data,
114 MHD_gnutls_x509_crt_fmt_t format) 114 MHD_gnutls_x509_crt_fmt_t format)
115{ 115{
116 int result = 0, need_free = 0; 116 int result = 0, need_free = 0;
117 MHD_gnutls_datum_t _data; 117 MHD_gnutls_datum_t _data;
@@ -132,7 +132,8 @@ MHD_gnutls_x509_crq_import (MHD_gnutls_x509_crq_t crq,
132 opaque *out; 132 opaque *out;
133 133
134 /* Try the first header */ 134 /* Try the first header */
135 result = MHD__gnutls_fbase64_decode (PEM_CRQ, data->data, data->size, &out); 135 result =
136 MHD__gnutls_fbase64_decode (PEM_CRQ, data->data, data->size, &out);
136 137
137 if (result <= 0) /* Go for the second header */ 138 if (result <= 0) /* Go for the second header */
138 result = 139 result =
@@ -189,7 +190,8 @@ cleanup:
189 * 190 *
190 **/ 191 **/
191int 192int
192MHD_gnutls_x509_crq_get_dn (MHD_gnutls_x509_crq_t crq, char *buf, size_t * sizeof_buf) 193MHD_gnutls_x509_crq_get_dn (MHD_gnutls_x509_crq_t crq, char *buf,
194 size_t * sizeof_buf)
193{ 195{
194 if (crq == NULL) 196 if (crq == NULL)
195 { 197 {
@@ -198,8 +200,8 @@ MHD_gnutls_x509_crq_get_dn (MHD_gnutls_x509_crq_t crq, char *buf, size_t * sizeo
198 } 200 }
199 201
200 return MHD__gnutls_x509_parse_dn (crq->crq, 202 return MHD__gnutls_x509_parse_dn (crq->crq,
201 "certificationRequestInfo.subject.rdnSequence", 203 "certificationRequestInfo.subject.rdnSequence",
202 buf, sizeof_buf); 204 buf, sizeof_buf);
203} 205}
204 206
205/** 207/**
@@ -232,8 +234,8 @@ MHD_gnutls_x509_crq_get_dn (MHD_gnutls_x509_crq_t crq, char *buf, size_t * sizeo
232 **/ 234 **/
233int 235int
234MHD_gnutls_x509_crq_get_dn_by_oid (MHD_gnutls_x509_crq_t crq, const char *oid, 236MHD_gnutls_x509_crq_get_dn_by_oid (MHD_gnutls_x509_crq_t crq, const char *oid,
235 int indx, unsigned int raw_flag, 237 int indx, unsigned int raw_flag,
236 void *buf, size_t * sizeof_buf) 238 void *buf, size_t * sizeof_buf)
237{ 239{
238 if (crq == NULL) 240 if (crq == NULL)
239 { 241 {
@@ -242,8 +244,8 @@ MHD_gnutls_x509_crq_get_dn_by_oid (MHD_gnutls_x509_crq_t crq, const char *oid,
242 } 244 }
243 245
244 return MHD__gnutls_x509_parse_dn_oid (crq->crq, 246 return MHD__gnutls_x509_parse_dn_oid (crq->crq,
245 "certificationRequestInfo.subject.rdnSequence", 247 "certificationRequestInfo.subject.rdnSequence",
246 oid, indx, raw_flag, buf, sizeof_buf); 248 oid, indx, raw_flag, buf, sizeof_buf);
247} 249}
248 250
249/** 251/**
@@ -265,7 +267,7 @@ MHD_gnutls_x509_crq_get_dn_by_oid (MHD_gnutls_x509_crq_t crq, const char *oid,
265 **/ 267 **/
266int 268int
267MHD_gnutls_x509_crq_get_dn_oid (MHD_gnutls_x509_crq_t crq, 269MHD_gnutls_x509_crq_get_dn_oid (MHD_gnutls_x509_crq_t crq,
268 int indx, void *oid, size_t * sizeof_oid) 270 int indx, void *oid, size_t * sizeof_oid)
269{ 271{
270 if (crq == NULL) 272 if (crq == NULL)
271 { 273 {
@@ -274,8 +276,8 @@ MHD_gnutls_x509_crq_get_dn_oid (MHD_gnutls_x509_crq_t crq,
274 } 276 }
275 277
276 return MHD__gnutls_x509_get_dn_oid (crq->crq, 278 return MHD__gnutls_x509_get_dn_oid (crq->crq,
277 "certificationRequestInfo.subject.rdnSequence", 279 "certificationRequestInfo.subject.rdnSequence",
278 indx, oid, sizeof_oid); 280 indx, oid, sizeof_oid);
279} 281}
280 282
281/* Parses an Attribute list in the MHD__asn1_struct, and searches for the 283/* Parses an Attribute list in the MHD__asn1_struct, and searches for the
@@ -319,7 +321,8 @@ parse_attribute (ASN1_TYPE MHD__asn1_struct,
319 snprintf (tmpbuffer1, sizeof (tmpbuffer1), "?%u", k1); 321 snprintf (tmpbuffer1, sizeof (tmpbuffer1), "?%u", k1);
320 322
321 len = sizeof (value) - 1; 323 len = sizeof (value) - 1;
322 result = MHD__asn1_read_value (MHD__asn1_struct, tmpbuffer1, value, &len); 324 result =
325 MHD__asn1_read_value (MHD__asn1_struct, tmpbuffer1, value, &len);
323 326
324 if (result == ASN1_ELEMENT_NOT_FOUND) 327 if (result == ASN1_ELEMENT_NOT_FOUND)
325 { 328 {
@@ -362,7 +365,8 @@ parse_attribute (ASN1_TYPE MHD__asn1_struct,
362 tmpbuffer1, indx + 1); 365 tmpbuffer1, indx + 1);
363 366
364 len = sizeof (value) - 1; 367 len = sizeof (value) - 1;
365 result = MHD__asn1_read_value (MHD__asn1_struct, tmpbuffer3, value, &len); 368 result =
369 MHD__asn1_read_value (MHD__asn1_struct, tmpbuffer3, value, &len);
366 370
367 if (result != ASN1_SUCCESS) 371 if (result != ASN1_SUCCESS)
368 { 372 {
@@ -434,7 +438,7 @@ cleanup:
434 **/ 438 **/
435int 439int
436MHD_gnutls_x509_crq_get_challenge_password (MHD_gnutls_x509_crq_t crq, 440MHD_gnutls_x509_crq_get_challenge_password (MHD_gnutls_x509_crq_t crq,
437 char *pass, size_t * sizeof_pass) 441 char *pass, size_t * sizeof_pass)
438{ 442{
439 if (crq == NULL) 443 if (crq == NULL)
440 { 444 {
@@ -461,8 +465,8 @@ MHD_gnutls_x509_crq_get_challenge_password (MHD_gnutls_x509_crq_t crq,
461 **/ 465 **/
462int 466int
463MHD_gnutls_x509_crq_set_attribute_by_oid (MHD_gnutls_x509_crq_t crq, 467MHD_gnutls_x509_crq_set_attribute_by_oid (MHD_gnutls_x509_crq_t crq,
464 const char *oid, void *buf, 468 const char *oid, void *buf,
465 size_t sizeof_buf) 469 size_t sizeof_buf)
466{ 470{
467 int result; 471 int result;
468 472
@@ -476,7 +480,7 @@ MHD_gnutls_x509_crq_set_attribute_by_oid (MHD_gnutls_x509_crq_t crq,
476 */ 480 */
477 result = 481 result =
478 MHD__asn1_write_value (crq->crq, "certificationRequestInfo.attributes", 482 MHD__asn1_write_value (crq->crq, "certificationRequestInfo.attributes",
479 "NEW", 1); 483 "NEW", 1);
480 if (result != ASN1_SUCCESS) 484 if (result != ASN1_SUCCESS)
481 { 485 {
482 MHD_gnutls_assert (); 486 MHD_gnutls_assert ();
@@ -485,9 +489,9 @@ MHD_gnutls_x509_crq_set_attribute_by_oid (MHD_gnutls_x509_crq_t crq,
485 489
486 result = 490 result =
487 MHD__gnutls_x509_encode_and_write_attribute (oid, 491 MHD__gnutls_x509_encode_and_write_attribute (oid,
488 crq->crq, 492 crq->crq,
489 "certificationRequestInfo.attributes.?LAST", 493 "certificationRequestInfo.attributes.?LAST",
490 buf, sizeof_buf, 1); 494 buf, sizeof_buf, 1);
491 495
492 if (result < 0) 496 if (result < 0)
493 { 497 {
@@ -515,8 +519,8 @@ MHD_gnutls_x509_crq_set_attribute_by_oid (MHD_gnutls_x509_crq_t crq,
515 **/ 519 **/
516int 520int
517MHD_gnutls_x509_crq_get_attribute_by_oid (MHD_gnutls_x509_crq_t crq, 521MHD_gnutls_x509_crq_get_attribute_by_oid (MHD_gnutls_x509_crq_t crq,
518 const char *oid, int indx, void *buf, 522 const char *oid, int indx,
519 size_t * sizeof_buf) 523 void *buf, size_t * sizeof_buf)
520{ 524{
521 if (crq == NULL) 525 if (crq == NULL)
522 { 526 {
@@ -550,8 +554,8 @@ MHD_gnutls_x509_crq_get_attribute_by_oid (MHD_gnutls_x509_crq_t crq,
550 **/ 554 **/
551int 555int
552MHD_gnutls_x509_crq_set_dn_by_oid (MHD_gnutls_x509_crq_t crq, const char *oid, 556MHD_gnutls_x509_crq_set_dn_by_oid (MHD_gnutls_x509_crq_t crq, const char *oid,
553 unsigned int raw_flag, const void *data, 557 unsigned int raw_flag, const void *data,
554 unsigned int sizeof_data) 558 unsigned int sizeof_data)
555{ 559{
556 if (sizeof_data == 0 || data == NULL || crq == NULL) 560 if (sizeof_data == 0 || data == NULL || crq == NULL)
557 { 561 {
@@ -559,8 +563,8 @@ MHD_gnutls_x509_crq_set_dn_by_oid (MHD_gnutls_x509_crq_t crq, const char *oid,
559 } 563 }
560 564
561 return MHD__gnutls_x509_set_dn_oid (crq->crq, 565 return MHD__gnutls_x509_set_dn_oid (crq->crq,
562 "certificationRequestInfo.subject", oid, 566 "certificationRequestInfo.subject", oid,
563 raw_flag, data, sizeof_data); 567 raw_flag, data, sizeof_data);
564} 568}
565 569
566/** 570/**
@@ -575,7 +579,8 @@ MHD_gnutls_x509_crq_set_dn_by_oid (MHD_gnutls_x509_crq_t crq, const char *oid,
575 * 579 *
576 **/ 580 **/
577int 581int
578MHD_gnutls_x509_crq_set_version (MHD_gnutls_x509_crq_t crq, unsigned int version) 582MHD_gnutls_x509_crq_set_version (MHD_gnutls_x509_crq_t crq,
583 unsigned int version)
579{ 584{
580 int result; 585 int result;
581 unsigned char null = version; 586 unsigned char null = version;
@@ -590,7 +595,8 @@ MHD_gnutls_x509_crq_set_version (MHD_gnutls_x509_crq_t crq, unsigned int version
590 null--; 595 null--;
591 596
592 result = 597 result =
593 MHD__asn1_write_value (crq->crq, "certificationRequestInfo.version", &null, 1); 598 MHD__asn1_write_value (crq->crq, "certificationRequestInfo.version",
599 &null, 1);
594 if (result != ASN1_SUCCESS) 600 if (result != ASN1_SUCCESS)
595 { 601 {
596 MHD_gnutls_assert (); 602 MHD_gnutls_assert ();
@@ -624,7 +630,7 @@ MHD_gnutls_x509_crq_get_version (MHD_gnutls_x509_crq_t crq)
624 len = sizeof (version); 630 len = sizeof (version);
625 if ((result = 631 if ((result =
626 MHD__asn1_read_value (crq->crq, "certificationRequestInfo.version", 632 MHD__asn1_read_value (crq->crq, "certificationRequestInfo.version",
627 version, &len)) != ASN1_SUCCESS) 633 version, &len)) != ASN1_SUCCESS)
628 { 634 {
629 635
630 if (result == ASN1_ELEMENT_NOT_FOUND) 636 if (result == ASN1_ELEMENT_NOT_FOUND)
@@ -648,7 +654,8 @@ MHD_gnutls_x509_crq_get_version (MHD_gnutls_x509_crq_t crq)
648 * 654 *
649 **/ 655 **/
650int 656int
651MHD_gnutls_x509_crq_set_key (MHD_gnutls_x509_crq_t crq, MHD_gnutls_x509_privkey_t key) 657MHD_gnutls_x509_crq_set_key (MHD_gnutls_x509_crq_t crq,
658 MHD_gnutls_x509_privkey_t key)
652{ 659{
653 int result; 660 int result;
654 661
@@ -659,10 +666,10 @@ MHD_gnutls_x509_crq_set_key (MHD_gnutls_x509_crq_t crq, MHD_gnutls_x509_privkey_
659 } 666 }
660 667
661 result = MHD__gnutls_x509_encode_and_copy_PKI_params (crq->crq, 668 result = MHD__gnutls_x509_encode_and_copy_PKI_params (crq->crq,
662 "certificationRequestInfo.subjectPKInfo", 669 "certificationRequestInfo.subjectPKInfo",
663 key->pk_algorithm, 670 key->pk_algorithm,
664 key->params, 671 key->params,
665 key->params_size); 672 key->params_size);
666 673
667 if (result < 0) 674 if (result < 0)
668 { 675 {
@@ -685,7 +692,7 @@ MHD_gnutls_x509_crq_set_key (MHD_gnutls_x509_crq_t crq, MHD_gnutls_x509_privkey_
685 **/ 692 **/
686int 693int
687MHD_gnutls_x509_crq_set_challenge_password (MHD_gnutls_x509_crq_t crq, 694MHD_gnutls_x509_crq_set_challenge_password (MHD_gnutls_x509_crq_t crq,
688 const char *pass) 695 const char *pass)
689{ 696{
690 int result; 697 int result;
691 698
@@ -699,7 +706,7 @@ MHD_gnutls_x509_crq_set_challenge_password (MHD_gnutls_x509_crq_t crq,
699 */ 706 */
700 result = 707 result =
701 MHD__asn1_write_value (crq->crq, "certificationRequestInfo.attributes", 708 MHD__asn1_write_value (crq->crq, "certificationRequestInfo.attributes",
702 "NEW", 1); 709 "NEW", 1);
703 if (result != ASN1_SUCCESS) 710 if (result != ASN1_SUCCESS)
704 { 711 {
705 MHD_gnutls_assert (); 712 MHD_gnutls_assert ();
@@ -708,9 +715,9 @@ MHD_gnutls_x509_crq_set_challenge_password (MHD_gnutls_x509_crq_t crq,
708 715
709 result = 716 result =
710 MHD__gnutls_x509_encode_and_write_attribute ("1.2.840.113549.1.9.7", 717 MHD__gnutls_x509_encode_and_write_attribute ("1.2.840.113549.1.9.7",
711 crq->crq, 718 crq->crq,
712 "certificationRequestInfo.attributes.?LAST", 719 "certificationRequestInfo.attributes.?LAST",
713 pass, strlen (pass), 1); 720 pass, strlen (pass), 1);
714 721
715 if (result < 0) 722 if (result < 0)
716 { 723 {
@@ -739,8 +746,10 @@ MHD_gnutls_x509_crq_set_challenge_password (MHD_gnutls_x509_crq_t crq,
739 * 746 *
740 **/ 747 **/
741int 748int
742MHD_gnutls_x509_crq_sign2 (MHD_gnutls_x509_crq_t crq, MHD_gnutls_x509_privkey_t key, 749MHD_gnutls_x509_crq_sign2 (MHD_gnutls_x509_crq_t crq,
743 enum MHD_GNUTLS_HashAlgorithm dig, unsigned int flags) 750 MHD_gnutls_x509_privkey_t key,
751 enum MHD_GNUTLS_HashAlgorithm dig,
752 unsigned int flags)
744{ 753{
745 int result; 754 int result;
746 MHD_gnutls_datum_t signature; 755 MHD_gnutls_datum_t signature;
@@ -755,7 +764,7 @@ MHD_gnutls_x509_crq_sign2 (MHD_gnutls_x509_crq_t crq, MHD_gnutls_x509_privkey_t
755 */ 764 */
756 result = 765 result =
757 MHD__gnutls_x509_sign_tbs (crq->crq, "certificationRequestInfo", 766 MHD__gnutls_x509_sign_tbs (crq->crq, "certificationRequestInfo",
758 dig, key, &signature); 767 dig, key, &signature);
759 768
760 if (result < 0) 769 if (result < 0)
761 { 770 {
@@ -767,7 +776,7 @@ MHD_gnutls_x509_crq_sign2 (MHD_gnutls_x509_crq_t crq, MHD_gnutls_x509_privkey_t
767 */ 776 */
768 result = 777 result =
769 MHD__asn1_write_value (crq->crq, "signature", signature.data, 778 MHD__asn1_write_value (crq->crq, "signature", signature.data,
770 signature.size * 8); 779 signature.size * 8);
771 780
772 MHD__gnutls_free_datum (&signature); 781 MHD__gnutls_free_datum (&signature);
773 782
@@ -780,8 +789,8 @@ MHD_gnutls_x509_crq_sign2 (MHD_gnutls_x509_crq_t crq, MHD_gnutls_x509_privkey_t
780 /* Step 3. Write the signatureAlgorithm field. 789 /* Step 3. Write the signatureAlgorithm field.
781 */ 790 */
782 result = MHD__gnutls_x509_write_sig_params (crq->crq, "signatureAlgorithm", 791 result = MHD__gnutls_x509_write_sig_params (crq->crq, "signatureAlgorithm",
783 key->pk_algorithm, dig, key->params, 792 key->pk_algorithm, dig,
784 key->params_size); 793 key->params, key->params_size);
785 if (result < 0) 794 if (result < 0)
786 { 795 {
787 MHD_gnutls_assert (); 796 MHD_gnutls_assert ();
@@ -803,7 +812,8 @@ MHD_gnutls_x509_crq_sign2 (MHD_gnutls_x509_crq_t crq, MHD_gnutls_x509_privkey_t
803 * 812 *
804 **/ 813 **/
805int 814int
806MHD_gnutls_x509_crq_sign (MHD_gnutls_x509_crq_t crq, MHD_gnutls_x509_privkey_t key) 815MHD_gnutls_x509_crq_sign (MHD_gnutls_x509_crq_t crq,
816 MHD_gnutls_x509_privkey_t key)
807{ 817{
808 return MHD_gnutls_x509_crq_sign2 (crq, key, MHD_GNUTLS_MAC_SHA1, 0); 818 return MHD_gnutls_x509_crq_sign2 (crq, key, MHD_GNUTLS_MAC_SHA1, 0);
809} 819}
@@ -831,8 +841,8 @@ MHD_gnutls_x509_crq_sign (MHD_gnutls_x509_crq_t crq, MHD_gnutls_x509_privkey_t k
831 **/ 841 **/
832int 842int
833MHD_gnutls_x509_crq_export (MHD_gnutls_x509_crq_t crq, 843MHD_gnutls_x509_crq_export (MHD_gnutls_x509_crq_t crq,
834 MHD_gnutls_x509_crt_fmt_t format, void *output_data, 844 MHD_gnutls_x509_crt_fmt_t format,
835 size_t * output_data_size) 845 void *output_data, size_t * output_data_size)
836{ 846{
837 if (crq == NULL) 847 if (crq == NULL)
838 { 848 {
@@ -841,7 +851,7 @@ MHD_gnutls_x509_crq_export (MHD_gnutls_x509_crq_t crq,
841 } 851 }
842 852
843 return MHD__gnutls_x509_export_int (crq->crq, format, PEM_CRQ, 853 return MHD__gnutls_x509_export_int (crq->crq, format, PEM_CRQ,
844 output_data, output_data_size); 854 output_data, output_data_size);
845} 855}
846 856
847/** 857/**
@@ -862,7 +872,8 @@ MHD_gnutls_x509_crq_export (MHD_gnutls_x509_crq_t crq,
862 * 872 *
863 **/ 873 **/
864int 874int
865MHD_gnutls_x509_crq_get_pk_algorithm (MHD_gnutls_x509_crq_t crq, unsigned int *bits) 875MHD_gnutls_x509_crq_get_pk_algorithm (MHD_gnutls_x509_crq_t crq,
876 unsigned int *bits)
866{ 877{
867 int result; 878 int result;
868 879
@@ -874,8 +885,8 @@ MHD_gnutls_x509_crq_get_pk_algorithm (MHD_gnutls_x509_crq_t crq, unsigned int *b
874 885
875 result = 886 result =
876 MHD__gnutls_x509_get_pk_algorithm (crq->crq, 887 MHD__gnutls_x509_get_pk_algorithm (crq->crq,
877 "certificationRequestInfo.subjectPKInfo", 888 "certificationRequestInfo.subjectPKInfo",
878 bits); 889 bits);
879 if (result < 0) 890 if (result < 0)
880 { 891 {
881 MHD_gnutls_assert (); 892 MHD_gnutls_assert ();