Merged from silc_1_0_branch. silc.trunk.merged.silc.1.0.branch.1
authorPekka Riikonen <priikone@silcnet.org>
Tue, 7 Jan 2003 10:25:44 +0000 (10:25 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 7 Jan 2003 10:25:44 +0000 (10:25 +0000)
158 files changed:
.cvsignore
CHANGES
INSTALL
Makefile.am.pre
TODO
apps/irssi/Makefile.am
apps/irssi/default.theme
apps/irssi/docs/help/in/action.in
apps/irssi/docs/help/in/admin.in
apps/irssi/docs/help/in/ban.in
apps/irssi/docs/help/in/cat.in
apps/irssi/docs/help/in/cd.in
apps/irssi/docs/help/in/close.in
apps/irssi/docs/help/in/cmode.in
apps/irssi/docs/help/in/cumode.in
apps/irssi/docs/help/in/dehilight.in
apps/irssi/docs/help/in/exec.in
apps/irssi/docs/help/in/getkey.in
apps/irssi/docs/help/in/info.in
apps/irssi/docs/help/in/invite.in
apps/irssi/docs/help/in/key.in
apps/irssi/docs/help/in/kick.in
apps/irssi/docs/help/in/lastlog.in
apps/irssi/docs/help/in/layout.in
apps/irssi/docs/help/in/list.in
apps/irssi/docs/help/in/load.in
apps/irssi/docs/help/in/log.in
apps/irssi/docs/help/in/motd.in
apps/irssi/docs/help/in/msg.in
apps/irssi/docs/help/in/names.in
apps/irssi/docs/help/in/part.in
apps/irssi/docs/help/in/query.in
apps/irssi/docs/help/in/quit.in
apps/irssi/docs/help/in/save.in
apps/irssi/docs/help/in/sconnect.in
apps/irssi/docs/help/in/script.in
apps/irssi/docs/help/in/server.in
apps/irssi/docs/help/in/shutdown.in
apps/irssi/docs/help/in/smsg.in [new file with mode: 0644]
apps/irssi/docs/help/in/stats.in
apps/irssi/docs/help/in/upgrade.in [deleted file]
apps/irssi/docs/help/in/users.in
apps/irssi/docs/help/in/whois.in
apps/irssi/silc.conf
apps/irssi/src/core/chat-commands.c
apps/irssi/src/core/core.c
apps/irssi/src/core/net-nonblock.c
apps/irssi/src/core/net-nonblock.h
apps/irssi/src/core/network.c
apps/irssi/src/core/servers.c
apps/irssi/src/core/session.c
apps/irssi/src/fe-common/core/fe-messages.c
apps/irssi/src/fe-common/core/fe-messages.h
apps/irssi/src/fe-common/core/themes.c
apps/irssi/src/fe-common/silc/Makefile.am
apps/irssi/src/fe-common/silc/fe-common-silc.c
apps/irssi/src/fe-common/silc/fe-messages.c [new file with mode: 0644]
apps/irssi/src/fe-common/silc/module-formats.c
apps/irssi/src/fe-common/silc/module-formats.h
apps/irssi/src/fe-text/Makefile.am
apps/irssi/src/silc/core/client_ops.c
apps/irssi/src/silc/core/client_ops.h
apps/irssi/src/silc/core/silc-commands.h
apps/irssi/src/silc/core/silc-core.c
apps/irssi/src/silc/core/silc-core.h
apps/irssi/src/silc/core/silc-nicklist.c
apps/irssi/src/silc/core/silc-servers.c
apps/silcd/command.c
apps/silcd/command_reply.c
apps/silcd/idlist.c
apps/silcd/packet_receive.c
apps/silcd/packet_send.c
apps/silcd/server.c
apps/silcd/server.h
apps/silcd/server_backup.c
apps/silcd/server_internal.h
apps/silcd/server_query.c
apps/silcd/server_util.c
apps/silcd/server_util.h
apps/silcd/serverconfig.c
apps/silcd/silcd.c
configure.in.pre
doc/Makefile.am.pre
doc/draft-riikonen-silc-flags-payloads-02.nroff [new file with mode: 0644]
doc/draft-riikonen-silc-spec-07.nroff [new file with mode: 0644]
doc/example_silcd.conf.in
doc/silc.yo
doc/silcd.conf.yo
doc/silcd.yo
includes/silcwin32.h
lib/Makefile.am.pre
lib/contrib/.cvsignore [new file with mode: 0644]
lib/silcclient/client.c
lib/silcclient/client_attrs.c
lib/silcclient/client_channel.c
lib/silcclient/client_notify.c
lib/silcclient/client_ops_example.c
lib/silcclient/client_prvmsg.c
lib/silcclient/command.c
lib/silcclient/command_reply.c
lib/silcclient/silcclient.h
lib/silccore/silcargument.c
lib/silccore/silcattrs.c
lib/silccore/silcauth.c
lib/silccore/silcchannel.c
lib/silccore/silcchannel_i.h [deleted file]
lib/silccore/silccommand.c
lib/silccore/silcidcache.c
lib/silccore/silcmessage.c
lib/silccore/silcmessage.h
lib/silccore/silcnotify.c
lib/silccore/silcpacket.c
lib/silccore/silcpacket.h
lib/silccore/tests/Makefile.am [new file with mode: 0644]
lib/silccore/tests/test_silcargument.c [new file with mode: 0644]
lib/silccrypt/Makefile.am
lib/silccrypt/md5_internal.h
lib/silccrypt/silccipher.c
lib/silccrypt/silcpkcs.c
lib/silccrypt/silcpkcs.h
lib/silccrypt/tests/Makefile.am [new file with mode: 0644]
lib/silccrypt/tests/inst_aes [deleted file]
lib/silccrypt/tests/inst_twofish [deleted file]
lib/silccrypt/tests/test_hmacmd5.c [new file with mode: 0644]
lib/silccrypt/tests/test_hmacsha1.c [new file with mode: 0644]
lib/silccrypt/tests/test_mars.c [deleted file]
lib/silccrypt/tests/test_md5.c [new file with mode: 0644]
lib/silccrypt/tests/test_sha1.c [new file with mode: 0644]
lib/silcmath/Makefile.am
lib/silcsftp/sftp_util.c
lib/silcsftp/tests/sftp_client.c
lib/silcsftp/tests/sftp_server.c
lib/silcsim/Makefile.am
lib/silcske/payload.c
lib/silcske/silcske.c
lib/silcutil/silcbuffmt.c
lib/silcutil/silcconfig.c
lib/silcutil/silcfileutil.c
lib/silcutil/silcmemory.c
lib/silcutil/silcschedule.c
lib/silcutil/silcsockconn.c
lib/silcutil/silcutil.c
lib/silcutil/silcutil.h
lib/silcutil/silcvcard.c
lib/silcutil/silcvcard.h
lib/silcutil/stacktrace.c
lib/silcutil/unix/silcunixmutex.c
lib/silcutil/unix/silcunixsockconn.c
lib/silcutil/win32/silcwin32mutex.c
lib/silcutil/win32/silcwin32sockconn.c
lib/silcutil/win32/silcwin32thread.c
lib/silcutil/win32/silcwin32util.c
libtoolfix [new file with mode: 0755]
prepare
tutorial/mybot/mybot.c
win32/libsilc/libsilc.def
win32/libsilc/libsilc.dsp
win32/silcdefs.h

index 33fa3feef67786c6b3b657fe6244545a9c7e8464..b79d574a955ab54f0583b1e0f0e24ccd9aa781fc 100644 (file)
@@ -7,6 +7,8 @@ Makefile.defines_int
 Makefile.defines_int.in
 acconfig.h
 aclocal.m4
+autom4te.cache
+autom4te-*.cache
 config.cache
 config.guess
 config.h
@@ -19,5 +21,6 @@ configure.in
 libtool
 libtool-shared
 ltconfig
+ltmain.sh
 stamp-h
 stamp-h.in
diff --git a/CHANGES b/CHANGES
index 15b5754a1a0b6e5b2a5ba452179847fc62ff473f..40e281ac905e35aadc754d78f077345796baa8cf 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,315 @@
+Thu Dec 26 14:19:29 EET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Added some sanity checks in server for correctness of the
+         server configuration.  Affected file silcd/serverconfig.c.
+
+Fri Dec 20 10:47:59 CET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Prevent endless resolving of user informations in USERS
+         command by checking the command reply status correctly.
+         Affected file lib/silcclient/command_reply.c.
+
+Tue Dec 17 10:05:00 CET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Fixed file writing on WIN32 to use O_BINARY flag.  Affected
+         file is lib/silcutil/silcfileutil.c.  A patch by Matthew
+         Aldous <Matthew@Aldous.com>.
+
+       * Added better implementation using CriticalSection of
+         SilcMutex on WIN32.  A patch by Mikko Lähteenmäki
+         <mikko.lahteenmaki@pikabaana.net>.
+
+       * Added some Winsock WIN32 compatiblity defines into
+         includes/silcwin32.h.
+
+Mon Dec 16 19:33:05 EET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Fixed double free in async host lookup code.  Affected file
+         lib/silcutil/silcsockconn.c.
+
+       * On backup router handle now the SERVER_SIGNOFF from router
+         for local connected servers too, and close the connections.
+
+         Do not process them as normally signing off servers when they
+         really signoff by sending EOF fe, but always assume that
+         router sends the SERVER_SIGNOFF.
+
+         Affected files silcd/server.c and silcd/packet_receive.c.
+
+       * Fixed socket unsetting when closing connections.  Affected
+         files silcd/server.c and silcd/packet_send.c.
+
+       * Do not print the nickname in SERVER_SIGNOFF if we do not
+         have it.  Prevents asserts in Irssi core.  It is possible we
+         don't have the nick if it was just being resolved when server
+         signoff.  Affected file irssi/src/silc/core/client_ops.c.
+
+Thu Dec 12 23:22:50 EET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Fixed autonick crashbug in client library.  Affected file
+         lib/silcclient/client.c.
+
+       * Fixed Unix implementation of SilcMutex to really assert if
+         the mutex is locked/unlcoked already.  Affected file
+         lib/silcutil/unix/silcunixmutex.c.
+
+       * Fixed locking in silc_schedule_uninit.  It didn't lock
+         when dispatching timeout tasks.  Affected file is
+         lib/silcutil/silcschedule.c.
+
+       * Changed Win32 implementation of SilcThread to use modern
+         Win32 interface.  Affected file is 
+         lib/silcutil/win32/silcwin32thread.c  A patch by Mikko L.
+
+Thu Dec 12 12:06:59 CET 2002 Jochen Eisinger <c0ffee@penguin-breeder.org>
+
+       * Don't print signed messages when sending failed.  Affected files
+         irssi/src/silc/core/silc-[servers.c/commands.h] 
+
+       * Send adquate signal when founding a channel by joing it.  Affect
+         file irssi/src/silc/core/client_ops.c
+
+Wed Dec 11 21:46:19 CET 2002 Jochen Eisinger <c0ffee@penguin-breeder.org>
+
+       * Fix theme abstracts parsing.  Affected files irssi/default.theme,
+         irssi/src/fe-common/core/themes.c
+
+Wed Dec 11 20:20:07 EET 2002 Pekka Riikonen <priikone@silcnet.org>
+
+       * Fixed close command to use the port correctly when closing
+         server connections.  Affected file silcd/idlist.c.
+
+       * Check for NULL outbuf in silc_socket_write.  It is possible
+         that it is NULL is some odd case.  Affected files are
+         lib/silcutil/[unix/win32]/silc[unix/win32]sockconn.c.
+
+       * Do not call final protocol callback for backup router
+         resuming protocol when closing connection.  It is closed
+         by timeout in case of error.  Affected file silcd/server.c.
+
+       * Backup reconnect to router if backup resuming protocol
+         failed.  Affected file silcd/server_backup.c.
+
+Wed Dec 11 10:01:26 CET 2002 Pekka Riikonen <priikone@silcnet.org>
+
+       * Fixed double free in SKE library error hadling when signature
+         error occurred.  Affected file lib/silcske/silcske.c.
+
+       * Save the fingerprint to new SilcClientEntry after changing 
+         nickname.  Affected file lib/silcclient/client_notify.c.
+
+       * Print SIGNOFF in Irssi SILC client only if the nickname is
+         known.  Prevents asserts in Irssi core.  It is possible we
+         don't have the nick if it was just being resolved when it
+         quit.  Affected file irssi/src/silc/core/client_ops.c.
+
+Tue Dec 10 21:47:56 EET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Fixed double free in invite list adding code when adding
+         invite strings.  Affected file silcd/server_util.c.
+
+Fri Dec  6 17:40:24 EET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * More log printing during backup router protocol.  Affected
+         file silcd/server_backup.c.
+
+       * Removed backwards support for old private key file format.
+         Affected file lib/silccrypt/silcpkcs.c.
+
+       * Removed backwards support for not-so-strict decryption length
+         check, it's strict now.  Affected lib/silccrypt/silccipher.c.
+
+       * GETKEY to update the client entrys fingerprint too.
+         Affected file lib/silcclient/command_reply.c.
+
+       * Added --without-libtoolfix for package builders using weird
+         wrappers around libtool (BSD at least).
+
+Thu Dec  5 22:29:46 EET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Fixed backup router bugs:  When backup resumes router and
+         receives a CHANNEL_MESSAGE packet the backup must not act
+         as router since the packet header decryption would be
+         different.  Also, when relaying packets to channel, do
+         not re-encrypt packets on backup that came from the primary
+         since the connection isn't really router-router connection.
+         Affected files silcd/server.c, silcd/packet_send.c.
+
+       * Added checks in encryption/decryption that encryption/decryption
+         length sent as argument really is multiple by block size.  Helps
+         catching really weird bugs like the above backup router bugs
+         when packets are being decrypted in wrong way.  Affected files
+         lib/silccore/silcpacket.c, and lib/silccrypt/silccipher.c.
+
+       * Fixed padding generation in private key file encryption.
+         Affected file lib/silccrypt/silcpkcs.c.
+
+Thu Dec  5 16:35:23 EET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Added ignore_message_signatures setting which can be used
+         to ignore signatures in messages.  Affected files are
+         irssi/src/silc/core/client_ops.c, silc-core.c.
+
+       * Fixed the libtoolfix to use command line options instead of
+         environment variables.  They didn't work as expected.  Now,
+         the libtool is fully run-time configurable.
+
+Wed Dec  4 21:08:52 CET 2002  Jochen Eisinger <c0ffee@penguin-breeder.org>
+
+       * Verify signature payload for signed messages. Affected files
+         irssi/src/silc/core/client_ops.h, irssi/src/silc/core/silc-servers.c,
+         irssi/src/silc/core/silc-core.h
+
+       * Display signature verification result in public and private
+         messages using theme abstracts. See irssi/default.theme for
+         examples on their usage. Affected files
+         irssi/default.theme, irssi/src/fe-common/silc/fe-messages.h,
+         irssi/src/fe-common/silc/module-formats.[ch],
+         irssi/src/fe-common/silc/fe-common-silc.c,
+         irssi/src/fe-common/silc/Makefile.am
+         irssi/src/fe-common/core/fe-messages.[ch]
+
+       * Fixed bugs in Irssi's theme parsing. Affected files
+         irssi/src/fe-common/core/themes.c
+         
+Wed Dec  4 18:29:13 EET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Calculate the correct length for signed messages before
+         encrypting, it must be multiple by block size.  Affected
+         file lib/silccore/silcmessage.c.
+
+       * silc_message_signed_get_public_key returns now both
+         decoded and encoded public key.  Affected files are
+         lib/silccore/silcmessage.[ch].
+
+       * Added libtoolfix script that makes the libtool more generic
+         and configurable in run-time.  Now we can specify in run-time
+         if what kind of libraries we want to create, regardless of
+         configuration.  SIMs are now creates even if --disable-shared
+         was explicitly given.
+
+Tue Dec  3 23:26:55 EET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Fixed founder key sending in CMODE command in client.
+         Affected file lib/silcclient/command.c.
+
+       * Fixed CUMODE founder authentication in server to not check
+         for client's public key since it's not supposed to do that.
+         Affected file silcd/command.c.
+
+Tue Dec  3 12:02:41 CET 2002  Jochen Eisinger <c0ffee@penguin-breeder.org>
+
+       * Set realname and hostname in NICK_REC records. Affected file
+         irssi/src/silc/core/silc-nicklist.c
+
+Mon Dec  2 20:50:20 EET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Remove 1.0 protocol backwards compat code from client
+         library.
+
+       * Added more reliable check for whether nickname did change
+         or not, or whether only Client ID changed in NICK_CHANGE
+         notify.  Affected file lib/silcclient/client_notify.c.
+         Fixes bug in '@' character handling in a nickname.
+
+       * Added support for automatically parsing signature from
+         the message payload.  Added new function
+         silc_message_get_signature to return the payload to
+         application.  Affected files lib/silccore/silcmessage.[ch].
+
+       * Changed the private_message and channel_message client
+         operations to deliver the SilcMessagePayload to the
+         application too.  Application can use it fe. to get the
+         signature from the message for verification.  Affected
+         file lib/silcclient/silcclient.h, client_channel.c and
+         client_prvmsg.c.
+
+       * Redefined the signed payload for message payloads.
+         Updated protocol specs and implemented.
+
+Mon Dec  2 16:28:29 EET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Fixed wrong invite and ban list handling in server command
+         reply.  Affected files are silcd/command_reply.c,
+         silcd/server_util.[ch].
+
+Sun Dec  1 20:48:17 EET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Fixed CMODE setting in server when founder mode was set.
+         Affected file silcd/command.c.  Bug #95.
+
+       * Added support to setting specific public key in CMODE in
+         Irssi SILC client.  Affected file lib/silcclient/command.c.
+
+       * Added support to use specific public key in CUMODE in
+         Irssi SILC Client.  Affected file lib/silcclient/command.c.
+
+       * Added support for inviting and banning by public key in
+         Irssi SILC client.  Affected file lib/silcclient/command.c.
+
+       * Fixed fingerprint/babbleprint showing in invite and ban
+         list command replys.  Affected file is
+         irssi/src/silc/core/client_ops.c.
+
+Sun Dec  1 16:32:03 CET 2002  Jochen Eisinger <c0ffee@penguin-breeder.org>
+
+       * Format CMODE +c and +h to display both the mode and the argument
+
+Sun Dec  1 18:17:22 EET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Added test vectors and test programs for SHA-1, MD5,
+         HMAC-SHA1 and HMAC-MD5.  New tests are located in
+         lib/silccrypt/tests/.  Fixed also argument decoding bug in
+         MD5 implementation.  Affected file lib/silccrypt/md5.c.
+
+       * Changed the channel private key and private message key
+         generation (with static keys) to use SHA1 instead of MD5,
+         as SHA1 is the mandatory hash function in SILC.  Affected
+         file lib/silcclient/client_[channel/prvmsg].c.
+
+       * Changed the private key file encryption to use SHA1 instead
+         of MD5.  Added support for the old generation and added
+         automatic change of the key (to be removed later).  Affected
+         files lib/silccrypt/silcpkcs.c.
+
+Sat Nov 30 19:07:52 EET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Load only files with .pub suffix in PublicKeyDir.  Affected
+         file silcd/serverconfig.c.
+
+Sat Nov 30 14:29:34 CET 2002  Johnny Mnemonic <johnny@themnemonic.org>
+
+       * Extended the SILC_SERVER_LOG_ERROR macro to all available logging
+         channels.  Affected files silcd/silcd.c, silcd/server.h.
+
+       * Added the config directive PublicKeyDir for the client block.
+         Affected files doc/exampe_silcd.conf.in, silcd/serverconfig.[ch].
+
+Sat Nov 30 09:30:55 CET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Merged Toni's irssi/silc.conf patch.
+
+       * ROBODoc cleanup patch to lib/silccrypt/silcpkcs.h by johnny.
+
+       * Max alloc tests in allocation routines.  Affected file
+         lib/silcutil/silcmemory.c.
+
+Fri Nov 29 23:44:29 EET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Fixed a typo in resuming code that fixed detach/resume code
+         in server.  Bug #93.  Affected file silcd/packet_receive.c.
+
+Thu Nov 28 17:17:11 CET 2002  Jochen Eisinger <c0ffee@penguin-breeder.org>
+
+       * Do reverse lookups for server when /connecting. Affected files
+         irssi/silc.conf, irssi/src/core/servers.c, irssi/src/core/network.c,
+         irssi/src/core/net-nonblock.*
+       
+Thu Nov 28 16:19:18 CET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Added library versioning for shared libraries.  Affected
+         files configure.in.pre and lib/Makefile.am.pre.
+
 Wed Nov 27 21:51:52 CET 2002  Jochen Eisinger <c0ffee@penguin-breeder.org>
 
        * Display INVITE and BAN lists as specified by SILC 1.2
diff --git a/INSTALL b/INSTALL
index 847e9e68c8f37c483c7a64f6a7069ae009b33ea1..9871e92e93a7683fa78bfb5fd16f22f55455ce5c 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -49,6 +49,11 @@ package or does not want to use them, you can give the --disable-asm
 option to the `configure' script.  This will assure that assembler
 optimized code is not compiled in.
 
+`--enabled-shared'
+
+   If you wish to compile and install shared libraries then enable this
+option.  By default all libraries are compiled as static libraries.
+
 `--enable-debug'
 
    If you would like to enable the debugging for the compiled programs
index 522f7f2c910d6c9e3416ec2878b47ec9246ee954..e20a823ba1a666c4fa4d7d14d26135876147555d 100644 (file)
@@ -33,7 +33,7 @@ dist-bzip: distdir
        -rm -rf $(distdir)
 
 SILC_EXTRA_DIST = SILC_DISTRIBUTION_EXTRA
-EXTRA_DIST = CHANGES CREDITS $(SILC_EXTRA_DIST)
+EXTRA_DIST = libtoolfix CHANGES CREDITS $(SILC_EXTRA_DIST)
 
 #
 # Installing of SILC into the system
diff --git a/TODO b/TODO
index 7ed56659ea7521b3930089779c6844db05725c20..1d5f3a69a4ed8b2250c102941de176f167e1489e 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,14 +1,6 @@
 TODO for Irssi SILC Client 1.0
 ==============================
 
- o Support to set arbitrary pulic key in CMODE.
-
- o INVITE/BAN by public key file.
-
- o Signed message payload handling on UI
-
- o bugs parsing nicknames with @ in NICK_CHANGE
-
  o Testing - See test plan:
      http://silcnet.org/docs/silc-client-1.0-test.pdf
      http://silcnet.org/docs/silc-client-1.0-test.ps
@@ -17,6 +9,8 @@ TODO for Irssi SILC Client 1.0
 TODO for SILC Server 1.0
 ========================
 
+ o Fix CUMODE_CHANGE and CMODE_CHANGE for founder key things.
+
  o 1.2 backup router support
 
  o Testing
@@ -25,9 +19,11 @@ TODO for SILC Server 1.0
 TODO/bugs In SILC Libraries
 ===========================
 
- o WIN32 silc_net_create_connection_async does not work the same way
-   than on Unix.  Do it with threads on WIN32.  The function works but
-   is not actually async currently (Fix this to 0.9.x).
+ o Test cases for all cryptographic primitive in lib/silccrypt/
+
+ o Test cases for all payload encoding and decoding routins in lib/silccore/
+
+ o Test cases for math library routines in lib/silcmath/
 
 
 TODO in Toolkit Documentation
index 4665195fab24e17dc2bfba220f2f8293606e95ec..69891b7bc62a304787f79d8004dc11ee95f16fec 100644 (file)
@@ -19,7 +19,7 @@ include $(top_srcdir)/Makefile.defines.in
 
 #confdir = $(sysconfdir)
 confdir = $(silc_etcdir)
-conf_DATA = silc.conf
+conffile = silc.conf
 
 themedir = $(datadir)/silc/themes
 theme_DATA = default.theme
@@ -33,7 +33,7 @@ EXTRA_DIST = \
        file2header.sh \
        irssi.spec \
        irssi.spec.in \
-       $(conf_DATA) \
+       $(conffile) \
        $(theme_DATA) \
        irssi-config.in \
        irssi-icon.png \
index 121ca9459dc4538caa2cc2aea1f4b3d52d958286..1e2dca6f6ec73d1e7dc3571c984991d88b80db64 100644 (file)
@@ -273,6 +273,64 @@ abstracts = {
   sb_act_hilight = "%M$*";
   # hilight with specified color, $0 = color, $1 = text
   sb_act_hilight_color = "$0$1-%n";
+
+  # signed messages
+  # the following formats fit the Irssi default theme:
+  # 
+  # flag_signed = "%GS%n";
+  # flag_unknown = "%Y?%n";
+  # flag_failed = "%RF%n";
+  # 
+  # pubmsghinick_signed = "{msgnick {flag_signed} $0$2-%n}";
+  # pubmsghinick_unknown = "{msgnick {flag_unknown} $0$2-%n}";
+  # pubmsghinick_failed = "{msgnick {flag_failed} $0$2-%n}";
+  # 
+  # pubmsgmenick_signed = "{msgnick {flag_signed} $1-}";
+  # pubmsgmenick_unknown = "{msgnick {flag_unknown} $1-}";
+  # pubmsgmenick_failed = "{msgnick {flag_failed} $1-}";
+  # 
+  # pubmsgnick_signed = "{msgnick {flag_signed} $1-}";
+  # pubmsgnick_unknown = "{msgnick {flag_unknown} $1-}";
+  # pubmsgnick_failed = "{msgnick {flag_failed} $1-}";
+  # 
+  # privmsg_signed = "{privmsg {flag_signed}$0 $1}";
+  # privmsg_unknown = "{privmsg {flag_unknown}$0 $1}";
+  # privmsg_failed = "{privmsg {flag_failed}$0 $1}";
+  # 
+  # privmsgnick_signed = "{msgnick {flag_signed} %R$*%n}";
+  # privmsgnick_unknown = "{msgnick {flag_unknown} %R$*%n}";
+  # privmsgnick_failed = "{msgnick {flag_failed} %R$*%n}";
+  # 
+  # ownmsgnick_signed = "{msgnick {flag_signed} $1-}";
+  # ownprivmsgnick_signed = "{msgnick {flag_signed} $*}";
+  #
+  flag_signed = "[%cS%n]";
+  flag_unknown = "[%Y?%n]";
+  flag_failed = "[%RF%n]";
+
+  pubmsghinick_signed = "{msgnick {flag_signed} $0$2-%n}";
+  pubmsghinick_unknown = "{msgnick {flag_unknown} $0$2-%n}";
+  pubmsghinick_failed = "{msgnick {flag_failed} $0$2-%n}";
+  
+  pubmsgmenick_signed = "%g<{flag_signed}$1->%n %|";
+  pubmsgmenick_unknown = "%g<{flag_unknown}$1->%n %|";
+  pubmsgmenick_failed = "%g<{flag_failed}$1->%n %|";
+  
+  pubmsgnick_signed = "{msgnick {flag_signed}$0 $1-}";
+  pubmsgnick_unknown = "{msgnick {flag_unknown}$0 $1-}";
+  pubmsgnick_failed = "{msgnick {flag_failed}$0 $1-}";
+  
+  privmsg_signed = "{privmsg {flag_signed}$0 $1}";
+  privmsg_unknown = "{privmsg {flag_unknown}$0 $1}";
+  privmsg_failed = "{privmsg {flag_failed}$0 $1}";
+  
+  privmsgnick_signed = "{privmsgnick {flag_signed}$0}";
+  privmsgnick_unknown = "{privmsgnick {flag_unknown}$0}";
+  privmsgnick_failed = "{privmsgnick {flag_failed}$0}";
+  
+  ownmsgnick_signed = "{msgnick {flag_signed} $1-}%g";
+  ownprivmsg_signed = "->*%c{flag_signed}$1-%n* %g";
+  ownprivmsgnick_signed = "->*%c{flag_signed}$0%n* %g$1-";
 };
 
 #
index 89123fccd57b2f4d8b59499c67eb4f66fc2db426..6f0b9f1b980a491a120883ddb00731a9132fcf09 100644 (file)
@@ -1,9 +1,6 @@
 
 @SYNTAX:action@
 
-Same as ME, but gets channel as an additional parameter.
-Example: /ACTION #irssi yawns
-(This outputs the following to #irssi: * Nick yawns)
+Same as ME, but gets channel as an additional parameter. Example: /ACTION silc yawns (This outputs the following to channel silc: * Nick yawns)
 
 See also: ME
-
index f854cd0f4f53d4e7c5b7a93b9fd83ddfdfab3a5b..76160f02b4901f1973a70b84f8bfe48baf7cd013 100644 (file)
@@ -5,7 +5,6 @@ Displays the administrative details about the given server. If
 no server is specified, the server you are connected to is
 used.
 
-This command may be an alias.
-
-See also: INFO
+This command is an alias of INFO.
 
+See also: INFO, STATS
index 32bf76e931790afbdc51170562cc57e14b391473..f6b7496aa9e3f36dbf889949ba5d382264f020d7 100644 (file)
@@ -5,6 +5,9 @@ This command is used to manage the ban list of the channel.
 You must be channel operator to be able to use this command.
 Wildcards may be used with this command.
 
+In ban list it is possible to add nicknames, server name, username,
+hostname or netmask (IP/MASK), and public keys.
+
 Examples:
     /BAN #mychannel +foobar!mr.bar@foo.bar.com
         Adds nickname `foobar' with username `mr.bar' from host
@@ -17,6 +20,10 @@ Examples:
         Adds foo* nicknames from any server with any username from
         *.foobar.com hosts to the ban list on current channel.
 
+    /BAN * +/path/to/public_key.pub
+        Adds the public key from file /path/to/public_key.pub to
+        ban list of the current channel.
+
     /BAN * -looser
         Removes the nickname `looser' from the ban list on current
         channel.
@@ -24,5 +31,5 @@ Examples:
     /BAN *
         Shows the ban list of the current channel.
 
-See also: KNOCKOUT, KICKBAN
+See also: KICK
 
index ea324aa3eb092c91ec6d511f3c5190b2ef9d91fc..51c07678dd7f846c774f668d9dc8beb537082452 100644 (file)
@@ -4,5 +4,5 @@
 Outputs the contents of the specified file. Equivalent to
 UNIX 'cat' command.
 
-See also: CD
+See also: EXEC
 
index dd62f710f60819fc17a797830c8605313b434352..1d9f8d62e9e7b371d10d3a8b0dffdffbda4e3726 100644 (file)
@@ -4,5 +4,5 @@
 Changes the current working directory. Equivalent to UNIX
 'cd' command.
 
-See also: DCC GET
+See also: EXEC
 
index 7ce6dffd846f8ad1de69b211e7af4121b7131c96..e7f8043f6ed00d2265b4f1fb9a189e5cd5f10aba 100644 (file)
@@ -4,5 +4,10 @@
 Operator command.  Makes the server to close connection to another server
 or router.
 
-See also: OPER, SILCOPER
+You need to use same name of the server as configured in silcd.conf.
+
+Example: /CLOSE sauna.silcnet.org
+
+See also: SCONNECT, OPER, SILCOPER
+
 
index 6f4f25db9920fb2d29c5d3fa88f55bfa7a383ff3..6806bea14b562dc4f760e9d2dc2b843fb9d0bdd5 100644 (file)
@@ -24,7 +24,8 @@ option(s).  The following modes are available:
                     be provided when joining to the channel.
     c <cipher>      Set/unset channel's cipher
     h <hmac>        Set/unset channel's hmac
-    f               Set/unset channel founder authentication.
+    f [<pubkeyfile> <privkeyfile> [<privkey passphrase>]]
+                    Set/unset channel founder authentication.
                     Channel founder may set this mode so that
                     if the client leaves the channel it can
                     claim the founder rights when it returns
@@ -32,6 +33,14 @@ option(s).  The following modes are available:
                     be permanent channel.  You can claim the
                     founder rights using CUMODE or JOIN commands.
 
+                    If the <pubkeyfile> and <privkeyfile> is
+                    provided then the <pubkeyfile> will the used
+                    as founder public key, and the private key
+                    is used to compute a signature for the SILC
+                    server.  If these are omitted then the default
+                    SILC keypair is used.  Normally you do not need
+                    to provide these arguments.
+
 Multiple modes can be set/unset at once if the modes does not
 require any arguments.  If mode requires an argument then only
 one mode can be set at once.
index 2bb44bcab4e1d5a28883e12b36c17a9a0915fb4d..623c7e548aeaa1409f42fe173c44b34c8f099b36 100644 (file)
@@ -15,11 +15,20 @@ are available:
         only to remove both modes at once).
 
     f <nickname>[@<server>]
+      [<pubkeyfile> <privkeyfile> [<privkey passphrase>]]
 
         Set/Unset channel founder.  If you are channel
         founder you can set the channel founder authentication
         using CMODEc command.
 
+        If the <pubkeyfile> and <privkeyfile> is
+        provided then the <pubkeyfile> will the used
+        as founder public key, and the private key
+        is used to compute a signature for the SILC
+        server.  If these are omitted then the default
+        SILC keypair is used.  Normally you do not need
+        to provide these arguments.
+
     o <nickname>[@<server>]
 
         Set/unset channel operator.  Requires that 
index 34f856a572a031d68c1ec71208c04765610ddc16..7c87d1f97c61fe2189b4c545f80dad4147d65371 100644 (file)
@@ -1,9 +1,6 @@
 
 @SYNTAX:dehilight@
 
-Makes irssi not to highlight items containing the text.
-If parameter is a number, deletes the specified hilight
-entry from the list.
-
-See also: HILIGHT
+Remove given highlight. If parameter is a number, deletes the specified hilight entry from the list.
 
+See also: HILIGHT, SET HILIGHT
index c33ec59f89df87bdd221e51800620c808fba56de..d88af57fb1e705172a9c91feb7f939d30068fda6 100644 (file)
@@ -35,3 +35,6 @@ standard input of the process with -in option.
 kill the process. It is meant to remove the processes that don't die
 even with SIGKILL. This option just closes the pipes used to
 communicate with the process and frees all memory it used.
+
+See also: CAT, CD
+
index bb1c4c5857e851f8224f792d588ca41b70eb6ab4..82fdfdb67d751eb136691d3148960bfc0ac27707 100644 (file)
@@ -8,3 +8,4 @@ client posesses the corresponding private key as well.  You will be
 prompted to verify and accept the fetched public key.  The public key
 is saved into your local key directory (~/.silc/clientkeys/).
 
+See also: WHOIS, KEY
index 12e0b2f39fa5d58d4a5bbc9cf68a30394ee74a58..e4e9eec7ca1938f8fcb489231fca2d7b72464007 100644 (file)
@@ -5,3 +5,4 @@ Displays the administrative details about the given server. If
 no server is specified, the server you are connected to is
 used.
 
+See also: STATS
index 7d11e262b80efa6e466c39d1a7901f4b0b01e71e..21afbd1810ad53b59b39cea871f37aa417fd8a9a 100644 (file)
@@ -4,6 +4,9 @@
 This command is used to invite an client to a channel and to manage
 the channel's invite list.  Wildcards may be used with this command.
 
+In invite list it is possible to add nicknames, server name, username,
+hostname or netmask (IP/MASK), and public keys.
+
 Examples:
     /INVITE silc joe
         Invites nickname `joe' to channel 'silc', and adds the client
@@ -17,6 +20,10 @@ Examples:
         Adds nicknames foo* from silcnet.org server from *.foobar.com
         hosts to the invite list of the current channel.
 
+    /INVITE * +/path/to/public_key.pub
+        Adds the public key from file /path/to/public_key.pub to
+        invite list of the current channel.
+
     /INVITE * -joe
         Removes nickname `joe' from the invite list of the current
         channel.
index 062c2ad303ca1cb9a8a8a26eb163bdab75b29c74..a14b49f1d681177ea7e0abd76f07e4664eb0355c 100644 (file)
@@ -103,3 +103,5 @@ Examples:
     /KEY MSG nick set secretkey -responder
     /KEY MSG foo agreement 10.2.1.7 5000
     /KEY MSG bar negotiate 10.2.1.7 5000
+
+See also: WHOIS, CHANNEL, GETKEY
index 3e73dbe247cc5ec07a72dd3e56ac3486dccd7f30..1f67d34fc9ff61238b2925f01b9b0c45a226b69c 100644 (file)
@@ -8,5 +8,5 @@ you are channel operator.
 
 The default alias for /KICK is /K.
 
-See also: KNOCKOUT
+See also: BAN
 
index 0c508c4f51cb15e34d4217f740d35f0b80e9f0ca..732a47124edc44064fef4fb6b9069be8b044c607 100644 (file)
@@ -18,5 +18,5 @@
 
 Shows the given number of lines of log from the current window.
 
-See also:
+See also: LOG, SET LOG, WINDOW LOG
 
index d0cde15eb12d20d7b0ae212594f255bb0e3ade17..0d6d26f9caae275a94df073b3da395d66ae70a84 100644 (file)
@@ -7,7 +7,9 @@ run irssi, all the channels and queries are exactly in the same
 windows where they were when you called /LAYOUT SAVE.
 
 Channels aren't actually joined in those windows immediately, they're
-just marked "next time you join to '#channel' in server that has tag
-'ircnet' place it to this window".
+just marked "next time you join to 'channel' in server that has tag
+'silcnet' place it to this window".
 
 /LAYOUT RESET removes the saved layout.
+
+See also: SAVE
index a1f697e7348fb85b34ec2f275e714417e08377f9..ae4b02d9fbd87cbed64264ecf26f113d5aa3e14e 100644 (file)
@@ -1,16 +1,9 @@
 
 @SYNTAX:list@
 
-Lists the channel names. Trying to list all the channel 
-names usually causes you to be disconnected from the 
-server with the reason "Excess flood", as usually all
-40000 channels form together and server naively attempts
-to send you them.
+Lists all channel names and number of people on them. Channel topics
+are also shown.
 
-Thus, on IRCNet, you should rather use service ALIS
-(Advanced Listing Service), which will allow you to query
-for channel with specific name, topic, mode or usercount.
-Type /SQUERY ALIS HELP to get more info about it.
-
-See also: SQUERY
+Your server only knows number of people on channels if it has local
+clients joined onto those. This is why you'll see N/A for some channels.
 
index 16ce9be588df1dcc18a6d8cbc764a9141d437a77..7b427454dfdfd18662af6ddb2f287240267b616d 100644 (file)
@@ -4,11 +4,8 @@
 Load a plugin. If full path isn't given, irssi searches the
 plugin from directories:
 
- ~/.irssi/modules/
- <install dir, /usr/local or /usr maybe>/lib/irssi/modules/
-
-See plugins page of http://irssi.org/ to see if there's any plugins
-you'd want to use.
+~/.silc/modules/
+/path/to/silc/modules/ (by default /usr/local/silc/modules)
 
 See also: UNLOAD
 
index 6a61ef9f0c8e25348f70f9096f37dd01f89f064e..ea5948f3df6d54b04cc95a93baf43a7f8d3b5f5b 100644 (file)
@@ -22,19 +22,19 @@ All of these are parsed with strftime():
 /SET log_close_string <text> - Text written to log when it's closed
 /SET log_day_changed <text> - Text written to log when day changes
 
-NOTE: Log files are locked after opened, so two Irssis can't
+NOTE: Log files are locked after opened, so two clients can't
 accidentally try to write to the same log file.
 
 Examples:
         
-/LOG OPEN -targets cras ~/irclogs/cras.log MSGS
-     - Logs all messages from/to nick `cras'
+/LOG OPEN -targets Toni ~/silclogs/Toni.log MSGS
+     - Logs all messages from/to nick `Toni'
 
-/LOG OPEN -targets #linux ~/irclogs/linux/linux-%%Y-%%m-%%d
-     - Logs all messages in channel #linux. Log is rotated daily, so
-       logs in 1. May 2000 goes to file "linux-2000-05-01", when the
-       day is changed, Irssi closes the log and starts logging to
-       "linux-2000-05-02" etc.
+/LOG OPEN -targets silc ~/silclogs/silc/silc-%%Y-%%m-%%d
+     - Logs all messages in channel silc. Log is rotated daily, so
+       logs in 1. May 2000 goes to file "silc-2000-05-01", when the
+       day is changed the log is closed and new log is opened as
+       "silc-2000-05-02".
 
-See also: SET LOG, WINDOW LOG
+See also: LASTLOG, SET LOG, WINDOW LOG
 
index ba3544088e4064ce3ff156553538623fd97e69fa..d066ee68b2b68ca592797331453a9b467e3439da 100644 (file)
@@ -1,7 +1,6 @@
 
 @SYNTAX:motd@
 
-Shows the motd of the current server. This contains
-usually some useful info on the server, administrator and
-the rules.
+Shows the motd of the current or given server. This contains usually some useful info on the server, administrator and the rules.
 
+See also: INFO, ADMIN, STATS
index 6267a6790f64e27415ddb592b9c17751dc3e5ce3..fb7c4fc7f625191628c52161687cbd83ccae1315 100644 (file)
@@ -1,9 +1,22 @@
 
 @SYNTAX:msg@
 
-Sends a message to a remote client. Usually this
-is used for sending private messages to other persons.
+Sends a private message to other user in the network.
 
-Examples:
+It is possible to digitally sign your messages.  The receiver
+may then verify the message with your public key.  By default
+messages are not signed.  If you want your private messages 
+to be signed you SMSG command instead of this MSG command.
 
-/MSG friend Hi, what's up?
+If -channel option is provided then this command actually
+send channel message to the specified channel.  The message
+IS NOT private message, it is normal channel message.  It is
+also possible to digitally sign channel messages by using
+SMSG command or by doing /set sign_channel_messages on, in
+which case _all_ channel messages will be signed.
+
+Example:
+
+/MSG Toni Hi, what's up?
+
+See also: QUERY SMSG
index d3512d0bba50084bca7737ff8be8899e1dfa03f1..6882ecba78714304d51765b331fe4a0beba6e3b7 100644 (file)
@@ -6,17 +6,15 @@
      -voices: show voiced people in list
      -normal: show rest of the people in list
 
-Shows the names (nicks) in the specified channels. /NAMES **
-shows all nicks in all channels, you probably don't want
-to do this.
+Shows users of specified channels. /NAMES ** shows all nicks in all channels, you probably don't want to do this.
 
 Examples:
 
 /NAMES
      - shows nicks in the current channel.
 
-/NAMES -ops #c1,#c2
-     - shows operators in channels #c1 and #c2
+/NAMES -ops silc,beginners
+     - shows operators in channels silc and beginners
 
-See also: WHO, CHANNEL
+See also: USERS, WHO, WHOIS, WHOWAS, CHANNEL
 
index ff3b12fb64ce679c9096021fc5e7cd05771a0c5b..c10d6e7595060f1433ce9568d4404cc4ad1fd37c 100644 (file)
@@ -1,8 +1,7 @@
 
 @SYNTAX:part@
 
-Parts from the current or specified channel. Depending
-on your settings, closes the corresponding window, too.
+Parts from the current or specified channel. Depending on your settings it closes the corresponding window also.
 
-See also: LEAVE, JOIN
+See also: JOIN
 
index 52f191eef1dad3abdcf8c7226b84a7df96709426..2631e68aec52cb0f281bef12fedea99e66c1c810 100644 (file)
@@ -1,13 +1,9 @@
 
 @SYNTAX:query@
 
-Starts a private conversation with the nick.  All text you
-type that would normally be sent to your channel now goes to
-the specified nick in the form of MSGs. 
+Starts a private conversation with given person.
 
-Usually this command opens up a new window, too.
-
-The query is ended by giving command UNQUERY
+The query session is ended by giving command UNQUERY
 
 See also: UNQUERY, WINDOW, MSG, SET QUERY
 
index 1c1e7bac089d226010a2d238e6997c8efd50146d..39cf8842af8d53cd6fa8ad7afbf5730ee030bd7c 100644 (file)
@@ -1,10 +1,8 @@
 
 @SYNTAX:quit@
 
-This ends your session. If a quit message is supplied, it 
-will be displayed to anyone else on any channel you were on 
-before quitting. If one isn't specified, the text "Leaving" is
-used.
+This ends your session.
 
-/EXIT does the same.
+If a quit message is supplied, it will be displayed to everyone on all channels you were on before quitting. If quit message isn't specified, the text "leaving" is used.
 
+See also: EXIT
index a6d5ea5be516327e93df7316a1b17fd66d743155..664d8668cb085e7d62e9e7aac79ec23a2b7bcc89 100644 (file)
@@ -1,8 +1,6 @@
 
 @SYNTAX:save@
 
-Saves the current Irssi configuration into the configuration
-file.
-
-See also: RELOAD
+Saves the current configuration.
 
+See also: RELOAD, LAYOUT
index f77c5d3d978752c89a1acd3affe52d2354edf6da..6162777401f3b0f3dca62cbf8b4d3ceb7b3bb8dc 100644 (file)
@@ -5,7 +5,8 @@ Operator command. Makes an server to connect to another
 server or router.  The <server> is the hostname or IP 
 addres of the server.
 
-Example: /SCONNECT silc.silcnet.org 706
+You need to use same name of the server as configured in silcd.conf.
 
-See also: OPER, SILCOPER, CLOSE, SHUTDOWN
+Example: /SCONNECT sauna.silcnet.org
 
+See also: CLOSE, OPER, SILCOPER
index 0354512bde4c2577519eb6428a5c7a8ea91d2fd7..fc2f6410b6be1025d4b3ea4b7049380da616e157 100644 (file)
@@ -15,5 +15,5 @@ Without any parameters, /SCRIPT acts in same way as if you would call /SCRIPT LI
 
 /SCRIPT RESET unloads all loaded scripts and resets the perl interpreter.
 
-See also: LOAD, UNLOAD
+See also: LOAD, UNLOAD, RUN
 
index ac514f73f7cf5d12d1f5bf8588b1cd42b44d875f..2256e982297bc96ae45cba0d9ec15cfd2277af77 100644 (file)
@@ -4,11 +4,9 @@
      -4, -6: specify explicitly whether to use IPv4 or IPv6 address
      -auto: Automatically connect to server at startup (default)
      -noauto: Don't connect to server at startup
-     -silcnet: Specify what network this server belongs to
-     -host: Specify what host name to use, if you have multiple
+     -silcnet: Specify the network this server belongs to
+     -host: Specify what host name to bind to, if you have multiple interfaces
      -!: don't autojoin channels
-     -cmdspeed: Same as /SET cmd_queue_speed, see section 3.1
-     -cmdmax: Same as /SET cmd_max_at_once, see section 3.1
      -port: This is pretty much like the port argument later, 
             except this can be used to modify existing server's 
             port.
@@ -25,7 +23,4 @@ where the server is connected (ie. /window new hide;
 
 /SERVER REMOVE <address> [<port>]
 
-/SERVER LIST
-
-See also: RMRECONNS, DISCONNECT, RECONNECT
-
+See also: RMRECONNS, DISCONNECT, RECONNECT, CONNECT
index 48ff58c9c81ece6273561e549af79ea709531ea5..e71d100787dee87306b42f36eec6496222fcf640 100644 (file)
@@ -1,7 +1,6 @@
 
 @SYNTAX:shutdown@
 
-Operator command.  Shutdowns the server.
+Operator command.  Shuts the server down.
 
 See also: OPER, SILCOPER, CLOSE
-
diff --git a/apps/irssi/docs/help/in/smsg.in b/apps/irssi/docs/help/in/smsg.in
new file mode 100644 (file)
index 0000000..86d3fb1
--- /dev/null
@@ -0,0 +1,33 @@
+
+@SYNTAX:smsg@
+
+Sends a signed private message to other user in the network.
+The message will be digitally signed and the receiver may verify
+the message by using your public key.
+
+If -channel option is provided then this command actually
+send channel message to the specified channel.  The message
+IS NOT private message, it is normal channel message.  Also this
+message will be signed and can be verified by using your public
+key.
+
+The default theme of Irssi SILC Client shows the digital signed
+messages with [S] at start of the nickname who sent the message, when
+the message was successfully verified, [?] if the message could not
+be verified since the public key of the sender isn't cached locally,
+or [F] if the signature verificationn failed.  If you do not have
+the sender's public key you can fetch it with GETKEY command.
+
+If you don't want to verify the signatures from received messages
+you may do /SET ignore_message_signatures on.  In this case
+signatures in messages are ignored and they appear as normal
+non-signed messages.  By default, all message signatures are
+verified.
+
+Examples:
+
+/SMSG Foobar Very authenticated message
+/SMSG -channel silc Another signed message
+/SMSG * I truly said this
+
+See also: MSG QUERY GETKEY
index 58418794ead28f757a0a8f595ecc329d462274df..310cc87c4b25684a53bb91716753484105b04940 100644 (file)
@@ -2,3 +2,5 @@
 @SYNTAX:stats@
 
 Shows various server and network statistics.
+
+See also: INFO, ADMIN
diff --git a/apps/irssi/docs/help/in/upgrade.in b/apps/irssi/docs/help/in/upgrade.in
deleted file mode 100644 (file)
index 00c9c18..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-
-@SYNTAX:upgrade@
-
-Upgrade irssi to new version on-the-fly without disconnecting from
-server, so other people won't even notice you quit from network. This ONLY
-executes the new binary, it does NOT download/compile/whatever irssi.
-
-NOTE: THIS COMMAND DOES NOT WORK WITH Irssi-SILC CLIENT!
-
index 71cf2db271d4e998557f85259ca8d90b01203a6a..4fe4760b3d258c3d11c2f96c1dd0fe680b79af30 100644 (file)
@@ -1,11 +1,8 @@
 
 @SYNTAX:users@
 
-Shows users of the specified channel. The channel must be either joined or it
-needs to be a public channel (without secret or private flags set).
+Lists users of given channel. The channel must be either joined or it needs to be a public channel (without secret or private flags set).
 
 Alias WHO is by default USERS * command.
 
-See also: WHOIS, WHOWAS
-
-
+See also: NAMES, WHOIS, WHOWAS
index 1533b0c31805a708981429d0946ffcee7c4d0639..d153a023e55f76e54f2a410ef1d22c88bdfc0361 100644 (file)
@@ -26,5 +26,5 @@ informations is received.
 If you want to send your information in WHOIS you can set the
 information with ATTR command.  See HELP ATTR.
 
-See also: WHOWAS, CHANNEL, ATTR
+See also: WHOIS, CHANNEL, ATTR, NAMES, WHO
 
index 559e4cde9a6e4e161443eafc79a6cf9ba39790da..c2bd1c69bd57a94aef601fc78943b6c4d2e0fbc6 100644 (file)
@@ -1,10 +1,10 @@
 #
 # Configured servers
 #
+# silc.silcnet.org is DNS round robin for all (currently) known public SILCNet servers.
+#
 servers = (
-  { address = "silc.silcnet.org"; chatnet = SILCNet; port = 706; },
-  { address = "silc.ytti.fi"; chatnet = SILCNet; port = 706; },
-  { address = "silc.peelo.com"; chatnet = SILCNet; port = 706; },
+  { address = "silc.silcnet.org"; chatnet = SILCNet; port = 706; autoconnect = "yes"; }
 );
 
 #
@@ -37,8 +37,6 @@ aliases = {
   EXIT = "quit";
   SIGNOFF = "quit";
   DESCRIBE = "action";
-  DATE = "time";
-  HOST = "userhost";
   LAST = "lastlog";
   SAY = "msg *";
   WHO = "users *";
@@ -56,15 +54,12 @@ aliases = {
   KN = "knockout";
   BANS = "ban";
   B = "ban";
-  MUB = "unban *";
-  UB = "unban";
   IG = "ignore";
   UNIG = "unignore";
   SB = "scrollback";
   WC = "window close";
   WN = "window new hide";
   GOTO = "sb goto";
-  CHAT = "dcc chat";
   ADMIN = "info";
   RUN = "SCRIPT LOAD";
   UPTIME = "eval exec - expr `date +%s` - \\$F | awk '{print \"Irssi uptime: \"int(\\\\\\$1/3600/24)\"d \"int(\\\\\\$1/3600%24)\"h \"int(\\\\\\$1/60%60)\"m \"int(\\\\\\$1%60)\"s\" }'";
@@ -73,6 +68,7 @@ aliases = {
   Q = "QUERY";
   MOOD = "ATTR status_mood";
   OP = "CUMODE $C +o";
+  DEOP = "CUMODE $C -o";
 };
 
 #
@@ -179,7 +175,7 @@ statusbar = {
       placement = "top";
       position = "1";
       visible = "always";
-      disabled = "yes";
+      disabled = "no";
       items = {
         barstart = { priority = "100"; };
         topic = { };
@@ -201,7 +197,6 @@ statusbar = {
 # aes-256-cbc, aes-192-cbc, aes-128-cbc,
 # twofish-256-cbc, twofish-192-cbc, twofish-128-cbc,
 # rc6-256-cbc, rc6-192-cbc, rc6-128-cbc, 
-# mars-256-cbc, mars-192-cbc, mars-128-cbc,
 # cast-256-cbc, cast-192-cbc and cast-128-cbc
 #
 # Available hash functions are (default: sha1):
@@ -219,15 +214,17 @@ settings = {
     crypto_default_hmac = "hmac-sha1-96";
   };
   "fe-common/core" = {
-    autocreate_own_query = "no";
+    autocreate_own_query = "yes";
     use_status_window = "no";
     autoclose_windows = "no";
     use_msgs_window = "no";
-    autocreate_windows = "no";
-    autocreate_query_level = "none";
+    autocreate_windows = "yes";
+    autocreate_query_level = "MSG";
+    reuse_unused_windows = "yes";
   };
   core = {
     server_reconnect_time = "10000";
+    resolve_reverse_lookup = "yes";
   };
   "fe-text" = { indent = "8"; };
 };
index 16c3a0e90c7d512e8d62db29d22f5147564869df..722d3df58955473c0c943e87429497123d94ee5b 100644 (file)
@@ -112,7 +112,7 @@ static SERVER_CONNECT_REC *get_server_connect(const char *data, int *plus_addr,
         return conn;
 }
 
-/* SYNTAX: CONNECT [-4 | -6] [-ssl] [-noproxy] [-ircnet <ircnet>]
+/* SYNTAX: CONNECT [-4 | -6] [-ssl] [-noproxy] [-silcnet <silcnet>]
                    [-host <hostname>] [-rawlog <file>]
                    <address>|<chatnet> [<port> [<password> [<nick>]]] */
 static void cmd_connect(const char *data)
@@ -214,7 +214,7 @@ static void sig_default_command_server(const char *data, SERVER_REC *server,
         signal_emit("command server connect", 3, data, server, item);
 }
 
-/* SYNTAX: SERVER [-4 | -6] [-ssl] [-noproxy] [-ircnet <ircnet>]
+/* SYNTAX: SERVER [-4 | -6] [-ssl] [-noproxy] [-silcnet <silcnet>]
                   [-host <hostname>] [-rawlog <file>]
                   [+]<address>|<chatnet> [<port> [<password> [<nick>]]] */
 static void cmd_server_connect(const char *data, SERVER_REC *server)
@@ -289,7 +289,6 @@ static void cmd_quit(const char *data)
        signal_emit("gui exit", 0);
 }
 
-/* SYNTAX: JOIN [-invite] [-<server tag>] <channels> [<keys>] */
 static void cmd_join(const char *data, SERVER_REC *server)
 {
        GHashTable *optlist;
@@ -320,7 +319,7 @@ static void cmd_join(const char *data, SERVER_REC *server)
        cmd_params_free(free_arg);
 }
 
-/* SYNTAX: MSG [-<server tag>] [-channel | -nick] <targets> <message> */
+/* SYNTAX: MSG [-channel] <target> <message> */
 static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
 {
        GHashTable *optlist;
index b4e6d6e0627f9607eb01ffb00d5e3410476cc07b..7125344ff0bfc08b79db1cdabe509fa39c6d1959 100644 (file)
@@ -155,8 +155,8 @@ static void sig_init_finished(void)
 void core_init_paths(int argc, char *argv[])
 {
        static struct poptOption options[] = {
-               { "config", 0, POPT_ARG_STRING, NULL, 0, "Configuration file location (~/.irssi/config)", "PATH" },
-               { "home", 0, POPT_ARG_STRING, NULL, 0, "Irssi home dir location (~/.irssi)", "PATH" },
+               { "config", 0, POPT_ARG_STRING, NULL, 0, "Configuration file location (~/.silc/config)", "PATH" },
+               { "home", 0, POPT_ARG_STRING, NULL, 0, "Irssi home dir location (~/.silc)", "PATH" },
                { NULL, '\0', 0, NULL }
        };
        const char *home;
index 6af87a96fac464da4be0e2bff820605772ea01d4..ce6be49af5dc679eebc8d16fc1f61fd1eac3d7bd 100644 (file)
@@ -73,13 +73,15 @@ static int g_io_channel_read_block(GIOChannel *channel, void *data, int len)
 
 /* nonblocking gethostbyname(), ip (IPADDR) + error (int, 0 = not error) is
    written to pipe when found PID of the resolver child is returned */
-int net_gethostbyname_nonblock(const char *addr, GIOChannel *pipe)
+int net_gethostbyname_nonblock(const char *addr, GIOChannel *pipe,
+                              int reverse_lookup)
 {
        RESOLVED_IP_REC rec;
        const char *errorstr;
 #ifndef WIN32
        int pid;
 #endif
+       int len;
 
        g_return_val_if_fail(addr != NULL, FALSE);
 
@@ -103,6 +105,13 @@ int net_gethostbyname_nonblock(const char *addr, GIOChannel *pipe)
        rec.error = net_gethostbyname(addr, &rec.ip4, &rec.ip6);
        if (rec.error == 0) {
                errorstr = NULL;
+               if (reverse_lookup) {
+                       /* reverse lookup the IP, ignore any error */
+                       if (rec.ip4.family != 0)
+                               net_gethostbyaddr(&rec.ip4, &rec.host4);
+                       if (rec.ip6.family != 0)
+                               net_gethostbyaddr(&rec.ip6, &rec.host6);
+               }
        } else {
                errorstr = net_gethosterror(rec.error);
                rec.errlen = errorstr == NULL ? 0 : strlen(errorstr)+1;
@@ -111,6 +120,22 @@ int net_gethostbyname_nonblock(const char *addr, GIOChannel *pipe)
         g_io_channel_write_block(pipe, &rec, sizeof(rec));
        if (rec.errlen != 0)
                g_io_channel_write_block(pipe, (void *) errorstr, rec.errlen);
+       else {
+               if (rec.host4) {
+                       len = strlen(rec.host4) + 1;
+                       g_io_channel_write_block(pipe, (void *) &len, 
+                                                      sizeof(int));
+                       g_io_channel_write_block(pipe, (void *) rec.host4,
+                                                      len);
+               }
+               if (rec.host6) {
+                       len = strlen(rec.host6) + 1;
+                       g_io_channel_write_block(pipe, (void *) &len,
+                                                      sizeof(int));
+                       g_io_channel_write_block(pipe, (void *) rec.host6,
+                                                      len);
+               }
+       }
 
 #ifndef WIN32
        if (pid == 0)
@@ -124,8 +149,12 @@ int net_gethostbyname_nonblock(const char *addr, GIOChannel *pipe)
 /* get the resolved IP address */
 int net_gethostbyname_return(GIOChannel *pipe, RESOLVED_IP_REC *rec)
 {
+       int len;
+
        rec->error = -1;
        rec->errorstr = NULL;
+       rec->host4 = NULL;
+       rec->host6 = NULL;
 
 #ifndef WIN32
        fcntl(g_io_channel_unix_get_fd(pipe), F_SETFL, O_NONBLOCK);
@@ -143,6 +172,17 @@ int net_gethostbyname_return(GIOChannel *pipe, RESOLVED_IP_REC *rec)
                   reason, just ignore it. */
                rec->errorstr = g_malloc0(rec->errlen+1);
                 g_io_channel_read_block(pipe, rec->errorstr, rec->errlen);
+       } else {
+               if (rec->host4) {
+                       g_io_channel_read_block(pipe, &len, sizeof(int));
+                       rec->host4 = g_malloc0(len);
+                       g_io_channel_read_block(pipe, rec->host4, len);
+               }
+               if (rec->host6) {
+                       g_io_channel_read_block(pipe, &len, sizeof(int));
+                       rec->host6 = g_malloc0(len);
+                       g_io_channel_read_block(pipe, rec->host6, len);
+               }
        }
 
        return 0;
@@ -244,7 +284,7 @@ int net_connect_nonblock(const char *server, int port, const IPADDR *my_ip,
        rec->pipes[1] = g_io_channel_unix_new(fd[1]);
 
        /* start nonblocking host name lookup */
-       net_gethostbyname_nonblock(server, rec->pipes[1]);
+       net_gethostbyname_nonblock(server, rec->pipes[1], 0);
        rec->tag = g_input_add(rec->pipes[0], G_INPUT_READ,
                               (GInputFunction) simple_readpipe, rec);
 
index a0e5cddf24630495d753bdec269c51a4b68fc36a..32cfac702be046f29c896d7b18bbd146abf40358 100644 (file)
@@ -9,6 +9,7 @@ typedef struct {
        int errlen; /* error text length */
        char *errorstr; /* error string - dynamically allocated, you'll
                           need to free() it yourself unless it's NULL */
+       char *host4, *host6; /* dito */
 } RESOLVED_IP_REC;
 
 typedef struct {
@@ -24,7 +25,8 @@ typedef void (*NET_CALLBACK) (GIOChannel *, void *);
 typedef void (*NET_HOST_CALLBACK) (RESOLVED_NAME_REC *, void *);
 
 /* nonblocking gethostbyname(), PID of the resolver child is returned. */
-int net_gethostbyname_nonblock(const char *addr, GIOChannel *pipe);
+int net_gethostbyname_nonblock(const char *addr, GIOChannel *pipe,
+                              int reverse_lookup);
 /* Get host's name, call func when finished */
 int net_gethostbyaddr_nonblock(IPADDR *ip, NET_HOST_CALLBACK func, void *data);
 /* get the resolved IP address. returns -1 if some error occured with read() */
index 6b2ceab4c50ea3fa6ebb2b141a884656044b38a7..bb46dd54fcd9f0e5ee51aac3507f571acffb89e6 100644 (file)
@@ -468,18 +468,19 @@ int net_gethostbyaddr(IPADDR *ip, char **name)
 #ifdef HAVE_IPV6
        struct addrinfo req, *ai;
        int host_error;
+       char hostname[NI_MAXHOST];
+       char ipname[MAX_IP_LEN];
 #else
        struct hostent *hp;
 #endif
-       char ipname[MAX_IP_LEN];
 
        g_return_val_if_fail(ip != NULL, -1);
        g_return_val_if_fail(name != NULL, -1);
 
-       net_ip2host(ip, ipname);
-
        *name = NULL;
 #ifdef HAVE_IPV6
+       net_ip2host(ip, ipname);
+
        memset(&req, 0, sizeof(struct addrinfo));
        req.ai_socktype = SOCK_STREAM;
        req.ai_flags = AI_CANONNAME;
@@ -488,11 +489,19 @@ int net_gethostbyaddr(IPADDR *ip, char **name)
        host_error = getaddrinfo(ipname, NULL, &req, &ai);
        if (host_error != 0)
                return host_error;
-       *name = g_strdup(ai->ai_canonname);
+        host_error = getnameinfo(ai->ai_addr, ai->ai_addrlen,
+                                 hostname, NI_MAXHOST, NULL, 0, 0);
+        if (host_error != 0) {
+                freeaddrinfo(ai);
+                return host_error;
+        }
+
+       *name = g_strdup(hostname);
 
        freeaddrinfo(ai);
 #else
-       hp = gethostbyaddr(ipname, strlen(ipname), AF_INET);
+       if (ip->family != AF_INET) return -1;
+       hp = gethostbyaddr(&ip->ip, 4, AF_INET);
        if (hp == NULL) return -1;
 
        *name = g_strdup(hp->h_name);
index 92a6e5ac7b3c65d2b5ab3e20b865ca6d31124cf4..f9ab791aabb1f6e1666c1584aa1dcf47dc5d2691 100644 (file)
@@ -213,6 +213,7 @@ static void server_connect_callback_readpipe(SERVER_REC *server)
        RESOLVED_IP_REC iprec;
         IPADDR *ip;
        const char *errormsg;
+       char *servername = NULL;
 
        g_source_remove(server->connect_tag);
        server->connect_tag = -1;
@@ -234,20 +235,31 @@ static void server_connect_callback_readpipe(SERVER_REC *server)
        } else if (server->connrec->family == AF_INET) {
                /* force IPv4 connection */
                ip = iprec.ip4.family == 0 ? NULL : &iprec.ip4;
+               servername = iprec.host4;
        } else if (server->connrec->family == AF_INET6) {
                /* force IPv6 connection */
                ip = iprec.ip6.family == 0 ? NULL : &iprec.ip6;
+               servername = iprec.host6;
        } else {
                /* pick the one that was found, or if both do it like
                   /SET resolve_prefer_ipv6 says. */
-               ip = iprec.ip4.family == 0 ||
-                       (iprec.ip6.family != 0 &&
-                        settings_get_bool("resolve_prefer_ipv6")) ?
-                       &iprec.ip6 : &iprec.ip4;
+               if (iprec.ip4.family == 0 ||
+                   (iprec.ip6.family != 0 &&
+                    settings_get_bool("resolve_prefer_ipv6"))) {
+                       ip = &iprec.ip6;
+                       servername = iprec.host6;
+               } else {
+                       ip = &iprec.ip4;
+                       servername = iprec.host4;
+               }
        }
 
        if (ip != NULL) {
                /* host lookup ok */
+               if (servername) {
+                       g_free(server->connrec->address);
+                       server->connrec->address = g_strdup(servername);
+               }
                server_real_connect(server, ip, NULL);
                errormsg = NULL;
        } else {
@@ -273,6 +285,8 @@ static void server_connect_callback_readpipe(SERVER_REC *server)
        }
 
        g_free(iprec.errorstr);
+       g_free(iprec.host4);
+       g_free(iprec.host6);
 }
 
 SERVER_REC *server_connect(SERVER_CONNECT_REC *conn)
@@ -356,7 +370,8 @@ int server_start_connect(SERVER_REC *server)
                        server->connrec->proxy : server->connrec->address;
                server->connect_pid =
                        net_gethostbyname_nonblock(connect_address,
-                                                  server->connect_pipe[1]);
+                                                  server->connect_pipe[1],
+                                                  settings_get_bool("resolve_reverse_lookup"));
                server->connect_tag =
                        g_input_add(server->connect_pipe[0], G_INPUT_READ,
                                    (GInputFunction)
@@ -666,6 +681,7 @@ static void sig_chat_protocol_deinit(CHAT_PROTOCOL_REC *proto)
 void servers_init(void)
 {
        settings_add_bool("server", "resolve_prefer_ipv6", FALSE);
+       settings_add_bool("server", "resolve_reverse_lookup", FALSE);
        lookup_servers = servers = NULL;
 
        signal_add("chat protocol deinit", (SIGNAL_FUNC) sig_chat_protocol_deinit);
index 004cd4f737022110f4f837ce969d44cded2913cb..7ebd8f82b956ef60a21bd2eab624d4b42787c1ac 100644 (file)
@@ -357,7 +357,7 @@ void session_init(void)
         session_file = NULL;
        args_register(options);
 
-       command_bind("upgrade", NULL, (SIGNAL_FUNC) cmd_upgrade);
+       /*command_bind("upgrade", NULL, (SIGNAL_FUNC) cmd_upgrade);*/
 
        signal_add("session save", (SIGNAL_FUNC) sig_session_save);
        signal_add("session restore", (SIGNAL_FUNC) sig_session_restore);
@@ -372,7 +372,7 @@ void session_deinit(void)
 {
        g_free_not_null(irssi_binary);
 
-        command_unbind("upgrade", (SIGNAL_FUNC) cmd_upgrade);
+        /*command_unbind("upgrade", (SIGNAL_FUNC) cmd_upgrade);*/
 
        signal_remove("session save", (SIGNAL_FUNC) sig_session_save);
        signal_remove("session restore", (SIGNAL_FUNC) sig_session_restore);
index e210c2a2d156101e53adc30dee660797419e33f5..31bbbfad056125c3ccee7b1dd7844af09ecbd423 100644 (file)
@@ -39,7 +39,7 @@
 
 #define ishighalnum(c) ((unsigned char) (c) >= 128 || i_isalnum(c))
 
-static GHashTable *printnicks;
+GHashTable *printnicks;
 
 /* convert _underlined_ and *bold* words (and phrases) to use real
    underlining or bolding */
index afe7644df8bbf2a020795064722303d53d1cbab6..07ecef80824830c1dfc6d40bb5d53d7a60759139 100644 (file)
@@ -7,4 +7,6 @@ char *expand_emphasis(WI_ITEM_REC *item, const char *text);
 
 char *channel_get_nickmode(CHANNEL_REC *channel, const char *nick);
 
+extern GHashTable *printnicks;
+
 #endif
index baa1d3e599d112d554dee9dfbf571801d6b8efb2..437b118faeccf36a8a08eb1b6823c39164ecec22 100644 (file)
@@ -301,12 +301,51 @@ static int data_is_empty(const char **data)
         return FALSE;
 }
 
+/* return "data" from {abstract data} string */
+char *theme_format_expand_get(THEME_REC *theme, const char **format)
+{
+       GString *str;
+       char *ret, dummy;
+       int braces = 1; /* we start with one brace opened */
+
+       str = g_string_new(NULL);
+       while ((**format != '\0') && (braces)) {
+               if (**format == '{')
+                       braces++;
+               else if (**format == '}')
+                       braces--;
+               else if ((braces > 1) && (**format == ' ')) {
+                       g_string_append(str, "\\x20");
+                       (*format)++;
+                       continue;
+               } else {
+                       theme_format_append_next(theme, str, format,
+                                                'n', 'n',
+                                                &dummy, &dummy, 0);
+                       continue;
+               }
+               
+               if (!braces) {
+                       (*format)++;
+                       break;
+               }
+
+               g_string_append_c(str, **format);
+               (*format)++;
+       }
+
+       ret = str->str;
+        g_string_free(str, FALSE);
+        return ret;
+}
+
 /* expand a single {abstract ...data... } */
 static char *theme_format_expand_abstract(THEME_REC *theme,
                                          const char **formatp,
                                          char default_fg, char default_bg,
                                          int flags)
 {
+       GString *str;
        const char *p, *format;
        char *abstract, *data, *ret;
        int len;
@@ -345,9 +384,8 @@ static char *theme_format_expand_abstract(THEME_REC *theme,
        abstract = g_strdup(data);
 
        /* we'll need to get the data part. it may contain
-          more abstracts, they are automatically expanded. */
-       data = theme_format_expand_data(theme, formatp, default_fg, default_bg,
-                                       NULL, NULL, flags);
+          more abstracts, they are _NOT_ expanded. */
+       data = theme_format_expand_get(theme, formatp);
        len = strlen(data);
 
        if (len > 1 && i_isdigit(data[len-1]) && data[len-2] == '$') {
@@ -367,7 +405,21 @@ static char *theme_format_expand_abstract(THEME_REC *theme,
                                   PARSE_FLAG_ONLY_ARGS);
        g_free(abstract);
         g_free(data);
-       abstract = ret;
+       str = g_string_new(NULL);
+       p = ret;
+       while (*p != '\0') {
+               if (*p == '\\') {
+                       int chr;
+                       p++;
+                       chr = expand_escape(&p);
+                       g_string_append_c(str, chr != -1 ? chr : *p);
+               } else
+                       g_string_append_c(str, *p);
+               p++;
+       }
+       g_free(ret);
+       abstract = str->str;
+       g_string_free(str, FALSE);
 
        /* abstract may itself contain abstracts or replaces */
        p = abstract;
index 72abc05ef880c6de8aaf73f42bba61c0d8802e64..1a89f348df3e661239671ec37969380e6dc0e8cd 100644 (file)
@@ -27,7 +27,8 @@ libfe_common_silc_a_SOURCES = \
        fe-channels.c \
        fe-common-silc.c \
        module-formats.c \
-       silc-modules.c 
+       silc-modules.c \
+       fe-messages.c
 
 noinst_HEADERS = \
        module-formats.h \
index e1912d5c91b2d0272aa8d6e2fb017094ee8b2c04..51047a005396ddf52936115d787c034e88d34a7f 100644 (file)
@@ -30,18 +30,23 @@ void fe_silc_channels_deinit(void);
 void fe_silc_modules_init(void);
 void fe_silc_modules_deinit(void);
 
+void fe_silc_messages_init(void);
+void fe_silc_messages_deinit(void);
+
 void fe_silc_init(void)
 {
   theme_register(fecommon_silc_formats);
 
   fe_silc_channels_init();
   fe_silc_modules_init();
+  fe_silc_messages_init();
 
   module_register("silc", "fe");
 }
 
 void fe_silc_deinit(void)
 {
+  fe_silc_messages_deinit();
   fe_silc_modules_deinit();
   fe_silc_channels_deinit();
 
diff --git a/apps/irssi/src/fe-common/silc/fe-messages.c b/apps/irssi/src/fe-common/silc/fe-messages.c
new file mode 100644 (file)
index 0000000..41e0514
--- /dev/null
@@ -0,0 +1,248 @@
+/*
+
+  fe-messages.c
+
+  Author: Jochen Eisinger <c0ffee@penguin-breeder.org>
+
+  Copyright (C) 2002 Jochen Eisinger
+
+  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
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+  
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+*/
+
+#include "module.h"
+#include "modules.h"
+#include "signals.h"
+#include "themes.h"
+#include "levels.h"
+#include "misc.h"
+#include "special-vars.h"
+#include "settings.h"
+
+#include "servers.h"
+#include "channels.h"
+#include "nicklist.h"
+#include "ignore.h"
+
+#include "window-items.h"
+#include "fe-queries.h"
+#include "fe-messages.h"
+#include "hilight-text.h"
+#include "printtext.h"
+#include "module-formats.h"
+
+#define VERIFIED_MSG(v,msg) (v == SILC_MSG_SIGNED_VERIFIED ? \
+                               msg##_SIGNED : (v == SILC_MSG_SIGNED_UNKNOWN ? \
+                               msg##_UNKNOWN : msg##_FAILED))
+
+static void sig_signed_message_public(SERVER_REC * server, const char *msg,
+                                     const char *nick,
+                                     const char *address,
+                                     const char *target,
+                                     int verified)
+{
+  CHANNEL_REC *chanrec;
+  NICK_REC *nickrec = NULL; /* we cheat here a little to keep the limit of 
+                              6 parameters to a signal handler ... */
+  const char *nickmode, *printnick;
+  int for_me, print_channel, level;
+  char *color, *freemsg = NULL;
+
+  /* NOTE: this may return NULL if some channel is just closed with
+     /WINDOW CLOSE and server still sends the few last messages */
+  chanrec = channel_find(server, target);
+  if (nickrec == NULL && chanrec != NULL)
+    nickrec = nicklist_find(chanrec, nick);
+
+  for_me = !settings_get_bool("hilight_nick_matches") ? FALSE :
+      nick_match_msg(chanrec, msg, server->nick);
+  color = for_me ? NULL :
+      hilight_match_nick(server, target, nick, address, MSGLEVEL_PUBLIC,
+                        msg);
+
+  print_channel = chanrec == NULL ||
+      !window_item_is_active((WI_ITEM_REC *) chanrec);
+  if (!print_channel && settings_get_bool("print_active_channel") &&
+      window_item_window((WI_ITEM_REC *) chanrec)->items->next != NULL)
+    print_channel = TRUE;
+
+  level = MSGLEVEL_PUBLIC;
+  if (for_me || color != NULL)
+    level |= MSGLEVEL_HILIGHT;
+
+  if (settings_get_bool("emphasis"))
+    msg = freemsg = expand_emphasis((WI_ITEM_REC *) chanrec, msg);
+
+  /* get nick mode & nick what to print the msg with
+     (in case there's multiple identical nicks) */
+  nickmode = channel_get_nickmode(chanrec, nick);
+  printnick = nickrec == NULL ? nick :
+      g_hash_table_lookup(printnicks, nickrec);
+  if (printnick == NULL)
+    printnick = nick;
+
+  if (!print_channel) {
+    /* message to active channel in window */
+    if (color != NULL) {
+      /* highlighted nick */
+      printformat_module("fe-common/silc", server, target,
+                        level, VERIFIED_MSG(verified, SILCTXT_PUBMSG_HILIGHT),
+                        color, printnick, msg, nickmode);
+    } else {
+      printformat_module("fe-common/silc", server, target, level,
+                        for_me ? VERIFIED_MSG(verified, SILCTXT_PUBMSG_ME) :
+                                 VERIFIED_MSG(verified,SILCTXT_PUBMSG),
+                        printnick, msg, nickmode);
+    }
+  } else {
+    /* message to not existing/active channel */
+    if (color != NULL) {
+      /* highlighted nick */
+      printformat_module("fe-common/silc", server, target, level,
+                        VERIFIED_MSG(verified, SILCTXT_PUBMSG_HILIGHT_CHANNEL),
+                        color, printnick, target, msg, nickmode);
+    } else {
+      printformat_module("fe-common/silc", server, target, level,
+                        for_me ? VERIFIED_MSG(verified, SILCTXT_PUBMSG_ME_CHANNEL) :
+                        VERIFIED_MSG(verified, SILCTXT_PUBMSG_CHANNEL),
+                        printnick, target, msg, nickmode);
+    }
+  }
+
+  g_free_not_null(freemsg);
+  g_free_not_null(color);
+}
+
+static void sig_signed_message_private(SERVER_REC * server,
+                                      const char *msg, const char *nick,
+                                      const char *address, int verified)
+{
+  QUERY_REC *query;
+  char *freemsg = NULL;
+
+  query = query_find(server, nick);
+
+  if (settings_get_bool("emphasis"))
+    msg = freemsg = expand_emphasis((WI_ITEM_REC *) query, msg);
+
+  printformat_module("fe-common/silc", server, nick, MSGLEVEL_MSGS,
+                    query == NULL ? VERIFIED_MSG(verified, SILCTXT_MSG_PRIVATE) :
+                    VERIFIED_MSG(verified, SILCTXT_MSG_PRIVATE_QUERY), nick, address, msg);
+
+  g_free_not_null(freemsg);
+}
+
+static void sig_signed_message_own_public(SERVER_REC * server,
+                                         const char *msg,
+                                         const char *target)
+{
+  WINDOW_REC *window;
+  CHANNEL_REC *channel;
+  const char *nickmode;
+  char *freemsg = NULL;
+  int print_channel;
+
+  channel = channel_find(server, target);
+  if (channel != NULL)
+    target = channel->visible_name;
+
+  nickmode = channel_get_nickmode(channel, server->nick);
+
+  window = channel == NULL ? NULL :
+      window_item_window((WI_ITEM_REC *) channel);
+
+  print_channel = window == NULL ||
+      window->active != (WI_ITEM_REC *) channel;
+
+  if (!print_channel && settings_get_bool("print_active_channel") &&
+      window != NULL && g_slist_length(window->items) > 1)
+    print_channel = TRUE;
+
+  if (settings_get_bool("emphasis"))
+    msg = freemsg = expand_emphasis((WI_ITEM_REC *) channel, msg);
+
+  if (!print_channel) {
+    printformat_module("fe-common/silc", server, target,
+                      MSGLEVEL_PUBLIC | MSGLEVEL_NOHILIGHT |
+                      MSGLEVEL_NO_ACT, SILCTXT_OWN_MSG_SIGNED, server->nick, msg,
+                      nickmode);
+  } else {
+    printformat_module("fe-common/silc", server, target,
+                      MSGLEVEL_PUBLIC | MSGLEVEL_NOHILIGHT |
+                      MSGLEVEL_NO_ACT, SILCTXT_OWN_MSG_CHANNEL_SIGNED,
+                      server->nick, target, msg, nickmode);
+  }
+
+  g_free_not_null(freemsg);
+}
+
+static void sig_signed_message_own_private(SERVER_REC * server,
+                                          const char *msg,
+                                          const char *target,
+                                          const char *origtarget)
+{
+  QUERY_REC *query;
+  char *freemsg = NULL;
+
+  g_return_if_fail(server != NULL);
+  g_return_if_fail(msg != NULL);
+
+  if (target == NULL) {
+    /* this should only happen if some special target failed and
+       we should display some error message. currently the special
+       targets are only ',' and '.'. */
+    g_return_if_fail(strcmp(origtarget, ",") == 0 ||
+                    strcmp(origtarget, ".") == 0);
+
+    printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CLIENTNOTICE,
+                      *origtarget == ',' ? SILCTXT_NO_MSGS_GOT :
+                      SILCTXT_NO_MSGS_SENT);
+    signal_stop();
+    return;
+  }
+
+  query = privmsg_get_query(server, target, TRUE, MSGLEVEL_MSGS);
+
+  if (settings_get_bool("emphasis"))
+    msg = freemsg = expand_emphasis((WI_ITEM_REC *) query, msg);
+
+  printformat_module("fe-common/silc", server, target,
+                    MSGLEVEL_MSGS | MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT,
+                    query == NULL ? SILCTXT_OWN_MSG_PRIVATE_SIGNED :
+                    SILCTXT_OWN_MSG_PRIVATE_QUERY_SIGNED, target, msg,
+                    server->nick);
+
+  g_free_not_null(freemsg);
+}
+
+void fe_silc_messages_init(void)
+{
+  signal_add_last("message signed_public",
+                 (SIGNAL_FUNC) sig_signed_message_public);
+  signal_add_last("message signed_private",
+                 (SIGNAL_FUNC) sig_signed_message_private);
+  signal_add_last("message signed_own_public",
+                 (SIGNAL_FUNC) sig_signed_message_own_public);
+  signal_add_last("message signed_own_private",
+                 (SIGNAL_FUNC) sig_signed_message_own_private);
+}
+
+void fe_silc_messages_deinit(void)
+{
+  signal_remove("message signed_public",
+               (SIGNAL_FUNC) sig_signed_message_public);
+  signal_remove("message signed_private",
+               (SIGNAL_FUNC) sig_signed_message_private);
+  signal_remove("message signed_own_public",
+               (SIGNAL_FUNC) sig_signed_message_own_public);
+  signal_remove("message signed_own_private",
+               (SIGNAL_FUNC) sig_signed_message_own_private);
+}
index 050f4e6c3328008c7653f5af291860f217de6a6d..09440ca5c9c5c4606944c3566f705fe22c73785f 100644 (file)
@@ -50,6 +50,36 @@ FORMAT_REC fecommon_silc_formats[] = {
        { "killed", "{nick $0} has been killed from the SILC Network by {nick $1} ($2)", 3, { 0, 0, 0 } },
        { "quieted", "You have been queited and cannot talk on {channel $0}", 1, { 0 } },
        { "appears", "{channick $0} now appears as {channick_hilight $1}", 4, { 0, 0, 0, 0 } },
+       { "pubmsg_hilight_signed", "{pubmsghinick_signed $0 $3 $1}$2", 4, { 0, 0, 0, 0 } },
+       { "pubmsg_hilight_unknown", "{pubmsghinick_unknown $0 $3 $1}$2", 4, { 0, 0, 0, 0 } },
+       { "pubmsg_hilight_failed", "{pubmsghinick_failed $0 $3 $1}$2", 4, { 0, 0, 0, 0 } },
+       { "pubmsg_me_signed", "{pubmsgmenick_signed $2 {menick $0}}$1", 3, { 0, 0, 0 } },
+       { "pubmsg_me_unknown", "{pubmsgmenick_unknown $2 {menick $0}}$1", 3, { 0, 0, 0 } },
+       { "pubmsg_me_failed", "{pubmsgmenick_failed $2 {menick $0}}$1", 3, { 0, 0, 0 } },
+       { "pubmsg_signed", "{pubmsgnick_signed $2 {pubnick $0}}$1", 3, { 0, 0, 0 } },
+       { "pubmsg_unknown", "{pubmsgnick_unknown $2 {pubnick $0}}$1", 3, { 0, 0, 0 } },
+       { "pubmsg_failed", "{pubmsgnick_failed $2 {pubnick $0}}$1", 3, { 0, 0, 0 } },
+       { "pubmsg_hilight_channel_signed", "{pubmsghinick_signed $0 $4 $1{msgchannel $2}}$3", 5, { 0, 0, 0, 0, 0 } },
+       { "pubmsg_hilight_channel_unknown", "{pubmsghinick_unknown $0 $4 $1{msgchannel $2}}$3", 5, { 0, 0, 0, 0, 0 } },
+       { "pubmsg_hilight_channel_failed", "{pubmsghinick_failed $0 $4 $1{msgchannel $2}}$3", 5, { 0, 0, 0, 0, 0 } },
+       { "pubmsg_me_channel_signed", "{pubmsgmenick_signed $3 {menick $0}{msgchannel $1}}$2", 4, { 0, 0, 0, 0 } },
+       { "pubmsg_me_channel_unknown", "{pubmsgmenick_unknown $3 {menick $0}{msgchannel $1}}$2", 4, { 0, 0, 0, 0 } },
+       { "pubmsg_me_channel_failed", "{pubmsgmenick_failed $3 {menick $0}{msgchannel $1}}$2", 4, { 0, 0, 0, 0 } },
+       { "pubmsg_channel_signed", "{pubmsgnick_signed $3 {pubnick $0}{msgchannel $1}}$2", 4, { 0, 0, 0, 0 } },
+       { "pubmsg_channel_unknown", "{pubmsgnick_unknown $3 {pubnick $0}{msgchannel $1}}$2", 4, { 0, 0, 0, 0 } },
+       { "pubmsg_channel_failed", "{pubmsgnick_failed $3 {pubnick $0}{msgchannel $1}}$2", 4, { 0, 0, 0, 0 } },
+       { "msg_private_signed", "{privmsg_signed $0 $1}$2", 3, { 0, 0, 0 } },
+       { "msg_private_unknown", "{privmsg_unknown $0 $1}$2", 3, { 0, 0, 0 } },
+       { "msg_private_failed", "{privmsg_failed $0 $1}$2", 3, { 0, 0, 0 } },
+       { "msg_private_query_signed", "{privmsgnick_signed $0}$2", 3, { 0, 0, 0 } },
+       { "msg_private_query_unknown", "{privmsgnick_unknown $0}$2", 3, { 0, 0, 0 } },
+       { "msg_private_query_failed", "{privmsgnick_failed $0}$2", 3, { 0, 0, 0 } },
+       { "own_msg_signed", "{ownmsgnick_signed $2 {ownnick $0}}$1", 3, { 0, 0, 0 } },
+       { "own_msg_channel_signed", "{ownmsgnick_signed $3 {ownnick $0}{msgchannel $1}}$2", 4, { 0, 0, 0, 0 } },
+       { "no_msgs_got", "You have not received a message from anyone yet", 0 },
+       { "no_msgs_sent", "You have not sent a message to anyone yet", 0 },
+       { "own_msg_private_signed", "{ownprivmsg_signed msg $0}$1", 2, { 0, 0 } },
+       { "own_msg_private_query_signed", "{ownprivmsgnick_signed {ownprivnick $2}}$1", 3, { 0, 0, 0 } },
 
        /* WHOIS, WHOWAS and USERS (alias WHO) messages */
        { NULL, "Who Queries", 0 },
index 27c92de0ea31c77028cc75fb4facb1f3ce425248..7df09206b9ec5be9a67ed4a584c2eb715e912e71 100644 (file)
@@ -47,6 +47,36 @@ enum {
   SILCTXT_CHANNEL_KILLED,
   SILCTXT_CHANNEL_QUIETED,
   SILCTXT_CHANNEL_APPEARS,
+  SILCTXT_PUBMSG_HILIGHT_SIGNED,
+  SILCTXT_PUBMSG_HILIGHT_UNKNOWN,
+  SILCTXT_PUBMSG_HILIGHT_FAILED,
+  SILCTXT_PUBMSG_ME_SIGNED,
+  SILCTXT_PUBMSG_ME_UNKNOWN,
+  SILCTXT_PUBMSG_ME_FAILED,
+  SILCTXT_PUBMSG_SIGNED,
+  SILCTXT_PUBMSG_UNKNOWN,
+  SILCTXT_PUBMSG_FAILED,
+  SILCTXT_PUBMSG_HILIGHT_CHANNEL_SIGNED,
+  SILCTXT_PUBMSG_HILIGHT_CHANNEL_UNKNOWN,
+  SILCTXT_PUBMSG_HILIGHT_CHANNEL_FAILED,
+  SILCTXT_PUBMSG_ME_CHANNEL_SIGNED,
+  SILCTXT_PUBMSG_ME_CHANNEL_UNKNOWN,
+  SILCTXT_PUBMSG_ME_CHANNEL_FAILED,
+  SILCTXT_PUBMSG_CHANNEL_SIGNED,
+  SILCTXT_PUBMSG_CHANNEL_UNKNOWN,
+  SILCTXT_PUBMSG_CHANNEL_FAILED,
+  SILCTXT_MSG_PRIVATE_SIGNED,
+  SILCTXT_MSG_PRIVATE_UNKNOWN,
+  SILCTXT_MSG_PRIVATE_FAILED,
+  SILCTXT_MSG_PRIVATE_QUERY_SIGNED,
+  SILCTXT_MSG_PRIVATE_QUERY_UNKNOWN,
+  SILCTXT_MSG_PRIVATE_QUERY_FAILED,
+  SILCTXT_OWN_MSG_SIGNED,
+  SILCTXT_OWN_MSG_CHANNEL_SIGNED,
+  SILCTXT_NO_MSGS_GOT,
+  SILCTXT_NO_MSGS_SENT,
+  SILCTXT_OWN_MSG_PRIVATE_SIGNED,
+  SILCTXT_OWN_MSG_PRIVATE_QUERY_SIGNED,
 
   SILCTXT_FILL_2,
 
index d1d51c46de88483dc528fb4b05e92c4f13fffbe8..02cb3dd807e0caf2caa86bce895c2a587aeb6270 100644 (file)
@@ -19,12 +19,12 @@ silc_DEPENDENCIES =                 \
 LIBS = $(SILC_COMMON_LIBS)
 silc_LDADD = \
        @COMMON_LIBS@ \
+       -L../../../lib -lsilcclient \
        @PERL_LINK_LIBS@ \
        @PERL_FE_LINK_LIBS@ \
        @PERL_LINK_FLAGS@ \
        @PROG_LIBS@     \
-       @TEXTUI_LIBS@   \
-       -L../../../lib -lsilcclient
+       @TEXTUI_LIBS@
 silc_LDFLAGS = -export-dynamic
 
 tparm_sources = \
index 78f0781a337cf1e0ca37c70ed957ff82f03d1d89..b55b0d31a7c859a9aa96d21fb73d0cdce191311c 100644 (file)
@@ -153,17 +153,107 @@ void silc_say_error(char *msg, ...)
   va_end(va);
 }
 
+/* try to verify a message using locally stored public key data */
+int verify_message_signature(SilcClientEntry sender,
+                            SilcMessageSignedPayload sig,
+                            SilcMessagePayload message)
+{
+  SilcPublicKey pk;
+  char file[256], filename[256];
+  char *fingerprint, *fingerprint2;
+  unsigned char *pk_data;
+  SilcUInt32 pk_datalen;
+  struct stat st;
+  int ret = SILC_MSG_SIGNED_VERIFIED, i;
+
+  if (sig == NULL)
+    return SILC_MSG_SIGNED_UNKNOWN;
+
+  /* get public key from the signature payload and compare it with the
+     one stored in the client entry */
+  pk = silc_message_signed_get_public_key(sig, &pk_data, &pk_datalen);
+
+  if (pk != NULL) {
+    fingerprint = silc_hash_fingerprint(NULL, pk_data, pk_datalen);
+
+    if (sender->fingerprint) {
+      fingerprint2 = silc_fingerprint(sender->fingerprint,
+                                     sender->fingerprint_len);
+      if (strcmp(fingerprint, fingerprint2)) {
+        /* since the public key differs from the senders public key, the
+           verification _failed_ */
+        silc_pkcs_public_key_free(pk);
+        silc_free(fingerprint);
+        ret = SILC_MSG_SIGNED_UNKNOWN;
+      }
+      silc_free(fingerprint2);
+    }
+  } else if (sender->fingerprint)
+    fingerprint = silc_fingerprint(sender->fingerprint,
+                                  sender->fingerprint_len);
+  else
+    /* no idea, who or what signed that message ... */
+    return SILC_MSG_SIGNED_UNKNOWN;
+  
+  /* search our local client key cache */
+  for (i = 0; i < strlen(fingerprint); i++)
+    if (fingerprint[i] == ' ')
+      fingerprint[i] = '_';
+    
+  snprintf(file, sizeof(file) - 1, "clientkey_%s.pub", fingerprint);
+  snprintf(filename, sizeof(filename) - 1, "%s/clientkeys/%s", 
+          get_irssi_dir(), file);
+  silc_free(fingerprint);
+  
+  if (stat(filename, &st) < 0)
+    /* we don't have the public key cached ... use the one from the sig */
+    ret = SILC_MSG_SIGNED_UNKNOWN;
+  else {
+    SilcPublicKey cached_pk=NULL;
+
+    /* try to load the file */
+    if (!silc_pkcs_load_public_key(filename, &cached_pk, SILC_PKCS_FILE_PEM) &&
+       !silc_pkcs_load_public_key(filename, &cached_pk, 
+                                  SILC_PKCS_FILE_BIN)) {
+      printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP, 
+                        SILCTXT_PUBKEY_COULD_NOT_LOAD, "client");
+      if (pk == NULL)
+       return SILC_MSG_SIGNED_UNKNOWN;
+      else
+       ret = SILC_MSG_SIGNED_UNKNOWN;
+    }
+
+    if (cached_pk) {
+      if (pk)
+        silc_pkcs_public_key_free(pk);
+      pk = cached_pk; 
+    }
+  }
+
+  /* the public key is now in pk, our "level of trust" in ret */
+  if ((pk) && silc_message_signed_verify(sig, message, pk, 
+                                        silc_client->sha1hash)!= SILC_AUTH_OK)
+    ret = SILC_MSG_SIGNED_FAILED;
+
+  if (pk)
+    silc_pkcs_public_key_free(pk);
+
+  return ret;
+}
+
 /* Message for a channel. The `sender' is the nickname of the sender 
    received in the packet. The `channel_name' is the name of the channel. */
 
 void silc_channel_message(SilcClient client, SilcClientConnection conn,
                          SilcClientEntry sender, SilcChannelEntry channel,
+                         SilcMessagePayload payload,
                          SilcMessageFlags flags, const unsigned char *message,
                          SilcUInt32 message_len)
 {
   SILC_SERVER_REC *server;
   SILC_NICK_REC *nick;
   SILC_CHANNEL_REC *chanrec;
+  int verified = 0;
   
   SILC_LOG_DEBUG(("Start"));
 
@@ -183,6 +273,16 @@ void silc_channel_message(SilcClient client, SilcClientConnection conn,
       nick = silc_nicklist_insert(chanrec, chu, FALSE);
   }
 
+  /* If the messages is digitally signed, verify it, if possible. */
+  if (flags & SILC_MESSAGE_FLAG_SIGNED) {
+    if (!settings_get_bool("ignore_message_signatures")) {
+      SilcMessageSignedPayload sig = silc_message_get_signature(payload);
+      verified = verify_message_signature(sender, sig, payload);
+    } else {
+      flags &= ~SILC_MESSAGE_FLAG_SIGNED;
+    }
+  }
+  
   if (flags & SILC_MESSAGE_FLAG_DATA) {
     /* MIME object received, try to display it as well as we can */
     char type[128], enc[128];
@@ -211,6 +311,8 @@ void silc_channel_message(SilcClient client, SilcClientConnection conn,
   if (!message)
     return;
 
+  /* FIXME: replace those printformat calls with signals and add signature
+            information to them (if present) */
   if (flags & SILC_MESSAGE_FLAG_ACTION)
     printformat_module("fe-common/silc", server, channel->channel_name,
                       MSGLEVEL_ACTIONS, SILCTXT_CHANNEL_ACTION, 
@@ -232,18 +334,30 @@ void silc_channel_message(SilcClient client, SilcClientConnection conn,
 
       silc_utf8_decode(message, message_len, SILC_STRING_LANGUAGE,
                       cp, message_len);
-      signal_emit("message public", 6, server, cp,
-                 nick == NULL ? "[<unknown>]" : nick->nick,
-                 nick == NULL ? "" : nick->host == NULL ? "" : nick->host,
-                 chanrec->name, nick);
+      if (flags & SILC_MESSAGE_FLAG_SIGNED)
+        signal_emit("message signed_public", 6, server, cp,
+                   nick == NULL ? "[<unknown>]" : nick->nick,
+                   nick == NULL ? "" : nick->host == NULL ? "" : nick->host,
+                   chanrec->name, verified);
+      else
+        signal_emit("message public", 6, server, cp,
+                   nick == NULL ? "[<unknown>]" : nick->nick,
+                   nick == NULL ? "" : nick->host == NULL ? "" : nick->host,
+                   chanrec->name, nick);
       silc_free(dm);
       return;
     }
 
-    signal_emit("message public", 6, server, message,
-               nick == NULL ? "[<unknown>]" : nick->nick,
-               nick == NULL ? "" : nick->host == NULL ? "" : nick->host,
-               chanrec->name, nick);
+    if (flags & SILC_MESSAGE_FLAG_SIGNED)
+      signal_emit("message signed_public", 6, server, message,
+                 nick == NULL ? "[<unknown>]" : nick->nick,
+                 nick == NULL ? "" : nick->host == NULL ? "" : nick->host,
+                 chanrec->name, verified);
+    else
+      signal_emit("message public", 6, server, message,
+                 nick == NULL ? "[<unknown>]" : nick->nick,
+                 nick == NULL ? "" : nick->host == NULL ? "" : nick->host,
+                 chanrec->name, nick);
   }
 }
 
@@ -251,12 +365,14 @@ void silc_channel_message(SilcClient client, SilcClientConnection conn,
    sender received in the packet. */
 
 void silc_private_message(SilcClient client, SilcClientConnection conn,
-                         SilcClientEntry sender, SilcMessageFlags flags,
+                         SilcClientEntry sender, SilcMessagePayload payload,
+                         SilcMessageFlags flags,
                          const unsigned char *message,
                          SilcUInt32 message_len)
 {
   SILC_SERVER_REC *server;
   char userhost[256];
+  int verified = 0;
   
   SILC_LOG_DEBUG(("Start"));
 
@@ -266,6 +382,16 @@ void silc_private_message(SilcClient client, SilcClientConnection conn,
     snprintf(userhost, sizeof(userhost) - 1, "%s@%s",
             sender->username, sender->hostname);
 
+  /* If the messages is digitally signed, verify it, if possible. */
+  if (flags & SILC_MESSAGE_FLAG_SIGNED) {
+    if (!settings_get_bool("ignore_message_signatures")) {
+      SilcMessageSignedPayload sig = silc_message_get_signature(payload);
+      verified = verify_message_signature(sender, sig, payload);
+    } else {
+      flags &= ~SILC_MESSAGE_FLAG_SIGNED;
+    }
+  }
+  
   if (flags & SILC_MESSAGE_FLAG_DATA) {
     /* MIME object received, try to display it as well as we can */
     char type[128], enc[128];
@@ -307,16 +433,26 @@ void silc_private_message(SilcClient client, SilcClientConnection conn,
 
     silc_utf8_decode(message, message_len, SILC_STRING_LANGUAGE,
                     cp, message_len);
-    signal_emit("message private", 4, server, cp,
-               sender->nickname ? sender->nickname : "[<unknown>]",
-               sender->username ? userhost : NULL);
+    if (flags & SILC_MESSAGE_FLAG_SIGNED)
+      signal_emit("message signed_private", 5, server, cp,
+                 sender->nickname ? sender->nickname : "[<unknown>]",
+                 sender->username ? userhost : NULL, verified);
+    else
+      signal_emit("message private", 4, server, cp,
+                 sender->nickname ? sender->nickname : "[<unknown>]",
+                 sender->username ? userhost : NULL);
     silc_free(dm);
     return;
   }
 
-  signal_emit("message private", 4, server, message,
-             sender->nickname ? sender->nickname : "[<unknown>]",
-             sender->username ? userhost : NULL);
+  if (flags & SILC_MESSAGE_FLAG_SIGNED)
+    signal_emit("message signed_private", 5, server, message,
+               sender->nickname ? sender->nickname : "[<unknown>]",
+               sender->username ? userhost : NULL, verified);
+  else
+    signal_emit("message private", 4, server, message,
+               sender->nickname ? sender->nickname : "[<unknown>]",
+               sender->username ? userhost : NULL);
 }
 
 /* Notify message to the client. The notify arguments are sent in the
@@ -422,9 +558,9 @@ void silc_notify(SilcClient client, SilcClientConnection conn,
       snprintf(buf, sizeof(buf) - 1, "%s@%s",
               client_entry->username, client_entry->hostname);
     signal_emit("message part", 5, server, channel->channel_name,
-               client_entry->nickname,  client_entry->username ? 
+               client_entry->nickname,  client_entry->username ? 
                buf : "", client_entry->nickname);
-    
+
     chanrec = silc_channel_find_entry(server, channel);
     if (chanrec != NULL) {
       nickrec = silc_nicklist_find(chanrec, client_entry);
@@ -444,15 +580,20 @@ void silc_notify(SilcClient client, SilcClientConnection conn,
     tmp = va_arg(va, char *);
     
     silc_server_free_ftp(server, client_entry);
-    
-    memset(buf, 0, sizeof(buf));
-    if (client_entry->username)
-      snprintf(buf, sizeof(buf) - 1, "%s@%s",
-              client_entry->username, client_entry->hostname);
-    signal_emit("message quit", 4, server, client_entry->nickname,
-               client_entry->username ? buf : "", 
-               tmp ? tmp : "");
-    
+
+    /* Print only if we have the nickname.  If this cliente has just quit
+       when we were only resolving it, it is possible we don't have the
+       nickname. */
+    if (client_entry->nickname) {
+      memset(buf, 0, sizeof(buf));
+      if (client_entry->username)
+        snprintf(buf, sizeof(buf) - 1, "%s@%s",
+                client_entry->username, client_entry->hostname);
+      signal_emit("message quit", 4, server, client_entry->nickname,
+                 client_entry->username ? buf : "", 
+                 tmp ? tmp : "");
+    }
+
     list1 = nicklist_get_same_unique(SERVER(server), client_entry);
     for (list_tmp = list1; list_tmp != NULL; list_tmp = 
           list_tmp->next->next) {
@@ -791,12 +932,18 @@ void silc_notify(SilcClient client, SilcClientConnection conn,
   
       for (i = 0; i < clients_count; i++) {
        memset(buf, 0, sizeof(buf));
-       if (clients[i]->username)
-         snprintf(buf, sizeof(buf) - 1, "%s@%s",
-                  clients[i]->username, clients[i]->hostname);
-       signal_emit("message quit", 4, server, clients[i]->nickname,
-                   clients[i]->username ? buf : "", 
-                   "server signoff");
+
+       /* Print only if we have the nickname.  If this client has just quit
+          when we were only resolving it, it is possible we don't have the
+          nickname. */
+       if (clients[i]->nickname) {
+         if (clients[i]->username)
+           snprintf(buf, sizeof(buf) - 1, "%s@%s",
+                    clients[i]->username, clients[i]->hostname);
+         signal_emit("message quit", 4, server, clients[i]->nickname,
+                     clients[i]->username ? buf : "", 
+                     "server signoff");
+       }
 
        silc_server_free_ftp(server, clients[i]);
        
@@ -1060,12 +1207,13 @@ static void silc_client_join_get_users(SilcClient client,
                       channel->channel_name, chanrec->topic);
 
   if (founder) {
-    if (founder == conn->local_entry)
+    if (founder == conn->local_entry) {
       printformat_module("fe-common/silc", 
                         server, channel->channel_name, MSGLEVEL_CRAP,
                         SILCTXT_CHANNEL_FOUNDER_YOU,
                         channel->channel_name);
-    else
+      signal_emit("nick mode changed", 2, chanrec, ownnick);
+    } else
       printformat_module("fe-common/silc", 
                         server, channel->channel_name, MSGLEVEL_CRAP,
                         SILCTXT_CHANNEL_FOUNDER,
@@ -1157,9 +1305,10 @@ void  silc_parse_inviteban_list(SilcClient client,
          /* a public key */
          char *fingerprint, *babbleprint;
 
-         fingerprint = silc_hash_fingerprint(NULL, tmp, len);
-         babbleprint = silc_hash_fingerprint(NULL, tmp, len);
-
+         /* tmp is Public Key Payload, take public key from it. */
+         fingerprint = silc_hash_fingerprint(NULL, tmp + 4, len - 4);
+         babbleprint = silc_hash_babbleprint(NULL, tmp + 4, len - 4);
+         
          printformat_module("fe-common/silc", server,
                             (chanrec ? chanrec->visible_name : NULL),
                             MSGLEVEL_CRAP, SILCTXT_CHANNEL_INVITEBAN_PUBKEY,
index 68e2b09eeff3d43bc56ab049d400c3ad0718cac7..8c3f7630e0d5d6236496b7c196fa561c8c56e7dc 100644 (file)
@@ -27,11 +27,13 @@ void silc_say_error(char *msg, ...);
 void silc_channel_message(SilcClient client, SilcClientConnection conn,
                          SilcClientEntry sender, 
                          SilcChannelEntry channel, 
+                         SilcMessagePayload payload,
                          SilcMessageFlags flags, 
                          const unsigned char *message,
                          SilcUInt32 message_len);
 void silc_private_message(SilcClient client, SilcClientConnection conn,
                          SilcClientEntry sender, 
+                         SilcMessagePayload payload,
                          SilcMessageFlags flags, 
                          const unsigned char *message,
                          SilcUInt32 message_len);
index d2ba8367f46cc9c6814ca3d9bd76d5a187dc23c7..a2832f0f94924656acad4d98216c163d0fd65540 100644 (file)
             cmd_return_error(CMDERR_NOT_CONNECTED); \
        } G_STMT_END
 
+/* Returning from command function with error */
+#define cmd_return_error_value(a,v) \
+       G_STMT_START { \
+         signal_emit("error command", 1, GINT_TO_POINTER(a)); \
+         signal_stop(); \
+         return (v); \
+       } G_STMT_END
+
 #endif
index caf8b508b750f39853399359bc9cb22299cd57d6..eeea2685303e9ffbbe7e6f804c490d114d8c6fb0 100644 (file)
@@ -395,6 +395,7 @@ void silc_core_init(void)
   settings_add_int("server", "key_exchange_rekey_secs", 3600);
   settings_add_int("server", "connauth_request_secs", 2);
   settings_add_int("server", "heartbeat", 300);
+  settings_add_bool("server", "ignore_message_signatures", FALSE);
 
   /* Requested Attributes settings */
   settings_add_bool("silc", "attr_allow", TRUE);
index 0ae04ab2e9bbcba20d5f2904a08365a1bc5597b2..594c3ffe91cdeef96e7aad034ac2b5715b9b2c0d 100644 (file)
@@ -29,4 +29,8 @@ extern SilcClient silc_client;
 
 #define IS_SILC_ITEM(rec) (IS_SILC_CHANNEL(rec) || IS_SILC_QUERY(rec))
 
+#define SILC_MSG_SIGNED_VERIFIED 0
+#define SILC_MSG_SIGNED_UNKNOWN 1
+#define SILC_MSG_SIGNED_FAILED 2
+
 #endif
index 2a517db2a8a557d8e2b5e813f4cfe3052c369b22..a8c302bca499c9fb424caced1af589bcdd811842 100644 (file)
@@ -36,7 +36,9 @@ SILC_NICK_REC *silc_nicklist_insert(SILC_CHANNEL_REC *channel,
 
   rec = g_new0(SILC_NICK_REC, 1);
   rec->nick = g_strdup(user->client->nickname);
-  rec->host = g_strdup(user->client->username);
+  rec->host = g_strdup_printf("%s@%s", user->client->username,
+                             user->client->hostname);
+  rec->realname = g_strdup(user->client->realname);
   rec->silc_user = user;
   rec->unique_id = user->client;
 
index 4d68aeb0ad0cde2bd8433f716275ea84a31e6ddf..c6cbdb4889ce46b0bc7fb4a4cd4715fee43f8dd1 100644 (file)
 void silc_servers_reconnect_init(void);
 void silc_servers_reconnect_deinit(void);
 
-static void silc_send_channel(SILC_SERVER_REC *server,
-                             char *channel, char *msg)
+static int silc_send_channel(SILC_SERVER_REC *server,
+                             char *channel, char *msg,
+                             SilcMessageFlags flags)
 {
   SILC_CHANNEL_REC *rec;
   
   rec = silc_channel_find(server, channel);
   if (rec == NULL || rec->entry == NULL) {
-    cmd_return_error(CMDERR_NOT_JOINED);
-    return;
+    cmd_return_error_value(CMDERR_NOT_JOINED, FALSE);
   }
 
   silc_client_send_channel_message(silc_client, server->conn, rec->entry, 
-                                  NULL, SILC_MESSAGE_FLAG_UTF8,
-                                  msg, strlen(msg), TRUE);
+                                  NULL, flags, msg, strlen(msg), TRUE);
+  return TRUE;
 }
 
 typedef struct {
@@ -134,8 +134,8 @@ static void silc_send_msg_clients(SilcClient client,
   g_free(rec);
 }
 
-static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg,
-                       int msg_len, SilcMessageFlags flags)
+static int silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg,
+                         int msg_len, SilcMessageFlags flags)
 {
   PRIVMSG_REC *rec;
   SilcClientEntry *clients;
@@ -145,7 +145,7 @@ static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg,
   if (!silc_parse_userfqdn(nick, &nickname, NULL)) {
     printformat_module("fe-common/silc", server, NULL,
                       MSGLEVEL_CRAP, SILCTXT_BAD_NICK, nick);
-    return;
+    return FALSE;
   }
 
   /* Find client entry */
@@ -163,7 +163,7 @@ static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg,
     silc_client_get_clients(silc_client, server->conn,
                            nickname, NULL, silc_send_msg_clients, rec);
     silc_free(nickname);
-    return;
+    return FALSE;
   }
 
   /* Send the private message directly */
@@ -171,6 +171,7 @@ static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg,
   silc_client_send_private_message(silc_client, server->conn, 
                                   clients[0], flags,
                                   msg, msg_len, TRUE);
+  return TRUE;
 }
 
 void silc_send_mime(SILC_SERVER_REC *server, WI_ITEM_REC *to,
@@ -249,7 +250,8 @@ static void send_message(SILC_SERVER_REC *server, char *target,
   }
 
   if (target_type == SEND_TARGET_CHANNEL)
-    silc_send_channel(server, target, message ? message : msg);
+    silc_send_channel(server, target, message ? message : msg,
+                     SILC_MESSAGE_FLAG_UTF8);
   else
     silc_send_msg(server, target, message ? message : msg,
                  message ? strlen(message) : strlen(msg),
@@ -444,6 +446,7 @@ char *silc_server_get_channels(SILC_SERVER_REC *server)
 /* SYNTAX: WATCH [<-add | -del> <nickname>] */
 /* SYNTAX: STATS */
 /* SYNTAX: ATTR [<-del> <option> [{ <value>}]] */
+/* SYNTAX: SMSG [<-channel>] <target> <message> */
 
 void silc_command_exec(SILC_SERVER_REC *server,
                       const char *command, const char *args)
@@ -495,6 +498,77 @@ static void command_sconnect(const char *data, SILC_SERVER_REC *server)
   signal_stop();
 }
 
+/* SMSG command, to send digitally signed messages */
+
+static void command_smsg(const char *data, SILC_SERVER_REC *server,
+                        WI_ITEM_REC *item)
+{
+  GHashTable *optlist;
+  char *target, *origtarget, *msg;
+  void *free_arg;
+  int free_ret, target_type;
+  
+  g_return_if_fail(data != NULL);
+  if (server == NULL || !server->connected)
+    cmd_param_error(CMDERR_NOT_CONNECTED);
+
+  if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS |
+                     PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
+                     "msg", &optlist, &target, &msg))
+    return;
+  if (*target == '\0' || *msg == '\0')
+    cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
+
+  origtarget = target;
+  free_ret = FALSE;
+
+  if (strcmp(target, "*") == 0) {
+    if (item == NULL)
+      cmd_param_error(CMDERR_NOT_JOINED);
+
+    target_type = IS_CHANNEL(item) ?
+      SEND_TARGET_CHANNEL : SEND_TARGET_NICK;
+    target = (char *) window_item_get_target(item);
+  } else if (g_hash_table_lookup(optlist, "channel") != NULL) {
+    target_type = SEND_TARGET_CHANNEL;
+  } else {
+    target_type = server_ischannel(SERVER(server), target) ?
+      SEND_TARGET_CHANNEL : SEND_TARGET_NICK;
+  }
+
+  if (target != NULL) {
+    char *message = NULL;
+    int len, result;
+
+    if (!silc_term_utf8()) {
+      len = silc_utf8_encoded_len(msg, strlen(msg), SILC_STRING_LANGUAGE);
+      message = silc_calloc(len + 1, sizeof(*message));
+      g_return_if_fail(message != NULL);
+      silc_utf8_encode(msg, strlen(msg), SILC_STRING_LANGUAGE, message, len);
+    }
+
+    if (target_type == SEND_TARGET_CHANNEL)
+      result = silc_send_channel(server, target, message ? message : msg,
+                                SILC_MESSAGE_FLAG_UTF8 |
+                                SILC_MESSAGE_FLAG_SIGNED);
+    else
+      result = silc_send_msg(server, target, message ? message : msg,
+                            message ? strlen(message) : strlen(msg),
+                            SILC_MESSAGE_FLAG_UTF8 |
+                            SILC_MESSAGE_FLAG_SIGNED);
+    silc_free(message);
+    if (!result)
+      goto out;
+  }
+
+  signal_emit(target != NULL && target_type == SEND_TARGET_CHANNEL ?
+             "message signed_own_public" : "message signed_own_private", 4,
+             server, msg, target, origtarget);
+out:
+  if (free_ret && target != NULL) g_free(target);
+  cmd_params_free(free_arg);
+}
+
 /* FILE command */
 
 SILC_TASK_CALLBACK(silc_client_file_close_later)
@@ -983,6 +1057,7 @@ void silc_server_init(void)
   command_bind_silc("watch", MODULE_NAME, (SIGNAL_FUNC) command_self);
   command_bind_silc("stats", MODULE_NAME, (SIGNAL_FUNC) command_self);
   command_bind_silc("attr", MODULE_NAME, (SIGNAL_FUNC) command_attr);
+  command_bind_silc("smsg", MODULE_NAME, (SIGNAL_FUNC) command_smsg);
 
   command_set_options("connect", "+silcnet");
 }
@@ -1021,6 +1096,7 @@ void silc_server_deinit(void)
   command_unbind("watch", (SIGNAL_FUNC) command_self);
   command_unbind("stats", (SIGNAL_FUNC) command_self);
   command_unbind("attr", (SIGNAL_FUNC) command_attr);
+  command_unbind("smsg", (SIGNAL_FUNC) command_smsg);
 }
 
 void silc_server_free_ftp(SILC_SERVER_REC *server,
index 6ae07106f5875f881c1c902bf4191b64d25a9221..78beef6f58c38c90c71ae045894c8c16000351e1 100644 (file)
@@ -1133,9 +1133,10 @@ SILC_SERVER_CMD_FUNC(invite)
 
     /* Allocate hash table for invite list if it doesn't exist yet */
     if (!channel->invite_list)
-      channel->invite_list = silc_hash_table_alloc(0, silc_hash_ptr,
-                                                  NULL, NULL, NULL,
-                                                  NULL, NULL, TRUE);
+      channel->invite_list =
+       silc_hash_table_alloc(0, silc_hash_ptr,
+                             NULL, NULL, NULL,
+                             silc_server_inviteban_destruct, channel, TRUE);
 
     /* Check if the ID is in the list already */
     silc_hash_table_list(channel->invite_list, &htl);
@@ -1190,9 +1191,11 @@ SILC_SERVER_CMD_FUNC(invite)
       if (tmp[0] == 0x00) {
        /* Allocate hash table for invite list if it doesn't exist yet */
        if (!channel->invite_list)
-         channel->invite_list = silc_hash_table_alloc(0, silc_hash_ptr,
-                                                      NULL, NULL, NULL,
-                                                      NULL, NULL, TRUE);
+         channel->invite_list =
+           silc_hash_table_alloc(0, silc_hash_ptr,
+                                 NULL, NULL, NULL,
+                                 silc_server_inviteban_destruct, channel,
+                                 TRUE);
     
        /* Check for resource limit */
        if (silc_hash_table_count(channel->invite_list) > 64) {
@@ -2969,6 +2972,11 @@ SILC_SERVER_CMD_FUNC(cmode)
                                                0);
          goto out;
        }
+      } else {
+       /* If key was not sent and the channel mode has already founder
+          then the key was not to be changed. */
+       if (channel->mode & SILC_CHANNEL_MODE_FOUNDER_AUTH)
+         goto has_founder;
       }
 
       /* Set the founder authentication */
@@ -3013,6 +3021,7 @@ SILC_SERVER_CMD_FUNC(cmode)
        channel->founder_key = NULL;
        goto out;
       }
+    has_founder:
     }
   } else {
     if (chl->mode & SILC_CHANNEL_UMODE_CHANFO) {
@@ -3073,7 +3082,6 @@ SILC_SERVER_CMD_FUNC(cumode)
   SilcServerCommandContext cmd = (SilcServerCommandContext)context;
   SilcServer server = cmd->server;
   SilcClientEntry client = (SilcClientEntry)cmd->sock->user_data;
-  SilcIDListData idata = (SilcIDListData)client;
   SilcChannelID *channel_id = NULL;
   SilcClientID *client_id = NULL;
   SilcChannelEntry channel;
@@ -3205,9 +3213,7 @@ SILC_SERVER_CMD_FUNC(cumode)
       SilcHashTableList htl;
 
       if (!(channel->mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) ||
-         !channel->founder_key || !idata->public_key ||
-         !silc_pkcs_public_key_compare(channel->founder_key, 
-                                       idata->public_key)) {
+         !channel->founder_key) {
        silc_server_command_send_status_reply(cmd, SILC_COMMAND_CUMODE,
                                              SILC_STATUS_ERR_AUTH_FAILED, 0);
        goto out;
@@ -4177,9 +4183,11 @@ SILC_SERVER_CMD_FUNC(ban)
       if (tmp[0] == 0x00) {
        /* Allocate hash table for ban list if it doesn't exist yet */
        if (!channel->ban_list)
-         channel->ban_list = silc_hash_table_alloc(0, silc_hash_ptr,
-                                                   NULL, NULL, NULL,
-                                                   NULL, NULL, TRUE);
+         channel->ban_list =
+           silc_hash_table_alloc(0, silc_hash_ptr,
+                                 NULL, NULL, NULL,
+                                 silc_server_inviteban_destruct, channel,
+                                 TRUE);
     
        /* Check for resource limit */
        if (silc_hash_table_count(channel->ban_list) > 64) {
index 2711d02f6d3e463d0cd2a73abd9dbe25711b66c8..a72e6c206a8ccdef7d0f727f6fe7ec6fbbd94fba 100644 (file)
@@ -1000,16 +1000,46 @@ SILC_SERVER_CMD_REPLY_FUNC(join)
 
   /* Get the ban list */
   tmp = silc_argument_get_arg_type(cmd->args, 8, &len);
-  if (tmp) {
-    silc_free(entry->ban_list);
-    entry->ban_list = silc_memdup(tmp, len);
+  if (tmp && len > 2) {
+    SilcArgumentPayload iargs;
+    SilcUInt16 iargc;
+    SILC_GET16_MSB(iargc, tmp);
+    iargs = silc_argument_payload_parse(tmp + 2, len - 2, iargc);
+    if (iargs) {
+      /* Delete old ban list */
+      if (entry->ban_list)
+       silc_hash_table_free(entry->ban_list);
+      entry->ban_list =
+       silc_hash_table_alloc(0, silc_hash_ptr,
+                             NULL, NULL, NULL,
+                             silc_server_inviteban_destruct, entry, TRUE);
+
+      /* Add new ban list */
+      silc_server_inviteban_process(server, entry->ban_list, 0, iargs);
+      silc_argument_payload_free(iargs);
+    }
   }
 
   /* Get the invite list */
   tmp = silc_argument_get_arg_type(cmd->args, 9, &len);
-  if (tmp) {
-    silc_free(entry->invite_list);
-    entry->invite_list = silc_memdup(tmp, len);
+  if (tmp && len > 2) {
+    SilcArgumentPayload iargs;
+    SilcUInt16 iargc;
+    SILC_GET16_MSB(iargc, tmp);
+    iargs = silc_argument_payload_parse(tmp + 2, len - 2, iargc);
+    if (iargs) {
+      /* Delete old invite list */
+      if (entry->invite_list)
+       silc_hash_table_free(entry->invite_list);
+      entry->invite_list =
+       silc_hash_table_alloc(0, silc_hash_ptr,
+                             NULL, NULL, NULL,
+                             silc_server_inviteban_destruct, entry, TRUE);
+
+      /* Add new invite list */
+      silc_server_inviteban_process(server, entry->invite_list, 0, iargs);
+      silc_argument_payload_free(iargs);
+    }
   }
 
   /* Get the topic */
index 6a4d5f767068236bdd717a67a06bbd02beccebcf..9acdd06844330fd6b2e7f93baaa55d344aa68687 100644 (file)
@@ -227,7 +227,7 @@ silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
     
     if (sock && ((sock->hostname && !strcasecmp(sock->hostname, hostname)) ||
                 (sock->ip && !strcasecmp(sock->ip, hostname)))
-       && sock->port == port)
+       && server->id->port == htons(port))
       break;
 
     id_cache = NULL;
@@ -295,8 +295,10 @@ int silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry)
     if (!silc_idcache_del_by_context(id_list->servers, entry))
       return FALSE;
 
-    SILC_LOG_DEBUG(("Deleting server %s", entry->server_name ?
-                   entry->server_name : ""));
+    SILC_LOG_DEBUG(("Deleting server %s id %s", entry->server_name ?
+                   entry->server_name : "",
+                   entry->id ?
+                   silc_id_render(entry->id, SILC_ID_SERVER) : ""));
 
     /* Free data */
     silc_free(entry->server_name);
@@ -654,10 +656,6 @@ static void silc_idlist_del_channel_foreach(void *key, void *context,
 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry)
 {
   if (entry) {
-    SilcHashTableList htl;
-    SilcBuffer tmp;
-    SilcUInt32 type;
-
     /* Remove from cache */
     if (!silc_idcache_del_by_context(id_list->channels, entry))
       return FALSE;
@@ -676,31 +674,10 @@ int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry)
     silc_free(entry->id);
     silc_free(entry->topic);
 
-    if (entry->invite_list) {
-      silc_hash_table_list(entry->invite_list, &htl);
-      while (silc_hash_table_get(&htl, (void **)&type, (void **)&tmp)) {
-       if (type == 1) {
-         silc_free((char *)tmp);
-         continue;
-       }
-       silc_buffer_free(tmp);
-      }
-      silc_hash_table_list_reset(&htl);
+    if (entry->invite_list)
       silc_hash_table_free(entry->invite_list);
-    }
-
-    if (entry->ban_list) {
-      silc_hash_table_list(entry->ban_list, &htl);
-      while (silc_hash_table_get(&htl, (void **)&type, (void **)&tmp)) {
-       if (type == 1) {
-         silc_free((char *)tmp);
-         continue;
-       }
-       silc_buffer_free(tmp);
-      }
-      silc_hash_table_list_reset(&htl);
+    if (entry->ban_list)
       silc_hash_table_free(entry->ban_list);
-    }
 
     if (entry->channel_key)
       silc_cipher_free(entry->channel_key);
index 01aa8258e905e8c91e7102c3dbb71c2f6f9809c1..e49fafb59e7fb9a6d34595eff5748831a191b5a3 100644 (file)
@@ -1087,9 +1087,10 @@ void silc_server_notify(SilcServer server,
        goto out;
 
       if (action == 0 && !channel->invite_list)
-       channel->invite_list = silc_hash_table_alloc(0, silc_hash_ptr,
-                                                    NULL, NULL, NULL,
-                                                    NULL, NULL, TRUE);
+       channel->invite_list =
+         silc_hash_table_alloc(0, silc_hash_ptr,
+                               NULL, NULL, NULL,
+                               silc_server_inviteban_destruct, channel, TRUE);
 
       /* Proces the invite action */
       silc_server_inviteban_process(server, channel->invite_list, action,
@@ -1305,9 +1306,22 @@ void silc_server_notify(SilcServer server,
     }
     silc_free(server_id);
 
-    /* Sending SERVER_SIGNOFF is not right way to signoff local connection */
-    if (SILC_IS_LOCAL(server_entry))
+    /* For local entrys SERVER_SIGNOFF is processed only on backup router.
+       It is possible that router sends server signoff for a server.  If
+       backup router has it as local connection it will be closed. */
+    if (SILC_IS_LOCAL(server_entry)) {
+      if (server->server_type == SILC_BACKUP_ROUTER) {
+       sock = server_entry->connection;
+       SILC_LOG_DEBUG(("Closing connection %s after SERVER_SIGNOFF",
+                      sock->hostname));
+       SILC_SET_DISCONNECTING(sock);
+       if (sock->user_data)
+         silc_server_free_sock_user_data(server, sock, NULL);
+       silc_server_close_connection(server, sock);
+      }
+
       break;
+    }
 
     /* Remove all servers that are originated from this server, and
        remove the clients of those servers too. */
@@ -1661,9 +1675,10 @@ void silc_server_notify(SilcServer server,
        goto out;
 
       if (action == 0 && !channel->ban_list)
-       channel->ban_list = silc_hash_table_alloc(0, silc_hash_ptr,
-                                                 NULL, NULL, NULL,
-                                                 NULL, NULL, TRUE);
+       channel->ban_list =
+         silc_hash_table_alloc(0, silc_hash_ptr,
+                               NULL, NULL, NULL,
+                               silc_server_inviteban_destruct, channel, TRUE);
 
       /* Proces the ban action */
       silc_server_inviteban_process(server, channel->ban_list, action,
@@ -2094,9 +2109,12 @@ void silc_server_channel_key(SilcServer server,
 
   /* Save the channel key */
   channel = silc_server_save_channel_key(server, buffer, NULL);
-  if (!channel)
+  if (!channel) {
+    SILC_LOG_ERROR(("Bad channel key from %s (%s)",
+                   sock->hostname, sock->ip));
     return;
-
+  }
+    
   /* Distribute the key to everybody who is on the channel. If we are router
      we will also send it to locally connected servers. */
   silc_server_send_channel_key(server, sock, channel, FALSE);
@@ -3920,5 +3938,4 @@ void silc_server_resume_client(SilcServer server,
   }
 
   silc_free(client_id);
-    silc_idlist_del_data(detached_client);
 }
index 0d97aeafd33ecabab76994248887f38c9ee996d0..8e3ab0f248742ce3a308a3074059467eb3aec13b 100644 (file)
@@ -38,18 +38,24 @@ int silc_server_packet_send_real(SilcServer server,
   if (SILC_IS_DISCONNECTING(sock))
     return -1;
 
-  /* If rekey protocol is active we must assure that all packets are
-     sent through packet queue. */
-  if (SILC_SERVER_IS_REKEY(sock))
-    force_send = FALSE;
-
-  /* If outbound data is already pending do not force send */
-  if (SILC_IS_OUTBUF_PENDING(sock))
-    force_send = FALSE;
-
   /* Send the packet */
-  ret = silc_packet_send(sock, force_send);
+  ret = silc_packet_send(sock, FALSE);
   if (ret != -2) {
+    if (ret == -1) {
+      SILC_LOG_ERROR(("Error sending packet to connection "
+                     "%s:%d [%s]", sock->hostname, sock->port,
+                     (sock->type == SILC_SOCKET_TYPE_UNKNOWN ? "Unknown" :
+                      sock->type == SILC_SOCKET_TYPE_CLIENT ? "Client" :
+                      sock->type == SILC_SOCKET_TYPE_SERVER ? "Server" :
+                      "Router")));
+
+      SILC_SET_DISCONNECTING(sock);
+      if (sock->user_data)
+       silc_server_free_sock_user_data(server, sock, NULL);
+      silc_server_close_connection(server, sock);
+      return ret;
+    }
+
     server->stat.packets_sent++;
     return ret;
   }
@@ -741,6 +747,9 @@ silc_server_packet_relay_to_channel_encrypt(SilcServer server,
                                            unsigned char *data,
                                            unsigned int data_len)
 {
+  SilcUInt32 mac_len, iv_len;
+  unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
+
   /* If we are router and the packet came from router and private key
      has not been set for the channel then we must encrypt the packet
      as it was decrypted with the session key shared between us and the
@@ -748,11 +757,17 @@ silc_server_packet_relay_to_channel_encrypt(SilcServer server,
      same channel key. */
   if (server->server_type == SILC_ROUTER &&
       sock->type == SILC_SOCKET_TYPE_ROUTER &&
-      !(channel->mode & SILC_CHANNEL_MODE_PRIVKEY) &&
-      channel->channel_key) {
-    SilcUInt32 mac_len = silc_hmac_len(channel->hmac);
-    SilcUInt32 iv_len = silc_cipher_get_block_len(channel->channel_key);
-    unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
+      !(channel->mode & SILC_CHANNEL_MODE_PRIVKEY) && channel->key) {
+
+    /* If we are backup router and remote is our primary router and
+       we are currently doing backup resuming protocol we must not
+       re-encrypt message with session key. */
+    if (server->backup_router && SILC_SERVER_IS_BACKUP(sock) &&
+       SILC_PRIMARY_ROUTE(server) == sock)
+      return TRUE;
+
+    mac_len = silc_hmac_len(channel->hmac);
+    iv_len = silc_cipher_get_block_len(channel->channel_key);
 
     if (data_len <= mac_len + iv_len) {
       SILC_LOG_WARNING(("Corrupted channel message, cannot relay it"));
@@ -760,8 +775,9 @@ silc_server_packet_relay_to_channel_encrypt(SilcServer server,
     }
 
     memcpy(iv, data + (data_len - iv_len - mac_len), iv_len);
-    silc_message_payload_encrypt(data, data_len - iv_len, iv, iv_len,
-                                channel->channel_key, channel->hmac);
+    silc_message_payload_encrypt(data, data_len - iv_len, data_len,
+                                iv, iv_len, channel->channel_key,
+                                channel->hmac);
   }
 
   return TRUE;
@@ -1991,7 +2007,6 @@ void silc_server_packet_queue_purge(SilcServer server,
       (SILC_IS_DISCONNECTED(sock) == FALSE)) {
     server->stat.packets_sent++;
     silc_packet_send(sock, TRUE);
-    SILC_SET_CONNECTION_FOR_INPUT(server->schedule, sock->sock);
     SILC_UNSET_OUTBUF_PENDING(sock);
     silc_buffer_clear(sock->outbuf);
   }
index 2a9b149ab2542400164e27241488a4c38368fe84..c3359196fe887f7dfc30da1aeed9c6a8b751f15c 100644 (file)
@@ -30,7 +30,6 @@
 SILC_TASK_CALLBACK(silc_server_rehash_close_connection);
 SILC_TASK_CALLBACK(silc_server_connect_to_router_retry);
 SILC_TASK_CALLBACK(silc_server_connect_router);
-SILC_TASK_CALLBACK(silc_server_connect_to_router);
 SILC_TASK_CALLBACK(silc_server_connect_to_router_second);
 SILC_TASK_CALLBACK(silc_server_connect_to_router_final);
 SILC_TASK_CALLBACK(silc_server_accept_new_connection);
@@ -42,7 +41,6 @@ SILC_TASK_CALLBACK(silc_server_close_connection_final);
 SILC_TASK_CALLBACK(silc_server_free_client_data_timeout);
 SILC_TASK_CALLBACK(silc_server_timeout_remote);
 SILC_TASK_CALLBACK(silc_server_channel_key_rekey);
-SILC_TASK_CALLBACK(silc_server_failure_callback);
 SILC_TASK_CALLBACK(silc_server_get_stats);
 
 /* Allocates a new SILC server object. This has to be done before the server
@@ -1006,7 +1004,7 @@ SILC_TASK_CALLBACK(silc_server_connect_router)
    server to do authentication and key exchange with our router - called
    from schedule. */
 
-SILC_TASK_CALLBACK(silc_server_connect_to_router)
+SILC_TASK_CALLBACK_GLOBAL(silc_server_connect_to_router)
 {
   SilcServer server = (SilcServer)context;
   SilcServerConnection sconn;
@@ -1109,8 +1107,6 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router_second)
       silc_ske_free(ctx->ske);
     silc_free(ctx->dest_id);
     silc_free(ctx);
-    silc_schedule_task_del_by_callback(server->schedule,
-                                      silc_server_failure_callback);
     silc_server_disconnect_remote(server, sock, 
                                  SILC_STATUS_ERR_KEY_EXCHANGE_FAILED, NULL);
 
@@ -1154,8 +1150,6 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router_second)
       silc_ske_free(ctx->ske);
     silc_free(ctx->dest_id);
     silc_free(ctx);
-    silc_schedule_task_del_by_callback(server->schedule,
-                                      silc_server_failure_callback);
     silc_server_disconnect_remote(server, sock, 
                                  SILC_STATUS_ERR_KEY_EXCHANGE_FAILED, NULL);
 
@@ -1230,8 +1224,6 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router_second)
     silc_free(sconn->remote_host);
     silc_free(sconn->backup_replace_ip);
     silc_free(sconn);
-    silc_schedule_task_del_by_callback(server->schedule,
-                                      silc_server_failure_callback);
     silc_server_disconnect_remote(server, sock, 
                                  SILC_STATUS_ERR_KEY_EXCHANGE_FAILED, NULL);
     return;
@@ -1673,8 +1665,6 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_second)
     silc_server_config_unref(&ctx->sconfig);
     silc_server_config_unref(&ctx->rconfig);
     silc_free(ctx);
-    silc_schedule_task_del_by_callback(server->schedule,
-                                      silc_server_failure_callback);
     silc_server_disconnect_remote(server, sock, 
                                  SILC_STATUS_ERR_KEY_EXCHANGE_FAILED,
                                  NULL);
@@ -1706,8 +1696,6 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_second)
     silc_server_config_unref(&ctx->sconfig);
     silc_server_config_unref(&ctx->rconfig);
     silc_free(ctx);
-    silc_schedule_task_del_by_callback(server->schedule,
-                                      silc_server_failure_callback);
     silc_server_disconnect_remote(server, sock, 
                                  SILC_STATUS_ERR_KEY_EXCHANGE_FAILED, NULL);
     server->stat.auth_failures++;
@@ -1795,8 +1783,6 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_final)
     silc_server_config_unref(&ctx->sconfig);
     silc_server_config_unref(&ctx->rconfig);
     silc_free(ctx);
-    silc_schedule_task_del_by_callback(server->schedule,
-                                      silc_server_failure_callback);
     silc_server_disconnect_remote(server, sock, SILC_STATUS_ERR_AUTH_FAILED,
                                  NULL);
     server->stat.auth_failures++;
@@ -2133,8 +2119,6 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_final)
                        server->schedule);
 
  out:
-  silc_schedule_task_del_by_callback(server->schedule,
-                                    silc_server_failure_callback);
   silc_protocol_free(protocol);
   if (ctx->packet)
     silc_packet_context_free(ctx->packet);
@@ -2159,6 +2143,7 @@ SILC_TASK_CALLBACK(silc_server_packet_process)
   SilcCipher cipher = NULL;
   SilcHmac hmac = NULL;
   SilcUInt32 sequence = 0;
+  bool local_is_router;
   int ret;
 
   if (!sock) {
@@ -2254,7 +2239,7 @@ SILC_TASK_CALLBACK(silc_server_packet_process)
       else
        silc_server_free_sock_user_data(server, sock, NULL);
     } else if (server->router_conn && server->router_conn->sock == sock &&
-            !server->router && server->standalone)
+              !server->router && server->standalone)
       silc_schedule_task_add(server->schedule, 0,
                             silc_server_connect_to_router,
                             server, 1, 0,
@@ -2280,10 +2265,20 @@ SILC_TASK_CALLBACK(silc_server_packet_process)
     sequence = idata->psn_receive;
   }
 
-  /* Process the packet. This will call the parser that will then
+  /* Then, process the packet. This will call the parser that will then
      decrypt and parse the packet. */
-  ret = silc_packet_receive_process(sock, server->server_type == SILC_ROUTER ?
-                                   TRUE : FALSE, cipher, hmac, sequence,
+
+  local_is_router = (server->server_type == SILC_ROUTER);
+
+  /* If socket connection is our primary, we are backup and we are doing
+     backup resuming, we won't process the packet as being a router 
+     (affects channel message decryption). */
+  if (server->backup_router && SILC_SERVER_IS_BACKUP(sock) &&
+      SILC_PRIMARY_ROUTE(server) == sock)
+    local_is_router = FALSE;
+
+  ret = silc_packet_receive_process(sock, local_is_router,
+                                   cipher, hmac, sequence,
                                    silc_server_packet_parse, server);
 
   /* If processing failed the connection is closed. */
@@ -2421,14 +2416,14 @@ bool silc_server_packet_parse(SilcPacketParserContext *parser_context,
        and we want to call this processor with valid cipher. */
     if (idata)
       ret = silc_packet_receive_process(
-                                 sock, server->server_type == SILC_ROUTER ?
-                                 TRUE : FALSE, idata->receive_key,
+                                 sock, server->server_type == SILC_ROUTER,
+                                 idata->receive_key,
                                  idata->hmac_receive, idata->psn_receive,
                                  silc_server_packet_parse, server);
     else
       ret = silc_packet_receive_process(
-                                 sock, server->server_type == SILC_ROUTER ?
-                                 TRUE : FALSE, NULL, NULL, 0,
+                                 sock, server->server_type == SILC_ROUTER,
+                                 NULL, NULL, 0,
                                  silc_server_packet_parse, server);
 
     if (!ret) {
@@ -2534,14 +2529,8 @@ void silc_server_packet_parse_type(SilcServer server,
     if (packet->flags & SILC_PACKET_FLAG_LIST)
       break;
     if (sock->protocol) {
-      SilcServerFailureContext f;
-      f = silc_calloc(1, sizeof(*f));
-      f->sock = silc_socket_dup(sock);
-
-      /* We will wait 5 seconds to process this failure packet */
-      silc_schedule_task_add(server->schedule, sock->sock,
-                            silc_server_failure_callback, (void *)f, 5, 0,
-                            SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
+      sock->protocol->state = SILC_PROTOCOL_STATE_FAILURE;
+      silc_protocol_execute(sock->protocol, server->schedule, 0, 0);
     }
     break;
 
@@ -2940,7 +2929,9 @@ void silc_server_close_connection(SilcServer server,
   char tmp[128];
 
   if (!server->sockets[sock->sock] && SILC_IS_DISCONNECTED(sock)) {
-    silc_schedule_task_add(server->schedule, 0,
+    silc_schedule_unset_listen_fd(server->schedule, sock->sock);
+    silc_schedule_task_del_by_fd(server->schedule, sock->sock);
+    silc_schedule_task_add(server->schedule, sock->sock,
                           silc_server_close_connection_final,
                           (void *)sock, 0, 1, SILC_TASK_TIMEOUT,
                           SILC_TASK_PRI_NORMAL);
@@ -2956,9 +2947,6 @@ void silc_server_close_connection(SilcServer server,
                    sock->type == SILC_SOCKET_TYPE_SERVER ? "Server" :
                    "Router"), tmp[0] ? tmp : ""));
 
-  /* We won't listen for this connection anymore */
-  silc_schedule_unset_listen_fd(server->schedule, sock->sock);
-
   /* Unregister all tasks */
   silc_schedule_task_del_by_fd(server->schedule, sock->sock);
 
@@ -2972,7 +2960,8 @@ void silc_server_close_connection(SilcServer server,
   if (!sock->user_data) {
     /* If any protocol is active cancel its execution. It will call
        the final callback which will finalize the disconnection. */
-    if (sock->protocol) {
+    if (sock->protocol && sock->protocol->protocol &&
+       sock->protocol->protocol->type != SILC_PROTOCOL_SERVER_BACKUP) {
       SILC_LOG_DEBUG(("Cancelling protocol, calling final callback"));
       silc_protocol_cancel(sock->protocol, server->schedule);
       sock->protocol->state = SILC_PROTOCOL_STATE_ERROR;
@@ -2982,7 +2971,10 @@ void silc_server_close_connection(SilcServer server,
     }
   }
 
-  silc_schedule_task_add(server->schedule, 0,
+  /* We won't listen for this connection anymore */
+  silc_schedule_unset_listen_fd(server->schedule, sock->sock);
+
+  silc_schedule_task_add(server->schedule, sock->sock,
                         silc_server_close_connection_final,
                         (void *)sock, 0, 1, SILC_TASK_TIMEOUT,
                         SILC_TASK_PRI_NORMAL);
@@ -3169,6 +3161,7 @@ void silc_server_free_sock_user_data(SilcServer server,
          server->id_entry->router = NULL;
          server->router = NULL;
          server->standalone = TRUE;
+         server->backup_primary = FALSE;
          backup_router = NULL;
        } else {
          if (server->id_entry != backup_router) {
@@ -3219,11 +3212,15 @@ void silc_server_free_sock_user_data(SilcServer server,
                               SILC_TASK_PRI_NORMAL);
       }
 
+      SILC_SERVER_SEND_OPERS(server, FALSE, TRUE, SILC_NOTIFY_TYPE_NONE,
+                            ("Server %s signoff", user_data->server_name));
+
       if (!backup_router) {
        /* Remove all servers that are originated from this server, and
           remove the clients of those servers too. */
        silc_server_remove_servers_by_server(server, user_data, TRUE);
 
+#if 0
        /* Remove the clients that this server owns as they will become
           invalid now too.  For backup router the server is actually
           coming from the primary router, so mark that as the owner
@@ -3233,6 +3230,7 @@ void silc_server_free_sock_user_data(SilcServer server,
          silc_server_remove_clients_by_server(server, server->router,
                                               user_data, TRUE);
        else
+#endif
          silc_server_remove_clients_by_server(server, user_data,
                                               user_data, TRUE);
 
@@ -3329,7 +3327,8 @@ void silc_server_free_sock_user_data(SilcServer server,
   }
 
   /* If any protocol is active cancel its execution */
-  if (sock->protocol) {
+  if (sock->protocol && sock->protocol->protocol &&
+      sock->protocol->protocol->type != SILC_PROTOCOL_SERVER_BACKUP) {
     SILC_LOG_DEBUG(("Cancelling protocol, calling final callback"));
     silc_protocol_cancel(sock->protocol, server->schedule);
     sock->protocol->state = SILC_PROTOCOL_STATE_ERROR;
@@ -3575,7 +3574,8 @@ SILC_TASK_CALLBACK(silc_server_timeout_remote)
 
   /* If we have protocol active we must assure that we call the protocol's
      final callback so that all the memory is freed. */
-  if (sock->protocol) {
+  if (sock->protocol && sock->protocol->protocol &&
+      sock->protocol->protocol->type != SILC_PROTOCOL_SERVER_BACKUP) {
     protocol = sock->protocol->protocol->type;
     silc_protocol_cancel(sock->protocol, server->schedule);
     sock->protocol->state = SILC_PROTOCOL_STATE_ERROR;
@@ -4590,27 +4590,6 @@ void silc_server_announce_channels(SilcServer server,
   silc_free(channel_ids);
 }
 
-/* Failure timeout callback. If this is called then we will immediately
-   process the received failure. We always process the failure with timeout
-   since we do not want to blindly trust to received failure packets.
-   This won't be called (the timeout is cancelled) if the failure was
-   bogus (it is bogus if remote does not close the connection after sending
-   the failure). */
-
-SILC_TASK_CALLBACK(silc_server_failure_callback)
-{
-  SilcServer server = app_context;
-  SilcServerFailureContext f = (SilcServerFailureContext)context;
-
-  if (f->sock->protocol) {
-    f->sock->protocol->state = SILC_PROTOCOL_STATE_FAILURE;
-    silc_protocol_execute(f->sock->protocol, server->schedule, 0, 0);
-  }
-
-  silc_socket_free(f->sock);
-  silc_free(f);
-}
-
 /* Assembles user list and users mode list from the `channel'. */
 
 bool silc_server_get_users_on_channel(SilcServer server,
@@ -5083,7 +5062,8 @@ SILC_TASK_CALLBACK_GLOBAL(silc_server_rekey_final)
   if (protocol->state == SILC_PROTOCOL_STATE_ERROR ||
       protocol->state == SILC_PROTOCOL_STATE_FAILURE) {
     /* Error occured during protocol */
-    SILC_LOG_ERROR(("Error occurred during rekey protocol"));
+    SILC_LOG_ERROR(("Error occurred during rekey protocol with
+                  %s (%s)", sock->hostname, sock->ip));
     silc_protocol_cancel(protocol, server->schedule);
     silc_protocol_free(protocol);
     sock->protocol = NULL;
index d7b2d3da912461110cd92f94a1c591eb5445185e..1204b2449f59feb6bf3406b17db736bb5130ff97 100644 (file)
@@ -120,9 +120,16 @@ do {                                                                       \
   (sock->protocol && sock->protocol->protocol &&                       \
    sock->protocol->protocol->type == SILC_PROTOCOL_SERVER_BACKUP)
 
-/* Output an error message wether to stderr or LOG_ERROR if we are in the
-   background. */
-#define SILC_SERVER_LOG_ERROR(fmt) silc_server_stderr(silc_format fmt)
+/* Output a message to stderr or to the appropriate log facility wether
+   we are in the background or not. */
+#define SILC_SERVER_LOG_INFO(fmt)                                      \
+  silc_server_stderr(SILC_LOG_INFO, silc_format fmt)
+#define SILC_SERVER_LOG_WARNING(fmt)                                   \
+  silc_server_stderr(SILC_LOG_WARNING, silc_format fmt)
+#define SILC_SERVER_LOG_ERROR(fmt)                                     \
+  silc_server_stderr(SILC_LOG_ERROR, silc_format fmt)
+#define SILC_SERVER_LOG_FATAL(fmt)                                     \
+  silc_server_stderr(SILC_LOG_WARNING, silc_format fmt)
 
 /* Prototypes */
 int silc_server_alloc(SilcServer *new_server);
@@ -242,6 +249,6 @@ SilcBuffer silc_server_get_client_channel_list(SilcServer server,
                                               bool get_private,
                                               bool get_secret,
                                               SilcBuffer *user_mode_list);
-void silc_server_stderr(char *message);
+void silc_server_stderr(SilcLogType type, char *message);
 
 #endif
index 88da61f8c36115e9b1da493e83dc27db0c3482ac..78634fe2e02fcc35a8b58da88df56808590256ce 100644 (file)
@@ -430,6 +430,17 @@ void silc_server_backup_send_dest(SilcServer server,
   }
 }
 
+SILC_TASK_CALLBACK(silc_server_backup_timeout)
+{
+  SilcProtocol protocol = context;
+  SilcServer server = app_context;
+
+  SILC_LOG_INFO(("Timeout occurred during backup resuming protocol"));
+  silc_protocol_cancel(protocol, server->schedule);
+  protocol->state = SILC_PROTOCOL_STATE_ERROR;
+  silc_protocol_execute_final(protocol, server->schedule);
+}
+
 /* Processes incoming RESUME_ROUTER packet. This can give the packet
    for processing to the protocol handler or allocate new protocol if
    start command is received. */
@@ -544,6 +555,10 @@ void silc_server_backup_resume_router(SilcServer server,
                        &sock->protocol, proto_ctx, 
                        silc_server_protocol_backup_done);
     silc_protocol_execute(sock->protocol, server->schedule, 0, 0);
+    silc_schedule_task_add(server->schedule, sock->sock,
+                          silc_server_backup_timeout,
+                          sock->protocol, 30, 0, SILC_TASK_TIMEOUT,
+                          SILC_TASK_PRI_NORMAL);
   }
 }
 
@@ -619,6 +634,11 @@ SILC_TASK_CALLBACK(silc_server_backup_connected_later)
                      &sock->protocol, proto_ctx, 
                      silc_server_protocol_backup_done);
   silc_protocol_execute(sock->protocol, server->schedule, 0, 0);
+
+  silc_schedule_task_add(server->schedule, sock->sock,
+                        silc_server_backup_timeout,
+                        sock->protocol, 30, 0, SILC_TASK_TIMEOUT,
+                        SILC_TASK_PRI_NORMAL);
 }
 
 /* Called when we've established connection back to our primary router
@@ -692,6 +712,8 @@ static void silc_server_backup_connect_primary(SilcServer server,
   idata = (SilcIDListData)server_entry;
 
   SILC_LOG_DEBUG(("Sending CONNECTED packet (session %d)", ctx->session));
+  SILC_LOG_INFO(("Sending CONNECTED (session %d) to backup router",
+               ctx->session));
 
   /* Send the CONNECTED packet back to the backup router. */
   buffer = silc_buffer_alloc(2);
@@ -792,7 +814,9 @@ SILC_TASK_CALLBACK_GLOBAL(silc_server_protocol_backup)
            ctx->sessions[ctx->sessions_count].connected = FALSE;
            ctx->sessions[ctx->sessions_count].server_entry = server_entry;
 
-           SILC_LOG_DEBUG(("Sending START to %s (session %d)", 
+           SILC_LOG_DEBUG(("Sending START to %s (session %d)",
+                           server_entry->server_name, ctx->sessions_count));
+           SILC_LOG_INFO(("Expecting CONNECTED from %s (session %d)",
                            server_entry->server_name, ctx->sessions_count));
 
            /* This connection is performing this protocol too now */
@@ -839,6 +863,8 @@ SILC_TASK_CALLBACK_GLOBAL(silc_server_protocol_backup)
 
            SILC_LOG_DEBUG(("Sending START to %s (session %d)", 
                            server_entry->server_name, ctx->sessions_count));
+           SILC_LOG_INFO(("Expecting CONNECTED from %s (session %d)",
+                           server_entry->server_name, ctx->sessions_count));
 
            /* This connection is performing this protocol too now */
            ((SilcSocketConnection)server_entry->connection)->protocol =
@@ -890,7 +916,14 @@ SILC_TASK_CALLBACK_GLOBAL(silc_server_protocol_backup)
         to be back online. We send the CONNECTED packet after we've
         established the connection to the primary router. */
       primary = silc_server_config_get_primary_router(server);
-      if (primary && server->backup_primary) {
+      if (primary && server->backup_primary &&
+         !silc_server_num_sockets_by_remote(server,
+                                            silc_net_is_ip(primary->host) ?
+                                            primary->host : NULL,
+                                            silc_net_is_ip(primary->host) ?
+                                            NULL : primary->host,
+                                            primary->port,
+                                            SILC_SOCKET_TYPE_ROUTER)) {
        SILC_LOG_DEBUG(("Received START (session %d), reconnect to router",
                        ctx->session));
        silc_server_backup_reconnect(server,
@@ -901,6 +934,8 @@ SILC_TASK_CALLBACK_GLOBAL(silc_server_protocol_backup)
        /* Nowhere to connect just return the CONNECTED packet */
        SILC_LOG_DEBUG(("Received START (session %d), send CONNECTED back",
                        ctx->session));
+       SILC_LOG_INFO(("Sending CONNECTED (session %d) to backup router",
+                     ctx->session));
 
        /* Send the CONNECTED packet back to the backup router. */
        packet = silc_buffer_alloc(2);
@@ -940,11 +975,13 @@ SILC_TASK_CALLBACK_GLOBAL(silc_server_protocol_backup)
        break;
       }
 
-      SILC_LOG_DEBUG(("Received CONNECTED (session %d)", ctx->session));
-
       for (i = 0; i < ctx->sessions_count; i++) {
        if (ctx->sessions[i].session == ctx->session) {
          ctx->sessions[i].connected = TRUE;
+         SILC_LOG_INFO(("Received CONNECTED from %s (session %d)",
+                        ctx->sessions[i].server_entry->server_name,
+                        ctx->session));
+         SILC_LOG_DEBUG(("Received CONNECTED (session %d)", ctx->session));
          break;
        }
       }
@@ -954,7 +991,8 @@ SILC_TASK_CALLBACK_GLOBAL(silc_server_protocol_backup)
          return;
       }
 
-      SILC_LOG_DEBUG(("All sessions has returned CONNECTED packets"));
+      SILC_LOG_INFO(("All sessions have returned CONNECTED packets, "
+                    "continuing"));
       SILC_LOG_DEBUG(("Sending ENDING packet to primary router"));
 
       /* Send with a timeout */
@@ -1101,7 +1139,7 @@ SILC_TASK_CALLBACK_GLOBAL(silc_server_protocol_backup)
        break;
       }
 
-      SILC_LOG_DEBUG(("Received RESUMED from new primary router"));
+      SILC_LOG_INFO(("Received RESUMED from new primary router"));
 
       if (server->backup_router)
        server->server_type = SILC_BACKUP_ROUTER;
@@ -1122,6 +1160,7 @@ SILC_TASK_CALLBACK_GLOBAL(silc_server_protocol_backup)
          SILC_LOG_INFO(("Resuming the use of primary router %s",
                         router->server_name));
        }
+       server->backup_primary = FALSE;
 
        /* Update the client entries of the backup router to the new 
           router */
@@ -1192,11 +1231,16 @@ SILC_TASK_CALLBACK(silc_server_protocol_backup_done)
   SilcIDCacheList list;
   SilcIDCacheEntry id_cache;
 
+  silc_schedule_task_del_by_context(server->schedule, protocol);
+
   if (protocol->state == SILC_PROTOCOL_STATE_ERROR ||
       protocol->state == SILC_PROTOCOL_STATE_FAILURE) {
     SILC_LOG_ERROR(("Error occurred during backup router resuming protcool"));
   }
 
+  if (server->server_shutdown)
+    return;
+
   /* Remove this protocol from all server entries that has it */
   if (silc_idcache_get_all(server->local_list->servers, &list)) {
     if (silc_idcache_list_first(list, &id_cache)) {
@@ -1207,6 +1251,29 @@ SILC_TASK_CALLBACK(silc_server_protocol_backup_done)
        if (sock->protocol == protocol) {
          sock->protocol = NULL;
 
+         /* Backup closes connection and reconnects if error occurred */
+         if (SILC_PRIMARY_ROUTE(server) == sock && server->backup_router) {
+           if (protocol->state == SILC_PROTOCOL_STATE_ERROR ||
+               protocol->state == SILC_PROTOCOL_STATE_FAILURE) {
+             server->backup_noswitch = TRUE;
+             server->server_type = SILC_BACKUP_ROUTER;
+
+             if (sock->user_data)
+               silc_server_free_sock_user_data(server, sock, NULL);
+             silc_server_close_connection(server, sock);
+
+             silc_schedule_task_add(server->schedule, 0,
+                                    silc_server_connect_to_router,
+                                    server, 1, 0,
+                                    SILC_TASK_TIMEOUT,
+                                    SILC_TASK_PRI_NORMAL);
+
+             if (!silc_idcache_list_next(list, &id_cache))
+               break;
+             continue;
+           }
+         }
+
          if (server_entry->data.status & SILC_IDLIST_STATUS_DISABLED)
            server_entry->data.status &= ~SILC_IDLIST_STATUS_DISABLED;
        }
@@ -1227,6 +1294,29 @@ SILC_TASK_CALLBACK(silc_server_protocol_backup_done)
        if (sock->protocol == protocol) {
          sock->protocol = NULL;
 
+         /* Backup closes connection and reconnects if error occurred */
+         if (SILC_PRIMARY_ROUTE(server) == sock && server->backup_router) {
+           if (protocol->state == SILC_PROTOCOL_STATE_ERROR ||
+               protocol->state == SILC_PROTOCOL_STATE_FAILURE) {
+             server->backup_noswitch = TRUE;
+             server->server_type = SILC_BACKUP_ROUTER;
+
+             if (sock->user_data)
+               silc_server_free_sock_user_data(server, sock, NULL);
+             silc_server_close_connection(server, sock);
+
+             silc_schedule_task_add(server->schedule, 0,
+                                    silc_server_connect_to_router,
+                                    server, 1, 0,
+                                    SILC_TASK_TIMEOUT,
+                                    SILC_TASK_PRI_NORMAL);
+
+             if (!silc_idcache_list_next(list, &id_cache))
+               break;
+             continue;
+           }
+         }
+
          if (server_entry->data.status & SILC_IDLIST_STATUS_DISABLED)
            server_entry->data.status &= ~SILC_IDLIST_STATUS_DISABLED;
        }
@@ -1238,7 +1328,9 @@ SILC_TASK_CALLBACK(silc_server_protocol_backup_done)
     silc_idcache_list_free(list);
   }
 
-  SILC_LOG_DEBUG(("Backup resuming protocol has ended"));
+  if (protocol->state != SILC_PROTOCOL_STATE_ERROR &&
+      protocol->state != SILC_PROTOCOL_STATE_FAILURE)
+    SILC_LOG_INFO(("Backup resuming protocol ended successfully"));
 
   if (ctx->sock->protocol)
     ctx->sock->protocol = NULL;
index 406d4338f1e5fa6b291a6a7fa65b2fca5f3d6673..0f4e14b43c4c35ff945f093ceea53413eb749732 100644 (file)
@@ -232,6 +232,7 @@ do {                                                \
 /* Prototypes */
 SILC_TASK_CALLBACK_GLOBAL(silc_server_rekey_final);
 SILC_TASK_CALLBACK_GLOBAL(silc_server_rekey_callback);
+SILC_TASK_CALLBACK_GLOBAL(silc_server_connect_to_router);
 void silc_server_watcher_list_destroy(void *key, void *context,
                                      void *user_context);
 
index dd79c597f08a22c8675c8eb12e31b1aea9bd725a..6475c57301b06b7dcde972704472061994bf0c7a 100644 (file)
@@ -1554,7 +1554,7 @@ SilcBuffer silc_server_query_reply_attrs(SilcServer server,
   SilcAttributeObjPk pk;
   SilcAttributeObjService service;
   unsigned char *tmp;
-  unsigned char sign[2048];
+  unsigned char sign[2048 + 1];
   SilcUInt32 sign_len;
 
   SILC_LOG_DEBUG(("Constructing Requested Attributes"));
index bc31cb6d0d72c32eb90813daaa652452cce3e813..dead873a6d250037bff3b3c9a91a585e9a4acc0a 100644 (file)
@@ -1772,6 +1772,12 @@ bool silc_server_inviteban_match(SilcServer server, SilcHashTable list,
   return ret;
 }
 
+static void silc_server_inviteban_dummy_dest(void *key, void *context,
+                                            void *user_context)
+{
+  /* Nothing */
+}
+
 /* Process invite or ban information */
 
 void silc_server_inviteban_process(SilcServer server, SilcHashTable list,
@@ -1797,7 +1803,8 @@ void silc_server_inviteban_process(SilcServer server, SilcHashTable list,
        char *string = NULL;
        silc_hash_table_find(list, (void *)1,
                             NULL, (void **)&string);
-       silc_hash_table_del(list, (void *)1);
+       silc_hash_table_del_ext(list, (void *)1, NULL, NULL, NULL, NULL,
+                               silc_server_inviteban_dummy_dest, NULL);
        if (!string)
          string = silc_calloc(len + 2, sizeof(*string));
        else
@@ -1869,10 +1876,8 @@ void silc_server_inviteban_process(SilcServer server, SilcHashTable list,
        char *string = NULL, *start, *end, *n;
 
        if (silc_hash_table_find(list, (void *)1, NULL, (void **)&string)) {
-         silc_hash_table_del(list, (void *)1);
-
          if (!strncmp(string, tmp, strlen(string) - 1)) {
-           silc_free(string);
+           silc_hash_table_del(list, (void *)1);
            string = NULL;
          } else {
            start = strstr(string, tmp);
@@ -1881,7 +1886,7 @@ void silc_server_inviteban_process(SilcServer server, SilcHashTable list,
              n = silc_calloc(strlen(string) - len, sizeof(*n));
              strncat(n, string, start - string);
              strncat(n, end + 1, ((string + strlen(string)) - end) - 1);
-             silc_free(string);
+             silc_hash_table_del(list, (void *)1);
              string = n;
            }
          }
@@ -1899,7 +1904,6 @@ void silc_server_inviteban_process(SilcServer server, SilcHashTable list,
        while (silc_hash_table_get(&htl, (void **)&type, (void **)&tmp2)) {
          if (type == 2 && !memcmp(tmp2->data, tmp, len)) {
            silc_hash_table_del_by_context(list, (void *)2, tmp2);
-           silc_buffer_free(tmp2);
            break;
          }
        }
@@ -1913,7 +1917,6 @@ void silc_server_inviteban_process(SilcServer server, SilcHashTable list,
        while (silc_hash_table_get(&htl, (void **)&type, (void **)&tmp2)) {
          if (type == 3 && !memcmp(tmp2->data, tmp, len)) {
            silc_hash_table_del_by_context(list, (void *)3, tmp2);
-           silc_buffer_free(tmp2);
            break;
          }
        }
@@ -1924,3 +1927,23 @@ void silc_server_inviteban_process(SilcServer server, SilcHashTable list,
     }
   }
 }
+
+/* Destructor for invite or ban list entrys */
+
+void silc_server_inviteban_destruct(void *key, void *context,
+                                   void *user_context)
+{
+  switch ((SilcUInt32)key) {
+  case 1:
+    /* Invite string */
+    silc_free(context);
+    break;
+  case 2:
+  case 3:
+    /* Public key/Channel ID SilcBuffer */
+    silc_buffer_free(context);
+    break;
+  default:
+    break;
+  }
+}
index e072df4473a358f298ec8a66fac0151e32660c11..393f09003e6f558b70cdfefe8be4c5956104e912 100644 (file)
@@ -203,4 +203,8 @@ bool silc_server_inviteban_match(SilcServer server, SilcHashTable list,
 void silc_server_inviteban_process(SilcServer server, SilcHashTable list,
                                   SilcUInt8 action, SilcArgumentPayload args);
 
+/* Destructor for invite or ban list entrys */
+void silc_server_inviteban_destruct(void *key, void *context,
+                                   void *user_context);
+
 #endif /* SERVER_UTIL_H */
index 73a38bfde43bba4a89a656b8cd95d75622496d76..911caff0dde735085b13ccc4fa628097740cbe6e 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "serverincludes.h"
 #include "server_internal.h"
+#include <dirent.h>
 
 #if 0
 #define SERVER_CONFIG_DEBUG(fmt) SILC_LOG_DEBUG(fmt)
@@ -118,7 +119,7 @@ my_find_param(SilcServerConfig config, const char *name)
 }
 
 /* parse an authdata according to its auth method */
-static bool my_parse_authdata(SilcAuthMethod auth_meth, char *p,
+static bool my_parse_authdata(SilcAuthMethod auth_meth, const char *p,
                              void **auth_data, SilcUInt32 *auth_data_len)
 {
   if (auth_meth == SILC_AUTH_PASSWORD) {
@@ -138,6 +139,7 @@ static bool my_parse_authdata(SilcAuthMethod auth_meth, char *p,
   } else if (auth_meth == SILC_AUTH_PUBLIC_KEY) {
     /* p is a public key file name */
     SilcPublicKey public_key;
+    SilcPublicKey cached_key;
 
     if (!silc_pkcs_load_public_key(p, &public_key, SILC_PKCS_FILE_PEM))
       if (!silc_pkcs_load_public_key(p, &public_key, SILC_PKCS_FILE_BIN)) {
@@ -146,6 +148,16 @@ static bool my_parse_authdata(SilcAuthMethod auth_meth, char *p,
        return FALSE;
       }
 
+    if (*auth_data &&
+       silc_hash_table_find_ext(*auth_data, public_key, (void **)&cached_key,
+                                NULL, silc_hash_public_key, NULL,
+                                silc_hash_public_key_compare, NULL)) {
+      silc_pkcs_public_key_free(public_key);
+      SILC_SERVER_LOG_WARNING(("Warning: public key file \"%s\" already "
+                              "configured, ignoring this key", p));
+      return TRUE; /* non fatal error */
+    }
+
     /* The auth_data is a pointer to the hash table of public keys. */
     if (auth_data) {
       if (*auth_data == NULL)
@@ -161,6 +173,47 @@ static bool my_parse_authdata(SilcAuthMethod auth_meth, char *p,
   return TRUE;
 }
 
+static bool my_parse_publickeydir(const char *dirname, void **auth_data)
+{
+  int total = 0;
+  struct dirent *get_file;
+  DIR *dp;
+
+  if (!(dp = opendir(dirname))) {
+    SILC_SERVER_LOG_ERROR(("Error while parsing config file: "
+                          "Could not open directory \"%s\"", dirname));
+    return FALSE;
+  }
+
+  /* errors are not considered fatal */
+  while ((get_file = readdir(dp))) {
+    const char *filename = get_file->d_name;
+    char buf[1024];
+    int dirname_len = strlen(dirname), filename_len = strlen(filename);
+    struct stat check_file;
+
+    /* Ignore "." and "..", and take files only with ".pub" suffix. */
+    if (!strcmp(filename, ".") || !strcmp(filename, "..") ||
+       (filename_len < 5) || strcmp(filename + filename_len - 4, ".pub"))
+      continue;
+
+    memset(buf, 0, sizeof(buf));
+    snprintf(buf, sizeof(buf) - 1, "%s%s%s", dirname,
+            (dirname[dirname_len - 1] == '/' ? "" : "/"), filename);
+
+    if (stat(buf, &check_file) < 0) {
+      SILC_SERVER_LOG_ERROR(("Error stating file %s: %s", buf,
+                            strerror(errno)));
+    } else if (S_ISREG(check_file.st_mode)) {
+      my_parse_authdata(SILC_AUTH_PUBLIC_KEY, buf, auth_data, NULL);
+      total++;
+    }
+  }
+
+  SILC_LOG_DEBUG(("Tried to load %d public keys in \"%s\"", total, dirname));
+  return TRUE;
+}
+
 /* Callbacks */
 
 SILC_CONFIG_CALLBACK(fetch_generic)
@@ -521,6 +574,7 @@ SILC_CONFIG_CALLBACK(fetch_serverinfo)
   }
   else if (!strcmp(name, "publickey")) {
     char *file_tmp = (char *) val;
+    CONFIG_IS_DOUBLE(server_info->public_key);
 
     /* try to load specified file, if fail stop config parsing */
     if (!silc_pkcs_load_public_key(file_tmp, &server_info->public_key,
@@ -533,6 +587,7 @@ SILC_CONFIG_CALLBACK(fetch_serverinfo)
   }
   else if (!strcmp(name, "privatekey")) {
     char *file_tmp = (char *) val;
+    CONFIG_IS_DOUBLE(server_info->private_key);
 
     /* try to load specified file, if fail stop config parsing */
     if (!silc_pkcs_load_private_key(file_tmp, &server_info->private_key,
@@ -752,6 +807,12 @@ SILC_CONFIG_CALLBACK(fetch_client)
       goto got_err;
     }
   }
+  else if (!strcmp(name, "publickeydir")) {
+    if (!my_parse_publickeydir((char *) val, (void **)&tmp->publickeys)) {
+      got_errno = SILC_CONFIG_EPRINTLINE;
+      goto got_err;
+    }
+  }
   else if (!strcmp(name, "params")) {
     CONFIG_IS_DOUBLE(tmp->param);
     tmp->param = my_find_param(config, (char *) val);
@@ -812,13 +873,18 @@ SILC_CONFIG_CALLBACK(fetch_admin)
     }
   }
   else if (!strcmp(name, "publickey")) {
-    CONFIG_IS_DOUBLE(tmp->publickeys);
     if (!my_parse_authdata(SILC_AUTH_PUBLIC_KEY, (char *) val,
                           (void **)&tmp->publickeys, NULL)) {
       got_errno = SILC_CONFIG_EPRINTLINE;
       goto got_err;
     }
   }
+  else if (!strcmp(name, "publickeydir")) {
+    if (!my_parse_publickeydir((char *) val, (void **)&tmp->publickeys)) {
+      got_errno = SILC_CONFIG_EPRINTLINE;
+      goto got_err;
+    }
+  }
   else
     return SILC_CONFIG_EINTERNAL;
   return SILC_CONFIG_OK;
@@ -1158,6 +1224,7 @@ static const SilcConfigTable table_client[] = {
   { "host",            SILC_CONFIG_ARG_STRE,   fetch_client,   NULL },
   { "passphrase",      SILC_CONFIG_ARG_STR,    fetch_client,   NULL },
   { "publickey",       SILC_CONFIG_ARG_STR,    fetch_client,   NULL },
+  { "publickeydir",    SILC_CONFIG_ARG_STR,    fetch_client,   NULL },
   { "params",          SILC_CONFIG_ARG_STR,    fetch_client,   NULL },
   { 0, 0, 0, 0 }
 };
@@ -1168,6 +1235,7 @@ static const SilcConfigTable table_admin[] = {
   { "nick",            SILC_CONFIG_ARG_STRE,   fetch_admin,    NULL },
   { "passphrase",      SILC_CONFIG_ARG_STR,    fetch_admin,    NULL },
   { "publickey",       SILC_CONFIG_ARG_STR,    fetch_admin,    NULL },
+  { "publickeydir",    SILC_CONFIG_ARG_STR,    fetch_admin,    NULL },
   { "port",            SILC_CONFIG_ARG_INT,    fetch_admin,    NULL },
   { "params",          SILC_CONFIG_ARG_STR,    fetch_admin,    NULL },
   { 0, 0, 0, 0 }
@@ -1235,6 +1303,82 @@ static void silc_server_config_set_defaults(SilcServerConfig config)
                               SILC_SERVER_CONNAUTH_TIMEOUT);
 }
 
+/* Check for correctness of the configuration */
+
+static bool silc_server_config_check(SilcServerConfig config)
+{
+  bool ret = TRUE;
+  SilcServerConfigServer *s;
+  SilcServerConfigRouter *r;
+  bool b = FALSE;
+
+  /* ServerConfig is mandatory */
+  if (!config->server_info) {
+    SILC_SERVER_LOG_ERROR(("\nError: Missing mandatory block `ServerInfo'"));
+    ret = FALSE;
+  }
+
+  /* RouterConnection sanity checks */
+
+  if (config->routers && config->routers->backup_router == TRUE &&
+      !config->servers) {
+    SILC_SERVER_LOG_ERROR((
+         "\nError: First RouterConnection block must be primary router "
+        "connection. You have marked it incorrectly as backup router."));
+    ret = FALSE;
+  }
+  if (config->routers && config->routers->initiator == FALSE &&
+      config->routers->backup_router == FALSE) {
+    SILC_SERVER_LOG_ERROR((
+         "\nError: First RouterConnection block must be primary router "
+        "connection and it must be marked as Initiator."));
+    ret = FALSE;
+  }
+  if (config->routers && config->routers->backup_router == TRUE &&
+      !config->servers && !config->routers->next) {
+    SILC_SERVER_LOG_ERROR((
+         "\nError: You have configured backup router but not primary router. "
+        "If backup router is configured also primary router must be "
+        "configured."));
+    ret = FALSE;
+  }
+
+  /* Backup router sanity checks */
+
+  for (r = config->routers; r; r = r->next) {
+    if (r->backup_router && !strcmp(r->host, r->backup_replace_ip)) {
+      SILC_SERVER_LOG_ERROR((
+          "\nError: Backup router connection incorrectly configured to use "
+         "primary and backup router as same host `%s'. They must not be "
+         "same host.", r->host));
+      ret = FALSE;
+    }
+  }
+  
+  /* ServerConnection sanity checks */
+  
+  for (s = config->servers; s; s = s->next) {
+    if (s->backup_router) {
+      b = TRUE;
+      break;
+    }
+  }
+  if (b) {
+    for (s = config->servers; s; s = s->next) {
+      if (!s->backup_router) {
+       SILC_SERVER_LOG_ERROR((
+          "\nError: Your server is backup router but not all ServerConnection "
+         "blocks were marked as backup connections. They all must be "
+         "marked as backup connections."));
+       ret = FALSE;
+       break;
+      }
+    }
+  }
+
+  return ret;
+}
+
 /* Allocates a new configuration object, opens configuration file and
    parses it. The parsed data is returned to the newly allocated
    configuration object. The SilcServerConfig must be freed by calling
@@ -1287,9 +1431,11 @@ SilcServerConfig silc_server_config_alloc(const char *filename)
         SILC_SERVER_LOG_ERROR(("Error while parsing config file: %s.",
                               silc_config_strerror(ret)));
       linebuf = silc_config_read_line(file, line);
-      SILC_SERVER_LOG_ERROR(("  file %s line %lu:  %s\n", filename,
-                            line, linebuf));
-      silc_free(linebuf);
+      if (linebuf) {
+       SILC_SERVER_LOG_ERROR(("  file %s line %lu:  %s\n", filename,
+                              line, linebuf));
+       silc_free(linebuf);
+      }
     }
     silc_server_config_destroy(config_new);
     return NULL;
@@ -1298,10 +1444,8 @@ SilcServerConfig silc_server_config_alloc(const char *filename)
   /* close (destroy) the file object */
   silc_config_close(file);
 
-  /* If config_new is incomplete, abort the object and return NULL */
-  if (!config_new->server_info) {
-    SILC_SERVER_LOG_ERROR(("\nError: Missing mandatory block "
-                          "`server_info'"));
+  /* Check the configuration */
+  if (!silc_server_config_check(config_new)) {
     silc_server_config_destroy(config_new);
     return NULL;
   }
index b0155df1edd9990043a43a63324a18cb3297812b..33a5043cc7ca12475dc117c538a5930024e62773 100644 (file)
@@ -305,6 +305,127 @@ SILC_TASK_CALLBACK(dump_stats)
 
 #undef STAT_OUTPUT
 
+#ifdef SILC_DEBUG
+  /* Dump lists */
+  {
+    SilcIDCacheList list = NULL;
+    SilcIDCacheEntry id_cache = NULL;
+    SilcServerEntry server_entry;
+    SilcClientEntry client_entry;
+    SilcChannelEntry channel_entry;
+    int c;
+
+    fprintf(fdd, "\nDumping databases\n");
+    
+    if (silc_idcache_get_all(silcd->local_list->servers, &list)) {
+      if (silc_idcache_list_first(list, &id_cache)) {
+       fprintf(fdd, "\nServers in local-list:\n");
+       c = 1;
+       while (id_cache) {
+         server_entry = (SilcServerEntry)id_cache->context;
+         fprintf(fdd, "  %d: name %s id %s status 0x%x\n", c,
+                 server_entry->server_name ? server_entry->server_name :
+                 "N/A", server_entry->id ?
+                 silc_id_render(server_entry->id, SILC_ID_SERVER) : "N/A",
+                 server_entry->data.status);
+         if (!silc_idcache_list_next(list, &id_cache))
+           break;
+         c++;
+       }
+      }
+      silc_idcache_list_free(list);
+    }
+    if (silc_idcache_get_all(silcd->global_list->servers, &list)) {
+      if (silc_idcache_list_first(list, &id_cache)) {
+       fprintf(fdd, "\nServers in global-list:\n");
+       c = 1;
+       while (id_cache) {
+         server_entry = (SilcServerEntry)id_cache->context;
+         fprintf(fdd, "  %d: name %s id %s status 0x%x\n", c,
+                 server_entry->server_name ? server_entry->server_name :
+                 "N/A", server_entry->id ?
+                 silc_id_render(server_entry->id, SILC_ID_SERVER) : "N/A",
+                 server_entry->data.status);
+         if (!silc_idcache_list_next(list, &id_cache))
+           break;
+         c++;
+       }
+      }
+      silc_idcache_list_free(list);
+    }
+    if (silc_idcache_get_all(silcd->local_list->clients, &list)) {
+      if (silc_idcache_list_first(list, &id_cache)) {
+       fprintf(fdd, "\nClients in local-list:\n");
+       c = 1;
+       while (id_cache) {
+         client_entry = (SilcClientEntry)id_cache->context;
+         fprintf(fdd, "  %d: name %s id %s status 0x%x\n", c,
+                 client_entry->nickname ? client_entry->nickname :
+                 (unsigned char *)"N/A", client_entry->id ?
+                 silc_id_render(client_entry->id, SILC_ID_CLIENT) : "N/A",
+                 client_entry->data.status);
+         if (!silc_idcache_list_next(list, &id_cache))
+           break;
+         c++;
+       }
+      }
+      silc_idcache_list_free(list);
+    }
+    if (silc_idcache_get_all(silcd->global_list->clients, &list)) {
+      if (silc_idcache_list_first(list, &id_cache)) {
+       fprintf(fdd, "\nClients in global-list:\n");
+       c = 1;
+       while (id_cache) {
+         client_entry = (SilcClientEntry)id_cache->context;
+         fprintf(fdd, "  %d: name %s id %s status 0x%x\n", c,
+                 client_entry->nickname ? client_entry->nickname :
+                 (unsigned char *)"N/A", client_entry->id ?
+                 silc_id_render(client_entry->id, SILC_ID_CLIENT) : "N/A",
+                 client_entry->data.status);
+         if (!silc_idcache_list_next(list, &id_cache))
+           break;
+         c++;
+       }
+      }
+      silc_idcache_list_free(list);
+    }
+    if (silc_idcache_get_all(silcd->local_list->channels, &list)) {
+      if (silc_idcache_list_first(list, &id_cache)) {
+       fprintf(fdd, "\nChannels in local-list:\n");
+       c = 1;
+       while (id_cache) {
+         channel_entry = (SilcChannelEntry)id_cache->context;
+         fprintf(fdd, "  %d: name %s id %s\n", c,
+                 channel_entry->channel_name ? channel_entry->channel_name :
+                 "N/A", channel_entry->id ?
+                 silc_id_render(channel_entry->id, SILC_ID_CHANNEL) : "N/A");
+         if (!silc_idcache_list_next(list, &id_cache))
+           break;
+         c++;
+       }
+      }
+      silc_idcache_list_free(list);
+    }
+    if (silc_idcache_get_all(silcd->global_list->channels, &list)) {
+      if (silc_idcache_list_first(list, &id_cache)) {
+       fprintf(fdd, "\nChannels in global-list:\n");
+       c = 1;
+       while (id_cache) {
+         channel_entry = (SilcChannelEntry)id_cache->context;
+         fprintf(fdd, "  %d: name %s id %s\n", c,
+                 channel_entry->channel_name ? channel_entry->channel_name :
+                 "N/A", channel_entry->id ?
+                 silc_id_render(channel_entry->id, SILC_ID_CHANNEL) : "N/A");
+         if (!silc_idcache_list_next(list, &id_cache))
+           break;
+         c++;
+       }
+      }
+      silc_idcache_list_free(list);
+    }
+  }
+#endif
+
   fflush(fdd);
   fclose(fdd);
 }
@@ -389,10 +510,10 @@ static void silc_get_debug_level(int level)
     }
 }
 
-/* This function should not be called directly but thru the wrapper
-   macro SILC_SERVER_LOG_STDERR() */
+/* This function should not be called directly but through the appropriate
+   wrapper macro defined in server.h */
 
-void silc_server_stderr(char *message)
+void silc_server_stderr(SilcLogType type, char *message)
 {
   if (silcd->background) {
     char *p, *n = message;
@@ -407,7 +528,8 @@ void silc_server_stderr(char *message)
     }
     *n = 0;
 
-    silc_log_output(SILC_LOG_ERROR, message);
+    /* the message is freed inside the logging function */
+    silc_log_output(type, message);
   }
   else {
     fprintf(stderr, "%s\n", message);
index 56728edaf5ea95da9fef1a9524aa927442914e9b..671dac894b0f2fabe6e7c1f8ce2c30b203f3873e 100644 (file)
@@ -60,12 +60,54 @@ if test "$GCC"; then
   CFLAGS="-Wall -finline-functions $CFLAGS"
 fi
 
+#
+# Library versioning.
+#
+# Do the releases and library versioning according to following rules:
+#
+#  - If any code has changed in library, increment [LIB]_REVISION
+#  - If functions were added, set [LIB]_REVISION to 0
+#  - If functions were added, removed or changed, increment [LIB]_CURRENT
+#  - If functions were added, increment [LIB]_AGE
+#  - If functions were removed, set [LIB]_AGE to 0
+#
+# where [LIB] is LIBSILC and LIBSILCCLIENT, and where "functions" means
+# functions public interfaces.
+#
+# The LIB_BASE_VERSION defines the SILC software major.minor version and 
+# it is increment only when these version numbers actually change.
+#
+
+# Base version for libraries.  Do not change this unless SILC version
+# changes too.
+LIB_BASE_VERSION=1.0
+
+# libsilc versions
+LIBSILC_CURRENT=1
+LIBSILC_REVISION=0
+LIBSILC_AGE=1
+
+# libsilcclient versions
+LIBSILCCLIENT_CURRENT=1
+LIBSILCCLIENT_REVISION=1
+LIBSILCCLIENT_AGE=0
+
+# Substitute the version numbers
+AC_SUBST(LIB_BASE_VERSION)
+AC_SUBST(LIBSILC_CURRENT)
+AC_SUBST(LIBSILC_REVISION)
+AC_SUBST(LIBSILC_AGE)
+AC_SUBST(LIBSILCCLIENT_CURRENT)
+AC_SUBST(LIBSILCCLIENT_REVISION)
+AC_SUBST(LIBSILCCLIENT_AGE)
+
 #
 # Program checking
 #
 AC_PROG_INSTALL
 AC_PROG_RANLIB
 AC_PROG_MAKE_SET
+AC_DISABLE_SHARED
 AC_PROG_LIBTOOL
 AC_PATH_PROG(sedpath, sed)
 
@@ -133,20 +175,21 @@ sim_support=false
 AC_MSG_CHECKING(for SIM support)
 AC_MSG_RESULT()
 AC_CHECK_HEADERS(dlfcn.h,
-  AC_CHECK_LIB(dl, dlopen,
-    [
-      AC_DEFINE(SILC_SIM)
-      sim_support=true
-      LIBS="$LIBS -ldl"
-    ],
-    [
-      AC_CHECK_LIB(c, dlopen,
-        [
-          AC_DEFINE(SILC_SIM)
-          sim_support=true
-        ])
-    ])
-  )
+  [
+    AC_CHECK_LIB(dl, dlopen,
+      [
+        AC_DEFINE(SILC_SIM)
+        sim_support=true
+        LIBS="$LIBS -ldl"
+      ],
+      [
+        AC_CHECK_LIB(c, dlopen,
+          [
+            AC_DEFINE(SILC_SIM)
+            sim_support=true
+          ])
+      ])
+   ])
 
 AM_CONDITIONAL(SILC_SIM, test x$sim_support = xtrue)
 if test x$sim_support = xtrue; then
@@ -606,13 +649,14 @@ AC_ARG_WITH(iconv,
     case "${withval}" in
       no)
         AC_MSG_RESULT(no)
-
-        AC_CHECK_HEADERS(iconv.h, AC_CHECK_FUNC(iconv, has_iconv=true))
+        AC_CHECK_HEADERS(iconv.h,
+          [
+            AC_CHECK_FUNC(iconv, has_iconv=true)
+          ])
         check_iconv=false
         ;;
       *)
         AC_MSG_RESULT(yes)
-
         if test -d $withval/include; then
           CPPFLAGS="$CPPFLAGS -I$withval/include"
           CFLAGS="$CFLAGS -I$withval/include"
@@ -620,16 +664,19 @@ AC_ARG_WITH(iconv,
         if test -d $withval/lib; then
           LDFLAGS="$LDFLAGS -L$withval/lib"
         fi
+        ;;
     esac
   ],
   [
     AC_MSG_RESULT(no)
-
-    AC_CHECK_HEADERS(iconv.h, AC_CHECK_FUNCS(iconv,
-                                [
-                                  has_iconv=true
-                                  check_iconv=false
-                                 ]))
+    AC_CHECK_HEADERS(iconv.h,
+      [
+        AC_CHECK_FUNCS(iconv,
+          [
+            has_iconv=true
+            check_iconv=false
+          ])
+      ])
   ])
 
 if test x$check_iconv = xtrue; then
@@ -950,6 +997,22 @@ AC_ARG_WITH(silcd,
     AC_MSG_RESULT(yes)
   ])
 
+libtoolfix=true
+AC_MSG_CHECKING(whether to do libtoolfix)
+AC_ARG_WITH(libtoolfix,
+  [  --without-libtoolfix     Do not fix libtool, for package builders],
+  [
+    AC_MSG_RESULT(no)
+    libtoolfix=false
+  ],
+  [
+    AC_MSG_RESULT(yes)
+  ])
+
+AC_SUBST(ETCDIR)
+AC_DEFINE_UNQUOTED(SILC_ETCDIR, "$ETCDIR")
+
+
 
 ##
 ##  Misc
@@ -979,6 +1042,18 @@ INCLUDE_DEFINES_INT="include \$(top_srcdir)/Makefile.defines_int"
 AC_SUBST(INCLUDE_DEFINES_INT)
 AC_SUBST(SILC_DIST_SUBDIRS)
 
+#
+# Fix the libtool to support run-time configuration.  This allows us
+# to in run-time specify when to compile shared/static libraries without
+# need to reconfigure the entire libtool.
+#
+if test x$libtoolfix = xtrue; then
+  ./libtoolfix $SILC_TOP_SRCDIR/ltmain.sh
+fi
+AM_CONDITIONAL(SILC_LIBTOOLFIX, test x$libtoolfix = xtrue)
+
+
+#
 # Makefile outputs
 #
 AC_CONFIG_FILES(
@@ -990,7 +1065,9 @@ includes/Makefile
 lib/Makefile
 lib/contrib/Makefile
 lib/silccore/Makefile
+lib/silccore/tests/Makefile
 lib/silccrypt/Makefile
+lib/silccrypt/tests/Makefile
 lib/silcmath/Makefile
 lib/silcmath/mpi/Makefile.defines
 lib/silcmath/mpi/Makefile.defines_int
@@ -1085,7 +1162,7 @@ if test "x$silc_dist" = "xsilc-server" ||
    test "x$silc_dist" = "xsilc-toolkit"; then
   silcd="yes"
   if test x$without_silcd = xtrue; then
-    without_silcd="no"
+    silcd="no"
   fi
 echo " Compile SILC Server ...........: $silcd"
 echo " Server configuration file .....: $summary_silcd_configfile"
index e0733aee8c7f75ecbc9a6a9c8164b9eeb600f588..6fc615506e43700d894840a5567bad01b4f7b374 100644 (file)
@@ -28,7 +28,7 @@ all:
        touch draft-riikonen-silc-pp-06.txt
        touch draft-riikonen-silc-ke-auth-06.txt
        touch draft-riikonen-silc-commands-04.txt
-       touch draft-riikonen-silc-flags-payloads-01.txt
+       touch draft-riikonen-silc-flags-payloads-02.txt
        touch draft-riikonen-presence-attrs-01.txt
 
 if SILC_DIST_TOOLKIT
@@ -60,7 +60,7 @@ dist-hook:
        touch draft-riikonen-silc-pp-06.txt
        touch draft-riikonen-silc-ke-auth-06.txt
        touch draft-riikonen-silc-commands-04.txt
-       touch draft-riikonen-silc-flags-payloads-01.txt
+       touch draft-riikonen-silc-flags-payloads-02.txt
        touch draft-riikonen-presence-attrs-01.txt
        $(makerfc) draft-riikonen-silc-spec-06.nroff \
                draft-riikonen-silc-spec-06.txt
@@ -70,8 +70,8 @@ dist-hook:
                draft-riikonen-silc-ke-auth-06.txt
        $(makerfc) draft-riikonen-silc-commands-04.nroff \
                draft-riikonen-silc-commands-04.txt
-       $(makerfc) draft-riikonen-silc-flags-payloads-01.nroff \
-               draft-riikonen-silc-flags-payloads-01.txt
+       $(makerfc) draft-riikonen-silc-flags-payloads-02.nroff \
+               draft-riikonen-silc-flags-payloads-02.txt
        $(makerfc) draft-riikonen-presence-attrs-01.nroff \
                draft-riikonen-presence-attrs-01.txt
 
@@ -83,7 +83,7 @@ dist-hook:
        touch draft-riikonen-silc-pp-06.txt
        touch draft-riikonen-silc-ke-auth-06.txt
        touch draft-riikonen-silc-commands-04.txt
-       touch draft-riikonen-silc-flags-payloads-01.txt
+       touch draft-riikonen-silc-flags-payloads-02.txt
        touch draft-riikonen-presence-attrs-01.txt
 endif
 
diff --git a/doc/draft-riikonen-silc-flags-payloads-02.nroff b/doc/draft-riikonen-silc-flags-payloads-02.nroff
new file mode 100644 (file)
index 0000000..f1fcc87
--- /dev/null
@@ -0,0 +1,421 @@
+.pl 10.0i
+.po 0
+.ll 7.2i
+.lt 7.2i
+.nr LL 7.2i
+.nr LT 7.2i
+.ds LF Riikonen
+.ds RF FORMFEED[Page %]
+.ds CF
+.ds LH Internet Draft
+.ds RH 7 December 2002
+.ds CH
+.na
+.hy 0
+.in 0
+.nf
+Network Working Group                                        P. Riikonen
+Internet-Draft
+draft-riikonen-flags-payloads-02.txt                     7 December 2003
+Expires: 7 May 2003
+
+.in 3
+
+.ce 2
+SILC Message Flag Payloads
+<draft-riikonen-flags-payloads-02.txt>
+
+.ti 0
+Status of this Memo
+
+This document is an Internet-Draft and is in full conformance with   
+all provisions of Section 10 of RFC 2026.  Internet-Drafts are   
+working documents of the Internet Engineering Task Force (IETF), its   
+areas, and its working groups.  Note that other groups may also   
+distribute working documents as Internet-Drafts.   
+
+Internet-Drafts are draft documents valid for a maximum of six months   
+and may be updated, replaced, or obsoleted by other documents at any   
+time.  It is inappropriate to use Internet-Drafts as reference   
+material or to cite them other than as "work in progress."   
+
+The list of current Internet-Drafts can be accessed at   
+http://www.ietf.org/ietf/1id-abstracts.txt   
+
+The list of Internet-Draft Shadow Directories can be accessed at   
+http://www.ietf.org/shadow.html   
+
+The distribution of this memo is unlimited.  
+
+
+.ti 0
+Abstract
+
+This memo describes the data payloads associated with the SILC Message
+Flags, as defined in the SILC Packet Protocol Internet Draft [SILC2].  The 
+purpose of the Message Flags is to augment the function of the Message
+Payload used to send both private and channel messages, by allowing the
+sender to tell the receiver what type of data the payload includes, and
+how the data should be processed.  Some of the Message Flags may define
+additional payloads to be associated with the flag, and this memo
+describes these payloads.
+
+
+
+
+
+
+
+
+.ti 0
+Table of Contents
+
+.nf
+1 Introduction ..................................................  2
+  1.1 Requirements Terminology ..................................  2
+2 SILC Message Flags ............................................  2
+3 SILC Message Flag Payloads ....................................  3
+  3.1 SILC_MESSAGE_FLAG_REQUEST .................................  3
+  3.2 SILC_MESSAGE_FLAG_REPLY ...................................  3
+  3.3 SILC_MESSAGE_FLAG_SIGNED ..................................  4
+  3.4 SILC_MESSAGE_FLAG_DATA ....................................  6
+4 Security Considerations .......................................  7
+5 References ....................................................  7
+6 Author's Address ..............................................  8
+
+
+.ti 0
+1. Introduction
+
+The Secure Internet Live Conferencing [SILC1] supports sending binary
+messages between users in the network.  To make the data sending, and
+processing at the receiver's end as simple as possible the SILC defines
+Message Flags to the Message Payload [SILC2] that is used to send private
+and channel messages, which can help the receiver to decide how the data
+is encoded, and how it should be interpreted.  Some of the Message Flags
+may define additional payloads to be associated with the flag, but the
+[SILC2] does not define them.  This memo defines the payloads for those
+Message Flags that was marked to include additional payloads in [SILC2].
+
+By defining the payloads for the Message Flags the Message Payload
+can be augmented to support any kind of data, which can be easily 
+interpreted at the receiver end.  For example, it would be possible to 
+send audio stream, video stream, image files and HTML pages as messages, 
+and the receiver can either choose to ignore the message or to process 
+it, or to perhaps pass the message to some application for processing.
+Without specific payloads for Message Flags it is almost impossible for 
+the receiver to interpret binary data from the payload.
+
+
+.ti 0
+1.1 Requirements Terminology
+  
+The keywords MUST, MUST NOT, REQUIRED, SHOULD, SHOULD NOT, RECOMMENDED,
+MAY, and OPTIONAL, when they appear in this document, are to be
+interpreted as described in [RFC2119].
+
+
+.ti 0
+2 SILC Message Flags
+
+The Message Flags was added to the SILC protocol for the reason that SILC
+provides sending binary data as messages between users, and entities in
+the network, and interpreting pure binary data is almost impossible.  
+With the flags the purpose, the reason, and the way the message is
+supposed to be interpreted can be told to the recipient.  Other
+conferencing protocols which are usually ASCII based protocols do not have
+such problems since they do not generally support sending of binary data
+at all, or require encoding of the data before it can be sent over the
+network.
+
+The Message Payload in SILC can have flags that can augment the function
+of the payload.  The flags can tell for example that the message is a
+request, or a reply to an earlier received request.  They can tell that
+the message is some action that the sender is performing, or they can tell
+that the message is an auto reply, or that it is explicitly digitally
+signed by the sender.
+
+The problem of Message Flags is that the space for flags mask is only 16
+bits, so there is a limited number of flags available.  For this reason a
+flag that defines some generic way of sending any kind of data as a
+message, and that it can be easily interpreted at the receiver's end is
+important.  For this reason the flag SILC_MESSAGE_FLAG_DATA was added to
+the protocol which can represent any data.  This memo describe how this 
+flag is used and how the associated payload is constructed and processed.  
+This memo also describes payloads for all the other flags that can have 
+associated payloads.
+
+
+.ti 0
+3 SILC Message Flag Payloads
+
+The [SILC2] defines the flags which may have associated payloads.  This 
+section will list these flags and define the payloads.
+
+
+.ti 0
+3.1 SILC_MESSAGE_FLAG_REQUEST
+
+Currently this flag can be used in the context of application specific, 
+service specific or vendor specific requests, and the data payload type is 
+dependent of this context.  Therefore, payload is not defined for this 
+flag in this memo.  This flag may also be masked with some other flag in 
+the message payload, including with some other flag that defines 
+additional payload.
+
+
+.ti 0
+3.2 SILC_MESSAGE_FLAG_REPLY
+
+Currently this flag can be used in the context of application specific, 
+service specific or vendor specific replies, and the data payload type is 
+dependent of this context.  Therefore, payload is not defined for this 
+flag in this memo.  This flag may also be masked with some other flag in  
+the message payload, including with some other flag that defines 
+additional payload.
+
+
+.ti 0
+3.3 SILC_MESSAGE_FLAG_SIGNED
+
+This flag is used to tell the recipient that the sent message is
+digitally signed by the sender, and that the recipient should verify
+the signature to verify the true authenticity of the received message.
+All message payloads in SILC provides message authentication code (MAC)
+which can be used to verify that the sender produced and sent the message.
+Even so, signing messages digitally can be used to verify the authenticity
+of the message when recipient trusts the sender.
+
+This flag defines a payload which is used to deliver the actual message,
+sender's public key and the digital signature.  The payload for
+SILC_MESSAGE_FLAG_SIGNED is as follows:
+
+.in 5
+.nf
+                     1                   2                   3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+|                                                               |
+~                   Start of Message Payload                    ~
+|                                                               |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+|                                                               |
+~                      Public Key Payload                       ~
+|                                                               |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+|     Signature Data Length     |                               |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               +
+|                                                               |
+~                        Signature Data                         ~
+|                                                               |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+|                                                               |
+~                       Initial Vector *                        ~
+|                                                               |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+|                                                               |
+~                              MAC *                            ~
+|                                                               |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+.in 3
+
+.ce
+Figure 1:  SILC_MESSAGE_FLAG_SIGNED Payload
+
+
+.in 6
+o Start of Message Payload (variable length) - This is the
+  start of the Message Payload without the IV and MAC fields,
+  since those fields are appended at the end of this payload.
+
+o Public Key Payload (variable length) - This includes the
+  Public Key Payload [SILC2] which can be used to deliver the
+  sender's public key (or certificate).  It also indicates the
+  type of the public key (or certificate) which the recipient
+  use to identify how the signature must be verified.  This
+  payload must always be present but it is not required to
+  include the public key data.  The Public Key Type field in
+  the Public Key Payload MUST be set to the correct type of
+  the key, even if the actual public key data is not included.
+
+o Signature Data Length (2 bytes) - Indicates the length of
+  the Signature Data field not including any other field.
+
+o Signature Data (variable length) - Includes the actual
+  signature data.  The signature computation and encoding
+  is key type specific.  See [SILC3] for all key types, and
+  their respective references of how to compute and encode
+  the signature.
+
+o Initial Vector (variable length) - the IV of the Message
+  Payload as defined in [SILC2].  This field is not encrypted.
+
+o MAC (variable length) - the MAC of the Message Payload as
+  defined in [SILC2].  The MAC is computed after encryption
+  and after signature computation.  All data in the Message
+  Payload and this payload, including the IV field are
+  included in the MAC computation.  This field is not
+  encrypted.
+.in 3
+
+How the data is processed before it is signed is key type specific.
+The actual data that to be signed MUST be the plaintext message
+payload before encryption.  The data to be signed is concatenation
+of the Start of Message Payload field and the Public Key Payload,
+in that order.  Any other fields are not included for signature data.
+Before signing, the data is always processed, usually hashed.  The
+hash function to be used is defined in the key type specific
+definitions.  See the key type specific references in [SILC3].
+
+If the public key of the sender is included in the payload the
+recipient SHOULD verify it before accepting the public key.  Recipient
+SHOULD verify the signature before accepting a public key.  With
+certificates the certificate verification may be done before
+verifying the signature.  If the signature verification fails the
+message should still be displayed.  The end user should also be
+notified about the result of the signature verification.
+
+To make the packet size smaller implementations may not want to
+include the actual public key in all signed messages.  Sending the
+public key in the first message is usually sufficient.  Subsequent
+messages may include empty Public Key Payload with an indication of
+the public key type.
+
+Implementations that do not support this flag can still process the
+message payload in normal manner.  These implementations merely parse
+the decrypted payload in normal manner and ignore the extra data in
+the payload.
+
+This flag MAY be masked with any other Message Flag including those that
+define additional payloads.  As long as the defined payload resides in
+the data area of the message payload this flag may be masked with the
+other flags.
+
+
+
+.ti 0
+3.4 SILC_MESSAGE_FLAG_DATA
+
+This flag is used to represent any data as a message in the way that it
+can be easily interpreted by the recipient.  This flag is used to send
+MIME objects as messages from the sender to the receiver.  The MIME as
+defined in [RFC2045], [RFC2046], [RFC2047], [RFC2048] and [RFC2049] is
+well established protocol for sending different kind of data with many
+applications and protocols.  It support dozens of different media types
+and encodings, and for this reason is ideal for sending data in SILC
+message payloads as well.
+
+When the receiver has checked that the message payload includes the 
+SILC_MESSAGE_FLAG_DATA flag, it may then start parsing the MIME header.  
+It would also be possible to pass the message to some application which 
+can already interpret MIME objects.  If the receiver does not support the 
+media type received in the MIME header, it SHOULD be treated as
+"application/octet-stream".  The receiver MAY also ignore and discard 
+messages that it does not support.
+
+The MIME header MUST be at the start of the data area of the Message
+Payload.  The MIME header received in the data area of the payload SHOULD
+have the MIME-Version field at first and then Content-Type field.  The
+MIME-Version field is not required to be present in each body part of
+multipart entity.  Additionally the header MAY also include any other
+MIME compliant headers.  The character encoding for the MIME Header
+strings inside the message payload is US-ASCII, as defined in [RFC2045].
+The actual MIME object may define additional character sets or encodings
+for the data it delivers.
+
+Hence, the MIME Header in the message payload may be as follows:
+
+.in 8
+.nf
+MIME-Version: 1.0\\r\\n
+Content-Type: discrete/composite\\r\\n
+Content-Transfer-Encoding: binary\\r\\n
+\\r\\n
+.in 3
+
+The Content-Transfer-Encoding field behaves as defined in [RFC2045] and 
+defines the encoding of the data in the MIME object.  The preferred data 
+encoding with SILC is "binary".  However, many MIME media types defines 
+their preferred encoding and they may be used if binary encoding is not 
+suitable.
+
+When sending large amounts of traffic or large files as MIME objects the 
+limits of the SILC Packet needs to be taken into consideration.  The 
+maximum length of SILC Packet is 2^16 bytes, and larger messages would 
+need to be fragmented.  MIME provides way of fragmenting and reassembling
+messages, and it is to be done with SILC as defined in [RFC2046].  The 
+MIME fragmentation is defined for gateway usage, but in case of SILC the 
+sender may also start sending fragmented MIME objects.
+
+This flag SHOULD NOT be masked with some other Message Flag that defines 
+payloads for message data.  Generally this sort of setting would be
+impossible for the receiver to interpret.  However, flags that does not
+define any specific payloads MAY be masked with this flag as well.  For
+example, this flag could be masked also with SILC_MESSAGE_FLAG_REQUEST flag.
+It also can be masked with SILC_MESSAGE_FLAG_SIGNED flag since it does not
+define data specific payload.
+
+
+.ti 0
+4 Security Considerations
+
+In case of SILC_MESSAGE_FLAG_DATA the implementors should pay special
+attention to the security implications of any media type that can cause
+the remote execution of any actions in the receiver's environment.  The
+[RFC2046] and [RFC2048] discusses more MIME specific security
+considerations.  Even though SILC provides secured messages, in case of
+MIME which can be used to transfer files and documents which are stored in
+the receiver's local environment, securing separately the MIME object may
+be desired.  For example, augmenting the MIME support in SILC messages to
+support S/MIME may be desired in some implementations.
+
+
+
+.ti 0
+5 References 
+
+[SILC1]      Riikonen, P., "Secure Internet Live Conferencing (SILC),
+             Protocol Specification", Internet Draft, May 2002.
+
+[SILC2]      Riikonen, P., "SILC Packet Protocol", Internet Draft,
+             May 2002.
+
+[SILC3]      Riikonen, P., "SILC Key Exchange and Authentication 
+             Protocols", Internet Draft, May 2002.
+
+[RFC2045]    Freed, N., et al., "Multipurpose Internet Mail Extensions 
+             (MIME) Part One: Format of Internet Message Bodies",
+             Standards Track, RFC 2045, November 1996.
+
+[RFC2046]    Freed, N., et al., "Multipurpose Internet Mail Extensions 
+             (MIME) Part Two: Media Types", Standards Track, RFC 2045, 
+             November 1996.
+
+[RFC2047]    Moore K., "MIME (Multipurpose Internet Mail Extensions) 
+             Part Three: Message Header Extensions for Non-ASCII Text"
+             Standards Track, RFC 2047, November 1996.
+
+[RFC2048]    Freed, N., et al., "Multipurpose Internet Mail Extensions
+             (MIME) Part Four: Registration Procedures", Standards 
+             Track, RFC 2048, November 1996.
+
+[RFC2049]    Freed, N., et al., "Multipurpose Internet Mail Extensions
+             (MIME) Part Five: Conformance Criteria and Examples", 
+             Standards Track, RFC 2049, November 1996.
+
+[RFC2119]    Bradner, S., "Key Words for use in RFCs to Indicate
+             Requirement Levels", BCP 14, RFC 2119, March 1997.
+
+
+
+.ti 0
+6 Author's Address
+
+Pekka Riikonen
+Snellmaninkatu 34 A 15
+70100 Kuopio
+Finland
+
+EMail: priikone@iki.fi
+
+This Internet-Draft expires 7 May 2003
diff --git a/doc/draft-riikonen-silc-spec-07.nroff b/doc/draft-riikonen-silc-spec-07.nroff
new file mode 100644 (file)
index 0000000..077cda3
--- /dev/null
@@ -0,0 +1,2517 @@
+.pl 10.0i
+.po 0
+.ll 7.2i
+.lt 7.2i
+.nr LL 7.2i
+.nr LT 7.2i
+.ds LF Riikonen
+.ds RF FORMFEED[Page %]
+.ds CF
+.ds LH Internet Draft
+.ds RH XXX
+.ds CH
+.na
+.hy 0
+.in 0
+.nf
+Network Working Group                                        P. Riikonen
+Internet-Draft
+draft-riikonen-silc-spec-06.txt                         XXX
+Expires: XXX
+
+.in 3
+
+.ce 3
+Secure Internet Live Conferencing (SILC),
+Protocol Specification
+<draft-riikonen-silc-spec-07.txt>
+
+.ti 0
+Status of this Memo
+
+This document is an Internet-Draft and is in full conformance with   
+all provisions of Section 10 of RFC 2026.  Internet-Drafts are   
+working documents of the Internet Engineering Task Force (IETF), its   
+areas, and its working groups.  Note that other groups may also   
+distribute working documents as Internet-Drafts.   
+
+Internet-Drafts are draft documents valid for a maximum of six months   
+and may be updated, replaced, or obsoleted by other documents at any   
+time.  It is inappropriate to use Internet-Drafts as reference   
+material or to cite them other than as "work in progress."   
+
+The list of current Internet-Drafts can be accessed at   
+http://www.ietf.org/ietf/1id-abstracts.txt   
+
+The list of Internet-Draft Shadow Directories can be accessed at   
+http://www.ietf.org/shadow.html   
+
+The distribution of this memo is unlimited.  
+
+
+.ti 0
+Abstract
+
+This memo describes a Secure Internet Live Conferencing (SILC)
+protocol which provides secure conferencing services over insecure
+network channel.  SILC is IRC [IRC] like protocol, however, it is 
+not equivalent to IRC and does not support IRC.  Strong cryptographic
+methods are used to protect SILC packets inside the SILC network.
+Three other Internet Drafts relates very closely to this memo;
+SILC Packet Protocol [SILC2], SILC Key Exchange and Authentication
+Protocols [SILC3] and SILC Commands [SILC4].
+
+
+
+
+
+
+.ti 0
+Table of Contents
+
+.nf
+1 Introduction ..................................................  3
+  1.1 Requirements Terminology ..................................  4
+2 SILC Concepts .................................................  4
+  2.1 SILC Network Topology .....................................  4
+  2.2 Communication Inside a Cell ...............................  6
+  2.3 Communication in the Network ..............................  6
+  2.4 Channel Communication .....................................  7
+  2.5 Router Connections ........................................  8
+3 SILC Specification ............................................  8
+  3.1 Client ....................................................  9
+      3.1.1 Client ID ...........................................  9
+  3.2 Server .................................................... 10
+      3.2.1 Server's Local ID List .............................. 10
+      3.2.2 Server ID ........................................... 11
+      3.2.3 SILC Server Ports ................................... 12
+  3.3 Router .................................................... 12
+      3.3.1 Router's Local ID List .............................. 13
+      3.3.2 Router's Global ID List ............................. 13
+      3.3.3 Router's Server ID .................................. 14
+  3.4 Channels .................................................. 14
+      3.4.1 Channel ID .......................................... 15
+  3.5 Operators ................................................. 16
+  3.6 SILC Commands ............................................. 16
+  3.7 SILC Packets .............................................. 17
+  3.8 Packet Encryption ......................................... 17
+      3.8.1 Determination of the Source and the Destination ..... 18
+      3.8.2 Client To Client .................................... 18
+      3.8.3 Client To Channel ................................... 20
+      3.8.4 Server To Server .................................... 20
+  3.9 Key Exchange And Authentication ........................... 20
+      3.9.1 Authentication Payload .............................. 21
+  3.10 Algorithms ............................................... 23
+      3.10.1 Ciphers ............................................ 23
+             3.10.1.1 CBC Mode .................................. 24
+             3.10.1.2 CTR Mode .................................. 24
+             3.10.1.3 Randomized CBC Mode ....................... 25
+      3.10.2 Public Key Algorithms .............................. 26
+      3.10.3 Hash Functions ..................................... 26
+      3.10.4 MAC Algorithms ..................................... 27
+      3.10.5 Compression Algorithms ............................. 27
+  3.11 SILC Public Key .......................................... 28
+  3.12 SILC Version Detection ................................... 30
+  3.13 Backup Routers ........................................... 31
+      3.13.1 Switching to Backup Router ......................... 32
+      3.13.2 Resuming Primary Router ............................ 33
+      3.13.3 Discussion on Backup Router Scheme ................. 36
+4 SILC Procedures ............................................... 36
+  4.1 Creating Client Connection ................................ 36
+  4.2 Creating Server Connection ................................ 38
+      4.2.1 Announcing Clients, Channels and Servers ............ 38
+  4.3 Joining to a Channel ...................................... 39
+  4.4 Channel Key Generation .................................... 41
+  4.5 Private Message Sending and Reception ..................... 41
+  4.6 Private Message Key Generation ............................ 42
+  4.7 Channel Message Sending and Reception ..................... 43
+  4.8 Session Key Regeneration .................................. 43
+  4.9 Command Sending and Reception ............................. 44
+  4.10 Closing Connection ....................................... 45
+  4.11 Detaching and Resuming a Session ......................... 45
+5 Security Considerations ....................................... 47
+6 References .................................................... 48
+7 Author's Address .............................................. 49
+
+
+.ti 0
+List of Figures
+
+.nf
+Figure 1:  SILC Network Topology
+Figure 2:  Communication Inside cell
+Figure 3:  Communication Between Cells
+Figure 4:  Router Connections
+Figure 5:  SILC Public Key
+Figure 6:  Counter Block
+
+
+.ti 0
+1. Introduction
+
+This document describes a Secure Internet Live Conferencing (SILC)
+protocol which provides secure conferencing services over insecure
+network channel.  SILC is IRC [IRC] like protocol, however, it is 
+not equivalent to IRC and does not support IRC.  Some of the SILC's
+features are not found in IRC but in traditional Instant Message (IM)
+protocols.  SILC combines features from both of these chat protocol
+styles, and SILC can be implemented as either IRC-like system or
+IM-like system.
+
+Strong cryptographic methods are used to protect SILC packets inside
+the SILC network.  Three other Internet Drafts relates very closely
+to this memo; SILC Packet Protocol [SILC2], SILC Key Exchange and
+Authentication Protocols [SILC3] and SILC Commands [SILC4].
+
+The protocol uses extensively packets as conferencing protocol 
+requires message and command sending.  The SILC Packet Protocol is
+described in [SILC2] and should be read to fully comprehend this
+document and protocol.  [SILC2] also describes the packet encryption
+and decryption in detail.  The SILC Packet Protocol provides secured
+and authenticated packets, and the protocol is designed to be compact.
+This makes SILC also suitable in environment of low bandwidth
+requirements such as mobile networks.  All packet payloads in SILC
+can be also compressed.
+
+The security of SILC protocol, and for any security protocol for that
+matter, is based on strong and secure key exchange protocol.  The SILC
+Key Exchange protocol is described in [SILC3] along with connection
+authentication protocol and should be read to fully comprehend this
+document and protocol.
+
+The SILC protocol has been developed to work on TCP/IP network
+protocol, although it could be made to work on other network protocols
+with only minor changes.  However, it is recommended that TCP/IP
+protocol is used under SILC protocol.  Typical implementation would
+be made in client-server model.
+
+
+.ti 0
+1.1 Requirements Terminology
+
+The keywords MUST, MUST NOT, REQUIRED, SHOULD, SHOULD NOT, RECOMMENDED, 
+MAY, and OPTIONAL, when they appear in this document, are to be
+interpreted as described in [RFC2119].
+
+
+.ti 0
+2. SILC Concepts
+
+This section describes various SILC protocol concepts that forms the 
+actual protocol, and in the end, the actual SILC network.  The mission
+of the protocol is to deliver messages from clients to other clients 
+through routers and servers in secure manner.  The messages may also 
+be delivered from one client to many clients forming a group, also 
+known as a channel.
+
+This section does not focus to security issues.  Instead, basic network 
+concepts are introduced to make the topology of the SILC network 
+clear.
+
+
+.ti 0
+2.1 SILC Network Topology
+
+SILC network forms a ring as opposed to tree style network topology that
+conferencing protocols usually have.  The network has a cells which are 
+constructed from router and zero or more servers.  The servers are 
+connected to the router in a star like network topology.  Routers in the 
+network are connected to each other forming a ring.  The rationale for 
+this is to have servers that can perform specific kind of tasks what 
+other servers cannot perform.  This leads to two kinds of servers; normal 
+SILC servers and SILC routers.
+
+A difference between normal server and router server is that routers 
+knows everything about everything in the network.  They also do the 
+actual routing of the messages to the correct receiver.  Normal servers 
+knows only about local information and nothing about global information.
+This makes the network faster as there are less servers that needs to 
+keep global information up to date at all time.
+
+This, on the other hand, leads to kind of a cellular like network, where
+routers are in the center of the cell and servers are connected to the
+router.
+
+The following diagram represents SILC network topology.
+
+.in 8
+.nf
+  ---- ---- ----         ---- ---- ----
+ | S8 | S5 | S4 |       | S7 | S5 | S6 |
+ ----- ---- -----       ----- ---- -----
+| S7 | S/R1 | S2 | --- | S8 | S/R2 | S4 |
+ ---- ------ ----       ---- ------ ----
+ | S6 | S3 | S1 |       | S1 | S3 | S2 |         ---- ----
+  ---- ---- ----         ---- ---- ----         | S3 | S1 |
+     Cell 1.   \\             Cell 2.  | \\____  ----- -----
+                |                     |        | S4 | S/R4 |
+    ---- ---- ----         ---- ---- ----       ---- ------
+   | S7 | S4 | S2 |       | S1 | S3 | S2 |      | S2 | S5 |
+   ----- ---- -----       ----- ---- -----       ---- ----
+  | S6 | S/R3 | S1 | --- | S4 | S/R5 | S5 | ____/ Cell 4.
+   ---- ------ ----       ---- ------ ----
+   | S8 | S5 | S3 |       | S6 | S7 | S8 |     ... etc ...
+    ---- ---- ----         ---- ---- ----
+       Cell 3.                Cell 5.
+.in 3
+
+.ce
+Figure 1:  SILC Network Topology
+
+
+A cell is formed when a server or servers connect to one router.  In
+SILC network normal server cannot directly connect to other normal
+server.  Normal server may only connect to SILC router which then
+routes the messages to the other servers in the cell.  Router servers
+on the other hand may connect to other routers to form the actual SILC 
+network, as seen in above figure.  However, router is also normal SILC 
+server; clients may connect to it the same way as to normal SILC 
+server.  Normal server also cannot have active connections to more 
+than one router.  Normal server cannot be connected to two different 
+cells.  Router servers, on the other hand, may have as many router to 
+router connections as needed.
+
+There are many issues in this network topology that needs to be careful
+about.  Issues like the size of the cells, the number of the routers in 
+the SILC network and the capacity requirements of the routers.  These
+issues should be discussed in the Internet Community and additional
+documents on the issue may be written.
+
+
+.ti 0
+2.2 Communication Inside a Cell
+
+It is always guaranteed that inside a cell message is delivered to the 
+recipient with at most two server hops.  A client which is connected to
+server in the cell and is talking on channel to other client connected 
+to other server in the same cell, will have its messages delivered from 
+its local server first to the router of the cell, and from the router 
+to the other server in the cell.
+
+The following diagram represents this scenario:
+
+
+.in 25
+.nf
+1 --- S1     S4 --- 5
+         S/R
+ 2 -- S2     S3
+     /        |
+    4         3
+.in 3
+
+
+.ce
+Figure 2:  Communication Inside cell
+
+
+Example:  Client 1. connected to Server 1. send message to
+          Client 4. connected to Server 2. travels from Server 1.
+          first to Router which routes the message to Server 2.
+          which then sends it to the Client 4.  All the other
+          servers in the cell will not see the routed message.
+
+
+If the client is connected directly to the router, as router is also normal
+SILC server, the messages inside the cell are always delivered only with 
+one server hop.  If clients communicating with each other are connected 
+to the same server, no router interaction is needed.  This is the optimal
+situation of message delivery in the SILC network.
+
+
+.ti 0
+2.3 Communication in the Network
+
+If the message is destined to server that does not belong to local cell 
+the message is routed to the router server to which the destination 
+server belongs, if the local router is connected to destination router.
+If there is no direct connection to the destination router, the local
+router routes the message to its primary route.  The following diagram
+represents message sending between cells.
+
+
+
+.in 16
+.nf
+1 --- S1     S4 --- 5            S2 --- 1
+         S/R - - - - - - - - S/R
+ 2 -- S2     S3           S1
+     /        |             \\
+    4         3              2
+
+   Cell 1.               Cell 2.
+.in 3
+
+
+.ce
+Figure 3:  Communication Between Cells
+
+
+Example:  Client 5. connected to Server 4. in Cell 1. sends message
+          to Client 2. connected to Server 1. in Cell 2. travels
+          from Server 4. to Router which routes the message to
+          Router in Cell 2, which then routes the message to 
+          Server 1.  All the other servers and routers in the
+          network will not see the routed message.
+
+
+The optimal case of message delivery from the client point of view is
+when clients are connected directly to the routers and the messages
+are delivered from one router to the other.
+
+
+.ti 0 
+2.4 Channel Communication
+
+Messages may be sent to group of clients as well.  Sending messages to
+many clients works the same way as sending messages point to point, from
+message delivery point of view.  Security issues are another matter
+which are not discussed in this section.
+
+Router server handles the message routing to multiple recipients.  If 
+any recipient is not in the same cell as the sender the messages are 
+routed further.
+
+Server distributes the channel message to its local clients which are 
+joined to the channel.  Router also distributes the message to its 
+local clients on the channel.
+
+
+
+.ti 0
+2.5 Router Connections
+
+Router connections play very important role in making the SILC like
+network topology to work.  For example, sending broadcast packets in
+SILC network require special connections between routers; routers must
+be connected in a specific way.
+
+Every router has their primary route which is a connection to another
+router in the network.  Unless there is only two routers in the network
+must not routers use each other as their primary routes.  The router
+connections in the network must form a ring.
+
+Example with three routers in the network:
+
+
+.in 16
+.nf
+    S/R1 - < - < - < - < - < - < - S/R2
+     \\                               /
+      v                             ^
+       \\ - > -  > - S/R3 - > - > - /
+.in 3
+
+
+.ce
+Figure 4:  Router Connections
+
+
+Example:  Network with three routers.  Router 1. uses Router 2. as its
+          primary router.  Router 2. uses Router 3. as its primary router,
+          and Router 3. uses Router 1. as its primary router.  There may
+          be other direct connections between the routers but they must
+          not be used as primary routes.
+
+The above example is applicable to any amount of routers in the network
+except for two routers.  If there are only two routers in the network both
+routers must be able to handle situation where they use each other as their
+primary routes.
+
+The issue of router connections are very important especially with SILC
+broadcast packets.  Usually all router wide information in the network is
+distributed by SILC broadcast packets.  This sort of ring network, with
+ability to have other direct routes in the network cause interesting
+routing problems.  The [SILC2] discusses the routing of packets in this
+sort of network in more detail.
+
+
+.ti 0
+3. SILC Specification
+
+This section describes the SILC protocol.  However, [SILC2] and
+[SILC3] describes other important protocols that are part of this SILC
+specification and must be read.
+
+
+.ti 0
+3.1 Client
+
+A client is a piece of software connecting to SILC server.  SILC client 
+cannot be SILC server.  Purpose of clients is to provide the user 
+interface of the SILC services for end user.  Clients are distinguished
+from other clients by unique Client ID.  Client ID is a 128 bit ID that
+is used in the communication in the SILC network.  The client ID is 
+based on the nickname selected by the user.  User uses logical nicknames
+in communication which are then mapped to the corresponding Client ID.
+Client ID's are low level identifications and should not be seen by the
+end user.
+
+Clients provide other information about the end user as well. Information
+such as the nickname of the user, username and the host name of the end 
+user and user's real name.  See section 3.2 Server for information of 
+the requirements of keeping this information.
+
+The nickname selected by the user is not unique in the SILC network.
+There can be 2^8 same nicknames for one IP address.  As for comparison to 
+IRC [IRC] where nicknames are unique this is a fundamental difference 
+between SILC and IRC.  This typically causes the server names or client's 
+host names to be used along with the nicknames on user interface to  
+identify specific users when sending messages.  This feature of SILC 
+makes IRC style nickname-wars obsolete as no one owns their nickname; 
+there can always be someone else with the same nickname.  The maximum 
+length of nickname is 128 bytes.
+
+
+.ti 0
+3.1.1 Client ID
+
+Client ID is used to identify users in the SILC network.  The Client ID
+is unique to the extent that there can be 2^128 different Client ID's,
+and ID's based on IPv6 addresses extends this to 2^224 different Client
+ID's.  Collisions are not expected to happen.  The Client ID is defined
+as follows.
+
+.in 6
+128 bit Client ID based on IPv4 addresses:
+
+32 bit  Server ID IP address (bits 1-32)
+ 8 bit  Random number or counter
+88 bit  Truncated MD5 hash value of the nickname
+
+224 bit Client ID based on IPv6 addresses:
+
+128 bit  Server ID IP address (bits 1-128)
+  8 bit  Random number or counter
+ 88 bit  Truncated MD5 hash value of the nickname
+
+o Server ID IP address - Indicates the server where this
+  client is coming from.  The IP address hence equals the
+  server IP address where to the client has connected.
+
+o Random number or counter - Random number to further 
+  randomize the Client ID.  Another choice is to use
+  a counter starting from the zero (0).  This makes it
+  possible to have 2^8 same nicknames from the same
+  server IP address.
+
+o MD5 hash - MD5 hash value of the lowercase nickname is
+  truncated taking 88 bits from the start of the hash value.
+  This hash value is used to search the user's Client ID
+  from the ID lists.  Note that the nickname MUST be in
+  lowercase format.
+
+.in 3
+Collisions could occur when more than 2^8 clients using same nickname
+from the same server IP address is connected to the SILC network.  
+Server MUST be able to handle this situation by refusing to accept 
+anymore of that nickname.
+
+Another possible collision may happen with the truncated hash value of
+the nickname.  It could be possible to have same truncated hash value for
+two different nicknames.  However, this is not expected to happen nor
+cause any problems if it would occur.  Nicknames are usually logical and
+it is unlikely to have two distinct logical nicknames produce same
+truncated hash value.
+
+
+.ti 0
+3.2 Server
+
+Servers are the most important parts of the SILC network.  They form the
+basis of the SILC, providing a point to which clients may connect to.
+There are two kinds of servers in SILC; normal servers and router servers.
+This section focus on the normal server and router server is described
+in the section 3.3 Router.
+
+Normal servers MUST NOT directly connect to other normal server.  Normal
+servers may only directly connect to router server.  If the message sent
+by the client is destined outside the local server it is always sent to
+the router server for further routing.  Server may only have one active
+connection to router on same port.  Normal server MUST NOT connect to other
+cell's router except in situations where its cell's router is unavailable.
+
+
+.ti 0
+3.2.1 Server's Local ID List
+
+Normal server keeps various information about the clients and their end
+users connected to it.  Every normal server MUST keep list of all locally
+connected clients, Client ID's, nicknames, usernames and host names and
+user's real name.  Normal servers only keeps local information and it
+does not keep any global information.  Hence, normal servers knows only
+about their locally connected clients.  This makes servers efficient as
+they don't have to worry about global clients.  Server is also responsible
+of creating the Client ID's for their clients.
+
+Normal server also keeps information about locally created channels and
+their Channel ID's.
+
+Hence, local list for normal server includes:
+
+.in 6
+server list        - Router connection
+   o Server name
+   o Server IP address
+   o Server ID
+   o Sending key
+   o Receiving key
+   o Public key
+
+client list        - All clients in server
+   o Nickname
+   o Username@host
+   o Real name
+   o Client ID
+   o Sending key
+   o Receiving key
+   o Public key
+
+
+channel list       - All channels in server
+   o Channel name
+   o Channel ID
+   o Client ID's on channel
+   o Client ID modes on channel
+   o Channel key
+.in 3
+
+
+.ti 0
+3.2.2 Server ID
+
+Servers are distinguished from other servers by unique 64 bit Server ID 
+(for IPv4) or 160 bit Server ID (for IPv6).  The Server ID is used in
+the SILC to route messages to correct servers.  Server ID's also provide
+information for Client ID's, see section 3.1.1 Client ID.  Server ID is
+defined as follows.
+
+.in 6
+64 bit Server ID based on IPv4 addresses:
+
+32 bit  IP address of the server
+16 bit  Port
+16 bit  Random number
+
+160 bit Server ID based on IPv6 addresses:
+
+128 bit  IP address of the server
+ 16 bit  Port
+ 16 bit  Random number
+
+o IP address of the server - This is the real IP address of
+  the server.
+
+o Port - This is the port the server is bound to.
+
+o Random number - This is used to further randomize the Server ID.
+
+.in 3
+Collisions are not expected to happen in any conditions.  The Server ID
+is always created by the server itself and server is responsible of
+distributing it to the router.
+
+
+.ti 0
+3.2.3 SILC Server Ports
+
+The following ports has been assigned by IANA for the SILC protocol:
+
+.in 10
+silc            706/tcp    SILC
+silc            706/udp    SILC
+.in 3
+
+
+If there are needs to create new SILC networks in the future the port
+numbers must be officially assigned by the IANA.
+
+Server on network above privileged ports (>1023) SHOULD NOT be trusted
+as they could have been set up by untrusted party.
+
+
+.ti 0
+3.3 Router
+
+Router server in SILC network is responsible for keeping the cell together
+and routing messages to other servers and to other routers.  Router server
+is also a normal server thus clients may connect to it as it would be
+just normal SILC server.
+
+However, router servers has a lot of important tasks that normal servers
+do not have.  Router server knows everything about everything in the SILC.
+They know all clients currently on SILC, all servers and routers and all
+channels in SILC.  Routers are the only servers in SILC that care about
+global information and keeping them up to date at all time.  And, this
+is what they must do.
+
+
+.ti 0
+3.3.1 Router's Local ID List
+
+Router server as well MUST keep local list of connected clients and
+locally created channels.  However, this list is extended to include all
+the informations of the entire cell, not just the server itself as for
+normal servers.
+
+However, on router this list is a lot smaller since routers do not need
+to keep information about user's nickname, username and host name and real
+name since these are not needed by the router.  The router keeps only
+information that it needs.
+
+Hence, local list for router includes:
+
+.in 6
+server list        - All servers in the cell
+   o Server name
+   o Server ID
+   o Router's Server ID
+   o Sending key
+   o Receiving key
+
+client list        - All clients in the cell
+   o Client ID
+
+channel list       - All channels in the cell
+   o Channel ID
+   o Client ID's on channel
+   o Client ID modes on channel
+   o Channel key
+.in 3
+
+
+Note that locally connected clients and other information include all the
+same information as defined in section section 3.2.1 Server's Local ID
+List.
+
+
+.ti 0
+3.3.2 Router's Global ID List
+
+Router server MUST also keep global list.  Normal servers do not have
+global list as they know only about local information.  Global list
+includes all the clients on SILC, their Client ID's, all created channels
+and their Channel ID's and all servers and routers on SILC and their
+Server ID's.  That is said, global list is for global information and the
+list must not include the local information already on the router's local
+list.
+
+Note that the global list does not include information like nicknames,
+usernames and host names or user's real names.  Router does not need to
+keep these informations as they are not needed by the router.  This 
+information is available from the client's server which maybe queried
+when needed.
+
+Hence, global list includes:
+
+.in 6
+server list        - All servers in SILC
+   o Server name
+   o Server ID
+   o Router's Server ID
+
+client list        - All clients in SILC
+   o Client ID
+
+channel list       - All channels in SILC
+   o Channel ID
+   o Client ID's on channel
+   o Client ID modes on channel
+.in 3
+
+
+
+.ti 0
+3.3.3 Router's Server ID
+
+Router's Server ID's are equivalent to normal Server ID's.  As routers
+are normal servers as well same types of ID's applies for routers as well.
+Thus, see section 3.2.2 Server ID.
+
+
+.ti 0
+3.4 Channels
+
+A channel is a named group of one or more clients which will all receive
+messages addressed to that channel.  The channel is created when first
+client requests JOIN command to the channel, and the channel ceases to
+exist when the last client has left it.  When channel exists, any client
+can reference it using the name of the channel.  If the channel has
+a founder mode set and last client leaves the channel the channel does
+not cease to exist.  The founder mode can be used to make permanent
+channels in the network.  The founder of the channel can regain the
+channel founder privileges on the channel later when he joins the
+channel.
+
+Channel names are unique although the real uniqueness comes from 64 bit
+Channel ID.  However, channel names are still unique and no two global
+channels with same name may exist.  The channel name is a string of
+maximum length of 256 bytes.  Channel names MUST NOT contain any
+whitespaces (`  '), any non-printable ASCII characters, commas (`,')
+and wildcard characters.
+
+Channels can have operators that can administrate the channel and
+operate all of its modes.  The following operators on channel exist on
+the SILC network.
+
+.in 6
+o Channel founder - When channel is created the joining client becomes
+  channel founder.  Channel founder is channel operator with some more
+  privileges.  Basically, channel founder can fully operate the channel
+  and all of its modes.  The privileges are limited only to the
+  particular channel.  There can be only one channel founder per
+  channel. Channel founder supersedes channel operator's privileges.
+
+  Channel founder privileges cannot be removed by any other operator on
+  channel.  When channel founder leaves the channel there is no channel
+  founder on the channel.  However, it is possible to set a mode for
+  the channel which allows the original channel founder to regain the
+  founder privileges even after leaving the channel.  Channel founder
+  also cannot be removed by force from the channel.
+
+o Channel operator - When client joins to channel that has not existed
+  previously it will become automatically channel operator (and channel
+  founder discussed above).  Channel operator is able administrate the
+  channel, set some modes on channel, remove a badly behaving client
+  from the channel and promote other clients to become channel
+  operator.  The privileges are limited only to the particular channel.
+
+  Normal channel user may be promoted (opped) to channel operator
+  gaining channel operator privileges.  Channel founder or other
+  channel operator may also demote (deop) channel operator to normal
+  channel user.
+.in 3
+
+
+.ti 0
+3.4.1 Channel ID
+
+Channels are distinguished from other channels by unique Channel ID.
+The Channel ID is a 64 bit ID (for IPv4) or 160 bit ID (for IPv6), and
+collisions are not expected to happen in any conditions.  Channel names
+are just for logical use of channels.  The Channel ID is created by the
+server where the channel is created.  The Channel ID is defined as
+follows.
+
+.in 6
+64 bit Channel ID based on IPv4 addresses:
+
+32 bit  Router's Server ID IP address (bits 1-32)
+16 bit  Router's Server ID port (bits 33-48)
+16 bit  Random number
+
+160 bit Channel ID based on IPv6 addresses:
+
+128 bit  Router's Server ID IP address (bits 1-128)
+ 16 bit  Router's Server ID port (bits 129-144)
+ 16 bit  Random number
+
+o Router's Server ID IP address - Indicates the IP address of 
+  the router of the cell where this channel is created.  This is 
+  taken from the router's Server ID.  This way SILC router knows 
+  where this channel resides in the SILC network.
+
+o Router's Server ID port - Indicates the port of the channel on 
+  the server.  This is taken from the router's Server ID.
+
+o Random number - To further randomize the Channel ID.  This makes
+  sure that there are no collisions.  This also means that
+  in a cell there can be 2^16 channels.
+.in 3
+
+
+.ti 0
+3.5 Operators
+
+Operators are normal users with extra privileges to their server or
+router.  Usually these people are SILC server and router administrators
+that take care of their own server and clients on them.  The purpose of
+operators is to administrate the SILC server or router.  However, even
+an operator with highest privileges is not able to enter invite-only
+channel, to gain access to the contents of a encrypted and authenticated
+packets traveling in the SILC network or to gain channel operator
+privileges on public channels without being promoted.  They have the
+same privileges as everyone else except they are able to administrate
+their server or router.
+
+
+.ti 0
+3.6 SILC Commands
+
+Commands are very important part on SILC network especially for client
+which uses commands to operate on the SILC network.  Commands are used
+to set nickname, join to channel, change modes and many other things.
+
+Client usually sends the commands and server replies by sending a reply
+packet to the command.  Server MAY also send commands usually to serve
+the original client's request.  Usually server cannot send commands to
+clients, however there MAY be commands that allow the server to send
+commands to client.  By default servers MAY send commands only to other
+servers and routers.
+
+Note that the command reply is usually sent only after client has sent
+the command request but server is allowed to send command reply packet
+to client even if client has not requested the command.  Client MAY
+choose to ignore the command reply.
+
+It is expected that some of the commands may be miss-used by clients
+resulting various problems on the server side.  Every implementation
+SHOULD assure that commands may not be executed more than once, say,
+in two (2) seconds.  However, to keep response rate up, allowing for
+example five (5) commands before limiting is allowed.  It is RECOMMENDED
+that commands such as SILC_COMMAND_NICK, SILC_COMMAND_JOIN, 
+SILC_COMMAND_LEAVE and SILC_COMMAND_KILL SHOULD be limited in all cases
+as they require heavy operations.  This should be sufficient to prevent
+the miss-use of commands.
+
+SILC commands are described in [SILC4].
+
+
+.ti 0
+3.7 SILC Packets
+
+Packets are naturally the most important part of the protocol and the
+packets are what actually makes the protocol.  Packets in SILC network
+are always encrypted using, usually the shared secret session key
+or some other key, for example, channel key, when encrypting channel
+messages.  It is not possible to send packet in SILC network without
+encryption.  The SILC Packet Protocol is a wide protocol and is described
+in [SILC2].  This document does not define or describe details of
+SILC packets.
+
+
+.ti 0
+3.8 Packet Encryption
+
+All packets passed in SILC network MUST be encrypted.  This section
+defines how packets must be encrypted in the SILC network.  The detailed
+description of the actual encryption process of the packets are
+described in [SILC2].
+
+Client and its server shares secret symmetric session key which is
+established by the SILC Key Exchange Protocol, described in [SILC3]. 
+Every packet sent from client to server, with exception of packets for
+channels, are encrypted with this session key.
+
+Channels has a channel key that are shared by every client on the channel.
+However, the channel keys are cell specific thus one cell does not know
+the channel key of the other cell, even if that key is for same channel.
+Channel key is also known by the routers and all servers that has clients
+on the channel.  However, channels MAY have channel private keys that
+are entirely local setting for the client.  All clients on the channel
+MUST know the channel private key before hand to be able to talk on the
+channel.  In this case, no server or router know the key for channel.
+
+Server shares secret symmetric session key with router which is
+established by the SILC Key Exchange Protocol.  Every packet passed from
+server to router, with exception of packets for channels, are encrypted
+with the shared session key.  Same way, router server shares secret
+symmetric key with its primary route.  However, every packet passed
+from router to other router, including packets for channels, are
+encrypted with the shared session key.  Every router connection has
+their own session keys.
+
+
+.ti 0
+3.8.1 Determination of the Source and the Destination
+
+The source and the destination of the packet needs to be determined
+to be able to route the packets to correct receiver.  This information
+is available in the SILC Packet Header which is included in all packets
+sent in SILC network.  The SILC Packet Header is described in [SILC2].
+
+The header MUST be encrypted with the session key who is next receiver
+of the packet along the route.  The receiver of the packet, for example
+a router along the route, is able to determine the sender and the
+destination of the packet by decrypting the SILC Packet Header and
+checking the ID's attached to the header.  The ID's in the header will
+tell to where the packet needs to be sent and where it is coming from.
+
+The header in the packet MUST NOT change during the routing of the
+packet.  The original sender, for example client, assembles the packet
+and the packet header and server or router between the sender and the
+receiver MUST NOT change the packet header.  Note however, that some
+packets such as commands may be resent by a server to serve the client's
+original command.  In this case the command packet sent by the server
+includes the server's IDs.
+
+Note that the packet and the packet header may be encrypted with
+different keys.  For example, packets to channels are encrypted with
+the channel key, however, the header is encrypted with the session key
+as described above.  However, the header and the packet may be encrypted
+with same key.  This is the case, for example, with command packets.
+
+
+.ti 0
+3.8.2 Client To Client
+
+The process of message delivery and encryption from client to another
+client is as follows.
+
+Example:  Private message from client to another client on different
+          servers.  Clients do not share private message delivery
+          keys; normal session keys are used.
+
+o Client 1. sends encrypted packet to its server.  The packet is
+  encrypted with the session key shared between client and its
+  server.
+
+o Server determines the destination of the packet and decrypts
+  the packet.  Server encrypts the packet with session key shared
+  between the server and its router, and sends the packet to the
+  router.
+
+o Router determines the destination of the packet and decrypts
+  the packet.  Router encrypts the packet with session key 
+  shared between the router and the destination server, and sends
+  the packet to the server.
+
+o Server determines the client to which the packet is destined
+  to and decrypts the packet.  Server encrypts the packet with
+  session key shared between the server and the destination client,
+  and sends the packet to the client.
+
+o Client 2. decrypts the packet.
+
+
+Example:  Private message from client to another client on different
+          servers.  Clients has established secret shared private
+          message delivery key with each other and that is used in 
+          the message encryption.
+
+o Client 1. sends encrypted packet to its server.  The packet header
+  is encrypted with the session key shared between the client and
+  server, and the private message is encrypted with the private
+  message delivery key shared between clients.
+
+o Server determines the destination of the packet and sends the 
+  packet to the router.
+
+o Router determines the destination of the packet and sends the
+  packet to the server.
+
+o Server determines the client to which the packet is destined
+  to and sends the packet to the client.
+
+o Client 2. decrypts the packet with the secret shared key.
+
+If clients share secret key with each other the private message
+delivery is much simpler since servers and routers between the
+clients do not need to decrypt and re-encrypt the packet.
+
+The process for clients on same server is much simpler as there are
+no need to send the packet to the router.  The process for clients 
+on different cells is same as above except that the packet is routed 
+outside the cell.  The router of the destination cell routes the 
+packet to the destination same way as described above.
+
+
+.ti 0
+3.8.3 Client To Channel
+
+Process of message delivery from client on channel to all the clients
+on the channel.
+
+Example:  Channel of four users; two on same server, other two on
+          different cells.  Client sends message to the channel.
+
+o Client 1. encrypts the packet with channel key and sends the
+  packet to its server.
+
+o Server determines local clients on the channel and sends the
+  packet to the Client on the same server.  Server then sends
+  the packet to its router for further routing.
+
+o Router determines local clients on the channel, if found
+  sends packet to the local clients.  Router determines global
+  clients on the channel and sends the packet to its primary
+  router or fastest route.
+
+o (Other router(s) do the same thing and sends the packet to
+   the server(s))
+
+o Server determines local clients on the channel and sends the
+  packet to the client.
+
+o All clients receiving the packet decrypts it.
+
+
+.ti 0
+3.8.4 Server To Server
+
+Server to server packet delivery and encryption is described in above
+examples. Router to router packet delivery is analogous to server to
+server.  However, some packets, such as channel packets, are processed
+differently.  These cases are described later in this document and
+more in detail in [SILC2].
+
+
+.ti 0
+3.9 Key Exchange And Authentication
+
+Key exchange is done always when for example client connects to server
+but also when server and router, and router and router connects to each
+other.  The purpose of key exchange protocol is to provide secure key
+material to be used in the communication.  The key material is used to
+derive various security parameters used to secure SILC packets.  The
+SILC Key Exchange protocol is described in detail in [SILC3].
+
+Authentication is done after key exchange protocol has been successfully
+completed.  The purpose of authentication is to authenticate for example
+client connecting to the server.  However, clients may be accepted
+to connect to server without explicit authentication.  Servers are
+required to use authentication protocol when connecting.  The 
+authentication may be based on passphrase (pre-shared-secret) or public 
+key based on digital signatures.  All passphrases sent in SILC protocol 
+MUST be UTF-8 [RFC2279] encoded. The connection authentication protocol
+is described in detail in [SILC3].
+
+
+.ti 0
+3.9.1 Authentication Payload
+
+Authentication payload is used separately from the SKE and the Connection
+Authentication protocol.  It can be used during the session to authenticate
+with the remote.  For example, the client can authenticate itself to the
+server to become server operator.  In this case, Authentication Payload is
+used.
+
+The format of the Authentication Payload is as follows:
+
+.in 5
+.nf
+                     1                   2                   3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+|        Payload Length         |     Authentication Method     |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+|      Public Data Length       |                               |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               +
+|                                                               |
+~                           Public Data                         ~
+|                                                               |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+|   Authentication Data Length  |                               |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               +
+|                                                               |
+~                       Authentication Data                     ~
+|                                                               |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+.in 3
+.ce
+Figure 5:  Authentication Payload
+
+
+.in 6
+o Payload Length (2 bytes) - Length of the entire payload.
+
+o Authentication Method (2 bytes) - The method of the
+  authentication.  The authentication methods are defined
+  in [SILC2] in the Connection Auth Request Payload.  The NONE 
+  authentication method SHOULD NOT be used.
+
+o Public Data Length (2 bytes) - Indicates the length of
+  the Public Data field.
+
+o Public Data (variable length) - This is defined only if
+  the authentication method is public key.  If it is any other
+  this field MAY include a random data for padding purposes.
+  However, in this case the field MUST be ignored by the
+  receiver.
+
+  When the authentication method is public key this includes
+  128 to 4096 bytes of non-zero random data that is used in
+  the signature process, described subsequently.
+
+o Authentication Data Length (2 bytes) - Indicates the
+  length of the Authentication Data field.  If zero (0)
+  value is found in this field the payload MUST be 
+  discarded.
+
+o Authentication Data (variable length) - Authentication 
+  method dependent authentication data.
+.in 3
+
+
+If the authentication method is password based, the Authentication
+Data field includes the plaintext UTF-8 encoded password.  It is safe
+to send plaintext password since the entire payload is encrypted.  In
+this case the Public Data Length is set to zero (0), but MAY also include
+random data for padding purposes.  It is also RECOMMENDED that maximum
+amount of padding is applied to SILC packet when using password based
+authentication.  This way it is not possible to approximate the length
+of the password from the encrypted packet.
+
+If the authentication method is public key based (or certificate)
+the Authentication Data is computed as follows:
+
+  HASH = hash(random bytes | ID | public key (or certificate));
+  Authentication Data = sign(HASH);
+
+The hash() and the sign() are the hash function and the public key
+cryptography function selected in the SKE protocol, unless otherwise
+stated in the context where this payload is used.  The public key
+is SILC style public key unless certificates are used.  The ID is the
+entity's ID (Client or Server ID) which is authenticating itself.  The
+ID encoding is described in [SILC2].  The random bytes are non-zero
+random bytes of length between 128 and 4096 bytes, and will be included
+into the Public Data field as is.
+
+The receiver will compute the signature using the random data received
+in the payload, the ID associated to the connection and the public key
+(or certificate) received in the SKE protocol.  After computing the
+receiver MUST verify the signature.  In case of public key authentication
+also this payload is encrypted.
+
+
+.ti 0
+3.10 Algorithms
+
+This section defines all the allowed algorithms that can be used in
+the SILC protocol.  This includes mandatory cipher, mandatory public
+key algorithm and MAC algorithms.
+
+
+.ti 0
+3.10.1 Ciphers
+
+Cipher is the encryption algorithm that is used to protect the data
+in the SILC packets.  See [SILC2] of the actual encryption process and
+definition of how it must be done.  SILC has a mandatory algorithm that
+must be supported in order to be compliant with this protocol.
+
+The following ciphers are defined in SILC protocol:
+
+aes-256-cbc          AES in CBC mode, 256 bit key            (REQUIRED)
+aes-256-ctr          AES in CTR mode, 256 bit key            (RECOMMENDED)
+aes-256-rcbc         AES in randomized CBC mode, 256 bit key (OPTIONAL)
+aes-192-<mode>       AES in <mode> mode, 192 bit key         (OPTIONAL)
+aes-128-<mode>       AES in <mode> mode, 128 bit key         (RECOMMENDED)
+twofish-256-<mode>   Twofish in <mode> mode, 256 bit key     (OPTIONAL)
+twofish-192-<mode>   Twofish in <mode> mode, 192 bit key     (OPTIONAL)
+twofish-128-<mode>   Twofish in <mode> mode, 128 bit key     (OPTIONAL)
+cast-256-<mode>      CAST-256 in <mode> mode, 256 bit key    (OPTIONAL)
+cast-192-<mode>      CAST-256 in <mode> mode, 192 bit key    (OPTIONAL)
+cast-128-<mode>      CAST-256 in <mode> mode, 128 bit key    (OPTIONAL)
+serpent-<len>-<mode> Serpent in <mode> mode, <len> bit key   (OPTIONAL)
+rc6-<len>-<mode>     RC6 in <mode> mode, <len> bit key       (OPTIONAL)
+mars-<len>-<mode>    MARS in <mode> mode, <len> bit key      (OPTIONAL)
+none                 No encryption                           (OPTIONAL)
+
+The <mode> is either "cbc", "ctr" or "rcbc".  Other encryption modes MAY
+be defined as to be used in SILC using the same format.  The <len> is
+either 256, 192 or 128 bit key length.  Also, additional ciphers MAY be
+defined to be used in SILC by using the same name format as above.
+
+Algorithm "none" does not perform any encryption process at all and 
+thus is not recommended to be used.  It is recommended that no client
+or server implementation would accept none algorithm except in special
+debugging mode.
+
+
+.ti 0
+3.10.1.1 CBC Mode
+
+The "cbc" encryption mode is CBC mode with inter-packet chaining.  This
+means that the Initial Vector (IV) for the next encryption block is
+the previous ciphertext block.  The very first IV MUST be random and is
+generated as described in [SILC3].
+
+
+.ti 0
+3.10.1.2 CTR Mode
+
+The "ctr" encryption mode is CTR mode.  The CTR mode in SILC is stateful
+in encryption and decryption.  Both sender and receiver maintain the
+counter for the CTR mode and thus can precompute the key stream for
+encryption and decryption.  By default, CTR mode does not require
+plaintext padding, however implementations MAY apply padding to the
+packets.  If the last key block is larger than the last plaintext block
+the resulted value is truncated to the size of the plaintext block and
+the most significant bits are used.  When sending authentication data
+inside packets the maximum amount of padding SHOULD be applied with
+CTR mode as well.
+
+In CTR mode only the encryption operation of the cipher is used.  The
+decryption operation is not needed since both encryption and decryption
+process is simple XOR with the plaintext block and the key stream block.
+
+The counter block is used to create the key for the CTR mode.  When
+SILC specifications refer to Initial Vector (IV) in general cases, in
+case of CTR mode it refers to the counter block.  The format of the
+128 bit counter block is as follows:
+
+.in 5
+.nf
+                     1                   2                   3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+|                   Truncated HASH from SKE                     |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+|                Sending/Receiving IV from SKE                  |
+|                                                               |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+|                        Block Counter                          |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+.in 3
+
+.ce
+Figure 6:  Counter Block
+
+.in 6
+o Truncated HASH from SKE (4 bytes) - This value is the first 4
+  bytes from the HASH value that was computed as a result of SKE
+  protocol.  This acts as session identifier and each rekey MUST
+  produce a new HASH value.
+
+o Sending/Receiving IV from SKE (8 bytes) - This value is the
+  first 8 bytes from the Sending IV or Receiving IV generated in
+  the SKE protocol.  When this mode is used to encrypt sending
+  traffic the Sending IV is used, when used to decrypt receiving
+  traffic the Receiving IV is used.  This assures that two parties
+  of the protocol use different IV for sending traffic.  Each rekey
+  MUST produce a new value.
+
+o Block Counter (4 bytes) - This is the counter value for the
+  counter block and is MSB ordered number starting from one (1)
+  value for first block and incrementing for subsequent blocks.
+  The same value MUST NOT be used twice.  The rekey MUST be
+  performed before this counter value wraps.
+.in 3
+
+CTR mode MUST NOT be used with "none" MAC.  Implementations also MUST
+assure that the same counter block is not used to encrypt more than
+one block.  Also, the key material used with CTR mode MUST be fresh
+key material.  Static keys (pre-shared keys) MUST NOT be used with
+CTR mode.  For this reason using CTR mode to encrypt for example
+channel messages or private messages with a pre-shared key is
+inappropriate.  For private messages, the Key Agreement could be
+performed to produce fresh key material.
+
+If the IV Included flag was negotiated in SKE, implementations SHOULD
+still use the same counter block format as defined above.  However, 
+implementations are RECOMMENDED to replace the Truncated HASH field
+with a 32 bit random value for each IV (counter block) per encrypted
+SILC packet.  Also note, that in this case the decryption process is
+not stateful and receiver cannot precompute the key stream.
+
+
+.ti 0
+3.10.1.3 Randomized CBC Mode
+
+The "rcbc" encryption mode is CBC mode with randomized IV.  This means
+that each IV for each packet MUST be chosen randomly.  When encrypting
+more than one block the normal inter-packet chaining is used, but for
+the first block new random IV is selected in each packet.  In this mode
+the IV is appended at the end of the last ciphertext block and thus
+delivered to the recipient.  This mode increases the ciphertext size by
+one ciphertext block.  Note also that some data payloads in SILC are
+capable of delivering the IV to the recipient.  When explicitly
+encrypting these payloads with randomized CBC the IV MUST NOT be appended
+at the end of the ciphertext.  When encrypting these payloads with
+"cbc" mode they implicitly become randomized CBC since the IV is
+usually selected random and included in the ciphertext.  In these
+cases using either CBC or randomized CBC is actually equivalent.
+
+
+.ti 0
+3.10.2 Public Key Algorithms
+
+Public keys are used in SILC to authenticate entities in SILC network
+and to perform other tasks related to public key cryptography.  The 
+public keys are also used in the SILC Key Exchange protocol [SILC3].
+
+The following public key algorithms are defined in SILC protocol:
+
+.in 6
+rsa        RSA  (REQUIRED)
+dss        DSS  (OPTIONAL)
+.in 3
+
+DSS is described in [Menezes].  The RSA MUST be implemented according
+PKCS #1 [PKCS1].  The mandatory PKCS #1 implementation in SILC MUST be
+compliant to either PKCS #1 version 1.5 or newer with the following
+notes: The signature encoding is always in same format as the encryption
+encoding regardless of the PKCS #1 version.  The signature with appendix
+(with hash algorithm OID in the data) MUST NOT be used in the SILC.  The
+rationale for this is that there is no binding between the PKCS #1 OIDs
+and the hash algorithms used in the SILC protocol.  Hence, the encoding
+is always in PKCS #1 version 1.5 format.
+
+Additional public key algorithms MAY be defined to be used in SILC.
+
+When signatures are computed in SILC the computing of the signature is
+represented as sign().  The signature computing procedure is dependent
+of the public key algorithm, and the public key or certificate encoding.
+When using SILC public key the signature is computed as described in
+previous paragraph for RSA and DSS keys.  If the hash function is not
+specified separately for signing process sha1 MUST be used.  When using
+SSH2 public keys the signature is computed as described in [SSH-TRANS].
+When using X.509 version 3 certificates the signature is computed as
+described in [PKCS7].  When using OpenPGP certificates the signature is
+computed as described in [PGP].
+
+
+.ti 0
+3.10.3 Hash Functions
+
+Hash functions are used as part of MAC algorithms defined in the next
+section.  They are also used in the SILC Key Exchange protocol defined
+in the [SILC3].
+
+The following Hash algorithm are defined in SILC protocol:
+
+.in 6
+sha1             SHA-1, length = 20      (REQUIRED)
+md5              MD5, length = 16        (RECOMMENDED)
+.in 3
+
+
+
+.ti 0
+3.10.4 MAC Algorithms
+
+Data integrity is protected by computing a message authentication code
+(MAC) of the packet data.  See [SILC2] for details how to compute the
+MAC.
+
+The following MAC algorithms are defined in SILC protocol:
+
+.in 6
+hmac-sha1-96     HMAC-SHA1, length = 12 bytes  (REQUIRED)
+hmac-md5-96      HMAC-MD5, length = 12 bytes   (OPTIONAL)
+hmac-sha1        HMAC-SHA1, length = 20 bytes  (OPTIONAL)
+hmac-md5         HMAC-MD5, length = 16 bytes   (OPTIONAL)
+none             No MAC                        (OPTIONAL)
+.in 3
+
+The "none" MAC is not recommended to be used as the packet is not
+authenticated when MAC is not computed.  It is recommended that no
+client or server would accept none MAC except in special debugging
+mode.
+
+The HMAC algorithm is described in [HMAC] and hash algorithms that
+are used as part of the HMACs are described in [Scheneir] and in
+[Menezes].
+
+Additional MAC algorithms MAY be defined to be used in SILC.
+
+
+.ti 0
+3.10.5 Compression Algorithms
+
+SILC protocol supports compression that may be applied to unencrypted
+data.  It is recommended to use compression on slow links as it may
+significantly speed up the data transmission.  By default, SILC does not
+use compression which is the mode that must be supported by all SILC
+implementations.
+
+The following compression algorithms are defined:
+
+.in 6
+none        No compression               (REQUIRED)
+zlib        GNU ZLIB (LZ77) compression  (OPTIONAL)
+.in 3
+
+Additional compression algorithms MAY be defined to be used in SILC.
+
+
+
+.ti 0
+3.11 SILC Public Key
+
+This section defines the type and format of the SILC public key.  All
+implementations MUST support this public key type.  See [SILC3] for
+other optional public key and certificate types allowed in the SILC
+protocol.  Public keys in SILC may be used to authenticate entities
+and to perform other tasks related to public key cryptography.
+
+The format of the SILC Public Key is as follows:
+
+
+.in 5
+.nf
+                     1                   2                   3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+|                        Public Key Length                      |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+|     Algorithm Name Length     |                               |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               +
+|                                                               |
+~                         Algorithm Name                        ~
+|                                                               |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+|       Identifier Length       |                               |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               +
+|                                                               |
+~                           Identifier                          ~
+|                                                               |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+|                                                               |
+~                           Public Data                         ~
+|                                                               |
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+.in 3
+
+.ce
+Figure 5:  SILC Public Key
+
+
+.in 6
+o Public Key Length (4 bytes) - Indicates the full length
+  of the public key, not including this field.
+
+o Algorithm Name Length (2 bytes) - Indicates the length
+  of the Algorithm Length field, not including this field.
+
+o Algorithm name (variable length) - Indicates the name
+  of the public key algorithm that the key is.  See the
+  section 3.10.2 Public Key Algorithms for defined names.
+
+o Identifier Length (2 bytes) - Indicates the length of
+  the Identifier field, not including this field.
+
+o Identifier (variable length) - Indicates the identifier
+  of the public key.  This data can be used to identify
+  the owner of the key.  The identifier is of the following
+  format:
+
+     UN   User name
+     HN   Host name or IP address
+     RN   Real name
+     E    EMail address
+     O    Organization
+     C    Country
+
+
+  Examples of an identifier:
+
+    `UN=priikone, HN=poseidon.pspt.fi, E=priikone@poseidon.pspt.fi'
+
+    `UN=sam, HN=dummy.fi, RN=Sammy Sam, O=Company XYZ, C=Finland'
+
+  At least user name (UN) and host name (HN) MUST be provided as
+  identifier.  The fields are separated by commas (`,').  If
+  comma is in the identifier string it must be written as `\\,',
+  for example, `O=Company XYZ\\, Inc.'.
+
+o Public Data (variable length) - Includes the actual
+  public data of the public key.
+
+  The format of this field for RSA algorithm is
+  as follows:
+
+     4 bytes            Length of e
+     variable length    e
+     4 bytes            Length of n
+     variable length    n
+
+
+  The format of this field for DSS algorithm is
+  as follows:
+
+     4 bytes            Length of p
+     variable length    p
+     4 bytes            Length of q
+     variable length    q
+     4 bytes            Length of g
+     variable length    g
+     4 bytes            Length of y
+     variable length    y
+
+  The variable length fields are multiple precession
+  integers encoded as strings in both examples.
+
+  Other algorithms must define their own type of this
+  field if they are used.
+.in 3
+
+All fields in the public key are in MSB (most significant byte first)
+order.  All strings in the public key are UTF-8 encoded.
+
+If an external protocol need to refer to SILC Public Key by name, the
+name "silc-rsa" and "silc-dss" for SILC Public Key based on RSA algorithm
+and SILC Public Key based on DSS algorithm, respectively, are to be used.
+However, this SILC specification does not use these names directly, and 
+they are defined here for external protocols (protocols that may like 
+to use SILC Public Key).
+
+
+.ti 0
+3.12 SILC Version Detection
+
+The version detection of both client and server is performed at the
+connection phase while executing the SILC Key Exchange protocol.  The
+version identifier is exchanged between initiator and responder.  The
+version identifier is of the following format:
+
+.in 6
+SILC-<protocol version>-<software version>
+.in 3
+
+The version strings are of the following format:
+
+.in 6
+protocol version = <major>.<minor>
+software version = <major>[.<minor>[.<build or vendor string>]]
+.in 3
+
+Protocol version MUST provide both major and minor version.  Currently
+implementations MUST set the protocol version and accept at least the 
+protocol version as SILC-1.2-<software version>.  If new protocol version 
+causes incompatibilities with older version the <minor> version number 
+MUST be incremented.  The <major> is incremented if new protocol version 
+is fully incompatible.
+
+Software version MAY provide major, minor and build (vendor) version.
+The software version MAY be freely set and accepted.  The version string 
+MUST consist of printable US-ASCII characters.
+
+Thus, the version strings could be, for example:
+
+.in 6
+SILC-1.1-2.0.2
+SILC-1.0-1.2
+SILC-1.2-1.0.VendorXYZ
+SILC-1.2-2.4.5 Vendor Limited
+.in 3
+
+
+.ti 0
+3.13 Backup Routers
+
+Backup routers may exist in the cell in addition of the primary router.
+However, they must not be active routers and act as routers in the cell.
+Only one router may be acting as primary router in the cell.  In the case
+of failure of the primary router may one of the backup routers become
+active.  The purpose of backup routers are in case of failure of the
+primary router to maintain working connections inside the cell and outside
+the cell and to avoid netsplits.
+
+Backup routers are normal servers in the cell that are prepared to take
+over the tasks of the primary router if needed.  They need to have at
+least one direct and active connection to the primary router of the cell.
+This communication channel is used to send the router information to
+the backup router.  When the backup router connects to the primary router
+of the cell it MUST present itself as router server in the Connection
+Authentication protocol, even though it is normal server as long as the
+primary router is available.  Reason for this is that the configuration
+needed in the responder end requires usually router connection level
+configuration.  The responder, however must understand and treat the
+connection as normal server (except when feeding router level data to
+the backup router).
+
+Backup router must know everything that the primary router knows to be
+able to take over the tasks of the primary router.  It is the primary
+router's responsibility to feed the data to the backup router.  If the
+backup router does not know all the data in the case of failure some
+connections may be lost.  The primary router of the cell must consider
+the backup router being actual router server when it feeds the data to
+it.
+
+In addition of having direct connection to the primary router of the
+cell, the backup router must also have connection to the same router
+the primary router of the cell is connected.  However, it must not be
+active router connection meaning that the backup router must not use
+that channel as its primary route and it must not notify the router
+about having connected servers, channels and clients behind it.  It
+merely connects to the router.  This sort of connection is later
+referred as being passive connection.  Some keepalive actions may be
+needed by the router to keep the connection alive.
+
+It is required that other normal servers have passive connections to
+the backup router(s) in the cell.  Some keepalive actions may be needed
+by the server to keep the connection alive.  After they notice the
+failure of the primary router they must start using the connection to
+the first backup router as their primary route.
+
+Also, if any other router in the network is using the cell's primary
+router as its own primary router, it must also have passive connection
+to the cell's backup router.  It too is prepared to switch to use the
+backup router as its new primary router as soon as the original primary
+router becomes unresponsive.
+
+All of the parties of this protocol knows which one is the backup router
+of the cell from their local configuration.  Each of the entity must
+be configured accordingly and care must be taken when configuring the
+backup routers, servers and other routers in the network.
+
+It must be noted that some of the channel messages and private messages
+may be lost during the switch to the backup router.  The announcements
+assures that the state of the network is not lost during the switch.
+
+It is RECOMMENDED that there would be at least one backup router in
+the cell.  It is NOT RECOMMENDED to have all servers in the cell acting
+as backup routers as it requires establishing several connections to
+several servers in the cell.  Large cells can easily have several
+backup routers in the cell.
+
+The order of the backup routers are decided at the configuration phase.
+All the parties of this protocol must be configured accordingly to 
+understand the order of the backup routers.  It is not required that
+the backup server is actually active server in the cell.  Backup router
+may be a spare server in the cell that does not accept normal client
+connections at all.  It may be reserved purely for the backup purposes.
+These, however, are cell management issues.
+
+If also the first backup router is down as well and there is another
+backup router in the cell then it will start acting as the primary
+router as described above.
+
+
+.ti 0
+3.13.1 Switching to Backup Router
+
+When the primary router of the cell becomes unresponsive, for example
+by sending EOF to the connection, all the parties of this protocol MUST
+replace the old connection to the primary router with first configured
+backup router.  The backup router usually needs to do local modifications
+to its database in order to update all the information needed to maintain
+working routes.  The backup router must understand that clients that
+were originated from the primary router are now originated from some of
+the existing server connections and must update them accordingly.  It
+must also remove those clients that were owned by the primary router
+since those connections were lost when the primary router became
+unresponsive.
+
+All the other parties of the protocol must also update their local
+database to understand that the route to the primary router will now go
+to the backup router.
+
+Servers connected to the backup router MUST send SILC_PACKET_RESUME_ROUTER
+packet with type number 21, to indicate that the server will start using
+the backup router as primary router.  The backup router MUST NOT allow
+this action if it detects that primary is still up and running.  If
+backup router knows that primary is up and running it MUST send type
+number 22 back to the server.  The server then MUST NOT use the backup
+as primary router, but must try to establish connection back to the
+primary router.  If the action is allowed type number 21 is sent back
+to the server from the backup router.
+
+The servers connected to the backup router must then announce their
+clients, channels, channel users, channel user modes and channel modes
+to the backup router.  This is to assure that none of the important notify 
+packets were lost during the switch to the backup router.  The backup
+router must check which of these announced entities it already have
+and distribute the new ones to the primary route.
+
+The backup router too must announce its servers, clients, channels
+and other information to the new primary router.  The primary router
+of the backup router too must announce its informations to the backup
+router.  Both must process only the ones they do not know about.  If
+any of the announced modes does not match then they are enforced in
+normal manner defined later in this specification.
+
+
+.ti 0
+3.13.2 Resuming Primary Router
+
+Usually the primary router is unresponsive only a short period of time
+and it is intended that the original router of the cell will resume
+its position as primary router when it comes back online.  The backup
+router that is now acting as primary router of the cell must constantly
+try to connect to the original primary router of the cell.  It is
+RECOMMENDED that it would try to reconnect in 30 second intervals to
+the primary router.
+
+When the connection is established to the primary router the backup
+resuming protocol is executed.  The protocol is advanced as follows:
+
+  1. Backup router sends SILC_PACKET_RESUME_ROUTER packet with type
+     value 1 the primary router that came back online.  The packet
+     will indicate the primary router has been replaced by the backup
+     router.  After sending the packet the backup router will announce
+     all of its channels, channel users, modes etc. to the primary
+     router.
+
+     If the primary knows that it has not been replaced (for example
+     the backup itself disconnected from the primary router and thinks
+     that it is now primary in the cell) the primary router send
+     SILC_PACKET_FAILURE with the type value 1 back to the backup
+     router.  If backup receives this it MUST NOT continue with the
+     backup resuming protocol.
+
+  2. Backup router sends SILC_PACKET_RESUME_ROUTER packet with type
+     value 2 to its current primary router to indicate that it will
+     resign as being primary router.  Then, backup router sends the
+     SILC_PACKET_RESUME_ROUTER packet with type value 1 to all
+     connected servers to also indicate that it will resign as being
+     primary router.
+
+  3. Backup router also send SILC_PACKET_RESUME_ROUTER packet with
+     type value 2 to the router that is using the backup router
+     currently as its primary router.
+
+  4. Any server and router that receives the SILC_PACKET_RESUME_ROUTER
+     with type value 1 or 2 must reconnect immediately to the
+     primary router of the cell that came back online.  After they
+     have created the connection they MUST NOT use that connection
+     as active primary route but still route all packets to the
+     backup router.  After the connection is created they MUST send
+     SILC_PACKET_RESUME_ROUTER with type value 3 back to the
+     backup router.  The session ID value found in the first packet
+     MUST be set in this packet.
+
+  5. Backup router MUST wait for all packets with type value 3 before
+     it continues with the protocol.  It knows from the session ID values
+     set in the packet when it have received all packets.  The session
+     value should be different in all packets it have sent earlier.
+     After the packets is received the backup router sends the
+     SILC_PACKET_RESUME_ROUTER packet with type value 4 to the
+     primary router that came back online.  This packet will indicate 
+     that the backup router is now ready to resign as being primary
+     router.  The session ID value in this packet MUST be the same as
+     in first packet sent to the primary router.  During this time
+     the backup router must still route all packets it is receiving
+     from server connections.
+
+  6. The primary router receives the packet and send the
+     SILC_PACKET_RESUME_ROUTER with type value 5 to all connected servers
+     including the backup router.  It also sends the packet with type
+     value 6 to its primary router, and to the router that is using
+     it as its primary router.  The Session ID value in this packet
+     SHOULD be zero (0).
+
+  7. Any server and router that receives the SILC_PACKET_RESUME_ROUTER
+     with type value 5 or 6 must switch their primary route to the
+     new primary router and remove the route for the backup router, since
+     it is not anymore the primary router of the cell.  They must also
+     update their local database to understand that the clients are
+     not originated from the backup router but from the locally connected
+     servers.  After that they MUST announce their channels, channel
+     users, modes etc. to the primary router.  They must not use the
+     backup router connection after this and the connection is considered
+     to be passive connection.  The implementations SHOULD be able
+     to disable the connection without closing the actual link.
+
+After this protocol is executed the backup router is now again normal
+server in the cell that has the backup link to the primary router.  The
+primary router feeds the router specific data again to the backup router.
+All server connections in the backup router are considered passive
+connections.
+
+When the primary router of the cell comes back online and connects
+to its primary router, the remote primary router must send the 
+SILC_PACKET_RESUME_ROUTER with type value 20 indicating that the
+connection is not allowed since the router has been replaced by an
+backup router.  The session ID value in this packet SHOULD be zero (0).
+When the router receives this packet it must not use the connection
+as active connection but to understand that it cannot act as primary
+router in the cell.  It must wait that the backup router connects to
+it, and the backup resuming protocol is executed.
+
+The following type values has been defined for SILC_PACKET_RESUME_ROUTER
+packet:
+
+  1    SILC_SERVER_BACKUP_START
+  2    SILC_SERVER_BACKUP_START_GLOBAL
+  3    SILC_SERVER_BACKUP_START_CONNECTED
+  4    SILC_SERVER_BACKUP_START_ENDING
+  5    SILC_SERVER_BACKUP_START_RESUMED
+  6    SILC_SERVER_BACKUP_START_RESUMED_GLOBAL
+  20   SILC_SERVER_BACKUP_START_REPLACED
+  21   SILC_SERVER_BACKUP_START_USE
+  22   SILC_SERVER_BACKUP_START_USE_DENIED
+
+If any other value is found in the type field the packet must be 
+discarded.  The SILC_PACKET_RESUME_ROUTER packet and its payload
+is defined in [SILC2].
+
+
+
+
+.ti 0
+3.13.3 Discussion on Backup Router Scheme
+
+It is clear that this backup router support is not able to handle all
+possible situations arising in unreliable network environment.  This
+scheme for example does not handle situation when the router actually
+does not go offline but the network link goes down temporarily.  It would
+require some intelligence to figure out when it is best time to switch
+to the backup router.  To make it even more complicated it is possible
+that the backup router may have not lost the network link to the primary
+router.
+
+Other possible situation is when the network link is lost temporarily
+between two primary routers in the SILC network.  Unless the routers
+notice the link going down they cannot perhaps find alternative routes.
+Worst situation is when the link goes down only for a short period of
+time, thus causing lag.  Should the routers or servers find alternative
+routes if they cannot get response from the router during the lag?
+When alternative routes are being found it must be careful not to
+mess up existing primary routes between routers in the network.
+
+It is suggested that the current backup router scheme is only temporary
+solution and existing backup router protocols are studied further.  It
+is also suggested that the backup router specification will be separated
+from this SILC specification Internet-Draft and additional specification
+is written on the subject.
+
+
+.ti 0
+4 SILC Procedures
+
+This section describes various SILC procedures such as how the 
+connections are created and registered, how channels are created and
+so on.  The section describes the procedures only generally as details
+are described in [SILC2] and [SILC3].
+
+
+.ti 0
+4.1 Creating Client Connection
+
+This section describes the procedure when client connects to SILC server.
+When client connects to server the server MUST perform IP address lookup
+and reverse IP address lookup to assure that the origin host really is
+who it claims to be.  Client, host, connecting to server SHOULD have 
+both valid IP address and fully qualified domain name (FQDN).
+
+After that the client and server performs SILC Key Exchange protocol
+which will provide the key material used later in the communication.
+The key exchange protocol MUST be completed successfully before the
+connection registration may continue.  The SILC Key Exchange protocol
+is described in [SILC3].
+
+Typical server implementation would keep a list of connections that it
+allows to connect to the server.  The implementation would check, for
+example, the connecting client's IP address from the connection list
+before the SILC Key Exchange protocol has been started.  Reason for
+this is that if the host is not allowed to connect to the server there
+is no reason to perform the key exchange protocol.
+
+After successful key exchange protocol the client and server performs
+connection authentication protocol.  The purpose of the protocol is to
+authenticate the client connecting to the server.  Flexible
+implementation could also accept the client to connect to the server
+without explicit authentication.  However, if authentication is
+desired for a specific client it may be based on passphrase or
+public key authentication.  If authentication fails the connection
+MUST be terminated.  The connection authentication protocol is described
+in [SILC3].
+
+After successful key exchange and authentication protocol the client
+registers itself by sending SILC_PACKET_NEW_CLIENT packet to the
+server.  This packet includes various information about the client
+that the server uses to create the client.  Server creates the client
+and sends SILC_PACKET_NEW_ID to the client which includes the created
+Client ID that the client MUST start using after that.  After that
+all SILC packets from the client MUST have the Client ID as the
+Source ID in the SILC Packet Header, described in [SILC2].
+
+Client MUST also get the server's Server ID that is to be used as
+Destination ID in the SILC Packet Header when communicating with
+the server (for example when sending commands to the server).  The
+ID may be resolved in two ways.  Client can take the ID from an
+previously received packet from server that MUST include the ID,
+or to send SILC_COMMAND_INFO command and receive the Server ID as
+command reply.
+
+Server MAY choose not to use the information received in the
+SILC_PACKET_NEW_CLIENT packet.  For example, if public key or 
+certificate were used in the authentication, server MAY use those
+informations rather than what it received from client.  This is suitable
+way to get the true information about client if it is available.
+
+The nickname of client is initially set to the username sent in the
+SILC_PACKET_NEW_CLIENT packet.  User should set the nickname to more
+suitable by sending SILC_COMMAND_NICK command.  However, this is not
+required as part of registration process.
+
+Server MUST also distribute the information about newly registered
+client to its router (or if the server is router, to all routers in
+the SILC network).  More information about this in [SILC2].
+
+Router server MUST also check whether some client in the local cell
+is watching for the nickname this new client has, and send the 
+SILC_NOTIFY_TYPE_WATCH to the watcher.
+
+
+.ti 0
+4.2 Creating Server Connection
+
+This section describes the procedure when server connects to its
+router (or when router connects to other router, the cases are
+equivalent).  The procedure is very much alike when client connects
+to the server thus it is not repeated here.
+
+One difference is that server MUST perform connection authentication
+protocol with proper authentication.  A proper authentication is based
+on passphrase authentication or public key authentication based on
+digital signatures.
+
+After server and router has successfully performed the key exchange
+and connection authentication protocol, the server register itself
+to the router by sending SILC_PACKET_NEW_SERVER packet.  This packet
+includes the server's Server ID that it has created by itself and
+other relevant information about the server.
+
+After router has received the SILC_PACKET_NEW_SERVER packet it
+distributes the information about newly registered server to all routers
+in the SILC network.  More information about this in [SILC2].
+
+As client needed to resolve the destination ID this MUST be done by the
+server that connected to the router, as well.  The way to resolve it is
+to get the ID from previously received packet.  The server MAY also 
+use SILC_COMMAND_INFO command to resolve the ID.  Server MUST also start
+using its own Server ID as Source ID in SILC Packet Header and the
+router's Server ID as Destination when communicating with the router.
+
+
+.ti 0
+4.2.1 Announcing Clients, Channels and Servers
+
+After server or router has connected to the remote router, and it already
+has connected clients and channels it MUST announce them to the router.
+If the server is router server, also all the local servers in the cell
+MUST be announced.
+
+All clients are announced by compiling a list of ID Payloads into the
+SILC_PACKET_NEW_ID packet.  All channels are announced by compiling a
+list of Channel Payloads into the SILC_PACKET_NEW_CHANNEL packet.
+Channels' mode and founder public key and other channel mode specific
+data is announced by sending SILC_NOTIFY_TYPE_CMODE_CHANGE notify list.
+Also, the channel users on the channels must be announced by compiling a
+list of Notify Payloads with the SILC_NOTIFY_TYPE_JOIN notify type into
+the SILC_PACKET_NOTIFY packet.  The users' modes on the channel must 
+also be announced by compiling list of Notify Payloads with the 
+SILC_NOTIFY_TYPE_CUMODE_CHANGE notify type into the SILC_PACKET_NOTIFY
+packet.
+
+The router MUST also announce the local servers by compiling list of
+ID Payloads into the SILC_PACKET_NEW_ID packet.
+
+Also, clients' modes (user modes in SILC) MUST be announced.  This is
+done by compiling a list of Notify Payloads with SILC_NOTIFY_UMODE_CHANGE
+notify type into the SILC_PACKET_NOTIFY packet.  Also, channel's topics
+MUST be announced by compiling a list of Notify Payloads with the
+SILC_NOTIFY_TOPIC_SET notify type into the SILC_PACKET_NOTIFY packet.
+
+The router which receives these lists MUST process them and broadcast
+the packets to its primary route.  When processing the announced channels
+and channel users the router MUST check whether a channel exists already
+with the same name.  If channel exists with the same name it MUST check
+whether the Channel ID is different.  If the Channel ID is different the
+router MUST send the notify type SILC_NOTIFY_TYPE_CHANNEL_CHANGE to the
+server to force the channel ID change to the ID the router has.  If the
+mode of the channel is different the router MUST send the notify type
+SILC_NOTIFY_TYPE_CMODE_CHANGE to the server to force the mode change
+to the mode that the router has.
+
+The router MUST also generate new channel key and distribute it to the
+channel.  The key MUST NOT be generated if the SILC_CMODE_PRIVKEY mode
+is set.
+
+If the channel has channel founder on the router the router MUST send
+the notify type SILC_NOTIFY_TYPE_CUMODE_CHANGE to the server to force
+the mode change for the channel founder on the server.  The channel 
+founder privileges MUST be removed.
+
+The router processing the channels MUST also compile a list of
+Notify Payloads with the SILC_NOTIFY_TYPE_JOIN notify type into the
+SILC_PACKET_NOTIFY and send the packet to the server.  This way the
+server (or router) will receive the clients on the channel that
+the router has.
+
+
+.ti 0
+4.3 Joining to a Channel
+
+This section describes the procedure when client joins to a channel.
+Client joins to channel by sending command SILC_COMMAND_JOIN to the
+server.  If the receiver receiving join command is normal server the
+server MUST check its local list whether this channel already exists
+locally.  This would indicate that some client connected to the server
+has already joined to the channel.  If this is case the client is
+joined to the channel, new channel key is created and information about
+newly joined channel is sent to the router.  The router is informed
+by sending SILC_NOTIFY_TYPE_JOIN notify type.  The notify type MUST
+also be sent to the local clients on the channel.  The new channel key
+is also sent to the router and to local clients on the channel.
+
+If the channel does not exist in the local list the client's command
+MUST be sent to the router which will then perform the actual joining
+procedure.  When server receives the reply to the command from the
+router it MUST be sent to the client which sent the command originally.
+Server will also receive the channel key from the server that it MUST
+send to the client which originally requested the join command.  The
+server MUST also save the channel key.
+
+If the receiver of the join command is router it MUST first check its
+local list whether anyone in the cell has already joined to the channel.
+If this is the case the client is joined to the channel and reply is
+sent to the client.  If the command was sent by server the command reply
+is sent to the server which sent it.  Then the router MUST also create
+new channel key and distribute it to all clients on the channel and
+all servers that has clients on the channel.  Router MUST also send
+the SILC_NOTIFY_TYPE_JOIN notify type to local clients on the channel
+and to local servers that has clients on the channel.
+
+If the channel does not exist on the router's local list it MUST
+check the global list whether the channel exists at all.  If it does
+the client is joined to the channel as described previously.  If
+the channel does not exist the channel is created and the client
+is joined to the channel.  The channel key is also created and
+distributed as previously described.  The client joining to the created
+channel is made automatically channel founder and both channel founder
+and channel operator privileges is set for the client.
+
+If the router created the channel in the process, information about the
+new channel MUST be broadcasted to all routers.  This is done by 
+broadcasting SILC_PACKET_NEW_CHANNEL packet to the router's primary
+route.  When the router joins the client to the channel it MUST also
+send information about newly joined client to all routers in the SILC
+network.  This is done by broadcasting the SILC_NOTIFY_TYPE_JOIN notify
+type to the router's primary route. 
+
+It is important to note that new channel key is created always when
+new client joins to channel, whether the channel has existed previously
+or not.  This way the new client on the channel is not able to decrypt
+any of the old traffic on the channel.  Client which receives the reply to
+the join command MUST start using the received Channel ID in the channel
+message communication thereafter.  Client also receives the key for the
+channel in the command reply.  Note that the channel key is never
+generated if the SILC_CMODE_PRIVKEY mode is set.
+
+
+.ti 0
+4.4 Channel Key Generation
+
+Channel keys are created by router which creates the channel by taking
+enough randomness from cryptographically strong random number generator.
+The key is generated always when channel is created, when new client
+joins a channel and after the key has expired.  Key could expire for
+example in an hour.
+
+The key MUST also be re-generated whenever some client leaves a channel.
+In this case the key is created from scratch by taking enough randomness
+from the random number generator.  After that the key is distributed to
+all clients on the channel.  However, channel keys are cell specific thus
+the key is created only on the cell where the client, which left the
+channel, exists.  While the server or router is creating the new channel
+key, no other client may join to the channel.  Messages that are sent
+while creating the new key are still processed with the old key.  After
+server has sent the SILC_PACKET_CHANNEL_KEY packet MUST client start
+using the new key.  If server creates the new key the server MUST also
+send the new key to its router.  See [SILC2] on more information about
+how channel messages must be encrypted and decrypted when router is
+processing them.
+
+When client receives the SILC_PACKET_CHANNEL_KEY packet with the
+Channel Key Payload it MUST process the key data to create encryption
+and decryption key, and to create the HMAC key that is used to compute
+the MACs of the channel messages.  The processing is as follows:
+
+  channel_key  = raw key data
+  HMAC key     = hash(raw key data)
+
+The raw key data is the key data received in the Channel Key Payload.
+The hash() function is the hash function used in the HMAC of the channel.
+Note that the server also MUST save the channel key.
+
+
+.ti 0
+4.5 Private Message Sending and Reception
+
+Private messages are sent point to point.  Client explicitly destine
+a private message to specific client that is delivered to only to that
+client.  No other client may receive the private message.  The receiver
+of the private message is destined in the SILC Packet Header as any
+other packet as well.
+
+If the sender of a private message does not know the receiver's Client
+ID, it MUST resolve it from server.  There are two ways to resolve the
+client ID from server; it is RECOMMENDED that client implementations
+send SILC_COMMAND_IDENTIFY command to receive the Client ID.  Client
+MAY also send SILC_COMMAND_WHOIS command to receive the Client ID.
+If the sender has received earlier a private message from the receiver
+it should have cached the Client ID from the SILC Packet Header.
+
+If server receives a private message packet which includes invalid
+destination Client ID the server MUST send SILC_NOTIFY_TYPE_ERROR
+notify to the client with error status indicating that such Client ID
+does not exist.
+
+See [SILC2] for description of private message encryption and decryption
+process.
+
+
+.ti 0
+4.6 Private Message Key Generation
+
+Private message MAY be protected with a key generated by the client.
+The key may be generated and sent to the other client by sending packet
+SILC_PACKET_PRIVATE_MESSAGE_KEY which travels through the network
+and is secured by session keys.  After that the private message key
+is used in the private message communication between those clients.
+The key sent inside the payload SHOULD be randomly generated.  This
+packet MUST NOT be used to send pre-shared keys.
+
+Other choice is to entirely use keys that are not sent through
+the SILC network at all.  This significantly adds security.  This key
+could be a pre-shared-key that is known by both of the clients.  Both
+agree about using the key and starts sending packets that indicate
+that the private message is secured using private message key.  In
+case of pre-shared keys (static keys) the IV used in encryption SHOULD
+be chosen randomly.
+
+It is also possible to negotiate fresh key material by performing
+Key Agreement.  The SILC_PACKET_KEY_AGREEMENT packet MAY be used to
+negotiate the fresh key material.  In this case the resulted key
+material is used to secure the private messages.  Also, the IV used
+in encryption is used as defined in [SILC3], unless otherwise stated
+by the encryption mode used.  By performing Key Agreement the clients
+may negotiate the cipher and HMAC to be used in the private message
+encryption and to negotiate additional security parameters.
+
+If the key is pre-shared key or other key material not generated by
+Key Agreement, then the key material SHOULD be processed as defined
+in [SILC3].  The hash function to be used SHOULD be SHA1.  In the
+processing, however, the HASH, as defined in [SILC3] MUST be ignored.
+After processing the key material it is employed as defined in [SILC3].
+In this case also, implementations SHOULD use the SILC protocol's
+mandatory cipher and HMAC in private message encryption.
+
+
+.ti 0
+4.7 Channel Message Sending and Reception
+
+Channel messages are delivered to group of users.  The group forms a
+channel and all clients on the channel receives messages sent to the
+channel.
+
+Channel messages are destined to channel by specifying the Channel ID
+as Destination ID in the SILC Packet Header.  The server MUST then
+distribute the message to all clients on the channel by sending the
+channel message destined explicitly to a client on the channel.
+
+If server receives a channel message packet which includes invalid
+destination Channel ID the server MUST send SILC_NOTIFY_TYPE_ERROR
+notify to the sender with error status indicating that such Channel ID
+does not exist.
+
+See the [SILC2] for description of channel message routing for router
+servers, and channel message encryption and decryption process.
+
+
+.ti 0
+4.8 Session Key Regeneration
+
+Session keys MUST be regenerated periodically, say, once in an hour.
+The re-key process is started by sending SILC_PACKET_REKEY packet to
+other end, to indicate that re-key must be performed.  The initiator
+of the connection SHOULD initiate the re-key.
+
+If perfect forward secrecy (PFS) flag was selected in the SILC Key
+Exchange protocol [SILC3] the re-key MUST cause new key exchange with
+SKE protocol.  In this case the protocol is secured with the old key
+and the protocol results to new key material.  See [SILC3] for more
+information.  After the SILC_PACKET_REKEY packet is sent the sender
+will perform the SKE protocol.
+
+If PFS flag was set the resulted key material is processed as described
+in the section Processing the Key Material in [SILC3].  The difference
+with re-key in the processing is that the initial data for the hash 
+function is just the resulted key material and not the HASH as it
+is not computed at all with re-key.  Other than that, the key processing
+it equivalent to normal SKE negotiation.
+
+If PFS flag was not set, which is the default case, then re-key is done
+without executing SKE protocol.  In this case, the new key is created by
+providing the current sending encryption key to the SKE protocol's key
+processing function.  The process is described in the section Processing
+the Key Material in [SILC3].  The difference in the processing is that
+the initial data for the hash function is the current sending encryption
+key and not the SKE's KEY and HASH values.  Other than that, the key
+processing is equivalent to normal SKE negotiation.
+
+After both parties has regenerated the session key, both MUST send
+SILC_PACKET_REKEY_DONE packet to each other.  These packets are still
+secured with the old key.  After these packets, the subsequent packets
+MUST be protected with the new key.
+
+
+.ti 0
+4.9 Command Sending and Reception
+
+Client usually sends the commands in the SILC network.  In this case
+the client simply sends the command packet to server and the server
+processes it and replies with command reply packet.  See the [SILC3]
+for detailed description of all commands.
+
+However, if the server is not able to process the command, it is sent 
+to the server's router.  This is case for example with commands such
+as, SILC_COMMAND_JOIN and SILC_COMMAND_WHOIS commands.  However, there
+are other commands as well.  For example, if client sends the WHOIS
+command requesting specific information about some client the server must
+send the WHOIS command to router so that all clients in SILC network
+are searched.  The router, on the other hand, sends the WHOIS command
+further to receive the exact information about the requested client.
+The WHOIS command travels all the way to the server which owns the client
+and it replies with command reply packet.  Finally, the server which
+sent the command receives the command reply and it must be able to
+determine which client sent the original command.  The server then
+sends command reply to the client.  Implementations should have some
+kind of cache to handle, for example, WHOIS information.  Servers
+and routers along the route could all cache the information for faster
+referencing in the future.
+
+The commands sent by server may be sent hop by hop until someone is able
+to process the command.  However, it is preferred to destine the command
+as precisely as it is possible.  In this case, other routers en route
+MUST route the command packet by checking the true sender and true
+destination of the packet.  However, servers and routers MUST NOT route
+command reply packets to clients coming from other server.  Client
+MUST NOT accept command reply packet originated from anyone else but
+from its own server.
+
+
+
+.ti 0
+4.10 Closing Connection
+
+When remote client connection is closed the server MUST send the notify
+type SILC_NOTIFY_TYPE_SIGNOFF to its primary router and to all channels
+the client was joined.  The server MUST also save the client's information
+for a period of time for history purposes.
+
+When remote server or router connection is closed the server or router
+MUST also remove all the clients that was behind the server or router
+from the SILC Network.  The server or router MUST also send the notify
+type SILC_NOTIFY_TYPE_SERVER_SIGNOFF to its primary router and to all
+local clients that are joined on the same channels with the remote 
+server's or router's clients.
+
+Router server MUST also check whether some client in the local cell
+is watching for the nickname this client has, and send the 
+SILC_NOTIFY_TYPE_WATCH to the watcher, unless the client which left
+the network has the SILC_UMODE_REJECT_WATCHING user mode set.
+
+
+.ti 0
+4.11 Detaching and Resuming a Session
+
+SILC protocol provides a possibility for a client to detach itself from
+the network without actually signing off from the network.  The client
+connection to the server is closed but the client remains as valid client
+in the network.  The client may then later resume its session back from
+any server in the network.
+
+When client wishes to detach from the network it MUST send the
+SILC_COMMAND_DETACH command to its server.  The server then MUST set
+SILC_UMODE_DETACHED mode to the client and send SILC_NOTIFY_UMODE_CHANGE
+notify to its primary router, which will then MUST broadcast it further
+to other routers in the network.  This user mode indicates that the
+client is detached from the network.  Implementations MUST NOT use
+the SILC_UMODE_DETACHED flag to determine whether a packet can be sent
+to the client.  All packets MUST still be sent to the client even if
+client is detached from the network.  Only the server that originally
+had the active client connection is able to make the decision after it
+notices that the network connection is not active.  In this case the
+default case is to discard the packet.
+
+The SILC_UMODE_DETACHED flag cannot be set by client itself directly
+with SILC_COMMAND_UMODE command, but only implicitly by sending the
+SILC_COMMAND_DETACH command.  The flag also cannot be unset by the
+client, server or router with SILC_COMMAND_UMODE command, but only
+implicitly by sending and receiving the SILC_PACKET_RESUME_CLIENT
+packet.
+
+When the client wishes to resume its session in the SILC Network it
+connects to a server in the network, which MAY also be a different
+from the original server, and performs normal procedures regarding
+creating a connection as described in section 4.1.  After the SKE
+and the Connection Authentication protocols has been successfully
+completed the client MUST NOT send SILC_PACKET_NEW_CLIENT packet, but
+MUST send SILC_PACKET_RESUME_CLIENT packet.  This packet is used to
+perform the resuming procedure.  The packet MUST include the detached
+client's Client ID, which the client must know.  It also includes
+Authentication Payload which includes signature made with the client's
+private key.  The signature is computed as defined in the section
+3.9.1.  Thus, the authentication method MUST be based in public key
+authentication.
+
+When server receives the SILC_PACKET_RESUME_CLIENT packet it MUST
+do the following:  Server checks that the Client ID is valid client
+and that it has the SILC_UMODE_DETACHED mode set.  Then it verifies
+the Authentication Payload with the detached client's public key.
+If it does not have the public key it retrieves it by sending
+SILC_COMMAND_GETKEY command to the server that has the public key from
+the original client connection.  The server MUST NOT use the public
+key received in the SKE protocol for this connection.  If the
+signature is valid the server unsets the SILC_UMODE_DETACHED flag,
+and sends the SILC_PACKET_RESUME_CLIENT packet to its primary router.
+The routers MUST broadcast the packet and unset the SILC_UMODE_DETACHED
+flag when the packet is received.  If the server is router server it
+also MUST send the SILC_PACKET_RESUME_CLIENT packet to the original
+server whom owned the detached client.
+
+The servers and routers that receives the SILC_PACKET_RESUME_CLIENT
+packet MUST know whether the packet already has been received for
+the client.  It is protocol error to attempt to resume the client
+session from more than one server.  The implementations could set
+internal flag that indicates that the client is resumed.  If router
+receive SILC_PACKET_RESUME_CLIENT packet for client that is already
+resumed the client MUST be killed from the network.  This would
+indicate that the client is attempting to resume the session more
+than once which is protocol error.  In this case the router sends
+SILC_NOTIFY_TYPE_KILLED to the client.  All routers that detect
+the same situation MUST also send the notify for the client.
+
+The servers and routers that receive the SILC_PACKET_RESUME_CLIENT
+must also understand that the client may not be found behind the
+same server that it originally came from.  They must update their
+caches according this.  The server that now owns the client session
+MUST check whether the Client ID of the resumed client is based
+on the server's Server ID.  If it is not it creates a new Client
+ID and send SILC_NOTIFY_TYPE_NICK_CHANGE to the network.  It MUST
+also send the channel keys of all channels that the client is
+joined to the client since it does not have them.  Whether the
+Client ID was changed or not the server MUST send SILC_PACKET_NEW_ID
+packet to the client.  Only after this the client is resumed back
+to the network and may start sending packets and messages.
+
+It is also possible that the server does not know about the channels
+that the client has joined.  In this case it join the client internally
+to the channels, generate new channel keys and distribute the keys
+to the channels as described in section 4.4.
+
+It is implementation issue for how long servers keep detached client
+sessions.  It is RECOMMENDED that the detached sessions would be
+persistent as long as the server is running.
+
+
+.ti 0
+5 Security Considerations
+
+Security is central to the design of this protocol, and these security
+considerations permeate the specification.  Common security considerations
+such as keeping private keys truly private and using adequate lengths for
+symmetric and asymmetric keys must be followed in order to maintain the
+security of this protocol.
+
+Special attention must also be paid on the servers and routers that are
+running the SILC service.  The SILC protocol's security depends greatly
+on the security and the integrity of the servers and administrators that
+are running the service.  It is recommended that some form of registration
+is required by the server and router administrator prior acceptance to
+the SILC Network.  Even though, the SILC protocol is secure in a network
+of mutual distrust between clients, servers, routers and administrators
+of the servers, the client should be able to trust the servers they are
+using if they wish to do so.
+
+It however must be noted that if the client requires absolute security
+by not trusting any of the servers or routers in the SILC Network, it can
+be accomplished by negotiating private keys outside the SILC Network,
+either using SKE or some other key exchange protocol, or to use some
+other external means for distributing the keys.  This applies for all 
+messages, private messages and channel messages.
+
+It is important to note that SILC, like any other security protocol is
+not full proof system; the SILC servers and routers could very well be
+compromised.  However, to provide acceptable level of security and
+usability for end user the protocol use many times session keys or other
+keys generated by the servers to secure the messages.  This is
+intentional design feature to allow ease of use for end user.  This way
+the network is still usable, and remains encrypted even if the external
+means of distributing the keys is not working.  The implementation,
+however, may like to not follow this design feature, and always negotiate
+the keys outside SILC network.  This is acceptable solution and many times
+recommended.  The implementation still must be able to work with the
+server generated keys.
+
+If this is unacceptable for the client or end user, the private keys
+negotiated outside the SILC Network should always be used.  In the end
+it is always implementor's choice whether to negotiate private keys by
+default or whether to use the keys generated by the servers.
+
+It is also recommended that router operators in the SILC Network would
+form a joint forum to discuss the router and SILC Network management
+issues.  Also, router operators along with the cell's server operators
+should have a forum to discuss the cell management issues.
+
+
+.ti 0
+6 References
+
+[SILC2]      Riikonen, P., "SILC Packet Protocol", Internet Draft,
+             May 2002.
+
+[SILC3]      Riikonen, P., "SILC Key Exchange and Authentication 
+             Protocols", Internet Draft, May 2002.
+
+[SILC4]      Riikonen, P., "SILC Commands", Internet Draft, May 2002.
+
+[IRC]        Oikarinen, J., and Reed D., "Internet Relay Chat Protocol",
+             RFC 1459, May 1993.
+
+[IRC-ARCH]   Kalt, C., "Internet Relay Chat: Architecture", RFC 2810,
+             April 2000.
+
+[IRC-CHAN]   Kalt, C., "Internet Relay Chat: Channel Management", RFC
+             2811, April 2000.
+
+[IRC-CLIENT] Kalt, C., "Internet Relay Chat: Client Protocol", RFC
+             2812, April 2000.
+
+[IRC-SERVER] Kalt, C., "Internet Relay Chat: Server Protocol", RFC
+             2813, April 2000.
+
+[SSH-TRANS]  Ylonen, T., et al, "SSH Transport Layer Protocol", 
+             Internet Draft.
+
+[PGP]        Callas, J., et al, "OpenPGP Message Format", RFC 2440,
+             November 1998.
+
+[SPKI]       Ellison C., et al, "SPKI Certificate Theory", RFC 2693,
+             September 1999.
+
+[PKIX-Part1] Housley, R., et al, "Internet X.509 Public Key 
+             Infrastructure, Certificate and CRL Profile", RFC 2459,
+             January 1999.
+
+[Schneier]   Schneier, B., "Applied Cryptography Second Edition",
+             John Wiley & Sons, New York, NY, 1996.
+
+[Menezes]    Menezes, A., et al, "Handbook of Applied Cryptography",
+             CRC Press 1997.
+
+[OAKLEY]     Orman, H., "The OAKLEY Key Determination Protocol",
+             RFC 2412, November 1998.
+
+[ISAKMP]     Maughan D., et al, "Internet Security Association and
+             Key Management Protocol (ISAKMP)", RFC 2408, November
+             1998.
+
+[IKE]        Harkins D., and Carrel D., "The Internet Key Exchange
+             (IKE)", RFC 2409, November 1998.
+
+[HMAC]       Krawczyk, H., "HMAC: Keyed-Hashing for Message
+             Authentication", RFC 2104, February 1997.
+
+[PKCS1]      Kalinski, B., and Staddon, J., "PKCS #1 RSA Cryptography
+             Specifications, Version 2.0", RFC 2437, October 1998.
+
+[RFC2119]    Bradner, S., "Key Words for use in RFCs to Indicate
+             Requirement Levels", BCP 14, RFC 2119, March 1997.
+
+[RFC2279]    Yergeau, F., "UTF-8, a transformation format of ISO
+             10646", RFC 2279, January 1998.
+
+[PKCS7]      Kalinski, B., "PKCS #7: Cryptographic Message Syntax,
+             Version 1.5", RFC 2315, March 1998.
+
+
+.ti 0
+7 Author's Address
+
+.nf
+Pekka Riikonen
+Snellmaninkatu 34 A 15
+70100 Kuopio
+Finland
+
+EMail: priikone@iki.fi
+
+This Internet-Draft expires XXX
index f6e7839ab62528ea71cfd0bb5d07e8dbe272680c..41426d40497cc96af54d9858257d251fc5784657 100644 (file)
@@ -405,10 +405,9 @@ ConnectionParams {
 #
 # The authentication data is specified by Passphrase and/or PublicKey.
 # If both are provided then both password and public key based authentication
-# is allowed.  If the Publickey is used it includes the file path to the
-# public key file.  If none of them is provided then authentication is not
-# required.  The PublicKey can be set multiple times to set multiple
-# public keys for one connection.
+# is allowed.  The "PublicKey" includes the single key contained in the
+# specified file, while "PublicKeyDir" includes all files in the specified
+# directory, which must all be valid public keys with ".pub" suffix.
 #
 # Next example connection will match to all incoming client connections,
 # and no authentication is required.
@@ -416,9 +415,10 @@ ConnectionParams {
 Client {
        #Host = "10.1.*";
        #Passphrase = "secret";
-       #PublicKey = "/path/to/the/user_my.key";
-       #PublicKey = "/path/to/the/user_221.key";
-       #PublicKey = "/path/to/the/user_313.key";
+       #PublicKey = "/path/to/the/user_my.pub";
+       #PublicKey = "/path/to/the/user_221.pub";
+       #PublicKey = "/path/to/the/user_313.pub";
+       #PublicKeyDir = "/path/to/keys/dir/";
        Params = "normal";
 };
 
@@ -439,7 +439,7 @@ Admin {
        User = "priikone";
        Nick = "pekka";
        Passphrase = "verysecret";
-       # PublicKey = "/path/to/the/public.key";
+       # PublicKey = "/path/to/the/public.pub";
 };
 
 #
@@ -463,7 +463,7 @@ Admin {
 ServerConnection {
        Host = "10.2.1.7";
        Passphrase = "verysecret";
-       #PublicKey = "/path/to/the/public.key";
+       #PublicKey = "/path/to/the/public.pub";
        Params = "normal";
        Backup = false;
 };
@@ -500,7 +500,7 @@ RouterConnection {
        Host = "10.2.1.100";
        Port = 706;
        Passphrase = "verysecret";
-       #PublicKey = "/path/to/the/public.key";
+       #PublicKey = "/path/to/the/public.pub";
        Params = "normal";
        Initiator = true;
        #BackupHost = "10.2.1.6";
index 0eecf1398112501200b287dbcb0e7bfcd3e5cc9b..726b0a70eafeb8d5ee8cce7bda70a8164b92e039 100644 (file)
@@ -1,4 +1,4 @@
-manpage(SILC) (1) (October 31 2002) (silc-client-0.9.7) (silc-client)
+manpage(SILC) (1) (December 7 2002) (silc-client) (silc-client)
 
 
 manpagename(silc) (client for SILC, a secure and flexible conferencing network)
@@ -16,11 +16,12 @@ the SILC network.  The silc client resembles IRC clients to make the
 using easier for new users.
 
 bf(Silc) supports sending of practically any kind of messages in addition
-of normal text messages in the SILC network.  The session to SILC server
+of normal text messages in the SILC network.  This includes multimedia
+messages like images, video and audio stream.  The session to SILC server
 is secured with session key, channel messages are protected with channel
 key and private messages with session keys.  It is also possible to use
 private channel keys and private message keys in addition to server
-generated keys.
+generated keys.  It is also possible to digitally sign all messages.
 
 bf(Silc) supports em(passphrase) authentication and public key authentication
 based on em(digital signatures), when connecting to SILC server.  bf(Silc)
index 406001d674a2b5ff0462849257d457f2258dd965..9eab20c4ca3b15e415d6a879847cdfa08d894210 100644 (file)
@@ -1,4 +1,4 @@
-manpage(SILCD_CONF) (5) (November 2 2002) (silc-server-0.9.7.1) (silc-server)
+manpage(SILCD_CONF) (5) (November 2 2002) (silc-server) (silc-server)
 
 
 manpagename(silcd.conf) (format of configuration file for silcd)
index e104a9a99bf5aa828e35d8249c38be9c1a836f3a..a4677d25387ba37db1c748df9fa9c78ea121a851 100644 (file)
@@ -1,4 +1,4 @@
-manpage(SILCD) (8) (October 31 2002) (silc-server-0.9.7.1) (silc-server)
+manpage(SILCD) (8) (October 31 2002) (silc-server) (silc-server)
 
 
 manpagename(silcd) (SILC server)
index 26486bc31c863d802f9e8bde857802ef4147b46a..e670a75f96950223a118987606e93e7d1abab982 100644 (file)
 #endif
 #endif
 
+# Some winsock compatiblity requirements
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x400
+#else
+#undef _WIN32_WINNT
+#define _WIN32_WINNT 0x400
+#endif /* _WIN32_WINNT */
+#if !defined(SO_SYNCHRONOUS_NONALERT)
+#define SO_SYNCHRONOUS_NONALERT 0x20
+#endif
+#if !defined(SO_OPENTYPE)
+#define SO_OPENTYPE 0x7008
+#endif
+
 #undef inline
 #define inline __inline
 
index 626978adbd9d5a726596e9de5aeaab92b91b3b3c..fc4c150571f6aabed45d78ed14466cf66a0f1a69 100644 (file)
@@ -69,10 +69,21 @@ remove:
        -rm -rf libsilc.a
        -rm -rf libsilcclient.a
 
+if SILC_DIST_TOOLKIT
+install-exec-hook:
+       -mkdir -p $(DESTDIR)$(libdir)
+       -$(LIBTOOL) $(INSTALL) libsilc.la $(DESTDIR)$(libdir)/
+       -$(LIBTOOL) $(INSTALL) libsilcclient.la $(DESTDIR)$(libdir)/
+else
 install-exec-hook:
        -mkdir -p $(libdir)
-       -$(LIBTOOL) $(INSTALL) libsilc.la $(libdir)/
-       -$(LIBTOOL) $(INSTALL) libsilcclient.la $(libdir)/
+       -$(LIBTOOL) $(INSTALL) libsilc.la $(DESTDIR)$(libdir)/
+       -rm -rf $(DESTDIR)$(libdir)/libsilc.a
+if SILC_DIST_CLIENT
+       -$(LIBTOOL) $(INSTALL) libsilcclient.la $(DESTDIR)$(libdir)/
+       -rm -rf $(DESTDIR)$(libdir)/libsilcclient.a
+endif
+endif
 
 if SILC_DIST_WIN32DLL
 # WIN32 DLL generation
@@ -88,15 +99,25 @@ silcclient.dll: libsilcclient.a
        -mno-cygwin -o silcclient.dll libsilcclient.a -L. -lsilc -lwsock32
 endif
 
+LIB_BASE_VERSION=@LIB_BASE_VERSION@
+LIBSILC_CURRENT=@LIBSILC_CURRENT@
+LIBSILC_REVISION=@LIBSILC_REVISION@
+LIBSILC_AGE=@LIBSILC_AGE@
+LIBSILCCLIENT_CURRENT=@LIBSILCCLIENT_CURRENT@
+LIBSILCCLIENT_REVISION=@LIBSILCCLIENT_REVISION@
+LIBSILCCLIENT_AGE=@LIBSILCCLIENT_AGE@
+
 libsilc.a:
        find $(SILCLIB_DIRS) -type f -name *.lo | xargs \
        $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) \
-       -rpath $(libdir) -o libsilc.la
+       -version-info $(LIBSILC_CURRENT):$(LIBSILC_REVISION):$(LIBSILC_AGE) \
+       -release $(LIB_BASE_VERSION) -rpath $(DESTDIR)$(libdir) -o libsilc.la
 
 libsilcclient.a:
        find $(SILCCLIENTLIB_DIRS) -type f -name *.lo | xargs \
        $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) \
-       -rpath $(libdir) -o libsilcclient.la
+       -version-info $(LIBSILCCLIENT_CURRENT):$(LIBSILCCLIENT_REVISION):$(LIBSILCCLIENT_AGE) \
+       -release $(LIB_BASE_VERSION) -rpath $(DESTDIR)$(libdir) -o libsilcclient.la
 
 if SILC_DIST_TOOLKIT
 SILC_EXTRA_DIST = doc
diff --git a/lib/contrib/.cvsignore b/lib/contrib/.cvsignore
new file mode 100644 (file)
index 0000000..282522d
--- /dev/null
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
index ec313c1ae279d5cce34b525b5b0c4732318b8f4c..745cb698b52daf343e7233769ab7df0f770f7c00 100644 (file)
@@ -1645,10 +1645,10 @@ SILC_TASK_CALLBACK(silc_client_send_auto_nick)
 {
   SilcClientConnection conn = (SilcClientConnection)context;
   SilcClient client = conn->client;
-
-  silc_client_command_send(client, conn, SILC_COMMAND_NICK, 
-                          ++conn->cmd_ident, 1, 1, 
-                          client->nickname, strlen(client->nickname));
+  if (client)
+    silc_client_command_send(client, conn, SILC_COMMAND_NICK, 
+                            ++conn->cmd_ident, 1, 1, 
+                            client->nickname, strlen(client->nickname));
 }
 
 /* Client session resuming callback.  If the session was resumed
index b244979fb263da9a450a2a602747455041e5f70a..65a8b03e9e86c26a61796f892aac2507032d8f1f 100644 (file)
@@ -81,7 +81,7 @@ SilcBuffer silc_client_attributes_process(SilcClient client,
   SilcAttribute attribute;
   SilcAttributePayload attr;
   SilcAttributeObjPk pk;
-  unsigned char sign[2048];
+  unsigned char sign[2048 + 1];
   SilcUInt32 sign_len;
 
   SILC_LOG_DEBUG(("Process Requested Attributes"));
index 67cde554841011c0c3919261e60777c4189fa0ad..68983d59c6f6692dc5adf3837deca7c95632cd1f 100644 (file)
@@ -109,7 +109,8 @@ void silc_client_send_channel_message(SilcClient client,
 
   /* Encode the message payload. This also encrypts the message payload. */
   payload = silc_message_payload_encode(flags, data, data_len, TRUE, FALSE,
-                                       cipher, hmac, client->rng);
+                                       cipher, hmac, client->rng, NULL,
+                                       client->private_key, client->sha1hash);
 
   /* Get data used in packet header encryption, keys and stuff. */
   cipher = conn->internal->send_key;
@@ -205,9 +206,9 @@ static void silc_client_channel_message_cb(SilcClient client,
     
     /* Pass the message to application */
     client->internal->ops->channel_message(
-                              client, conn, clients[0], channel,
-                              silc_message_get_flags(res->payload),
-                              message, message_len);
+                           client, conn, clients[0], channel, res->payload,
+                           silc_message_get_flags(res->payload),
+                           message, message_len);
   }
 
  out:
@@ -316,9 +317,9 @@ void silc_client_channel_message(SilcClient client,
 
   /* Pass the message to application */
   client->internal->ops->channel_message(
-                                client, conn, client_entry, channel,
-                                silc_message_get_flags(payload),
-                                message, message_len);
+                            client, conn, client_entry, channel, payload,
+                            silc_message_get_flags(payload),
+                            message, message_len);
 
  out:
   silc_free(id);
@@ -511,7 +512,7 @@ bool silc_client_add_channel_private_key(SilcClient client,
   /* Produce the key material */
   keymat = silc_calloc(1, sizeof(*keymat));
   if (silc_ske_process_key_material_data(key, key_len, 16, 256, 16, 
-                                        client->md5hash, keymat) 
+                                        client->sha1hash, keymat) 
       != SILC_SKE_STATUS_OK)
     return FALSE;
 
index 50d5c562e6d1a35da4860ad7d6ce07fba7cfdcc3..f42ebaa6482bc21f6cd9d16e86df364b0d426847 100644 (file)
@@ -597,82 +597,51 @@ void silc_client_notify_by_server(SilcClient client,
     if (!client_id)
       goto out;
 
-    /* From protocol version 1.1 we get the new nickname in notify as well,
-       so we don't have to resolve it.  Do it the hard way if server doesn't
-       send it to us. */
+    /* Take the nickname */
     tmp = silc_argument_get_arg_type(args, 3, NULL);
-    if (tmp) {
-      /* Protocol version 1.1 */
-      char *tmp_nick = NULL;
-
-      /* Check whether nickname changed at all.  It is possible that nick
-        change notify is received but nickname didn't changed, only the
-        ID changes. */
-      if (client->internal->params->nickname_parse)
-       client->internal->params->nickname_parse(client_entry->nickname,
-                                                &tmp_nick);
-      else
-       tmp_nick = strdup(tmp);
-
-      if (tmp_nick && !strcmp(tmp, tmp_nick)) {
-       /* Nickname didn't change. Update only the ID */
-       silc_idcache_del_by_context(conn->internal->client_cache,
-                                   client_entry);
-       silc_free(client_entry->id);
-       client_entry->id = silc_id_dup(client_id, SILC_ID_CLIENT);
-       silc_idcache_add(conn->internal->client_cache, strdup(tmp),
-                        client_entry->id, client_entry, 0, NULL);
-
-       /* Notify application */
-       client->internal->ops->notify(client, conn, type, 
-                                     client_entry, client_entry);
-       break;
-      }
-      silc_free(tmp_nick);
-
-      /* Create new client entry, and save all old information with the
-        new nickname and client ID */
-      client_entry2 = silc_client_add_client(client, conn, NULL, NULL, 
-                                            client_entry->realname,
-                                            silc_id_dup(client_id, 
-                                                        SILC_ID_CLIENT), 0);
-      if (!client_entry2)
-       goto out;
-
-      if (client_entry->server)
-       client_entry2->server = strdup(client_entry->server);
-      if (client_entry->username)
-       client_entry2->username = strdup(client_entry->username);
-      if (client_entry->hostname)
-       client_entry2->hostname = strdup(client_entry->hostname);
-      silc_client_update_client(client, conn, client_entry2, tmp, NULL, NULL,
-                               client_entry->mode);
-    } else {
-      /* Protocol version 1.0 */
+    if (!tmp)
+      goto out;
 
-      /* Find client entry and if not found resolve it */
-      client_entry2 = silc_client_get_client_by_id(client, conn, client_id);
-      if (!client_entry2) {
-       /* Resolve the entry information */
-       silc_client_notify_by_server_resolve(client, conn, packet, 
-                                            SILC_ID_CLIENT, client_id);
+    /* Check whether nickname changed at all.  It is possible that nick
+       change notify is received but nickname didn't changed, only the
+       ID changes.  Check whether the hashes in the Client ID match, if
+       they do nickname didn't change. */
+    if (SILC_ID_COMPARE_HASH(client_entry->id, client_id)) {
+      /* Nickname didn't change. Update only the ID */
+      silc_idcache_del_by_context(conn->internal->client_cache,
+                                 client_entry);
+      silc_free(client_entry->id);
+      client_entry->id = silc_id_dup(client_id, SILC_ID_CLIENT);
+      silc_idcache_add(conn->internal->client_cache, strdup(tmp),
+                      client_entry->id, client_entry, 0, NULL);
+
+      /* Notify application */
+      client->internal->ops->notify(client, conn, type, 
+                                   client_entry, client_entry);
+      break;
+    }
 
-       /* Add the new entry even though we resolved it. This is because we
-          want to replace the old entry with the new entry here right now. */
-       client_entry2 = 
-         silc_client_add_client(client, conn, NULL, NULL, NULL, 
-                                silc_id_dup(client_id, SILC_ID_CLIENT), 
-                                client_entry->mode);
-
-       /* Replace old ID entry with new one on all channels. */
-       silc_client_replace_from_channels(client, conn, client_entry,
-                                         client_entry2);
-       break;
-      }
+    /* Create new client entry, and save all old information with the
+       new nickname and client ID */
+    client_entry2 = silc_client_add_client(client, conn, NULL, NULL, 
+                                          client_entry->realname,
+                                          silc_id_dup(client_id, 
+                                                      SILC_ID_CLIENT), 0);
+    if (!client_entry2)
+      goto out;
 
-      if (client_entry2 != conn->local_entry)
-       silc_client_nickname_format(client, conn, client_entry2);
-    }
+    if (client_entry->server)
+      client_entry2->server = strdup(client_entry->server);
+    if (client_entry->username)
+      client_entry2->username = strdup(client_entry->username);
+    if (client_entry->hostname)
+      client_entry2->hostname = strdup(client_entry->hostname);
+    client_entry2->fingerprint = client_entry->fingerprint;
+    client_entry2->fingerprint_len = client_entry->fingerprint_len;
+    client_entry->fingerprint = NULL;
+    client_entry->fingerprint_len = NULL;
+    silc_client_update_client(client, conn, client_entry2, tmp, NULL, NULL,
+                             client_entry->mode);
 
     /* Remove the old from cache */
     silc_idcache_del_by_context(conn->internal->client_cache, client_entry);
index c94692da3574ac644ee80aa42b5a21f797c17351..19b9acc14fdc856291da82e83f43c54b5f13938e 100644 (file)
@@ -31,8 +31,8 @@ silc_say(SilcClient client, SilcClientConnection conn,
 static void
 silc_channel_message(SilcClient client, SilcClientConnection conn,
                     SilcClientEntry sender, SilcChannelEntry channel,
-                    SilcMessageFlags flags, const unsigned char *message,
-                    SilcUInt32 message_len)
+                    SilcMessagePayload payload, SilcMessageFlags flags,
+                    const unsigned char *message, SilcUInt32 message_len)
 {
 
 }
@@ -46,8 +46,8 @@ silc_channel_message(SilcClient client, SilcClientConnection conn,
 
 static void
 silc_private_message(SilcClient client, SilcClientConnection conn,
-                    SilcClientEntry sender, SilcMessageFlags flags,
-                    const unsigned char *message,
+                    SilcClientEntry sender, SilcMessagePayload payload,
+                    SilcMessageFlags flags, const unsigned char *message,
                     SilcUInt32 message_len)
 {
 
index aff49a2362f63d4d0318b5f72026dd2917e46a58..36d7bbe43a7eaffd76fe308eb7980b50da6a9867 100644 (file)
@@ -58,7 +58,8 @@ void silc_client_send_private_message(SilcClient client,
                                       !client_entry->generated,
                                       TRUE, client_entry->send_key,
                                       client_entry->hmac_send,
-                                      client->rng);
+                                      client->rng, NULL, client->private_key,
+                                      client->sha1hash);
 
   /* If we don't have private message specific key then private messages
      are just as any normal packet thus call normal packet sending.  If
@@ -211,8 +212,8 @@ void silc_client_private_message(SilcClient client,
 
   /* Pass the private message to application */
   message = silc_message_get_data(payload, &message_len);
-  client->internal->ops->private_message(client, conn, remote_client, flags,
-                                        message, message_len);
+  client->internal->ops->private_message(client, conn, remote_client, payload,
+                                        flags, message, message_len);
 
   /* See if we are away (gone). If we are away we will reply to the
      sender with the set away message. */
@@ -382,7 +383,7 @@ bool silc_client_add_private_message_key(SilcClient client,
   /* Produce the key material as the protocol defines */
   keymat = silc_calloc(1, sizeof(*keymat));
   if (silc_ske_process_key_material_data(key, key_len, 16, 256, 16, 
-                                        client->md5hash, keymat) 
+                                        client->sha1hash, keymat) 
       != SILC_SKE_STATUS_OK)
     return FALSE;
 
index ed94414ddf2e3a23b273f6aab8ffae69e3c7ec41..3131900efdc680fb6379fb6dafc5765c79639bef 100644 (file)
@@ -625,6 +625,7 @@ SILC_CLIENT_CMD_FUNC(invite)
   SilcClientEntry client_entry = NULL;
   SilcChannelEntry channel;
   SilcBuffer buffer, clidp, chidp, args = NULL;
+  SilcPublicKey pubkey = NULL;
   char *nickname = NULL, *name;
   char *invite = NULL;
   unsigned char action[1];
@@ -687,12 +688,19 @@ SILC_CLIENT_CMD_FUNC(invite)
        goto out;
       }
     } else {
-      invite = cmd->argv[2];
-      invite++;
       if (cmd->argv[2][0] == '+')
        action[0] = 0x00;
       else
        action[0] = 0x01;
+
+      /* Check if it is public key file to be added to invite list */
+      if (!silc_pkcs_load_public_key(cmd->argv[2] + 1, &pubkey,
+                                    SILC_PKCS_FILE_PEM))
+       silc_pkcs_load_public_key(cmd->argv[2] + 1, &pubkey,
+                                 SILC_PKCS_FILE_BIN);
+      invite = cmd->argv[2];
+      if (!pubkey)
+       invite++;
     }
   }
 
@@ -701,7 +709,15 @@ SILC_CLIENT_CMD_FUNC(invite)
     silc_buffer_format(args,
                       SILC_STR_UI_SHORT(1),
                       SILC_STR_END);
-    args = silc_argument_payload_encode_one(args, invite, strlen(invite), 1);
+    if (pubkey) {
+      chidp = silc_pkcs_public_key_payload_encode(pubkey);
+      args = silc_argument_payload_encode_one(args, chidp->data,
+                                             chidp->len, 2);
+      silc_buffer_free(chidp);
+      silc_pkcs_public_key_free(pubkey);
+    } else {
+      args = silc_argument_payload_encode_one(args, invite, strlen(invite), 1);
+    }
   }
 
   /* Send the command */
@@ -1368,7 +1384,7 @@ SILC_CLIENT_CMD_FUNC(cmode)
   SilcClientCommandContext cmd = (SilcClientCommandContext)context;
   SilcClientConnection conn = cmd->conn;
   SilcChannelEntry channel;
-  SilcBuffer buffer, chidp, auth = NULL;
+  SilcBuffer buffer, chidp, auth = NULL, pk = NULL;
   unsigned char *name, *cp, modebuf[4], tmp[4], *arg = NULL;
   SilcUInt32 mode, add, type, len, arg_len = 0;
   int i;
@@ -1530,10 +1546,27 @@ SILC_CLIENT_CMD_FUNC(cmode)
       break;
     case 'f':
       if (add) {
+       SilcPublicKey pubkey = cmd->client->public_key;
+       SilcPrivateKey privkey = cmd->client->private_key;
+
        mode |= SILC_CHANNEL_MODE_FOUNDER_AUTH;
        type = 7;
-       auth = silc_auth_public_key_auth_generate(cmd->client->public_key,
-                                                 cmd->client->private_key,
+
+       if (cmd->argc >= 5) {
+         char *pass = "";
+         if (cmd->argc >= 6)
+           pass = cmd->argv[5];
+         if (!silc_load_key_pair(cmd->argv[3], cmd->argv[4], pass,
+                                 NULL, &pubkey, &privkey)) {
+           SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
+               "Could not load key pair, check your arguments");
+           COMMAND_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS);
+           goto out;
+         }
+       }
+
+       pk = silc_pkcs_public_key_payload_encode(pubkey);
+       auth = silc_auth_public_key_auth_generate(pubkey, privkey,
                                                  cmd->client->rng, 
                                                  cmd->client->sha1hash,
                                                  conn->local_id,
@@ -1558,10 +1591,12 @@ SILC_CLIENT_CMD_FUNC(cmode)
      that requires an argument. */
   if (type && arg) {
     buffer = 
-      silc_command_payload_encode_va(SILC_COMMAND_CMODE, 0, 3,
+      silc_command_payload_encode_va(SILC_COMMAND_CMODE, 0, 4,
                                     1, chidp->data, chidp->len, 
                                     2, modebuf, sizeof(modebuf),
-                                    type, arg, arg_len);
+                                    type, arg, arg_len,
+                                    8, pk ? pk->data : NULL,
+                                    pk ? pk->len : 0);
   } else {
     buffer = 
       silc_command_payload_encode_va(SILC_COMMAND_CMODE, 0, 2,
@@ -1573,8 +1608,8 @@ SILC_CLIENT_CMD_FUNC(cmode)
                          0, NULL, NULL, buffer->data, buffer->len, TRUE);
   silc_buffer_free(buffer);
   silc_buffer_free(chidp);
-  if (auth)
-    silc_buffer_free(auth);
+  silc_buffer_free(auth);
+  silc_buffer_free(pk);
 
   /* Notify application */
   COMMAND(SILC_STATUS_OK);
@@ -1683,8 +1718,23 @@ SILC_CLIENT_CMD_FUNC(cumode)
       break;
     case 'f':
       if (add) {
-       auth = silc_auth_public_key_auth_generate(cmd->client->public_key,
-                                                 cmd->client->private_key,
+       SilcPublicKey pubkey = cmd->client->public_key;
+       SilcPrivateKey privkey = cmd->client->private_key;
+
+       if (cmd->argc >= 6) {
+         char *pass = "";
+         if (cmd->argc >= 7)
+           pass = cmd->argv[6];
+         if (!silc_load_key_pair(cmd->argv[4], cmd->argv[5], pass,
+                                 NULL, &pubkey, &privkey)) {
+           SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
+               "Could not load key pair, check your arguments");
+           COMMAND_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS);
+           goto out;
+         }
+       }
+
+       auth = silc_auth_public_key_auth_generate(pubkey, privkey,
                                                  cmd->client->rng,
                                                  cmd->client->sha1hash,
                                                  conn->local_id,
@@ -2006,7 +2056,8 @@ SILC_CLIENT_CMD_FUNC(ban)
   SilcBuffer buffer, chidp, args = NULL;
   char *name, *ban = NULL;
   unsigned char action[1];
-
+  SilcPublicKey pubkey = NULL;
+  
   if (!cmd->conn) {
     SILC_NOT_CONNECTED(cmd->client, cmd->conn);
     COMMAND_ERROR(SILC_STATUS_ERR_NOT_REGISTERED);
@@ -2044,8 +2095,14 @@ SILC_CLIENT_CMD_FUNC(ban)
     else
       action[0] = 0x01;
 
+    /* Check if it is public key file to be added to invite list */
+    if (!silc_pkcs_load_public_key(cmd->argv[2] + 1, &pubkey,
+                                  SILC_PKCS_FILE_PEM))
+      silc_pkcs_load_public_key(cmd->argv[2] + 1, &pubkey,
+                               SILC_PKCS_FILE_BIN);
     ban = cmd->argv[2];
-    ban++;
+    if (!pubkey)
+      ban++;
   }
 
   if (ban) {
@@ -2053,7 +2110,15 @@ SILC_CLIENT_CMD_FUNC(ban)
     silc_buffer_format(args,
                       SILC_STR_UI_SHORT(1),
                       SILC_STR_END);
-    args = silc_argument_payload_encode_one(args, ban, strlen(ban), 1);
+    if (pubkey) {
+      chidp = silc_pkcs_public_key_payload_encode(pubkey);
+      args = silc_argument_payload_encode_one(args, chidp->data,
+                                             chidp->len, 2);
+      silc_buffer_free(chidp);
+      silc_pkcs_public_key_free(pubkey);
+    } else {
+      args = silc_argument_payload_encode_one(args, ban, strlen(ban), 1);
+    }
   }
 
   chidp = silc_id_payload_encode(channel->id, SILC_ID_CHANNEL);
@@ -2596,8 +2661,8 @@ void silc_client_commands_register(SilcClient client)
   SILC_CLIENT_CMD(join, JOIN, "JOIN", 9);
   SILC_CLIENT_CMD(motd, MOTD, "MOTD", 2);
   SILC_CLIENT_CMD(umode, UMODE, "UMODE", 2);
-  SILC_CLIENT_CMD(cmode, CMODE, "CMODE", 4);
-  SILC_CLIENT_CMD(cumode, CUMODE, "CUMODE", 5);
+  SILC_CLIENT_CMD(cmode, CMODE, "CMODE", 6);
+  SILC_CLIENT_CMD(cumode, CUMODE, "CUMODE", 9);
   SILC_CLIENT_CMD(kick, KICK, "KICK", 4);
   SILC_CLIENT_CMD(ban, BAN, "BAN", 3);
   SILC_CLIENT_CMD(detach, DETACH, "DETACH", 0);
index d615c14204e31f67138afae054961ae7c7e55b58..0ae2890bf8c233eee94188c01c2014e99e75a909 100644 (file)
@@ -1744,6 +1744,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(users)
 {
   SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
   SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
+  SilcClientCommandReplyContext r = (SilcClientCommandReplyContext)context2;
 
   SILC_LOG_DEBUG(("Start"));
 
@@ -1754,6 +1755,13 @@ SILC_CLIENT_CMD_REPLY_FUNC(users)
     goto out;
   }
 
+  if (r && !silc_command_get_status(r->payload, NULL, &cmd->error)) {
+    SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
+       "%s", silc_get_status_message(cmd->error));
+    COMMAND_REPLY_ERROR;
+    goto out;
+  }
+
   if (silc_client_command_reply_users_save(cmd, cmd->status, TRUE,
                                           silc_client_command_reply_users_cb,
                                           silc_client_command_reply_users))
@@ -1818,6 +1826,14 @@ SILC_CLIENT_CMD_REPLY_FUNC(getkey)
       goto out;
     }
 
+    /* Save fingerprint */
+    if (!client_entry->fingerprint) {
+      client_entry->fingerprint = silc_calloc(20, sizeof(unsigned char));
+      client_entry->fingerprint_len = 20;
+      silc_hash_make(cmd->client->sha1hash, tmp + 4, len - 4,
+                    client_entry->fingerprint);
+    }
+
     /* Notify application */
     COMMAND_REPLY((SILC_ARGS, id_type, client_entry, public_key));
   } else if (id_type == SILC_ID_SERVER) {
index f2bc667ccff0b7d1acf678de235fac05415489c1..d87dff84b92f2054edc34d15498df2fa459195e0 100644 (file)
@@ -538,7 +538,7 @@ typedef struct {
      (like it may tell the message is multimedia message). */
   void (*channel_message)(SilcClient client, SilcClientConnection conn, 
                          SilcClientEntry sender, SilcChannelEntry channel, 
-                         SilcMessageFlags flags,
+                         SilcMessagePayload payload, SilcMessageFlags flags,
                          const unsigned char *message,
                          SilcUInt32 message_len);
 
@@ -548,7 +548,8 @@ typedef struct {
      can be interpreted (like it may tell the message is multimedia 
      message). */
   void (*private_message)(SilcClient client, SilcClientConnection conn,
-                         SilcClientEntry sender, SilcMessageFlags flags,
+                         SilcClientEntry sender, SilcMessagePayload payload,
+                         SilcMessageFlags flags,
                          const unsigned char *message,
                          SilcUInt32 message_len);
 
@@ -1126,6 +1127,9 @@ void silc_client_close_connection(SilcClient client,
  *    keys are set then the first key (the key that was added first as
  *    private key) is used. 
  *
+ *    If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
+ *    digitally signed with the SILC key pair.
+ *
  ***/
 void silc_client_send_channel_message(SilcClient client, 
                                      SilcClientConnection conn,
@@ -1158,6 +1162,9 @@ void silc_client_send_channel_message(SilcClient client,
  *    message. The `data' is the private message. If the `force_send' is
  *    TRUE the packet is sent immediately. 
  *
+ *    If the `flags' includes SILC_MESSAGE_FLAG_SIGNED the message will be
+ *    digitally signed with the SILC key pair.
+ *
  ***/
 void silc_client_send_private_message(SilcClient client,
                                      SilcClientConnection conn,
index c58a1c9809d2c3e35dda4a7258c8adb40e1ecb53..d492ed742576b6e4442812568c86d0634581f679 100644 (file)
@@ -132,7 +132,7 @@ SilcBuffer silc_argument_payload_encode(SilcUInt32 argc,
 
   len = 0;
   for (i = 0; i < argc; i++)
-    len += 3 + argv_lens[i];
+    len += 3 + (SilcUInt16)argv_lens[i];
 
   buffer = silc_buffer_alloc_size(len);
   if (!buffer)
@@ -143,9 +143,9 @@ SilcBuffer silc_argument_payload_encode(SilcUInt32 argc,
     silc_buffer_format(buffer,
                       SILC_STR_UI_SHORT(argv_lens[i]),
                       SILC_STR_UI_CHAR(argv_types[i]),
-                      SILC_STR_UI_XNSTRING(argv[i], argv_lens[i]),
+                      SILC_STR_UI_XNSTRING(argv[i], (SilcUInt16)argv_lens[i]),
                       SILC_STR_END);
-    silc_buffer_pull(buffer, 3 + argv_lens[i]);
+    silc_buffer_pull(buffer, 3 + (SilcUInt16)argv_lens[i]);
   }
 
   silc_buffer_push(buffer, len);
@@ -161,9 +161,9 @@ SilcBuffer silc_argument_payload_encode_one(SilcBuffer args,
                                            SilcUInt32 arg_type)
 {
   SilcBuffer buffer = args;
-  int len;
+  SilcUInt32 len;
 
-  len = 3 + arg_len;
+  len = 3 + (SilcUInt16)arg_len;
   buffer = silc_buffer_realloc(buffer,
                               (buffer ? buffer->truelen + len : len));
   if (!buffer)
@@ -173,7 +173,7 @@ SilcBuffer silc_argument_payload_encode_one(SilcBuffer args,
   silc_buffer_format(buffer, 
                     SILC_STR_UI_SHORT(arg_len),
                     SILC_STR_UI_CHAR(arg_type),
-                    SILC_STR_UI_XNSTRING(arg, arg_len),
+                    SILC_STR_UI_XNSTRING(arg, (SilcUInt16)arg_len),
                     SILC_STR_END);
   silc_buffer_push(buffer, buffer->data - buffer->head);
 
index fee2c3959b0d19c82565ebdf023ba625bc485265..2ba0117b79e0573bc4568281c989bed98a07bee5 100644 (file)
@@ -46,7 +46,7 @@ silc_attribute_payload_encode_int(SilcAttribute attribute,
 {
   SilcBuffer tmpbuf = NULL;
   unsigned char tmp[4], *str = NULL, *ret;
-  int len;
+  SilcUInt32 len;
 
   /* Encode according to attribute type */
   if (flags & SILC_ATTRIBUTE_FLAG_VALID) {
@@ -70,7 +70,7 @@ silc_attribute_payload_encode_int(SilcAttribute attribute,
     case SILC_ATTRIBUTE_SERVICE:
       {
        SilcAttributeObjService *service = object;
-       int len2;
+       SilcUInt32 len2;
        if (object_size != sizeof(*service))
          return NULL;
        len = strlen(service->address);
@@ -131,7 +131,7 @@ silc_attribute_payload_encode_int(SilcAttribute attribute,
     case SILC_ATTRIBUTE_GEOLOCATION:
       {
        SilcAttributeObjGeo *geo = object;
-       int len1, len2, len3, len4;
+       SilcUInt32 len1, len2, len3, len4;
        if (object_size != sizeof(*geo))
          return NULL;
        len1 = (geo->longitude ? strlen(geo->longitude) : 0);
@@ -162,7 +162,7 @@ silc_attribute_payload_encode_int(SilcAttribute attribute,
     case SILC_ATTRIBUTE_DEVICE_INFO:
       {
        SilcAttributeObjDevice *dev = object;
-       int len1, len2, len3, len4;
+       SilcUInt32 len1, len2, len3, len4;
        if (object_size != sizeof(*dev))
          return NULL;
        len1 = (dev->manufacturer ? strlen(dev->manufacturer) : 0);
@@ -278,7 +278,8 @@ SilcDList silc_attribute_payload_parse(const unsigned char *payload,
   SilcBufferStruct buffer;
   SilcDList list;
   SilcAttributePayload newp;
-  int len, ret;
+  SilcUInt32 len;
+  int ret;
 
   SILC_LOG_DEBUG(("Parsing Attribute Payload list"));
 
@@ -344,9 +345,9 @@ SilcBuffer silc_attribute_payload_encode_data(SilcBuffer attrs,
                                              SilcUInt32 data_len)
 {
   SilcBuffer buffer = attrs;
-  int len;
+  SilcUInt32 len;
 
-  len = 4 + data_len;
+  len = 4 + (SilcUInt16)data_len;
   buffer = silc_buffer_realloc(buffer,
                               (buffer ? buffer->truelen + len : len));
   if (!buffer)
@@ -357,7 +358,7 @@ SilcBuffer silc_attribute_payload_encode_data(SilcBuffer attrs,
                     SILC_STR_UI_CHAR(attribute),
                     SILC_STR_UI_CHAR(flags),
                     SILC_STR_UI_SHORT((SilcUInt16)data_len),
-                    SILC_STR_UI_XNSTRING(data, data_len),
+                    SILC_STR_UI_XNSTRING(data, (SilcUInt16)data_len),
                     SILC_STR_END);
   silc_buffer_push(buffer, buffer->data - buffer->head);
 
index 7b7128ce574516fe5e87b0e4ac512f02b9582e9f..38a1a961392e87fe668cd7110f48dc0418990780 100644 (file)
@@ -241,7 +241,7 @@ SilcBuffer silc_auth_public_key_auth_generate(SilcPublicKey public_key,
                                              const void *id, SilcIdType type)
 {
   unsigned char *randomdata;
-  unsigned char auth_data[2048];
+  unsigned char auth_data[2048 + 1];
   SilcUInt32 auth_len;
   unsigned char *tmp;
   SilcUInt32 tmp_len;
index f9e6ff85d4d061dacf707b017a6593613629f86b..5c83bbb422801ac4b472c19a18409a4ac8bde860 100644 (file)
@@ -1,29 +1,42 @@
 /*
 
-  silcchannel.c
+  silcchannel.c 
 
-  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+  Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2001 Pekka Riikonen
+  Copyright (C) 1997 - 2002 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
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-  
+  the Free Software Foundation; version 2 of the License.
+
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
 
 */
-/* Channel Payload, Channel Message Payload and Channel Key Payload 
-   implementations. */
+/* Channel Payload and Channel Key Payload implementations. */
 /* $Id$ */
 
 #include "silcincludes.h"
 #include "silcchannel.h"
-#include "silcchannel_i.h"
+
+/******************************************************************************
+
+                              Channel Payload
+
+******************************************************************************/
+
+/* Channel Message Payload structure. Contents of this structure is parsed
+   from SILC packets. */
+struct SilcChannelPayloadStruct {
+  unsigned char *channel_name;
+  unsigned char *channel_id;
+  SilcUInt32 mode;
+  SilcUInt16 name_len;
+  SilcUInt16 id_len;
+};
 
 /* Parses channel payload returning new channel payload structure. */
 
@@ -74,7 +87,8 @@ SilcDList silc_channel_payload_parse_list(const unsigned char *payload,
   SilcBufferStruct buffer;
   SilcDList list;
   SilcChannelPayload newp;
-  int len, ret;
+  SilcUInt32 len;
+  int ret;
 
   SILC_LOG_DEBUG(("Parsing channel payload list"));
 
@@ -217,6 +231,17 @@ SilcUInt32 silc_channel_get_mode(SilcChannelPayload payload)
 
 ******************************************************************************/
 
+/* Channel Key Payload structrue. Channel keys are parsed from SILC
+   packets into this structure. */
+struct SilcChannelKeyPayloadStruct {
+  unsigned char *id;
+  unsigned char *cipher;
+  unsigned char *key;
+  SilcUInt16 id_len;
+  SilcUInt16 cipher_len;
+  SilcUInt16 key_len;
+};
+
 /* Parses channel key payload returning new channel key payload structure */
 
 SilcChannelKeyPayload 
diff --git a/lib/silccore/silcchannel_i.h b/lib/silccore/silcchannel_i.h
deleted file mode 100644 (file)
index 34dc5bb..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
-
-  silcchannel_i.h 
-
-  Author: Pekka Riikonen <priikone@silcnet.org>
-
-  Copyright (C) 1997 - 2002 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
-  the Free Software Foundation; version 2 of the License.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-*/
-
-#ifndef SILCCHANNEL_I_H
-#define SILCCHANNEL_I_H
-
-#ifndef SILCCHANNEL_H
-#error "Do not include internal header file directly"
-#endif
-
-/******************************************************************************
-
-                              Channel Payload
-
-******************************************************************************/
-
-/* Channel Message Payload structure. Contents of this structure is parsed
-   from SILC packets. */
-struct SilcChannelPayloadStruct {
-  unsigned char *channel_name;
-  unsigned char *channel_id;
-  SilcUInt32 mode;
-  SilcUInt16 name_len;
-  SilcUInt16 id_len;
-};
-
-
-/******************************************************************************
-
-                             Channel Key Payload
-
-******************************************************************************/
-
-/* Channel Key Payload structrue. Channel keys are parsed from SILC
-   packets into this structure. */
-struct SilcChannelKeyPayloadStruct {
-  unsigned char *id;
-  unsigned char *cipher;
-  unsigned char *key;
-  SilcUInt16 id_len;
-  SilcUInt16 cipher_len;
-  SilcUInt16 key_len;
-};
-
-#endif /* SILCCHANNEL_I_H */
index d8470570c205f7cb363b0d0b7d093db4138bf295..a16dfc6fce792b6e0c8edfe1ac0d17265120b219 100644 (file)
@@ -1,16 +1,15 @@
 /*
 
-  silccommand.c
+  silccommand.c 
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2001 Pekka Riikonen
+  Copyright (C) 1997 - 2002 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
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-  
+  the Free Software Foundation; version 2 of the License.
+
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@@ -76,6 +75,7 @@ SilcCommandPayload silc_command_payload_parse(const unsigned char *payload,
   }
 
   if (newp->cmd == 0) {
+    SILC_LOG_ERROR(("Incorrect command type in command payload"));
     silc_free(newp);
     return NULL;
   }
@@ -111,6 +111,8 @@ SilcBuffer silc_command_payload_encode(SilcCommand cmd,
 
   if (argc) {
     args = silc_argument_payload_encode(argc, argv, argv_lens, argv_types);
+    if (!args)
+      return NULL;
     len = args->len;
   }
 
@@ -154,7 +156,8 @@ SilcBuffer silc_command_payload_encode_payload(SilcCommandPayload payload)
 
   if (payload->args) {
     args = silc_argument_payload_encode_payload(payload->args);
-    len = args->len;
+    if (args)
+      len = args->len;
     argc = silc_argument_get_arg_num(payload->args);
   }
 
index 19adb9ff83989a48b07d52f2410542198d708b0f..3d6904e74421b00d962d69e55466f92c9240fa0a 100644 (file)
@@ -189,7 +189,11 @@ bool silc_idcache_add(SilcIDCache cache, char *name, void *id,
 static void silc_idcache_destructor(void *key, void *context,
                                    void *user_context)
 {
-  silc_free(context);
+  SilcIDCacheEntry c = context;
+  if (c) {
+    memset(c, 'F', sizeof(*c));
+    silc_free(c);
+  }
 }
 
 /* Delete cache entry from cache. */
@@ -207,7 +211,7 @@ bool silc_idcache_del(SilcIDCache cache, SilcIDCacheEntry old)
   if (old->id)
     ret = silc_hash_table_del(cache->id_table, old->id);
   else
-    silc_free(old);
+    silc_idcache_destructor(NULL, old, NULL);
 
   return ret;
 }
@@ -274,7 +278,7 @@ bool silc_idcache_del_by_context(SilcIDCache cache, void *context)
   if (c->id)
     ret = silc_hash_table_del_by_context(cache->id_table, c->id, c);
   else
-    silc_free(c);
+    silc_idcache_destructor(NULL, c, NULL);
 
   return ret;
 }
@@ -304,6 +308,7 @@ static void silc_idcache_purge_foreach(void *key, void *context,
   SilcIDCache cache = (SilcIDCache)user_context;
   SilcUInt32 curtime = time(NULL);
   SilcIDCacheEntry c = (SilcIDCacheEntry)context;
+  bool ret = FALSE;
 
   if (!context)
     return;
@@ -311,20 +316,23 @@ static void silc_idcache_purge_foreach(void *key, void *context,
   if (c->expire && c->expire < curtime) {
     /* Remove the entry from the hash tables */
     if (c->name)
-      silc_hash_table_del_by_context(cache->name_table, c->name, c);
+      ret = silc_hash_table_del_by_context(cache->name_table, c->name, c);
     if (c->context)
-      silc_hash_table_del(cache->context_table, c->context);
+      ret = silc_hash_table_del(cache->context_table, c->context);
     if (c->id)
-      silc_hash_table_del_by_context_ext(cache->id_table, c->id, c,
-                                        NULL, NULL, NULL, NULL, 
-                                        silc_idcache_destructor_dummy, NULL);
-
-    /* Call the destructor */
-    if (cache->destructor)
-      cache->destructor(cache, c);
-
-    /* Free the entry, it has been deleted from the hash tables */
-    silc_free(c);
+      ret =
+       silc_hash_table_del_by_context_ext(cache->id_table, c->id, c,
+                                          NULL, NULL, NULL, NULL, 
+                                          silc_idcache_destructor_dummy,
+                                          NULL);
+    if (ret == TRUE) {
+      /* Call the destructor */
+      if (cache->destructor)
+       cache->destructor(cache, c);
+
+      /* Free the entry, it has been deleted from the hash tables */
+      silc_idcache_destructor(NULL, c, NULL);
+    }
   }
 }
 
@@ -358,13 +366,14 @@ bool silc_idcache_purge_by_context(SilcIDCache cache, void *context)
       silc_hash_table_del_by_context_ext(cache->id_table, c->id, c,
                                         NULL, NULL, NULL, NULL, 
                                         silc_idcache_destructor_dummy, NULL);
-  
-  /* Call the destructor */
-  if (cache->destructor)
-    cache->destructor(cache, c);
+  if (ret == TRUE) {
+    /* Call the destructor */
+    if (cache->destructor)
+      cache->destructor(cache, c);
 
-  /* Free the entry, it has been deleted from the hash tables */
-  silc_free(c);
+    /* Free the entry, it has been deleted from the hash tables */
+    silc_idcache_destructor(NULL, c, NULL);
+  }
 
   return ret;
 }
index e3fd64f970cb17556abd27cb35a6eec618429aa1..08ec1feff16ff05c58a09a35a88bfcf2209bae3a 100644 (file)
@@ -54,7 +54,7 @@ struct SilcMessagePayloadStruct {
   unsigned char *pad;
   unsigned char *iv;
   unsigned char *mac;
-  /*SilcMessageSignedPayload sig;*/
+  SilcMessageSignedPayload sig;
 };
 
 /* Decrypts the Message Payload. The `data' is the actual Message Payload */
@@ -67,13 +67,14 @@ bool silc_message_payload_decrypt(unsigned char *data,
                                  SilcHmac hmac,
                                  bool check_mac)
 {
-  SilcUInt32 mac_len = 0, iv_len = 0;
-  unsigned char *mac, mac2[32];
-
+  SilcUInt32 mac_len, iv_len = 0, block_len;
+  SilcUInt16 len, totlen, dlen;
+  unsigned char mac[32], *ivp, *dec;
+  
   mac_len = silc_hmac_len(hmac);
 
-  /* IV is present for channel messages and private messages when static
-     key (pre-shared key) is used. */
+  /* IV is present for all channel messages, and private messages when 
+     static key (pre-shared key) is used. */
   if (!private_message || (private_message && static_key))
     iv_len = silc_cipher_get_block_len(cipher);
 
@@ -81,24 +82,63 @@ bool silc_message_payload_decrypt(unsigned char *data,
     return FALSE;
 
   if (check_mac) {
-    /* Take the MAC */
-    mac = data + (data_len - mac_len);
-
     /* Check the MAC of the message */
     SILC_LOG_DEBUG(("Checking message MAC"));
     silc_hmac_init(hmac);
     silc_hmac_update(hmac, data, data_len - mac_len);
-    silc_hmac_final(hmac, mac2, &mac_len);
-    if (memcmp(mac, mac2, mac_len)) {
+    silc_hmac_final(hmac, mac, &mac_len);
+    if (memcmp(data + (data_len - mac_len), mac, mac_len)) {
       SILC_LOG_DEBUG(("Message MAC does not match"));
       return FALSE;
     }
     SILC_LOG_DEBUG(("MAC is Ok"));
   }
 
-  /* Decrypt the message */
-  silc_cipher_decrypt(cipher, data, data, data_len - iv_len - mac_len,
-                     (iv_len ? data + (data_len - iv_len - mac_len) : NULL));
+  /* Decrypt the entire buffer into allocated decryption buffer, since we
+     do not reliably know its encrypted length (it may include unencrypted
+     data at the end). */
+
+  /* Get pointer to the IV */
+  ivp = (iv_len ? data + (data_len - iv_len - mac_len) :
+        silc_cipher_get_iv(cipher));
+
+  /* Allocate buffer for decryption.  Since there might be unencrypted
+     data at the end, it might not be multiple by block size, make it so. */
+  block_len = silc_cipher_get_block_len(cipher);
+  dlen = data_len - iv_len - mac_len;
+  if (dlen & (block_len - 1))
+    dlen += SILC_MESSAGE_PAD(dlen);
+  if (dlen > data_len - iv_len - mac_len)
+    dlen -= block_len;
+  dec = silc_malloc(dlen);
+
+  /* Decrypt */
+  silc_cipher_decrypt(cipher, data, dec, dlen, ivp);
+
+  /* Now verify the true length of the payload and copy the decrypted
+     part over the original data.  First get data length, and then padding
+     length from the decrypted data.  Then, copy over the original data. */
+
+  totlen = 2;
+  SILC_GET16_MSB(len, dec + totlen);
+  totlen += 2 + len;
+  if (totlen + iv_len + mac_len + 2 > data_len) {
+    memset(dec, 0, dlen);
+    silc_free(dec);
+    return FALSE;
+  }
+  SILC_GET16_MSB(len, dec + totlen);
+  totlen += 2 + len;
+  if (totlen + iv_len + mac_len > data_len) {
+    memset(dec, 0, dlen);
+    silc_free(dec);
+    return FALSE;
+  }
+
+  memcpy(data, dec, totlen);
+  memset(dec, 0, dlen);
+  silc_free(dec);
+
   return TRUE;
 }
 
@@ -134,8 +174,8 @@ silc_message_payload_parse(unsigned char *payload,
   if (hmac)
     mac_len = silc_hmac_len(hmac);
 
-  /* IV is present for channel messages and private messages when static
-     key (pre-shared key) is used. */
+  /* IV is present for all channel messages, and private messages when 
+     static key (pre-shared key) is used. */
   if (cipher && (!private_message || (private_message && static_key)))
     iv_len = silc_cipher_get_block_len(cipher);
 
@@ -150,8 +190,6 @@ silc_message_payload_parse(unsigned char *payload,
                                                         &newp->data_len),
                             SILC_STR_UI16_NSTRING_ALLOC(&newp->pad, 
                                                         &newp->pad_len),
-                            SILC_STR_UI_XNSTRING(&newp->iv, iv_len),
-                            SILC_STR_UI_XNSTRING(&newp->mac, mac_len),
                             SILC_STR_END);
   if (ret == -1)
     goto err;
@@ -162,7 +200,22 @@ silc_message_payload_parse(unsigned char *payload,
     goto err;
   }
 
-  newp->iv_len = iv_len;
+  /* Parse Signed Message Payload if provided */
+  if (newp->flags & SILC_MESSAGE_FLAG_SIGNED &&
+      newp->data_len + newp->pad_len + 6 + mac_len + iv_len < buffer.len) {
+    newp->sig =
+      silc_message_signed_payload_parse(buffer.data + 6 + newp->data_len +
+                                       newp->pad_len,
+                                       buffer.len - iv_len - mac_len);
+  }
+
+  /* Parse IV and MAC from the payload */
+  if (iv_len) {
+    newp->iv = buffer.data + (buffer.len - iv_len - mac_len);
+    newp->iv_len = iv_len;
+  }
+  if (mac_len)
+    newp->mac = buffer.data + (buffer.len - mac_len);
 
   return newp;
 
@@ -174,10 +227,11 @@ silc_message_payload_parse(unsigned char *payload,
 /* This function is used to encrypt the Messsage Payload which is
    the `data' and `data_len'.  This is used internally by the Message
    Payload encoding routines but application may call this too if needed. 
-   The `data_len' is the data lenght which is used to create MAC out of. */
+   The `true_len' is the data length which is used to create MAC out of. */
 
 bool silc_message_payload_encrypt(unsigned char *data,
                                  SilcUInt32 data_len,
+                                 SilcUInt32 true_len,
                                  unsigned char *iv,
                                  SilcUInt32 iv_len,
                                  SilcCipher cipher,
@@ -189,17 +243,16 @@ bool silc_message_payload_encrypt(unsigned char *data,
 
   /* Encrypt payload of the packet. If the IV is added to packet do
      not encrypt that. */
-  silc_cipher_encrypt(cipher, data, data, data_len - iv_len,
-                     iv_len ? iv : NULL);
+  silc_cipher_encrypt(cipher, data, data, data_len, iv_len ? iv : NULL);
 
   /* Compute the MAC of the encrypted message data */
   silc_hmac_init(hmac);
-  silc_hmac_update(hmac, data, data_len);
+  silc_hmac_update(hmac, data, true_len);
   silc_hmac_final(hmac, mac, &mac_len);
 
   /* Put rest of the data to the payload */
-  silc_buffer_set(&buf, data, data_len + mac_len);
-  silc_buffer_pull(&buf, data_len);
+  silc_buffer_set(&buf, data, true_len + mac_len);
+  silc_buffer_pull(&buf, true_len);
   silc_buffer_put(&buf, mac, mac_len);
 
   return TRUE;
@@ -214,12 +267,16 @@ SilcBuffer silc_message_payload_encode(SilcMessageFlags flags,
                                       bool private_message,
                                       SilcCipher cipher,
                                       SilcHmac hmac,
-                                      SilcRng rng)
+                                      SilcRng rng,
+                                      SilcPublicKey public_key,
+                                      SilcPrivateKey private_key,
+                                      SilcHash hash)
 {
   int i;
   SilcBuffer buffer;
   SilcUInt32 len, pad_len = 0, mac_len = 0, iv_len = 0;
   unsigned char pad[16], iv[SILC_CIPHER_MAX_IV_SIZE];
+  SilcBuffer sig = NULL;
 
   SILC_LOG_DEBUG(("Encoding Message Payload"));
 
@@ -265,28 +322,57 @@ SilcBuffer silc_message_payload_encode(SilcMessageFlags flags,
   }
 
   /* Encode the Message Payload */
-  silc_buffer_pull_tail(buffer, 6 + data_len + pad_len + iv_len);
+  silc_buffer_pull_tail(buffer, 6 + data_len + pad_len);
   silc_buffer_format(buffer, 
                     SILC_STR_UI_SHORT(flags),
                     SILC_STR_UI_SHORT(data_len),
                     SILC_STR_UI_XNSTRING(data, data_len),
                     SILC_STR_UI_SHORT(pad_len),
                     SILC_STR_UI_XNSTRING(pad, pad_len),
-                    SILC_STR_UI_XNSTRING(iv, iv_len),
                     SILC_STR_END);
 
   memset(pad, 0, sizeof(pad));
 
-  /* Now encrypt the Message Payload */
+  /* Sign the message if wanted */
+  if (flags & SILC_MESSAGE_FLAG_SIGNED && private_key && hash) {
+    sig = silc_message_signed_payload_encode(buffer->data, buffer->len,
+                                            public_key, private_key, hash);
+    if (sig) {
+      buffer = silc_buffer_realloc(buffer, buffer->truelen + sig->len);
+      if (buffer) {
+       silc_buffer_pull(buffer, 6 + data_len + pad_len);
+       silc_buffer_pull_tail(buffer, sig->len);
+       silc_buffer_put(buffer, sig->data, sig->len);
+       silc_buffer_push(buffer, 6 + data_len + pad_len);
+      }
+    }
+  }
+
+  /* Put IV */
+  silc_buffer_pull(buffer, 6 + data_len + pad_len + (sig ? sig->len : 0));
+  silc_buffer_pull_tail(buffer, iv_len);
+  silc_buffer_format(buffer, 
+                    SILC_STR_UI_XNSTRING(iv, iv_len),
+                    SILC_STR_END);
+  silc_buffer_push(buffer, 6 + data_len + pad_len + (sig ? sig->len : 0));
+  
+  SILC_LOG_HEXDUMP(("foo"), buffer->data, buffer->len);
+  
+  /* Now encrypt the Message Payload and compute MAC */
   if (cipher) {
-    if (!silc_message_payload_encrypt(buffer->data, buffer->len,
-                                     iv, iv_len, cipher, hmac)) {
+    if (!silc_message_payload_encrypt(buffer->data,
+                                     buffer->len - iv_len -
+                                     (sig ? sig->len : 0),
+                                     buffer->len, iv, iv_len,
+                                     cipher, hmac)) {
       silc_buffer_free(buffer);
+      silc_buffer_free(sig);
       return NULL;
     }
   }
   silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer) - buffer->len);
 
+  silc_buffer_free(sig);
   return buffer;
 }
 
@@ -298,6 +384,8 @@ void silc_message_payload_free(SilcMessagePayload payload)
     memset(payload->data, 0, payload->data_len);
     silc_free(payload->data);
   }
+  if (payload->sig)
+    silc_message_signed_payload_free(payload->sig);
   silc_free(payload->pad);
   silc_free(payload);
 }
@@ -333,6 +421,14 @@ unsigned char *silc_message_get_iv(SilcMessagePayload payload)
   return payload->iv;
 }
 
+/* Return signature of the message */
+
+const SilcMessageSignedPayload
+silc_message_get_signature(SilcMessagePayload payload)
+{
+  return (const SilcMessageSignedPayload)payload->sig;
+}
+
 /******************************************************************************
 
                      SILC_MESSAGE_FLAG_SIGNED Payload
@@ -392,6 +488,8 @@ silc_message_signed_payload_parse(const unsigned char *data,
 
   SILC_LOG_DEBUG(("Parsing SILC_MESSAGE_FLAG_SIGNED Payload"));
 
+  SILC_LOG_HEXDUMP(("sig payload"), (unsigned char *)data, data_len);
+
   silc_buffer_set(&buffer, (unsigned char *)data, data_len);
   sig = silc_calloc(1, sizeof(*sig));
   if (!sig)
@@ -404,6 +502,8 @@ silc_message_signed_payload_parse(const unsigned char *data,
                             SILC_STR_END);
   if (ret == -1 || sig->pk_len > data_len - 4) {
     silc_message_signed_payload_free(sig);
+    SILC_LOG_DEBUG(("Malformed public key in SILC_MESSAGE_FLAG_SIGNED "
+                   "Payload"));
     return NULL;
   }
 
@@ -416,12 +516,15 @@ silc_message_signed_payload_parse(const unsigned char *data,
                             SILC_STR_END);
   if (ret == -1) {
     silc_message_signed_payload_free(sig);
+    SILC_LOG_DEBUG(("Malformed SILC_MESSAGE_FLAG_SIGNED Payload"));
     return NULL;
   }
   silc_buffer_push(&buffer, 4);
 
   /* Signature must be provided */
   if (sig->sign_len < 1)  {
+    SILC_LOG_DEBUG(("Malformed signature in SILC_MESSAGE_SIGNED_PAYLOAD "
+                   "Payload"));
     silc_message_signed_payload_free(sig);
     return NULL;
   }
@@ -437,12 +540,11 @@ silc_message_signed_payload_encode(const unsigned char *message_payload,
                                   SilcUInt32 message_payload_len,
                                   SilcPublicKey public_key,
                                   SilcPrivateKey private_key,
-                                  SilcHash hash,
-                                  bool include_public_key)
+                                  SilcHash hash)
 {
   SilcBuffer buffer, sign;
   SilcPKCS pkcs;
-  unsigned char auth_data[2048];
+  unsigned char auth_data[2048 + 1];
   SilcUInt32 auth_len;
   unsigned char *pk = NULL;
   SilcUInt32 pk_len = 0;
@@ -450,10 +552,8 @@ silc_message_signed_payload_encode(const unsigned char *message_payload,
 
   if (!message_payload || !message_payload_len || !private_key || !hash)
     return NULL;
-  if (include_public_key && !public_key)
-    return NULL;
-
-  if (include_public_key)
+  
+  if (public_key)
     pk = silc_pkcs_public_key_encode(public_key, &pk_len);
 
   /* Now we support only SILC style public key */
@@ -472,6 +572,7 @@ silc_message_signed_payload_encode(const unsigned char *message_payload,
 
   /* Allocate PKCS object */
   if (!silc_pkcs_alloc(private_key->name, &pkcs)) {
+    SILC_LOG_ERROR(("Could not allocated PKCS"));
     silc_buffer_clear(sign);
     silc_buffer_free(sign);
     silc_free(pk);
@@ -483,6 +584,7 @@ silc_message_signed_payload_encode(const unsigned char *message_payload,
   if (silc_pkcs_get_key_len(pkcs) / 8 > sizeof(auth_data) - 1 ||
       !silc_pkcs_sign_with_hash(pkcs, hash, sign->data, sign->len, auth_data,
                                &auth_len)) {
+    SILC_LOG_ERROR(("Could not compute signature"));
     silc_buffer_clear(sign);
     silc_buffer_free(sign);
     silc_pkcs_free(pkcs);
@@ -502,25 +604,27 @@ silc_message_signed_payload_encode(const unsigned char *message_payload,
     return NULL;
   }
 
-  silc_buffer_format(sign,
+  silc_buffer_format(buffer,
                     SILC_STR_UI_SHORT(pk_len),
                     SILC_STR_UI_SHORT(pk_type),
                     SILC_STR_END);
 
   if (pk_len && pk) {
-    silc_buffer_pull(sign, 4);
-    silc_buffer_format(sign,
+    silc_buffer_pull(buffer, 4);
+    silc_buffer_format(buffer,
                       SILC_STR_UI_XNSTRING(pk, pk_len),
                       SILC_STR_END);
-    silc_buffer_push(sign, 4);
+    silc_buffer_push(buffer, 4);
   }
 
-  silc_buffer_pull(sign, 4 + pk_len);
-  silc_buffer_format(sign,
+  silc_buffer_pull(buffer, 4 + pk_len);
+  silc_buffer_format(buffer,
                     SILC_STR_UI_SHORT(auth_len),
                     SILC_STR_UI_XNSTRING(auth_data, auth_len),
                     SILC_STR_END);
-  silc_buffer_push(sign, 4 + pk_len);
+  silc_buffer_push(buffer, 4 + pk_len);
+
+  SILC_LOG_HEXDUMP(("sig payload"), buffer->data, buffer->len);
 
   memset(auth_data, 0, sizeof(auth_data));
   silc_pkcs_free(pkcs);
@@ -535,12 +639,10 @@ silc_message_signed_payload_encode(const unsigned char *message_payload,
 
 void silc_message_signed_payload_free(SilcMessageSignedPayload sig)
 {
-  if (sig) {
-    memset(sig->sign_data, 0, sig->sign_len);
-    silc_free(sig->sign_data);
-    silc_free(sig->pk_data);
-    silc_free(sig);
-  }
+  memset(sig->sign_data, 0, sig->sign_len);
+  silc_free(sig->sign_data);
+  silc_free(sig->pk_data);
+  silc_free(sig);
 }
 
 /* Verify the signature in SILC_MESSAGE_FLAG_SIGNED Payload */
@@ -559,15 +661,13 @@ int silc_message_signed_verify(SilcMessageSignedPayload sig,
     return ret;
 
   /* Generate the signature verification data, the Message Payload */
-  tmp = silc_buffer_alloc_size(6 + message->data_len + message->pad_len +
-                              message->iv_len);
+  tmp = silc_buffer_alloc_size(6 + message->data_len + message->pad_len);
   silc_buffer_format(tmp,
                     SILC_STR_UI_SHORT(message->flags),
                     SILC_STR_UI_SHORT(message->data_len),
                     SILC_STR_UI_XNSTRING(message->data, message->data_len),
                     SILC_STR_UI_SHORT(message->pad_len),
                     SILC_STR_UI_XNSTRING(message->pad, message->pad_len),
-                    SILC_STR_UI_XNSTRING(message->iv, message->iv_len),
                     SILC_STR_END);
   sign = silc_message_signed_encode_data(tmp->data, tmp->len,
                                         sig->pk_data, sig->pk_len,
@@ -612,7 +712,9 @@ int silc_message_signed_verify(SilcMessageSignedPayload sig,
 /* Return the public key from the payload */
 
 SilcPublicKey
-silc_message_signed_get_public_key(SilcMessageSignedPayload sig)
+silc_message_signed_get_public_key(SilcMessageSignedPayload sig,
+                                  unsigned char **pk_data,
+                                  SilcUInt32 *pk_data_len)
 {
   SilcPublicKey pk;
 
@@ -620,5 +722,10 @@ silc_message_signed_get_public_key(SilcMessageSignedPayload sig)
                                                    sig->pk_len, &pk))
     return NULL;
 
+  if (pk_data)
+    *pk_data = sig->pk_data;
+  if (pk_data_len)
+    *pk_data_len = sig->pk_len;
+
   return pk;
 }
index e003e029ee1a52623182896bca5ebea7c9febbc9..8e1a9f81ec52dbc08e4ab6b86fdf6cfe8d0a11c8 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 -2002 Pekka Riikonen
+  Copyright (C) 1997 - 2002 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
  ***/
 typedef struct SilcMessagePayloadStruct *SilcMessagePayload;
 
+/****s* silccore/SilcMessageAPI/SilcMessageSignedPayload
+ *
+ * NAME
+ * 
+ *    typedef struct SilcMessageSignedPayloadStruct *SilcMessageSignedPayload;
+ *
+ *
+ * DESCRIPTION
+ *
+ *    This context represents the SILC_MESSAGE_FLAG_SIGNED Payload which
+ *    is used with channel messages and private messages to indicate that
+ *    the message is digitally signed.  This payload may include the
+ *    message sender's public key and it includes the digital signature.
+ *    This payload MUST NOT be used in any other context except with
+ *    channel and private message sending and reception.
+ *
+ ***/
+typedef struct SilcMessageSignedPayloadStruct *SilcMessageSignedPayload;
+
 /****d* silccore/SilcMessageAPI/SilcMessageFlags
  *
  * NAME
@@ -161,6 +180,7 @@ silc_message_payload_parse(unsigned char *payload,
  *
  *    bool silc_message_payload_encrypt(unsigned char *data,
  *                                      SilcUInt32 data_len,
+ *                                      SilcUInt32 true_len,
  *                                      unsigned char *iv,
  *                                      SilcUInt32 iv_len,
  *                                      SilcCipher cipher,
@@ -171,7 +191,7 @@ silc_message_payload_parse(unsigned char *payload,
  *    This function is used to encrypt the Messsage Payload which is
  *    the `data' and `data_len'.  The `data_len' is the data length which
  *    is used to create MAC out of.  The `data' MUST have additional space
- *    after `data_len' bytes for the MAC which is appended to the data.
+ *    after `true_len' bytes for the MAC which is appended to the data.
  *
  *    This is usually used by the Message Payload interface itself but can
  *    be called by the appliation if separate encryption process is required.
@@ -182,6 +202,7 @@ silc_message_payload_parse(unsigned char *payload,
  ***/
 bool silc_message_payload_encrypt(unsigned char *data,
                                  SilcUInt32 data_len,
+                                 SilcUInt32 true_len,
                                  unsigned char *iv,
                                  SilcUInt32 iv_len,
                                  SilcCipher cipher,
@@ -198,7 +219,10 @@ bool silc_message_payload_encrypt(unsigned char *data,
  *                                           bool private_message,
  *                                           SilcCipher cipher,
  *                                           SilcHmac hmac,
- *                                           SilcRng rng);
+ *                                           SilcRng rng,
+ *                                           SilcPublicKey public_key,
+ *                                           SilcPrivateKey private_key,
+ *                                           SilcHash hash);
  *
  * DESCRIPTION
  *
@@ -219,10 +243,15 @@ bool silc_message_payload_encrypt(unsigned char *data,
  *    message that will be encrypted with session keys (no private message
  *    key) then `cipher' and `hmac' is NULL and this merely encodes the
  *    payload buffer, and the caller must encrypt the packet later.
- *
  *    If `rng' is NULL then global RNG is used, if non-NULL then the
  *    `rng' is used (for IV and padding generation).
  *
+ *    The `public_key', `private_key' and `hash' are provided only if the
+ *    flags includes SILC_MESSAGE_FLAG_SIGNED, in which case the message
+ *    will be digitally signed.  If `public_key' is non-NULL then it will
+ *    be included in the message.  The `private_message' and `hash' MUST
+ *    be provided.  The `hash' SHOULD be SHA1.
+ *
  ***/
 SilcBuffer silc_message_payload_encode(SilcMessageFlags flags,
                                       const unsigned char *data,
@@ -231,7 +260,10 @@ SilcBuffer silc_message_payload_encode(SilcMessageFlags flags,
                                       bool private_message,
                                       SilcCipher cipher,
                                       SilcHmac hmac,
-                                      SilcRng rng);
+                                      SilcRng rng,
+                                      SilcPublicKey public_key,
+                                      SilcPrivateKey private_key,
+                                      SilcHash hash);
 
 /****f* silccore/SilcMessageAPI/silc_message_payload_free
  *
@@ -306,24 +338,26 @@ unsigned char *silc_message_get_mac(SilcMessagePayload payload);
  ***/
 unsigned char *silc_message_get_iv(SilcMessagePayload payload);
 
-/****s* silccore/SilcMessageAPI/SilcMessageSignedPayload
+/****f* silccore/SilcMessageAPI/silc_message_get_signature
  *
- * NAME
- * 
- *    typedef struct SilcMessageSignedPayloadStruct *SilcMessageSignedPayload;
+ * SYNOPSIS
  *
+ *    const SilcMessageSignedPayload
+ *    silc_message_get_signature(SilcMessagePayload payload);
  *
  * DESCRIPTION
  *
- *    This context represents the SILC_MESSAGE_FLAG_SIGNED Payload which
- *    is used with channel messages and private messages to indicate that
- *    the message is digitally signed.  This payload may include the
- *    message sender's public key and it includes the digital signature.
- *    This payload MUST NOT be used in any other context except with
- *    channel and private message sending and reception.
+ *    Returns the pointer to the signature of the message if the
+ *    SILC_MESSAGE_FLAG_SIGNED was set.  If the flag is set and this
+ *    function returns NULL then error had occurred and the signature
+ *    could not be retrieved from the message.
+ *
+ *    The caller SHOULD verify the signature by calling the
+ *    silc_message_signed_verify function.
  *
  ***/
-typedef struct SilcMessageSignedPayloadStruct *SilcMessageSignedPayload;
+const SilcMessageSignedPayload
+silc_message_get_signature(SilcMessagePayload payload);
 
 /****f* silccore/SilcMessageAPI/silc_message_signed_payload_parse
  *
@@ -335,10 +369,13 @@ typedef struct SilcMessageSignedPayloadStruct *SilcMessageSignedPayload;
  *
  * DESCRIPTION
  *
- *    Parses the SILC_MESSAGE_FLAG_SIGNED Payload from the `data' of
+ *    Parses the SilcMessageSignedPayload Payload from the `data' of
  *    length of `data_len' bytes.  The `data' must be payload without
  *    the actual message payload.  Returns the parsed payload or NULL
- *    on error.  Caller must free the returned payload.
+ *    on error.  Caller must free the returned payload.  Application
+ *    usually does not need to call this since the function
+ *    silc_message_payload_parse calls this automatically for signed
+ *    messages.
  *
  ***/
 SilcMessageSignedPayload
@@ -354,18 +391,22 @@ silc_message_signed_payload_parse(const unsigned char *data,
  *                                       SilcUInt32 message_payload_len,
  *                                       SilcPublicKey public_key,
  *                                       SilcPrivateKey private_key,
- *                                       bool include_public_key);
+ *                                       SilcHash hash);
  *
  * DESCRIPTION
  *
- *    Encodes the SILC_MESSAGE_FLAG_SIGNED Payload and computes the
+ *    Encodes the SilcMessageSignedPayload Payload and computes the
  *    digital signature.  The `message_payload' is the message data that
  *    is used in the signature computation.  The encoding of the buffer
- *    is specified in the SILC protocol.  If `include_public_key' is
- *    TRUE then the public key included in the payload.  The `private_key'
+ *    is specified in the SILC protocol.  If `public_key' is provided
+ *    then the public key included in the payload.  The `private_key'
  *    is used to produce the signature.  This function returns the encoded
  *    payload with the signature or NULL on error.  Caller must free the
- *    returned buffer.
+ *    returned buffer.  The `hash' SHOULD be SHA-1 hash function.
+ *    
+ *    Application usually does not need to call this since the function
+ *    silc_message_payload_encode calls this automatically if the caller
+ *    wants to sign the message.
  *
  ***/
 SilcBuffer
@@ -373,8 +414,7 @@ silc_message_signed_payload_encode(const unsigned char *message_payload,
                                   SilcUInt32 message_payload_len,
                                   SilcPublicKey public_key,
                                   SilcPrivateKey private_key,
-                                  SilcHash hash,
-                                  bool include_public_key);
+                                  SilcHash hash);
 
 /****f* silccore/SilcMessageAPI/silc_message_signed_payload_free
  *
@@ -384,7 +424,7 @@ silc_message_signed_payload_encode(const unsigned char *message_payload,
  *
  * DESCRIPTION
  *
- *    Frees the SILC_MESSAGE_FLAG_SIGNED Payload.
+ *    Frees the SilcMessageSignedPayload Payload.
  *
  ***/
 void silc_message_signed_payload_free(SilcMessageSignedPayload sig);
@@ -401,7 +441,7 @@ void silc_message_signed_payload_free(SilcMessageSignedPayload sig);
  * DESCRIPTION
  *
  *    This routine can be used to verify the signature found in
- *    SILC_MESSAGE_FLAG_SIGNED Payload.  This returns SILC_AUTH_OK if the
+ *    SilcMessageSignedPayload Payload.  This returns SILC_AUTH_OK if the
  *    signature verification was successful.
  *
  ***/
@@ -419,12 +459,16 @@ int silc_message_signed_verify(SilcMessageSignedPayload sig,
  *
  * DESCRIPTION
  *
- *    Returns the public key from the SILC_MESSAGE_FLAG_SIGNED Payload
- *    or NULL if it does not include public key.  The caller must free
- *    the returned public key.
+ *    Returns the decoded SilcPublicKey from the SilcMessageSignedPayload
+ *    Payload or NULL if it does not include public key.  The caller must
+ *    free the returned public key pointer.  This also returns the raw
+ *    public key (before decoding) into `pk_data' and `pk_data_len' if
+ *    they are provided.  The caller must not free these pointers.
  *
  ***/
 SilcPublicKey
-silc_message_signed_get_public_key(SilcMessageSignedPayload sig);
+silc_message_signed_get_public_key(SilcMessageSignedPayload sig,
+                                  unsigned char **pk_data,
+                                  SilcUInt32 *pk_data_len);
 
 #endif /* SILCMESSAGE_H */
index 20a42e9e863c8ac7c8853a57163b346002e7e944..f8a6389a5a4cf6d5361adde0f37ed970b8e752e4 100644 (file)
@@ -1,16 +1,15 @@
 /*
 
-  silcnotify.c
+  silcnotify.c 
 
-  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+  Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2000 Pekka Riikonen
+  Copyright (C) 2000 - 2002 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
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-  
+  the Free Software Foundation; version 2 of the License.
+
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@@ -88,8 +87,8 @@ SilcBuffer silc_notify_payload_encode(SilcNotifyType type, SilcUInt32 argc,
   unsigned char **argv;
   SilcUInt32 *argv_lens = NULL, *argv_types = NULL;
   unsigned char *x;
-  SilcUInt32 x_len;
-  int i, k = 0, len = 0;
+  SilcUInt32 x_len, len = 0;
+  int i, k = 0;
 
   if (argc) {
     argv = silc_calloc(argc, sizeof(unsigned char *));
@@ -161,7 +160,7 @@ SilcBuffer silc_notify_payload_encode_args(SilcNotifyType type,
                                           SilcBuffer args)
 {
   SilcBuffer buffer;
-  int len;
+  SilcUInt32 len;
 
   len = 5 + (args ? args->len : 0);
   buffer = silc_buffer_alloc_size(len);
index 0c3bcb9118c4581c9086db9e139e25e0b21ead0c..7bac3681106e2d8282b224cda531b985a7b9d7d8 100644 (file)
@@ -83,8 +83,8 @@ void silc_packet_encrypt(SilcCipher cipher, SilcHmac hmac, SilcUInt32 sequence,
 
   /* Encrypt the data area of the packet. */
   if (cipher) {
-    SILC_LOG_DEBUG(("Encrypting packet, cipher %s, len %d", 
-                   silc_cipher_get_name(cipher), len));
+    SILC_LOG_DEBUG(("Encrypting packet (%d), cipher %s, len %d", 
+                   sequence, silc_cipher_get_name(cipher), len));
     silc_cipher_encrypt(cipher, buffer->data, buffer->data, len, NULL);
   }
 
@@ -116,7 +116,7 @@ bool silc_packet_assemble(SilcPacketContext *packet, SilcRng rng,
                          const SilcBuffer assembled_packet)
 { 
   unsigned char tmppad[SILC_PACKET_MAX_PADLEN];   
-  int block_len = cipher ? silc_cipher_get_block_len(cipher) : 0;
+  unsigned int block_len = cipher ? silc_cipher_get_block_len(cipher) : 0;
   int i, ret;
 
   SILC_LOG_DEBUG(("Assembling outgoing packet"));
@@ -202,9 +202,9 @@ bool silc_packet_send_prepare(SilcSocketConnection sock,
                              SilcHmac hmac,
                              const SilcBuffer packet)
 { 
-  int totlen;
+  SilcUInt32 totlen;
   unsigned char *oldptr;
-  int mac_len = hmac ? silc_hmac_len(hmac) : 0;
+  unsigned int mac_len = hmac ? silc_hmac_len(hmac) : 0;
 
   if (!packet)
     return FALSE;
@@ -305,7 +305,9 @@ bool silc_packet_receive_process(SilcSocketConnection sock,
                                 void *parser_context)
 {
   SilcPacketParserContext *parse_ctx;
-  int packetlen, paddedlen, mac_len = 0, ret, block_len;
+  SilcUInt16 packetlen;
+  SilcUInt32 paddedlen, mac_len = 0, block_len;
+  int ret;
   bool cont = TRUE;
   unsigned char tmp[SILC_PACKET_MIN_HEADER_LEN], *header;
   unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
@@ -361,9 +363,11 @@ bool silc_packet_receive_process(SilcSocketConnection sock,
     /* Check MAC of the packet */
     if (!silc_packet_check_mac(hmac, sock->inbuf->data, paddedlen,
                               sock->inbuf->data + paddedlen, sequence)) {
-      SILC_LOG_WARNING(("Packet MAC check failed %s:%d [%s] [%s]", 
+      SILC_LOG_WARNING(("Packet MAC check failed %s:%d "
+                       "[%s type %d len %dB seq %d] [%s]",
                        sock->hostname, sock->port,
                        silc_get_packet_name(header[3]),
+                       header[3], paddedlen, sequence,
                        (sock->type == SILC_SOCKET_TYPE_UNKNOWN ? "Unknown" :
                         sock->type == SILC_SOCKET_TYPE_CLIENT ? "Client" :
                         sock->type == SILC_SOCKET_TYPE_SERVER ? "Server" :
@@ -379,8 +383,8 @@ bool silc_packet_receive_process(SilcSocketConnection sock,
       return FALSE;
     parse_ctx->packet = silc_packet_context_alloc();
     parse_ctx->packet->buffer = silc_buffer_alloc_size(paddedlen);
-    parse_ctx->packet->type = header[3];
-    parse_ctx->packet->padlen = header[4];
+    parse_ctx->packet->type = (SilcPacketType)header[3];
+    parse_ctx->packet->padlen = (SilcUInt8)header[4];
     parse_ctx->packet->sequence = sequence++;
     parse_ctx->sock = sock;
     parse_ctx->context = parser_context;
@@ -501,8 +505,11 @@ static int silc_packet_decrypt(SilcCipher cipher, SilcHmac hmac,
     if (cipher) {
       /* Decrypt rest of the packet */
       SILC_LOG_DEBUG(("Decrypting the packet"));
-      silc_cipher_decrypt(cipher, buffer->data, buffer->data, buffer->len,
-                         NULL);
+      if (!silc_cipher_decrypt(cipher, buffer->data, buffer->data,
+                              buffer->len, NULL)) {
+       SILC_LOG_ERROR(("silc_cipher_decrypt failed"));
+       return -1;
+      }
     }
     return 0;
 
@@ -510,7 +517,7 @@ static int silc_packet_decrypt(SilcCipher cipher, SilcHmac hmac,
     /* Decrypt rest of the header plus padding */
     if (cipher) {
       SilcUInt16 len;
-      int block_len = silc_cipher_get_block_len(cipher);
+      SilcUInt32 block_len = silc_cipher_get_block_len(cipher);
 
       SILC_LOG_DEBUG(("Decrypting the header"));
 
@@ -527,7 +534,11 @@ static int silc_packet_decrypt(SilcCipher cipher, SilcHmac hmac,
        return -1;
       }
       silc_buffer_pull(buffer, block_len);
-      silc_cipher_decrypt(cipher, buffer->data, buffer->data, len, NULL);
+      if (!silc_cipher_decrypt(cipher, buffer->data, buffer->data,
+                              len, NULL)) {
+       SILC_LOG_ERROR(("silc_cipher_decrypt failed"));
+       return -1;
+      }
     }
 
     return 1;
index 0e15ae438b714ae7a01584a78af24a23942f9d90..b2c9dd2790dc0b121ffc10c5f3919e452aa3dd01 100644 (file)
@@ -335,7 +335,7 @@ typedef bool (*SilcPacketParserCallback)(SilcPacketParserContext
 #define SILC_PACKET_LENGTH(__packetdata, __ret_truelen, __ret_paddedlen) \
 do {                                                                    \
   SILC_GET16_MSB((__ret_truelen), (__packetdata));                      \
-  (__ret_paddedlen) = (__ret_truelen) + (__packetdata)[4];              \
+  (__ret_paddedlen) = (__ret_truelen) + (SilcUInt8)(__packetdata)[4];   \
 } while(0)
 /***/
 
diff --git a/lib/silccore/tests/Makefile.am b/lib/silccore/tests/Makefile.am
new file mode 100644 (file)
index 0000000..7adf83c
--- /dev/null
@@ -0,0 +1,27 @@
+#
+#  Makefile.am
+#
+#  Author: Pekka Riikonen <priikone@silcnet.org>
+#
+#  Copyright (C) 2002 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
+#  the Free Software Foundation; version 2 of the License.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+
+AUTOMAKE_OPTIONS = 1.0 no-dependencies foreign
+
+bin_PROGRAMS =         test_silcargument
+
+test_silcargument_SOURCES = test_silcargument.c
+
+LIBS = $(SILC_COMMON_LIBS)
+LDADD = -L.. -L../.. -lsilc
+
+include $(top_srcdir)/Makefile.defines.in
diff --git a/lib/silccore/tests/test_silcargument.c b/lib/silccore/tests/test_silcargument.c
new file mode 100644 (file)
index 0000000..0b36d32
--- /dev/null
@@ -0,0 +1,190 @@
+/*
+
+  test_silcargument.c 
+
+  Author: Pekka Riikonen <priikone@silcnet.org>
+
+  Copyright (C) 2002 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
+  the Free Software Foundation; version 2 of the License.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+*/
+
+/* Tests:
+   silc_argument_payload_parse
+   silc_argument_payload_encode
+   silc_argument_payload_encode_one
+   silc_argument_payload_encode_payload
+   silc_argument_payload_free
+   silc_argument_get_arg_num
+   silc_argument_get_arg_first_arg
+   silc_argument_get_arg_next_arg
+   silc_argument_get_arg_type
+*/
+
+#include "silcincludes.h"
+#include "silcargument.h"
+
+#define ARG_NUM 250
+
+int main(int argc, char **argv)
+{
+  SilcArgumentPayload payload;
+  SilcBuffer args, args2;
+  char arg[ARG_NUM + 2];
+  int i;
+  unsigned char **argvv, *a;
+  SilcUInt32 *argvv_lens, l;
+  SilcUInt32 *argvv_types, t;
+  bool success = FALSE;
+
+  if (argc > 1 && !strcmp(argv[1], "-d")) {
+    silc_debug = 1;
+    silc_debug_hexdump = 1;
+    silc_log_set_debug_string("*argument*");
+  }
+
+  SILC_LOG_DEBUG(("Encoding %d arguments", ARG_NUM));
+  argvv = silc_calloc(ARG_NUM, sizeof(unsigned char *));
+  argvv_lens = silc_calloc(ARG_NUM, sizeof(SilcUInt32));
+  argvv_types = silc_calloc(ARG_NUM, sizeof(SilcUInt32));
+  for (i = 0; i < ARG_NUM; i++) {
+    memset(arg, 0, sizeof(arg));
+    memset(arg, 'a', i + 1);
+
+    SILC_LOG_DEBUG(("Argument %d, len %d, type %d", i + 1,
+                  strlen(arg), i + 1));
+    SILC_LOG_HEXDUMP(("Argument data"), arg, strlen(arg));
+
+    argvv[i] = silc_memdup(arg, strlen(arg));
+    argvv_lens[i] = strlen(arg);
+    argvv_types[i] = i + 1;
+  }
+  args = silc_argument_payload_encode(ARG_NUM, argvv, argvv_lens, argvv_types);
+  if (!args)
+    goto out;
+  SILC_LOG_DEBUG(("Encoding was successful"));
+
+
+  SILC_LOG_DEBUG(("Adding one extra argument"));
+  memset(arg, 0, sizeof(arg));
+  memset(arg, 'a', ARG_NUM + 1);
+  SILC_LOG_DEBUG(("Argument %d, len %d, type %d", ARG_NUM + 1,
+                strlen(arg), ARG_NUM + 1));
+  SILC_LOG_HEXDUMP(("Argument data"), arg, strlen(arg));
+  args = silc_argument_payload_encode_one(args, arg, strlen(arg), 
+                                         ARG_NUM + 1);
+  if (!args)
+    goto out;
+  SILC_LOG_DEBUG(("Adding one argument was successful"));
+
+  SILC_LOG_HEXDUMP(("Encoded payload"), args->data, args->len);
+
+
+  SILC_LOG_DEBUG(("Parsing the encoded payload"));
+  payload = silc_argument_payload_parse(args->data, args->len, ARG_NUM + 1);
+  if (!payload)
+    goto out;
+  SILC_LOG_DEBUG(("Parsing was successful"));
+
+
+  SILC_LOG_DEBUG(("Re-encoding the parsed payload"));
+  args2 = silc_argument_payload_encode_payload(payload);
+  if (!args2)
+    goto out;
+  if (args2->len != args->len ||
+      memcmp(args2->data, args->data, args->len)) {
+    SILC_LOG_DEBUG(("Re-encoding failed"));
+    goto out;
+  }
+  silc_buffer_free(args2);
+  SILC_LOG_DEBUG(("Re-encoding was successful"));
+
+
+  SILC_LOG_DEBUG(("Checking number of arguments"));
+  SILC_LOG_DEBUG(("Number of arguments: %d (expecting %d)",
+                silc_argument_get_arg_num(payload), ARG_NUM + 1));
+  if (silc_argument_get_arg_num(payload) != ARG_NUM + 1)
+    goto out;
+
+
+  SILC_LOG_DEBUG(("Traversing the parsed arguments"));
+  i = 0;
+  a = silc_argument_get_first_arg(payload, &t, &l);
+  if (!a || t != argvv_types[0] || l != argvv_lens[0] ||
+      memcmp(a, argvv[0], l)) {
+    SILC_LOG_DEBUG(("First argument failed"));
+    goto out;
+  }
+  while (a) {
+    if (i + 1 == ARG_NUM + 1) {
+      SILC_LOG_DEBUG(("Argument %d, len %d (expected %d), "
+                     "type %d (expected %d)", i + 1, l, strlen(arg),
+                     t, ARG_NUM + 1));
+      if (!a || t != ARG_NUM + 1 || l != strlen(arg) ||
+         memcmp(a, arg, l)) {
+       SILC_LOG_DEBUG(("Argument %d failed", ARG_NUM + 1));
+       goto out;
+      }
+    } else {
+      SILC_LOG_DEBUG(("Argument %d, len %d (expected %d), "
+                     "type %d (expected %d)", i + 1, l, argvv_lens[i],
+                     t, argvv_types[i]));
+      if (!a || t != argvv_types[i] || l != argvv_lens[i] ||
+         memcmp(a, argvv[i], l)) {
+       SILC_LOG_DEBUG(("Argument %d failed", i + 1));
+       goto out;
+      }
+    }
+    a = silc_argument_get_next_arg(payload, &t, &l);
+    i++;
+  }
+  if (i != ARG_NUM + 1) {
+    SILC_LOG_DEBUG(("All arguments was not parsed, missing %d args",
+                   ARG_NUM + 1 - i));
+    goto out;
+  }
+  SILC_LOG_DEBUG(("Traversing successful"));
+
+
+  SILC_LOG_DEBUG(("Traversing arguments by type"));
+  for (i = 0; i < ARG_NUM + 1; i++) {
+    a = silc_argument_get_arg_type(payload, i + 1, &l);
+    if (i + 1 == ARG_NUM + 1) {
+      if (!a || t != ARG_NUM + 1 || l != strlen(arg) ||
+         memcmp(a, arg, l)) {
+       SILC_LOG_DEBUG(("Argument %d failed", ARG_NUM + 1));
+       goto out;
+      }
+    } else {
+      if (!a || l != argvv_lens[i] || memcmp(a, argvv[i], l)) {
+       SILC_LOG_DEBUG(("Argument %d failed", i + 1));
+       goto out;
+      }
+    }
+  }
+  SILC_LOG_DEBUG(("Traversing successful"));
+
+  success = TRUE;
+
+ out:
+  silc_argument_payload_free(payload);
+  for (i = 0; i < ARG_NUM; i++)
+    silc_free(argvv[i]);
+  silc_free(argvv);
+  silc_free(argvv_lens);
+  silc_free(argvv_types);
+  silc_buffer_free(args);
+
+  SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE"));
+  fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE");
+
+  exit(success);
+}
index c3f058f0af2a5d4583b08ceb95074e02fe4c7f08..47f7204491e8e6810f2b9556744055b1bb07944b 100644 (file)
@@ -38,6 +38,15 @@ libsilccrypt_la_SOURCES = \
        silcpkcs.c \
        pkcs1.c
 
+if SILC_LIBTOOLFIX
+# Tell libtool to compile silccrypt as shared since silcsim will need it.
+LTFLAGS = --libtool-enable-shared
+else
+LTFLAGS = 
+endif
+
+CFLAGS = $(LTFLAGS)
+
 if SILC_DIST_TOOLKIT
 include_HEADERS =      \
        aes.h           \
@@ -61,6 +70,6 @@ include_HEADERS =     \
        twofish.h
 endif
 
-EXTRA_DIST = *.h
+EXTRA_DIST = *.h tests
 
 include $(top_srcdir)/Makefile.defines.in
index 71f1603c1c3ce9f7bb1fc1793d98c718db970183..35835b82451431817aa2dc89cf4731c236b474b9 100644 (file)
@@ -4,9 +4,9 @@
 #define MD5_INTERNAL_H
 
 struct MD5Context {
-       SilcUInt32 buf[4];
-       SilcUInt32 bits[2];
-       unsigned char in[64];
+  SilcUInt32 buf[4];
+  SilcUInt32 bits[2];
+  unsigned char in[64];
 };
 
 void MD5Init(struct MD5Context *context);
index 72d984b35cebbcf324ae9fac7ba17814134668ec..53c938b69a17e475d44ba9f7392bf993911a99ea 100644 (file)
@@ -315,6 +315,11 @@ bool silc_cipher_encrypt(SilcCipher cipher, const unsigned char *src,
                         unsigned char *dst, SilcUInt32 len, 
                         unsigned char *iv)
 {
+#ifdef SILC_DEBUG
+  assert((len & (cipher->cipher->block_len - 1)) == 0);
+#endif
+  if (len & (cipher->cipher->block_len - 1))
+    return FALSE;
   return cipher->cipher->encrypt(cipher->context, src, dst, len,
                                 iv ? iv : cipher->iv);
 }
@@ -325,6 +330,11 @@ bool silc_cipher_decrypt(SilcCipher cipher, const unsigned char *src,
                         unsigned char *dst, SilcUInt32 len, 
                         unsigned char *iv)
 {
+#ifdef SILC_DEBUG
+  assert((len & (cipher->cipher->block_len - 1)) == 0);
+#endif
+  if (len & (cipher->cipher->block_len - 1))
+    return FALSE;
   return cipher->cipher->decrypt(cipher->context, src, dst, len,
                                 iv ? iv : cipher->iv);
 }
index 410845fce97c52d2f24127ba7754d6997ba9d94e..4deddfd96f33b063277784024cd7f1861b4bb98d 100644 (file)
@@ -895,15 +895,6 @@ bool silc_pkcs_public_key_payload_decode(unsigned char *data,
   if (!public_key)
     return FALSE;
 
-#if 1
-  /* XXX 1.1 version support.  Check whether the data is actually raw
-     public key and attempt to decode.  Remove this later! */
-  if (silc_pkcs_public_key_decode(data, data_len, public_key)) {
-    (*public_key)->pk_type = SILC_SKE_PK_TYPE_SILC;
-    return TRUE;
-  }
-#endif
-
   silc_buffer_set(&buf, data, data_len);
   ret = silc_buffer_unformat(&buf,
                             SILC_STR_UI_SHORT(&pk_len),
@@ -1112,7 +1103,7 @@ bool silc_pkcs_private_key_decode(unsigned char *data, SilcUInt32 data_len,
 
 /* Internal routine to save public key */
 
-static bool silc_pkcs_save_public_key_internal(char *filename,
+static bool silc_pkcs_save_public_key_internal(const char *filename,
                                               unsigned char *data,
                                               SilcUInt32 data_len,
                                               SilcUInt32 encoding)
@@ -1152,7 +1143,7 @@ static bool silc_pkcs_save_public_key_internal(char *filename,
 
 /* Saves public key into file */
 
-bool silc_pkcs_save_public_key(char *filename, SilcPublicKey public_key,
+bool silc_pkcs_save_public_key(const char *filename, SilcPublicKey public_key,
                               SilcUInt32 encoding)
 {
   unsigned char *data;
@@ -1168,9 +1159,8 @@ bool silc_pkcs_save_public_key(char *filename, SilcPublicKey public_key,
 
 /* Saves public key into file */
 
-bool silc_pkcs_save_public_key_data(char *filename, unsigned char *data,
-                                   SilcUInt32 data_len,
-                                   SilcUInt32 encoding)
+bool silc_pkcs_save_public_key_data(const char *filename, unsigned char *data,
+                                   SilcUInt32 data_len, SilcUInt32 encoding)
 {
   return silc_pkcs_save_public_key_internal(filename, data, data_len,
                                            encoding);
@@ -1180,7 +1170,7 @@ bool silc_pkcs_save_public_key_data(char *filename, unsigned char *data,
 
 /* Internal routine to save private key. */
 
-static bool silc_pkcs_save_private_key_internal(char *filename,
+static bool silc_pkcs_save_private_key_internal(const char *filename,
                                                unsigned char *data,
                                                SilcUInt32 data_len,
                                                unsigned char *key,
@@ -1188,11 +1178,11 @@ static bool silc_pkcs_save_private_key_internal(char *filename,
                                                SilcUInt32 encoding)
 {
   SilcCipher aes;
-  SilcHash md5;
+  SilcHash sha1;
   SilcHmac sha1hmac;
   SilcBuffer buf, enc;
-  SilcUInt32 len, blocklen;
-  unsigned char tmp[32], keymat[32];
+  SilcUInt32 len, blocklen, padlen;
+  unsigned char tmp[32], keymat[64];
   int i;
 
   memset(tmp, 0, sizeof(tmp));
@@ -1207,9 +1197,9 @@ static bool silc_pkcs_save_private_key_internal(char *filename,
   if (blocklen * 2 > sizeof(tmp))
     return FALSE;
 
-  /* Allocate MD5 hash */
-  if (!silc_hash_alloc("md5", &md5)) {
-    SILC_LOG_ERROR(("Could not allocate MD5 hash, probably not registered"));
+  /* Allocate SHA1 hash */
+  if (!silc_hash_alloc("sha1", &sha1)) {
+    SILC_LOG_ERROR(("Could not allocate SHA1 hash, probably not registered"));
     silc_cipher_free(aes);
     return FALSE;
   }
@@ -1217,7 +1207,7 @@ static bool silc_pkcs_save_private_key_internal(char *filename,
   /* Allocate HMAC */
   if (!silc_hmac_alloc("hmac-sha1-96", NULL, &sha1hmac)) {
     SILC_LOG_ERROR(("Could not allocate SHA1 HMAC, probably not registered"));
-    silc_hash_free(md5);
+    silc_hash_free(sha1);
     silc_cipher_free(aes);
     return FALSE;
   }
@@ -1226,33 +1216,33 @@ static bool silc_pkcs_save_private_key_internal(char *filename,
      is 256 bits length, and derived by taking hash of the data, then 
      re-hashing the data and the previous digest, and using the first and
      second digest as the key. */
-  silc_hash_init(md5);
-  silc_hash_update(md5, key, key_len);
-  silc_hash_final(md5, keymat);
-  silc_hash_init(md5);
-  silc_hash_update(md5, key, key_len);
-  silc_hash_update(md5, keymat, 16);
-  silc_hash_final(md5, keymat + 16);
+  silc_hash_init(sha1);
+  silc_hash_update(sha1, key, key_len);
+  silc_hash_final(sha1, keymat);
+  silc_hash_init(sha1);
+  silc_hash_update(sha1, key, key_len);
+  silc_hash_update(sha1, keymat, 16);
+  silc_hash_final(sha1, keymat + 16);
 
   /* Set the key to the cipher */
-  silc_cipher_set_key(aes, keymat, sizeof(keymat) * 8);
+  silc_cipher_set_key(aes, keymat, 256);
 
   /* Encode the buffer to be encrypted.  Add padding to it too, at least
      block size of the cipher. */
 
   /* Allocate buffer for encryption */
   len = silc_hmac_len(sha1hmac);
-  enc = silc_buffer_alloc_size(data_len + 4 + 4 +
-                              (blocklen + (data_len % blocklen)) + len);
+  padlen = 16 + (16 - ((data_len + 4) % blocklen));
+  enc = silc_buffer_alloc_size(4 + 4 + data_len + padlen + len);
   if (!enc) {
     silc_hmac_free(sha1hmac);
-    silc_hash_free(md5);
+    silc_hash_free(sha1);
     silc_cipher_free(aes);
     return FALSE;
   }
 
   /* Generate padding */
-  for (i = 0; i < blocklen + (data_len % blocklen); i++)
+  for (i = 0; i < padlen; i++)
     tmp[i] = silc_rng_global_get_byte_fast();
 
   /* Put magic number */
@@ -1263,8 +1253,7 @@ static bool silc_pkcs_save_private_key_internal(char *filename,
   silc_buffer_format(enc,
                     SILC_STR_UI_INT(data_len),
                     SILC_STR_UI_XNSTRING(data, data_len),
-                    SILC_STR_UI_XNSTRING(tmp, blocklen + (data_len %
-                                                          blocklen)),
+                    SILC_STR_UI_XNSTRING(tmp, padlen),
                     SILC_STR_END);
 
   /* Encrypt. */
@@ -1286,7 +1275,7 @@ static bool silc_pkcs_save_private_key_internal(char *filename,
   memset(keymat, 0, sizeof(keymat));
   memset(tmp, 0, sizeof(tmp));
   silc_hmac_free(sha1hmac);
-  silc_hash_free(md5);
+  silc_hash_free(sha1);
   silc_cipher_free(aes);
 
   data = enc->data;
@@ -1329,7 +1318,8 @@ static bool silc_pkcs_save_private_key_internal(char *filename,
 
 /* Saves private key into file. */
 
-bool silc_pkcs_save_private_key(char *filename, SilcPrivateKey private_key, 
+bool silc_pkcs_save_private_key(const char *filename,
+                               SilcPrivateKey private_key,
                                unsigned char *passphrase,
                                SilcUInt32 passphrase_len,
                                SilcUInt32 encoding)
@@ -1350,12 +1340,16 @@ bool silc_pkcs_save_private_key(char *filename, SilcPrivateKey private_key,
 /* Loads public key from file and allocates new public key. Returns TRUE
    if loading was successful. */
 
-bool silc_pkcs_load_public_key(char *filename, SilcPublicKey *public_key,
+bool silc_pkcs_load_public_key(const char *filename, SilcPublicKey *public_key,
                               SilcUInt32 encoding)
 {
   unsigned char *cp, *old, *data, byte;
   SilcUInt32 i, data_len, len;
 
+  SILC_LOG_DEBUG(("Loading public key `%s' with %s encoding", filename,
+                 encoding == SILC_PKCS_FILE_PEM ? "Base64" :
+                 encoding == SILC_PKCS_FILE_BIN ? "Binary" : "Unkonwn"));
+  
   old = data = silc_file_readfile(filename, &data_len);
   if (!data)
     return FALSE;
@@ -1406,19 +1400,24 @@ bool silc_pkcs_load_public_key(char *filename, SilcPublicKey *public_key,
 /* Load private key from file and allocates new private key. Returns TRUE
    if loading was successful. */
 
-bool silc_pkcs_load_private_key(char *filename, SilcPrivateKey *private_key,
+bool silc_pkcs_load_private_key(const char *filename,
+                               SilcPrivateKey *private_key,
                                unsigned char *passphrase,
                                SilcUInt32 passphrase_len,
                                SilcUInt32 encoding)
 {
   SilcCipher aes;
-  SilcHash md5;
+  SilcHash sha1;
   SilcHmac sha1hmac;
   SilcUInt32 blocklen;
-  unsigned char tmp[32], keymat[32];
+  unsigned char tmp[32], keymat[64];
   unsigned char *cp, *old, *data, byte;
   SilcUInt32 i, data_len, len, magic, mac_len;
 
+  SILC_LOG_DEBUG(("Loading private key `%s' with %s encoding", filename,
+                 encoding == SILC_PKCS_FILE_PEM ? "Base64" :
+                 encoding == SILC_PKCS_FILE_BIN ? "Binary" : "Unkonwn"));
+  
   old = data = silc_file_readfile(filename, &data_len);
   if (!data)
     return FALSE;
@@ -1489,9 +1488,9 @@ bool silc_pkcs_load_private_key(char *filename, SilcPrivateKey *private_key,
     return FALSE;
   }
 
-  /* Allocate MD5 hash */
-  if (!silc_hash_alloc("md5", &md5)) {
-    SILC_LOG_ERROR(("Could not allocate MD5 hash, probably not registered"));
+  /* Allocate SHA1 hash */
+  if (!silc_hash_alloc("sha1", &sha1)) {
+    SILC_LOG_ERROR(("Could not allocate SHA1 hash, probably not registered"));
     silc_cipher_free(aes);
     memset(old, 0, data_len);
     silc_free(old);
@@ -1501,7 +1500,7 @@ bool silc_pkcs_load_private_key(char *filename, SilcPrivateKey *private_key,
   /* Allocate HMAC */
   if (!silc_hmac_alloc("hmac-sha1-96", NULL, &sha1hmac)) {
     SILC_LOG_ERROR(("Could not allocate SHA1 HMAC, probably not registered"));
-    silc_hash_free(md5);
+    silc_hash_free(sha1);
     silc_cipher_free(aes);
     memset(old, 0, data_len);
     silc_free(old);
@@ -1512,16 +1511,16 @@ bool silc_pkcs_load_private_key(char *filename, SilcPrivateKey *private_key,
      is 256 bits length, and derived by taking hash of the data, then 
      re-hashing the data and the previous digest, and using the first and
      second digest as the key. */
-  silc_hash_init(md5);
-  silc_hash_update(md5, passphrase, passphrase_len);
-  silc_hash_final(md5, keymat);
-  silc_hash_init(md5);
-  silc_hash_update(md5, passphrase, passphrase_len);
-  silc_hash_update(md5, keymat, 16);
-  silc_hash_final(md5, keymat + 16);
+  silc_hash_init(sha1);
+  silc_hash_update(sha1, passphrase, passphrase_len);
+  silc_hash_final(sha1, keymat);
+  silc_hash_init(sha1);
+  silc_hash_update(sha1, passphrase, passphrase_len);
+  silc_hash_update(sha1, keymat, 16);
+  silc_hash_final(sha1, keymat + 16);
 
   /* Set the key to the cipher */
-  silc_cipher_set_key(aes, keymat, sizeof(keymat) * 8);
+  silc_cipher_set_key(aes, keymat, 256);
 
   /* First, verify the MAC of the private key data */
   mac_len = silc_hmac_len(sha1hmac);
@@ -1533,7 +1532,7 @@ bool silc_pkcs_load_private_key(char *filename, SilcPrivateKey *private_key,
     memset(keymat, 0, sizeof(keymat));
     memset(tmp, 0, sizeof(tmp));
     silc_hmac_free(sha1hmac);
-    silc_hash_free(md5);
+    silc_hash_free(sha1);
     silc_cipher_free(aes);
     memset(old, 0, data_len);
     silc_free(old);
@@ -1543,14 +1542,14 @@ bool silc_pkcs_load_private_key(char *filename, SilcPrivateKey *private_key,
   len -= 4;
 
   /* Decrypt the private key buffer */
-  silc_cipher_decrypt(aes, data, data, len - mac_len, silc_cipher_get_iv(aes));
+  silc_cipher_decrypt(aes, data, data, len - mac_len, NULL);
   SILC_GET32_MSB(i, data);
   if (i > len) {
     SILC_LOG_DEBUG(("Bad private key length in buffer!"));
     memset(keymat, 0, sizeof(keymat));
     memset(tmp, 0, sizeof(tmp));
     silc_hmac_free(sha1hmac);
-    silc_hash_free(md5);
+    silc_hash_free(sha1);
     silc_cipher_free(aes);
     memset(old, 0, data_len);
     silc_free(old);
@@ -1563,7 +1562,7 @@ bool silc_pkcs_load_private_key(char *filename, SilcPrivateKey *private_key,
   memset(keymat, 0, sizeof(keymat));
   memset(tmp, 0, sizeof(tmp));
   silc_hmac_free(sha1hmac);
-  silc_hash_free(md5);
+  silc_hash_free(sha1);
   silc_cipher_free(aes);
 
   /* Now decode the actual private key */
index d9497309729b4b37112b365dd55163732d74dc4c..eb1a1f709dca6a7e2c0e26a361ed253a0c542be4 100644 (file)
 /****s* silccrypt/SilcPKCSAPI/SilcPKCS
  *
  * NAME
- * 
+ *
  *    typedef struct SilcPKCSStruct *SilcPKCS;
  *
  * DESCRIPTION
  *
  *    This context is the actual PKCS context and is allocated
  *    by silc_pkcs_alloc and given as argument usually to all
- *    silc_pkcs _* functions.  It is freed by the silc_pkcs_free
+ *    silc_pkcs_* functions.  It is freed by the silc_pkcs_free
  *    function.
  *
  ***/
@@ -77,13 +77,13 @@ typedef struct SilcPKCSObjectStruct {
 /****s* silccrypt/SilcPKCSAPI/SilcPublicKey
  *
  * NAME
- * 
+ *
  *    typedef struct { ... } *SilcPublicKey;
  *
  * DESCRIPTION
  *
  *    SILC style public key object.  Public key is read from file to this
- *    object.  Public keys received from network must be in this format as 
+ *    object.  Public keys received from network must be in this format as
  *    well.  The format is defined by the SILC protocol specification.
  *    This object is allocated by silc_pkcs_public_key_alloc and freed
  *    by silc_pkcs_public_key_free.  The object is given as argument to
@@ -104,15 +104,15 @@ typedef struct {
 /****s* silccrypt/SilcPKCSAPI/SilcPublicKeyIdentifier
  *
  * NAME
- * 
+ *
  *    typedef struct { ... } *SilcPublicKeyIdentifier;
  *
  * DESCRIPTION
  *
- *    Decoded SILC Public Key identifier.  Note that some of the fields 
- *    may be NULL.  This context is allcated by the function
+ *    Decoded SILC Public Key identifier.  Note that some of the fields
+ *    may be NULL.  This context is allocated by the function
  *    silc_pkcs_decode_identifier and freed by silc_pkcs_free_identifier.
- *    The identifier in SilcPublicKey is the 'identifier' field, which
+ *    The identifier in SilcPublicKey is the `identifier' field, which
  *    can be given as argument to silc_pkcs_decode_identifier.
  *
  * SOURCE
@@ -130,7 +130,7 @@ typedef struct {
 /****s* silccrypt/SilcPKCSAPI/SilcPrivateKey
  *
  * NAME
- * 
+ *
  *    typedef struct { ... } *SilcPrivateKey;
  *
  * DESCRIPTION
@@ -177,16 +177,16 @@ extern DLLAPI const SilcPKCSObject silc_default_pkcs[];
    as argument to the init function. By doing this we would achieve
    that PKCS could be used as SIM's. The only requirement would be
    that they are compiled against GMP (well, actually even that would
-   not be a requirement, but the most generic case anyway). The new init 
+   not be a requirement, but the most generic case anyway). The new init
    would look something like this:
 
    #define SILC_PKCS_API_INIT(pkcs) \
    inline int silc_##pkcs##_init(void *context, SilcUInt32 keylen, \
                                  void *p1, void *p2)
 
-   Now we wouldn't have to send the SilcRng object since the primes are 
-   provided as arguments. To send them as void * they could actually be 
-   used as in anyway for real (MP_INT (SilcMPInt) or even something else 
+   Now we wouldn't have to send the SilcRng object since the primes are
+   provided as arguments. To send them as void * they could actually be
+   used as in anyway for real (MP_INT (SilcMPInt) or even something else
    (the pointer could be kludged to be something else in the module))
    (Plus, the SilcRng object management in prime generation would be
    simpler and better what it is now (in silcprimegen.c, that is)).
@@ -306,8 +306,8 @@ bool silc_pkcs_unregister_all(void);
  *
  * DESCRIPTION
  *
- *    Allocates a new SilcPKCS object. The new allocated object is returned
- *    to the 'new_pkcs' argument. Returns FALSE on error.
+ *    Allocates a new SilcPKCS object.  The new allocated object is returned
+ *    to the 'new_pkcs' argument.  Returns FALSE on error.
  *
  ***/
 bool silc_pkcs_alloc(const unsigned char *name, SilcPKCS *new_pkcs);
@@ -411,7 +411,7 @@ unsigned char *silc_pkcs_get_public_key(SilcPKCS pkcs, SilcUInt32 *len);
  * SYNOPSIS
  *
  *    unsigned char *silc_pkcs_get_private_key(SilcPKCS pkcs,
- *                                            SilcUInt32 *len);
+ *                                             SilcUInt32 *len);
  *
  * DESCRIPTION
  *
@@ -426,7 +426,7 @@ unsigned char *silc_pkcs_get_private_key(SilcPKCS pkcs, SilcUInt32 *len);
  * SYNOPSIS
  *
  *    SilcUInt32 silc_pkcs_public_key_set(SilcPKCS pkcs,
- *                                       SilcPublicKey public_key);
+ *                                        SilcPublicKey public_key);
  *
  * DESCRIPTION
  *
@@ -441,7 +441,7 @@ SilcUInt32 silc_pkcs_public_key_set(SilcPKCS pkcs, SilcPublicKey public_key);
  *
  *    SilcUInt32 silc_pkcs_public_key_data_set(SilcPKCS pkcs,
  *                                             unsigned char *pk,
- *                                            SilcUInt32 pk_len);
+ *                                             SilcUInt32 pk_len);
  *
  * DESCRIPTION
  *
@@ -456,7 +456,7 @@ SilcUInt32 silc_pkcs_public_key_data_set(SilcPKCS pkcs, unsigned char *pk,
  * SYNOPSIS
  *
  *    SilcUInt32 silc_pkcs_private_key_set(SilcPKCS pkcs,
- *                                        SilcPrivateKey private_key);
+ *                                         SilcPrivateKey private_key);
  *
  * DESCRIPTION
  *
@@ -470,8 +470,8 @@ SilcUInt32 silc_pkcs_private_key_set(SilcPKCS pkcs, SilcPrivateKey private_key);
  * SYNOPSIS
  *
  *    SilcUInt32 silc_pkcs_private_key_data_set(SilcPKCS pkcs,
- *                                             unsigned char *prv,
- *                                             SilcUInt32 prv_len);
+ *                                              unsigned char *prv,
+ *                                              SilcUInt32 prv_len);
  *
  * DESCRIPTION
  *
@@ -486,8 +486,8 @@ SilcUInt32 silc_pkcs_private_key_data_set(SilcPKCS pkcs, unsigned char *prv,
  * SYNOPSIS
  *
  *    bool silc_pkcs_encrypt(SilcPKCS pkcs, unsigned char *src,
- *                          SilcUInt32 src_len, unsigned char *dst,
- *                          SilcUInt32 *dst_len);
+ *                           SilcUInt32 src_len, unsigned char *dst,
+ *                           SilcUInt32 *dst_len);
  *
  * DESCRIPTION
  *
@@ -502,12 +502,12 @@ bool silc_pkcs_encrypt(SilcPKCS pkcs, unsigned char *src, SilcUInt32 src_len,
  * SYNOPSIS
  *
  *    bool silc_pkcs_decrypt(SilcPKCS pkcs, unsigned char *src,
- *                          SilcUInt32 src_len, unsigned char *dst,
- *                          SilcUInt32 *dst_len);
+ *                           SilcUInt32 src_len, unsigned char *dst,
+ *                           SilcUInt32 *dst_len);
  *
  * DESCRIPTION
  *
- *    Decrypts. Returns FALSE on error.
+ *    Decrypts.  Returns FALSE on error.
  *
  ***/
 bool silc_pkcs_decrypt(SilcPKCS pkcs, unsigned char *src, SilcUInt32 src_len,
@@ -518,12 +518,12 @@ bool silc_pkcs_decrypt(SilcPKCS pkcs, unsigned char *src, SilcUInt32 src_len,
  * SYNOPSIS
  *
  *    bool silc_pkcs_sign(SilcPKCS pkcs, unsigned char *src,
- *                       SilcUInt32 src_len, unsigned char *dst,
- *                       SilcUInt32 *dst_len);
+ *                        SilcUInt32 src_len, unsigned char *dst,
+ *                        SilcUInt32 *dst_len);
  *
  * DESCRIPTION
  *
- *    Generates signature. Returns FALSE on error.
+ *    Generates signature.  Returns FALSE on error.
  *
  ***/
 bool silc_pkcs_sign(SilcPKCS pkcs, unsigned char *src, SilcUInt32 src_len,
@@ -534,12 +534,12 @@ bool silc_pkcs_sign(SilcPKCS pkcs, unsigned char *src, SilcUInt32 src_len,
  * SYNOPSIS
  *
  *    bool silc_pkcs_verify(SilcPKCS pkcs, unsigned char *signature,
- *                         SilcUInt32 signature_len, unsigned char *data,
- *                         SilcUInt32 data_len);
+ *                          SilcUInt32 signature_len, unsigned char *data,
+ *                          SilcUInt32 data_len);
  *
  * DESCRIPTION
  *
- *    Verifies signature. Returns FALSE on error.
+ *    Verifies signature.  Returns FALSE on error.
  *
  ***/
 bool silc_pkcs_verify(SilcPKCS pkcs, unsigned char *signature,
@@ -551,12 +551,12 @@ bool silc_pkcs_verify(SilcPKCS pkcs, unsigned char *signature,
  * SYNOPSIS
  *
  *    bool silc_pkcs_sign_with_hash(SilcPKCS pkcs, SilcHash hash,
- *                                 unsigned char *src, SilcUInt32 src_len,
- *                                 unsigned char *dst, SilcUInt32 *dst_len);
+ *                                  unsigned char *src, SilcUInt32 src_len,
+ *                                  unsigned char *dst, SilcUInt32 *dst_len);
  *
  * DESCRIPTION
  *
- *    Generates signature with hash. The hash is signed. Returns FALSE on
+ *    Generates signature with hash.  The hash is signed.  Returns FALSE on
  *    error.
  *
  ***/
@@ -569,15 +569,15 @@ bool silc_pkcs_sign_with_hash(SilcPKCS pkcs, SilcHash hash,
  * SYNOPSIS
  *
  *    bool silc_pkcs_verify_with_hash(SilcPKCS pkcs, SilcHash hash,
- *                                   unsigned char *signature,
- *                                   SilcUInt32 signature_len,
- *                                   unsigned char *data,
- *                                   SilcUInt32 data_len);
+ *                                    unsigned char *signature,
+ *                                    SilcUInt32 signature_len,
+ *                                    unsigned char *data,
+ *                                    SilcUInt32 data_len);
  *
  * DESCRIPTION
  *
- *    Verifies signature with hash. The `data' is hashed and verified against
- *    the `signature'. Returns FALSE on error.
+ *    Verifies signature with hash.  The `data' is hashed and verified against
+ *    the `signature'.  Returns FALSE on error.
  *
  ***/
 bool silc_pkcs_verify_with_hash(SilcPKCS pkcs, SilcHash hash,
@@ -591,8 +591,8 @@ bool silc_pkcs_verify_with_hash(SilcPKCS pkcs, SilcHash hash,
  * SYNOPSIS
  *
  *    char *silc_pkcs_encode_identifier(char *username, char *host,
- *                                     char *realname, char *email,
- *                                     char *org, char *country);
+ *                                      char *realname, char *email,
+ *                                      char *org, char *country);
  *
  * DESCRIPTION
  *
@@ -626,7 +626,7 @@ SilcPublicKeyIdentifier silc_pkcs_decode_identifier(char *identifier);
  *
  * DESCRIPTION
  *
- *    Frees decoded public key identifier context. Call this to free the
+ *    Frees decoded public key identifier context.  Call this to free the
  *    context returned by the silc_pkcs_decode_identifier.
  *
  ***/
@@ -637,13 +637,13 @@ void silc_pkcs_free_identifier(SilcPublicKeyIdentifier identifier);
  * SYNOPSIS
  *
  *    SilcPublicKey silc_pkcs_public_key_alloc(const char *name,
- *                                            const char *identifier,
- *                                            const unsigned char *pk,
- *                                            SilcUInt32 pk_len);
+ *                                             const char *identifier,
+ *                                             const unsigned char *pk,
+ *                                             SilcUInt32 pk_len);
  *
  * DESCRIPTION
  *
- *    Allocates SILC style public key formed from sent arguments. All data
+ *    Allocates SILC style public key formed from sent arguments.  All data
  *    is duplicated.
  *
  ***/
@@ -670,12 +670,12 @@ void silc_pkcs_public_key_free(SilcPublicKey public_key);
  * SYNOPSIS
  *
  *    SilcPrivateKey silc_pkcs_private_key_alloc(const char *name,
- *                                              const unsigned char *prv,
- *                                              SilcUInt32 prv_len);
+ *                                               const unsigned char *prv,
+ *                                               SilcUInt32 prv_len);
  *
  * DESCRIPTION
  *
- *    Allocates SILC private key formed from sent arguments. All data is
+ *    Allocates SILC private key formed from sent arguments.  All data is
  *    duplicated.
  *
  ***/
@@ -705,7 +705,7 @@ void silc_pkcs_private_key_free(SilcPrivateKey private_key);
  *
  * DESCRIPTION
  *
- *    Encodes SILC style public key from SilcPublicKey. Returns the encoded
+ *    Encodes SILC style public key from SilcPublicKey.  Returns the encoded
  *    data.
  *
  ***/
@@ -718,18 +718,18 @@ silc_pkcs_public_key_encode(SilcPublicKey public_key, SilcUInt32 *len);
  *
  *    unsigned char *
  *    silc_pkcs_public_key_data_encode(unsigned char *pk, SilcUInt32 pk_len,
- *                                    char *pkcs, char *identifier,
- *                                    SilcUInt32 *len);
+ *                                     char *pkcs, char *identifier,
+ *                                     SilcUInt32 *len);
  *
  * DESCRIPTION
  *
- *    Encodes SILC style public key. Returns the encoded data.
+ *    Encodes SILC style public key.  Returns the encoded data.
  *
  ***/
 unsigned char *
 silc_pkcs_public_key_data_encode(unsigned char *pk, SilcUInt32 pk_len,
-                                char *pkcs, char *identifier,
-                                SilcUInt32 *len);
+                                 char *pkcs, char *identifier,
+                                 SilcUInt32 *len);
 
 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_decode
  *
@@ -748,7 +748,7 @@ silc_pkcs_public_key_data_encode(unsigned char *pk, SilcUInt32 pk_len,
 bool silc_pkcs_public_key_decode(unsigned char *data, SilcUInt32 data_len,
                                 SilcPublicKey *public_key);
 
-/****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_decode
+/****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_payload_encode
  *
  * SYNOPSIS
  *
@@ -763,19 +763,18 @@ bool silc_pkcs_public_key_decode(unsigned char *data, SilcUInt32 data_len,
  ***/
 SilcBuffer silc_pkcs_public_key_payload_encode(SilcPublicKey public_key);
 
-/****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_decode
+/****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_payload_decode
  *
  * SYNOPSIS
  *
- *    bool
- *    silc_pkcs_public_key_payload_decode(unsigned char *data,
- *                                        SilcUInt32 data_len,
- *                                        SilcPublicKey *public_key);
+ *    bool silc_pkcs_public_key_payload_decode(unsigned char *data,
+ *                                             SilcUInt32 data_len,
+ *                                             SilcPublicKey *public_key);
  *
  * DESCRIPTION
  *
  *    Decodes Public Key Payload from `data' of `data_len' bytes in length
- *    data buffer into `public_key' pointer. Returns FALSE if the payload
+ *    data buffer into `public_key' pointer.  Returns FALSE if the payload
  *    cannot be decoded.
  *
  ***/
@@ -788,7 +787,7 @@ bool silc_pkcs_public_key_payload_decode(unsigned char *data,
  * SYNOPSIS
  *
  *    bool silc_pkcs_public_key_compare(SilcPublicKey key1,
- *                                     SilcPublicKey key2);
+ *                                      SilcPublicKey key2);
  *
  * DESCRIPTION
  *
@@ -818,11 +817,11 @@ SilcPublicKey silc_pkcs_public_key_copy(SilcPublicKey public_key);
  *
  *    unsigned char *
  *    silc_pkcs_private_key_encode(SilcPrivateKey private_key,
- *                                SilcUInt32 *len);
+ *                                 SilcUInt32 *len);
  *
  * DESCRIPTION
  *
- *    Encodes SILC private key from SilcPrivateKey. Returns the encoded data.
+ *    Encodes SILC private key from SilcPrivateKey.  Returns the encoded data.
  *
  ***/
 unsigned char *
@@ -834,11 +833,11 @@ silc_pkcs_private_key_encode(SilcPrivateKey private_key, SilcUInt32 *len);
  *
  *    unsigned char *
  *    silc_pkcs_private_key_data_encode(unsigned char *prv, SilcUInt32 prv_len,
- *                                     char *pkcs, SilcUInt32 *len);
+ *                                      char *pkcs, SilcUInt32 *len);
  *
  * DESCRIPTION
  *
- *    Encodes SILC private key. Returns the encoded data.
+ *    Encodes SILC private key.  Returns the encoded data.
  *
  ***/
 unsigned char *
@@ -850,13 +849,13 @@ silc_pkcs_private_key_data_encode(unsigned char *prv, SilcUInt32 prv_len,
  * SYNOPSIS
  *
  *    bool silc_pkcs_private_key_decode(unsigned char *data,
- *                                     SilcUInt32 data_len,
- *                                     SilcPrivateKey *private_key);
+ *                                      SilcUInt32 data_len,
+ *                                      SilcPrivateKey *private_key);
  *
  * DESCRIPTION
  *
- *    Decodes SILC style private key. Returns TRUE if the decoding was
- *    successful. Allocates new private key as well.
+ *    Decodes SILC style private key.  Returns TRUE if the decoding was
+ *    successful.  Allocates new private key as well.
  *
  ***/
 bool silc_pkcs_private_key_decode(unsigned char *data, SilcUInt32 data_len,
@@ -866,24 +865,26 @@ bool silc_pkcs_private_key_decode(unsigned char *data, SilcUInt32 data_len,
  *
  * SYNOPSIS
  *
- *    bool silc_pkcs_save_public_key(char *filename, SilcPublicKey public_key,
- *                                  SilcUInt32 encoding);
+ *    bool silc_pkcs_save_public_key(const char *filename,
+ *                                   SilcPublicKey public_key,
+ *                                   SilcUInt32 encoding);
  *
  * DESCRIPTION
  *
- *    Saves public key into file. Returns FALSE on error.
+ *    Saves public key into file.  Returns FALSE on error.
  *
  ***/
-bool silc_pkcs_save_public_key(char *filename, SilcPublicKey public_key,
+bool silc_pkcs_save_public_key(const char *filename, SilcPublicKey public_key,
                               SilcUInt32 encoding);
 
 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_save_public_key_data
  *
  * SYNOPSIS
  *
- *    bool silc_pkcs_save_public_key_data(char *filename, unsigned char *data,
- *                                       SilcUInt32 data_len,
- *                                       SilcUInt32 encoding);
+ *    bool silc_pkcs_save_public_key_data(const char *filename,
+ *                                        unsigned char *data,
+ *                                        SilcUInt32 data_len,
+ *                                        SilcUInt32 encoding);
  *
  * DESCRIPTION
  *
@@ -891,16 +892,15 @@ bool silc_pkcs_save_public_key(char *filename, SilcPublicKey public_key,
  *    data when calling this function.  Returns FALSE on error.
  *
  ***/
-bool silc_pkcs_save_public_key_data(char *filename, unsigned char *data,
-                                   SilcUInt32 data_len,
-                                   SilcUInt32 encoding);
+bool silc_pkcs_save_public_key_data(const char *filename, unsigned char *data,
+                                   SilcUInt32 data_len, SilcUInt32 encoding);
 
 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_save_private_key
  *
  * SYNOPSIS
  *
- *    bool silc_pkcs_save_private_key(char *filename,
- *                                   SilcPrivateKey private_key,
+ *    bool silc_pkcs_save_private_key(const char *filename,
+ *                                    SilcPrivateKey private_key,
  *                                    unsigned char *passphrase,
  *                                    SilcUInt32 passphrase_len,
  *                                    SilcUInt32 encoding);
@@ -912,7 +912,8 @@ bool silc_pkcs_save_public_key_data(char *filename, unsigned char *data,
  *    is AES with 256 bit key in CBC mode.  Returns FALSE on error.
  *
  ***/
-bool silc_pkcs_save_private_key(char *filename, SilcPrivateKey private_key, 
+bool silc_pkcs_save_private_key(const char *filename,
+                               SilcPrivateKey private_key,
                                unsigned char *passphrase,
                                SilcUInt32 passphrase_len,
                                SilcUInt32 encoding);
@@ -921,23 +922,24 @@ bool silc_pkcs_save_private_key(char *filename, SilcPrivateKey private_key,
  *
  * SYNOPSIS
  *
- *    bool silc_pkcs_load_public_key(char *filename, SilcPublicKey *public_key,
- *                                  SilcUInt32 encoding);
+ *    bool silc_pkcs_load_public_key(const char *filename,
+ *                                   SilcPublicKey *public_key,
+ *                                   SilcUInt32 encoding);
  *
  * DESCRIPTION
  *
- *    Loads public key from file and allocates new public key. Returns TRUE
+ *    Loads public key from file and allocates new public key.  Returns TRUE
  *    if loading was successful.
  *
  ***/
-bool silc_pkcs_load_public_key(char *filename, SilcPublicKey *public_key,
+bool silc_pkcs_load_public_key(const char *filename, SilcPublicKey *public_key,
                               SilcUInt32 encoding);
 
 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_load_private_key
  *
  * SYNOPSIS
  *
- *    bool silc_pkcs_load_private_key(char *filename,
+ *    bool silc_pkcs_load_private_key(const char *filename,
  *                                    SilcPrivateKey *private_key,
  *                                    unsigned char *passphrase,
  *                                    SilcUInt32 passphrase_len,
@@ -945,14 +947,15 @@ bool silc_pkcs_load_public_key(char *filename, SilcPublicKey *public_key,
  *
  * DESCRIPTION
  *
- *    Load private key from file and allocates new private key. Returns TRUE
- *    if loading was successful. The `passphrase' is used as decryption
+ *    Loads private key from file and allocates new private key.  Returns TRUE
+ *    if loading was successful.  The `passphrase' is used as decryption
  *    key of the private key file.
  *
  ***/
-bool silc_pkcs_load_private_key(char *filename, SilcPrivateKey *private_key,
+bool silc_pkcs_load_private_key(const char *filename,
+                               SilcPrivateKey *private_key,
                                unsigned char *passphrase,
                                SilcUInt32 passphrase_len,
                                SilcUInt32 encoding);
 
-#endif /* SILCPKCS_H */
+#endif /* !SILCPKCS_H */
diff --git a/lib/silccrypt/tests/Makefile.am b/lib/silccrypt/tests/Makefile.am
new file mode 100644 (file)
index 0000000..e2aa131
--- /dev/null
@@ -0,0 +1,38 @@
+#
+#  Makefile.am
+#
+#  Author: Pekka Riikonen <priikone@silcnet.org>
+#
+#  Copyright (C) 2002 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
+#  the Free Software Foundation; version 2 of the License.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+
+AUTOMAKE_OPTIONS = 1.0 no-dependencies foreign
+
+bin_PROGRAMS =         test_sha1       \
+               test_md5        \
+               test_hmacsha1   \
+               test_hmacmd5    \
+               test_aes        \
+               test_twofish
+
+test_sha1_SOURCES = test_sha1.c
+test_md5_SOURCES = test_md5.c
+test_hmacsha1_SOURCES = test_hmacsha1.c
+test_hmacmd5_SOURCES = test_hmacmd5.c
+
+test_aes_SOURCES = test_aes.c
+test_twofish_SOURCES = test_aes.c
+
+LIBS = $(SILC_COMMON_LIBS)
+LDADD = -L.. -L../.. -lsilc
+
+include $(top_srcdir)/Makefile.defines.in
diff --git a/lib/silccrypt/tests/inst_aes b/lib/silccrypt/tests/inst_aes
deleted file mode 100644 (file)
index e68d762..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-gcc -I.. \
--I../../../includes -I../../silccore -I../../trq -I../../silcske \
--I../.. -I../../silccore -I../../silcmath -I../../silcutil \
--I../../silcmath/mpi -I../../silcske -I../../silcsim \
--I../../silcsftp -Wall -finline-functions \
--o test_aes test_aes.c -L../.. -lsilc
-
diff --git a/lib/silccrypt/tests/inst_twofish b/lib/silccrypt/tests/inst_twofish
deleted file mode 100644 (file)
index 5e03534..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-gcc -I.. \
--I../../../includes -I../../silccore -I../../trq -I../../silcske \
--I../.. -I../../silccore -I../../silcmath -I../../silcutil \
--I../../silcmath/gmp -I../../silcske -I../../silcsim \
--Wall -finline-functions \
--o test_twofish test_twofish.c -L../.. -lsilc
-
diff --git a/lib/silccrypt/tests/test_hmacmd5.c b/lib/silccrypt/tests/test_hmacmd5.c
new file mode 100644 (file)
index 0000000..94f7795
--- /dev/null
@@ -0,0 +1,124 @@
+#include "silcincludes.h"
+
+/* Test vectors from RFC 2202 */
+
+/* First test vector */
+const unsigned char key1[] = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
+int key1_len = 16;
+const unsigned char data1[] = "Hi There";
+const unsigned char data1_digest[] = "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d";
+
+/* Second test vector */
+const unsigned char key2[] = "Jefe";
+int key2_len = 4;
+const unsigned char data2[] = "what do ya want for nothing?";
+const unsigned char data2_digest[] = "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38";
+
+/* Third test vector, data 0xdd repeated 50 times */
+const unsigned char key3[] = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa";
+int key3_len = 16;
+unsigned char data3[50];
+const unsigned char data3_digest[] = "\x56\xbe\x34\x52\x1d\x14\x4c\x88\xdb\xb8\xc7\x33\xf0\xe8\xb3\xf6";
+
+/* Fourth test vector, key 0xaa 80 times */
+unsigned char key4[80];
+int key4_len = 80;
+const unsigned char data4[] = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data";
+const unsigned char data4_digest[] = "\x6f\x63\x0f\xad\x67\xcd\xa0\xee\x1f\xb1\xf5\x62\xdb\x3a\xa5\x3e";
+
+int main(int argc, char **argv)
+{
+  bool success = FALSE;
+  unsigned char digest[16];
+  SilcUInt32 len;
+  SilcHmac hmac;
+  
+  if (argc > 1 && !strcmp(argv[1], "-d")) {
+    silc_debug = 1;
+    silc_debug_hexdump = 1;
+    silc_log_set_debug_string("*crypt*,*hash*,*md5*,*hmac*");
+  }
+
+  SILC_LOG_DEBUG(("Registering builtin hash functions"));
+  silc_hash_register_default();
+  silc_hmac_register_default();
+
+  SILC_LOG_DEBUG(("Allocating md5 HMAC"));
+  if (!silc_hmac_alloc("hmac-md5", NULL, &hmac)) {
+    SILC_LOG_DEBUG(("Allocating md5 HMAC failed"));
+    goto err;
+  }
+
+  /* First test vector */
+  SILC_LOG_DEBUG(("First test vector"));
+  silc_hmac_init_with_key(hmac, key1, key1_len);
+  silc_hmac_update(hmac, data1, strlen(data1));
+  silc_hmac_final(hmac, digest, &len);
+  SILC_LOG_HEXDUMP(("Key"), (unsigned char *)key1, key1_len);
+  SILC_LOG_HEXDUMP(("Message"), (unsigned char *)data1, strlen(data1));
+  SILC_LOG_HEXDUMP(("Digest"), digest, len);
+  SILC_LOG_HEXDUMP(("Expected digest"), (unsigned char *)data1_digest, len);
+  if (memcmp(digest, data1_digest, len)) {
+    SILC_LOG_DEBUG(("HMAC failed"));
+    goto err;
+  }
+  SILC_LOG_DEBUG(("HMAC is successful"));
+  
+  /* Second test vector */
+  SILC_LOG_DEBUG(("Second test vector"));
+  silc_hmac_init_with_key(hmac, key2, key2_len);
+  silc_hmac_update(hmac, data2, strlen(data2));
+  silc_hmac_final(hmac, digest, &len);
+  SILC_LOG_HEXDUMP(("Key"), (unsigned char *)key2, key2_len);
+  SILC_LOG_HEXDUMP(("Message"), (unsigned char *)data2, strlen(data2));
+  SILC_LOG_HEXDUMP(("Digest"), digest, len);
+  SILC_LOG_HEXDUMP(("Expected digest"), (unsigned char *)data2_digest, len);
+  if (memcmp(digest, data2_digest, len)) {
+    SILC_LOG_DEBUG(("HMAC failed"));
+    goto err;
+  }
+  SILC_LOG_DEBUG(("HMAC is successful"));
+  
+  /* Third test vector */
+  SILC_LOG_DEBUG(("Third test vector"));
+  silc_hmac_init_with_key(hmac, key3, key3_len);
+  memset(data3, '\xdd', sizeof(data3));
+  silc_hmac_update(hmac, data3, sizeof(data3));
+  silc_hmac_final(hmac, digest, &len);
+  SILC_LOG_HEXDUMP(("Key"), (unsigned char *)key3, key3_len);
+  SILC_LOG_HEXDUMP(("Message"), (unsigned char *)data3, sizeof(data3));
+  SILC_LOG_HEXDUMP(("Digest"), digest, len);
+  SILC_LOG_HEXDUMP(("Expected digest"), (unsigned char *)data3_digest, len);
+  if (memcmp(digest, data3_digest, len)) {
+    SILC_LOG_DEBUG(("HMAC failed"));
+    goto err;
+  }
+  SILC_LOG_DEBUG(("HMAC is successful"));
+  
+  /* Fourth test vector */
+  SILC_LOG_DEBUG(("Fourth test vector"));
+  memset(key4, '\xaa', key4_len);
+  silc_hmac_init_with_key(hmac, key4, key4_len);
+  silc_hmac_update(hmac, data4, strlen(data4));
+  silc_hmac_final(hmac, digest, &len);
+  SILC_LOG_HEXDUMP(("Key"), (unsigned char *)key4, key4_len);
+  SILC_LOG_HEXDUMP(("Message"), (unsigned char *)data4, sizeof(data4));
+  SILC_LOG_HEXDUMP(("Digest"), digest, len);
+  SILC_LOG_HEXDUMP(("Expected digest"), (unsigned char *)data4_digest, len);
+  if (memcmp(digest, data4_digest, len)) {
+    SILC_LOG_DEBUG(("HMAC failed"));
+    goto err;
+  }
+  SILC_LOG_DEBUG(("HMAC is successful"));
+  
+  success = TRUE;
+  
+ err:
+  SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE"));
+  fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE");
+
+  silc_hmac_free(hmac);
+  silc_hash_unregister_all();
+  silc_hmac_unregister_all();
+  return success;
+}
diff --git a/lib/silccrypt/tests/test_hmacsha1.c b/lib/silccrypt/tests/test_hmacsha1.c
new file mode 100644 (file)
index 0000000..a5a67b6
--- /dev/null
@@ -0,0 +1,124 @@
+#include "silcincludes.h"
+
+/* Test vectors from RFC 2202 */
+
+/* First test vector */
+const unsigned char key1[] = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
+int key1_len = 20;
+const unsigned char data1[] = "Hi There";
+const unsigned char data1_digest[] = "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e\xf1\x46\xbe\x00";
+
+/* Second test vector */
+const unsigned char key2[] = "Jefe";
+int key2_len = 4;
+const unsigned char data2[] = "what do ya want for nothing?";
+const unsigned char data2_digest[] = "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79";
+
+/* Third test vector, data 0xdd repeated 50 times */
+const unsigned char key3[] = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa";
+int key3_len = 20;
+unsigned char data3[50];
+const unsigned char data3_digest[] = "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f\x63\xf1\x75\xd3";
+
+/* Fourth test vector, key 0xaa 80 times */
+unsigned char key4[80];
+int key4_len = 80;
+const unsigned char data4[] = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data";
+const unsigned char data4_digest[] = "\xe8\xe9\x9d\x0f\x45\x23\x7d\x78\x6d\x6b\xba\xa7\x96\x5c\x78\x08\xbb\xff\x1a\x91";
+
+int main(int argc, char **argv)
+{
+  bool success = FALSE;
+  unsigned char digest[20];
+  SilcUInt32 len;
+  SilcHmac hmac;
+  
+  if (argc > 1 && !strcmp(argv[1], "-d")) {
+    silc_debug = 1;
+    silc_debug_hexdump = 1;
+    silc_log_set_debug_string("*crypt*,*hash*,*sha1*,*hmac*");
+  }
+
+  SILC_LOG_DEBUG(("Registering builtin hash functions"));
+  silc_hash_register_default();
+  silc_hmac_register_default();
+
+  SILC_LOG_DEBUG(("Allocating sha1 HMAC"));
+  if (!silc_hmac_alloc("hmac-sha1", NULL, &hmac)) {
+    SILC_LOG_DEBUG(("Allocating sha1 HMAC failed"));
+    goto err;
+  }
+
+  /* First test vector */
+  SILC_LOG_DEBUG(("First test vector"));
+  silc_hmac_init_with_key(hmac, key1, key1_len);
+  silc_hmac_update(hmac, data1, strlen(data1));
+  silc_hmac_final(hmac, digest, &len);
+  SILC_LOG_HEXDUMP(("Key"), (unsigned char *)key1, key1_len);
+  SILC_LOG_HEXDUMP(("Message"), (unsigned char *)data1, strlen(data1));
+  SILC_LOG_HEXDUMP(("Digest"), digest, len);
+  SILC_LOG_HEXDUMP(("Expected digest"), (unsigned char *)data1_digest, len);
+  if (memcmp(digest, data1_digest, len)) {
+    SILC_LOG_DEBUG(("HMAC failed"));
+    goto err;
+  }
+  SILC_LOG_DEBUG(("HMAC is successful"));
+  
+  /* Second test vector */
+  SILC_LOG_DEBUG(("Second test vector"));
+  silc_hmac_init_with_key(hmac, key2, key2_len);
+  silc_hmac_update(hmac, data2, strlen(data2));
+  silc_hmac_final(hmac, digest, &len);
+  SILC_LOG_HEXDUMP(("Key"), (unsigned char *)key2, key2_len);
+  SILC_LOG_HEXDUMP(("Message"), (unsigned char *)data2, strlen(data2));
+  SILC_LOG_HEXDUMP(("Digest"), digest, len);
+  SILC_LOG_HEXDUMP(("Expected digest"), (unsigned char *)data2_digest, len);
+  if (memcmp(digest, data2_digest, len)) {
+    SILC_LOG_DEBUG(("HMAC failed"));
+    goto err;
+  }
+  SILC_LOG_DEBUG(("HMAC is successful"));
+  
+  /* Third test vector */
+  SILC_LOG_DEBUG(("Third test vector"));
+  silc_hmac_init_with_key(hmac, key3, key3_len);
+  memset(data3, '\xdd', sizeof(data3));
+  silc_hmac_update(hmac, data3, sizeof(data3));
+  silc_hmac_final(hmac, digest, &len);
+  SILC_LOG_HEXDUMP(("Key"), (unsigned char *)key3, key3_len);
+  SILC_LOG_HEXDUMP(("Message"), (unsigned char *)data3, sizeof(data3));
+  SILC_LOG_HEXDUMP(("Digest"), digest, len);
+  SILC_LOG_HEXDUMP(("Expected digest"), (unsigned char *)data3_digest, len);
+  if (memcmp(digest, data3_digest, len)) {
+    SILC_LOG_DEBUG(("HMAC failed"));
+    goto err;
+  }
+  SILC_LOG_DEBUG(("HMAC is successful"));
+  
+  /* Fourth test vector */
+  SILC_LOG_DEBUG(("Fourth test vector"));
+  memset(key4, '\xaa', key4_len);
+  silc_hmac_init_with_key(hmac, key4, key4_len);
+  silc_hmac_update(hmac, data4, strlen(data4));
+  silc_hmac_final(hmac, digest, &len);
+  SILC_LOG_HEXDUMP(("Key"), (unsigned char *)key4, key4_len);
+  SILC_LOG_HEXDUMP(("Message"), (unsigned char *)data4, sizeof(data4));
+  SILC_LOG_HEXDUMP(("Digest"), digest, len);
+  SILC_LOG_HEXDUMP(("Expected digest"), (unsigned char *)data4_digest, len);
+  if (memcmp(digest, data4_digest, len)) {
+    SILC_LOG_DEBUG(("HMAC failed"));
+    goto err;
+  }
+  SILC_LOG_DEBUG(("HMAC is successful"));
+  
+  success = TRUE;
+  
+ err:
+  SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE"));
+  fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE");
+
+  silc_hmac_free(hmac);
+  silc_hash_unregister_all();
+  silc_hmac_unregister_all();
+  return success;
+}
diff --git a/lib/silccrypt/tests/test_mars.c b/lib/silccrypt/tests/test_mars.c
deleted file mode 100644 (file)
index 78bf2ff..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "mars.h"
-
-int main()
-{
-       int i;
-       unsigned char key[256];
-       unsigned char plain[256];
-       unsigned char plain2[256];
-       unsigned char cipher[256];
-       unsigned char iv[256];
-
-       memset(&key, 0, sizeof(key));
-       memset(&plain, 0, sizeof(plain));
-       memset(&plain2, 0, sizeof(plain2));
-       memset(&cipher, 0, sizeof(cipher));
-       memset(&iv, 0, sizeof(iv));
-
-       fprintf(stderr, "\nKey:\n");
-       for (i = 0; i < (sizeof(key) / 2); i += 2) {
-               fprintf(stderr, "%02x%02x ", key[i], key[i+1]);
-       }
-
-       fprintf(stderr, "\nSetting key\n");
-       silc_mars_init(NULL, key, 128);
-
-       fprintf(stderr, "\nPlaintext:\n");
-       for (i = 0; i < (sizeof(plain) / 2); i += 2) {
-               plain[i] = i;
-               plain[i+1] = i+1;
-               fprintf(stderr, "%02x%02x ", plain[i], plain[i+1]);
-       }
-
-       fprintf(stderr, "\n\nEncrypting\n");
-       silc_mars_encrypt_cbc(NULL, plain, cipher, 256, iv);
-
-       fprintf(stderr, "Ciphertext:\n");
-       for (i = 0; i < (sizeof(cipher)/2); i += 2) {
-               fprintf(stderr, "%02x", cipher[i]);
-               fprintf(stderr, "%02x ", cipher[i+1]);
-       }
-
-       fprintf(stderr, "\n\nDecrypting\n");
-       silc_mars_decrypt_cbc(NULL, cipher, plain2, 256, iv);
-
-       fprintf(stderr, "Decryptedtext:\n");
-       for (i = 0; i < (sizeof(plain2)/2); i += 2) {
-               fprintf(stderr, "%02x", plain2[i]);
-               fprintf(stderr, "%02x ", plain2[i+1]);
-       }
-       fprintf(stderr, "\nDone\n");
-
-       return 0;
-}
diff --git a/lib/silccrypt/tests/test_md5.c b/lib/silccrypt/tests/test_md5.c
new file mode 100644 (file)
index 0000000..5f9ac5c
--- /dev/null
@@ -0,0 +1,92 @@
+#include "silcincludes.h"
+
+/* Test vectors from RFC 1321 */
+
+/* First test vector */
+const unsigned char data1[] = "a";
+const unsigned char data1_digest[] = "\x0c\xc1\x75\xb9\xc0\xf1\xb6\xa8\x31\xc3\x99\xe2\x69\x77\x26\x61";
+
+/* Second test vector. */
+const unsigned char data2[] = "message digest";
+const unsigned char data2_digest[] = "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61\xd0";
+
+/* Third test vector. */
+const unsigned char data3[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+const unsigned char data3_digest[] = "\xd1\x74\xab\x98\xd2\x77\xd9\xf5\xa5\x61\x1c\x2c\x9f\x41\x9d\x9f";
+
+int main(int argc, char **argv)
+{
+  bool success = FALSE;
+  unsigned char digest[16];
+  SilcHash md5;
+  
+  if (argc > 1 && !strcmp(argv[1], "-d")) {
+    silc_debug = 1;
+    silc_debug_hexdump = 1;
+    silc_log_set_debug_string("*crypt*,*hash*,*md5*");
+  }
+
+  SILC_LOG_DEBUG(("Registering builtin hash functions"));
+  silc_hash_register_default();
+
+  SILC_LOG_DEBUG(("Allocating md5 hash function"));
+  if (!silc_hash_alloc("md5", &md5)) {
+    SILC_LOG_DEBUG(("Allocating md5 hash function failed"));
+    goto err;
+  }
+
+  /* First test vector */
+  SILC_LOG_DEBUG(("First test vector"));
+  silc_hash_init(md5);
+  silc_hash_update(md5, data1, strlen(data1));
+  silc_hash_final(md5, digest);
+  SILC_LOG_HEXDUMP(("Message"), (unsigned char *)data1, strlen(data1));
+  SILC_LOG_HEXDUMP(("Digest"), digest, sizeof(digest));
+  SILC_LOG_HEXDUMP(("Expected digest"), (unsigned char *)data1_digest,
+                  sizeof(digest));
+  if (memcmp(digest, data1_digest, sizeof(digest))) {
+    SILC_LOG_DEBUG(("Hash failed"));
+    goto err;
+  }
+  SILC_LOG_DEBUG(("Hash is successful"));
+  
+  /* Second test vector */
+  SILC_LOG_DEBUG(("Second test vector"));
+  silc_hash_init(md5);
+  silc_hash_update(md5, data2, strlen(data2));
+  silc_hash_final(md5, digest);
+  SILC_LOG_HEXDUMP(("Message"), (unsigned char *)data2, strlen(data2));
+  SILC_LOG_HEXDUMP(("Digest"), digest, sizeof(digest));
+  SILC_LOG_HEXDUMP(("Expected digest"), (unsigned char *)data2_digest,
+                  sizeof(digest));
+  if (memcmp(digest, data2_digest, sizeof(digest))) {
+    SILC_LOG_DEBUG(("Hash failed"));
+    goto err;
+  }
+  SILC_LOG_DEBUG(("Hash is successful"));
+
+  /* Third test vector */
+  SILC_LOG_DEBUG(("Third test vector"));
+  silc_hash_init(md5);
+  silc_hash_update(md5, data3, strlen(data3));
+  silc_hash_final(md5, digest);
+  SILC_LOG_HEXDUMP(("Message"), (unsigned char *)data3, strlen(data3));
+  SILC_LOG_HEXDUMP(("Digest"), digest, sizeof(digest));
+  SILC_LOG_HEXDUMP(("Expected digest"), (unsigned char *)data3_digest,
+                  sizeof(digest));
+  if (memcmp(digest, data3_digest, sizeof(digest))) {
+    SILC_LOG_DEBUG(("Hash failed"));
+    goto err;
+  }
+  SILC_LOG_DEBUG(("Hash is successful"));
+
+  success = TRUE;
+  
+ err:
+  SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE"));
+  fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE");
+
+  silc_hash_free(md5);
+  silc_hash_unregister_all();
+  return success;
+}
diff --git a/lib/silccrypt/tests/test_sha1.c b/lib/silccrypt/tests/test_sha1.c
new file mode 100644 (file)
index 0000000..93efb3d
--- /dev/null
@@ -0,0 +1,76 @@
+#include "silcincludes.h"
+
+/* Test vectors from NIST secure hashing definition for SHA-1 */
+
+/* First test vector */
+const unsigned char data1[] = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
+const unsigned char data1_digest[] = "\x84\x98\x3e\x44\x1c\x3b\xd2\x6e\xba\xae\x4a\xa1\xf9\x51\x29\xe5\xe5\x46\x70\xf1";
+
+/* Second test vector. This will be allocated with 1000000 'a' characters
+   and hashed */
+char *data2 = NULL;
+const unsigned char data2_digest[] = "\x34\xaa\x97\x3c\xd4\xc4\xda\xa4\xf6\x1e\xeb\x2b\xdb\xad\x27\x31\x65\x34\x01\x6f";
+
+int main(int argc, char **argv)
+{
+  bool success = FALSE;
+  unsigned char digest[20];
+  SilcHash sha1;
+  
+  if (argc > 1 && !strcmp(argv[1], "-d")) {
+    silc_debug = 1;
+    silc_debug_hexdump = 1;
+    silc_log_set_debug_string("*crypt*,*hash*,*sha1*");
+  }
+
+  SILC_LOG_DEBUG(("Registering builtin hash functions"));
+  silc_hash_register_default();
+
+  SILC_LOG_DEBUG(("Allocating sha1 hash function"));
+  if (!silc_hash_alloc("sha1", &sha1)) {
+    SILC_LOG_DEBUG(("Allocating sha1 hash function failed"));
+    goto err;
+  }
+
+  /* First test vector */
+  SILC_LOG_DEBUG(("First test vector"));
+  silc_hash_init(sha1);
+  silc_hash_update(sha1, data1, strlen(data1));
+  silc_hash_final(sha1, digest);
+  SILC_LOG_HEXDUMP(("Message"), (unsigned char *)data1, strlen(data1));
+  SILC_LOG_HEXDUMP(("Digest"), digest, sizeof(digest));
+  SILC_LOG_HEXDUMP(("Expected digest"), (unsigned char *)data1_digest,
+                  sizeof(digest));
+  if (memcmp(digest, data1_digest, sizeof(digest))) {
+    SILC_LOG_DEBUG(("Hash failed"));
+    goto err;
+  }
+  SILC_LOG_DEBUG(("Hash is successful"));
+  
+  /* First test vector */
+  SILC_LOG_DEBUG(("Second test vector"));
+  data2 = silc_malloc(1000000);
+  memset(data2, 'a', 1000000);
+  silc_hash_init(sha1);
+  silc_hash_update(sha1, data2, 1000000);
+  silc_hash_final(sha1, digest);
+  SILC_LOG_HEXDUMP(("Digest"), digest, sizeof(digest));
+  SILC_LOG_HEXDUMP(("Expected digest"), (unsigned char *)data2_digest,
+                  sizeof(digest));
+  if (memcmp(digest, data2_digest, sizeof(digest))) {
+    SILC_LOG_DEBUG(("Hash failed"));
+    goto err;
+  }
+  SILC_LOG_DEBUG(("Hash is successful"));
+
+  success = TRUE;
+  
+ err:
+  SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE"));
+  fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE");
+
+  silc_free(data2);
+  silc_hash_free(sha1);
+  silc_hash_unregister_all();
+  return success;
+}
index ba61a1e05627b246c5d392a3963a5c5988a7561d..4dec62ac8500d3c05e8ac9cd65827e357d2b64f8 100644 (file)
@@ -29,7 +29,7 @@ noinst_LTLIBRARIES = libsilcmath.la
 if SILC_MP_NSS_MPI
 MP_SOURCE = mp_mpi.c
 if SILC_DIST_TOOLKIT
-MP_HEADER = mpi/mpi.h mpi/mplogic.h mpi/mpprime.h mpi/mpi-config.h
+MP_HEADER = mpi/mpi.h mpi/mplogic.h mpi/mpi-config.h
 else
 MP_HEADER =
 endif
index 2e982d6d6b70a502cfb4f12e886ee03f6ff68d18..dc2f5cff67e19fab735a3a158518b0e0289e298a 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2001 Pekka Riikonen
+  Copyright (C) 2001 - 2002 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
@@ -133,7 +133,8 @@ SilcSFTPPacket silc_sftp_packet_decode(SilcBuffer packet,
 SilcBuffer silc_sftp_attr_encode(SilcSFTPAttributes attr)
 {
   SilcBuffer buffer;
-  int i, ret, len = 4;
+  int i, ret;
+  SilcUInt32 len = 4;
 
   if (attr->flags & SILC_SFTP_ATTR_SIZE)
     len += 8;
@@ -152,10 +153,9 @@ SilcBuffer silc_sftp_attr_encode(SilcSFTPAttributes attr)
     }
   }
 
-  buffer = silc_buffer_alloc(len);
+  buffer = silc_buffer_alloc_size(len);
   if (!buffer)
     return NULL;
-  silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
 
   silc_buffer_format(buffer, 
                     SILC_STR_UI_INT(attr->flags), 
index f0c24d81852a67bd3e158f702853d5d0cabc1dab..d74a98ecd7ecf0170a7dbdffb6876e3048b0c7d2 100644 (file)
 
 */
 
+/* Tests:
+   silc_sftp_client_start();
+   silc_sftp_client_receive_process();
+   silc_sftp_opendir();
+   silc_sftp_readdir();
+   silc_sftp_open();
+   silc_sftp_read();
+   silc_sftp_fstat();
+   silc_sftp_lstat();
+   silc_sftp_close();
+*/
+
 #include "silcincludes.h"
 #include "silcsftp.h"
 
@@ -32,6 +44,7 @@ char *dir;
 char *file;
 bool opendir;
 SilcUInt64 offset;
+bool success = FALSE;
 
 static void sftp_name(SilcSFTP sftp, SilcSFTPStatus status,
                      const SilcSFTPName name, void *context);
@@ -40,29 +53,26 @@ static void sftp_handle(SilcSFTP sftp, SilcSFTPStatus status,
 static void sftp_data(SilcSFTP sftp, SilcSFTPStatus status,
                      const unsigned char *data, SilcUInt32 data_len,
                      void *context);
+static void end_test(void);
 
-static void send_packet(SilcSocketConnection sock,
-                       SilcBuffer packet, void *context)
+static void send_packet(SilcBuffer packet, void *context)
 {
   Client client = (Client)context;
+  SilcSocketConnection sock = client->sock;
   SilcPacketContext packetdata;
+  const SilcBufferStruct p;
   int ret;
 
   memset(&packetdata, 0, sizeof(packetdata));
   packetdata.type = SILC_PACKET_FTP;
   packetdata.truelen = packet->len + SILC_PACKET_HEADER_LEN;
-  packetdata.padlen = SILC_PACKET_PADLEN(packetdata.truelen, 0);
-  silc_packet_send_prepare(sock,
-                          SILC_PACKET_HEADER_LEN,
-                          packetdata.padlen,
-                          packet->len);
-  packetdata.buffer = sock->outbuf;
-  silc_buffer_put(sock->outbuf, packet->data, packet->len);
-  silc_packet_assemble(&packetdata, NULL);
+  SILC_PACKET_PADLEN(packetdata.truelen, 0, packetdata.padlen);
+  silc_packet_assemble(&packetdata, NULL, NULL, NULL, sock,
+                      packet->data, packet->len, (const SilcBuffer)&p);
   ret = silc_packet_send(sock, TRUE);
   if (ret != -2)
     return;
-
+  
   silc_schedule_set_listen_fd(client->schedule, sock->sock, 
                              (SILC_TASK_READ | SILC_TASK_WRITE), FALSE);
   SILC_SET_OUTBUF_PENDING(sock);
@@ -79,7 +89,7 @@ static bool packet_parse(SilcPacketParserContext *parser, void *context)
   assert(packet->type == SILC_PACKET_FTP);
 
   silc_sftp_client_receive_process(client->sftp, sock, packet);
-
+    
   return TRUE;
 }
 
@@ -91,23 +101,24 @@ SILC_TASK_CALLBACK(packet_process)
 
   if (type == SILC_TASK_WRITE) {
     if (sock->outbuf->data - sock->outbuf->head)
-     silc_buffer_push(sock->outbuf, sock->outbuf->data - sock->outbuf->head);
+      silc_buffer_push(sock->outbuf, sock->outbuf->data - sock->outbuf->head);
 
     ret = silc_packet_send(sock, TRUE);
     if (ret < 0)
       return;
-
+      
     silc_schedule_set_listen_fd(client->schedule, fd, SILC_TASK_READ, FALSE);
     SILC_UNSET_OUTBUF_PENDING(sock);
     silc_buffer_clear(sock->outbuf);
     return;
+    
   }
 
   if (type == SILC_TASK_READ) {
     ret = silc_packet_receive(sock);
     if (ret < 0)
       return;
-
+  
     if (ret == 0) {
       silc_net_close_connection(sock->sock);
       silc_socket_free(sock);
@@ -119,6 +130,70 @@ SILC_TASK_CALLBACK(packet_process)
   }
 }
 
+static void sftp_status(SilcSFTP sftp, SilcSFTPStatus status,
+                       const char *message, const char *lang_tag,
+                       void *context)
+{
+  fprintf(stderr, "Status %d\n", status);
+  if (status != SILC_SFTP_STATUS_OK) {
+    SILC_LOG_DEBUG(("Error status"));
+    success = FALSE;
+    end_test();
+    return;
+  }
+
+  success = TRUE;
+  end_test();
+}
+
+static void sftp_attr(SilcSFTP sftp, SilcSFTPStatus status,
+                     const SilcSFTPAttributes attrs, void *context)
+{
+  SilcSFTPHandle handle = (SilcSFTPHandle)context;
+  int debug = silc_debug;
+  int i;
+  
+  fprintf(stderr, "Status %d\n", status);
+  if (status != SILC_SFTP_STATUS_OK) {
+    SILC_LOG_DEBUG(("Error status"));
+    success = FALSE;
+    end_test();
+    return;
+  }
+    
+  if (!debug)
+    silc_debug = 1;
+
+  SILC_LOG_DEBUG(("Attr.flags: %d", attrs->flags));
+  SILC_LOG_DEBUG(("Attr.size: %lu", attrs->size));
+  SILC_LOG_DEBUG(("Attr.uid: %d", attrs->uid));
+  SILC_LOG_DEBUG(("Attr.gid: %d", attrs->gid));
+  SILC_LOG_DEBUG(("Attr.permissions: %d", attrs->permissions));
+  SILC_LOG_DEBUG(("Attr.atime: %d", attrs->atime));
+  SILC_LOG_DEBUG(("Attr.mtime: %d", attrs->mtime));
+  SILC_LOG_DEBUG(("Attr.extended count: %d", attrs->extended_count));
+  for (i = 0; i < attrs->extended_count; i++) {
+    SILC_LOG_HEXDUMP(("Attr.extended_type[i]:", i),
+                    attrs->extended_type[i]->data,
+                    attrs->extended_type[i]->len);
+    SILC_LOG_HEXDUMP(("Attr.extended_data[i]:", i),
+                    attrs->extended_data[i]->data,
+                    attrs->extended_data[i]->len);
+  }
+    
+  silc_debug = debug;
+
+  if (!file) {
+    fprintf(stderr, "Closing file\n"); 
+    silc_sftp_close(sftp, handle, sftp_status, context);
+    return;
+  }
+  
+  fprintf(stderr, "LStatting file %s\n", file); 
+  silc_sftp_lstat(sftp, file, sftp_attr, context);
+  file = NULL;
+}
+
 static void sftp_data(SilcSFTP sftp, SilcSFTPStatus status,
                      const unsigned char *data, SilcUInt32 data_len,
                      void *context)
@@ -131,9 +206,19 @@ static void sftp_data(SilcSFTP sftp, SilcSFTPStatus status,
 
     fprintf(stderr, "Status %d\n", status);
 
-    if (!strcmp(file, "/sftp/sftp_server.c"))
+    if (status != SILC_SFTP_STATUS_EOF) {
+      SILC_LOG_DEBUG(("Error status"));
+      success = FALSE;
+      end_test();
       return;
-
+    }
+    
+    if (!strcmp(file, "/sftp/sftp_server.c")) {
+      fprintf(stderr, "FStatting file handle %s\n", file); 
+      silc_sftp_fstat(sftp, handle, sftp_attr, context);
+      return;
+    }
+      
     /* Open another file */
     opendir = FALSE;
     memset(&attrs, 0, sizeof(attrs));
@@ -166,6 +251,13 @@ static void sftp_name(SilcSFTP sftp, SilcSFTPStatus status,
   SILC_LOG_DEBUG(("Name"));
   fprintf(stderr, "Status %d\n", status);
 
+  if (status != SILC_SFTP_STATUS_OK) {
+    SILC_LOG_DEBUG(("Error status"));
+    success = FALSE;
+    end_test();
+    return;
+  }
+  
   fprintf(stderr, "Directory: %s\n", dir);
   for (i = 0; i < name->count; i++) {
     fprintf(stderr, "%s\n", name->long_filename[i]);
@@ -202,9 +294,13 @@ static void sftp_handle(SilcSFTP sftp, SilcSFTPStatus status,
 
   SILC_LOG_DEBUG(("Handle"));
   fprintf(stderr, "Status %d\n", status);
-  if (status != SILC_SFTP_STATUS_OK)
+  if (status != SILC_SFTP_STATUS_OK) {
+    SILC_LOG_DEBUG(("Error status"));
+    success = FALSE;
+    end_test();
     return;
-
+  }
+  
   if (opendir) {
     fprintf(stderr, "Reading %s\n", dir);
     /* Readdir */
@@ -225,6 +321,12 @@ static void sftp_version(SilcSFTP sftp, SilcSFTPStatus status,
 
   SILC_LOG_DEBUG(("Version"));
   fprintf(stderr, "Status %d\n", status);
+  if (status != SILC_SFTP_STATUS_OK) {
+    SILC_LOG_DEBUG(("Error status"));
+    success = FALSE;
+    end_test();
+    return;
+  }
 
   /* opendir */
   dir = "/";
@@ -243,10 +345,10 @@ int main(int argc, char **argv)
   if (argc > 1 && !strcmp(argv[1], "-d")) {
     silc_debug = 1;
     silc_debug_hexdump = 1;
-    silc_log_set_debug_string("");
+    silc_log_set_debug_string("*sftp*");
   }
 
-  client->schedule = silc_schedule_init(100);
+  client->schedule = silc_schedule_init(100, NULL);
   if (!client->schedule)
     return -1;
 
@@ -260,9 +362,16 @@ int main(int argc, char **argv)
                         SILC_TASK_GENERIC, SILC_TASK_PRI_NORMAL);
 
   /* Start SFTP session */
-  client->sftp = silc_sftp_client_start(client->sock, send_packet, client,
+  client->sftp = silc_sftp_client_start(send_packet, client,
                                        sftp_version, client);
 
   silc_schedule(client->schedule);
   return 0;
 }
+
+static void end_test(void)
+{
+  SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE"));
+  fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE");
+  exit(success);
+}
index 61e451cccafaf45e8f5079637234528bebe23c76..29d39d6b7a8ca4423d69fb05b6357c6a9af80d69 100644 (file)
 #include "silcincludes.h"
 #include "silcsftp.h"
 
+typedef struct {
+  SilcSocketConnection sock;
+  void *server;
+} *ServerSession;
+
 typedef struct {
   SilcSchedule schedule;
   int sock;
   SilcSFTPFilesystem fs;
-  SilcSocketConnection socks[100];
+  ServerSession sessions[100];
   SilcSFTP sftp[100];
 } *Server;
 
-static void send_packet(SilcSocketConnection sock,
-                       SilcBuffer packet, void *context)
+static void send_packet(SilcBuffer packet, void *context)
 {
-  Server server = (Server)context;
+  ServerSession session = context;
+  Server server = session->server;
   SilcPacketContext packetdata;
+  const SilcBufferStruct p;
   int ret;
 
   memset(&packetdata, 0, sizeof(packetdata));
   packetdata.type = SILC_PACKET_FTP;
   packetdata.truelen = packet->len + SILC_PACKET_HEADER_LEN;
-  packetdata.padlen = SILC_PACKET_PADLEN(packetdata.truelen, 0);
-  silc_packet_send_prepare(sock,
-                          SILC_PACKET_HEADER_LEN,
-                          packetdata.padlen,
-                          packet->len);
-  packetdata.buffer = sock->outbuf;
-  silc_buffer_put(sock->outbuf, packet->data, packet->len);
-  silc_packet_assemble(&packetdata, NULL);
-  ret = silc_packet_send(sock, TRUE);
+  SILC_PACKET_PADLEN(packetdata.truelen, 0, packetdata.padlen);
+  silc_packet_assemble(&packetdata, NULL, NULL, NULL, session->sock,
+                      packet->data, packet->len, (const SilcBuffer)&p);
+  ret = silc_packet_send(session->sock, TRUE);
   if (ret != -2)
     return;
 
-  silc_schedule_set_listen_fd(server->schedule, sock->sock, 
+  silc_schedule_set_listen_fd(server->schedule, session->sock->sock, 
                              (SILC_TASK_READ | SILC_TASK_WRITE), FALSE);
-  SILC_SET_OUTBUF_PENDING(sock);
+  SILC_SET_OUTBUF_PENDING(session->sock);
 }
 
 static bool packet_parse(SilcPacketParserContext *parser, void *context)
@@ -72,12 +73,14 @@ static bool packet_parse(SilcPacketParserContext *parser, void *context)
 
 SILC_TASK_CALLBACK(packet_process)
 {
-  Server server = (Server)context;
-  SilcSocketConnection sock = server->socks[fd];
+  Server server = context;
+  ServerSession session = server->sessions[fd];
+  SilcSocketConnection sock;
   int ret;
 
-  if (!sock)
+  if (!session)
     return;
+  sock = session->sock;
 
   if (type == SILC_TASK_WRITE) {
     if (sock->outbuf->data - sock->outbuf->head)
@@ -101,7 +104,8 @@ SILC_TASK_CALLBACK(packet_process)
     if (ret == 0) {
       silc_net_close_connection(sock->sock);
       silc_schedule_unset_listen_fd(server->schedule, sock->sock);
-      server->socks[sock->sock] = NULL;
+      silc_free(server->sessions[sock->sock]);
+      server->sessions[sock->sock] = NULL;
       silc_socket_free(sock);
       return;
     }
@@ -125,9 +129,11 @@ SILC_TASK_CALLBACK(accept_connection)
   silc_net_set_socket_opt(sock, SOL_SOCKET, SO_REUSEADDR, 1);
 
   silc_socket_alloc(sock, 0, NULL, &sc);
-  server->socks[sock] = sc;
+  server->sessions[sock] = silc_calloc(1, sizeof(server->sessions[0]));
+  server->sessions[sock]->sock = sc;
+  server->sessions[sock]->server = server;
   server->sftp[sock] = 
-    silc_sftp_server_start(sc, send_packet, server,
+    silc_sftp_server_start(send_packet, server->sessions[sock],
                           server->fs);
   silc_schedule_task_add(server->schedule, sock, packet_process,
                         server, 0, 0, SILC_TASK_GENERIC,
@@ -140,8 +146,10 @@ int main()
   void *dir;
 
   silc_debug = 1;
-
-  server->schedule = silc_schedule_init(100);
+  silc_debug_hexdump = 1;
+  silc_log_set_debug_string("*sftp*");
+  
+  server->schedule = silc_schedule_init(100, NULL);
   if (!server->schedule)
     return -1;
 
index 9aa48f93871c21904dc5a9c704641bba44acefa5..3e45d3d7521ff8b513100b8bd6570ad39613957b 100644 (file)
@@ -36,7 +36,6 @@ SIM_CIPHER_OBJS = \
         blowfish.o \
         rc5.o \
         rc6.o \
-        mars.o \
         aes.o \
         rsa.o \
         twofish.o \
@@ -53,10 +52,16 @@ if SILC_SIM
 all: $(SIM_CIPHER_OBJS) $(SIM_HASH_OBJS)
 endif
 
+if SILC_LIBTOOLFIX
+LTFLAGS = --libtool-enable-shared
+else
+LTFLAGS =
+endif
+
 $(SIM_CIPHER_OBJS):
        @if test '!' -f lib$*.la ; then \
          $(LIBTOOL) --mode=link $(CCLD) -rpath $(silc_modulesdir) \
-               ../silccrypt/$*.lo -o lib$*.la; \
+               ../silccrypt/$*.lo -o lib$*.la $(LTFLAGS); \
          cd $(srcdir) && $(LN_S) -f $(srcdir)/.libs/lib$*.so \
                $(srcdir)/$*.sim.so; \
        fi
@@ -64,7 +69,7 @@ $(SIM_CIPHER_OBJS):
 $(SIM_HASH_OBJS):
        @if test '!' -f lib$*.la ; then \
          $(LIBTOOL) --mode=link $(CCLD) -rpath $(silc_modulesdir) \
-               ../silccrypt/$*.lo -o lib$*.la; \
+               ../silccrypt/$*.lo -o lib$*.la $(LTFLAGS); \
          cd $(srcdir) && $(LN_S) -f $(srcdir)/.libs/lib$*.so \
                $(srcdir)/$*.sim.so; \
        fi
index 99457a804669daf43d87bffb7326d82d8fe397cc..d7fb301d5e514acfb0ff31626a026d87ee2e7313 100644 (file)
@@ -1,16 +1,15 @@
 /*
 
-  payload.c
+  payload.c 
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2000 - 2001 Pekka Riikonen
+  Copyright (C) 2000 - 2002 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
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-  
+  the Free Software Foundation; version 2 of the License.
+
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@@ -36,10 +35,9 @@ SilcSKEStatus silc_ske_payload_start_encode(SilcSKE ske,
   if (!payload)
     return SILC_SKE_STATUS_ERROR;
 
-  buf = silc_buffer_alloc(payload->len);
+  buf = silc_buffer_alloc_size(payload->len);
   if (!buf)
     return SILC_SKE_STATUS_OUT_OF_MEMORY;
-  silc_buffer_pull_tail(buf, SILC_BUFFER_END(buf));
 
   /* Encode the payload */
   ret = silc_buffer_format(buf,
@@ -135,7 +133,6 @@ silc_ske_payload_start_decode(SilcSKE ske,
   }
 
   if (tmp != 0) {
-    SILC_LOG_DEBUG(("Bad reserved field"));
     SILC_LOG_ERROR(("Bad RESERVED field in KE Start Payload"));
     status = SILC_SKE_STATUS_BAD_RESERVED_FIELD;
     goto err;
@@ -215,11 +212,10 @@ SilcSKEStatus silc_ske_payload_ke_encode(SilcSKE ske,
 
   /* Allocate channel payload buffer. The length of the buffer
      is 4 + public key + 2 + x + 2 + signature. */
-  buf = silc_buffer_alloc(4 + payload->pk_len + 2 + x_len + 
-                         2 + payload->sign_len);
+  buf = silc_buffer_alloc_size(4 + payload->pk_len + 2 + x_len + 
+                              2 + payload->sign_len);
   if (!buf)
     return SILC_SKE_STATUS_OUT_OF_MEMORY;
-  silc_buffer_pull_tail(buf, SILC_BUFFER_END(buf));
 
   /* Encode the payload */
   ret = silc_buffer_format(buf, 
index 4fd34f780c840b044f56b68d95f36f7f02c30774..2fd4e0107ea646bea7f2fe87dabc7d29830a80a6 100644 (file)
@@ -111,6 +111,8 @@ void silc_ske_free(SilcSKE ske)
     }
     silc_free(ske->hash);
     silc_free(ske->callbacks);
+
+    memset(ske, 'F', sizeof(*ske));
     silc_free(ske);
   }
 }
@@ -389,6 +391,7 @@ SilcSKEStatus silc_ske_initiator_phase_2(SilcSKE ske,
       silc_free(x);
       silc_mp_uninit(&payload->x);
       silc_free(payload);
+      ske->ke1_payload = NULL;
       ske->status = SILC_SKE_STATUS_OK;
       return ske->status;
     }
@@ -398,7 +401,7 @@ SilcSKEStatus silc_ske_initiator_phase_2(SilcSKE ske,
 
   /* Compute signature data if we are doing mutual authentication */
   if (private_key && ske->start_payload->flags & SILC_SKE_SP_FLAG_MUTUAL) {
-    unsigned char hash[32], sign[2048];
+    unsigned char hash[32], sign[2048 + 1];
     SilcUInt32 hash_len, sign_len;
 
     SILC_LOG_DEBUG(("We are doing mutual authentication"));
@@ -420,6 +423,7 @@ SilcSKEStatus silc_ske_initiator_phase_2(SilcSKE ske,
       silc_mp_uninit(&payload->x);
       silc_free(payload->pk_data);
       silc_free(payload);
+      ske->ke1_payload = NULL;
       ske->status = SILC_SKE_STATUS_SIGNATURE_ERROR;
       return ske->status;
     }
@@ -435,7 +439,9 @@ SilcSKEStatus silc_ske_initiator_phase_2(SilcSKE ske,
     silc_free(x);
     silc_mp_uninit(&payload->x);
     silc_free(payload->pk_data);
+    silc_free(payload->sign_data);
     silc_free(payload);
+    ske->ke1_payload = NULL;
     ske->status = status;
     return status;
   }
@@ -1016,7 +1022,7 @@ SilcSKEStatus silc_ske_responder_finish(SilcSKE ske,
   SilcSKEStatus status = SILC_SKE_STATUS_OK;
   SilcBuffer payload_buf;
   SilcMPInt *KEY;
-  unsigned char hash[32], sign[2048], *pk;
+  unsigned char hash[32], sign[2048 + 1], *pk;
   SilcUInt32 hash_len, sign_len, pk_len;
 
   SILC_LOG_DEBUG(("Start"));
@@ -1181,7 +1187,7 @@ silc_ske_assemble_security_properties(SilcSKE ske,
   /* Set random cookie */
   rp->cookie = silc_calloc(SILC_SKE_COOKIE_LEN, sizeof(*rp->cookie));
   for (i = 0; i < SILC_SKE_COOKIE_LEN; i++)
-    rp->cookie[i] = silc_rng_get_byte(ske->rng);
+    rp->cookie[i] = silc_rng_get_byte_fast(ske->rng);
   rp->cookie_len = SILC_SKE_COOKIE_LEN;
 
   /* Put version */
@@ -1210,8 +1216,8 @@ silc_ske_assemble_security_properties(SilcSKE ske,
 
   /* XXX */
   /* Get supported compression algorithms */
-  rp->comp_alg_list = strdup("");
-  rp->comp_alg_len = 0;
+  rp->comp_alg_list = strdup("none");
+  rp->comp_alg_len = strlen("none");
 
   rp->len = 1 + 1 + 2 + SILC_SKE_COOKIE_LEN + 
     2 + rp->version_len +
@@ -1537,9 +1543,8 @@ silc_ske_select_security_properties(SilcSKE ske,
     payload->hmac_alg_list = strdup(rp->hmac_alg_list);
   }
 
-#if 0
   /* Get supported compression algorithms */
-  cp = rp->hash_alg_list;
+  cp = rp->comp_alg_list;
   if (cp && strchr(cp, ',')) {
     while(cp) {
       char *item;
@@ -1548,15 +1553,23 @@ silc_ske_select_security_properties(SilcSKE ske,
       item = silc_calloc(len + 1, sizeof(char));
       memcpy(item, cp, len);
 
-      SILC_LOG_DEBUG(("Proposed hash alg `%s'", item));
+      SILC_LOG_DEBUG(("Proposed Compression `%s'", item));
 
-      if (silc_hash_is_supported(item) == TRUE) {
-       SILC_LOG_DEBUG(("Found hash alg `%s'", item));
-
-       payload->hash_alg_len = len;
-       payload->hash_alg_list = item;
+#if 1
+      if (!strcmp(item, "none")) {
+       SILC_LOG_DEBUG(("Found Compression `%s'", item));
+       payload->comp_alg_len = len;
+       payload->comp_alg_list = item;
+       break;
+      }
+#else
+      if (silc_hmac_is_supported(item) == TRUE) {
+       SILC_LOG_DEBUG(("Found Compression `%s'", item));
+       payload->comp_alg_len = len;
+       payload->comp_alg_list = item;
        break;
       }
+#endif
 
       cp += len;
       if (strlen(cp) == 0)
@@ -1567,20 +1580,7 @@ silc_ske_select_security_properties(SilcSKE ske,
       if (item)
        silc_free(item);
     }
-
-    if (!payload->hash_alg_len && !payload->hash_alg_list) {
-      SILC_LOG_DEBUG(("Could not find supported hash alg"));
-      silc_ske_abort(ske, SILC_SKE_STATUS_UNKNOWN_HASH_FUNCTION);
-      silc_free(payload->ke_grp_list);
-      silc_free(payload->pkcs_alg_list);
-      silc_free(payload->enc_alg_list);
-      silc_free(payload);
-      return;
-    }
-  } else {
-
   }
-#endif
 
   payload->len = 1 + 1 + 2 + SILC_SKE_COOKIE_LEN + 
     2 + payload->version_len + 
@@ -1600,16 +1600,22 @@ static SilcSKEStatus silc_ske_create_rnd(SilcSKE ske, SilcMPInt *n,
 {
   SilcSKEStatus status = SILC_SKE_STATUS_OK;
   unsigned char *string;
+  SilcUInt32 l;
+
+  if (!len)
+    return SILC_SKE_STATUS_ERROR;
 
   SILC_LOG_DEBUG(("Creating random number"));
 
+  l = ((len - 1) / 8);
+
   /* Get the random number as string */
-  string = silc_rng_get_rn_data(ske->rng, ((len - 1) / 8));
+  string = silc_rng_get_rn_data(ske->rng, l);
   if (!string)
     return SILC_SKE_STATUS_OUT_OF_MEMORY;
 
   /* Decode the string into a MP integer */
-  silc_mp_bin2mp(string, ((len - 1) / 8), rnd);
+  silc_mp_bin2mp(string, l, rnd);
   silc_mp_mod_2exp(rnd, rnd, len);
 
   /* Checks */
@@ -1618,7 +1624,7 @@ static SilcSKEStatus silc_ske_create_rnd(SilcSKE ske, SilcMPInt *n,
   if (silc_mp_cmp(rnd, n) >= 0)
     status = SILC_SKE_STATUS_ERROR;
 
-  memset(string, 'F', (len / 8));
+  memset(string, 'F', l);
   silc_free(string);
 
   return status;
index c323a631fca987bd000f61cb80ef75e9473c8292..4fffb7c34d87b7144f9007c921453c97b9e2dfe0 100644 (file)
 
 #include "silcincludes.h"
 
-/* Macro to check whether there is enough free space to add the
+/* Macros to check whether there is enough free space to add the
    required amount of data. For unformatting this means that there must
    be the data that is to be extracted. */
-#define MY_HAS_SPACE(__x__, __req__)           \
+#define FORMAT_HAS_SPACE(__x__, __req__)       \
   do {                                         \
     if (__req__ > (__x__)->len)                        \
       goto fail;                               \
   } while(0)
+#define UNFORMAT_HAS_SPACE(__x__, __req__)     \
+  do {                                         \
+    if (__req__ > (__x__)->len)                        \
+      goto fail;                               \
+    if ((__req__ + 1) <= 0)                    \
+      goto fail;                               \
+  } while(0)
 
 /* Formats the arguments sent and puts them into the buffer sent as
    argument. The buffer must be initialized beforehand and it must have
@@ -63,7 +70,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
     case SILC_BUFFER_PARAM_SI8_CHAR:
       {
        char x = (char)va_arg(ap, int);
-       MY_HAS_SPACE(dst, 1);
+       FORMAT_HAS_SPACE(dst, 1);
        silc_buffer_put(dst, &x, 1);
        silc_buffer_pull(dst, 1);
        break;
@@ -71,7 +78,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
     case SILC_BUFFER_PARAM_UI8_CHAR:
       {
        unsigned char x = (unsigned char)va_arg(ap, int);
-       MY_HAS_SPACE(dst, 1);
+       FORMAT_HAS_SPACE(dst, 1);
        silc_buffer_put(dst, &x, 1);
        silc_buffer_pull(dst, 1);
        break;
@@ -80,7 +87,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char xf[2];
        SilcInt16 x = (SilcInt16)va_arg(ap, int);
-       MY_HAS_SPACE(dst, 2);
+       FORMAT_HAS_SPACE(dst, 2);
        SILC_PUT16_MSB(x, xf);
        silc_buffer_put(dst, xf, 2);
        silc_buffer_pull(dst, 2);
@@ -90,7 +97,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char xf[2];
        SilcUInt16 x = (SilcUInt16)va_arg(ap, int);
-       MY_HAS_SPACE(dst, 2);
+       FORMAT_HAS_SPACE(dst, 2);
        SILC_PUT16_MSB(x, xf);
        silc_buffer_put(dst, xf, 2);
        silc_buffer_pull(dst, 2);
@@ -100,7 +107,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char xf[4];
        SilcInt32 x = va_arg(ap, SilcInt32);
-       MY_HAS_SPACE(dst, 4);
+       FORMAT_HAS_SPACE(dst, 4);
        SILC_PUT32_MSB(x, xf);
        silc_buffer_put(dst, xf, 4);
        silc_buffer_pull(dst, 4);
@@ -110,7 +117,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char xf[4];
        SilcUInt32 x = va_arg(ap, SilcUInt32);
-       MY_HAS_SPACE(dst, 4);
+       FORMAT_HAS_SPACE(dst, 4);
        SILC_PUT32_MSB(x, xf);
        silc_buffer_put(dst, xf, 4);
        silc_buffer_pull(dst, 4);
@@ -120,7 +127,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char xf[8];
        SilcInt64 x = va_arg(ap, SilcInt64);
-       MY_HAS_SPACE(dst, sizeof(SilcInt64));
+       FORMAT_HAS_SPACE(dst, sizeof(SilcInt64));
        SILC_PUT64_MSB(x, xf);
        silc_buffer_put(dst, xf, sizeof(SilcInt64));
        silc_buffer_pull(dst, sizeof(SilcInt64));
@@ -130,7 +137,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char xf[8];
        SilcUInt64 x = va_arg(ap, SilcUInt64);
-       MY_HAS_SPACE(dst, sizeof(SilcUInt64));
+       FORMAT_HAS_SPACE(dst, sizeof(SilcUInt64));
        SILC_PUT64_MSB(x, xf);
        silc_buffer_put(dst, xf, sizeof(SilcUInt64));
        silc_buffer_pull(dst, sizeof(SilcUInt64));
@@ -145,7 +152,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char *x = va_arg(ap, unsigned char *);
        SilcUInt32 tmp_len = strlen(x);
-       MY_HAS_SPACE(dst, tmp_len);
+       FORMAT_HAS_SPACE(dst, tmp_len);
        silc_buffer_put(dst, x, tmp_len);
        silc_buffer_pull(dst, tmp_len);
        break;
@@ -162,7 +169,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
        unsigned char *x = va_arg(ap, unsigned char *);
        SilcUInt32 len = va_arg(ap, SilcUInt32);
        if (x && len) {
-         MY_HAS_SPACE(dst, len);
+         FORMAT_HAS_SPACE(dst, len);
          silc_buffer_put(dst, x, len);
          silc_buffer_pull(dst, len);
        }
@@ -223,7 +230,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
     case SILC_BUFFER_PARAM_SI8_CHAR:
       {
        char *x = va_arg(ap, char *);
-       MY_HAS_SPACE(src, 1);
+       UNFORMAT_HAS_SPACE(src, 1);
        if (x)
          *x = src->data[0];
        silc_buffer_pull(src, 1);
@@ -232,7 +239,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
     case SILC_BUFFER_PARAM_UI8_CHAR:
       {
        unsigned char *x = va_arg(ap, unsigned char *);
-       MY_HAS_SPACE(src, 1);
+       UNFORMAT_HAS_SPACE(src, 1);
        if (x)
          *x = src->data[0];
        silc_buffer_pull(src, 1);
@@ -241,7 +248,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
     case SILC_BUFFER_PARAM_SI16_SHORT:
       {
        SilcInt16 *x = va_arg(ap, SilcInt16 *);
-       MY_HAS_SPACE(src, 2);
+       UNFORMAT_HAS_SPACE(src, 2);
        if (x)
          SILC_GET16_MSB(*x, src->data);
        silc_buffer_pull(src, 2);
@@ -250,7 +257,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
     case SILC_BUFFER_PARAM_UI16_SHORT:
       {
        SilcUInt16 *x = va_arg(ap, SilcUInt16 *);
-       MY_HAS_SPACE(src, 2);
+       UNFORMAT_HAS_SPACE(src, 2);
        if (x)
          SILC_GET16_MSB(*x, src->data);
        silc_buffer_pull(src, 2);
@@ -259,7 +266,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
     case SILC_BUFFER_PARAM_SI32_INT:
       {
        SilcInt32 *x = va_arg(ap, SilcInt32 *);
-       MY_HAS_SPACE(src, 4);
+       UNFORMAT_HAS_SPACE(src, 4);
        if (x)
          SILC_GET32_MSB(*x, src->data);
        silc_buffer_pull(src, 4);
@@ -268,7 +275,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
     case SILC_BUFFER_PARAM_UI32_INT:
       {
        SilcUInt32 *x = va_arg(ap, SilcUInt32 *);
-       MY_HAS_SPACE(src, 4);
+       UNFORMAT_HAS_SPACE(src, 4);
        if (x)
          SILC_GET32_MSB(*x, src->data);
        silc_buffer_pull(src, 4);
@@ -277,7 +284,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
     case SILC_BUFFER_PARAM_SI64_INT:
       {
        SilcInt64 *x = va_arg(ap, SilcInt64 *);
-       MY_HAS_SPACE(src, sizeof(SilcInt64));
+       UNFORMAT_HAS_SPACE(src, sizeof(SilcInt64));
        if (x)
          SILC_GET64_MSB(*x, src->data);
        silc_buffer_pull(src, sizeof(SilcInt64));
@@ -286,7 +293,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
     case SILC_BUFFER_PARAM_UI64_INT:
       {
        SilcUInt64 *x = va_arg(ap, SilcUInt64 *);
-       MY_HAS_SPACE(src, sizeof(SilcUInt64));
+       UNFORMAT_HAS_SPACE(src, sizeof(SilcUInt64));
        if (x)
          SILC_GET64_MSB(*x, src->data);
        silc_buffer_pull(src, sizeof(SilcUInt64));
@@ -296,10 +303,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
       {
        SilcUInt8 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
-       MY_HAS_SPACE(src, 1);
+       UNFORMAT_HAS_SPACE(src, 1);
        len2 = (SilcUInt8)src->data[0];
        silc_buffer_pull(src, 1);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (x)
          *x = src->data;
        silc_buffer_pull(src, len2);
@@ -309,10 +316,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
       {
        SilcUInt16 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
-       MY_HAS_SPACE(src, 2);
+       UNFORMAT_HAS_SPACE(src, 2);
        SILC_GET16_MSB(len2, src->data);
        silc_buffer_pull(src, 2);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (x)
          *x = src->data;
        silc_buffer_pull(src, len2);
@@ -322,10 +329,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
       {
        SilcUInt8 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
-       MY_HAS_SPACE(src, 1);
+       UNFORMAT_HAS_SPACE(src, 1);
        len2 = (SilcUInt8)src->data[0];
        silc_buffer_pull(src, 1);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (x && len2) {
          *x = silc_calloc(len2 + 1, sizeof(unsigned char));
          memcpy(*x, src->data, len2);
@@ -337,10 +344,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
       {
        SilcUInt16 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
-       MY_HAS_SPACE(src, 2);
+       UNFORMAT_HAS_SPACE(src, 2);
        SILC_GET16_MSB(len2, src->data);
        silc_buffer_pull(src, 2);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (x && len2) {
          *x = silc_calloc(len2 + 1, sizeof(unsigned char));
          memcpy(*x, src->data, len2);
@@ -352,10 +359,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
       {
        SilcUInt32 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
-       MY_HAS_SPACE(src, 4);
+       UNFORMAT_HAS_SPACE(src, 4);
        SILC_GET32_MSB(len2, src->data);
        silc_buffer_pull(src, 4);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (x)
          *x = src->data;
        silc_buffer_pull(src, len2);
@@ -365,10 +372,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
       {
        SilcUInt32 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
-       MY_HAS_SPACE(src, 4);
+       UNFORMAT_HAS_SPACE(src, 4);
        SILC_GET32_MSB(len2, src->data);
        silc_buffer_pull(src, 4);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (x && len2) {
          *x = silc_calloc(len2 + 1, sizeof(unsigned char));
          memcpy(*x, src->data, len2);
@@ -381,10 +388,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
        SilcUInt8 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
        SilcUInt8 *len = va_arg(ap, SilcUInt8 *);
-       MY_HAS_SPACE(src, 1);
+       UNFORMAT_HAS_SPACE(src, 1);
        len2 = (SilcUInt8)src->data[0];
        silc_buffer_pull(src, 1);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (len)
          *len = len2;
        if (x)
@@ -397,10 +404,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
        SilcUInt16 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
        SilcUInt16 *len = va_arg(ap, SilcUInt16 *);
-       MY_HAS_SPACE(src, 2);
+       UNFORMAT_HAS_SPACE(src, 2);
        SILC_GET16_MSB(len2, src->data);
        silc_buffer_pull(src, 2);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (len)
          *len = len2;
        if (x)
@@ -413,10 +420,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
        SilcUInt8 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
        SilcUInt8 *len = va_arg(ap, SilcUInt8 *);
-       MY_HAS_SPACE(src, 1);
+       UNFORMAT_HAS_SPACE(src, 1);
        len2 = (SilcUInt8)src->data[0];
        silc_buffer_pull(src, 1);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (len)
          *len = len2;
        if (x && len2) {
@@ -431,10 +438,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
        SilcUInt16 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
        SilcUInt16 *len = va_arg(ap, SilcUInt16 *);
-       MY_HAS_SPACE(src, 2);
+       UNFORMAT_HAS_SPACE(src, 2);
        SILC_GET16_MSB(len2, src->data);
        silc_buffer_pull(src, 2);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (len)
          *len = len2;
        if (x && len2) {
@@ -449,10 +456,10 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
        SilcUInt32 len2;
        unsigned char **x = va_arg(ap, unsigned char **);
        SilcUInt32 *len = va_arg(ap, SilcUInt32 *);
-       MY_HAS_SPACE(src, 4);
+       UNFORMAT_HAS_SPACE(src, 4);
        SILC_GET32_MSB(len2, src->data);
        silc_buffer_pull(src, 4);
-       MY_HAS_SPACE(src, len2);
+       UNFORMAT_HAS_SPACE(src, len2);
        if (len)
          *len = len2;
        if (x)
@@ -464,7 +471,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
       {
        unsigned char **x = va_arg(ap, unsigned char **);
        SilcUInt32 len = va_arg(ap, SilcUInt32);
-       MY_HAS_SPACE(src, len);
+       UNFORMAT_HAS_SPACE(src, len);
        if (len && x)
          *x = src->data;
        silc_buffer_pull(src, len);
@@ -474,7 +481,7 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
       {
        unsigned char **x = va_arg(ap, unsigned char **);
        SilcUInt32 len = va_arg(ap, SilcUInt32);
-       MY_HAS_SPACE(src, len);
+       UNFORMAT_HAS_SPACE(src, len);
        if (len && x) {
          *x = silc_calloc(len + 1, sizeof(unsigned char));
          memcpy(*x, src->data, len);
index f179dc1d03df1fa9c8d8aec63a99afe9a589e1c7..1f3e4699fdf79d20891961d4463f4b507dd69a73 100644 (file)
@@ -41,13 +41,14 @@ typedef struct SilcConfigOptionStruct {
 
 /* unique for each config file (and included ones) */
 struct SilcConfigFileObject {
-  char *filename; /* the original filename opened */
-  int level;   /* parsing level, how many nested silc_config_main we have */
-  char *base;  /* this is a fixed pointer to the base location */
-  char *p;     /* the Parser poitner */
+  char *filename;      /* the original filename opened */
+  int level;           /* parsing level, how many nested
+                          silc_config_main we have */
+  char *base;          /* this is a fixed pointer to the base location */
+  char *p;             /* the Parser poitner */
   SilcUInt32 len;      /* fixed length of the whole file */
   SilcUInt32 line;     /* current parsing line, strictly linked to p */
-  bool included; /* wether this file is main or included */
+  bool included;       /* wether this file is main or included */
 };
 
 /* We need the entity to base our block-style parsing on */
@@ -58,23 +59,23 @@ struct SilcConfigEntityObject {
 
 /* access error descriptions only with silc_config_strerror() */
 static char *errorstrs[] = {
-  "-OK",                                       /* SILC_CONFIG_OK */
-  "-SILENT",                                   /* SILC_CONFIG_ESILENT */
-  "-PRINTLINE",                                        /* SILC_CONFIG_EPRINTLINE */
-  "Invalid syntax",                            /* SILC_CONFIG_EGENERIC */
-  "Internal error! Please report this bug",    /* SILC_CONFIG_EINTERNAL */
-  "Can't open specified file",                 /* SILC_CONFIG_ECANTOPEN */
-  "Expected open-brace '{'",                   /* SILC_CONFIG_EOPENBRACE */
-  "Missing close-brace '}'",                   /* SILC_CONFIG_ECLOSEBRACE */
-  "Invalid data type",                         /* SILC_CONFIG_ETYPE */
-  "Unknown option",                            /* SILC_CONFIG_EBADOPTION */
-  "Invalid text",                              /* SILC_CONFIG_EINVALIDTEXT */
-  "Double option specification",               /* SILC_CONFIG_EDOUBLE */
-  "Expected data but not found",               /* SILC_CONFIG_EEXPECTED */
-  "Expected '='",                              /* SILC_CONFIG_EEXPECTEDEQUAL */
-  "Unexpected data",                           /* SILC_CONFIG_EUNEXPECTED */
-  "Missing mandatory fields",                  /* SILC_CONFIG_EMISSFIELDS */
-  "Missing ';'",                               /* SILC_CONFIG_EMISSCOLON */
+  "-OK",                                     /* SILC_CONFIG_OK */
+  "-SILENT",                                 /* SILC_CONFIG_ESILENT */
+  "-PRINTLINE",                                      /* SILC_CONFIG_EPRINTLINE */
+  "Invalid syntax",                          /* SILC_CONFIG_EGENERIC */
+  "Internal error! Please report this bug",   /* SILC_CONFIG_EINTERNAL */
+  "Can't open specified file",               /* SILC_CONFIG_ECANTOPEN */
+  "Expected open-brace '{'",                 /* SILC_CONFIG_EOPENBRACE */
+  "Missing close-brace '}'",                 /* SILC_CONFIG_ECLOSEBRACE */
+  "Invalid data type",                       /* SILC_CONFIG_ETYPE */
+  "Unknown option",                          /* SILC_CONFIG_EBADOPTION */
+  "Invalid text",                            /* SILC_CONFIG_EINVALIDTEXT */
+  "Double option specification",             /* SILC_CONFIG_EDOUBLE */
+  "Expected data but not found",             /* SILC_CONFIG_EEXPECTED */
+  "Expected '='",                            /* SILC_CONFIG_EEXPECTEDEQUAL */
+  "Unexpected data",                         /* SILC_CONFIG_EUNEXPECTED */
+  "Missing mandatory fields",                /* SILC_CONFIG_EMISSFIELDS */
+  "Missing ';'",                             /* SILC_CONFIG_EMISSCOLON */
 };
 
 /* return string describing SilcConfig's error code */
@@ -321,7 +322,7 @@ char *silc_config_read_line(SilcConfigFile *file, SilcUInt32 line)
 {
   register char *p;
   int len;
-  char *ret, *endbuf;
+  char *ret = NULL, *endbuf;
 
   if (!file || (line <= 0))
     return NULL;
@@ -336,7 +337,8 @@ char *silc_config_read_line(SilcConfigFile *file, SilcUInt32 line)
  found:
   if ((endbuf = strchr(p, '\n'))) {
     len = endbuf - p;
-    ret = silc_memdup(p, len);
+    if (len > 0)
+      ret = silc_memdup(p, len);
   } else {
     ret = silc_memdup(p, strlen(p));
   }
@@ -383,8 +385,9 @@ bool silc_config_register(SilcConfigEntity ent, const char *name,
                          const SilcConfigTable *subtable, void *context)
 {
   SilcConfigOption *newopt;
-  SILC_CONFIG_DEBUG(("Register new option=\"%s\" type=%u cb=0x%08x context=0x%08x",
-               name, type, (SilcUInt32) cb, (SilcUInt32) context));
+  SILC_CONFIG_DEBUG(("Register new option=\"%s\" "
+                    "type=%u cb=0x%08x context=0x%08x",
+                    name, type, (SilcUInt32) cb, (SilcUInt32) context));
 
   /* if we are registering a block, make sure there is a specified sub-table */
   if (!ent || !name || ((type == SILC_CONFIG_ARG_BLOCK) && !subtable))
@@ -469,7 +472,8 @@ static int silc_config_main_internal(SilcConfigEntity ent)
 
     /* obtain the keyword */
     my_next_token(file, buf);
-    SILC_CONFIG_DEBUG(("Looking up keyword=\"%s\" [line=%lu]", buf, file->line));
+    SILC_CONFIG_DEBUG(("Looking up keyword=\"%s\" [line=%lu]",
+                      buf, file->line));
 
     /* handle special directive */
     if (!strcasecmp(buf, "include")) {
index 7d2d14757281af64b6f1e7ae737fa72ed1cd7fe6..52112ee3903bac053bcdffd982b34faa6e2ff128 100644 (file)
@@ -65,8 +65,13 @@ int silc_file_writefile(const char *filename, const char *buffer,
                        SilcUInt32 len)
 {
   int fd;
+  int flags = O_CREAT | O_WRONLY | O_TRUNC;
 
-  if ((fd = creat(filename, 0644)) == -1) {
+#if defined(O_BINARY)
+  flags |= O_BINARY;
+#endif /* O_BINARY */
+
+  if ((fd = open(filename, flags, 0644)) == -1) {
     SILC_LOG_ERROR(("Cannot open file %s for writing: %s", filename,
                    strerror(errno)));
     return -1;
@@ -90,8 +95,13 @@ int silc_file_writefile_mode(const char *filename, const char *buffer,
                             SilcUInt32 len, int mode)
 {
   int fd;
+  int flags = O_CREAT | O_WRONLY | O_TRUNC;
+
+#if defined(O_BINARY)
+  flags |= O_BINARY;
+#endif /* O_BINARY */
 
-  if ((fd = creat(filename, mode)) == -1) {
+  if ((fd = open(filename, flags, 0644)) == -1) {
     SILC_LOG_ERROR(("Cannot open file %s for writing: %s", filename,
                    strerror(errno)));
     return -1;
index e2e455a9ec90cf214fb48a48db0860fec9243c3e..93fd8751e8334a593817bb3079004da40d829e07 100644 (file)
 
 #ifndef SILC_STACKTRACE
 
+#define SILC_MAX_ALLOC (1024 * 1024L * 1024L)
+
 void *silc_malloc(size_t size)
 {
   void *addr;
+  assert(size >= 0 && size <= SILC_MAX_ALLOC);
   addr = malloc(size);
   assert(addr != NULL);
   return addr;
@@ -33,6 +36,7 @@ void *silc_malloc(size_t size)
 void *silc_calloc(size_t items, size_t size)
 {
   void *addr;
+  assert(size * items >= 0 && size * items <= SILC_MAX_ALLOC);
   addr = calloc(items, size);
   assert(addr != NULL);
   return addr;
@@ -41,6 +45,7 @@ void *silc_calloc(size_t items, size_t size)
 void *silc_realloc(void *ptr, size_t size)
 {
   void *addr;
+  assert(size >= 0 && size <= SILC_MAX_ALLOC);
   addr = realloc(ptr, size);
   assert(addr != NULL);
   return addr;
@@ -53,7 +58,8 @@ void silc_free(void *ptr)
 
 void *silc_memdup(const void *ptr, size_t size)
 {
-  unsigned char *addr = silc_malloc(size + 1);
+  unsigned char *addr;
+  addr = silc_malloc(size + 1);
   assert(addr != NULL);
   memcpy((void *)addr, ptr, size);
   addr[size] = '\0';
index 515d3a9fc8134e92567fb407957f1c0c3cd30510..e0f658b08f52807e42fa93107a14f107155bbf59 100644 (file)
@@ -1,16 +1,15 @@
 /*
 
-  silcschedule.c
+  silcschedule.c 
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1998 - 2001 Pekka Riikonen
+  Copyright (C) 1998 - 2002 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
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-  
+  the Free Software Foundation; version 2 of the License.
+
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@@ -275,16 +274,16 @@ bool silc_schedule_uninit(SilcSchedule schedule)
     return FALSE;
 
   /* Dispatch all timeouts before going away */
+  SILC_SCHEDULE_LOCK(schedule);
   silc_mutex_lock(schedule->timeout_queue->lock);
   silc_schedule_dispatch_timeout(schedule, TRUE);
   silc_mutex_unlock(schedule->timeout_queue->lock);
+  SILC_SCHEDULE_UNLOCK(schedule);
 
   /* Deliver signals before going away */
   if (schedule->signal_tasks) {
-    SILC_SCHEDULE_UNLOCK(schedule);
     silc_schedule_internal_signals_call(schedule->internal, schedule);
     schedule->signal_tasks = FALSE;
-    SILC_SCHEDULE_LOCK(schedule);
   }
 
   /* Unregister all tasks */
@@ -343,8 +342,8 @@ void silc_schedule_stop(SilcSchedule schedule)
 static void silc_schedule_dispatch_nontimeout(SilcSchedule schedule)
 {
   SilcTask task;
-  int i, last_fd = schedule->last_fd;
-  SilcUInt32 fd;
+  int i;
+  SilcUInt32 fd, last_fd = schedule->last_fd;
 
   for (i = 0; i <= last_fd; i++) {
     if (schedule->fd_list[i].events == 0)
index 3ae1a1e8e0dbec5053f5dc2de51de5434ec9ad82..6817c5daea20f98150f7c52b3e9f4a696bc97e3e 100644 (file)
@@ -192,8 +192,8 @@ SILC_TASK_CALLBACK(silc_socket_host_lookup_finish)
      is cancelled also and we will not call the final callback. */
   if (lookup->sock->users == 1) {
     SILC_LOG_DEBUG(("Async host lookup was cancelled"));
-    silc_free(lookup);
     silc_socket_free(lookup->sock);
+    silc_free(lookup);
     return;
   }
 
index 7898a4c94f7b518f67709d45577dbf0383873339..8c9064891527f6199d346681f9d3a38cf3cb0d53 100644 (file)
@@ -657,15 +657,25 @@ char *silc_client_chmode(SilcUInt32 mode, const char *cipher, const char *hmac)
 
   if (mode & SILC_CHANNEL_MODE_SILENCE_OPERS)
     strncat(string, "M", 1);
+  
+  if (mode & SILC_CHANNEL_MODE_CIPHER)
+    strncat(string, "c", 1);
+  
+  if (mode & SILC_CHANNEL_MODE_HMAC)
+    strncat(string, "h", 1);
 
   if (mode & SILC_CHANNEL_MODE_CIPHER) {
-    if (strlen(cipher) + strlen(string) < sizeof(string))
+    if (strlen(cipher) + strlen(string) + 1< sizeof(string)) {
+      strncat(string, " ", 1);
       strncat(string, cipher, strlen(cipher));
+    }
   }
 
   if (mode & SILC_CHANNEL_MODE_HMAC) {
-    if (strlen(hmac) + strlen(string) < sizeof(string))
+    if (strlen(hmac) + strlen(string) + 1< sizeof(string)) {
+      strncat(string, " ", 1);
       strncat(string, hmac, strlen(hmac));
+    }
   }
 
   /* Rest of mode is ignored */
index 9a3429bede4c2ebc59ba23ebde0b3048e947f715..57c5b1db9434d3013ab603097fa1dfbafd241995 100644 (file)
@@ -393,7 +393,8 @@ char *silc_client_chumode_char(SilcUInt32 mode);
  *
  * DESCRIPTION
  *
- *    Creates fingerprint from data, usually used with SHA1 digests.
+ *    Return a textual representation of the fingerprint in *data, the
+ *    caller must free the returned string.
  *
  ***/
 char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
index 7f27ea1343572bce49fd312e744cd94dace003f1..a6d6fd5bd655e33ccbdf99bf51241553e31a5b4e 100644 (file)
@@ -69,9 +69,9 @@ unsigned char *silc_vcard_encode(SilcVCard vcard, SilcUInt32 *vcard_len)
     silc_buffer_strformat(&buffer,
                          "CATEGORIES:", vcard->categories, "\n",
                          SILC_STR_END);
-  if (vcard->class)
+  if (vcard->catclass)
     silc_buffer_strformat(&buffer,
-                         "CLASS:", vcard->class, "\n",
+                         "CLASS:", vcard->catclass, "\n",
                          SILC_STR_END);
   if (vcard->url)
     silc_buffer_strformat(&buffer,
@@ -204,7 +204,7 @@ bool silc_vcard_decode(const unsigned char *data, SilcUInt32 data_len,
     VCARD_FIELD(val, "TITLE:", vcard->title);
     VCARD_FIELD(val, "ROLE:", vcard->role);
     VCARD_FIELD(val, "CATEGORIES:", vcard->categories);
-    VCARD_FIELD(val, "CLASS:", vcard->class);
+    VCARD_FIELD(val, "CLASS:", vcard->catclass);
     VCARD_FIELD(val, "URL:", vcard->url);
     VCARD_FIELD(val, "LABEL;", vcard->label);
     VCARD_FIELD(val, "NOTE:", vcard->note);
@@ -363,7 +363,7 @@ void silc_vcard_free(SilcVCard vcard)
   silc_free(vcard->org_name);
   silc_free(vcard->org_unit);
   silc_free(vcard->categories);
-  silc_free(vcard->class);
+  silc_free(vcard->catclass);
   silc_free(vcard->url);
   silc_free(vcard->label);
   for (i = 0; i < vcard->num_addrs; i++) {
@@ -427,8 +427,8 @@ void silc_vcard_fprintf(SilcVCard vcard, FILE *stream)
            vcard->org_unit ? vcard->org_unit : "");
   if (vcard->categories)
     fprintf(stream, "CATEGORIES:%s\n", vcard->categories);
-  if (vcard->class)
-    fprintf(stream, "CLASS:%s\n", vcard->class);
+  if (vcard->catclass)
+    fprintf(stream, "CLASS:%s\n", vcard->catclass);
   if (vcard->url)
     fprintf(stream, "URL:%s\n", vcard->url);
   if (vcard->label)
index 5bbbca37033ee02fafc3c0f7bc00f9fb97b9e039..7f9666c528257d3a70bcb92f25070157a2c58b2f 100644 (file)
@@ -62,7 +62,7 @@ typedef struct {
   char *org_name;          /* organization name, string */
   char *org_unit;          /* organization unit, string */
   char *categories;        /* application category, string */
-  char *class;             /* class (public, private, confidental), string */
+  char *catclass;          /* class (public, private, confidental), string */
   char *url;               /* home page, URI string */
   char *label;             /* formatted address label, string (same
                               format as for 'addr' but comma sep.) */
@@ -155,7 +155,7 @@ SilcVCard silc_vcard_alloc(void);
  *
  * SYNOPSIS
  *
- *    void silc_vcard_free(SilcVcard vcard);
+ *    void silc_vcard_free(SilcVCard vcard);
  *
  * DESCRIPTION
  *
index eb8f2458e1b468965243cd5206a1f4def588fa72..38aae9545c22c0ee88f259f0a4e8b0ccdb6757b2 100644 (file)
@@ -23,7 +23,8 @@
 
 static void *st_blocks = NULL;
 static unsigned long st_blocks_count = 0;
-static int dump = FALSE;
+static bool dump = FALSE;
+static bool malloc_check = FALSE;
 
 #define SILC_ST_DEPTH 10
 
@@ -62,6 +63,16 @@ void silc_st_stacktrace(SilcStBlock stack)
     dump = TRUE;
   }
 
+  if (!malloc_check) {
+    /* Linux libc malloc check */
+    setenv("MALLOC_CHECK_", "2", 1);
+
+    /* NetBSD malloc check */
+    setenv("MALLOC_OPTIONS", "AJ", 1);
+
+    malloc_check = TRUE;
+  }
+
   /* Save the stack */
   SILC_ST_GET_FP(fp);
   for (stack->depth = 0; fp; stack->depth++) {
index 6b92ee3286d7a6c56cc79cee37607639e7f61aa4..d6eb0f233f973dd63e51d183b29b5ad577fb4696 100644 (file)
@@ -25,6 +25,7 @@
 struct SilcMutexStruct {
 #ifdef SILC_THREADS
   pthread_mutex_t mutex;
+  unsigned int locked : 1;
 #else
   void *tmp;
 #endif /* SILC_THREADS */
@@ -36,7 +37,6 @@ bool silc_mutex_alloc(SilcMutex *mutex)
   *mutex = silc_calloc(1, sizeof(**mutex));
   if (*mutex == NULL)
     return FALSE;
-
   pthread_mutex_init(&(*mutex)->mutex, NULL);
 #endif /* SILC_THREADS */
   return TRUE;
@@ -55,12 +55,16 @@ void silc_mutex_lock(SilcMutex mutex)
 #ifdef SILC_THREADS
   if (pthread_mutex_lock(&mutex->mutex))
     assert(FALSE);
+  assert(mutex->locked == 0);
+  mutex->locked = 1;
 #endif /* SILC_THREADS */
 }
 
 void silc_mutex_unlock(SilcMutex mutex)
 {
 #ifdef SILC_THREADS
+  assert(mutex->locked == 1);
+  mutex->locked = 0;
   if (pthread_mutex_unlock(&mutex->mutex))
     assert(FALSE);
 #endif /* SILC_THREADS */
index 285d9418fe84fdd77e5bd5c7f8e39b0b1fc01803..4d14ac5fc323626aa037aeff5eabedeca60441da 100644 (file)
@@ -33,6 +33,8 @@ int silc_socket_write(SilcSocketConnection sock)
   int fd = sock->sock;
   SilcBuffer src = sock->outbuf;
 
+  if (!src)
+    return -2;
   if (SILC_IS_DISABLED(sock))
     return -1;
 
index 95a6e2651262ee7d203cd98dd0fa27b032f71649..11c03c9c8e354ff7ca985f7f4a603f9e0412e9bd 100644 (file)
 #include "silcincludes.h"
 
 /* SILC Mutex structure */
-struct SilcMutexStruct {
+struct SilcMutexStruct {       
 #ifdef SILC_THREADS
-  HANDLE mutex;
+  CRITICAL_SECTION mutex;  
+  BOOL locked;
 #else
   void *tmp;
 #endif /* SILC_THREADS */
@@ -33,12 +34,8 @@ struct SilcMutexStruct {
 bool silc_mutex_alloc(SilcMutex *mutex)
 {
 #ifdef SILC_THREADS
-  *mutex = silc_calloc(1, sizeof(**mutex));
-  (*mutex)->mutex = CreateMutex(NULL, FALSE, NULL);
-  if (!(*mutex)->mutex) {
-    silc_free(*mutex);
-    return FALSE;
-  }
+  *mutex = silc_calloc(1, sizeof(**mutex));  
+  InitializeCriticalSection(&((*mutex)->mutex));  
 #endif /* SILC_THREADS */
   return TRUE;
 }
@@ -46,7 +43,7 @@ bool silc_mutex_alloc(SilcMutex *mutex)
 void silc_mutex_free(SilcMutex mutex)
 {
 #ifdef SILC_THREADS
-  CloseHandle(mutex->mutex);
+  DeleteCriticalSection(&mutex->mutex);
   silc_free(mutex);
 #endif /* SILC_THREADS */
 }
@@ -54,13 +51,17 @@ void silc_mutex_free(SilcMutex mutex)
 void silc_mutex_lock(SilcMutex mutex)
 {
 #ifdef SILC_THREADS
-  WaitForSingleObject(mutex->mutex, INFINITE);
+  EnterCriticalSection(&mutex->mutex);    
+  assert(mutex->locked == FALSE);
+  mutex->locked = TRUE;
 #endif /* SILC_THREADS */
 }
 
 void silc_mutex_unlock(SilcMutex mutex)
 {
 #ifdef SILC_THREADS
-  ReleaseMutex(mutex->mutex);
+  assert(mutex->locked == TRUE);
+  mutex->locked = FALSE;
+  LeaveCriticalSection(&mutex->mutex);       
 #endif /* SILC_THREADS */
 }
index 52515bbe82455d7869988cc2039ed0f989754e8f..55f37e56fa6307f6feab57c5471fb9ed4d3a35e8 100644 (file)
@@ -33,6 +33,8 @@ int silc_socket_write(SilcSocketConnection sock)
   SOCKET fd = sock->sock;
   SilcBuffer src = sock->outbuf;
 
+  if (!src)
+    return -2;
   if (SILC_IS_DISABLED(sock))
     return -1;
 
index bea9552d43e69443a97e9ded1e652e45b2030460..ca2a211207c9baf3feec507151d2eb5f4d99a63d 100644 (file)
@@ -17,9 +17,6 @@
   GNU General Public License for more details.
 
 */
-/* These routines are based on GLib's WIN32 gthread implementation and
-   thus credits should go there. */
-/* XXX Is the use of Tls necessary?? */
 /* $Id$ */
 
 #include "silcincludes.h"
@@ -64,8 +61,8 @@ SilcThread silc_thread_create(SilcThreadStart start_func, void *context,
   thread->start_func = start_func;
   thread->context = context;
   thread->waitable = waitable;
-  thread->thread = (HANDLE)_beginthreadex(NULL, 0, silc_thread_win32_start,
-                                         (void *)thread, 0, &id);
+  thread->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)silc_thread_win32_start, (void *)thread, 0, &id);
+
   if (!thread->thread) {
     SILC_LOG_ERROR(("Could not create new thread"));
     silc_free(thread);
@@ -89,14 +86,13 @@ void silc_thread_exit(void *exit_value)
     /* If the thread is waitable the memory is freed only in silc_thread_wait
        by another thread. If not waitable, free it now. */
     if (!thread->waitable) {
-      CloseHandle(thread->thread);
+      TerminateThread(thread->thread, 0);
       silc_free(thread);
     }
 
     TlsSetValue(silc_thread_tls, NULL);
   }
-
-  _endthreadex(0);
+  ExitThread(0);
 #endif
 }
 
@@ -134,8 +130,11 @@ bool silc_thread_wait(SilcThread thread, void **exit_value)
 
   /* The thread is waitable thus we will free all memory after the
      WaitForSingleObject returns, the thread is destroyed after that. */
-  WaitForSingleObject(self->thread, INFINITE);
-  CloseHandle(self->thread);
+
+  /* 2 sec timeout, otherwise we would run to infinite loop some cases.. */
+  if (WaitForSingleObject(self->thread, 2000) == WAIT_TIMEOUT)
+    TerminateThread(self->thread, 0);
+
   silc_free(self);
   if (exit_value)
     *exit_value = NULL;
index c8d9c9bf5304c99713640783054c43bd561d9025..b24a6b4827fa8ae9184f51c208a1ba11e2abdb89 100644 (file)
@@ -61,3 +61,13 @@ int silc_gettimeofday(struct timeval *tv)
 
   return 0;
 }
+
+char *silc_get_username(void)
+{
+  return strdup("foo");
+}
+
+char *silc_get_real_name(void)
+{
+  return strdup("Foo T. Bar");
+}
diff --git a/libtoolfix b/libtoolfix
new file mode 100755 (executable)
index 0000000..45d582f
--- /dev/null
@@ -0,0 +1,63 @@
+#!/bin/sh
+#
+# No Copyright 2002 Pekka Riikonen <priikone@silcnet.org>
+#
+# This script fixes the fundamental problem of libtool: it is not 
+# configurable in run-time.  This changes the libtool so that it becomes
+# more generic and configurable in run-time.
+#
+# New command line options to libtool:
+#
+# --libtool-enable-shared      Enable shared library compilation
+# --libtool-enable-static      Enable static library compilation
+# --libtool-disable-shared     Disable shared library compilation
+# --libtool-disable-static     Disable static library compilation
+#
+# If options are omitted the default libtool configuration will apply.
+#
+
+# Sanity checks
+if test '!' -f ./libtool; then
+  echo "./libtool does not exist"
+  exit 0
+fi
+
+# Take configuration from the ./libtool
+sed '/^# ltmain\.sh/q' ./libtool >./libtool.tmp
+
+# Put our wrapper to the new libtool.  This allows the run-time
+# configuration of the libtool.
+ltmain=`pwd`/ltmain.sh
+cat << EOF >> ./libtool.tmp
+args=\`echo \$*\`
+cargs=\`echo \$* | sed -e '/--libtool-enable-shared/s///' -e '/--libtool-enable-static/s///' -e '/--libtool-disable-shared/s///' -e '/--libtool-disable-static/s///'\`
+for i in \$args
+do
+  if test "\$i" = "--libtool-enable-shared"; then
+    build_libtool_libs=yes
+    fast_install=yes
+    continue
+  fi
+  if test "\$i" = "--libtool-disable-shared"; then
+    build_libtool_libs=no
+    continue
+  fi
+  if test "\$i" = "--libtool-enable-static"; then
+    build_old_libs=yes
+    continue
+  fi
+  if test "\$i" = "--libtool-disable-static"; then
+    build_old_libs=no
+    continue
+  fi
+done
+if test "\$cargs" = ""; then
+  cargs="--silent"
+fi
+. $ltmain \$cargs
+EOF
+
+mv -f ./libtool.tmp ./libtool
+chmod +x ./libtool
+
+exit 1
diff --git a/prepare b/prepare
index fbdcd9b0ad00d117356c535e1e46b6906684c2c5..e0ba0efe7f5abf09487201abd5b2dd366aacb94e 100755 (executable)
--- a/prepare
+++ b/prepare
@@ -37,7 +37,7 @@
 # SILC Distribution versions. Set here or give the version on the command
 # line as argument.
 #
-SILC_VERSION=0.9.5                     # Base version
+SILC_VERSION=0.9.7                     # Base version
 
 #############################################################################
 
index 8e16c897ec72c7a650ad112a20addef4562bd40e..10163ef81abd84d4a19da91f0f8114f8041789fe 100644 (file)
@@ -166,11 +166,16 @@ silc_say(SilcClient client, SilcClientConnection conn,
 static void
 silc_channel_message(SilcClient client, SilcClientConnection conn,
                     SilcClientEntry sender, SilcChannelEntry channel,
+                    SilcMessagePayload payload,
                     SilcMessageFlags flags, const unsigned char *message,
                     SilcUInt32 message_len)
 {
   /* Yay! We got a message from channel. */
-  fprintf(stdout, "<%s> %s\n", sender->nickname, message);
+
+  if (flags & SILC_MESSAGE_FLAG_SIGNED)
+    fprintf(stdout, "[SIGNED] <%s> %s\n", sender->nickname, message);
+  else
+    fprintf(stdout, "<%s> %s\n", sender->nickname, message);
 }
 
 
@@ -182,7 +187,8 @@ silc_channel_message(SilcClient client, SilcClientConnection conn,
 
 static void
 silc_private_message(SilcClient client, SilcClientConnection conn,
-                    SilcClientEntry sender, SilcMessageFlags flags,
+                    SilcClientEntry sender, SilcMessagePayload payload,
+                    SilcMessageFlags flags,
                     const unsigned char *message,
                     SilcUInt32 message_len)
 {
@@ -301,6 +307,13 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
     silc_client_send_channel_message(client, conn, channel, NULL, 0,
                                     "hello", strlen("hello"), FALSE);
     fprintf(stdout, "MyBot: Sent 'hello' to channel\n");
+
+    /* Now send digitally signed "hello" to the channel */
+    silc_client_send_channel_message(client, conn, channel, NULL,
+                                    SILC_MESSAGE_FLAG_SIGNED,
+                                    "hello, with signature", 
+                                    strlen("hello, with signature"), FALSE);
+    fprintf(stdout, "MyBot: Sent 'hello, with signature' to channel\n");
   }
 
   va_end(va);
index 487db212d2b201cef43a16186c452a0a388d7a81..c6102bb0d5c6000e66a9b57f4fe0f45d2ed6755f 100644 (file)
-;
-; Exports file for SILC Core DLL.
-;
-; This file is generated from MinGW compiled object files using the
-; following command:
-;
-; dlltool --export-all --output-def libsilc.def libsilc.a
-;
-; ----------------------------------------------------------------------------
-;
-; If you edit this file by adding or removing any exports be sure to
-; preserve the ordinal values (the @ n in the exports) and add new exports
-; always at the end of the list with new ordinal value. Do not ever
-; add new export with old ordinal value if you need to preserve backwards
-; compatiblity. -Pekka
-;
-EXPORTS
-       silc_aes_context_len @ 235 ; 
-       silc_aes_decrypt_cbc @ 236 ; 
-       silc_aes_encrypt_cbc @ 237 ; 
-       silc_aes_set_key @ 238 ; 
-       silc_aes_set_key_with_string @ 239 ; 
-       silc_argument_get_arg_num @ 240 ; 
-       silc_argument_get_arg_type @ 241 ; 
-       silc_argument_get_first_arg @ 242 ; 
-       silc_argument_get_next_arg @ 243 ; 
-       silc_argument_payload_encode @ 244 ; 
-       silc_argument_payload_encode_payload @ 245 ; 
-       silc_argument_payload_free @ 246 ; 
-       silc_argument_payload_parse @ 247 ; 
-       silc_auth_get_data @ 248 ; 
-       silc_auth_get_method @ 249 ; 
-       silc_auth_payload_encode @ 250 ; 
-       silc_auth_payload_free @ 251 ; 
-       silc_auth_payload_parse @ 252 ; 
-       silc_auth_public_key_auth_generate @ 253 ; 
-       silc_auth_public_key_auth_verify @ 254 ; 
-       silc_auth_public_key_auth_verify_data @ 255 ; 
-       silc_auth_verify @ 256 ; 
-       silc_auth_verify_data @ 257 ; 
-       silc_blowfish_context_len @ 258 ; 
-       silc_blowfish_decrypt_cbc @ 259 ; 
-       silc_blowfish_encrypt_cbc @ 260 ; 
-       silc_blowfish_set_key @ 261 ; 
-       silc_blowfish_set_key_with_string @ 262 ; 
-       silc_buffer_format @ 263 ; 
-       silc_buffer_unformat @ 264 ; 
-       silc_calloc @ 265 ; 
-       silc_cast_context_len @ 266 ; 
-       silc_cast_decrypt_cbc @ 267 ; 
-       silc_cast_encrypt_cbc @ 268 ; 
-       silc_cast_set_key @ 269 ; 
-       silc_cast_set_key_with_string @ 270 ; 
-       silc_channel_get_id @ 271 ; 
-       silc_channel_get_id_parse @ 272 ; 
-       silc_channel_get_mode @ 273 ; 
-       silc_channel_get_name @ 274 ; 
-       silc_channel_key_get_cipher @ 275 ; 
-       silc_channel_key_get_id @ 276 ; 
-       silc_channel_key_get_key @ 277 ; 
-       silc_channel_key_payload_encode @ 278 ; 
-       silc_channel_key_payload_free @ 279 ; 
-       silc_channel_key_payload_parse @ 280 ; 
-       silc_channel_message_get_mac @ 281 ; 
-       silc_channel_message_get_data @ 282 ; 
-       silc_channel_message_get_flags @ 283 ; 
-       silc_channel_message_get_iv @ 284 ; 
-       silc_channel_message_payload_decrypt @ 285 ; 
-       silc_channel_message_payload_encode @ 286 ; 
-       silc_channel_message_payload_free @ 287 ; 
-       silc_channel_message_payload_parse @ 288 ; 
-       silc_channel_payload_encode @ 289 ; 
-       silc_channel_payload_free @ 290 ; 
-       silc_channel_payload_list_free @ 291 ; 
-       silc_channel_payload_parse @ 292 ; 
-       silc_channel_payload_parse_list @ 293 ; 
-       silc_check_line @ 294 ; 
-       silc_cipher_alloc @ 295 ; 
-       silc_cipher_decrypt @ 296 ; 
-       silc_cipher_encrypt @ 297 ; 
-       silc_cipher_free @ 298 ; 
-       silc_cipher_get_block_len @ 299 ; 
-       silc_cipher_get_iv @ 300 ; 
-       silc_cipher_get_key_len @ 301 ; 
-       silc_cipher_get_supported @ 302 ; 
-       silc_cipher_is_supported @ 303 ; 
-       silc_cipher_list @ 304 ; 
-       silc_cipher_register @ 305 ; 
-       silc_cipher_register_default @ 306 ; 
-       silc_cipher_set_iv @ 307 ; 
-       silc_cipher_set_key @ 308 ; 
-       silc_cipher_unregister @ 309 ; 
-       silc_client_chmode @ 310 ; 
-       silc_client_chumode @ 311 ; 
-       silc_client_chumode_char @ 312 ; 
-       silc_command_get @ 313 ; 
-       silc_command_get_args @ 314 ; 
-       silc_command_get_ident @ 315 ; 
-       silc_command_payload_encode @ 316 ; 
-       silc_command_payload_encode_payload @ 317 ; 
-       silc_command_payload_encode_va @ 318 ; 
-       silc_command_payload_encode_vap @ 319 ; 
-       silc_command_payload_free @ 320 ; 
-       silc_command_payload_parse @ 321 ; 
-       silc_command_reply_payload_encode_va @ 322 ; 
-       silc_command_set_command @ 323 ; 
-       silc_command_set_ident @ 324 ; 
-       silc_config_open @ 327 ; 
-       silc_debug @ 328 DATA ; 
-       silc_pem_decode @ 329 ; 
-       silc_default_ciphers @ 330 DATA ; 
-       silc_default_hash @ 331 DATA ; 
-       silc_default_hmacs @ 332 DATA ; 
-       silc_default_pkcs @ 333 DATA ; 
-       silc_pem_encode @ 334 ; 
-       silc_pem_encode_file @ 335 ; 
-       silc_file_readfile @ 336 ; 
-       silc_file_writefile @ 337 ; 
-       silc_file_writefile_mode @ 338 ; 
-       silc_format @ 339 ; 
-       silc_free @ 340 ; 
-       silc_get_time @ 341 ; 
-       silc_gets @ 342 ; 
-       silc_gettimeofday @ 343 ; 
-       silc_hash_alloc @ 344 ; 
-       silc_hash_client_id_compare @ 345 ; 
-       silc_hash_data @ 346 ; 
-       silc_hash_data_compare @ 347 ; 
-       silc_hash_fingerprint @ 348 ; 
-       silc_hash_free @ 349 ; 
-       silc_hash_get_supported @ 350 ; 
-       silc_hash_id @ 351 ; 
-       silc_hash_id_compare @ 352 ; 
-       silc_hash_is_supported @ 353 ; 
-       silc_hash_len @ 354 ; 
-       silc_hash_list @ 355 ; 
-       silc_hash_make @ 356 ; 
-       silc_hash_ptr @ 357 ; 
-       silc_hash_register @ 358 ; 
-       silc_hash_register_default @ 359 ; 
-       silc_hash_string @ 360 ; 
-       silc_hash_string_compare @ 361 ; 
-       silc_hash_table_add @ 362 ; 
-       silc_hash_table_add_ext @ 363 ; 
-       silc_hash_table_alloc @ 364 ; 
-       silc_hash_table_count @ 365 ; 
-       silc_hash_table_del @ 366 ; 
-       silc_hash_table_del_by_context @ 367 ; 
-       silc_hash_table_del_by_context_ext @ 368 ; 
-       silc_hash_table_del_ext @ 369 ; 
-       silc_hash_table_find @ 370 ; 
-       silc_hash_table_find_ext @ 371 ; 
-       silc_hash_table_find_foreach @ 372 ; 
-       silc_hash_table_find_foreach_ext @ 373 ; 
-       silc_hash_table_foreach @ 374 ; 
-       silc_hash_table_free @ 375 ; 
-       silc_hash_table_get @ 376 ; 
-       silc_hash_table_list @ 377 ; 
-       silc_hash_table_rehash @ 378 ; 
-       silc_hash_table_rehash_ext @ 379 ; 
-       silc_hash_table_replace @ 380 ; 
-       silc_hash_table_replace_ext @ 381 ; 
-       silc_hash_table_size @ 382 ; 
-       silc_hash_uint @ 383 ; 
-       silc_hash_unregister @ 384 ; 
-       silc_hmac_alloc @ 385 ; 
-       silc_hmac_free @ 386 ; 
-       silc_hmac_get_supported @ 387 ; 
-       silc_hmac_is_supported @ 388 ; 
-       silc_hmac_len @ 389 ; 
-       silc_hmac_list @ 390 ; 
-       silc_hmac_make @ 391 ; 
-       silc_hmac_make_truncated @ 393 ; 
-       silc_hmac_make_with_key @ 394 ; 
-       silc_hmac_register @ 395 ; 
-       silc_hmac_register_default @ 396 ; 
-       silc_hmac_set_key @ 397 ; 
-       silc_hmac_unregister @ 398 ; 
-       silc_id_dup @ 399 ; 
-       silc_id_get_len @ 400 ; 
-       silc_id_id2str @ 401 ; 
-       silc_id_payload_encode @ 402 ; 
-       silc_id_payload_free @ 403 ; 
-       silc_id_payload_get_data @ 404 ; 
-       silc_id_payload_get_id @ 405 ; 
-       silc_id_payload_get_len @ 406 ; 
-       silc_id_payload_get_type @ 407 ; 
-       silc_id_payload_parse @ 408 ; 
-       silc_id_payload_parse_id @ 410 ; 
-       silc_id_render @ 411 ; 
-       silc_id_str2id @ 412 ; 
-       silc_idcache_add @ 413 ; 
-       silc_idcache_alloc @ 414 ; 
-       silc_idcache_del @ 415 ; 
-       silc_idcache_del_all @ 416 ; 
-       silc_idcache_del_by_context @ 417 ; 
-       silc_idcache_del_by_id @ 418 ; 
-       silc_idcache_del_by_id_ext @ 419 ; 
-       silc_idcache_find_by_context @ 420 ; 
-       silc_idcache_find_by_id @ 421 ; 
-       silc_idcache_find_by_id_one @ 422 ; 
-       silc_idcache_find_by_id_one_ext @ 423 ; 
-       silc_idcache_find_by_name @ 424 ; 
-       silc_idcache_find_by_name_one @ 425 ; 
-       silc_idcache_free @ 426 ; 
-       silc_idcache_get_all @ 427 ; 
-       silc_idcache_list_count @ 428 ; 
-       silc_idcache_list_first @ 429 ; 
-       silc_idcache_list_free @ 430 ; 
-       silc_idcache_list_next @ 431 ; 
-       silc_idcache_purge @ 432 ; 
-       silc_idcache_purge_by_context @ 433 ; 
-       silc_key_agreement_get_hostname @ 434 ; 
-       silc_key_agreement_get_port @ 435 ; 
-       silc_key_agreement_payload_encode @ 436 ; 
-       silc_key_agreement_payload_free @ 437 ; 
-       silc_key_agreement_payload_parse @ 438 ; 
-       silc_log_output @ 439 ; 
-       silc_log_output_debug @ 440 ; 
-       silc_log_output_hexdump @ 441 ; 
-       silc_log_reset_callbacks @ 442 ; 
-       silc_log_reset_debug_callbacks @ 443 ; 
-       silc_log_set_callback @ 444 ; 
-       silc_log_set_debug_callbacks @ 445 ; 
-       silc_log_set_file @ 446 ; 
-       silc_malloc @ 448 ; 
-       silc_mars_context_len @ 449 ; 
-       silc_mars_decrypt_cbc @ 450 ; 
-       silc_mars_encrypt_cbc @ 451 ; 
-       silc_mars_set_key @ 452 ; 
-       silc_mars_set_key_with_string @ 453 ; 
-       silc_math_gen_prime @ 454 ; 
-       silc_math_prime_test @ 455 ; 
-       silc_md5_context_len @ 456 ; 
-       silc_md5_final @ 457 ; 
-       silc_md5_init @ 458 ; 
-       silc_md5_transform @ 459 ; 
-       silc_md5_update @ 460 ; 
-       silc_mp_abs @ 461 ; 
-       silc_mp_add @ 462 ; 
-       silc_mp_add_ui @ 463 ; 
-       silc_mp_and @ 464 ; 
-       silc_mp_bin2mp @ 465 ; 
-       silc_mp_cmp @ 466 ; 
-       silc_mp_cmp_si @ 467 ; 
-       silc_mp_cmp_ui @ 468 ; 
-       silc_mp_div @ 469 ; 
-       silc_mp_div_2exp @ 470 ; 
-       silc_mp_div_2exp_qr @ 471 ; 
-       silc_mp_div_qr @ 472 ; 
-       silc_mp_div_ui @ 473 ; 
-       silc_mp_gcd @ 474 ; 
-       silc_mp_gcdext @ 475 ; 
-       silc_mp_get_str @ 476 ; 
-       silc_mp_get_ui @ 477 ; 
-       silc_mp_init @ 478 ; 
-       silc_mp_mod @ 479 ; 
-       silc_mp_mod_2exp @ 480 ; 
-       silc_mp_mod_ui @ 481 ; 
-       silc_mp_modinv @ 482 ; 
-       silc_mp_mp2bin @ 483 ; 
-       silc_mp_mp2bin_noalloc @ 484 ; 
-       silc_mp_mul @ 485 ; 
-       silc_mp_mul_2exp @ 486 ; 
-       silc_mp_mul_ui @ 487 ; 
-       silc_mp_neg @ 488 ; 
-       silc_mp_or @ 489 ; 
-       silc_mp_pow @ 490 ; 
-       silc_mp_pow_mod @ 491 ; 
-       silc_mp_pow_mod_ui @ 492 ; 
-       silc_mp_pow_ui @ 493 ; 
-       silc_mp_set @ 494 ; 
-       silc_mp_set_si @ 495 ; 
-       silc_mp_set_str @ 496 ; 
-       silc_mp_set_ui @ 497 ; 
-       silc_mp_size @ 498 ; 
-       silc_mp_sizeinbase @ 499 ; 
-       silc_mp_sqrt @ 500 ; 
-       silc_mp_sub @ 501 ; 
-       silc_mp_sub_ui @ 502 ; 
-       silc_mp_uninit @ 503 ; 
-       silc_mp_xor @ 504 ; 
-       silc_mutex_alloc @ 505 ; 
-       silc_mutex_free @ 506 ; 
-       silc_mutex_lock @ 507 ; 
-       silc_mutex_unlock @ 508 ; 
-       silc_net_accept_connection @ 509 ; 
-       silc_net_addr2bin @ 510 ; 
-       silc_net_check_host_by_sock @ 511 ; 
-       silc_net_check_local_by_sock @ 512 ; 
-       silc_net_close_connection @ 513 ; 
-       silc_net_close_server @ 514 ; 
-       silc_net_create_connection @ 515 ; 
-       silc_net_create_connection_async @ 516 ; 
-       silc_net_create_server @ 517 ; 
-       silc_net_get_local_port @ 518 ; 
-       silc_net_get_remote_port @ 519 ; 
-       silc_net_get_socket_opt @ 520 ; 
-       silc_net_is_ip @ 521 ; 
-       silc_net_localhost @ 522 ; 
-       silc_net_set_socket_nonblock @ 523 ; 
-       silc_net_set_socket_opt @ 524 ; 
-       silc_net_win32_init @ 525 ; 
-       silc_net_win32_uninit @ 526 ; 
-       silc_none_context_len @ 527 ; 
-       silc_none_decrypt_cbc @ 528 ; 
-       silc_none_encrypt_cbc @ 529 ; 
-       silc_none_set_key @ 530 ; 
-       silc_none_set_key_with_string @ 531 ; 
-       silc_notify_get_arg_num @ 532 ; 
-       silc_notify_get_args @ 533 ; 
-       silc_notify_get_type @ 534 ; 
-       silc_notify_payload_encode @ 535 ; 
-       silc_notify_payload_encode_args @ 536 ; 
-       silc_notify_payload_free @ 537 ; 
-       silc_notify_payload_parse @ 538 ; 
-       silc_packet_assemble @ 539 ; 
-       silc_packet_context_alloc @ 540 ; 
-       silc_packet_context_dup @ 541 ; 
-       silc_packet_context_free @ 542 ; 
-       silc_packet_encrypt @ 544 ; 
-       silc_packet_parse @ 545 ; 
-       silc_packet_parse_special @ 546 ; 
-       silc_packet_receive @ 547 ; 
-       silc_packet_receive_process @ 548 ; 
-       silc_packet_send @ 549 ; 
-       silc_packet_send_prepare @ 550 ; 
-       silc_parse_command_line @ 551 ; 
-       silc_parse_userfqdn @ 552 ; 
-       silc_pkcs1_decrypt @ 553 ; 
-       silc_pkcs1_encrypt @ 554 ; 
-       silc_pkcs1_sign @ 555 ; 
-       silc_pkcs1_verify @ 556 ; 
-       silc_pkcs_alloc @ 557 ; 
-       silc_pkcs_decode_identifier @ 558 ; 
-       silc_pkcs_decrypt @ 559 ; 
-       silc_pkcs_encode_identifier @ 560 ; 
-       silc_pkcs_encrypt @ 561 ; 
-       silc_pkcs_free @ 562 ; 
-       silc_pkcs_free_identifier @ 563 ; 
-       silc_pkcs_get_key_len @ 564 ; 
-       silc_pkcs_get_private_key @ 565 ; 
-       silc_pkcs_get_public_key @ 566 ; 
-       silc_pkcs_get_supported @ 567 ; 
-       silc_pkcs_is_supported @ 568 ; 
-       silc_pkcs_list @ 569 ; 
-       silc_pkcs_load_private_key @ 570 ; 
-       silc_pkcs_load_public_key @ 571 ; 
-       silc_pkcs_private_key_alloc @ 572 ; 
-       silc_pkcs_private_key_data_encode @ 573 ; 
-       silc_pkcs_private_key_data_set @ 574 ; 
-       silc_pkcs_private_key_decode @ 575 ; 
-       silc_pkcs_private_key_encode @ 576 ; 
-       silc_pkcs_private_key_free @ 577 ; 
-       silc_pkcs_private_key_set @ 578 ; 
-       silc_pkcs_public_key_alloc @ 579 ; 
-       silc_pkcs_public_key_data_encode @ 580 ; 
-       silc_pkcs_public_key_data_set @ 581 ; 
-       silc_pkcs_public_key_decode @ 582 ; 
-       silc_pkcs_public_key_encode @ 583 ; 
-       silc_pkcs_public_key_free @ 584 ; 
-       silc_pkcs_public_key_set @ 585 ; 
-       silc_pkcs_register @ 586 ; 
-       silc_pkcs_register_default @ 587 ; 
-       silc_pkcs_save_private_key @ 588 ; 
-       silc_pkcs_save_public_key @ 590 ; 
-       silc_pkcs_save_public_key_data @ 591 ; 
-       silc_pkcs_sign @ 592 ; 
-       silc_pkcs_sign_with_hash @ 593 ; 
-       silc_pkcs_unregister @ 594 ; 
-       silc_pkcs_verify @ 595 ; 
-       silc_pkcs_verify_with_hash @ 596 ; 
-       silc_private_message_get_flags @ 597 ; 
-       silc_private_message_get_message @ 598 ; 
-       silc_private_message_payload_encode @ 599 ; 
-       silc_private_message_payload_free @ 600 ; 
-       silc_private_message_payload_parse @ 601 ; 
-       silc_protocol_alloc @ 602 ; 
-       silc_protocol_cancel @ 603 ; 
-       silc_protocol_execute @ 604 ; 
-       silc_protocol_execute_final @ 605 ; 
-       silc_protocol_free @ 606 ; 
-       silc_protocol_list @ 607 ; 
-       silc_protocol_register @ 608 ; 
-       silc_protocol_unregister @ 609 ; 
-       silc_rc5_context_len @ 610 ; 
-       silc_rc5_decrypt_cbc @ 611 ; 
-       silc_rc5_encrypt_cbc @ 612 ; 
-       silc_rc5_set_key @ 613 ; 
-       silc_rc5_set_key_with_string @ 614 ; 
-       silc_rc6_context_len @ 615 ; 
-       silc_rc6_decrypt_cbc @ 616 ; 
-       silc_rc6_encrypt_cbc @ 617 ; 
-       silc_rc6_set_key @ 618 ; 
-       silc_rc6_set_key_with_string @ 619 ; 
-       silc_realloc @ 620 ; 
-       silc_rng_add_noise @ 621 ; 
-       silc_rng_alloc @ 622 ; 
-       silc_rng_free @ 623 ; 
-       silc_rng_get_byte @ 624 ; 
-       silc_rng_get_rn16 @ 625 ; 
-       silc_rng_get_rn32 @ 626 ; 
-       silc_rng_get_rn_data @ 627 ; 
-       silc_rng_get_rn_string @ 628 ; 
-       silc_rng_global_add_noise @ 629 ; 
-       silc_rng_global_get_byte @ 630 ; 
-       silc_rng_global_get_rn16 @ 631 ; 
-       silc_rng_global_get_rn32 @ 632 ; 
-       silc_rng_global_get_rn_data @ 633 ; 
-       silc_rng_global_get_rn_string @ 634 ; 
-       silc_rng_global_init @ 635 ; 
-       silc_rng_global_uninit @ 636 ; 
-       silc_rng_init @ 637 ; 
-       silc_rsa_clear_keys @ 638 ; 
-       silc_rsa_context_len @ 639 ; 
-       silc_rsa_decrypt @ 640 ; 
-       silc_rsa_encrypt @ 641 ; 
-       silc_rsa_get_private_key @ 642 ; 
-       silc_rsa_get_public_key @ 643 ; 
-       silc_rsa_init @ 644 ; 
-       silc_rsa_set_private_key @ 645 ; 
-       silc_rsa_set_public_key @ 646 ; 
-       silc_rsa_sign @ 647 ; 
-       silc_rsa_verify @ 648 ; 
-       silc_schedule @ 649 ; 
-       silc_schedule_init @ 650 ; 
-       silc_schedule_one @ 651 ; 
-       silc_schedule_set_listen_fd @ 652 ; 
-       silc_schedule_stop @ 653 ; 
-       silc_schedule_task_add @ 654 ; 
-       silc_schedule_task_del @ 655 ; 
-       silc_schedule_task_del_by_callback @ 656 ; 
-       silc_schedule_task_del_by_context @ 657 ; 
-       silc_schedule_task_del_by_fd @ 658 ; 
-       silc_schedule_uninit @ 659 ; 
-       silc_schedule_unset_listen_fd @ 660 ; 
-       silc_schedule_wakeup @ 661 ; 
-       silc_select @ 665 ; 
-       silc_sha1_context_len @ 666 ; 
-       silc_sha1_final @ 667 ; 
-       silc_sha1_init @ 668 ; 
-       silc_sha1_transform @ 669 ; 
-       silc_sha1_update @ 670 ; 
-       silc_ske_abort @ 671 ; 
-       silc_ske_alloc @ 672 ; 
-       silc_ske_assemble_security_properties @ 673 ; 
-       silc_ske_end @ 675 ; 
-       silc_ske_free @ 676 ; 
-       silc_ske_free_key_material @ 677 ; 
-       silc_ske_group_get_by_name @ 678 ; 
-       silc_ske_group_get_by_number @ 679 ; 
-       silc_ske_get_supported_groups @ 680 ; 
-       silc_ske_group_get_number @ 681 ; 
-       silc_ske_groups @ 682 ; 
-       silc_ske_initiator_finish @ 683 ; 
-       silc_ske_initiator_phase_1 @ 684 ; 
-       silc_ske_initiator_phase_2 @ 685 ; 
-       silc_ske_initiator_start @ 686 ; 
-       silc_ske_payload_ke_decode @ 688 ; 
-       silc_ske_payload_ke_encode @ 689 ; 
-       silc_ske_payload_ke_free @ 690 ; 
-       silc_ske_payload_start_decode @ 691 ; 
-       silc_ske_payload_start_encode @ 692 ; 
-       silc_ske_payload_start_free @ 693 ; 
-       silc_ske_process_key_material @ 694 ; 
-       silc_ske_process_key_material_data @ 695 ; 
-       silc_ske_responder_finish @ 696 ; 
-       silc_ske_responder_phase_1 @ 697 ; 
-       silc_ske_responder_phase_2 @ 698 ; 
-       silc_ske_responder_start @ 699 ; 
-       silc_ske_select_security_properties @ 700 ; 
-       silc_ske_set_callbacks @ 701 ; 
-       silc_socket_alloc @ 702 ; 
-       silc_socket_dup @ 703 ; 
-       silc_socket_free @ 704 ; 
-       silc_socket_host_lookup @ 705 ; 
-       silc_socket_read @ 706 ; 
-       silc_socket_set_heartbeat @ 707 ; 
-       silc_socket_write @ 708 ; 
-       silc_string_compare @ 709 ; 
-       silc_thread_create @ 710 ; 
-       silc_thread_exit @ 711 ; 
-       silc_thread_self @ 712 ; 
-       silc_thread_wait @ 713 ; 
-       silc_to_upper @ 715 ; 
-       silc_twofish_context_len @ 716 ; 
-       silc_twofish_decrypt_cbc @ 717 ; 
-       silc_twofish_encrypt_cbc @ 718 ; 
-       silc_twofish_set_key @ 719 ; 
-       silc_twofish_set_key_with_string @ 720 ; 
-       silc_buffer_format_vp @ 789 ; 
-       silc_buffer_unformat_vp @ 790 ; 
-       silc_sftp_client_start @ 791 ;
-       silc_sftp_client_shutdown @ 792 ;
-       silc_sftp_client_receive_process @ 793 ;
-       silc_sftp_open @ 794 ;
-       silc_sftp_close @ 795 ;
-       silc_sftp_read @ 796 ;
-       silc_sftp_write @ 797 ;
-       silc_sftp_remove @ 798 ;
-       silc_sftp_rename @ 799 ;
-       silc_sftp_mkdir @ 800 ;
-       silc_sftp_rmdir @ 801 ;
-       silc_sftp_opendir @ 802 ;
-       silc_sftp_readdir @ 803 ;
-       silc_sftp_stat @ 804 ;
-       silc_sftp_lstat @ 805 ;
-       silc_sftp_fstat @ 806 ;
-       silc_sftp_setstat @ 807 ;
-       silc_sftp_fsetstat @ 808 ;
-       silc_sftp_readlink @ 809 ;
-       silc_sftp_symlink @ 810 ;
-       silc_sftp_realpath @ 811 ;
-       silc_sftp_extended @ 812 ;
-       silc_sftp_server_start @ 813 ;
-       silc_sftp_server_shutdown @ 814 ;
-       silc_sftp_server_receive_process @ 815 ;
-       silc_sftp_fs_memory @ 816 ;
-       silc_sftp_fs_memory_alloc @ 817 ;
-       silc_sftp_fs_memory_free @ 818 ;
-       silc_sftp_fs_memory_add_dir @ 819 ;
-       silc_sftp_fs_memory_del_dir @ 820 ;
-       silc_sftp_fs_memory_add_file @ 821 ;
-       silc_sftp_fs_memory_del_file @ 822 ;
-       silc_file_open @ 824 ;
-       silc_file_close @ 825 ;
-       silc_file_read @ 826 ;
-       silc_file_write @ 827 ;
-       silc_file_size @ 828 ;
-       silc_hmac_init @ 829 ;
-       silc_hmac_update @ 830 ;
-       silc_hmac_final @ 831 ;
-       silc_hmac_init_with_key @ 832 ;
-       silc_hmac_get_name @ 833 ;
-       silc_hmac_get_hash @ 834 ;
-       silc_net_localip @ 835 ;
-       silc_sftp_server_set_monitor @ 836 ;
-       silc_net_gethostbyname @ 837 ;
-       silc_net_gethostbyaddr @ 838 ;
-       silc_net_gethostbyname_async @ 839 ;
-       silc_net_gethostbyaddr_async @ 840 ;
-       silc_net_is_ip4 @ 841 ;
-       silc_net_is_ip6 @ 842 ;
-       silc_log_set_debug_string @ 843 ;
-       silc_log_reset_all @ 844 ;
-       silc_log_flush_all @ 845 ;
-       silc_log_get_file @ 846 ;
-       silc_log_quick @ 847 DATA ;
-       silc_log_flushdelay @ 848 DATA ;
-       silc_hash_table_list_reset @ 849 ;
-       silc_debug_hexdump @ 850 DATA ;
-       silc_memdup @ 851 ;
-       silc_command_get_status @ 852 ;
-       silc_utf8_encode @ 853 ;
-       silc_utf8_decode @ 854 ;
-       silc_utf8_encoded_len @ 855 ;
-       silc_utf8_valid @ 856 ;
-       silc_mime_parse @ 857 ;
-       silc_get_status_message @ 858 ;
-       silc_get_mode_list @ 859 ;
-       silc_hash_table_find_by_context @ 860 ;
-       silc_channel_message_payload_encrypt @ 861 ;
-       silc_string_is_ascii @ 862 ;
-       silc_parse_version_string @ 863 ;
-       silc_version_to_num @ 864 ;
-       silc_fingerprint @ 865 ;
-        silc_get_packet_name @ 866 ;
-        silc_get_command_name @ 867 ;
-        silc_strncat @ 868 ;
-        silc_attribute_payload_parse @ 869 ;
-        silc_attribute_payload_encode @ 870 ;
-        silc_attribute_payload_alloc @ 871 ;
-        silc_attribute_payload_free @ 872 ;
-        silc_attribute_payload_list_free @ 873 ;
-        silc_attribute_payload_encode_data @ 874 ;
-        silc_attribute_get_attribute @ 875 ;
-        silc_attribute_get_data @ 876 ;
-        silc_attribute_get_object @ 877 ;
-        silc_attribute_get_flags @ 878 ;
-        silc_attribute_get_verify_data @ 879 ;
-        silc_hash_get_name @ 880 ;
-       silc_create_key_pair @ 881 ;
-       silc_load_key_pair @ 882 ;
-       silc_show_public_key @ 883 ;
-       silc_change_private_key_passphrase @ 884 ;
+;\r
+; Exports file for SILC Core DLL.\r
+;\r
+; This file is generated from MinGW compiled object files using the\r
+; following command:\r
+;\r
+; dlltool --export-all --output-def libsilc.def libsilc.a\r
+;\r
+; ----------------------------------------------------------------------------\r
+;\r
+; If you edit this file by adding or removing any exports be sure to\r
+; preserve the ordinal values (the @ n in the exports) and add new exports\r
+; always at the end of the list with new ordinal value. Do not ever\r
+; add new export with old ordinal value if you need to preserve backwards\r
+; compatiblity. -Pekka\r
+;\r
+EXPORTS\r
+       silc_aes_context_len @ 235 ; \r
+       silc_aes_decrypt_cbc @ 236 ; \r
+       silc_aes_encrypt_cbc @ 237 ; \r
+       silc_aes_set_key @ 238 ; \r
+       silc_aes_set_key_with_string @ 239 ; \r
+       silc_argument_get_arg_num @ 240 ; \r
+       silc_argument_get_arg_type @ 241 ; \r
+       silc_argument_get_first_arg @ 242 ; \r
+       silc_argument_get_next_arg @ 243 ; \r
+       silc_argument_payload_encode @ 244 ; \r
+       silc_argument_payload_encode_payload @ 245 ; \r
+       silc_argument_payload_free @ 246 ; \r
+       silc_argument_payload_parse @ 247 ; \r
+       silc_auth_get_data @ 248 ; \r
+       silc_auth_get_method @ 249 ; \r
+       silc_auth_payload_encode @ 250 ; \r
+       silc_auth_payload_free @ 251 ; \r
+       silc_auth_payload_parse @ 252 ; \r
+       silc_auth_public_key_auth_generate @ 253 ; \r
+       silc_auth_public_key_auth_verify @ 254 ; \r
+       silc_auth_public_key_auth_verify_data @ 255 ; \r
+       silc_auth_verify @ 256 ; \r
+       silc_auth_verify_data @ 257 ; \r
+       silc_blowfish_context_len @ 258 ; \r
+       silc_blowfish_decrypt_cbc @ 259 ; \r
+       silc_blowfish_encrypt_cbc @ 260 ; \r
+       silc_blowfish_set_key @ 261 ; \r
+       silc_blowfish_set_key_with_string @ 262 ; \r
+       silc_buffer_format @ 263 ; \r
+       silc_buffer_unformat @ 264 ; \r
+       silc_calloc @ 265 ; \r
+       silc_cast_context_len @ 266 ; \r
+       silc_cast_decrypt_cbc @ 267 ; \r
+       silc_cast_encrypt_cbc @ 268 ; \r
+       silc_cast_set_key @ 269 ; \r
+       silc_cast_set_key_with_string @ 270 ; \r
+       silc_channel_get_id @ 271 ; \r
+       silc_channel_get_id_parse @ 272 ; \r
+       silc_channel_get_mode @ 273 ; \r
+       silc_channel_get_name @ 274 ; \r
+       silc_channel_key_get_cipher @ 275 ; \r
+       silc_channel_key_get_id @ 276 ; \r
+       silc_channel_key_get_key @ 277 ; \r
+       silc_channel_key_payload_encode @ 278 ; \r
+       silc_channel_key_payload_free @ 279 ; \r
+       silc_channel_key_payload_parse @ 280 ; \r
+       silc_channel_payload_encode @ 289 ; \r
+       silc_channel_payload_free @ 290 ; \r
+       silc_channel_payload_list_free @ 291 ; \r
+       silc_channel_payload_parse @ 292 ; \r
+       silc_channel_payload_parse_list @ 293 ; \r
+       silc_check_line @ 294 ; \r
+       silc_cipher_alloc @ 295 ; \r
+       silc_cipher_decrypt @ 296 ; \r
+       silc_cipher_encrypt @ 297 ; \r
+       silc_cipher_free @ 298 ; \r
+       silc_cipher_get_block_len @ 299 ; \r
+       silc_cipher_get_iv @ 300 ; \r
+       silc_cipher_get_key_len @ 301 ; \r
+       silc_cipher_get_supported @ 302 ; \r
+       silc_cipher_is_supported @ 303 ; \r
+       silc_cipher_list @ 304 ; \r
+       silc_cipher_register @ 305 ; \r
+       silc_cipher_register_default @ 306 ; \r
+       silc_cipher_set_iv @ 307 ; \r
+       silc_cipher_set_key @ 308 ; \r
+       silc_cipher_unregister @ 309 ; \r
+       silc_client_chmode @ 310 ; \r
+       silc_client_chumode @ 311 ; \r
+       silc_client_chumode_char @ 312 ; \r
+       silc_command_get @ 313 ; \r
+       silc_command_get_args @ 314 ; \r
+       silc_command_get_ident @ 315 ; \r
+       silc_command_payload_encode @ 316 ; \r
+       silc_command_payload_encode_payload @ 317 ; \r
+       silc_command_payload_encode_va @ 318 ; \r
+       silc_command_payload_encode_vap @ 319 ; \r
+       silc_command_payload_free @ 320 ; \r
+       silc_command_payload_parse @ 321 ; \r
+       silc_command_reply_payload_encode_va @ 322 ; \r
+       silc_command_set_command @ 323 ; \r
+       silc_command_set_ident @ 324 ; \r
+       silc_config_open @ 327 ; \r
+       silc_debug @ 328 DATA ; \r
+       silc_pem_decode @ 329 ; \r
+       silc_default_ciphers @ 330 DATA ; \r
+       silc_default_hash @ 331 DATA ; \r
+       silc_default_hmacs @ 332 DATA ; \r
+       silc_default_pkcs @ 333 DATA ; \r
+       silc_pem_encode @ 334 ; \r
+       silc_pem_encode_file @ 335 ; \r
+       silc_file_readfile @ 336 ; \r
+       silc_file_writefile @ 337 ; \r
+       silc_file_writefile_mode @ 338 ; \r
+       silc_format @ 339 ; \r
+       silc_free @ 340 ; \r
+       silc_get_time @ 341 ; \r
+       silc_gets @ 342 ; \r
+       silc_gettimeofday @ 343 ; \r
+       silc_hash_alloc @ 344 ; \r
+       silc_hash_client_id_compare @ 345 ; \r
+       silc_hash_data @ 346 ; \r
+       silc_hash_data_compare @ 347 ; \r
+       silc_hash_fingerprint @ 348 ; \r
+       silc_hash_free @ 349 ; \r
+       silc_hash_get_supported @ 350 ; \r
+       silc_hash_id @ 351 ; \r
+       silc_hash_id_compare @ 352 ; \r
+       silc_hash_is_supported @ 353 ; \r
+       silc_hash_len @ 354 ; \r
+       silc_hash_list @ 355 ; \r
+       silc_hash_make @ 356 ; \r
+       silc_hash_ptr @ 357 ; \r
+       silc_hash_register @ 358 ; \r
+       silc_hash_register_default @ 359 ; \r
+       silc_hash_string @ 360 ; \r
+       silc_hash_string_compare @ 361 ; \r
+       silc_hash_table_add @ 362 ; \r
+       silc_hash_table_add_ext @ 363 ; \r
+       silc_hash_table_alloc @ 364 ; \r
+       silc_hash_table_count @ 365 ; \r
+       silc_hash_table_del @ 366 ; \r
+       silc_hash_table_del_by_context @ 367 ; \r
+       silc_hash_table_del_by_context_ext @ 368 ; \r
+       silc_hash_table_del_ext @ 369 ; \r
+       silc_hash_table_find @ 370 ; \r
+       silc_hash_table_find_ext @ 371 ; \r
+       silc_hash_table_find_foreach @ 372 ; \r
+       silc_hash_table_find_foreach_ext @ 373 ; \r
+       silc_hash_table_foreach @ 374 ; \r
+       silc_hash_table_free @ 375 ; \r
+       silc_hash_table_get @ 376 ; \r
+       silc_hash_table_list @ 377 ; \r
+       silc_hash_table_rehash @ 378 ; \r
+       silc_hash_table_rehash_ext @ 379 ; \r
+       silc_hash_table_replace @ 380 ; \r
+       silc_hash_table_replace_ext @ 381 ; \r
+       silc_hash_table_size @ 382 ; \r
+       silc_hash_uint @ 383 ; \r
+       silc_hash_unregister @ 384 ; \r
+       silc_hmac_alloc @ 385 ; \r
+       silc_hmac_free @ 386 ; \r
+       silc_hmac_get_supported @ 387 ; \r
+       silc_hmac_is_supported @ 388 ; \r
+       silc_hmac_len @ 389 ; \r
+       silc_hmac_list @ 390 ; \r
+       silc_hmac_make @ 391 ; \r
+       silc_hmac_make_truncated @ 393 ; \r
+       silc_hmac_make_with_key @ 394 ; \r
+       silc_hmac_register @ 395 ; \r
+       silc_hmac_register_default @ 396 ; \r
+       silc_hmac_set_key @ 397 ; \r
+       silc_hmac_unregister @ 398 ; \r
+       silc_id_dup @ 399 ; \r
+       silc_id_get_len @ 400 ; \r
+       silc_id_id2str @ 401 ; \r
+       silc_id_payload_encode @ 402 ; \r
+       silc_id_payload_free @ 403 ; \r
+       silc_id_payload_get_data @ 404 ; \r
+       silc_id_payload_get_id @ 405 ; \r
+       silc_id_payload_get_len @ 406 ; \r
+       silc_id_payload_get_type @ 407 ; \r
+       silc_id_payload_parse @ 408 ; \r
+       silc_id_payload_parse_id @ 410 ; \r
+       silc_id_render @ 411 ; \r
+       silc_id_str2id @ 412 ; \r
+       silc_idcache_add @ 413 ; \r
+       silc_idcache_alloc @ 414 ; \r
+       silc_idcache_del @ 415 ; \r
+       silc_idcache_del_all @ 416 ; \r
+       silc_idcache_del_by_context @ 417 ; \r
+       silc_idcache_del_by_id @ 418 ; \r
+       silc_idcache_del_by_id_ext @ 419 ; \r
+       silc_idcache_find_by_context @ 420 ; \r
+       silc_idcache_find_by_id @ 421 ; \r
+       silc_idcache_find_by_id_one @ 422 ; \r
+       silc_idcache_find_by_id_one_ext @ 423 ; \r
+       silc_idcache_find_by_name @ 424 ; \r
+       silc_idcache_find_by_name_one @ 425 ; \r
+       silc_idcache_free @ 426 ; \r
+       silc_idcache_get_all @ 427 ; \r
+       silc_idcache_list_count @ 428 ; \r
+       silc_idcache_list_first @ 429 ; \r
+       silc_idcache_list_free @ 430 ; \r
+       silc_idcache_list_next @ 431 ; \r
+       silc_idcache_purge @ 432 ; \r
+       silc_idcache_purge_by_context @ 433 ; \r
+       silc_key_agreement_get_hostname @ 434 ; \r
+       silc_key_agreement_get_port @ 435 ; \r
+       silc_key_agreement_payload_encode @ 436 ; \r
+       silc_key_agreement_payload_free @ 437 ; \r
+       silc_key_agreement_payload_parse @ 438 ; \r
+       silc_log_output @ 439 ; \r
+       silc_log_output_debug @ 440 ; \r
+       silc_log_output_hexdump @ 441 ; \r
+       silc_log_reset_callbacks @ 442 ; \r
+       silc_log_reset_debug_callbacks @ 443 ; \r
+       silc_log_set_callback @ 444 ; \r
+       silc_log_set_debug_callbacks @ 445 ; \r
+       silc_log_set_file @ 446 ; \r
+       silc_malloc @ 448 ; \r
+       silc_math_gen_prime @ 454 ; \r
+       silc_math_prime_test @ 455 ; \r
+       silc_md5_context_len @ 456 ; \r
+       silc_md5_final @ 457 ; \r
+       silc_md5_init @ 458 ; \r
+       silc_md5_transform @ 459 ; \r
+       silc_md5_update @ 460 ; \r
+       silc_mp_abs @ 461 ; \r
+       silc_mp_add @ 462 ; \r
+       silc_mp_add_ui @ 463 ; \r
+       silc_mp_and @ 464 ; \r
+       silc_mp_bin2mp @ 465 ; \r
+       silc_mp_cmp @ 466 ; \r
+       silc_mp_cmp_si @ 467 ; \r
+       silc_mp_cmp_ui @ 468 ; \r
+       silc_mp_div @ 469 ; \r
+       silc_mp_div_2exp @ 470 ; \r
+       silc_mp_div_2exp_qr @ 471 ; \r
+       silc_mp_div_qr @ 472 ; \r
+       silc_mp_div_ui @ 473 ; \r
+       silc_mp_gcd @ 474 ; \r
+       silc_mp_gcdext @ 475 ; \r
+       silc_mp_get_str @ 476 ; \r
+       silc_mp_get_ui @ 477 ; \r
+       silc_mp_init @ 478 ; \r
+       silc_mp_mod @ 479 ; \r
+       silc_mp_mod_2exp @ 480 ; \r
+       silc_mp_mod_ui @ 481 ; \r
+       silc_mp_modinv @ 482 ; \r
+       silc_mp_mp2bin @ 483 ; \r
+       silc_mp_mp2bin_noalloc @ 484 ; \r
+       silc_mp_mul @ 485 ; \r
+       silc_mp_mul_2exp @ 486 ; \r
+       silc_mp_mul_ui @ 487 ; \r
+       silc_mp_neg @ 488 ; \r
+       silc_mp_or @ 489 ; \r
+       silc_mp_pow @ 490 ; \r
+       silc_mp_pow_mod @ 491 ; \r
+       silc_mp_pow_mod_ui @ 492 ; \r
+       silc_mp_pow_ui @ 493 ; \r
+       silc_mp_set @ 494 ; \r
+       silc_mp_set_si @ 495 ; \r
+       silc_mp_set_str @ 496 ; \r
+       silc_mp_set_ui @ 497 ; \r
+       silc_mp_size @ 498 ; \r
+       silc_mp_sizeinbase @ 499 ; \r
+       silc_mp_sqrt @ 500 ; \r
+       silc_mp_sub @ 501 ; \r
+       silc_mp_sub_ui @ 502 ; \r
+       silc_mp_uninit @ 503 ; \r
+       silc_mp_xor @ 504 ; \r
+       silc_mutex_alloc @ 505 ; \r
+       silc_mutex_free @ 506 ; \r
+       silc_mutex_lock @ 507 ; \r
+       silc_mutex_unlock @ 508 ; \r
+       silc_net_accept_connection @ 509 ; \r
+       silc_net_addr2bin @ 510 ; \r
+       silc_net_check_host_by_sock @ 511 ; \r
+       silc_net_check_local_by_sock @ 512 ; \r
+       silc_net_close_connection @ 513 ; \r
+       silc_net_close_server @ 514 ; \r
+       silc_net_create_connection @ 515 ; \r
+       silc_net_create_connection_async @ 516 ; \r
+       silc_net_create_server @ 517 ; \r
+       silc_net_get_local_port @ 518 ; \r
+       silc_net_get_remote_port @ 519 ; \r
+       silc_net_get_socket_opt @ 520 ; \r
+       silc_net_is_ip @ 521 ; \r
+       silc_net_localhost @ 522 ; \r
+       silc_net_set_socket_nonblock @ 523 ; \r
+       silc_net_set_socket_opt @ 524 ; \r
+       silc_net_win32_init @ 525 ; \r
+       silc_net_win32_uninit @ 526 ; \r
+       silc_none_context_len @ 527 ; \r
+       silc_none_decrypt_cbc @ 528 ; \r
+       silc_none_encrypt_cbc @ 529 ; \r
+       silc_none_set_key @ 530 ; \r
+       silc_none_set_key_with_string @ 531 ; \r
+       silc_notify_get_arg_num @ 532 ; \r
+       silc_notify_get_args @ 533 ; \r
+       silc_notify_get_type @ 534 ; \r
+       silc_notify_payload_encode @ 535 ; \r
+       silc_notify_payload_encode_args @ 536 ; \r
+       silc_notify_payload_free @ 537 ; \r
+       silc_notify_payload_parse @ 538 ; \r
+       silc_packet_assemble @ 539 ; \r
+       silc_packet_context_alloc @ 540 ; \r
+       silc_packet_context_dup @ 541 ; \r
+       silc_packet_context_free @ 542 ; \r
+       silc_packet_encrypt @ 544 ; \r
+       silc_packet_parse @ 545 ; \r
+       silc_packet_parse_special @ 546 ; \r
+       silc_packet_receive @ 547 ; \r
+       silc_packet_receive_process @ 548 ; \r
+       silc_packet_send @ 549 ; \r
+       silc_packet_send_prepare @ 550 ; \r
+       silc_parse_command_line @ 551 ; \r
+       silc_parse_userfqdn @ 552 ; \r
+       silc_pkcs1_decrypt @ 553 ; \r
+       silc_pkcs1_encrypt @ 554 ; \r
+       silc_pkcs1_sign @ 555 ; \r
+       silc_pkcs1_verify @ 556 ; \r
+       silc_pkcs_alloc @ 557 ; \r
+       silc_pkcs_decode_identifier @ 558 ; \r
+       silc_pkcs_decrypt @ 559 ; \r
+       silc_pkcs_encode_identifier @ 560 ; \r
+       silc_pkcs_encrypt @ 561 ; \r
+       silc_pkcs_free @ 562 ; \r
+       silc_pkcs_free_identifier @ 563 ; \r
+       silc_pkcs_get_key_len @ 564 ; \r
+       silc_pkcs_get_private_key @ 565 ; \r
+       silc_pkcs_get_public_key @ 566 ; \r
+       silc_pkcs_get_supported @ 567 ; \r
+       silc_pkcs_is_supported @ 568 ; \r
+       silc_pkcs_list @ 569 ; \r
+       silc_pkcs_load_private_key @ 570 ; \r
+       silc_pkcs_load_public_key @ 571 ; \r
+       silc_pkcs_private_key_alloc @ 572 ; \r
+       silc_pkcs_private_key_data_encode @ 573 ; \r
+       silc_pkcs_private_key_data_set @ 574 ; \r
+       silc_pkcs_private_key_decode @ 575 ; \r
+       silc_pkcs_private_key_encode @ 576 ; \r
+       silc_pkcs_private_key_free @ 577 ; \r
+       silc_pkcs_private_key_set @ 578 ; \r
+       silc_pkcs_public_key_alloc @ 579 ; \r
+       silc_pkcs_public_key_data_encode @ 580 ; \r
+       silc_pkcs_public_key_data_set @ 581 ; \r
+       silc_pkcs_public_key_decode @ 582 ; \r
+       silc_pkcs_public_key_encode @ 583 ; \r
+       silc_pkcs_public_key_free @ 584 ; \r
+       silc_pkcs_public_key_set @ 585 ; \r
+       silc_pkcs_register @ 586 ; \r
+       silc_pkcs_register_default @ 587 ; \r
+       silc_pkcs_save_private_key @ 588 ; \r
+       silc_pkcs_save_public_key @ 590 ; \r
+       silc_pkcs_save_public_key_data @ 591 ; \r
+       silc_pkcs_sign @ 592 ; \r
+       silc_pkcs_sign_with_hash @ 593 ; \r
+       silc_pkcs_unregister @ 594 ; \r
+       silc_pkcs_verify @ 595 ; \r
+       silc_pkcs_verify_with_hash @ 596 ; \r
+       silc_protocol_alloc @ 602 ; \r
+       silc_protocol_cancel @ 603 ; \r
+       silc_protocol_execute @ 604 ; \r
+       silc_protocol_execute_final @ 605 ; \r
+       silc_protocol_free @ 606 ; \r
+       silc_protocol_list @ 607 ; \r
+       silc_protocol_register @ 608 ; \r
+       silc_protocol_unregister @ 609 ; \r
+       silc_rc5_context_len @ 610 ; \r
+       silc_rc5_decrypt_cbc @ 611 ; \r
+       silc_rc5_encrypt_cbc @ 612 ; \r
+       silc_rc5_set_key @ 613 ; \r
+       silc_rc5_set_key_with_string @ 614 ; \r
+       silc_rc6_context_len @ 615 ; \r
+       silc_rc6_decrypt_cbc @ 616 ; \r
+       silc_rc6_encrypt_cbc @ 617 ; \r
+       silc_rc6_set_key @ 618 ; \r
+       silc_rc6_set_key_with_string @ 619 ; \r
+       silc_realloc @ 620 ; \r
+       silc_rng_add_noise @ 621 ; \r
+       silc_rng_alloc @ 622 ; \r
+       silc_rng_free @ 623 ; \r
+       silc_rng_get_byte @ 624 ; \r
+       silc_rng_get_rn16 @ 625 ; \r
+       silc_rng_get_rn32 @ 626 ; \r
+       silc_rng_get_rn_data @ 627 ; \r
+       silc_rng_get_rn_string @ 628 ; \r
+       silc_rng_global_add_noise @ 629 ; \r
+       silc_rng_global_get_byte @ 630 ; \r
+       silc_rng_global_get_rn16 @ 631 ; \r
+       silc_rng_global_get_rn32 @ 632 ; \r
+       silc_rng_global_get_rn_data @ 633 ; \r
+       silc_rng_global_get_rn_string @ 634 ; \r
+       silc_rng_global_init @ 635 ; \r
+       silc_rng_global_uninit @ 636 ; \r
+       silc_rng_init @ 637 ; \r
+       silc_rsa_clear_keys @ 638 ; \r
+       silc_rsa_context_len @ 639 ; \r
+       silc_rsa_decrypt @ 640 ; \r
+       silc_rsa_encrypt @ 641 ; \r
+       silc_rsa_get_private_key @ 642 ; \r
+       silc_rsa_get_public_key @ 643 ; \r
+       silc_rsa_init @ 644 ; \r
+       silc_rsa_set_private_key @ 645 ; \r
+       silc_rsa_set_public_key @ 646 ; \r
+       silc_rsa_sign @ 647 ; \r
+       silc_rsa_verify @ 648 ; \r
+       silc_schedule @ 649 ; \r
+       silc_schedule_init @ 650 ; \r
+       silc_schedule_one @ 651 ; \r
+       silc_schedule_set_listen_fd @ 652 ; \r
+       silc_schedule_stop @ 653 ; \r
+       silc_schedule_task_add @ 654 ; \r
+       silc_schedule_task_del @ 655 ; \r
+       silc_schedule_task_del_by_callback @ 656 ; \r
+       silc_schedule_task_del_by_context @ 657 ; \r
+       silc_schedule_task_del_by_fd @ 658 ; \r
+       silc_schedule_uninit @ 659 ; \r
+       silc_schedule_unset_listen_fd @ 660 ; \r
+       silc_schedule_wakeup @ 661 ; \r
+       silc_select @ 665 ; \r
+       silc_sha1_context_len @ 666 ; \r
+       silc_sha1_final @ 667 ; \r
+       silc_sha1_init @ 668 ; \r
+       silc_sha1_transform @ 669 ; \r
+       silc_sha1_update @ 670 ; \r
+       silc_ske_abort @ 671 ; \r
+       silc_ske_alloc @ 672 ; \r
+       silc_ske_assemble_security_properties @ 673 ; \r
+       silc_ske_end @ 675 ; \r
+       silc_ske_free @ 676 ; \r
+       silc_ske_free_key_material @ 677 ; \r
+       silc_ske_group_get_by_name @ 678 ; \r
+       silc_ske_group_get_by_number @ 679 ; \r
+       silc_ske_get_supported_groups @ 680 ; \r
+       silc_ske_group_get_number @ 681 ; \r
+       silc_ske_groups @ 682 ; \r
+       silc_ske_initiator_finish @ 683 ; \r
+       silc_ske_initiator_phase_1 @ 684 ; \r
+       silc_ske_initiator_phase_2 @ 685 ; \r
+       silc_ske_initiator_start @ 686 ; \r
+       silc_ske_payload_ke_decode @ 688 ; \r
+       silc_ske_payload_ke_encode @ 689 ; \r
+       silc_ske_payload_ke_free @ 690 ; \r
+       silc_ske_payload_start_decode @ 691 ; \r
+       silc_ske_payload_start_encode @ 692 ; \r
+       silc_ske_payload_start_free @ 693 ; \r
+       silc_ske_process_key_material @ 694 ; \r
+       silc_ske_process_key_material_data @ 695 ; \r
+       silc_ske_responder_finish @ 696 ; \r
+       silc_ske_responder_phase_1 @ 697 ; \r
+       silc_ske_responder_phase_2 @ 698 ; \r
+       silc_ske_responder_start @ 699 ; \r
+       silc_ske_select_security_properties @ 700 ; \r
+       silc_ske_set_callbacks @ 701 ; \r
+       silc_socket_alloc @ 702 ; \r
+       silc_socket_dup @ 703 ; \r
+       silc_socket_free @ 704 ; \r
+       silc_socket_host_lookup @ 705 ; \r
+       silc_socket_read @ 706 ; \r
+       silc_socket_set_heartbeat @ 707 ; \r
+       silc_socket_write @ 708 ; \r
+       silc_string_compare @ 709 ; \r
+       silc_thread_create @ 710 ; \r
+       silc_thread_exit @ 711 ; \r
+       silc_thread_self @ 712 ; \r
+       silc_thread_wait @ 713 ; \r
+       silc_to_upper @ 715 ; \r
+       silc_twofish_context_len @ 716 ; \r
+       silc_twofish_decrypt_cbc @ 717 ; \r
+       silc_twofish_encrypt_cbc @ 718 ; \r
+       silc_twofish_set_key @ 719 ; \r
+       silc_twofish_set_key_with_string @ 720 ; \r
+       silc_buffer_format_vp @ 789 ; \r
+       silc_buffer_unformat_vp @ 790 ; \r
+       silc_sftp_client_start @ 791 ;\r
+       silc_sftp_client_shutdown @ 792 ;\r
+       silc_sftp_client_receive_process @ 793 ;\r
+       silc_sftp_open @ 794 ;\r
+       silc_sftp_close @ 795 ;\r
+       silc_sftp_read @ 796 ;\r
+       silc_sftp_write @ 797 ;\r
+       silc_sftp_remove @ 798 ;\r
+       silc_sftp_rename @ 799 ;\r
+       silc_sftp_mkdir @ 800 ;\r
+       silc_sftp_rmdir @ 801 ;\r
+       silc_sftp_opendir @ 802 ;\r
+       silc_sftp_readdir @ 803 ;\r
+       silc_sftp_stat @ 804 ;\r
+       silc_sftp_lstat @ 805 ;\r
+       silc_sftp_fstat @ 806 ;\r
+       silc_sftp_setstat @ 807 ;\r
+       silc_sftp_fsetstat @ 808 ;\r
+       silc_sftp_readlink @ 809 ;\r
+       silc_sftp_symlink @ 810 ;\r
+       silc_sftp_realpath @ 811 ;\r
+       silc_sftp_extended @ 812 ;\r
+       silc_sftp_server_start @ 813 ;\r
+       silc_sftp_server_shutdown @ 814 ;\r
+       silc_sftp_server_receive_process @ 815 ;\r
+       silc_sftp_fs_memory @ 816 ;\r
+       silc_sftp_fs_memory_alloc @ 817 ;\r
+       silc_sftp_fs_memory_free @ 818 ;\r
+       silc_sftp_fs_memory_add_dir @ 819 ;\r
+       silc_sftp_fs_memory_del_dir @ 820 ;\r
+       silc_sftp_fs_memory_add_file @ 821 ;\r
+       silc_sftp_fs_memory_del_file @ 822 ;\r
+       silc_file_open @ 824 ;\r
+       silc_file_close @ 825 ;\r
+       silc_file_read @ 826 ;\r
+       silc_file_write @ 827 ;\r
+       silc_file_size @ 828 ;\r
+       silc_hmac_init @ 829 ;\r
+       silc_hmac_update @ 830 ;\r
+       silc_hmac_final @ 831 ;\r
+       silc_hmac_init_with_key @ 832 ;\r
+       silc_hmac_get_name @ 833 ;\r
+       silc_hmac_get_hash @ 834 ;\r
+       silc_net_localip @ 835 ;\r
+       silc_sftp_server_set_monitor @ 836 ;\r
+       silc_net_gethostbyname @ 837 ;\r
+       silc_net_gethostbyaddr @ 838 ;\r
+       silc_net_gethostbyname_async @ 839 ;\r
+       silc_net_gethostbyaddr_async @ 840 ;\r
+       silc_net_is_ip4 @ 841 ;\r
+       silc_net_is_ip6 @ 842 ;\r
+       silc_log_set_debug_string @ 843 ;\r
+       silc_log_reset_all @ 844 ;\r
+       silc_log_flush_all @ 845 ;\r
+       silc_log_get_file @ 846 ;\r
+       silc_log_quick @ 847 DATA ;\r
+       silc_log_flushdelay @ 848 DATA ;\r
+       silc_hash_table_list_reset @ 849 ;\r
+       silc_debug_hexdump @ 850 DATA ;\r
+       silc_memdup @ 851 ;\r
+       silc_command_get_status @ 852 ;\r
+       silc_utf8_encode @ 853 ;\r
+       silc_utf8_decode @ 854 ;\r
+       silc_utf8_encoded_len @ 855 ;\r
+       silc_utf8_valid @ 856 ;\r
+       silc_mime_parse @ 857 ;\r
+       silc_get_status_message @ 858 ;\r
+       silc_get_mode_list @ 859 ;\r
+       silc_hash_table_find_by_context @ 860 ;\r
+       silc_string_is_ascii @ 862 ;\r
+       silc_parse_version_string @ 863 ;\r
+       silc_version_to_num @ 864 ;\r
+       silc_fingerprint @ 865 ;\r
+        silc_get_packet_name @ 866 ;\r
+        silc_get_command_name @ 867 ;\r
+        silc_strncat @ 868 ;\r
+        silc_attribute_payload_parse @ 869 ;\r
+        silc_attribute_payload_encode @ 870 ;\r
+        silc_attribute_payload_alloc @ 871 ;\r
+        silc_attribute_payload_free @ 872 ;\r
+        silc_attribute_payload_list_free @ 873 ;\r
+        silc_attribute_payload_encode_data @ 874 ;\r
+        silc_attribute_get_attribute @ 875 ;\r
+        silc_attribute_get_data @ 876 ;\r
+        silc_attribute_get_object @ 877 ;\r
+        silc_attribute_get_flags @ 878 ;\r
+        silc_attribute_get_verify_data @ 879 ;\r
+        silc_hash_get_name @ 880 ;\r
+       silc_create_key_pair @ 881 ;\r
+       silc_load_key_pair @ 882 ;\r
+       silc_show_public_key @ 883 ;\r
+       silc_change_private_key_passphrase @ 884 ;\r
+       silc_argument_payload_encode_one @ 885 ; \r
+       silc_message_payload_decrypt @ 886 ; \r
+       silc_message_payload_parse @ 887 ; \r
+       silc_message_payload_encrypt @ 888 ; \r
+       silc_message_payload_encode @ 889 ; \r
+       silc_message_payload_free @ 890 ; \r
+       silc_message_get_flags @ 891 ; \r
+       silc_message_get_data @ 892 ; \r
+       silc_message_get_mac @ 893 ; \r
+       silc_message_get_iv @ 894 ; \r
+       silc_message_signed_payload_parse @ 895 ; \r
+       silc_message_signed_payload_encode @ 896 ; \r
+       silc_message_signed_payload_free @ 897 ; \r
+       silc_message_signed_verify @ 898 ; \r
+        silc_message_signed_get_public_key @ 899 ;\r
+        silc_hmac_unregister_all @ 900 ;\r
+        silc_hash_unregister_all @ 901 ;\r
+        silc_pkcs_unregister_all @ 902 ;\r
+        silc_cipher_unregister_all @ 903 ;\r
+        silc_rng_get_byte_fast @ 904 ;\r
+        silc_cipher_get_name @ 905 ;\r
+        silc_hmac_get_name @ 906 ;\r
+        silc_hash_get_name @ 907 ;\r
+        silc_pkcs_public_key_payload_encode @ 908 ;\r
+        silc_pkcs_public_key_payload_decode @ 909 ;\r
+\r
index 0b0cd72d108177c4643b367ea8439bea59845560..f9b45781389f6876f182055eb02f2c0bb066dac1 100644 (file)
@@ -127,15 +127,15 @@ SOURCE=..\..\lib\silccore\silcidcache.c
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=..\..\lib\silccore\silcnotify.c\r
+SOURCE=..\..\lib\silccore\silcmessage.c\r
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=..\..\lib\silccore\silcpacket.c\r
+SOURCE=..\..\lib\silccore\silcnotify.c\r
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=..\..\lib\silccore\silcprivate.c\r
+SOURCE=..\..\lib\silccore\silcpacket.c\r
 # End Source File\r
 # End Group\r
 # Begin Group "silcske"\r
@@ -159,6 +159,10 @@ SOURCE=..\..\lib\silcske\silcske.c
 # PROP Default_Filter ""\r
 # Begin Source File\r
 \r
+SOURCE=..\..\lib\silcutil\silcapputil.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\..\lib\silcutil\silcbuffmt.c\r
 # End Source File\r
 # Begin Source File\r
@@ -287,10 +291,6 @@ SOURCE=..\..\lib\silccrypt\cast.c
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=..\..\lib\silccrypt\mars.c\r
-# End Source File\r
-# Begin Source File\r
-\r
 SOURCE=..\..\lib\silccrypt\md5.c\r
 # End Source File\r
 # Begin Source File\r
@@ -399,15 +399,15 @@ SOURCE=..\..\lib\silccore\silcidcache.h
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=..\..\lib\silccore\silcmode.h\r
+SOURCE=..\..\lib\silccore\silcmessage.h\r
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=..\..\lib\silccore\silcnotify.h\r
+SOURCE=..\..\lib\silccore\silcmode.h\r
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=..\..\lib\silccore\silcpacket.h\r
+SOURCE=..\..\lib\silccore\silcnotify.h\r
 # End Source File\r
 # Begin Source File\r
 \r
@@ -443,6 +443,10 @@ SOURCE=..\..\lib\silcske\silcske_status.h
 # PROP Default_Filter ""\r
 # Begin Source File\r
 \r
+SOURCE=..\..\lib\silcutil\silcapputil.h\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\..\lib\silcutil\silcbuffer.h\r
 # End Source File\r
 # Begin Source File\r
@@ -603,14 +607,6 @@ SOURCE=..\..\lib\silccrypt\ciphers_def.h
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=..\..\lib\silccrypt\mars.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\..\lib\silccrypt\mars_internal.h\r
-# End Source File\r
-# Begin Source File\r
-\r
 SOURCE=..\..\lib\silccrypt\md5.h\r
 # End Source File\r
 # Begin Source File\r
index fd58aefc88cdbc6a11e0bf7cfd90cd7b98a658af..a312361678abafaa75df04326e4d47a13a1b4e80 100644 (file)
 
 /* Native WIN32 compilation (-mno-cygwin GCC option) under cygwin, though
    the code compiles with any native WIN32 compiler. */
+#ifndef SILC_WIN32
 #define SILC_WIN32 1
+#endif
 
 /* SILC distribution definitions (leave this at the end of file) */
 #define SILC_DIST_TOOLKIT 1