aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/https/x509/mpi.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/https/x509/mpi.c')
-rw-r--r--src/daemon/https/x509/mpi.c317
1 files changed, 0 insertions, 317 deletions
diff --git a/src/daemon/https/x509/mpi.c b/src/daemon/https/x509/mpi.c
index 76995fdb..e8563967 100644
--- a/src/daemon/https/x509/mpi.c
+++ b/src/daemon/https/x509/mpi.c
@@ -83,126 +83,6 @@ MHD__gnutls_x509_read_rsa_params (opaque * der, int dersize, mpi_t * params)
83 83
84} 84}
85 85
86/* reads p,q and g
87 * from the certificate (subjectPublicKey BIT STRING).
88 * params[0-2]
89 */
90int
91MHD__gnutls_x509_read_dsa_params (opaque * der, int dersize, mpi_t * params)
92{
93 int result;
94 ASN1_TYPE spk = ASN1_TYPE_EMPTY;
95
96 if ((result =
97 MHD__asn1_create_element (MHD__gnutls_get_pkix (), "PKIX1.Dss-Parms",
98 &spk)) != ASN1_SUCCESS)
99 {
100 MHD_gnutls_assert ();
101 return MHD_gtls_asn2err (result);
102 }
103
104 result = MHD__asn1_der_decoding (&spk, der, dersize, NULL);
105
106 if (result != ASN1_SUCCESS)
107 {
108 MHD_gnutls_assert ();
109 MHD__asn1_delete_structure (&spk);
110 return MHD_gtls_asn2err (result);
111 }
112
113 /* FIXME: If the parameters are not included in the certificate
114 * then the issuer's parameters should be used. This is not
115 * done yet.
116 */
117
118 /* Read p */
119
120 if ((result = MHD__gnutls_x509_read_int (spk, "p", &params[0])) < 0)
121 {
122 MHD_gnutls_assert ();
123 MHD__asn1_delete_structure (&spk);
124 return GNUTLS_E_ASN1_GENERIC_ERROR;
125 }
126
127 /* Read q */
128
129 if ((result = MHD__gnutls_x509_read_int (spk, "q", &params[1])) < 0)
130 {
131 MHD_gnutls_assert ();
132 MHD__asn1_delete_structure (&spk);
133 MHD_gtls_mpi_release (&params[0]);
134 return GNUTLS_E_ASN1_GENERIC_ERROR;
135 }
136
137 /* Read g */
138
139 if ((result = MHD__gnutls_x509_read_int (spk, "g", &params[2])) < 0)
140 {
141 MHD_gnutls_assert ();
142 MHD__asn1_delete_structure (&spk);
143 MHD_gtls_mpi_release (&params[0]);
144 MHD_gtls_mpi_release (&params[1]);
145 return GNUTLS_E_ASN1_GENERIC_ERROR;
146 }
147
148 MHD__asn1_delete_structure (&spk);
149
150 return 0;
151
152}
153
154/* Reads an Integer from the DER encoded data
155 */
156
157int
158MHD__gnutls_x509_read_der_int (opaque * der, int dersize, mpi_t * out)
159{
160 int result;
161 ASN1_TYPE spk = ASN1_TYPE_EMPTY;
162
163 /* == INTEGER */
164 if ((result =
165 MHD__asn1_create_element (MHD__gnutls_getMHD__gnutls_asn (),
166 "GNUTLS.DSAPublicKey",
167 &spk)) != ASN1_SUCCESS)
168 {
169 MHD_gnutls_assert ();
170 return MHD_gtls_asn2err (result);
171 }
172
173 result = MHD__asn1_der_decoding (&spk, der, dersize, NULL);
174
175 if (result != ASN1_SUCCESS)
176 {
177 MHD_gnutls_assert ();
178 MHD__asn1_delete_structure (&spk);
179 return MHD_gtls_asn2err (result);
180 }
181
182 /* Read Y */
183
184 if ((result = MHD__gnutls_x509_read_int (spk, "", out)) < 0)
185 {
186 MHD_gnutls_assert ();
187 MHD__asn1_delete_structure (&spk);
188 return MHD_gtls_asn2err (result);
189 }
190
191 MHD__asn1_delete_structure (&spk);
192
193 return 0;
194
195}
196
197/* reads DSA's Y
198 * from the certificate
199 * only sets params[3]
200 */
201int
202MHD__gnutls_x509_read_dsa_pubkey (opaque * der, int dersize, mpi_t * params)
203{
204 return MHD__gnutls_x509_read_der_int (der, dersize, &params[3]);
205}
206 86
207/* Extracts DSA and RSA parameters from a certificate. 87/* Extracts DSA and RSA parameters from a certificate.
208 */ 88 */
@@ -331,181 +211,6 @@ cleanup:MHD__asn1_delete_structure (&spk);
331 return result; 211 return result;
332} 212}
333 213
334/*
335 * This function writes and encodes the parameters for DSS or RSA keys.
336 * This is the "signatureAlgorithm" fields.
337 */
338int
339MHD__gnutls_x509_write_sig_params (ASN1_TYPE dst,
340 const char *dst_name,
341 enum MHD_GNUTLS_PublicKeyAlgorithm
342 pk_algorithm,
343 enum MHD_GNUTLS_HashAlgorithm dig,
344 mpi_t * params, int params_size)
345{
346 int result;
347 char name[128];
348 const char *pk;
349
350 MHD_gtls_str_cpy (name, sizeof (name), dst_name);
351 MHD_gtls_str_cat (name, sizeof (name), ".algorithm");
352
353 pk = MHD_gtls_x509_sign_to_oid (pk_algorithm, HASH2MAC (dig));
354 if (pk == NULL)
355 {
356 MHD_gnutls_assert ();
357 return GNUTLS_E_INVALID_REQUEST;
358 }
359
360 /* write the OID.
361 */
362 result = MHD__asn1_write_value (dst, name, pk, 1);
363 if (result != ASN1_SUCCESS)
364 {
365 MHD_gnutls_assert ();
366 return MHD_gtls_asn2err (result);
367 }
368
369 MHD_gtls_str_cpy (name, sizeof (name), dst_name);
370 MHD_gtls_str_cat (name, sizeof (name), ".parameters");
371
372 if (pk_algorithm == MHD_GNUTLS_PK_RSA)
373 { /* RSA */
374 result = MHD__asn1_write_value (dst, name, NULL, 0);
375
376 if (result != ASN1_SUCCESS && result != ASN1_ELEMENT_NOT_FOUND)
377 {
378 /* Here we ignore the element not found error, since this
379 * may have been disabled before.
380 */
381 MHD_gnutls_assert ();
382 return MHD_gtls_asn2err (result);
383 }
384 }
385
386 return 0;
387}
388
389/*
390 * This function writes the parameters for DSS keys.
391 * Needs 3 parameters (p,q,g).
392 *
393 * Allocates the space used to store the DER data.
394 */
395int
396MHD__gnutls_x509_write_dsa_params (mpi_t * params,
397 int params_size, MHD_gnutls_datum_t * der)
398{
399 int result;
400 ASN1_TYPE spk = ASN1_TYPE_EMPTY;
401
402 der->data = NULL;
403 der->size = 0;
404
405 if (params_size < 3)
406 {
407 MHD_gnutls_assert ();
408 result = GNUTLS_E_INVALID_REQUEST;
409 goto cleanup;
410 }
411
412 if ((result =
413 MHD__asn1_create_element (MHD__gnutls_getMHD__gnutls_asn (),
414 "GNUTLS.DSAParameters",
415 &spk)) != ASN1_SUCCESS)
416 {
417 MHD_gnutls_assert ();
418 return MHD_gtls_asn2err (result);
419 }
420
421 result = MHD__gnutls_x509_write_int (spk, "p", params[0], 0);
422 if (result < 0)
423 {
424 MHD_gnutls_assert ();
425 goto cleanup;
426 }
427
428 result = MHD__gnutls_x509_write_int (spk, "q", params[1], 0);
429 if (result < 0)
430 {
431 MHD_gnutls_assert ();
432 goto cleanup;
433 }
434
435 result = MHD__gnutls_x509_write_int (spk, "g", params[2], 0);
436 if (result < 0)
437 {
438 MHD_gnutls_assert ();
439 goto cleanup;
440 }
441
442 result = MHD__gnutls_x509_der_encode (spk, "", der, 0);
443 if (result < 0)
444 {
445 MHD_gnutls_assert ();
446 goto cleanup;
447 }
448
449 result = 0;
450
451cleanup:MHD__asn1_delete_structure (&spk);
452 return result;
453}
454
455/*
456 * This function writes the public parameters for DSS keys.
457 * Needs 1 parameter (y).
458 *
459 * Allocates the space used to store the DER data.
460 */
461int
462MHD__gnutls_x509_write_dsa_public_key (mpi_t * params,
463 int params_size,
464 MHD_gnutls_datum_t * der)
465{
466 int result;
467 ASN1_TYPE spk = ASN1_TYPE_EMPTY;
468
469 der->data = NULL;
470 der->size = 0;
471
472 if (params_size < 3)
473 {
474 MHD_gnutls_assert ();
475 result = GNUTLS_E_INVALID_REQUEST;
476 goto cleanup;
477 }
478
479 if ((result =
480 MHD__asn1_create_element (MHD__gnutls_getMHD__gnutls_asn (),
481 "GNUTLS.DSAPublicKey",
482 &spk)) != ASN1_SUCCESS)
483 {
484 MHD_gnutls_assert ();
485 return MHD_gtls_asn2err (result);
486 }
487
488 result = MHD__gnutls_x509_write_int (spk, "", params[3], 0);
489 if (result < 0)
490 {
491 MHD_gnutls_assert ();
492 goto cleanup;
493 }
494
495 result = MHD__gnutls_x509_der_encode (spk, "", der, 0);
496 if (result < 0)
497 {
498 MHD_gnutls_assert ();
499 goto cleanup;
500 }
501
502 MHD__asn1_delete_structure (&spk);
503 return 0;
504
505cleanup:MHD__asn1_delete_structure (&spk);
506 return result;
507}
508
509/* this function reads a (small) unsigned integer 214/* this function reads a (small) unsigned integer
510 * from asn1 structs. Combines the read and the convertion 215 * from asn1 structs. Combines the read and the convertion
511 * steps. 216 * steps.
@@ -560,25 +265,3 @@ MHD__gnutls_x509_read_uint (ASN1_TYPE node, const char *value,
560 265
561 return 0; 266 return 0;
562} 267}
563
564/* Writes the specified integer into the specified node.
565 */
566int
567MHD__gnutls_x509_write_uint32 (ASN1_TYPE node, const char *value,
568 uint32_t num)
569{
570 opaque tmpstr[4];
571 int result;
572
573 MHD_gtls_write_uint32 (num, tmpstr);
574
575 result = MHD__asn1_write_value (node, value, tmpstr, 4);
576
577 if (result != ASN1_SUCCESS)
578 {
579 MHD_gnutls_assert ();
580 return MHD_gtls_asn2err (result);
581 }
582
583 return 0;
584}