Created SILC GIT repository.
[silc.git] / apps / irssi / src / silc / core / silc-queries.c
index 8ef5517250a8041fa8131a555dbea79e2c220ac9..18590f767e5d15defcb07a8726b9157fc07e7bf4 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2002 - 2006 Pekka Riikonen
+  Copyright (C) 2002 - 2008 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -292,7 +292,7 @@ void silc_query_attributes_default(SilcClient client,
     /* Put USER_INFO */
     silc_client_attribute_del(silc_client, conn,
                              SILC_ATTRIBUTE_USER_INFO, NULL);
-    tmp = silc_file_readfile(sv, &tmp_len);
+    tmp = silc_file_readfile(sv, &tmp_len, NULL);
     if (tmp) {
       tmp[tmp_len] = 0;
       if (silc_vcard_decode(tmp, tmp_len, &vcard))
@@ -364,7 +364,8 @@ void silc_query_attributes_default(SilcClient client,
        mask |= SILC_ATTRIBUTE_MOOD_ANXIOUS;
     }
     silc_client_attribute_add(silc_client, conn,
-                             SILC_ATTRIBUTE_STATUS_MOOD, (void *)mask,
+                             SILC_ATTRIBUTE_STATUS_MOOD,
+                             SILC_32_TO_PTR(mask),
                              sizeof(SilcUInt32));
     g_strfreev(list);
   }
@@ -384,7 +385,7 @@ void silc_query_attributes_default(SilcClient client,
     /* Put STATUS_MESSAGE */
     silc_client_attribute_del(silc_client, conn,
                              SILC_ATTRIBUTE_STATUS_MESSAGE, NULL);
-    tmp = silc_file_readfile(sv, &tmp_len);
+    tmp = silc_file_readfile(sv, &tmp_len, NULL);
     if (tmp) {
       mime = silc_mime_decode(NULL, tmp, tmp_len);
       if (mime)
@@ -435,7 +436,8 @@ void silc_query_attributes_default(SilcClient client,
        mask |= SILC_ATTRIBUTE_CONTACT_VIDEO;
     }
     silc_client_attribute_add(silc_client, conn,
-                             SILC_ATTRIBUTE_PREFERRED_CONTACT, (void *)mask,
+                             SILC_ATTRIBUTE_PREFERRED_CONTACT,
+                             SILC_32_TO_PTR(mask),
                              sizeof(SilcUInt32));
     g_strfreev(list);
   }
@@ -529,7 +531,7 @@ void silc_query_attributes_default(SilcClient client,
     list = g_strsplit(sv, " ", -1);
     for (entry = list; *entry != NULL; entry++) {
       if (!strncasecmp(*entry, "silc-rsa:", 8)) {
-       tmp = silc_file_readfile((*entry) + 8, &tmp_len);
+       tmp = silc_file_readfile((*entry) + 8, &tmp_len, NULL);
        if (tmp) {
          tmp[tmp_len] = 0;
          pk.type = "silc-rsa";
@@ -560,6 +562,11 @@ typedef struct {
   bool nopk;
 } *AttrVerify;
 
+static void silc_query_attributes_verify(SilcBool success, void *context)
+{
+  *(SilcBool *)context = success;
+}
+
 void silc_query_attributes_print(SILC_SERVER_REC *server,
                                 SilcClient client,
                                 SilcClientConnection conn,
@@ -821,12 +828,8 @@ void silc_query_attributes_print(SILC_SERVER_REC *server,
 
   /* Handle the signature verifications and public key verifying here */
 
-  if (usersign.data) {
-    /* Verify the signature now */
-    SilcPublicKey public_key;
+  if (verify->userpk.data) {
     SilcPKCSType type = 0;
-    unsigned char *verifyd;
-    SilcUInt32 verify_len;
 
     if (!strcmp(verify->userpk.type, "silc-rsa"))
       type = SILC_PKCS_SILC;
@@ -837,15 +840,26 @@ void silc_query_attributes_print(SILC_SERVER_REC *server,
     else if (!strcmp(verify->userpk.type, "pgp-sign-rsa"))
       type = SILC_PKCS_OPENPGP;
 
-    if (silc_pkcs_public_key_alloc(type, verify->userpk.data,
-                                  verify->userpk.data_len,
-                                  &verify->public_key)) {
+    silc_pkcs_public_key_alloc(type, verify->userpk.data,
+                              verify->userpk.data_len,
+                              &verify->public_key);
+  }
+
+  if (usersign.data) {
+    /* Verify the signature now */
+    unsigned char *verifyd;
+    SilcUInt32 verify_len;
+    SilcBool verified = FALSE;
+
+    if (verify->public_key) {
       verifyd = silc_attribute_get_verify_data(attrs, FALSE, &verify_len);
-      if (verifyd && silc_pkcs_verify(verify->public_key,
-                                     usersign.data,
-                                     usersign.data_len,
-                                     verifyd, verify_len,
-                                     sha1hash)) {
+      if (verifyd)
+       silc_pkcs_verify_async(verify->public_key, usersign.data,
+                              usersign.data_len, verifyd, verify_len,
+                              TRUE, sha1hash,
+                              silc_query_attributes_verify, &verified);
+
+      if (verified) {
        printformat_module("fe-common/silc", server, NULL,
                           MSGLEVEL_CRAP, SILCTXT_ATTR_USER_SIGN_VERIFIED);
       } else {
@@ -869,25 +883,27 @@ void silc_query_attributes_print(SILC_SERVER_REC *server,
     SilcPKCSType type = 0;
     unsigned char *verifyd;
     SilcUInt32 verify_len;
+    SilcBool verified = FALSE;
 
-    if (!strcmp(verify->userpk.type, "silc-rsa"))
+    if (!strcmp(serverpk.type, "silc-rsa"))
       type = SILC_PKCS_SILC;
-    else if (!strcmp(verify->userpk.type, "ssh-rsa"))
+    else if (!strcmp(serverpk.type, "ssh-rsa"))
       type = SILC_PKCS_SSH2;
-    else if (!strcmp(verify->userpk.type, "x509v3-sign-rsa"))
+    else if (!strcmp(serverpk.type, "x509v3-sign-rsa"))
       type = SILC_PKCS_X509V3;
-    else if (!strcmp(verify->userpk.type, "pgp-sign-rsa"))
+    else if (!strcmp(serverpk.type, "pgp-sign-rsa"))
       type = SILC_PKCS_OPENPGP;
 
     if (silc_pkcs_public_key_alloc(type, serverpk.data,
                                   serverpk.data_len,
                                   &public_key)) {
       verifyd = silc_attribute_get_verify_data(attrs, TRUE, &verify_len);
-      if (verifyd && silc_pkcs_verify(public_key,
-                                     serversign.data,
-                                     serversign.data_len,
-                                     verifyd, verify_len,
-                                     sha1hash)) {
+      if (verifyd)
+       silc_pkcs_verify_async(public_key, serversign.data,
+                              serversign.data_len, verifyd,
+                              verify_len, TRUE, sha1hash,
+                              silc_query_attributes_verify, &verified);
+      if (verified) {
        printformat_module("fe-common/silc", server, NULL,
                           MSGLEVEL_CRAP, SILCTXT_ATTR_SERVER_SIGN_VERIFIED);
       } else {
@@ -916,7 +932,6 @@ void silc_query_attributes_print(SILC_SERVER_REC *server,
 static void silc_query_attributes_print_final(bool success, void *context)
 {
   AttrVerify verify = context;
-  SilcClient client = verify->client;
   SILC_SERVER_REC *server = verify->server;
   char *format = NULL;
   unsigned char filename[256], *fingerprint = NULL, *tmp;
@@ -969,7 +984,6 @@ static void silc_query_attributes_print_final(bool success, void *context)
 static void silc_query_attributes_accept(const char *line, void *context)
 {
   AttrVerify verify = context;
-  SilcClient client = verify->client;
   SILC_SERVER_REC *server = verify->server;
   struct stat st;
   struct passwd *pw;
@@ -1031,11 +1045,13 @@ static void silc_query_attributes_accept(const char *line, void *context)
     }
 
     /* Save public key */
-    memset(filename2, 0, sizeof(filename2));
-    snprintf(filename2, sizeof(filename2) - 1, "%s/clientkey_%s.pub",
-            filename, fingerprint);
-    silc_pkcs_save_public_key(filename2, verify->public_key,
-                             SILC_PKCS_FILE_BASE64);
+    if (verify->public_key) {
+      memset(filename2, 0, sizeof(filename2));
+      snprintf(filename2, sizeof(filename2) - 1, "%s/clientkey_%s.pub",
+              filename, fingerprint);
+      silc_pkcs_save_public_key(filename2, verify->public_key,
+                               SILC_PKCS_FILE_BASE64);
+    }
 
     /* Save extension data */
     if (verify->extension) {