[gnutls-dev] MS-style newlines in certificate files

Nikos Mavroyanopoulos nmav@gnutls.org
Sat Aug 30 11:21:02 2003


--X1bOJ3K7DJ5YkBrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Sat, Aug 30, 2003 at 12:37:16AM +0200, Ivo Timmermans wrote:

> Hi,
> Apparently MS-DOS-style newlines (\r\n) aren't supported by gnutls'
> base-64 decoder; parsing certificate files with these newlines yield
> error -34 (Certificate parsing error).
> Is it possible to support this style of newlines?  Possibly Apple
> newlines (\r) too?
> See http://bugs.debian.org/202454 for details.

The attached patch should fix that for the ms-dos newlines. I'll have
to think something neater about the apple newlines.

> 	Ivo
> -- 
> Mein Gott, Henry!  Hinter dir!  Der Mobster von Loch Ness!
> 	- Nichtlustig

-- 
Nikos Mavroyanopoulos

--X1bOJ3K7DJ5YkBrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=diff

Index: x509_b64.c
===================================================================
RCS file: /cvs/gnutls/gnutls/lib/x509_b64.c,v
retrieving revision 2.30
retrieving revision 2.31
diff -u -r2.30 -r2.31
--- x509_b64.c	12 Aug 2003 12:00:53 -0000	2.30
+++ x509_b64.c	20 Aug 2003 22:21:32 -0000	2.31
@@ -353,12 +353,13 @@
  * The result_size is the return value
  */
 #define ENDSTR "-----\n"
+#define ENDSTR2 "-----\r\n"
 int _gnutls_fbase64_decode( const opaque* header, const opaque * data, size_t data_size,
 			   uint8 ** result)
 {
 	int ret;
-	char top[] = "-----BEGIN ";
-	char bottom[] = "\n-----END ";
+	const char top[] = "-----BEGIN ";
+	const char bottom[] = "\n-----END ";
 	uint8 *rdata;
 	int rdata_size;
 	uint8 *kdata;
@@ -385,6 +386,10 @@
 	}
 
 	kdata = strnstr( rdata, ENDSTR, data_size);
+	/* allow CR as well.
+	 */
+	if (kdata==NULL) kdata = strnstr( rdata, ENDSTR2, data_size);
+
 	if (kdata==NULL) {
 		gnutls_assert();
 		_gnutls_x509_log( "Could not find '%s'\n", ENDSTR);

--X1bOJ3K7DJ5YkBrT--