pax_global_header00006660000000000000000000000064122770133450014516gustar00rootroot0000000000000052 comment=d7a88b6697951727a2fa34b7d3d3543b0e5a2ecc irssi-plugin-otr-1.0.0/000077500000000000000000000000001227701334500147435ustar00rootroot00000000000000irssi-plugin-otr-1.0.0/.gitignore000066400000000000000000000003541227701334500167350ustar00rootroot00000000000000*.o *.so *.swp *.o *.swo *.pyc Makefile .libs/ .deps/ *~ *.la *.lo Makefile.in *.loT *.info *.bz2 *.tar configure aclocal.m4 autom4te.cache/ config.h config.h.in config.log config.status stamp-h1 libtool tags config/ !config/libotr.m4 irssi-plugin-otr-1.0.0/AUTHORS000066400000000000000000000000001227701334500160010ustar00rootroot00000000000000irssi-plugin-otr-1.0.0/ChangeLog000066400000000000000000000037011227701334500165160ustar00rootroot000000000000002014-02-12 irssi-otr 1.0.0 * Fix: typo in notice message of SMP event * Fix: otr info help syntax * Fix: otr info printing every user fingerprints * Update help page with otr info command * Updated README.md with otr fingerprint info * Add /otr info command * Merge pull request #38 from KwadroNaut/master * language, gender * Fix typo and add important notice to README * Fix: remove double quotes around a NULL value * Fix: remove gmodule useless linked library flags * Fix: remove .so on uninstall and set +x the .so on install 2013-05-09 irssi-otr 1.0.0-alpha2 * Merge pull request #30 from anarcat/master * cleanup automake voodoo * Fix: explicitly set ptr to NULL on asprintf error * Fix: handle IRC /me marker on msg receive * Fix: small typo in README.md * Fix: memory leak on error path * Fix: remove useless value * Fix: handle zero length string in rtrim() * Support split OTR message on receive. Bitlbee support. * Fix: print right nick name on otr finish * Merge pull request #18 from cbab/master * Fix: Automake install-data-hook must respect $DESTDIR * Fix: missing pthread header include * Fix: install help in /usr * Fix: move NULL free out of end label 2012-12-02 irssi-otr 1.0.0-alpha1 * Initial import of the alpha1 version * Major refactoring from the last version * Only supports libotr4 Version 0.3 * create queries for OTR messages if otr_createqueries is set * finish conversations on unload unless otr_finishonunload is off * added settings otr_policy, otr_policy_known and otr_ignore * fixed two segfault sources * key generation now operates on a temp file * the .irssi/otr dir now gets created with mode 700 * commands now take an optional nick@server argument (for single message window users) * changed loglevel of otr_log (heartbeats) and otr_finish * moved to the new public statusbar-item.h header Version 0.2 * fixed multiple server problem. * fixed fragmentation problem (seen with pidgin over IRC). irssi-plugin-otr-1.0.0/INSTALL000066400000000000000000000363321227701334500160030ustar00rootroot00000000000000Installation Instructions ************************* Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without warranty of any kind. Basic Installation ================== Briefly, the shell commands `./configure; make; make install' should configure, build, and install this package. The following more-detailed instructions are generic; see the `README' file for instructions specific to this package. Some packages provide this `INSTALL' file but do not implement all of the features documented below. The lack of an optional feature in a given package is not necessarily a bug. More recommendations for GNU packages can be found in *note Makefile Conventions: (standards)Makefile Conventions. The `configure' shell script attempts to guess correct values for various system-dependent variables used during compilation. It uses those values to create a `Makefile' in each directory of the package. It may also create one or more `.h' files containing system-dependent definitions. Finally, it creates a shell script `config.status' that you can run in the future to recreate the current configuration, and a file `config.log' containing compiler output (useful mainly for debugging `configure'). It can also use an optional file (typically called `config.cache' and enabled with `--cache-file=config.cache' or simply `-C') that saves the results of its tests to speed up reconfiguring. Caching is disabled by default to prevent problems with accidental use of stale cache files. If you need to do unusual things to compile the package, please try to figure out how `configure' could check whether to do them, and mail diffs or instructions to the address given in the `README' so they can be considered for the next release. If you are using the cache, and at some point `config.cache' contains results you don't want to keep, you may remove or edit it. The file `configure.ac' (or `configure.in') is used to create `configure' by a program called `autoconf'. You need `configure.ac' if you want to change it or regenerate `configure' using a newer version of `autoconf'. The simplest way to compile this package is: 1. `cd' to the directory containing the package's source code and type `./configure' to configure the package for your system. Running `configure' might take a while. While running, it prints some messages telling which features it is checking for. 2. Type `make' to compile the package. 3. Optionally, type `make check' to run any self-tests that come with the package, generally using the just-built uninstalled binaries. 4. Type `make install' to install the programs and any data files and documentation. When installing into a prefix owned by root, it is recommended that the package be configured and built as a regular user, and only the `make install' phase executed with root privileges. 5. Optionally, type `make installcheck' to repeat any self-tests, but this time using the binaries in their final installed location. This target does not install anything. Running this target as a regular user, particularly if the prior `make install' required root privileges, verifies that the installation completed correctly. 6. You can remove the program binaries and object files from the source code directory by typing `make clean'. To also remove the files that `configure' created (so you can compile the package for a different kind of computer), type `make distclean'. There is also a `make maintainer-clean' target, but that is intended mainly for the package's developers. If you use it, you may have to get all sorts of other programs in order to regenerate files that came with the distribution. 7. Often, you can also type `make uninstall' to remove the installed files again. In practice, not all packages have tested that uninstallation works correctly, even though it is required by the GNU Coding Standards. 8. Some packages, particularly those that use Automake, provide `make distcheck', which can by used by developers to test that all other targets like `make install' and `make uninstall' work correctly. This target is generally not run by end users. Compilers and Options ===================== Some systems require unusual options for compilation or linking that the `configure' script does not know about. Run `./configure --help' for details on some of the pertinent environment variables. You can give `configure' initial values for configuration parameters by setting variables in the command line or in the environment. Here is an example: ./configure CC=c99 CFLAGS=-g LIBS=-lposix *Note Defining Variables::, for more details. Compiling For Multiple Architectures ==================================== You can compile the package for more than one kind of computer at the same time, by placing the object files for each architecture in their own directory. To do this, you can use GNU `make'. `cd' to the directory where you want the object files and executables to go and run the `configure' script. `configure' automatically checks for the source code in the directory that `configure' is in and in `..'. This is known as a "VPATH" build. With a non-GNU `make', it is safer to compile the package for one architecture at a time in the source code directory. After you have installed the package for one architecture, use `make distclean' before reconfiguring for another architecture. On MacOS X 10.5 and later systems, you can create libraries and executables that work on multiple system types--known as "fat" or "universal" binaries--by specifying multiple `-arch' options to the compiler but only a single `-arch' option to the preprocessor. Like this: ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ CPP="gcc -E" CXXCPP="g++ -E" This is not guaranteed to produce working output in all cases, you may have to build one architecture at a time and combine the results using the `lipo' tool if you have problems. Installation Names ================== By default, `make install' installs the package's commands under `/usr/local/bin', include files under `/usr/local/include', etc. You can specify an installation prefix other than `/usr/local' by giving `configure' the option `--prefix=PREFIX', where PREFIX must be an absolute file name. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you pass the option `--exec-prefix=PREFIX' to `configure', the package uses PREFIX as the prefix for installing programs and libraries. Documentation and other data files still use the regular prefix. In addition, if you use an unusual directory layout you can give options like `--bindir=DIR' to specify different values for particular kinds of files. Run `configure --help' for a list of the directories you can set and what kinds of files go in them. In general, the default for these options is expressed in terms of `${prefix}', so that specifying just `--prefix' will affect all of the other directory specifications that were not explicitly provided. The most portable way to affect installation locations is to pass the correct locations to `configure'; however, many packages provide one or both of the following shortcuts of passing variable assignments to the `make install' command line to change installation locations without having to reconfigure or recompile. The first method involves providing an override variable for each affected directory. For example, `make install prefix=/alternate/directory' will choose an alternate location for all directory configuration variables that were expressed in terms of `${prefix}'. Any directories that were specified during `configure', but not in terms of `${prefix}', must each be overridden at install time for the entire installation to be relocated. The approach of makefile variable overrides for each directory variable is required by the GNU Coding Standards, and ideally causes no recompilation. However, some platforms have known limitations with the semantics of shared libraries that end up requiring recompilation when using this method, particularly noticeable in packages that use GNU Libtool. The second method involves providing the `DESTDIR' variable. For example, `make install DESTDIR=/alternate/directory' will prepend `/alternate/directory' before all installation names. The approach of `DESTDIR' overrides is not required by the GNU Coding Standards, and does not work on platforms that have drive letters. On the other hand, it does better at avoiding recompilation issues, and works well even when some directory options were not specified in terms of `${prefix}' at `configure' time. Optional Features ================= If the package supports it, you can cause programs to be installed with an extra prefix or suffix on their names by giving `configure' the option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. Some packages pay attention to `--enable-FEATURE' options to `configure', where FEATURE indicates an optional part of the package. They may also pay attention to `--with-PACKAGE' options, where PACKAGE is something like `gnu-as' or `x' (for the X Window System). The `README' should mention any `--enable-' and `--with-' options that the package recognizes. For packages that use the X Window System, `configure' can usually find the X include and library files automatically, but if it doesn't, you can use the `configure' options `--x-includes=DIR' and `--x-libraries=DIR' to specify their locations. Some packages offer the ability to configure how verbose the execution of `make' will be. For these packages, running `./configure --enable-silent-rules' sets the default to minimal output, which can be overridden with `make V=1'; while running `./configure --disable-silent-rules' sets the default to verbose, which can be overridden with `make V=0'. Particular systems ================== On HP-UX, the default C compiler is not ANSI C compatible. If GNU CC is not installed, it is recommended to use the following options in order to use an ANSI C compiler: ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" and if that doesn't work, install pre-built binaries of GCC for HP-UX. On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot parse its `' header file. The option `-nodtk' can be used as a workaround. If GNU CC is not installed, it is therefore recommended to try ./configure CC="cc" and if that doesn't work, try ./configure CC="cc -nodtk" On Solaris, don't put `/usr/ucb' early in your `PATH'. This directory contains several dysfunctional programs; working variants of these programs are available in `/usr/bin'. So, if you need `/usr/ucb' in your `PATH', put it _after_ `/usr/bin'. On Haiku, software installed for all users goes in `/boot/common', not `/usr/local'. It is recommended to use the following options: ./configure --prefix=/boot/common Specifying the System Type ========================== There may be some features `configure' cannot figure out automatically, but needs to determine by the type of machine the package will run on. Usually, assuming the package is built to be run on the _same_ architectures, `configure' can figure that out, but if it prints a message saying it cannot guess the machine type, give it the `--build=TYPE' option. TYPE can either be a short name for the system type, such as `sun4', or a canonical name which has the form: CPU-COMPANY-SYSTEM where SYSTEM can have one of these forms: OS KERNEL-OS See the file `config.sub' for the possible values of each field. If `config.sub' isn't included in this package, then this package doesn't need to know the machine type. If you are _building_ compiler tools for cross-compiling, you should use the option `--target=TYPE' to select the type of system they will produce code for. If you want to _use_ a cross compiler, that generates code for a platform different from the build platform, you should specify the "host" platform (i.e., that on which the generated programs will eventually be run) with `--host=TYPE'. Sharing Defaults ================ If you want to set default values for `configure' scripts to share, you can create a site shell script called `config.site' that gives default values for variables like `CC', `cache_file', and `prefix'. `configure' looks for `PREFIX/share/config.site' if it exists, then `PREFIX/etc/config.site' if it exists. Or, you can set the `CONFIG_SITE' environment variable to the location of the site script. A warning: not all `configure' scripts look for a site script. Defining Variables ================== Variables not defined in a site shell script can be set in the environment passed to `configure'. However, some packages may run configure again during the build, and the customized values of these variables may be lost. In order to avoid this problem, you should set them in the `configure' command line, using `VAR=value'. For example: ./configure CC=/usr/local2/bin/gcc causes the specified `gcc' to be used as the C compiler (unless it is overridden in the site shell script). Unfortunately, this technique does not work for `CONFIG_SHELL' due to an Autoconf bug. Until the bug is fixed you can use this workaround: CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash `configure' Invocation ====================== `configure' recognizes the following options to control how it operates. `--help' `-h' Print a summary of all of the options to `configure', and exit. `--help=short' `--help=recursive' Print a summary of the options unique to this package's `configure', and exit. The `short' variant lists options used only in the top level, while the `recursive' variant lists options also present in any nested packages. `--version' `-V' Print the version of Autoconf used to generate the `configure' script, and exit. `--cache-file=FILE' Enable the cache: use and save the results of the tests in FILE, traditionally `config.cache'. FILE defaults to `/dev/null' to disable caching. `--config-cache' `-C' Alias for `--cache-file=config.cache'. `--quiet' `--silent' `-q' Do not print messages saying which checks are being made. To suppress all normal output, redirect it to `/dev/null' (any error messages will still be shown). `--srcdir=DIR' Look for the package's source code in directory DIR. Usually `configure' can determine that directory automatically. `--prefix=DIR' Use DIR as the installation prefix. *note Installation Names:: for more details, including other options available for fine-tuning the installation locations. `--no-create' `-n' Run the configure checks, but stop before creating any output files. `configure' also accepts some other, not widely useful, options. Run `configure --help' for more details. irssi-plugin-otr-1.0.0/LICENSE000066400000000000000000000431031227701334500157510ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. irssi-plugin-otr-1.0.0/Makefile.am000066400000000000000000000001251227701334500167750ustar00rootroot00000000000000AM_CFLAGS = $(PACKAGE_CFLAGS) ACLOCAL_AMFLAGS = -I config SUBDIRS = help \ src irssi-plugin-otr-1.0.0/README.md000066400000000000000000000130351227701334500162240ustar00rootroot00000000000000## IMPORTANT ## Please use the git head master branch of libotr which contains a critical fix for irssi-otr to work. (Fix commit: d748757e581b74e7298df155ad49174cb914102b) http://sourceforge.net/p/otr/libotr/ci/master/tree/ irssi-otr ========= LibOTR (http://www.cypherpunks.ca/otr/) support for IRSSI. **Mailing list**: otr-dev@lists.cypherpunks.ca First of all, we strongly recommend to set this option to speed up any OTR commands or sessions. `/set cmd_queue_speed 1msec` The default value of irssi is much higher and used to avoid excess flood on IRC servers. However, with the message size this module is using and rate of a normal conversation, it seems OK to set this limit. Please inform us if it causes problems. Future works is to handle IRC excess flood inside this module. Requirements --------- * libotr 4.0.x - [Download Link](http://www.cypherpunks.ca/otr/index.php#downloads) * irssi-dev >= 0.8.15 - [Download Link](http://www.irssi.org/download) * glib2.0 Development package * libgcrypt >= 1.5.0 * automake, autoconf, libtool Installation --------- Run the following commands to compile and install. `$ ./bootstrap` `$ ./configure --prefix="/usr"` `$ make && make install` Quick Start --------- 1. `/load otr` in the Irssi main window. 2. Open a chat window with your buddy. 3. `/otr init`, initiate OTR session. If no key is found for your user and server, the key generation will be launched. You should see `OTR: Gone secure` and you are ready to communicate over OTR. Instructions --------- To load the OTR module at startup, use the following and make sure **otr.so** is located in the **modules/** directory of the Irssi home (usually ~/.irssi). `echo "load otr" >> ~/.irssi/startup` Once loaded, we recommend you add the OTR status bar allowing you to see the OTR state of private conversation. `/statusbar window add otr` Possible states are: * Plaintext * Finished * OTR * OTR (unverified) #### Key Generation #### Key generation happens in a separate process and its duration mainly depends on the available entropy. If **no** key is detected for the current user and server, the keys will be generated automatically for you. Or else, you can run: `/otr genkey nickname@server-addr-fqdn` Once done, you should see a message in the irssi main window indicating completion. `OTR: Key generation for completed in X seconds. Reloading keys.` The default OTR policy irssi-otr is now something between manual and opportunistic. Manual means you have to start it yourself by issuing a `/otr init` command and opportunistic means both peers send some magic whitespaces and start OTR once they receive these whitespaces from the other side. Irssi-otr uses a mode in between where we are not sending whitespaces as an announcement (as in opportunistic) but we still handle whitespaces if we see it from the other side. Therefore if your peer uses opportunistic the handshake should still start automatically once he writes something. To display the fingerprint of the OTR key you just generated, one can type `/otr info` to show the fingerprint. #### Authentication #### In order to be sure you are communicating with the right person you can do two things to autenticate him or her. 1. Use a **shared secret** previously decided between both parties or exchanged, **ideally** in person. Use the following command to iniate or respond to an authentication request. `/otr auth SHARED_SECRET` 2. The second method is to use the **[socialist millionaire problem](https://en.wikipedia.org/wiki/Socialist_millionaire)** (SMP) mechanism which consist of asking the other party a question for which him or her will only be able to respond with the correct answer. `/otr authq [YOUR QUESTION HERE] SHARED_SECRET` And respond with the command on number 1 above. 3. The third way is to trust manually. Exchange your fingerprint with the other party over a telephone or GPG-signed email for instance. `/otr trust [FP]` You can either type this command in the private conversation window of the buddy fingerprint you want to trust or enter the **FP** argument which is the five parts of the human readable fingerprint available via the `/otr contexts` command. For example: `/otr trust 487FFADA 5073FEDD C5AB5C14 5BB6C1FF 6D40D48A` You can abort an ongoing authentication at any time by using this command. `/otr authabort` To **distrust** a fingerprint for whatever reason you may have, use the following command which is like the trust command above. `/otr distrust [FP]` To completely **forget** a fingerprint meaning it will be erased from the OTR fingerprints file. Again, same as trust/distrust command, you can either enter the five parts of the fingerprint or execute the command in the private conversation window. `/otr forget [FP]` #### Finishing a Session #### If the window is closed, a **finish** action is triggered informing the other hand that you have ended the private session. The status bar will indicate `plaintext` if so. You can also use the `/otr finish` command to end the OTR session without closing the window. If your buddy finishes the session, you will be notified and the status bar will indicate `finished` in yellow. #### Other commands #### * Print the irssi-otr module version. `/otr version` * List all OTR contexts and their status. `/otr contexts` Irssi Files --------- In **/otr/otr.{key,fp}** you'll find the fingerprints and your private keys (should you at any point be interested). There is also the **otr.instag** file which is of no importance for you and used by libotr. irssi-plugin-otr-1.0.0/bootstrap000077500000000000000000000001171227701334500167050ustar00rootroot00000000000000#! /bin/sh set -x if [ ! -e config ]; then mkdir config fi autoreconf -i -s irssi-plugin-otr-1.0.0/config/000077500000000000000000000000001227701334500162105ustar00rootroot00000000000000irssi-plugin-otr-1.0.0/config/libotr.m4000066400000000000000000000103051227701334500177440ustar00rootroot00000000000000dnl dnl Off-the-Record Messaging library dnl Copyright (C) 2004-2007 Ian Goldberg, Chris Alexander, Nikita Borisov dnl dnl dnl This library is free software; you can redistribute it and/or dnl modify it under the terms of version 2.1 of the GNU Lesser General dnl Public License as published by the Free Software Foundation. dnl dnl This library is distributed in the hope that it will be useful, dnl but WITHOUT ANY WARRANTY; without even the implied warranty of dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU dnl Lesser General Public License for more details. dnl dnl You should have received a copy of the GNU Lesser General Public dnl License along with this library; if not, write to the Free Software dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA dnl dnl AM_PATH_LIBOTR([MINIMUM-VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) dnl Test for libotr, and define LIBOTR_CFLAGS and LIBOTR_LIBS as appropriate. dnl enables arguments --with-libotr-prefix= dnl --with-libotr-inc-prefix= dnl dnl You must already have found libgcrypt with AM_PATH_LIBGCRYPT dnl dnl Adapted from alsa.m4, originally by dnl Richard Boulton dnl Christopher Lansdown dnl Jaroslav Kysela AC_DEFUN([AM_PATH_LIBOTR], [dnl Save the original CFLAGS, LDFLAGS, and LIBS libotr_save_CFLAGS="$CFLAGS" libotr_save_LDFLAGS="$LDFLAGS" libotr_save_LIBS="$LIBS" libotr_found=yes dnl dnl Get the cflags and libraries for libotr dnl AC_ARG_WITH(libotr-prefix, [ --with-libotr-prefix=PFX Prefix where libotr is installed(optional)], [libotr_prefix="$withval"], [libotr_prefix=""]) AC_ARG_WITH(libotr-inc-prefix, [ --with-libotr-inc-prefix=PFX Prefix where libotr includes are (optional)], [libotr_inc_prefix="$withval"], [libotr_inc_prefix=""]) dnl Add any special include directories AC_MSG_CHECKING(for libotr CFLAGS) if test "$libotr_inc_prefix" != "" ; then LIBOTR_CFLAGS="$LIBOTR_CFLAGS -I$libotr_inc_prefix" CFLAGS="$CFLAGS $LIBOTR_CFLAGS" fi AC_MSG_RESULT($LIBOTR_CFLAGS) dnl add any special lib dirs AC_MSG_CHECKING(for libotr LIBS) if test "$libotr_prefix" != "" ; then LIBOTR_LIBS="$LIBOTR_LIBS -L$libotr_prefix" LDFLAGS="$LDFLAGS $LIBOTR_LIBS" fi dnl add the libotr library LIBOTR_LIBS="$LIBOTR_LIBS -lotr" LIBS="$LIBOTR_LIBS $LIBS" AC_MSG_RESULT($LIBOTR_LIBS) dnl Check for a working version of libotr that is of the right version. min_libotr_version=ifelse([$1], ,3.0.0,$1) no_libotr="" libotr_min_major_version=`echo $min_libotr_version | \ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` libotr_min_minor_version=`echo $min_libotr_version | \ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` libotr_min_sub_version=`echo $min_libotr_version | \ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` AC_MSG_CHECKING(for libotr headers version $libotr_min_major_version.x >= $min_libotr_version) AC_LANG_SAVE AC_LANG_C AC_TRY_COMPILE([ #include #include ], [ # if(OTRL_VERSION_MAJOR != $libotr_min_major_version) # error not present # else # if(OTRL_VERSION_MINOR > $libotr_min_minor_version) exit(0); # else # if(OTRL_VERSION_MINOR < $libotr_min_minor_version) # error not present # endif # if(OTRL_VERSION_SUB < $libotr_min_sub_version) # error not present # endif # endif # endif exit(0); ], [AC_MSG_RESULT(found.)], [AC_MSG_RESULT(not present.) ifelse([$3], , [AC_MSG_ERROR(Sufficiently new version of libotr not found.)]) libotr_found=no] ) AC_LANG_RESTORE dnl Now that we know that we have the right version, let's see if we have the library and not just the headers. AC_CHECK_LIB([otr], [otrl_message_receiving],, [ifelse([$3], , [AC_MSG_ERROR(No linkable libotr was found.)]) libotr_found=no], $LIBGCRYPT_LIBS ) LDFLAGS="$libotr_save_LDFLAGS" LIBS="$libotr_save_LIBS" if test "x$libotr_found" = "xyes" ; then ifelse([$2], , :, [$2]) else LIBOTR_CFLAGS="" LIBOTR_LIBS="" ifelse([$3], , :, [$3]) fi dnl That should be it. Now just export our symbols: AC_SUBST(LIBOTR_CFLAGS) AC_SUBST(LIBOTR_LIBS) ]) irssi-plugin-otr-1.0.0/configure.ac000066400000000000000000000060131227701334500172310ustar00rootroot00000000000000AC_INIT([irssi-otr],[1.0.0],[dgoulet@ev0ke.net],[],[https://github.com/dgoulet/irssi-otr]) AC_CONFIG_AUX_DIR([config]) AC_CANONICAL_TARGET AC_CANONICAL_HOST AC_CONFIG_MACRO_DIR([config]) AM_INIT_AUTOMAKE([foreign dist-bzip2 no-dist-gzip]) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) AC_PROG_GREP AC_PROG_CC # We do not want to create a .a for the module, so disable by default. AM_DISABLE_STATIC AM_PROG_LIBTOOL # Check for pthread AC_CHECK_LIB([pthread], [pthread_create], [], [AC_MSG_ERROR([Cannot find libpthread. Use [LDFLAGS]=-Ldir to specify its location.])] ) AC_ARG_WITH([irssi-headers], AS_HELP_STRING([--with-irssi-headers], [Directory containing the Irssi header files]), [IRSSI_HEADER_DIR="$withval"], [IRSSI_HEADER_DIR="\"\""]) # Check for Glib. It needs to be installed anyway or this macro will not be defined. AM_PATH_GLIB_2_0([2.22.0], [], [AC_MSG_ERROR([Glib 2.22 is required in order to compile. Please install the Glib development files.])], [gmodule]) AM_PATH_LIBGCRYPT(1:1.2.0,,AC_MSG_ERROR(libgcrypt 1.2.0 or newer is required.)) AM_PATH_LIBOTR(4.0.0, [], [AC_MSG_ERROR([libotr 4.0.0 or newer is required.])]) pkg_modules="gmodule-2.0 >= 2.0.0" PKG_CHECK_MODULES(GMODULE, [$pkg_modules]) LIBS="$LIBS" PACKAGE_CFLAGS="$GMODULE_CFLAGS -Wall -Werror=format-security" AC_SUBST(PACKAGE_CFLAGS) # Checking only a few Irssi headers is enough to tell that everything is # available. This is broken I know but tell that to the irssi guys to NOT use # cluster fu*** of headers and local inclusion system wide... CPPFLAGS="$CPPFLAGS $PACKAGE_CFLAGS -I$IRSSI_HEADER_DIR" AC_CHECK_HEADERS([\ irssi/src/common.h \ irssi/src/core/commands.h \ irssi/src/core/modules.h \ irssi/src/core/servers.h \ irssi/src/core/signals.h \ irssi/src/core/levels.h \ irssi/src/core/queries.h \ irssi/src/core/settings.h \ ], [], [AC_MSG_ERROR([Irssi Header files are needed])], [ #include #ifdef HAVE_IRSSI_SRC_COMMON_H #include #endif ]) LT_INIT CFLAGS="-Wall $CFLAGS -g -fno-strict-aliasing -fstack-protector-all -D_FORTIFY_SOURCE=2 -O1 -Wl,-z,relro,-z,now -fPIE -pie $PACKAGE_CFLAGS" DEFAULT_INCLUDES="-I\$(top_srcdir) -I\$(top_builddir) -I\$(top_builddir)/src -I\$(top_builddir)/include" AC_SUBST(DEFAULT_INCLUDES) # Hardcoded here since irssi only searches in $HOME/.irssi/modules or this path # which is unfortunate... IRSSI_MODULE_DIR="/usr/lib/irssi/modules" AC_SUBST(IRSSI_MODULE_DIR) AC_CONFIG_FILES([ Makefile help/Makefile src/Makefile ]) AC_OUTPUT # # Mini-report on what will be built # AS_ECHO() # Target architecture we're building for target_arch=$host_cpu [ for f in $CFLAGS; do if test $f = "-m32"; then target_arch="32-bit" elif test $f = "-m64"; then target_arch="64-bit" fi done ] AS_ECHO_N("Target architecture: ") AS_ECHO($target_arch) # Print the bindir and libdir this `make install' will install into. AS_ECHO() AS_ECHO_N("Module will be installed in: ") AS_ECHO("`eval eval echo $IRSSI_MODULE_DIR`") AS_ECHO() irssi-plugin-otr-1.0.0/help/000077500000000000000000000000001227701334500156735ustar00rootroot00000000000000irssi-plugin-otr-1.0.0/help/Makefile.am000066400000000000000000000002461227701334500177310ustar00rootroot00000000000000# The day Irssi will be able to check in $(prefix), this will change. Until # then, it's hardcoded. helpdir = /usr/share/irssi/help help_DATA = otr EXTRA_DIST = otr irssi-plugin-otr-1.0.0/help/otr000066400000000000000000000066631227701334500164350ustar00rootroot00000000000000 OTR %|[OPTION] Command to control the OTR module. Without an option, this help is printed. This help contains three sections which are %9options, quickstart and files.%n To add the OTR status bar (highly recommended): %9/statusbar window add otr%n %9Options:%n AUTH Start or respond to an authentication process. AUTHQ [<[question]>] Start a SMP authentication process. The question MUST be enclosed in brackets and followed by the secret with at least one white space between the question and secret. Example: %9/otr authq [My question is] rest is the secret%n AUTHABORT Abort an ongoing authentication process. CONTEXTS List known contexts which basically list the known fingerprints and their state. DEBUG Turn on debugging. DISTRUST [] Distrust a specific fingerprint. This command can be done inside a private window for which the current fingerprint of the other person will be used or else set fp to a human readable OTR fingerprint available with the above contexts command. Examples: %9/otr distrust 487FFADA 5073FEDD C5AB5C14 5BB6C1FF 6D40D48A%n FINISH End the OTR session. This MUST be done inside a private conversation window. FORGET [] Forget a specific fingerprint (deleted from the known fingerprints). The behavior is the same as the distrust command explained above. GENKEY @ Generate OTR keys for a given account name. This is done automatically if someone tries to establish a secure session. This process is done in a background thread and can take an arbitrary amount of time. The completion is checked when another irssi event is catched. Unfortunately, for technical reasons, the thread can't notify the irssi main window so a status check is done at each irssi events and a message is printed if the key is ready. HELP Print this help. INFO Display the OTR fingerprint(s) of all your account(s). INIT Initialize an OTR conversation within a private conversation window. TRUST [] Trust a specific fingerprint. The behavior is the same as the forget and distrust commands explained above. VERSION Print the version of the OTR module. %9Quickstart:%n Start a private conversation with the person you want to initiate a secure session. Once in the private message window: %9/otr init%n Key generation should start if no key is found for your account name. Once the process is done, either type a message which should automatically start the session or redo the init command. Time to authenticate the person. Either use a shared secret exchange through phone or GPG-signed email or use the socialist millionaire problem mechanism (SMP) which is basically to ask a question for which the answer can only be known by the other person. %9/otr auth %n OR %9/otr authq [A question] %n Or to respond to an authentication: %9/otr auth %n %9Files:%n This otr modules creates a directory in %9$HOME/.irssi/otr%n and creates three files: * %9otr.key%n Contains your OTR private key(s). NEVER shared this directory with someone else unless you know what you are doing. * %9otr.fp%n The known fingerprints with their _trust_ status. * %9otr.instag Instance tag of the libotr. This should NEVER be copied to an other computer. If unsure, just ignore this file. For more information on OTR, see http://www.cypherpunks.ca/otr/ irssi-plugin-otr-1.0.0/src/000077500000000000000000000000001227701334500155325ustar00rootroot00000000000000irssi-plugin-otr-1.0.0/src/Makefile.am000066400000000000000000000016771227701334500176010ustar00rootroot00000000000000AM_CFLAGS = $(LIBOTR_CFLAGS) $(LIBGCRYPT_CFLAGS) $(PACKAGE_FLAGS) IRSSI_DIST=/usr/include/irssi IRSSI_INCLUDE = -I$(IRSSI_DIST) \ -I$(IRSSI_DIST)/src \ -I$(IRSSI_DIST)/src/fe-common/core \ -I$(IRSSI_DIST)/src/core \ -I$(IRSSI_DIST)/src/fe-text \ -I$(IRSSI_DIST)/src/irc \ -I$(IRSSI_DIST)/src/irc/core \ -I$(IRSSI_DIST)/src/irc/dcc \ -I$(IRSSI_DIST)/src/irc/notifylist INCLUDES = -I$(top_srcdir)/src $(IRSSI_INCLUDE) plugindir = $(IRSSI_MODULE_DIR) plugin_LTLIBRARIES = libotr.la libotr_la_SOURCES = otr-formats.c otr-formats.h \ key.c key.h cmd.c cmd.h otr.c otr-ops.c \ utils.h utils.c otr.h module.c module.h irssi-otr.h libotr_la_LDFLAGS = -avoid-version -module libotr_la_LDFLAGS += $(LIBOTR_LIBS) $(LIBGCRYPT_LIBS) -lpthread install-data-hook: chmod 644 $(DESTDIR)/$(plugindir)/libotr.so rm $(DESTDIR)/$(plugindir)/libotr.la uninstall-hook: rm $(DESTDIR)/$(plugindir)/libotr.so irssi-plugin-otr-1.0.0/src/cmd.c000066400000000000000000000230651227701334500164470ustar00rootroot00000000000000/* * Off-the-Record Messaging (OTR) modules for IRC * * Copyright (C) 2008 - Uli Meis * 2012 - David Goulet * * 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. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA */ #define _GNU_SOURCE #include #include #include "cmd.h" #include "key.h" /* * /otr debug */ static void _cmd_debug(struct otr_user_state *ustate, SERVER_REC *irssi, const char *target, const void *data) { debug = !debug; if (debug) { IRSSI_INFO(NULL, NULL, "Debug on"); } else { IRSSI_INFO(NULL, NULL, "Debug off"); } } /* * /otr version */ static void _cmd_version(struct otr_user_state *ustate, SERVER_REC *irssi, const char *target, const void *data) { IRSSI_INFO(NULL, NULL, "OTR module version: " VERSION); } /* * /otr help */ static void _cmd_help(struct otr_user_state *ustate, SERVER_REC *irssi, const char *target, const void *data) { int ret; char *cmd_line; ret = asprintf(&cmd_line, "%sHELP otr", settings_get_str("cmdchars")); if (ret < 0) { return; } /* Call /help otr instread of duplicating the text output. */ signal_emit("send command", 3, cmd_line, irssi, NULL); free(cmd_line); } /* * /otr finish */ static void _cmd_finish(struct otr_user_state *ustate, SERVER_REC *irssi, const char *target, const void *data) { if (!irssi || !target) { IRSSI_NOTICE(irssi, target, "Failed: Can't get nick and server of current query window. " "(Or maybe you're doing this in the status window?)"); goto end; } otr_finish(irssi, target); end: return; } /* * /otr trust [FP] */ static void _cmd_trust(struct otr_user_state *ustate, SERVER_REC *irssi, const char *target, const void *data) { int argc; char **argv; char str_fp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN], *fp = NULL; utils_explode_args(data, &argv, &argc); if (argc == 5) { utils_hash_parts_to_readable_hash((const char **) argv, str_fp); fp = str_fp; } else if (!irssi || (irssi && argc != 0)) { /* If no IRSSI or some arguments (not 5), bad command. */ IRSSI_NOTICE(irssi, target, "Usage %9/otr trust [FP]%9 " "where FP is the five part of the fingerprint listed by " "%9/otr contexts%9 or do the command inside an OTR session " "private message window."); goto end; } otr_trust(irssi, target, fp, ustate); end: utils_free_args(&argv, argc); return; } /* * /otr authabort */ static void _cmd_authabort(struct otr_user_state *ustate, SERVER_REC *irssi, const char *target, const void *data) { if (!irssi || !target) { IRSSI_NOTICE(irssi, target, "Failed: Can't get nick and server of current query window. " "(Or maybe you're doing this in the status window?)"); goto end; } otr_auth_abort(irssi, target); end: return; } /* * /otr genkey mynick@irc.server.net */ static void _cmd_genkey(struct otr_user_state *ustate, SERVER_REC *irssi, const char *target, const void *data) { int argc; char **argv; utils_explode_args(data, &argv, &argc); if (argc) { if (strchr(argv[0], '@')) { key_gen_run(ustate, argv[0]); } else { IRSSI_INFO(NULL, NULL, "I need an account name. " "Try something like /otr genkey mynick@irc.server.net"); } } else { IRSSI_INFO(NULL, NULL, "I need an account name. " "Try something like /otr genkey mynick@irc.server.net"); } utils_free_args(&argv, argc); } /* * Authentication with a question. * * /otr authq [QUESTION] SECRET */ static void _cmd_authq(struct otr_user_state *ustate, SERVER_REC *irssi, const char *target, const void *data) { int ret; char *question = NULL, *secret = NULL; if (!irssi || !target) { IRSSI_NOTICE(irssi, target, "Failed: Can't get nick and server of current query window. " "(Or maybe you're doing this in the status window?)"); goto end; } /* * Returns a negative value if the command arguments are not formatted * correctly or missing. Note, an empty question or secret is valid. */ ret = utils_io_extract_smp(data, &question, &secret); if (ret < 0) { IRSSI_NOTICE(irssi, target, "Usage: %9/otr authq [QUESTION] " "SECRET%9"); goto end; } otr_auth(irssi, target, question, secret); free(question); free(secret); end: return; } /* * /otr auth SECRET */ static void _cmd_auth(struct otr_user_state *ustate, SERVER_REC *irssi, const char *target, const void *data) { int ret; char *secret = NULL; if (!irssi || !target) { IRSSI_NOTICE(irssi, target, "Failed: Can't get nick and server of current query window. " "(Or maybe you're doing this in the status window?)"); goto error; } ret = utils_auth_extract_secret(data, &secret); if (ret < 0) { IRSSI_NOTICE(irssi, target, "Huh... I need a secret here James."); goto error; } otr_auth(irssi, target, NULL, secret); free(secret); error: return; } /* * /otr contexts */ static void _cmd_contexts(struct otr_user_state *ustate, SERVER_REC *irssi, const char *target, const void *data) { otr_contexts(ustate); } /* * /otr init */ static void _cmd_init(struct otr_user_state *ustate, SERVER_REC *irssi, const char *target, const void *data) { ConnContext *ctx; /* No server object, just ignore the request */ if (!irssi || !target) { IRSSI_NOTICE(irssi, target, "Failed: Can't get nick and server of current query window. " "(Or maybe you're doing this in the status window?)"); goto end; } ctx = otr_find_context(irssi, target, 0); if (ctx && ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) { IRSSI_NOTICE(irssi, target, "Already secure!"); goto end; } IRSSI_NOTICE(irssi, target, "Initiating OTR session..."); /* * Irssi does not handle well the HTML tag in the default OTR query message * so just send the OTR tag instead. Contact me for a better fix! :) */ irssi_send_message(irssi, target, "?OTRv23?"); end: return; } /* * /otr forget [FP] */ static void _cmd_forget(struct otr_user_state *ustate, SERVER_REC *irssi, const char *target, const void *data) { int argc; char **argv; char str_fp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN], *fp = NULL; utils_explode_args(data, &argv, &argc); if (argc == 5) { utils_hash_parts_to_readable_hash((const char **) argv, str_fp); fp = str_fp; } else if (!irssi || (irssi && argc != 0)) { /* If no IRSSI or some arguments (not 5), bad command. */ IRSSI_NOTICE(irssi, target, "Usage %9/otr forget [FP]%9 " "where FP is the five part of the fingerprint listed by " "%9/otr contexts%9 or do the command inside an OTR session " "private message window"); goto error; } /* Trigger the forget action. */ otr_forget(irssi, target, fp, ustate); error: utils_free_args(&argv, argc); return; } /* * /otr distrust [FP] */ static void _cmd_distrust(struct otr_user_state *ustate, SERVER_REC *irssi, const char *target, const void *data) { int argc; char **argv; char str_fp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN], *fp = NULL; utils_explode_args(data, &argv, &argc); if (argc == 5) { utils_hash_parts_to_readable_hash((const char **) argv, str_fp); fp = str_fp; } else if (!irssi || (irssi && argc != 0)) { /* If no IRSSI or some arguments (not 5), bad command. */ IRSSI_NOTICE(irssi, target, "Usage %9/otr distrust [FP]%9 " "where FP is the five part of the fingerprint listed by " "%9/otr contexts%9 or do the command inside an OTR session " "private message window"); goto error; } /* Trigger the forget action. */ otr_distrust(irssi, target, fp, ustate); error: utils_free_args(&argv, argc); return; } /* * /otr info */ static void _cmd_info(struct otr_user_state *ustate, SERVER_REC *irssi, const char *target, const void *data) { unsigned int fp_found = 0; char ownfp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN]; OtrlPrivKey *key; for (key = user_state_global->otr_state->privkey_root; key != NULL; key = key->next) { otrl_privkey_fingerprint(user_state_global->otr_state, ownfp, key->accountname, OTR_PROTOCOL_ID); IRSSI_NOTICE(irssi, target, "%B%s%n fingerprint:", key->accountname, ownfp); IRSSI_NOTICE(irssi, target, "%g%s%n", ownfp); fp_found = 1; } if (!fp_found) { IRSSI_NOTICE(irssi, target, "No key found!"); } } static struct irssi_commands cmds[] = { { "version", _cmd_version }, { "debug", _cmd_debug }, { "help", _cmd_help }, { "init", _cmd_init }, { "finish", _cmd_finish }, { "trust", _cmd_trust }, { "distrust", _cmd_distrust }, { "forget", _cmd_forget }, { "authabort", _cmd_authabort }, { "auth", _cmd_auth }, { "authq", _cmd_authq }, { "genkey", _cmd_genkey }, { "contexts", _cmd_contexts }, { "info", _cmd_info }, { NULL, NULL }, { NULL, NULL } }; /* * Entry point for all other commands. * * Return TRUE if command exist and is executed else FALSE. */ void cmd_generic(struct otr_user_state *ustate, SERVER_REC *irssi, const char *target, char *cmd, const void *data) { struct irssi_commands *commands = cmds; assert(cmd); do { if (strcmp(commands->name, cmd) == 0) { commands->func(ustate, irssi, target, data); goto end; } } while ((++commands)->name); IRSSI_NOTICE(irssi, target, "Unknown command %9%s%n", cmd); end: return; } irssi-plugin-otr-1.0.0/src/cmd.h000066400000000000000000000026251227701334500164530ustar00rootroot00000000000000/* * Off-the-Record Messaging (OTR) modules for IRC * * Copyright (C) 2008 - Uli Meis * 2012 - David Goulet * * 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. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA */ #ifndef IRSSI_OTR_CMD_H #define IRSSI_OTR_CMD_H #include "otr.h" /* * The /otr commands structure. */ struct irssi_commands { const char *name; void (*func)(struct otr_user_state *ustate, SERVER_REC *irssi, const char *target, const void *data); }; /* * This is called once the command is received and then dispatch to the correct * func() of the right irssi_commands. */ void cmd_generic(struct otr_user_state *ustate, SERVER_REC *irssi, const char *target, char *cmd, const void *data); #endif /* IRSSI_OTR_CMD_H */ irssi-plugin-otr-1.0.0/src/irssi-otr.h000066400000000000000000000060271227701334500176430ustar00rootroot00000000000000/* * Off-the-Record Messaging (OTR) module for the irssi IRC client * * Copyright (C) 2008 - Uli Meis * 2012 - David Goulet * * 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. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA */ #ifndef IRSSI_IRSSI_OTR_H #define IRSSI_IRSSI_OTR_H #define UOFF_T_LONG_LONG 1 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* Ease our life a bit. */ #define get_client_config_dir get_irssi_dir #define IRSSI_CONN_ADDR(i) i->connrec->address #define IRSSI_NICK(i) i->nick #define OTR_IRSSI_MSG_PREFIX "%9OTR%9: " /* * Irssi macros for printing text to console. */ #define IRSSI_MSG(fmt, ...) \ do { \ printtext(NULL, NULL, MSGLEVEL_MSGS, OTR_IRSSI_MSG_PREFIX fmt, \ ## __VA_ARGS__); \ } while (0) #define IRSSI_INFO(irssi, username, fmt, ...) \ do { \ printtext(irssi, username, MSGLEVEL_CRAP, OTR_IRSSI_MSG_PREFIX fmt, \ ## __VA_ARGS__); \ } while (0) #define IRSSI_NOTICE(irssi, username, fmt, ...) \ do { \ printtext(irssi, username, MSGLEVEL_MSGS, OTR_IRSSI_MSG_PREFIX fmt, \ ## __VA_ARGS__); \ } while (0) #define IRSSI_DEBUG(fmt, ...) \ do { \ if (debug) { \ printtext(NULL, NULL, MSGLEVEL_MSGS, OTR_IRSSI_MSG_PREFIX fmt, \ ## __VA_ARGS__); \ } \ } while (0) #endif /* IRSSI_IRSSI_OTR_H */ irssi-plugin-otr-1.0.0/src/key.c000066400000000000000000000166751227701334500165050ustar00rootroot00000000000000/* * Off-the-Record Messaging (OTR) modules for IRC * * Copyright (C) 2008 - Uli Meis * 2012 - David Goulet * * 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. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include "key.h" /* * Key generation data for the thread in charge of creating the key. */ static struct key_gen_data key_gen_state = { .status = KEY_GEN_IDLE, .gcry_error = GPG_ERR_NO_ERROR, }; static pthread_t keygen_thread; /* * Build file path concatenate to the irssi config dir. */ static char *file_path_build(const char *path) { int ret; char *filename; if (!path) { path = ""; } /* Either NULL or the filename is returned here which is valid. */ ret = asprintf(&filename, "%s%s", get_client_config_dir(), path); if (ret < 0) { filename = NULL; } return filename; } /* * Reset key generation state and status is IDLE. */ static void reset_key_gen_state(void) { /* Safety. */ if (key_gen_state.key_file_path) { free(key_gen_state.key_file_path); } /* Pointer dup when key_gen_run is called. */ if (key_gen_state.account_name) { free(key_gen_state.account_name); } /* Nullify everything. */ memset(&key_gen_state, 0, sizeof(key_gen_state)); key_gen_state.status = KEY_GEN_IDLE; key_gen_state.gcry_error = GPG_ERR_NO_ERROR; } /* * Generate OTR key. Thread in the background. * * NOTE: NO irssi interaction should be done here like emitting signals or else * it causes a segfaults of libperl. */ static void *generate_key(void *data) { gcry_error_t err; assert(key_gen_state.newkey); key_gen_state.status = KEY_GEN_RUNNING; err = otrl_privkey_generate_calculate(key_gen_state.newkey); if (err != GPG_ERR_NO_ERROR) { key_gen_state.status = KEY_GEN_ERROR; key_gen_state.gcry_error = err; goto error; } key_gen_state.status = KEY_GEN_FINISHED; error: return NULL; } /* * Check key generation state and print message to user according to state. */ void key_gen_check(void) { gcry_error_t err; switch (key_gen_state.status) { case KEY_GEN_FINISHED: err = otrl_privkey_generate_finish(key_gen_state.ustate->otr_state, key_gen_state.newkey, key_gen_state.key_file_path); if (err != GPG_ERR_NO_ERROR) { IRSSI_MSG("Key generation finish state failed. Err: %s", gcry_strerror(err)); } else { IRSSI_MSG("Key generation for %9%s%n completed", key_gen_state.account_name); } reset_key_gen_state(); break; case KEY_GEN_ERROR: IRSSI_MSG("Key generation for %9%s%n failed. Err: %s (%d)", key_gen_state.account_name, gcry_strerror(key_gen_state.gcry_error), key_gen_state.gcry_error); reset_key_gen_state(); break; case KEY_GEN_RUNNING: case KEY_GEN_IDLE: /* Do nothing */ break; }; } /* * Run key generation in a seperate process (takes ages). The other process * will rewrite the key file, we shouldn't change anything till it's done and * we've reloaded the keys. */ void key_gen_run(struct otr_user_state *ustate, const char *account_name) { int ret; gcry_error_t err; assert(ustate); assert(account_name); if (key_gen_state.status != KEY_GEN_IDLE) { IRSSI_INFO(NULL, NULL, "Key generation for %s is still in progress. ", "Please wait until completion before creating a new key.", key_gen_state.account_name); goto error_status; } /* Make sure the pointer does not go away during the proess. */ key_gen_state.account_name = strdup(account_name); key_gen_state.ustate = ustate; /* Creating key file path. */ key_gen_state.key_file_path = file_path_build(OTR_KEYFILE); if (!key_gen_state.key_file_path) { IRSSI_INFO(NULL, NULL, "Key generation failed. ENOMEM"); goto error; } IRSSI_MSG("Key generation started for %9%s%n", key_gen_state.account_name); err = otrl_privkey_generate_start(ustate->otr_state, account_name, OTR_PROTOCOL_ID, &key_gen_state.newkey); if (err != GPG_ERR_NO_ERROR || !key_gen_state.newkey) { IRSSI_MSG("Key generation start failed. Err: %s", gcry_strerror(err)); goto error; } ret = pthread_create(&keygen_thread, NULL, generate_key, NULL); if (ret < 0) { IRSSI_MSG("Key generation failed. Thread failure: %s", strerror(errno)); goto error; } return; error: reset_key_gen_state(); error_status: return; } /* * Write fingerprints to file. */ void key_write_fingerprints(struct otr_user_state *ustate) { gcry_error_t err; char *filename; assert(ustate); filename = file_path_build(OTR_FINGERPRINTS_FILE); if (!filename) { goto error_filename; } err = otrl_privkey_write_fingerprints(ustate->otr_state, filename); if (err == GPG_ERR_NO_ERROR) { IRSSI_DEBUG("Fingerprints saved to %9%s%9", filename); } else { IRSSI_DEBUG("Error writing fingerprints: %d (%d)", gcry_strerror(err), gcry_strsource(err)); } free(filename); error_filename: return; } /* * Write instance tags to file. */ void key_write_instags(struct otr_user_state *ustate) { gcry_error_t err; char *filename; assert(ustate); filename = file_path_build(OTR_INSTAG_FILE); if (!filename) { goto error_filename; } err = otrl_instag_write(ustate->otr_state, filename); if (err == GPG_ERR_NO_ERROR) { IRSSI_DEBUG("Instance tags saved in %9%s%9", filename); } else { IRSSI_DEBUG("Error saving instance tags: %d (%d)", gcry_strerror(err), gcry_strsource(err)); } free(filename); error_filename: return; } /* * Load private keys. */ void key_load(struct otr_user_state *ustate) { int ret; gcry_error_t err; char *filename; assert(ustate); filename = file_path_build(OTR_KEYFILE); if (!filename) { goto error_filename; } ret = access(filename, F_OK); if (ret < 0) { IRSSI_DEBUG("No private keys found in %9%s%9", filename); goto end; } err = otrl_privkey_read(ustate->otr_state, filename); if (err == GPG_ERR_NO_ERROR) { IRSSI_DEBUG("Private keys loaded from %9%s%9", filename); } else { IRSSI_DEBUG("Error loading private keys: %d (%d)", gcry_strerror(err), gcry_strsource(err)); } end: free(filename); error_filename: return; } /* * Load fingerprints. */ void key_load_fingerprints(struct otr_user_state *ustate) { int ret; gcry_error_t err; char *filename; assert(ustate); filename = file_path_build(OTR_FINGERPRINTS_FILE); if (!filename) { goto error_filename; } ret = access(filename, F_OK); if (ret < 0) { IRSSI_DEBUG("No fingerprints found in %9%s%9", filename); goto end; } err = otrl_privkey_read_fingerprints(ustate->otr_state, filename, NULL, NULL); if (err == GPG_ERR_NO_ERROR) { IRSSI_DEBUG("Fingerprints loaded from %9%s%9", filename); } else { IRSSI_DEBUG("Error loading fingerprints: %d (%d)", gcry_strerror(err), gcry_strsource(err)); } end: free(filename); error_filename: return; } irssi-plugin-otr-1.0.0/src/key.h000066400000000000000000000031311227701334500164710ustar00rootroot00000000000000/* * Off-the-Record Messaging (OTR) modules for IRC * * Copyright (C) 2012 - David Goulet * * 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. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA */ #ifndef IRSSI_OTR_KEY_H #define IRSSI_OTR_KEY_H #include "otr.h" /* * Status of key generation. */ enum key_gen_status { KEY_GEN_IDLE = 0, KEY_GEN_RUNNING = 1, KEY_GEN_FINISHED = 2, KEY_GEN_ERROR = 3, }; /* * Data of the state of key generation. */ struct key_gen_data { struct otr_user_state *ustate; char *account_name; char *key_file_path; enum key_gen_status status; gcry_error_t gcry_error; void *newkey; }; void key_gen_check(void); void key_gen_run(struct otr_user_state *ustate, const char *account_name); void key_load(struct otr_user_state *ustate); void key_load_fingerprints(struct otr_user_state *ustate); void key_write_fingerprints(struct otr_user_state *ustate); void key_write_instags(struct otr_user_state *ustate); #endif /* IRSSI_OTR_KEY_H */ irssi-plugin-otr-1.0.0/src/module.c000066400000000000000000000200041227701334500171570ustar00rootroot00000000000000/* * Off-the-Record Messaging (OTR) module for the irssi IRC client * * Copyright (C) 2008 Uli Meis * 2012 David Goulet * * 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. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA */ #define _GNU_SOURCE #include #include #include #include #include #include #include "cmd.h" #include "key.h" #include "otr.h" #include "otr-formats.h" #include "utils.h" GCRY_THREAD_OPTION_PTHREAD_IMPL; static const char *signal_args_otr_event[] = { "iobject", "string", "string", NULL }; int debug = FALSE; /* * Need this to decode arguments in perl signal handlers. Maybe irssi should * install perl/perl-signals.h which is where this definition comes from? */ void perl_signal_register(const char *signal, const char **args); /* * Global state for the user. Init when the module loads. */ struct otr_user_state *user_state_global; /* * Pipes all outgoing private messages through OTR */ static void sig_server_sendmsg(SERVER_REC *server, const char *target, const char *msg, void *target_type_p) { int ret; char *otrmsg = NULL; key_gen_check(); if (GPOINTER_TO_INT(target_type_p) != SEND_TARGET_NICK) { goto end; } /* Critical section. On error, message MUST NOT be sent */ ret = otr_send(server, msg, target, &otrmsg); if (ret) { signal_stop(); goto end; } if (!otrmsg) { /* Send original message */ signal_continue(4, server, target, msg, target_type_p); } else { /* Send encrypted message */ signal_continue(4, server, target, otrmsg, target_type_p); } end: otrl_message_free(otrmsg); return; } /* * Pipes all incoming private messages through OTR */ void sig_message_private(SERVER_REC *server, const char *msg, const char *nick, const char *address) { int ret; char *new_msg = NULL; key_gen_check(); ret = otr_receive(server, msg, nick, &new_msg); if (ret) { signal_stop(); goto end; } if (!new_msg) { /* This message was not OTR */ signal_continue(4, server, msg, nick, address); } else { /* * Check for /me IRC marker and if so, handle it so the user does not * receive a message beginning with /me but rather let irssi handle it * as a IRC action. */ if (!strncmp(new_msg, OTR_IRC_MARKER_ME, OTR_IRC_MARKER_ME_LEN)) { signal_stop(); signal_emit("message irc action", 5, server, new_msg + OTR_IRC_MARKER_ME_LEN, nick, address, nick); } else { /* OTR received message */ signal_continue(4, server, new_msg, nick, address); } } end: otrl_message_free(new_msg); return; } /* * Finish an OTR conversation when its query is closed. */ static void sig_query_destroyed(QUERY_REC *query) { if (query && query->server && query->server->connrec) { otr_finish(query->server, query->name); } } /* * Handle /me IRC command. */ static void cmd_me(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item) { int ret; const char *target; char *msg, *otrmsg = NULL; QUERY_REC *query; query = QUERY(item); key_gen_check(); if (!query || !query->server) { goto end; } CMD_IRC_SERVER(server); if (!IS_IRC_QUERY(query)) { goto end; } if (!server || !server->connected) { cmd_return_error(CMDERR_NOT_CONNECTED); } target = window_item_get_target(item); ret = asprintf(&msg, OTR_IRC_MARKER_ME "%s", data); if (ret < 0) { goto end; } /* Critical section. On error, message MUST NOT be sent */ ret = otr_send(query->server, msg, target, &otrmsg); free(msg); if (!otrmsg) { goto end; } signal_stop(); if (otrmsg) { /* Send encrypted message */ irssi_send_message(SERVER(server), target, otrmsg); otrl_message_free(otrmsg); } signal_emit("message irc own_action", 3, server, data, item->visible_name); end: return; } /* * Handle the "/otr" command. */ static void cmd_otr(const char *data, void *server, WI_ITEM_REC *item) { char *cmd = NULL; QUERY_REC *query; query = QUERY(item); /* Check key generation state. */ key_gen_check(); if (*data == '\0') { IRSSI_INFO(NULL, NULL, "Alive!"); goto end; } utils_extract_command(data, &cmd); if (!cmd) { /* ENOMEM and cmd is untouched. */ goto end; } if (query && query->server && query->server->connrec) { cmd_generic(user_state_global, query->server, query->name, cmd, data); } else { cmd_generic(user_state_global, NULL, NULL, cmd, data); } statusbar_items_redraw("otr"); free(cmd); end: return; } /* * Optionally finish conversations on /quit. We're already doing this on unload * but the quit handler terminates irc connections before unloading. */ static void cmd_quit(const char *data, void *server, WI_ITEM_REC *item) { otr_finishall(user_state_global); } /* * Handle otr statusbar of irssi. */ static void otr_statusbar(struct SBAR_ITEM_REC *item, int get_size_only) { WI_ITEM_REC *wi = active_win->active; QUERY_REC *query = QUERY(wi); enum otr_status_format formatnum = TXT_OTR_MODULE_NAME; if (query && query->server && query->server->connrec) { formatnum = otr_get_status_format(query->server, query->name); } statusbar_item_default_handler(item, get_size_only, formatnum ? otr_formats[formatnum].def : "", " ", FALSE); } /* * Create otr module directory if none exists. */ static int create_module_dir(void) { int ret; char *dir_path = NULL; /* Create ~/.irssi/otr directory. */ ret = asprintf(&dir_path, "%s%s", get_client_config_dir(), OTR_DIR); if (ret < 0) { IRSSI_MSG("Unable to allocate home dir path."); goto error_alloc; } ret = access(dir_path, F_OK); if (ret < 0) { ret = mkdir(dir_path, S_IRWXU); if (ret < 0) { IRSSI_MSG("Unable to create %s directory.", dir_path); goto error; } } error: free(dir_path); error_alloc: return ret; } void irssi_send_message(SERVER_REC *irssi, const char *recipient, const char *msg) { assert(irssi); irssi->send_message(irssi, recipient, msg, GPOINTER_TO_INT(SEND_TARGET_NICK)); } /* * irssi init() */ void otr_init(void) { int ret; module_register(MODULE_NAME, "core"); theme_register(otr_formats); ret = create_module_dir(); if (ret < 0) { return; } gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); otr_lib_init(); user_state_global = otr_init_user_state(); if (!user_state_global) { IRSSI_MSG("Unable to allocate user global state"); return; } signal_add_first("server sendmsg", (SIGNAL_FUNC) sig_server_sendmsg); signal_add_first("message private", (SIGNAL_FUNC) sig_message_private); signal_add("query destroyed", (SIGNAL_FUNC) sig_query_destroyed); command_bind("otr", NULL, (SIGNAL_FUNC) cmd_otr); command_bind_first("quit", NULL, (SIGNAL_FUNC) cmd_quit); command_bind_irc_first("me", NULL, (SIGNAL_FUNC) cmd_me); statusbar_item_register("otr", NULL, otr_statusbar); statusbar_items_redraw("window"); perl_signal_register("otr event", signal_args_otr_event); } /* * irssi deinit() */ void otr_deinit(void) { signal_remove("server sendmsg", (SIGNAL_FUNC) sig_server_sendmsg); signal_remove("message private", (SIGNAL_FUNC) sig_message_private); signal_remove("query destroyed", (SIGNAL_FUNC) sig_query_destroyed); command_unbind("otr", (SIGNAL_FUNC) cmd_otr); command_unbind("quit", (SIGNAL_FUNC) cmd_quit); command_unbind("me", (SIGNAL_FUNC) cmd_me); statusbar_item_unregister("otr"); otr_finishall(user_state_global); /* Remove glib timer if any. */ otr_control_timer(0, NULL); otr_free_user_state(user_state_global); otr_lib_uninit(); theme_unregister(); } irssi-plugin-otr-1.0.0/src/module.h000066400000000000000000000020171227701334500171700ustar00rootroot00000000000000/* * Off-the-Record Messaging (OTR) module for the irssi IRC client * * Copyright (C) 2012 - David Goulet * * 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. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA */ #ifndef IRSSI_OTR_MODULE #define IRSSI_OTR_MODULE void sig_message_private(SERVER_REC *server, const char *msg, const char *nick, const char *address); #endif /* IRSSI_OTR_MODULE */ irssi-plugin-otr-1.0.0/src/otr-formats.c000066400000000000000000000023761227701334500201630ustar00rootroot00000000000000/* * Off-the-Record Messaging (OTR) modules for IRC * * Copyright (C) - 2012 David Goulet * * 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. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA */ #include "otr.h" #include "otr-formats.h" FORMAT_REC otr_formats[] = { { MODULE_NAME, "OTR", 0 }, /* Status bar format. */ { NULL, "Statusbar", 0 } , { "stb_plaintext", "{sb plaintext}", 0}, { "stb_finished", "{sb %yfinished%n}", 0}, { "stb_unknown", "{sb {hilight state unknown (BUG!)}}", 0}, { "stb_untrusted", "{sb %GOTR%n (%runverified%n)}", 0}, { "stb_trust", "{sb %GOTR%n}", 0}, /* Last element. */ { NULL, NULL, 0 } }; irssi-plugin-otr-1.0.0/src/otr-formats.h000066400000000000000000000024061227701334500201620ustar00rootroot00000000000000/* * Off-the-Record Messaging (OTR) modules for IRC * * Copyright (C) - 2012 David Goulet * * 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. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA */ #ifndef IRSSI_OTR_FORMATS_H #define IRSSI_OTR_FORMATS_H #include "irssi-otr.h" /* * Must be in sync with the otr_formats array. */ enum otr_status_format { TXT_OTR_MODULE_NAME = 0, TXT_OTR_FILL_1 = 1, TXT_STB_PLAINTEXT = 2, TXT_STB_FINISHED = 3, TXT_STB_UNKNOWN = 4, TXT_STB_UNTRUSTED = 5, TXT_STB_TRUST = 6, }; extern FORMAT_REC otr_formats[]; #endif /* IRSSI_OTR_FORMATS_H */ irssi-plugin-otr-1.0.0/src/otr-ops.c000066400000000000000000000263501227701334500173070ustar00rootroot00000000000000/* * Off-the-Record Messaging (OTR) modules for IRC * Copyright (C) 2008 Uli Meis * * 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. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA */ #include #include "key.h" #include "module.h" static OtrlPolicy OTR_DEFAULT_POLICY = OTRL_POLICY_MANUAL | OTRL_POLICY_WHITESPACE_START_AKE; /* * Return default policy for now. */ static OtrlPolicy ops_policy(void *opdata, ConnContext *context) { return OTR_DEFAULT_POLICY; } /* * Request for key generation. * * The lib actually expects us to be finished before the call returns. Since * this can take more than an hour on some systems there isn't even a point in * trying... */ static void ops_create_privkey(void *opdata, const char *accountname, const char *protocol) { key_gen_run(user_state_global, accountname); } /* * Inject OTR message. */ static void ops_inject_msg(void *opdata, const char *accountname, const char *protocol, const char *recipient, const char *message) { SERVER_REC *irssi = opdata; IRSSI_DEBUG("Inject msg:\n[%s]", message); irssi_send_message(irssi, recipient, message); } /* * Gone secure. */ static void ops_secure(void *opdata, ConnContext *context) { int ret; char ownfp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN]; char peerfp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN]; SERVER_REC *irssi = opdata; struct otr_peer_context *opc; assert(context); /* This should *really* not happened */ assert(context->msgstate == OTRL_MSGSTATE_ENCRYPTED); IRSSI_NOTICE(irssi, context->username, "Gone %9secure%9"); otr_status_change(irssi, context->username, OTR_STATUS_GONE_SECURE); opc = context->app_data; opc->active_fingerprint = context->active_fingerprint; ret = otrl_context_is_fingerprint_trusted(context->active_fingerprint); if (ret) { /* Secure and trusted */ goto end; } /* Not authenticated. Let's print out the fingerprints for comparison. */ otrl_privkey_hash_to_human(peerfp, context->active_fingerprint->fingerprint); otrl_privkey_fingerprint(user_state_global->otr_state, ownfp, context->accountname, OTR_PROTOCOL_ID); IRSSI_NOTICE(irssi, context->username, "Your peer is not " "authenticated. To make sure you're talking to the right person you can " "either agree on a secret and use the authentication command " "%9/otr auth%9 or %9/otr authq [QUESTION] SECRET%9. You can also " "use the traditional way and compare fingerprints " "(e.g. telephone or GPG-signed mail) and subsequently enter " "%9/otr trust%9."); IRSSI_NOTICE(irssi, context->username, "Your fingerprint is: %y%s%n", ownfp); IRSSI_NOTICE(irssi, context->username, "%9%s's%9 fingerprint is: %r%s%n", context->username, peerfp); end: return; } /* * Gone insecure. */ static void ops_insecure(void *opdata, ConnContext *context) { SERVER_REC *irssi = opdata; IRSSI_NOTICE(irssi, context->username, "Gone %rinsecure%r"); otr_status_change(irssi, context->username, OTR_STATUS_GONE_INSECURE); } /* * Really critical with IRC. Unfortunately, we can't tell our peer which size * to use. */ static int ops_max_msg(void *opdata, ConnContext *context) { return OTR_MAX_MSG_SIZE; } static void ops_handle_msg_event(void *opdata, OtrlMessageEvent msg_event, ConnContext *context, const char *message, gcry_error_t err) { SERVER_REC *server = opdata; char *username = context->username; switch (msg_event) { case OTRL_MSGEVENT_NONE: break; case OTRL_MSGEVENT_ENCRYPTION_REQUIRED: IRSSI_NOTICE(server, username, "%yEncryption is required.%n"); break; case OTRL_MSGEVENT_ENCRYPTION_ERROR: IRSSI_NOTICE(server, username, "An error occurred when " "encrypting your message. The message was NOT sent."); break; case OTRL_MSGEVENT_CONNECTION_ENDED: IRSSI_NOTICE(server, username, "%9%s%9 has already closed the " "connection to you.", username); break; case OTRL_MSGEVENT_SETUP_ERROR: if (!err) { err = GPG_ERR_INV_VALUE; } switch (err) { case GPG_ERR_INV_VALUE: IRSSI_NOTICE(server, username, "Error setting up private " "conversation: Malformed message received"); break; default: IRSSI_NOTICE(server, username, "Error up private " "conversation: %s", gcry_strerror(err)); break; } break; case OTRL_MSGEVENT_MSG_REFLECTED: IRSSI_NOTICE(server, username, "Receiving our own OTR messages. " "You are either trying to talk to yourself, or someone is " "reflecting your messages back at you."); break; case OTRL_MSGEVENT_MSG_RESENT: IRSSI_NOTICE(server, username, "The last message to %9%s%9 " "was resent: %s", username, message); break; case OTRL_MSGEVENT_RCVDMSG_NOT_IN_PRIVATE: IRSSI_NOTICE(server, username, "The encrypted message received " "from %s is unreadable, as you are not currently communicating " "privately.", username); break; case OTRL_MSGEVENT_RCVDMSG_UNREADABLE: IRSSI_NOTICE(server, username, "We received an unreadable " "encrypted message from %s.", username); break; case OTRL_MSGEVENT_RCVDMSG_MALFORMED: IRSSI_NOTICE(server, username, "We received a malformed data " "message from %s.", username); break; case OTRL_MSGEVENT_LOG_HEARTBEAT_RCVD: IRSSI_DEBUG("Heartbeat received from %s.", username); break; case OTRL_MSGEVENT_LOG_HEARTBEAT_SENT: IRSSI_DEBUG("Heartbeat sent to %s.", username); break; case OTRL_MSGEVENT_RCVDMSG_GENERAL_ERR: IRSSI_NOTICE(server, username, "General Error: %s.", message); break; case OTRL_MSGEVENT_RCVDMSG_UNENCRYPTED: IRSSI_NOTICE(server, username, "The following message from %9%s%9 was NOT " "encrypted.", username); /* * This is a hack I found to send the message in a private window of * the username without creating an infinite loop since the 'message * private' signal is hijacked in this module. If someone is able to * clean this up with a more elegant solution, by all means PLEASE * submit a patch or email me a better way. */ signal_remove("message private", (SIGNAL_FUNC) sig_message_private); signal_emit("message private", 4, server, message, username, IRSSI_CONN_ADDR(server)); signal_add_first("message private", (SIGNAL_FUNC) sig_message_private); break; case OTRL_MSGEVENT_RCVDMSG_UNRECOGNIZED: IRSSI_NOTICE(server, username, "Unrecognized OTR message " "received from %s.", username); break; case OTRL_MSGEVENT_RCVDMSG_FOR_OTHER_INSTANCE: IRSSI_DEBUG("%s has sent a message for a different instance.", username); break; } } /* * A context changed. */ static void ops_up_ctx_list(void *opdata) { otr_status_change(opdata, NULL, OTR_STATUS_CTX_UPDATE); } /* * Save fingerprint changes. */ static void ops_write_fingerprints(void *data) { key_write_fingerprints(user_state_global); } static int ops_is_logged_in(void *opdata, const char *accountname, const char *protocol, const char *recipient) { int ret; SERVER_REC *irssi = opdata; if (irssi) { /* Logged in */ ret = 1; } else { /* Not */ ret = 0; } IRSSI_DEBUG("User %s %s logged in", accountname, (ret == 0) ? "not" : ""); return ret; } static void ops_create_instag(void *opdata, const char *accountname, const char *protocol) { otrl_instag_generate(user_state_global->otr_state, "/dev/null", accountname, protocol); key_write_instags(user_state_global); } static void ops_smp_event(void *opdata, OtrlSMPEvent smp_event, ConnContext *context, unsigned short progress_percent, char *question) { SERVER_REC *irssi = opdata; const char *from = context->username; struct otr_peer_context *opc = context->app_data; /* * Without a peer context, we can't update the status bar. Code flow error * if none is found. This context is created automatically by an otrl_* * call or if non existent when returned from * otrl_message_sending/receiving. */ assert(opc); opc->smp_event = smp_event; switch (smp_event) { case OTRL_SMPEVENT_ASK_FOR_SECRET: IRSSI_NOTICE(irssi, from, "%9%s%9 wants to authenticate. " "Type %9/otr auth %9 to complete.", from); opc->ask_secret = 1; otr_status_change(irssi, from, OTR_STATUS_SMP_INCOMING); break; case OTRL_SMPEVENT_ASK_FOR_ANSWER: IRSSI_NOTICE(irssi, from, "%9%s%9 wants to authenticate and " "asked this question:", from); IRSSI_NOTICE(irssi, from, "%b>%n %y%s%n", question); IRSSI_NOTICE(irssi, from, "Type %9/otr auth %9 to complete."); opc->ask_secret = 1; otr_status_change(irssi, from, OTR_STATUS_SMP_INCOMING); break; case OTRL_SMPEVENT_IN_PROGRESS: IRSSI_NOTICE(irssi, from, "%9%s%9 replied to your auth request", from); otr_status_change(irssi, from, OTR_STATUS_SMP_FINALIZE); break; case OTRL_SMPEVENT_SUCCESS: IRSSI_NOTICE(irssi, from, "%gAuthentication successful.%n"); otr_status_change(irssi, from, OTR_STATUS_SMP_SUCCESS); break; case OTRL_SMPEVENT_ABORT: otr_auth_abort(irssi, context->username); otr_status_change(irssi, from, OTR_STATUS_SMP_ABORTED); break; case OTRL_SMPEVENT_FAILURE: case OTRL_SMPEVENT_CHEATED: case OTRL_SMPEVENT_ERROR: IRSSI_NOTICE(irssi, from, "%RAuthentication failed%n"); otr_status_change(irssi, from, OTR_STATUS_SMP_FAILED); break; default: IRSSI_NOTICE(irssi, from, "Received unknown SMP event. " "Ignoring"); break; } } /* * timer_control callback. */ static void ops_timer_control(void *opdata, unsigned int interval) { otr_control_timer(interval, opdata); } /* * Handle otr error message. */ static const char *ops_otr_error_message(void *opdata, ConnContext *context, OtrlErrorCode code) { char *msg = NULL; switch (code) { case OTRL_ERRCODE_NONE: break; case OTRL_ERRCODE_ENCRYPTION_ERROR: msg = strdup("Error occurred encrypting message."); break; case OTRL_ERRCODE_MSG_NOT_IN_PRIVATE: if (context) { msg = strdup("You sent encrypted data which was unexpected"); } break; case OTRL_ERRCODE_MSG_UNREADABLE: msg = strdup("You transmitted an unreadable encrypted message"); break; case OTRL_ERRCODE_MSG_MALFORMED: msg = strdup("You transmitted a malformed data message."); break; } return msg; } /* * Free otr error message callback. */ static void ops_otr_error_message_free(void *opdata, const char *err_msg) { if (err_msg) { free((char *)err_msg); } } /* * Assign OTR message operations. */ OtrlMessageAppOps otr_ops = { ops_policy, ops_create_privkey, ops_is_logged_in, ops_inject_msg, ops_up_ctx_list, NULL, /* new_fingerprint */ ops_write_fingerprints, ops_secure, ops_insecure, NULL, /* still_secure */ ops_max_msg, NULL, /* account_name */ NULL, /* account_name_free */ NULL, /* received_symkey */ ops_otr_error_message, ops_otr_error_message_free, NULL, /* resent_msg_prefix */ NULL, /* resent_msg_prefix_free */ ops_smp_event, ops_handle_msg_event, ops_create_instag, NULL, /* convert_msg */ NULL, /* convert_free */ ops_timer_control, }; irssi-plugin-otr-1.0.0/src/otr.c000066400000000000000000000621651227701334500165140ustar00rootroot00000000000000/* * Off-the-Record Messaging (OTR) modules for IRC * * Copyright (C) 2008 - Uli Meis * 2012 - David Goulet * * 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. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA */ #define _GNU_SOURCE #include #include #include #include "otr-formats.h" #include "key.h" static const char *statusbar_txt[] = { "FINISHED", "TRUST_MANUAL", "TRUST_SMP", "SMP_ABORT", "SMP_STARTED", "SMP_RESPONDED", "SMP_INCOMING", "SMP_FINALIZE", "SMP_ABORTED", "PEER_FINISHED", "SMP_FAILED", "SMP_SUCCESS", "GONE_SECURE", "GONE_INSECURE", "CTX_UPDATE" }; /* Glib timer for otr. */ static guint otr_timerid; /* * Allocate and return a string containing the account name of the Irssi server * record. * * Return: nick@myserver.net */ static char *create_account_name(SERVER_REC *irssi) { int ret; char *accname; assert(irssi); /* Valid or NULL, the caller should handle this */ ret = asprintf(&accname, "%s@%s", IRSSI_NICK(irssi), IRSSI_CONN_ADDR(irssi)); if (ret < 0) { IRSSI_INFO(NULL, NULL, "Unable to allocate account name."); /* * As stated in asprintf(3), if an error occurs, the contents of the * passed pointer is undefined. Force it to NULL here. */ accname = NULL; } return accname; } /* * Load instance tags. */ static void instag_load(struct otr_user_state *ustate) { int ret; char *filename; gcry_error_t err; assert(ustate); /* Getting the otr instance filename path */ ret = asprintf(&filename, "%s%s", get_client_config_dir(), OTR_INSTAG_FILE); if (ret < 0) { goto error_filename; } ret = access(filename, F_OK); if (ret < 0) { IRSSI_DEBUG("no instance tags found at %9%s%9", filename); goto end; } err = otrl_instag_read(ustate->otr_state, filename); if (err == GPG_ERR_NO_ERROR) { IRSSI_DEBUG("Instance tags loaded from %9%s%9", filename); } else { IRSSI_DEBUG("Error loading instance tags: %d (%d)", gcry_strerror(err), gcry_strsource(err)); } end: free(filename); error_filename: return; } /* * Free otr peer context. Callback passed to libotr. */ static void destroy_peer_context_cb(void *data) { struct otr_peer_context *opc = data; if (opc) { free(opc); } IRSSI_DEBUG("Peer context freed"); } /* * Allocate otr peer context. Callback passed to libotr. */ static void add_peer_context_cb(void *data, ConnContext *context) { struct otr_peer_context *opc; opc = otr_create_peer_context(); if (!opc) { return; } opc->active_fingerprint = context->active_fingerprint; context->app_data = opc; context->app_data_free = destroy_peer_context_cb; IRSSI_DEBUG("Peer context created for %s", context->username); } /* * Find Irssi server record by account name. */ static SERVER_REC *find_irssi_by_account_name(const char *accname) { GSList *tmp; size_t nick_len; char *address, *nick = NULL; SERVER_REC *server, *srv = NULL; assert(accname); address = strchr(accname, '@'); if (!address) { goto error; } /* Calculate the nickname length. */ nick_len = address - accname; /* Allocate right size for the nickname plus the NULL terminated byte. */ nick = malloc(nick_len + 1); if (!nick) { /* ENOMEM */ goto error; } /* Get the nick from the account name. */ strncpy(nick, accname, nick_len); nick[nick_len] = '\0'; /* Move after the @ */ address++; for (tmp = servers; tmp; tmp = tmp->next) { server = tmp->data; if (g_ascii_strncasecmp(server->connrec->address, address, strlen(server->connrec->address)) == 0 && strncmp(server->nick, nick, strlen(nick)) == 0) { srv = server; break; } } free(nick); error: return srv; } /* * Check if fingerprint is in an encrypted context. * * Return 1 if it does, else 0. */ static int check_fp_encrypted_msgstate(Fingerprint *fp) { int ret; ConnContext *context; assert(fp); /* Loop on all fingerprint's context(es). */ for (context = fp->context; context != NULL && context->m_context == fp->context; context = context->next) { if (context->msgstate == OTRL_MSGSTATE_ENCRYPTED && context->active_fingerprint == fp) { ret = 1; goto end; } } /* No state is encrypted. */ ret = 0; end: return ret; } /* * Timer called from the glib main loop and set up by the timer_control * callback of libotr. */ static gboolean timer_fired_cb(gpointer data) { otrl_message_poll(user_state_global->otr_state, &otr_ops, NULL); return TRUE; } void otr_control_timer(unsigned int interval, void *opdata) { if (otr_timerid) { g_source_remove(otr_timerid); otr_timerid = 0; } if (interval > 0) { otr_timerid = g_timeout_add_seconds(interval, timer_fired_cb, opdata); } } /* * Find context from nickname and irssi server record. */ ConnContext *otr_find_context(SERVER_REC *irssi, const char *nick, int create) { char *accname = NULL; ConnContext *ctx = NULL; assert(irssi); assert(nick); accname = create_account_name(irssi); if (!accname) { goto error; } ctx = otrl_context_find(user_state_global->otr_state, nick, accname, OTR_PROTOCOL_ID, OTRL_INSTAG_BEST, create, NULL, add_peer_context_cb, irssi); free(accname); error: return ctx; } /* * Create otr peer context. */ struct otr_peer_context *otr_create_peer_context(void) { return zmalloc(sizeof(struct otr_peer_context)); } /* * Return a newly allocated OTR user state. */ struct otr_user_state *otr_init_user_state(void) { struct otr_user_state *ous = NULL; ous = zmalloc(sizeof(*ous)); if (!ous) { goto error; } ous->otr_state = otrl_userstate_create(); instag_load(ous); /* Load keys and fingerprints. */ key_load(ous); key_load_fingerprints(ous); error: return ous; } /* * Destroy otr user state. */ void otr_free_user_state(struct otr_user_state *ustate) { if (ustate->otr_state) { otrl_userstate_free(ustate->otr_state); ustate->otr_state = NULL; } free(ustate); } /* * init otr lib. */ void otr_lib_init() { OTRL_INIT; } /* * deinit otr lib. */ void otr_lib_uninit() { } /* * Hand the given message to OTR. * * Return 0 if the message was successfully handled or else a negative value. */ int otr_send(SERVER_REC *irssi, const char *msg, const char *to, char **otr_msg) { gcry_error_t err; char *accname = NULL; ConnContext *ctx = NULL; assert(irssi); accname = create_account_name(irssi); if (!accname) { goto error; } IRSSI_DEBUG("Sending message..."); err = otrl_message_sending(user_state_global->otr_state, &otr_ops, irssi, accname, OTR_PROTOCOL_ID, to, OTRL_INSTAG_BEST, msg, NULL, otr_msg, OTRL_FRAGMENT_SEND_ALL_BUT_LAST, &ctx, add_peer_context_cb, irssi); if (err) { IRSSI_NOTICE(irssi, to, "Send failed."); goto error; } IRSSI_DEBUG("Message sent..."); /* Add peer context to OTR context if none exists. */ if (ctx && !ctx->app_data) { add_peer_context_cb(irssi, ctx); } free(accname); return 0; error: free(accname); return -1; } /* * List otr contexts to the main Irssi windows. */ void otr_contexts(struct otr_user_state *ustate) { char human_fp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN], *trust; ConnContext *ctx, *c_iter; Fingerprint *fp; assert(ustate); if (!ustate->otr_state->context_root) { IRSSI_INFO(NULL, NULL, "No active OTR contexts found"); goto end; } IRSSI_MSG("[ %KUser%n - %KAccount%n - %KStatus%n - %KFingerprint%n - " "%KTrust%n ]"); /* Iterate over all contextes of the user state. */ for (ctx = ustate->otr_state->context_root; ctx != NULL; ctx = ctx->next) { OtrlMessageState best_mstate = OTRL_MSGSTATE_PLAINTEXT; /* Skip master context. */ if (ctx != ctx->m_context) { continue; } for (fp = ctx->fingerprint_root.next; fp != NULL; fp = fp->next) { int used = 0; char *username, *accountname; username = ctx->username; accountname = ctx->accountname; for (c_iter = ctx->m_context; c_iter && c_iter->m_context == ctx->m_context; c_iter = c_iter->next) { /* Print account name, username and msgstate. */ if (c_iter->active_fingerprint == fp) { used = 1; if (c_iter->msgstate == OTRL_MSGSTATE_ENCRYPTED) { best_mstate = OTRL_MSGSTATE_ENCRYPTED; } else if (c_iter->msgstate == OTRL_MSGSTATE_FINISHED && best_mstate == OTRL_MSGSTATE_PLAINTEXT) { best_mstate = OTRL_MSGSTATE_FINISHED; } } } if (used) { switch (best_mstate) { case OTRL_MSGSTATE_ENCRYPTED: IRSSI_MSG("%b>%n %9%s%9 - %B%s%n - %GEncrypted%n -", accountname, username); break; case OTRL_MSGSTATE_PLAINTEXT: IRSSI_MSG("%b>%n %9%s%9 - %B%s%n - Plaintext -", accountname, username); break; case OTRL_MSGSTATE_FINISHED: IRSSI_MSG("%b>%n %9%s%9 - %B%s%n - %yFinished%n -", accountname, username); break; default: IRSSI_MSG("%b>%n %9%s%9 - %B%s%n - Unknown -", accountname, username); break; }; } else { IRSSI_MSG("%b>%n %9%s%9 - %B%s%n - Unused -", accountname, username); } /* Hash fingerprint to human. */ otrl_privkey_hash_to_human(human_fp, fp->fingerprint); trust = fp->trust; if (trust && trust[0] != '\0') { if (strncmp(trust, "smp", 3) == 0) { IRSSI_MSG(" %g%s%n - SMP", human_fp); } else { IRSSI_MSG(" %g%s%n - Manual", human_fp); } } else { IRSSI_MSG(" %r%s%n - Unverified", human_fp); } } } end: return; } /* * Finish the conversation. */ void otr_finish(SERVER_REC *irssi, const char *nick) { ConnContext *ctx; assert(irssi); assert(nick); ctx = otr_find_context(irssi, nick, FALSE); if (!ctx) { IRSSI_INFO(irssi, nick, "Nothing to do"); goto end; } otrl_message_disconnect(user_state_global->otr_state, &otr_ops, irssi, ctx->accountname, OTR_PROTOCOL_ID, nick, ctx->their_instance); otr_status_change(irssi, nick, OTR_STATUS_FINISHED); IRSSI_INFO(irssi, nick, "Finished conversation with %9%s%9", nick); end: return; } /* * Finish all otr contexts. */ void otr_finishall(struct otr_user_state *ustate) { ConnContext *context; SERVER_REC *irssi; assert(ustate); for (context = ustate->otr_state->context_root; context; context = context->next) { /* Only finish encrypted session. */ if (context->msgstate != OTRL_MSGSTATE_ENCRYPTED) { continue; } irssi = find_irssi_by_account_name(context->accountname); if (!irssi) { IRSSI_DEBUG("Unable to find server window for account %s", context->accountname); continue; } otr_finish(irssi, context->username); } } /* * Trust our peer. */ void otr_trust(SERVER_REC *irssi, const char *nick, char *str_fp, struct otr_user_state *ustate) { char peerfp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN]; struct otr_peer_context *opc; ConnContext *ctx; Fingerprint *fp_trust; assert(ustate); if (!irssi && !str_fp) { IRSSI_NOTICE(NULL, nick, "Need a fingerprint!"); goto error; } /* No human string fingerprint given. */ if (!str_fp) { ctx = otr_find_context(irssi, nick, FALSE); if (!ctx) { goto error; } opc = ctx->app_data; /* Always NEED a peer context or else code error. */ assert(opc); fp_trust = ctx->active_fingerprint; } else { fp_trust = otr_find_hash_fingerprint_from_human(str_fp, ustate); } if (fp_trust) { int ret; ret = otrl_context_is_fingerprint_trusted(fp_trust); if (ret) { IRSSI_NOTICE(irssi, nick, "Already trusted!"); goto end; } /* Trust level is manual at this point. */ otrl_context_set_trust(fp_trust, "manual"); key_write_fingerprints(ustate); otr_status_change(irssi, nick, OTR_STATUS_TRUST_MANUAL); otrl_privkey_hash_to_human(peerfp, fp_trust->fingerprint); IRSSI_NOTICE(irssi, nick, "Fingerprint %g%s%n trusted!", peerfp); } else { IRSSI_NOTICE(irssi, nick, "Fingerprint %y%s%n NOT found", (str_fp != NULL) ? str_fp : ""); } end: error: return; } /* * implements /otr authabort */ void otr_auth_abort(SERVER_REC *irssi, const char *nick) { ConnContext *ctx; assert(irssi); assert(nick); ctx = otr_find_context(irssi, nick, FALSE); if (!ctx) { IRSSI_NOTICE(irssi, nick, "Context for %9%s%9 not found.", nick); goto end; } otrl_message_abort_smp(user_state_global->otr_state, &otr_ops, irssi, ctx); otr_status_change(irssi, nick, OTR_STATUS_SMP_ABORT); if (ctx->smstate->nextExpected != OTRL_SMP_EXPECT1) { IRSSI_NOTICE(irssi, nick, "%rOngoing authentication aborted%n"); } else { IRSSI_NOTICE(irssi, nick, "%rAuthentication aborted%n"); } end: return; } /* * Initiate or respond to SMP authentication. */ void otr_auth(SERVER_REC *irssi, const char *nick, const char *question, const char *secret) { int ret; size_t secret_len = 0; ConnContext *ctx; struct otr_peer_context *opc; assert(irssi); assert(nick); ctx = otr_find_context(irssi, nick, 0); if (!ctx) { IRSSI_NOTICE(irssi, nick, "Context for %9%s%9 not found.", nick); goto end; } opc = ctx->app_data; /* Again, code flow error. */ assert(opc); if (ctx->msgstate != OTRL_MSGSTATE_ENCRYPTED) { IRSSI_INFO(irssi, nick, "You need to establish an OTR session before you " "can authenticate."); goto end; } /* Aborting an ongoing auth */ if (ctx->smstate->nextExpected != OTRL_SMP_EXPECT1) { otr_auth_abort(irssi, nick); } /* reset trust level */ if (ctx->active_fingerprint) { ret = otrl_context_is_fingerprint_trusted(ctx->active_fingerprint); if (!ret) { otrl_context_set_trust(ctx->active_fingerprint, ""); key_write_fingerprints(user_state_global); } } /* Libotr allows empty secret. */ if (secret) { secret_len = strlen(secret); } if (opc->ask_secret) { otrl_message_respond_smp(user_state_global->otr_state, &otr_ops, irssi, ctx, (unsigned char *) secret, secret_len); otr_status_change(irssi, nick, OTR_STATUS_SMP_RESPONDED); IRSSI_NOTICE(irssi, nick, "%yResponding to authentication...%n"); } else { if (question) { otrl_message_initiate_smp_q(user_state_global->otr_state, &otr_ops, irssi, ctx, question, (unsigned char *) secret, secret_len); } else { otrl_message_initiate_smp(user_state_global->otr_state, &otr_ops, irssi, ctx, (unsigned char *) secret, secret_len); } otr_status_change(irssi, nick, OTR_STATUS_SMP_STARTED); IRSSI_NOTICE(irssi, nick, "%yInitiated authentication...%n"); } opc->ask_secret = 0; end: return; } /* * For the given message we received through irssi, check if we need to queue * it for the case where that message is part of a bigger OTR full message. * This can happen with bitlbee for instance where OTR message are split in * different PRIVMSG. * * This uses a "queue" in the peer context so it's it very important to have * the peer context associated with the message (nickname + irssi object). * * Return an otr_msg_status code indicating the caller what to do with the msg. * OTR_MSG_ERROR indicates an error probably memory related. OTR_MSG_WAIT_MORE * tells the caller to NOT send out the message since we are waiting for more * to complete the OTR original message. OTR_MSG_ORIGINAL tell the caller to * simply use the original message. OTR_MSG_USE_QUEUE indicates that full_msg * can be used containing the reconstructed message. The caller SHOULD free(3) * this pointer after use. */ static enum otr_msg_status enqueue_otr_fragment(const char *msg, struct otr_peer_context *opc, char **full_msg) { enum otr_msg_status ret; size_t msg_len; assert(msg); assert(opc); /* We are going to use it quite a bit so ease our life a bit. */ msg_len = strlen(msg); if (opc->full_msg) { if (msg_len > (opc->msg_size - opc->msg_len)) { char *tmp_ptr; /* Realloc memory if there is not enough space. */ tmp_ptr = realloc(opc->full_msg, opc->msg_size + msg_len + 1); if (!tmp_ptr) { free(opc->full_msg); opc->full_msg = NULL; ret = OTR_MSG_ERROR; goto end; } opc->full_msg = tmp_ptr; opc->msg_size += msg_len + 1; } /* Copy msg to full message since we already have a part pending. */ strncpy(opc->full_msg + opc->msg_len, msg, msg_len); opc->msg_len += msg_len; opc->full_msg[opc->msg_len] = '\0'; IRSSI_DEBUG("Partial OTR message added to queue: %s", msg); /* * Are we waiting for more? If the message ends with a ".", the * transmission has ended else we have to wait for more. */ if (msg[msg_len - 1] != OTR_MSG_END_TAG) { ret = OTR_MSG_WAIT_MORE; goto end; } /* * Dup the string with enough space for the NULL byte since we are * about to free it before passing it to the caller. */ *full_msg = strndup(opc->full_msg, opc->msg_len + 1); /* Reset everything. */ free(opc->full_msg); opc->full_msg = NULL; opc->msg_size = opc->msg_len = 0; ret = OTR_MSG_USE_QUEUE; goto end; } else { char *pos; /* * Try to find the OTR message tag at the _beginning_of the packet and * check if this packet is not the end with the end tag of OTR "." */ pos = strstr(msg, OTR_MSG_BEGIN_TAG); if (pos && (pos == msg) && msg[msg_len - 1] != OTR_MSG_END_TAG) { /* Allocate full message buffer with an extra for NULL byte. */ opc->full_msg = zmalloc((msg_len * 2) + 1); if (!opc->full_msg) { ret = OTR_MSG_ERROR; goto end; } /* Copy full message with NULL terminated byte. */ strncpy(opc->full_msg, msg, msg_len); opc->msg_len += msg_len; opc->msg_size += ((msg_len * 2) + 1); opc->full_msg[opc->msg_len] = '\0'; ret = OTR_MSG_WAIT_MORE; IRSSI_DEBUG("Partial OTR message begins the queue: %s", msg); goto end; } /* Use original message. */ ret = OTR_MSG_ORIGINAL; goto end; } end: return ret; } /* * Hand the given message to OTR. * * Returns 0 if its an OTR protocol message or else negative value. */ int otr_receive(SERVER_REC *irssi, const char *msg, const char *from, char **new_msg) { int ret = -1; char *accname = NULL, *full_msg = NULL; const char *recv_msg = NULL; OtrlTLV *tlvs; ConnContext *ctx; struct otr_peer_context *opc; assert(irssi); accname = create_account_name(irssi); if (!accname) { goto error; } IRSSI_DEBUG("Receiving message..."); ctx = otr_find_context(irssi, from, 1); if (!ctx) { goto error; } /* Add peer context to OTR context if none exists */ if (!ctx->app_data) { add_peer_context_cb(irssi, ctx); } opc = ctx->app_data; assert(opc); ret = enqueue_otr_fragment(msg, opc, &full_msg); switch (ret) { case OTR_MSG_ORIGINAL: recv_msg = msg; break; case OTR_MSG_WAIT_MORE: ret = 1; goto error; case OTR_MSG_USE_QUEUE: recv_msg = full_msg; break; case OTR_MSG_ERROR: ret = -1; goto error; } ret = otrl_message_receiving(user_state_global->otr_state, &otr_ops, irssi, accname, OTR_PROTOCOL_ID, from, recv_msg, new_msg, &tlvs, &ctx, add_peer_context_cb, irssi); if (ret) { IRSSI_DEBUG("Ignoring message of length %d from %s to %s.\n" "%s", strlen(msg), from, accname, msg); } else { if (*new_msg) { IRSSI_DEBUG("Converted received message."); } } /* Check for disconnected message */ OtrlTLV *tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED); if (tlv) { otr_status_change(irssi, from, OTR_STATUS_PEER_FINISHED); IRSSI_NOTICE(irssi, from, "%9%s%9 has finished the OTR " "conversation. If you want to continue talking enter " "%9/otr finish%9 for plaintext or %9/otr init%9 to restart.", from); } otrl_tlv_free(tlvs); IRSSI_DEBUG("Message received."); error: if (full_msg) { free(full_msg); } free(accname); return ret; } /* * Get the OTR status of this conversation. */ enum otr_status_format otr_get_status_format(SERVER_REC *irssi, const char *nick) { int ret; enum otr_status_format code; ConnContext *ctx = NULL; assert(irssi); ctx = otr_find_context(irssi, nick, FALSE); if (!ctx) { code = TXT_STB_PLAINTEXT; goto end; } switch (ctx->msgstate) { case OTRL_MSGSTATE_PLAINTEXT: code = TXT_STB_PLAINTEXT; break; case OTRL_MSGSTATE_ENCRYPTED: /* Begin by checking trust. */ ret = otrl_context_is_fingerprint_trusted(ctx->active_fingerprint); if (ret) { code = TXT_STB_TRUST; } else { code = TXT_STB_UNTRUSTED; } break; case OTRL_MSGSTATE_FINISHED: code = TXT_STB_FINISHED; break; default: IRSSI_NOTICE(irssi, nick, "BUG Found! " "Please write us a mail and describe how you got here"); code = TXT_STB_UNKNOWN; break; } end: if (ctx) { IRSSI_DEBUG("Code: %d, state: %d, sm_prog_state: %d, auth state: %d", code, ctx->msgstate, ctx->smstate->sm_prog_state, ctx->auth.authstate); } return code; } /* * Change status bar text for a given nickname. */ void otr_status_change(SERVER_REC *irssi, const char *nick, enum otr_status_event event) { statusbar_items_redraw("otr"); signal_emit("otr event", 3, irssi, nick, statusbar_txt[event]); } /* * Search for a OTR Fingerprint object from the given human readable string and * return a pointer to the object if found else NULL. */ Fingerprint *otr_find_hash_fingerprint_from_human(const char *human_fp, struct otr_user_state *ustate) { char str_fp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN]; Fingerprint *fp = NULL, *fp_iter = NULL; ConnContext *context; /* Loop on all context of the user state */ for (context = ustate->otr_state->context_root; context != NULL; context = context->next) { /* Loop on all fingerprint of the context */ for (fp_iter = context->fingerprint_root.next; fp_iter; fp_iter = fp_iter->next) { otrl_privkey_hash_to_human(str_fp, fp_iter->fingerprint); /* Compare human fingerprint given in argument to the current. */ if (strncmp(str_fp, human_fp, sizeof(str_fp)) == 0) { fp = otrl_context_find_fingerprint(context, fp_iter->fingerprint, 0, NULL); goto end; } } } end: return fp; } /* * Forget a fingerprint. * * If str_fp is not NULL, it must be on the OTR human format like this: * "487FFADA 5073FEDD C5AB5C14 5BB6C1FF 6D40D48A". If str_fp is NULL, get the * context of the target nickname, check for the OTR peer context active * fingerprint and forget this one if possible. */ void otr_forget(SERVER_REC *irssi, const char *nick, char *str_fp, struct otr_user_state *ustate) { int ret; char fp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN]; Fingerprint *fp_forget; ConnContext *ctx = NULL; struct otr_peer_context *opc; if (!irssi && !str_fp) { IRSSI_NOTICE(NULL, nick, "Need a fingerprint!"); goto error; } /* No human string fingerprint given. */ if (!str_fp) { ctx = otr_find_context(irssi, nick, FALSE); if (!ctx) { goto error; } opc = ctx->app_data; /* Always NEED a peer context or else code error. */ assert(opc); fp_forget = opc->active_fingerprint; } else { fp_forget = otr_find_hash_fingerprint_from_human(str_fp, ustate); } if (fp_forget) { /* Don't do anything if context is in encrypted state. */ ret = check_fp_encrypted_msgstate(fp_forget); if (ret) { IRSSI_NOTICE(irssi, nick, "Fingerprint " "context is still encrypted. Finish the OTR " "session before forgetting a fingerprint " "(%9/otr finish%9)."); goto end; } otrl_privkey_hash_to_human(fp, fp_forget->fingerprint); /* Forget fp and context if it's the only one remaining. */ otrl_context_forget_fingerprint(fp_forget, 1); /* Update fingerprints file. */ key_write_fingerprints(ustate); IRSSI_NOTICE(irssi, nick, "Fingerprint %y%s%n forgotten.", fp); } else { IRSSI_NOTICE(irssi, nick, "Fingerprint %y%s%n NOT found", (str_fp != NULL) ? str_fp : ""); } end: error: return; } /* * Distrust a fingerprint. * * If str_fp is not NULL, it must be on the OTR human format like this: * "487FFADA 5073FEDD C5AB5C14 5BB6C1FF 6D40D48A". If str_fp is NULL, get the * context of the target nickname, check for the OTR peer context active * fingerprint and distrust it. */ void otr_distrust(SERVER_REC *irssi, const char *nick, char *str_fp, struct otr_user_state *ustate) { int ret; char fp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN]; Fingerprint *fp_distrust; ConnContext *ctx; struct otr_peer_context *opc; if (!irssi && !str_fp) { IRSSI_NOTICE(NULL, nick, "Need a fingerprint!"); goto error; } /* No human string fingerprint given. */ if (!str_fp) { ctx = otr_find_context(irssi, nick, FALSE); if (!ctx) { goto error; } opc = ctx->app_data; /* Always NEED a peer context or else code error. */ assert(opc); fp_distrust = opc->active_fingerprint; } else { fp_distrust = otr_find_hash_fingerprint_from_human(str_fp, ustate); } if (fp_distrust) { ret = otrl_context_is_fingerprint_trusted(fp_distrust); if (!ret) { /* Fingerprint already not trusted. Do nothing. */ IRSSI_NOTICE(irssi, nick, "Already not trusting it!"); goto end; } otrl_privkey_hash_to_human(fp, fp_distrust->fingerprint); otrl_context_set_trust(fp_distrust, ""); /* Update fingerprints file. */ key_write_fingerprints(ustate); IRSSI_NOTICE(irssi, nick, "Fingerprint %y%s%n distrusted.", fp); } else { IRSSI_NOTICE(irssi, nick, "Fingerprint %y%s%n NOT found", (str_fp != NULL) ? str_fp : ""); } end: error: return; } irssi-plugin-otr-1.0.0/src/otr.h000066400000000000000000000122331227701334500165100ustar00rootroot00000000000000/* * Off-the-Record Messaging (OTR) modules for IRC * * Copyright (C) 2008 - Uli Meis * 2012 - David Goulet * * 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. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA */ #ifndef IRSSI_OTR_OTR_H #define IRSSI_OTR_OTR_H /* Libotr */ #include #include #include #include #include "irssi-otr.h" #include "utils.h" /* irssi module name */ #define MODULE_NAME "otr" /* * XXX: Maybe this should be configurable? */ #define OTR_MAX_MSG_SIZE 400 /* OTR protocol id */ #define OTR_PROTOCOL_ID "IRC" #define OTR_DIR "/otr" #define OTR_KEYFILE OTR_DIR "/otr.key" #define OTR_FINGERPRINTS_FILE OTR_DIR "/otr.fp" #define OTR_INSTAG_FILE OTR_DIR "/otr.instag" /* * Specified in OTR protocol version 3. See: * http://www.cypherpunks.ca/otr/Protocol-v3-4.0.0.html */ #define OTR_MSG_BEGIN_TAG "?OTR:" #define OTR_MSG_END_TAG '.' /* IRC /me command marker and len. */ #define OTR_IRC_MARKER_ME "/me " #define OTR_IRC_MARKER_ME_LEN sizeof(OTR_IRC_MARKER_ME) - 1 /* * Memory allocation zeroed. Really useful! */ #define zmalloc(x) calloc(1, x) /* Irssi otr user state */ struct otr_user_state { OtrlUserState otr_state; }; /* * Peer OTR internal context. */ struct otr_peer_context { /* The SMP event status. Used for the Irssi status bar. */ OtrlSMPEvent smp_event; /* Did the SMP secret was asked so are we in a responder state? */ unsigned int ask_secret; /* * The fingerprint of the private message OTR session. This is useful for * the forget command for which we can recover the fingerprint * automatically. */ Fingerprint *active_fingerprint; /* * If needed, used to reconstruct the full message from fragmentation. * Bitlbee for instance does that where we receive a *long* OTR message * split in multiple PRIVMSG so we need to reconstruct it. */ char *full_msg; /* Size of full_msg. Note this is the allocated memory size. */ size_t msg_size; /* Len of the actual string in full_msg NOT counting the NULL byte. */ size_t msg_len; }; /* given to otr_status_change */ enum otr_status_event { OTR_STATUS_FINISHED, OTR_STATUS_TRUST_MANUAL, OTR_STATUS_TRUST_SMP, OTR_STATUS_SMP_ABORT, OTR_STATUS_SMP_STARTED, OTR_STATUS_SMP_RESPONDED, OTR_STATUS_SMP_INCOMING, OTR_STATUS_SMP_FINALIZE, OTR_STATUS_SMP_ABORTED, OTR_STATUS_PEER_FINISHED, OTR_STATUS_SMP_FAILED, OTR_STATUS_SMP_SUCCESS, OTR_STATUS_GONE_SECURE, OTR_STATUS_GONE_INSECURE, OTR_STATUS_CTX_UPDATE }; enum otr_msg_status { OTR_MSG_ORIGINAL = 1, OTR_MSG_WAIT_MORE = 2, OTR_MSG_USE_QUEUE = 3, OTR_MSG_ERROR = 4, }; /* there can be only one */ extern struct otr_user_state *user_state_global; /* Libotr ops functions */ extern OtrlMessageAppOps otr_ops; /* Active debug or not */ extern int debug; void irssi_send_message(SERVER_REC *irssi, const char *recipient, const char *message); void otr_status_change(SERVER_REC *irssi, const char *nick, enum otr_status_event event); /* init stuff */ struct otr_user_state *otr_init_user_state(void); void otr_free_user_state(struct otr_user_state *ustate); void otr_lib_init(); void otr_lib_uninit(); void otr_control_timer(unsigned int interval, void *opdata); /* Message transport. */ int otr_send(SERVER_REC *irssi, const char *msg, const char *to, char **otr_msg); int otr_receive(SERVER_REC *irssi, const char *msg, const char *from, char **new_msg); /* User interaction */ void otr_finish(SERVER_REC *irssi, const char *nick); void otr_auth(SERVER_REC *irssi, const char *nick, const char *question, const char *secret); void otr_auth_abort(SERVER_REC *irssi, const char *nick); void otr_contexts(struct otr_user_state *ustate); void otr_finishall(struct otr_user_state *ustate); void otr_forget(SERVER_REC *irssi, const char *nick, char *str_fp, struct otr_user_state *ustate); void otr_distrust(SERVER_REC *irssi, const char *nick, char *str_fp, struct otr_user_state *ustate); void otr_trust(SERVER_REC *irssi, const char *nick, char *str_fp, struct otr_user_state *ustate); enum otr_status_format otr_get_status_format(SERVER_REC *irssi, const char *nick); struct otr_peer_context *otr_create_peer_context(void); ConnContext *otr_find_context(SERVER_REC *irssi, const char *nick, int create); Fingerprint *otr_find_hash_fingerprint_from_human(const char *human_fp, struct otr_user_state *ustate); #endif /* IRSSI_OTR_OTR_H */ irssi-plugin-otr-1.0.0/src/utils.c000066400000000000000000000150121227701334500170350ustar00rootroot00000000000000/* * Off-the-Record Messaging (OTR) modules for IRC * * Copyright (C) 2012 - David Goulet * * 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. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA */ #include #include #include "otr.h" #include "utils.h" /* * Left trim a string. */ static char *ltrim(char *s) { assert(s); while (isspace(*s)) { s++; } return s; } /* * Right trim a string. */ static char *rtrim(char *s) { size_t len; char *back; assert(s); len = strlen(s); if (len == 0) { goto end; } back = s + len; /* Move up to the first non whitespace character. */ while (isspace(*--back)); /* Remove whitespace(s) from the string. */ *(back + 1) = '\0'; end: return s; } /* * Trim whitespaces in front and back of the string. */ char *utils_trim_string(char *s) { assert(s); return rtrim(ltrim(s)); } /* * Extract question and secret for an SMP authentication. * * Return 0 and set question/secret on success. Else, return negative value and * params are untouched. */ int utils_io_extract_smp(const char *data, char **question, char **secret) { unsigned int q_len, s_len; const char *tmp, *q_end, *q_beg, *args = data; char *q = NULL, *s = NULL; if (!data || !question || !secret) { goto error; } /* Check for '[' as first char */ q_beg = strchr(args, '['); if (!q_beg) { goto error; } /* * Move to "[my questions] secret" * ^ */ args = q_beg + 1; /* Search closing bracket for the end of the question. */ q_end = strchr(args, ']'); if (!q_end) { /* Malformed authq command */ goto error; } /* Get the question length */ q_len = (unsigned int) (q_end - args); /* Add 1 char for the \0 */ q = malloc((q_len + 1) * sizeof(char)); if (q == NULL) { goto error; } /* Copy question */ strncpy(q, args, q_len); q[q_len] = '\0'; /* Move to the closing bracket */ args = q_end; tmp = strchr(args, ' '); if (tmp == NULL) { goto error; } /* Ignore the next white space */ args = tmp + 1; /* * "[my questions] secret" * ^ */ s_len = (unsigned int) (args - data); s = malloc((s_len + 1) * sizeof(char)); if (s == NULL) { goto error; } strncpy(s, args, s_len); s[s_len] = '\0'; *question = q; *secret = s; return 0; error: free(q); free(s); return -1; } /* * Extract the secret from an auth otr command. The secret can have more than * one words so this is more efficient than exploding all args and * concatenating them. * * Return 0 and set secret on success or else return negative value an secret * is untouched. */ int utils_auth_extract_secret(const char *_data, char **secret) { int ret = -1; char *s, *cmd_offset = NULL, *data = NULL; if (!_data || !secret) { goto error; } data = strdup(_data); if (!data) { goto error; } s = utils_trim_string(data); cmd_offset = strchr(s, ' '); if (!cmd_offset) { goto error; } s = utils_trim_string(cmd_offset); *secret = strdup(s); ret = 0; error: free(data); return ret; } /* * Set _argv and _argc from the string in _data. * * On error, argv is untouched argc set to 0. */ void utils_explode_args(const char *_data, char ***_argv, int *_argc) { int argc = 0, i = 0, have_arg = 0; char **argv = NULL, *c, *data = NULL, *cmd_offset; if (!_data || !_argv || !_argc) { goto error; } data = strndup(_data, strlen(_data)); if (!data) { goto error; } c = utils_trim_string(data); /* Ignore first command */ cmd_offset = strchr(c, ' '); if (!cmd_offset) { goto error; } cmd_offset = utils_trim_string(cmd_offset); if (cmd_offset && strlen(cmd_offset) > 0) { argc++; have_arg = 1; } c = cmd_offset; while ((c = strchr(c + 1, ' '))) { /* Skip consecutive spaces. */ if (*(c + 1) == ' ') { continue; } argc++; have_arg = 1; } /* No args, only spaces encountered. */ if (!have_arg) { argc = 0; goto error; } argv = zmalloc(argc * sizeof(char *)); if (!argv) { goto error; } /* Ignore first command */ c = strtok(cmd_offset, " "); while (c != NULL) { argv[i] = strdup(c); c = strtok(NULL, " "); i++; } *_argv = argv; error: *_argc = argc; free(data); return; } /* * Free an argv array. Usually, call this after using utils_explode_args. */ void utils_free_args(char ***argv, int argc) { int i; char **args; assert(argv); /* Nothing to free. */ if (argc == 0) { return; } args = *argv; for (i = 0; i < argc; i++) { if (args[i]) { free(args[i]); } } free(args); } /* * Extract otr command from an irssi command string. * * Ex: /otr auth my_secret, _cmd is set to "auth" */ void utils_extract_command(const char *data, char **_cmd) { char *s, *cmd = NULL; assert(data); assert(_cmd); /* Search for the first whitespace. */ s = strchr(data, ' '); if (s) { cmd = strndup(data, s - data); if (!cmd) { goto error; } } else { cmd = strdup(data); } *_cmd = cmd; error: return; } /* * String to uppercase. Done inplace! */ void utils_string_to_upper(char *string) { int i = 0; char c; assert(string); while (string[i]) { c = string[i]; string[i] = toupper(c); i++; } } /* * Convert a fingerprint string of this format contained in parts: * d81d8363 f6d6090a c2632a53 352dadfa fd296a87 * to a privkey hash_to_human format of libotr: * D81D8363 F6D6090A C2632A53 352DADFA FD296A87 * * Stores the result in dst which is basically regroup the string and upper * case it. The dst argument must be equal or larger than * OTRL_PRIVKEY_FPRINT_HUMAN_LEN. */ void utils_hash_parts_to_readable_hash(const char **parts, char *dst) { int ret; /* Safety net. This is a code flow error. */ assert(parts && parts[0] && parts[1] && parts[2] && parts[3] && parts[4]); assert(dst); ret = snprintf(dst, OTRL_PRIVKEY_FPRINT_HUMAN_LEN, "%s %s %s %s %s", parts[0], parts[1], parts[2], parts[3], parts[4]); if (ret < 0) { goto error; } /* In place upper case full string. */ utils_string_to_upper(dst); error: return; } irssi-plugin-otr-1.0.0/src/utils.h000066400000000000000000000025521227701334500170470ustar00rootroot00000000000000/* * Off-the-Record Messaging (OTR) modules for IRC * * Copyright (C) 2012 - David Goulet * * 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. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA */ #ifndef IRSSI_OTR_UTILS_H #define IRSSI_OTR_UTILS_H void utils_free_args(char ***argv, int argc); void utils_extract_command(const char *data, char **_cmd); void utils_explode_args(const char *_data, char ***_argv, int *_argc); int utils_io_extract_smp(const char *data, char **question, char **secret); void utils_string_to_upper(char *string); int utils_auth_extract_secret(const char *_data, char **secret); void utils_hash_parts_to_readable_hash(const char **parts, char *dst); char *utils_trim_string(char *s); #endif /* IRSSI_OTR_UTILS_H */