updates.
[silc.git] / lib / silccrypt / silcpkcs.c
index 146b3082ef25a95c82ddec9df617cee4a5dfb7a3..fe0e1c659fad862933b3c379da19cea0fa58121d 100644 (file)
@@ -194,10 +194,9 @@ char *silc_pkcs_get_supported(void)
       memcpy(list + len, ",", 1);
       len++;
     }
+    list[len - 1] = 0;
   }
 
-  list[len - 1] = 0;
-
   return list;
 }
 
@@ -445,27 +444,36 @@ SilcPublicKeyIdentifier silc_pkcs_decode_identifier(char *identifier)
   cp = identifier;
   while (cp) {
     len = strcspn(cp, ",");
+    if (len - 1 >= 0 && cp[len - 1] == '\\') {
+      while (cp) {
+       cp += len + 1;
+       len = strcspn(cp, ",") + len;
+       if (len - 1 >= 0 && cp[len - 1] != '\\')
+         break;
+      }
+    }
+
     item = silc_calloc(len + 1, sizeof(char));
     memcpy(item, cp, len);
 
     if (strstr(item, "UN="))
-      ident->username = strdup(item + 3);
+      ident->username = strdup(item + strcspn(cp, "=") + 1);
     else if (strstr(item, "HN="))
-      ident->host = strdup(item + 3);
+      ident->host = strdup(item + strcspn(cp, "=") + 1);
     else if (strstr(item, "RN="))
-      ident->realname = strdup(item + 3);
+      ident->realname = strdup(item + strcspn(cp, "=") + 1);
     else if (strstr(item, "E="))
-      ident->email = strdup(item + 2);
+      ident->email = strdup(item + strcspn(cp, "=") + 1);
     else if (strstr(item, "O="))
-      ident->org = strdup(item + 2);
+      ident->org = strdup(item + strcspn(cp, "=") + 1);
     else if (strstr(item, "C="))
-      ident->country = strdup(item + 2);
+      ident->country = strdup(item + strcspn(cp, "=") + 1);
     
     cp += len;
     if (strlen(cp) == 0)
       cp = NULL;
     else
-      cp += 2;
+      cp += 1;
     
     if (item)
       silc_free(item);
@@ -874,7 +882,7 @@ static int silc_pkcs_save_public_key_internal(char *filename,
                     SILC_STR_END);
 
   /* Save into file */
-  if (silc_file_write(filename, buf->data, buf->len)) {
+  if (silc_file_writefile(filename, buf->data, buf->len)) {
     silc_buffer_free(buf);
     return FALSE;
   }
@@ -937,7 +945,7 @@ static int silc_pkcs_save_private_key_internal(char *filename,
                     SILC_STR_END);
 
   /* Save into a file */
-  if (silc_file_write_mode(filename, buf->data, buf->len, 0600)) {
+  if (silc_file_writefile_mode(filename, buf->data, buf->len, 0600)) {
     silc_buffer_free(buf);
     return FALSE;
   }
@@ -982,7 +990,7 @@ int silc_pkcs_load_public_key(char *filename, SilcPublicKey *public_key,
   unsigned char *cp, *old, *data, byte;
   uint32 i, data_len, len;
 
-  old = data = silc_file_read(filename, &data_len);
+  old = data = silc_file_readfile(filename, &data_len);
   if (!data)
     return FALSE;
 
@@ -1035,7 +1043,7 @@ int silc_pkcs_load_private_key(char *filename, SilcPrivateKey *private_key,
   unsigned char *cp, *old, *data, byte;
   uint32 i, data_len, len;
 
-  old = data = silc_file_read(filename, &data_len);
+  old = data = silc_file_readfile(filename, &data_len);
   if (!data)
     return FALSE;