}
if (format == GNUTLS_X509_FMT_DER) {
+ if (params_data == NULL) *params_data_size = 0;
+
if ((result=asn1_der_coding( c2, "", params_data, params_data_size, NULL)) != ASN1_SUCCESS) {
gnutls_assert();
asn1_delete_structure(&c2);
asn1_delete_structure(&c2);
} else { /* PEM */
- opaque tmp[5*1024];
+ opaque *tmp;
opaque *out;
- int len = sizeof(tmp) - 1;
+ int len;
+
+ len = 0;
+ asn1_der_coding( c2, "", NULL, &len, NULL);
+ tmp = gnutls_alloca( len);
+ if (tmp == NULL) {
+ gnutls_assert();
+ return GNUTLS_E_MEMORY_ERROR;
+ }
+
if ((result=asn1_der_coding( c2, "", tmp, &len, NULL)) != ASN1_SUCCESS) {
gnutls_assert();
+ gnutls_afree( tmp);
asn1_delete_structure(&c2);
return _gnutls_asn2err(result);
}
result = _gnutls_fbase64_encode("DH PARAMETERS",
tmp, len, &out);
+ gnutls_afree( tmp);
+
if (result < 0) {
gnutls_assert();
return result;
case ASN1_SYNTAX_ERROR:
return GNUTLS_E_ASN1_SYNTAX_ERROR;
case ASN1_MEM_ERROR:
- return GNUTLS_E_MEMORY_ERROR;
+ return GNUTLS_E_SHORT_MEMORY_BUFFER;
case ASN1_DER_OVERFLOW:
return GNUTLS_E_ASN1_DER_OVERFLOW;
default:
asn1_delete_structure(&sig);
}
+ if (sig_value->data == NULL) sig_value->size = 0;
+
result = asn1_der_coding( sig, "", sig_value->data, &sig_value->size, NULL);
if (result != ASN1_SUCCESS) {
gnutls_assert();
char tmpbuffer3[64];
char counter[MAX_INT_DIGITS];
char value[200];
- char escaped[256];
char oid[128];
int len, printable;
return _gnutls_asn2err(result);
}
- der_size = MAX_PARAMETER_SIZE*2 + 128;
+ _gnutls_x509_write_rsa_params( key->params, key->params_size, NULL, &der_size);
+
der = gnutls_alloca( der_size);
if (der == NULL) {
gnutls_assert();
}
/* This will encode and write the AttributeTypeAndValue field.
- * multi must be zero if writing an AttributeTypeAndValue, and 1 if Attribute.
+ * 'multi' must be zero if writing an AttributeTypeAndValue, and 1 if Attribute.
+ * In all cases only one value is written.
*/
int _gnutls_x509_encode_and_write_attribute( const char* given_oid, ASN1_TYPE asn1_struct,
const char* where, const unsigned char* data, int sizeof_data, int multi)
return _gnutls_asn2err(result);
}
- der_len = sizeof_data + 64;
- der = gnutls_alloca( der_len);
+ der_len = 0;
+ asn1_der_coding( c2, "", NULL, &der_len, NULL);
+ der = gnutls_alloca( der_len);
result = asn1_der_coding( c2, "", der, &der_len, NULL);
asn1_delete_structure( &c2);
return result;
}
+ if (der == NULL) *dersize = 0;
result = asn1_der_coding( spk, "", der, dersize, NULL);
asn1_delete_structure(&spk);
return _gnutls_asn2err(result);
}
- info->size = 128;
+ info->size = 0;
+ asn1_der_coding( dinfo, "", NULL, &info->size, NULL);
+
info->data = gnutls_malloc( info->size);
if (info->data == NULL) {
gnutls_assert();
gnutls_mac_algorithm hash, gnutls_x509_privkey signer, gnutls_datum* signature)
{
int result;
-opaque buf[MAX_X509_CERT_SIZE];
-int buf_size = sizeof(buf);
+opaque *buf;
+int buf_size;
gnutls_datum tbs;
+ buf_size = 0;
+ asn1_der_coding( cert, tbs_name, NULL, &buf_size, NULL);
+
+ buf = gnutls_alloca( buf_size);
+ if (buf == NULL) {
+ gnutls_assert();
+ return GNUTLS_E_MEMORY_ERROR;
+ }
+
result = asn1_der_coding( cert, tbs_name, buf, &buf_size, NULL);
if (result != ASN1_SUCCESS) {
gnutls_assert();
+ gnutls_afree(buf);
return _gnutls_asn2err(result);
}
tbs.data = buf;
tbs.size = buf_size;
- return _gnutls_x509_sign( &tbs, hash, signer, signature);
-
+ result = _gnutls_x509_sign( &tbs, hash, signer, signature);
+ gnutls_afree(buf);
+
+ return result;
}
#include <dn.h>
#include <x509.h>
#include <mpi.h>
+#include <common.h>
#include <verify.h>
static int _gnutls_verify_certificate2(gnutls_x509_crt cert,
gnutls_digest_algorithm algo, char *buf,
int *sizeof_buf)
{
-opaque cert_buf[MAX_X509_CERT_SIZE];
-int cert_buf_size = sizeof( cert_buf);
+opaque *cert_buf;
+int cert_buf_size;
int result;
gnutls_datum tmp;
return GNUTLS_E_INVALID_REQUEST;
}
+ cert_buf_size = 0;
+ asn1_der_coding( cert->cert, "", NULL, &cert_buf_size, NULL);
+
+ cert_buf = gnutls_alloca( cert_buf_size);
+ if (cert_buf == NULL) {
+ gnutls_assert();
+ return GNUTLS_E_MEMORY_ERROR;
+ }
+
result = asn1_der_coding( cert->cert, "",
cert_buf, &cert_buf_size, NULL);
if (result != ASN1_SUCCESS) {
gnutls_assert();
+ gnutls_afree( cert_buf);
return _gnutls_asn2err(result);
}
tmp.data = cert_buf;
tmp.size = cert_buf_size;
- return gnutls_fingerprint( algo, &tmp, buf, sizeof_buf);
+ result = gnutls_fingerprint( algo, &tmp, buf, sizeof_buf);
+ gnutls_afree( cert_buf);
+
+ return result;
}
int result;
if (format == GNUTLS_X509_FMT_DER) {
+ if (output_data == NULL) *output_data_size = 0;
+
if ((result=asn1_der_coding( asn1_data, "", output_data, output_data_size, NULL)) != ASN1_SUCCESS) {
gnutls_assert();