diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2003-03-31 23:05:48 +0000 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2003-03-31 23:05:48 +0000 |
commit | 32328077b3b8f066a613c9623e6764b14d26aaca (patch) | |
tree | f5493e32d31eceed50c472c983f6cab395dc011d /lib/x509 | |
parent | 3f5ffcac52749fee10e57f945116a6d5ab48f7ae (diff) | |
download | gnutls-32328077b3b8f066a613c9623e6764b14d26aaca.tar.gz |
More fixes to eliminate constants.
Diffstat (limited to 'lib/x509')
-rw-r--r-- | lib/x509/crl.c | 26 | ||||
-rw-r--r-- | lib/x509/x509.c | 55 |
2 files changed, 69 insertions, 12 deletions
diff --git a/lib/x509/crl.c b/lib/x509/crl.c index 2dbc0501ee..49510cdeb8 100644 --- a/lib/x509/crl.c +++ b/lib/x509/crl.c @@ -96,6 +96,7 @@ int gnutls_x509_crl_import(gnutls_x509_crl crl, const gnutls_datum * data, int result = 0, need_free = 0; int start, end; gnutls_datum _data = { data->data, data->size }; + opaque *signature = NULL; /* If the CRL is in PEM format then decode it */ @@ -150,12 +151,25 @@ int gnutls_x509_crl_import(gnutls_x509_crl crl, const gnutls_datum * data, /* Read the signature */ { - opaque signature[640]; int len; + len = 0; + result = asn1_read_value( crl->crl, "signature", NULL, &len); + + if (result != ASN1_MEM_ERROR) { + result = _gnutls_asn2err(result); + gnutls_assert(); + goto cleanup; + } + + signature = gnutls_malloc( len); + if (signature == NULL) { + gnutls_assert(); + return GNUTLS_E_MEMORY_ERROR; + } + /* read the bit string of the signature */ - len = sizeof(signature); result = asn1_read_value(crl->crl, "signature", signature, &len); @@ -183,7 +197,6 @@ int gnutls_x509_crl_import(gnutls_x509_crl crl, const gnutls_datum * data, * read. They will be read from the issuer's certificate if needed. */ - len = sizeof(signature); result = asn1_read_value(crl->crl, "signatureAlgorithm.algorithm", @@ -194,9 +207,13 @@ int gnutls_x509_crl_import(gnutls_x509_crl crl, const gnutls_datum * data, gnutls_assert(); goto cleanup; } - + crl->signature_algorithm = _gnutls_x509_oid2pk_algorithm(signature); + + gnutls_free( signature); + signature = NULL; + } if (need_free) @@ -205,6 +222,7 @@ int gnutls_x509_crl_import(gnutls_x509_crl crl, const gnutls_datum * data, return 0; cleanup: + gnutls_free( signature); _gnutls_free_datum(&crl->signed_data); _gnutls_free_datum(&crl->signature); if (need_free) diff --git a/lib/x509/x509.c b/lib/x509/x509.c index 75f0bdd86d..43873e96fc 100644 --- a/lib/x509/x509.c +++ b/lib/x509/x509.c @@ -150,6 +150,7 @@ int gnutls_x509_crt_import(gnutls_x509_crt cert, const gnutls_datum * data, int result = 0, need_free = 0; int start, end; gnutls_datum _data = { data->data, data->size }; + opaque *signature = NULL; /* If the Certificate is in PEM format then decode it */ @@ -205,14 +206,29 @@ int gnutls_x509_crt_import(gnutls_x509_crt cert, const gnutls_datum * data, goto cleanup; } - /* Read the signature */ + /* Read the signature + */ { - opaque signature[640]; int len; + + len = 0; + result = asn1_read_value( cert->cert, "signature", NULL, &len); + + if (result != ASN1_MEM_ERROR) { + result = _gnutls_asn2err(result); + gnutls_assert(); + goto cleanup; + } + + signature = gnutls_malloc( len); + if (signature == NULL) { + gnutls_assert(); + return GNUTLS_E_MEMORY_ERROR; + } + /* read the bit string of the signature */ - len = sizeof(signature); result = asn1_read_value( cert->cert, "signature", signature, &len); @@ -237,7 +253,6 @@ int gnutls_x509_crt_import(gnutls_x509_crt cert, const gnutls_datum * data, * read. They will be read from the issuer's certificate if needed. */ - len = sizeof(signature); result = asn1_read_value( cert->cert, "signatureAlgorithm.algorithm", signature, &len); @@ -246,8 +261,11 @@ int gnutls_x509_crt_import(gnutls_x509_crt cert, const gnutls_datum * data, gnutls_assert(); goto cleanup; } - + cert->signature_algorithm = _gnutls_x509_oid2pk_algorithm( signature); + + gnutls_free( signature); + signature = NULL; } if (need_free) _gnutls_free_datum( &_data); @@ -255,6 +273,7 @@ int gnutls_x509_crt_import(gnutls_x509_crt cert, const gnutls_datum * data, return 0; cleanup: + gnutls_free( signature); _gnutls_free_datum(&cert->signed_data); _gnutls_free_datum(&cert->signature); if (need_free) _gnutls_free_datum( &_data); @@ -505,27 +524,45 @@ int gnutls_x509_crt_get_serial(gnutls_x509_crt cert, char* result, int* result_s int gnutls_x509_crt_get_pk_algorithm( gnutls_x509_crt cert, int* bits) { int result; - opaque str[MAX_X509_CERT_SIZE]; + opaque *str; int algo; int len = sizeof(str); GNUTLS_MPI params[MAX_PUBLIC_PARAMS_SIZE]; - len = sizeof(str) - 1; + len = 0; result = asn1_read_value (cert->cert, "tbsCertificate.subjectPublicKeyInfo.algorithm.algorithm", - str, &len); + NULL, &len); + + if (result != ASN1_MEM_ERROR) { + gnutls_assert(); + return _gnutls_asn2err(result); + } + + str = gnutls_malloc( len); + if (str == NULL) { + gnutls_assert(); + return GNUTLS_E_MEMORY_ERROR; + } + result = + asn1_read_value + (cert->cert, + "tbsCertificate.subjectPublicKeyInfo.algorithm.algorithm", + str, &len); if (result != ASN1_SUCCESS) { gnutls_assert(); + gnutls_free(str); return _gnutls_asn2err(result); } algo = _gnutls_x509_oid2pk_algorithm( str); if ( bits==NULL) { + gnutls_free(str); return algo; } @@ -540,6 +577,7 @@ int gnutls_x509_crt_get_pk_algorithm( gnutls_x509_crt cert, int* bits) if (result != ASN1_SUCCESS) { gnutls_assert(); + gnutls_free(str); return _gnutls_asn2err(result); } @@ -569,6 +607,7 @@ int gnutls_x509_crt_get_pk_algorithm( gnutls_x509_crt cert, int* bits) _gnutls_mpi_release( ¶ms[3]); } + gnutls_free(str); return algo; } |