to gnutls_dh_(set/get)_bits()
- gnutls_anon_set_server_cred() was deprecated by gnutls_dh_set_bits()
- gnutls_x509pki_set_trust_(file/mem) can now be called multiple times
+- Added a minimal string library to assist in ASN.1 parsing
Version 0.3.5
- Corrected the RSA key exchange method, to avoid attacks against
+ Audit the code
+ Add support for certificates with DSS parameters
+ OpenPGP certificate support
-* Create a local string library and use it for ASN.1 parsing
* Add function to clone GNUTLS_STATE structures
* Minimize footprint.
* Improve support for compression
gnutls_privkey.h gnutls_constate.h gnutls_global.h x509_verify.h \
gnutls_sig.h gnutls_mem.h x509_extensions.h gnutls_ui.h \
gnutls-api.tex io_debug.h ext_max_record.h gnutls_session_pack.h \
- gnutls_alert.h asn1-api.tex
+ gnutls_alert.h asn1-api.tex gnutls_str.h
lib_LTLIBRARIES = libgnutls.la
gnutls_global.c gnutls_privkey.c gnutls_constate.c gnutls_anon_cred.c \
x509_sig_check.c pkix_asn1_tab.c pkcs1_asn1_tab.c gnutls_mem.c \
x509_extensions.c auth_x509.c gnutls_ui.c gnutls_sig.c auth_dhe_rsa.c \
- gnutls_dh_primes.c ext_max_record.c gnutls_alert.c gnutls_int_compat.c
+ gnutls_dh_primes.c ext_max_record.c gnutls_alert.c gnutls_int_compat.c \
+ gnutls_str.c
# Separate so we can create the documentation
COBJECTS2 = x509_ASN.y x509_asn1.c x509_der.c
#include "debug.h"
#include "gnutls_num.h"
#include "auth_srp.h"
+#include <gnutls_str.h>
int gen_srp_server_kx2(GNUTLS_STATE, opaque **);
int gen_srp_client_kx0(GNUTLS_STATE, opaque **);
info = _gnutls_get_auth_info( state);
username = info->username;
- strncpy( username, state->security_parameters.extensions.srp_username, MAX_SRP_USERNAME);
- username[ MAX_SRP_USERNAME - 1] = 0;
+ _gnutls_str_cpy( username, MAX_SRP_USERNAME, state->security_parameters.extensions.srp_username);
pwd_entry = _gnutls_srp_pwd_read_entry( state->gnutls_key, username, &err);
#include "gnutls_random.h"
#include "gnutls_dh.h"
#include "debug.h"
+#include <gnutls_str.h>
/* this function parses tpasswd.conf file. Format is:
* string(username):base64(v):base64(salt):int(index)
_gnutls_srp_clear_pwd_entry( pwd_entry);
return NULL;
}
- strcpy( pwd_entry->username, RNDUSER); /* Flawfinder: ignore */
+ _gnutls_str_cpy( pwd_entry->username, MAX_SRP_USERNAME, RNDUSER); /* Flawfinder: ignore */
pwd_entry->v = _gnutls_mpi_new(160);
if (pwd_entry->v==NULL) {
int vsize, hash_len = gnutls_hash_get_algo_len(GNUTLS_MAC_SHA);
opaque *tmp;
uint8 *rtext, *csalt;
- int rsalt_size, len;
+ int rsalt_size, len, tmpsize;
passwd_len = strlen(passwd); /* we do not want the null */
#include <x509_extensions.h>
#include <gnutls_algorithms.h>
#include <gnutls_dh.h>
+#include <gnutls_str.h>
#ifdef DEBUG
# warning MAX ALGORITHM PARAMS == 2, ok for RSA
}
#define _READ(a, aa, b, c, d, e, res, f) \
- result = _IREAD(a, aa, b, c, d, e, res, sizeof(res)-1, f); \
+ result = _IREAD(a, aa, sizeof(aa), b, c, d, e, res, sizeof(res)-1, f); \
if (result<0) return result; \
if (result==1) continue
-int _IREAD(node_asn * rasn, char *name3, char *rstr, char *OID,
+int _IREAD(node_asn * rasn, char *name3, int name3_size, char *rstr, char *OID,
char *ANAME, char *TYPE, char *res, int res_size, int CHOICE)
{
char name2[256];
if (strcmp(rstr, OID) == 0) {
- strcpy(str, "PKIX1Implicit88."); /* Flawfinder: ignore */
- strcat(str, ANAME); /* Flawfinder: ignore */
- strcpy(name2, "temp-structure-"); /* Flawfinder: ignore */
- strcat(name2, TYPE);
+ _gnutls_str_cpy(str, sizeof(str), "PKIX1Implicit88.");
+ _gnutls_str_cat(str, sizeof(str), ANAME);
+ _gnutls_str_cpy(name2, sizeof(name2), "temp-structure-");
+ _gnutls_str_cat(name2, sizeof(name2), TYPE);
if ((result =
asn1_create_structure(_gnutls_get_pkix(), str,
return GNUTLS_E_ASN1_ERROR;
}
- len = sizeof(str) - 1;
+ len = sizeof(str) -1;
if ((result =
asn1_read_value(rasn, name3, str, &len)) != ASN_OK) {
asn1_delete_structure(tmpasn);
asn1_delete_structure(tmpasn);
return 1;
}
- strcpy(name3, name2); /* Flawfinder: ignore */
+ _gnutls_str_cpy(name3, name3_size, name2);
len = sizeof(str) - 1;
if ((result = asn1_read_value(tmpasn, name3, str, &len)) != ASN_OK) { /* CHOICE */
if (CHOICE == 0) {
str[len] = 0;
/* strlen(str) < res_size, checked above */
- strcpy(res, str); /* Flawfinder: ignore */
+ _gnutls_str_cpy(res, res_size, str);
} else { /* CHOICE */
str[len] = 0;
- strcat(name3, "."); /* Flawfinder: ignore */
- strcat(name3, str);
+ _gnutls_str_cat(name3, name3_size, ".");
+ _gnutls_str_cat(name3, name3_size, str);
len = sizeof(str) - 1;
if ((result =
}
str[len] = 0;
if ( len < res_size)
- strcpy(res, str); /* Flawfinder: ignore */
+ _gnutls_str_cpy(res, res_size, str);
}
asn1_delete_structure(tmpasn);
if (k > 999)
data[0] = 0;
else
- sprintf(data, "%d", k); /* Flawfinder: ignore */
+ sprintf(data, "%d", k);
}
/* This function will attempt to read a Name
do {
k++;
- strcpy(name, root); /* Flawfinder: ignore */
- strcat(name, ".rdnSequence.?"); /* Flawfinder: ignore */
+ _gnutls_str_cpy(name, sizeof(name), root);
+ _gnutls_str_cat(name, sizeof(name), ".rdnSequence.?");
_gnutls_int2str(k, counter);
- strcat(name, counter); /* Flawfinder: ignore */
+ _gnutls_str_cat(name, sizeof(name), counter);
len = sizeof(str) - 1;
do {
k2++;
- strcpy(name2, name); /* Flawfinder: ignore */
- strcat(name2, ".?"); /* Flawfinder: ignore */
+ _gnutls_str_cpy(name2, sizeof(name2), name);
+ _gnutls_str_cat(name2, sizeof(name2), ".?");
_gnutls_int2str(k2, counter);
- strcat(name2, counter); /* Flawfinder: ignore */
+ _gnutls_str_cat(name2, sizeof(name2), counter);
len = sizeof(str) - 1;
result = asn1_read_value(rasn, name2, str, &len);
return GNUTLS_E_ASN1_PARSING_ERROR;
}
- strcpy(name3, name2);
- strcat(name3, ".type"); /* Flawfinder: ignore */
+ _gnutls_str_cpy(name3, sizeof(name3), name2);
+ _gnutls_str_cat(name3, sizeof(name3), ".type");
len = sizeof(str) - 1;
result = asn1_read_value(rasn, name3, str, &len);
return GNUTLS_E_ASN1_PARSING_ERROR;
}
- strcpy(name3, name2);
- strcat(name3, ".value"); /* Flawfinder: ignore */
+ _gnutls_str_cpy(name3, sizeof(name3), name2);
+ _gnutls_str_cat(name3, sizeof(name3), ".value");
if (result == ASN_OK) {
#ifdef DEBUG
time_t ctime;
int len, result;
- strcpy(name, root);
- strcat(name, ".tbsCertificate.validity."); /* Flawfinder: ignore */
- strcat(name, when);
+ _gnutls_str_cpy(name, sizeof(name), root);
+ _gnutls_str_cat(name, sizeof(name), ".tbsCertificate.validity.");
+ _gnutls_str_cat(name, sizeof(name), when);
len = sizeof(ttime) - 1;
if ((result = asn1_read_value(c2, name, ttime, &len)) < 0) {
}
/* CHOICE */
- strcpy(name, root);
+ _gnutls_str_cpy(name, sizeof(name), root);
if (strcmp(ttime, "GeneralizedTime") == 0) {
- strcat(name, ".tbsCertificate.validity."); /* Flawfinder: ignore */
- strcat(name, when);
- strcat(name, ".generalTime"); /* Flawfinder: ignore */
+ _gnutls_str_cat(name, sizeof(name), ".tbsCertificate.validity.");
+ _gnutls_str_cat(name, sizeof(name), when);
+ _gnutls_str_cat(name, sizeof(name), ".generalTime");
len = sizeof(ttime) - 1;
result = asn1_read_value(c2, name, ttime, &len);
if (result == ASN_OK)
ctime = _gnutls_generalTime2gtime(ttime);
} else { /* UTCTIME */
- strcat(name, ".tbsCertificate.validity."); /* Flawfinder: ignore */
- strcat(name, when);
- strcat(name, ".utcTime"); /* Flawfinder: ignore */
+ _gnutls_str_cat(name, sizeof(name), ".tbsCertificate.validity.");
+ _gnutls_str_cat(name, sizeof(name), when);
+ _gnutls_str_cat(name, sizeof(name), ".utcTime");
len = sizeof(ttime) - 1;
result = asn1_read_value(c2, name, ttime, &len);
if (result == ASN_OK)
char name[1024];
int len, result;
- strcpy(name, root);
- strcat(name, ".tbsCertificate.version"); /* Flawfinder: ignore */
+ _gnutls_str_cpy(name, sizeof(name), root);
+ _gnutls_str_cat(name, sizeof(name), ".tbsCertificate.version");
len = sizeof(gversion) - 1;
if ((result = asn1_read_value(c2, name, gversion, &len)) < 0) {
--- /dev/null
+/*
+ * Copyright (C) 2002 Nikos Mavroyanopoulos
+ *
+ * This file is part of GNUTLS.
+ *
+ * GNUTLS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GNUTLS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include <gnutls_int.h>
+#include <gnutls_errors.h>
+#include <gnutls_num.h>
+
+/* These function are like strcat, strcpy. They only
+ * do bound checking (they shouldn't cause buffer overruns),
+ * and they always produce null terminated strings.
+ */
+void _gnutls_str_cat( char* dest, size_t dest_tot_size, const char* src) {
+size_t str_size = strlen(src);
+size_t dest_size = strlen(dest);
+
+ if ( dest_tot_size - dest_size > str_size) {
+ strcat( dest, src);
+ } else {
+ if ( dest_tot_size - dest_size > 0) {
+ strncat( dest, src, (dest_tot_size - dest_size) -1);
+ dest[dest_tot_size-1] = 0;
+ }
+ }
+}
+
+void _gnutls_str_cpy( char* dest, size_t dest_tot_size, const char* src) {
+size_t str_size = strlen(src);
+
+ if ( dest_tot_size > str_size) {
+ strcpy( dest, src);
+ } else {
+ if ( dest_tot_size > 0) {
+ strncpy( dest, src, (dest_tot_size) -1);
+ dest[dest_tot_size-1] = 0;
+ }
+ }
+}
+
--- /dev/null
+void _gnutls_str_cpy( char* dest, size_t dest_tot_size, const char* src);
+void _gnutls_str_cat( char* dest, size_t dest_tot_size, const char* src);
#include <gnutls_errors.h>
#include <gnutls_global.h>
#include "debug.h"
+#include <gnutls_str.h>
/* Here we only extract the KeyUsage field
do {
k++;
- strcpy(name, root);
- strcat(name, ".?"); /* Flawfinder: ignore */
+ _gnutls_str_cpy(name, sizeof(name), root);
+ _gnutls_str_cat(name, sizeof(name), ".?");
_gnutls_int2str(k, counter);
- strcat(name, counter); /* Flawfinder: ignore */
+ _gnutls_str_cat(name, sizeof(name), counter);
len = sizeof(str) - 1;
result = asn1_read_value(rasn, name, str, &len);
do {
- strcpy(name2, name);
- strcat(name2, ".extnID"); /* Flawfinder: ignore */
+ _gnutls_str_cpy(name2, sizeof(name2), name);
+ _gnutls_str_cat(name2, sizeof(name2), ".extnID");
len = sizeof(extnID) - 1;
result =
return GNUTLS_E_ASN1_PARSING_ERROR;
}
- strcpy(name2, name);
- strcat(name2, ".critical"); /* Flawfinder: ignore */
+ _gnutls_str_cpy(name2, sizeof(name2), name);
+ _gnutls_str_cat(name2, sizeof(name2), ".critical");
len = sizeof(critical) - 1;
result =
return GNUTLS_E_ASN1_PARSING_ERROR;
}
- strcpy(name2, name);
- strcat(name2, ".extnValue"); /* Flawfinder: ignore */
+ _gnutls_str_cpy(name2, sizeof(name2), name);
+ _gnutls_str_cat(name2, sizeof(name2), ".extnValue");
len = sizeof(extnValue) - 1;
result =
do {
k++;
- strcpy(name, "certificate2"); /* Flawfinder: ignore */
- strcat(name, ".?"); /* Flawfinder: ignore */
+ _gnutls_str_cpy(name, sizeof(name), "certificate2");
+ _gnutls_str_cat(name, sizeof(name), ".?");
_gnutls_int2str(k, counter);
- strcat(name, counter); /* Flawfinder: ignore */
+ _gnutls_str_cat(name, sizeof(name), counter);
len = sizeof(str) - 1;
result = asn1_read_value(rasn, name, str, &len);
do {
- strcpy(name2, name);
- strcat(name2, ".extnID"); /* Flawfinder: ignore */
+ _gnutls_str_cpy(name2, sizeof(name2), name);
+ _gnutls_str_cat(name2, sizeof(name2), ".extnID");
len = sizeof(extnID) - 1;
result =
return GNUTLS_E_ASN1_PARSING_ERROR;
}
- strcpy(name2, name);
- strcat(name2, ".critical"); /* Flawfinder: ignore */
+ _gnutls_str_cpy(name2, sizeof(name2), name);
+ _gnutls_str_cat(name2, sizeof(name2), ".critical");
len = sizeof(critical) - 1;
result =
return GNUTLS_E_ASN1_PARSING_ERROR;
}
- strcpy(name2, name);
- strcat(name2, ".extnValue"); /* Flawfinder: ignore */
+ _gnutls_str_cpy(name2, sizeof(name2), name);
+ _gnutls_str_cat(name2, sizeof(name2), ".extnValue");
len = sizeof(extnValue) - 1;
result =
#include <gnutls_global.h>
#include <gnutls_pk.h>
#include <debug.h>
+#include <gnutls_str.h>
static gnutls_datum _gnutls_get_tbs( gnutls_cert* cert) {
node_asn *c2;
gnutls_datum der;
if (hash_algo==GNUTLS_MAC_MD5)
- strcpy(OID, "1 2 840 113549 2 5"); /* Flawfinder: ignore */
+ _gnutls_str_cpy(OID, sizeof(OID), "1 2 840 113549 2 5");
else if (hash_algo==GNUTLS_MAC_SHA)
- strcpy(OID, "1 3 14 3 2 26"); /* Flawfinder: ignore */
+ _gnutls_str_cpy(OID, sizeof(OID), "1 3 14 3 2 26");
else {
gnutls_assert();
return GNUTLS_E_UNKNOWN_MAC_ALGORITHM;
#include "gnutls_global.h"
#include "gnutls_num.h" /* GMAX */
#include <gnutls_sig.h>
+#include <gnutls_str.h>
/* TIME functions */
}
- strcpy( tmpstr, "certificate2.tbsCertificate.issuer"); /* Flawfinder: ignore */
+ _gnutls_str_cpy( tmpstr, sizeof(tmpstr), "certificate2.tbsCertificate.issuer");
result = asn1_get_start_end_der( c2, cert->raw.data, cert->raw.size,
tmpstr, &start1, &end1);
asn1_delete_structure( c2);
len1 = end1 - start1 + 1;
- strcpy( tmpstr, "certificate2.tbsCertificate.subject"); /* Flawfinder: ignore */
+ _gnutls_str_cpy( tmpstr, sizeof(tmpstr), "certificate2.tbsCertificate.subject");
result = asn1_get_start_end_der( c3, issuer_cert->raw.data, issuer_cert->raw.size,
tmpstr, &start2, &end2);
asn1_delete_structure( c3);