From: Pekka Riikonen Date: Mon, 22 Apr 2002 12:21:29 +0000 (+0000) Subject: updates X-Git-Tag: 1.2.beta1~1395 X-Git-Url: http://git.silcnet.org/gitweb/?p=crypto.git;a=commitdiff_plain;h=103b560c55e218ad043094bdcb29e709158c3b5b updates --- diff --git a/CHANGES b/CHANGES index 631a8f1b..ea45ac93 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,10 @@ Mon Apr 22 09:09:44 CEST 2002 Pekka Riikonen are lib/silccore/silcmode.h, lib/silcclient/command.c and silcd/command.c. + * SILC Publickey fields MUST be UTF-8 encoded now. Updated + the protocol specs and the code. Affected file is + lib/silccrypt/silcpkcs.c. + Sun Apr 21 19:44:38 EEST 2002 Pekka Riikonen * Disconnect Payload includes now the status type. Updated diff --git a/doc/draft-riikonen-silc-spec-05.nroff b/doc/draft-riikonen-silc-spec-05.nroff index 72fa8aee..4c284f12 100644 --- a/doc/draft-riikonen-silc-spec-05.nroff +++ b/doc/draft-riikonen-silc-spec-05.nroff @@ -1409,7 +1409,7 @@ o Public Data (variable length) - Includes the actual .in 3 All fields in the public key are in MSB (most significant byte first) -order. +order. All strings in the public key are UTF-8 encoded. .ti 0 diff --git a/lib/silccrypt/silcpkcs.c b/lib/silccrypt/silcpkcs.c index db3a8e25..8d409e35 100644 --- a/lib/silccrypt/silcpkcs.c +++ b/lib/silccrypt/silcpkcs.c @@ -406,16 +406,17 @@ char *silc_pkcs_encode_identifier(char *username, char *host, char *realname, SilcBuffer buf; char *identifier; SilcUInt32 len, tlen = 0; + char utf8[256 + 1]; if (!username || !host) return NULL; - len = (username ? strlen(username) : 0) + - (host ? strlen(host) : 0) + - (realname ? strlen(realname) : 0) + - (email ? strlen(email) : 0) + - (org ? strlen(org) : 0) + - (country ? strlen(country) : 0); + len = (username ? silc_utf8_encoded_len(username, strlen(username), 0) : 0) + + (host ? silc_utf8_encoded_len(host, strlen(host), 0) : 0) + + (realname ? silc_utf8_encoded_len(realname, strlen(realname), 0) : 0) + + (email ? silc_utf8_encoded_len(email, strlen(email), 0) : 0) + + (org ? silc_utf8_encoded_len(org, strlen(org), 0) : 0) + + (country ? silc_utf8_encoded_len(country, strlen(country), 0) : 0); if (len < 3) return NULL; @@ -425,62 +426,77 @@ char *silc_pkcs_encode_identifier(char *username, char *host, char *realname, silc_buffer_pull_tail(buf, len); if (username) { + memset(utf8, 0, sizeof(utf8)); + len = silc_utf8_encode(username, strlen(username), 0, utf8, + sizeof(utf8) - 1); silc_buffer_format(buf, SILC_STR_UI32_STRING("UN="), - SILC_STR_UI32_STRING(username), + SILC_STR_UI32_STRING(utf8), SILC_STR_END); - silc_buffer_pull(buf, 3 + strlen(username)); - tlen = 3 + strlen(username); + silc_buffer_pull(buf, 3 + len); + tlen = 3 + len; } if (host) { + memset(utf8, 0, sizeof(utf8)); + len = silc_utf8_encode(host, strlen(host), 0, utf8, sizeof(utf8) - 1); silc_buffer_format(buf, SILC_STR_UI32_STRING(", "), SILC_STR_UI32_STRING("HN="), - SILC_STR_UI32_STRING(host), + SILC_STR_UI32_STRING(utf8), SILC_STR_END); - silc_buffer_pull(buf, 5 + strlen(host)); - tlen += 5 + strlen(host); + silc_buffer_pull(buf, 5 + len); + tlen += 5 + len; } if (realname) { + memset(utf8, 0, sizeof(utf8)); + len = silc_utf8_encode(realname, strlen(realname), 0, utf8, + sizeof(utf8) - 1); silc_buffer_format(buf, SILC_STR_UI32_STRING(", "), SILC_STR_UI32_STRING("RN="), - SILC_STR_UI32_STRING(realname), + SILC_STR_UI32_STRING(utf8), SILC_STR_END); - silc_buffer_pull(buf, 5 + strlen(realname)); - tlen += 5 + strlen(realname); + silc_buffer_pull(buf, 5 + len); + tlen += 5 + len; } if (email) { + memset(utf8, 0, sizeof(utf8)); + len = silc_utf8_encode(email, strlen(email), 0, utf8, sizeof(utf8) - 1); silc_buffer_format(buf, SILC_STR_UI32_STRING(", "), SILC_STR_UI32_STRING("E="), - SILC_STR_UI32_STRING(email), + SILC_STR_UI32_STRING(utf8), SILC_STR_END); - silc_buffer_pull(buf, 4 + strlen(email)); - tlen += 4 + strlen(email); + silc_buffer_pull(buf, 4 + len); + tlen += 4 + len; } if (org) { + memset(utf8, 0, sizeof(utf8)); + len = silc_utf8_encode(org, strlen(org), 0, utf8, sizeof(utf8) - 1); silc_buffer_format(buf, SILC_STR_UI32_STRING(", "), SILC_STR_UI32_STRING("O="), - SILC_STR_UI32_STRING(org), + SILC_STR_UI32_STRING(utf8), SILC_STR_END); - silc_buffer_pull(buf, 4 + strlen(org)); - tlen += 4 + strlen(org); + silc_buffer_pull(buf, 4 + len); + tlen += 4 + len; } if (country) { + memset(utf8, 0, sizeof(utf8)); + len = silc_utf8_encode(country, strlen(country), 0, utf8, + sizeof(utf8) - 1); silc_buffer_format(buf, SILC_STR_UI32_STRING(", "), SILC_STR_UI32_STRING("C="), - SILC_STR_UI32_STRING(country), + SILC_STR_UI32_STRING(utf8), SILC_STR_END); - silc_buffer_pull(buf, 4 + strlen(country)); - tlen += 4 + strlen(country); + silc_buffer_pull(buf, 4 + len); + tlen += 4 + len; } silc_buffer_push(buf, buf->data - buf->head); diff --git a/lib/silcutil/silcstrutil.c b/lib/silcutil/silcstrutil.c index ebc24691..5e6a592b 100644 --- a/lib/silcutil/silcstrutil.c +++ b/lib/silcutil/silcstrutil.c @@ -187,6 +187,11 @@ SilcUInt32 silc_utf8_encode(const unsigned char *bin, SilcUInt32 bin_len, if (!bin || !bin_len) return 0; + if (silc_utf8_valid(bin, bin_len) && bin_len <= utf8_size) { + memcpy(utf8, bin, bin_len); + return bin_len; + } + for (i = 0; i < bin_len; i++) { switch (bin_encoding) { case SILC_STRING_ASCII: