updates.
[silc.git] / lib / silcclient / client_channel.c
index 81c9ca9a5b2f33030fb97f2dcba444f1eafb4291..46190226fecaf19b85cfc65f843ff38211afe9dd 100644 (file)
@@ -59,24 +59,30 @@ void silc_client_send_channel_message(SilcClient client,
   }
 
   /* Take the key to be used */
-  if (key) {
-    /* Use key application specified */
-    cipher = key->cipher;
-    hmac = key->hmac;
-  } else if (channel->curr_key) {
-    /* Use current private key */
-    cipher = channel->curr_key->cipher;
-    hmac = channel->curr_key->hmac;
-  } else if (!channel->curr_key && channel->private_keys) {
-    /* Use just some private key since we don't know what to use 
-       and private keys are set. */
-    silc_dlist_start(channel->private_keys);
-    key = silc_dlist_get(channel->private_keys);
-    cipher = key->cipher;
-    hmac = key->hmac;
-
-    /* Use this key as current private key */
-    channel->curr_key = key;
+  if (channel->mode & SILC_CHANNEL_MODE_PRIVKEY) {
+    if (key) {
+      /* Use key application specified */
+      cipher = key->cipher;
+      hmac = key->hmac;
+    } else if (channel->curr_key) {
+      /* Use current private key */
+      cipher = channel->curr_key->cipher;
+      hmac = channel->curr_key->hmac;
+    } else if (!channel->curr_key && channel->private_keys) {
+      /* Use just some private key since we don't know what to use 
+        and private keys are set. */
+      silc_dlist_start(channel->private_keys);
+      key = silc_dlist_get(channel->private_keys);
+      cipher = key->cipher;
+      hmac = key->hmac;
+      
+      /* Use this key as current private key */
+      channel->curr_key = key;
+    } else {
+      /* Use normal channel key generated by the server */
+      cipher = channel->channel_key;
+      hmac = channel->hmac;
+    }
   } else {
     /* Use normal channel key generated by the server */
     cipher = channel->channel_key;
@@ -192,13 +198,13 @@ void silc_client_channel_message(SilcClient client,
   /* If there is no channel private key then just decrypt the message 
      with the channel key. If private keys are set then just go through
      all private keys and check what decrypts correctly. */
-  if (!channel->private_keys) {
+  if (!(channel->mode & SILC_CHANNEL_MODE_PRIVKEY)) {
     /* Parse the channel message payload. This also decrypts the payload */
     payload = silc_channel_payload_parse(buffer, channel->channel_key,
                                         channel->hmac);
     if (!payload)
       goto out;
-  } else {
+  } else if (channel->private_keys) {
     SilcChannelPrivateKey entry;
 
     silc_dlist_start(channel->private_keys);
@@ -211,6 +217,8 @@ void silc_client_channel_message(SilcClient client,
     }
     if (entry == SILC_LIST_END)
       goto out;
+  } else {
+    goto out;
   }
 
   message = silc_channel_get_data(payload, NULL);