void silc_pkcs_free(SilcPKCS pkcs)
{
- if (pkcs)
+ if (pkcs) {
+ pkcs->pkcs->clear_keys(pkcs->context);
silc_free(pkcs->context);
+ }
silc_free(pkcs);
}
memcpy(list + len, ",", 1);
len++;
}
+ list[len - 1] = 0;
}
- list[len - 1] = 0;
-
return list;
}
/* Returns the length of the key */
-uint32 silc_pkcs_get_key_len(SilcPKCS self)
+uint32 silc_pkcs_get_key_len(SilcPKCS pkcs)
{
- return self->key_len;
+ return pkcs->key_len;
}
/* Returns SILC style public key */
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);
return FALSE;
}
+/* Compares two public keys and returns TRUE if they are same key, and
+ FALSE if they are not same. */
+
+bool silc_pkcs_public_key_compare(SilcPublicKey key1, SilcPublicKey key2)
+{
+ if (key1 == key2)
+ return TRUE;
+
+ if (key1->len == key2->len &&
+ key1->name && key2->name && key1->identifier && key2->identifier &&
+ !strcmp(key1->name, key2->name) &&
+ !strcmp(key1->identifier, key2->identifier) &&
+ !memcmp(key1->pk, key2->pk, key1->pk_len) &&
+ key1->pk_len == key2->pk_len)
+ return TRUE;
+
+ return FALSE;
+}
+
/* Encodes SILC private key from SilcPrivateKey. Returns the encoded data. */
unsigned char *
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;
}
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;
}
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;
break;
case SILC_PKCS_FILE_PEM:
data = silc_decode_pem(data, len, &len);
+ memset(old, 0, data_len);
+ silc_free(old);
+ old = data;
+ data_len = len;
break;
}
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;