├── .gitignore ├── CMakeLists.txt ├── ChangeLog ├── HOWTO_PACKAGE ├── INSTALL ├── LICENSE ├── Packaging-DEB.cmake ├── Packaging-RPM.cmake ├── Packaging.cmake ├── README ├── README.hexchat ├── README.irssi-headers ├── README.md ├── README.xchat ├── cmake-extensions ├── COPYING-CMAKE-SCRIPTS ├── FindLibGcrypt.cmake ├── FindLibOTR.cmake ├── Git.cmake └── cscope.cmake ├── formats.txt ├── io-config.h.in ├── irssi_otr.c ├── irssi_otr.h ├── makeformats.py ├── mksrcpackage.sh ├── otr.h ├── otr_key.c ├── otr_ops.c ├── otr_util.c ├── tarballdefs.cmake ├── xchat_otr.c └── xchat_otr.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.so 3 | term.h 4 | statusbar.h 5 | mainwindows.h 6 | .exrc 7 | *.swp 8 | cscope.files 9 | cscope.out 10 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Off-the-Record Messaging (OTR) module for the irssi IRC client 3 | # Copyright (C) 2008 Uli Meis 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA 18 | # 19 | 20 | PROJECT(irssi-otr) 21 | 22 | CMAKE_MINIMUM_REQUIRED(VERSION 2.4) 23 | IF(COMMAND cmake_policy) 24 | cmake_policy(SET CMP0003 NEW) 25 | ENDIF(COMMAND cmake_policy) 26 | 27 | SET(CMAKE_MODULE_PATH 28 | ${PROJECT_SOURCE_DIR}/cmake-extensions/ 29 | ${PROJECT_BINARY_DIR}) 30 | 31 | INCLUDE(cmake-extensions/cscope.cmake) 32 | INCLUDE(cmake-extensions/Git.cmake) 33 | INCLUDE(CheckFunctionExists) 34 | INCLUDE(CheckIncludeFile) 35 | INCLUDE(CheckIncludeFiles) 36 | INCLUDE(tarballdefs.cmake OPTIONAL) 37 | 38 | # get version from git 39 | 40 | IF(NOT IRSSIOTR_VERSION) 41 | IF(NOT EXISTS "${PROJECT_SOURCE_DIR}/.git") 42 | MESSAGE(FATAL_ERROR "Cannot determine the irssi-otr version since this is " 43 | "not a git checkout. Please set IRSSIOTR_VERSION, e.g. 44 | cmake -DIRSSIOTR_VERSION=mydistro-0.1 45 | or 46 | cmake -DIRSSIOTR_VERSION=mydistro-git-") 47 | ENDIF(NOT EXISTS "${PROJECT_SOURCE_DIR}/.git") 48 | FIND_GIT_TAGORCOMMIT(${PROJECT_SOURCE_DIR} IRSSIOTR_VERSION) 49 | IF(NOT IRSSIOTR_VERSION) 50 | MESSAGE(FATAL_ERROR 51 | "Couldn't determine version. Please run cmake -DIRSSIOTR_VERSION=...") 52 | ENDIF(NOT IRSSIOTR_VERSION) 53 | ENDIF(NOT IRSSIOTR_VERSION) 54 | 55 | MESSAGE(STATUS "Building irssi-otr version ${IRSSIOTR_VERSION}") 56 | 57 | # PkgConfig. Only available since 2.4.7, fetch if unavailable so people with 58 | # older cmake can run this 59 | 60 | FIND_PACKAGE(PkgConfig QUIET) 61 | 62 | IF(NOT PKG_CONFIG_FOUND) 63 | MESSAGE(STATUS "Couldn't find the pkg-config cmake module. Seems you're 64 | running cmake < 2.4.7. Will try to fetch the module from 2.4.7...") 65 | FIND_PACKAGE(Wget REQUIRED) 66 | EXECUTE_PROCESS(COMMAND "bash" "-c" 67 | "${WGET_EXECUTABLE} '-O' '-' \\ 68 | 'http://www.cmake.org/files/v2.4/cmake-2.4.7.tar.gz' | \\ 69 | tar xz cmake-2.4.7/Modules/FindPkgConfig.cmake && \\ 70 | mv cmake-2.4.7/Modules/FindPkgConfig.cmake . && \\ 71 | rmdir -p cmake-2.4.7/Modules" 72 | RESULT_VARIABLE PKGCONF_RET) 73 | IF(NOT PKGCONF_RET EQUAL 0) 74 | MESSAGE(FATAL_ERROR "Couldnt download cmake module for pkg-config") 75 | ENDIF(NOT PKGCONF_RET EQUAL 0) 76 | FIND_PACKAGE(PkgConfig REQUIRED) 77 | ENDIF(NOT PKG_CONFIG_FOUND) 78 | 79 | # GLIB 80 | 81 | pkg_check_modules(GLIB REQUIRED glib-2.0) 82 | 83 | # Python 84 | 85 | FIND_PACKAGE(PythonInterp) 86 | IF(NOT PYTHON_EXECUTABLE) 87 | MESSAGE(FATAL_ERROR "Couldn't find a python interpreter") 88 | ENDIF(NOT PYTHON_EXECUTABLE) 89 | 90 | # LIBOTR 91 | 92 | FIND_PACKAGE(LibOTR REQUIRED) 93 | IF (LIBOTR_VERSION LESS "3.1.0") 94 | MESSAGE(FATAL_ERROR "Need libotr version >= 3.1.0 (fragmentation)") 95 | ENDIF (LIBOTR_VERSION LESS "3.1.0") 96 | 97 | # LIBGCRYPT. A dependency of libotr and therefore one of ours. 98 | 99 | FIND_PACKAGE(LibGcrypt REQUIRED) 100 | 101 | # includes 102 | 103 | SET(IRSSIOTR_INCLUDE_DIRS 104 | ${PROJECT_SOURCE_DIR} 105 | ${PROJECT_BINARY_DIR} 106 | ${GLIB_INCLUDE_DIRS} 107 | ${LIBOTR_INCLUDE_DIRS}) 108 | 109 | SET(CMAKE_REQUIRED_INCLUDES ${IRSSIOTR_INCLUDE_DIRS}) 110 | SET(CMAKE_REQUIRED_DEFINITIONS -DHAVE_CONFIG_H ${LIBGCRYPT_CFLAGS}) 111 | 112 | # irssi public headers 113 | 114 | FIND_PATH(IRSSI_INCLUDE_DIR NAMES irssi/src/core/module.h) 115 | MARK_AS_ADVANCED(IRSSI_INCLUDE_DIR) 116 | 117 | IF(NOT IRSSI_INCLUDE_DIR) 118 | MESSAGE(STATUS "*** no irssi found ***") 119 | ELSEIF(BUILDFOR AND NOT BUILDFOR STREQUAL "irssi") 120 | MESSAGE(STATUS "*** not building for irssi ***") 121 | ELSE(NOT IRSSI_INCLUDE_DIR) 122 | MESSAGE(STATUS "*** building for irssi ***") 123 | SET(HAVE_IRSSI 1) 124 | SET(IRSSIOTR_INCLUDE_DIRS 125 | ${IRSSIOTR_INCLUDE_DIRS} 126 | ${IRSSI_INCLUDE_DIR}/irssi 127 | ${IRSSI_INCLUDE_DIR}/irssi/src 128 | ${IRSSI_INCLUDE_DIR}/irssi/src/core 129 | ${PROJECT_BINARY_DIR}/irssi-headers 130 | ${PROJECT_SOURCE_DIR}/irssi-headers) 131 | 132 | SET(CMAKE_REQUIRED_INCLUDES ${IRSSIOTR_INCLUDE_DIRS}) 133 | 134 | # irssi statusbar header 135 | 136 | CHECK_INCLUDE_FILES("glib.h;common.h;fe-text/statusbar-item.h" HAVE_IRSSISBAR_H) 137 | 138 | # Bad hack 139 | 140 | IF (NOT HAVE_IRSSISBAR_H) 141 | MESSAGE(STATUS "Need to fetch irssi header statusbar-item.h (you don't have it yet)") 142 | IF (NOT WGET_EXECUTABLE) 143 | FIND_PACKAGE(Wget REQUIRED) 144 | ENDIF (NOT WGET_EXECUTABLE) 145 | EXECUTE_PROCESS(COMMAND "mkdir" -p irssi-headers/fe-text) 146 | EXECUTE_PROCESS(COMMAND "bash" "-c" 147 | "${WGET_EXECUTABLE} '--post-data=revision=4936&root=irssi' \\ 148 | 'http://svn.irssi.org/cgi-bin/viewvc.cgi/irssi/trunk/src/fe-text/statusbar-item.h' || exit 1" 149 | ${PROJECT_SOURCE_DIR} WORKING_DIRECTORY irssi-headers/fe-text 150 | RESULT_VARIABLE IISBAR_RET) 151 | IF(NOT IISBAR_RET EQUAL 0) 152 | MESSAGE(FATAL_ERROR "Couldn't check out irssi headers from SVN") 153 | ENDIF(NOT IISBAR_RET EQUAL 0) 154 | SET(HAVE_IRSSISBAR_H 1 CACHE INTERNAL "Having irssi headers" FORCE) 155 | ENDIF (NOT HAVE_IRSSISBAR_H) 156 | 157 | ENDIF(NOT IRSSI_INCLUDE_DIR) 158 | 159 | FIND_PATH(HEXCHAT_INCLUDE_DIR NAMES hexchat-plugin.h) 160 | MARK_AS_ADVANCED(HEXCHAT_INCLUDE_DIR) 161 | 162 | IF(NOT HEXCHAT_INCLUDE_DIR) 163 | MESSAGE(STATUS "*** no hexchat found ***") 164 | ELSEIF(BUILDFOR AND NOT BUILDFOR STREQUAL "xchat") 165 | MESSAGE(STATUS "*** not building for hexchat ***") 166 | ELSE(NOT HEXCHAT_INCLUDE_DIR) 167 | MESSAGE(STATUS "*** building for hexchat ***") 168 | SET(HAVE_HEXCHAT 1) 169 | SET(IRSSIOTR_INCLUDE_DIRS 170 | ${IRSSIOTR_INCLUDE_DIRS} 171 | ${HEXCHAT_INCLUDE_DIR}) 172 | ENDIF(NOT HEXCHAT_INCLUDE_DIR) 173 | 174 | include_directories(${IRSSIOTR_INCLUDE_DIRS}) 175 | 176 | # gregex.h 177 | # available since 2.13 AFAIK 178 | # optional for html stripping and nick ignoring 179 | 180 | FIND_PATH(GREGEX_FILE "glib/gregex.h" ${GLIB_INCLUDE_DIRS} NO_DEFAULT_PATH) 181 | IF(GREGEX_FILE) 182 | CHECK_INCLUDE_FILE("glib.h" HAVE_GREGEX_H) 183 | ELSE() 184 | MESSAGE(FATAL_ERROR "gregex.h not found") 185 | ENDIF() 186 | 187 | # check for strsignal 188 | 189 | CHECK_FUNCTION_EXISTS(strsignal HAVE_STRSIGNAL) 190 | 191 | # generate io-config.h 192 | 193 | CONFIGURE_FILE(io-config.h.in io-config.h) 194 | 195 | # defs 196 | 197 | IF(NOT CMAKE_BUILD_TYPE) 198 | SET(CMAKE_BUILD_TYPE debug) 199 | ENDIF(NOT CMAKE_BUILD_TYPE) 200 | SET(CMAKE_C_FLAGS_DEBUG -g) 201 | 202 | MESSAGE(STATUS "This is a ${CMAKE_BUILD_TYPE} build") 203 | 204 | ADD_DEFINITIONS(-DHAVE_CONFIG_H -Wall ${LIBGCRYPT_CFLAGS}) 205 | 206 | # docdir 207 | 208 | IF(NOT DOCDIR) 209 | SET(DOCDIR share/doc/${CMAKE_PROJECT_NAME}) 210 | ENDIF(NOT DOCDIR) 211 | 212 | # generate otr-formats.{c,h} 213 | 214 | ADD_CUSTOM_COMMAND(OUTPUT 215 | ${PROJECT_BINARY_DIR}/otr-formats.c 216 | ${PROJECT_BINARY_DIR}/xchat-formats.c 217 | DEPENDS makeformats.py formats.txt README 218 | COMMAND 219 | ${PYTHON_EXECUTABLE} 220 | ${PROJECT_SOURCE_DIR}/makeformats.py 221 | ${PROJECT_SOURCE_DIR}/formats.txt 222 | ${PROJECT_SOURCE_DIR}/README 223 | ) 224 | 225 | # lib 226 | 227 | # Now that took some time to figure out... 228 | 229 | IF(APPLE) 230 | SET(APPLE_LDFLAGS "-single_module -undefined dynamic_lookup") 231 | ENDIF(APPLE) 232 | 233 | FOREACH(X ${LIBGCRYPT_LDFLAGS} ${GLIB_LDFLAGS} ${APPLE_LDFLAGS}) 234 | SET(MAIN_LDFLAGS "${MAIN_LDFLAGS} ${X}") 235 | ENDFOREACH(X ${LIBGCRYPT_LDFLAGS} ${GLIB_LDFLAGS} ${APPLE_LDFLAGS}) 236 | 237 | IF(HAVE_IRSSI) 238 | ADD_LIBRARY(irssiotr SHARED irssi_otr.c otr_util.c otr_ops.c otr_key.c ${PROJECT_BINARY_DIR}/otr-formats.c) 239 | TARGET_LINK_LIBRARIES(irssiotr ${GLIB_LIBRARIES} ${LIBOTR_LIBRARIES}) 240 | SET_TARGET_PROPERTIES(irssiotr PROPERTIES 241 | COMPILE_FLAGS -DTARGET_IRSSI 242 | OUTPUT_NAME "otr" 243 | LINK_FLAGS "${MAIN_LDFLAGS}") 244 | IF(APPLE) 245 | SET_TARGET_PROPERTIES(irssiotr PROPERTIES SUFFIX ".so") 246 | ENDIF(APPLE) 247 | ENDIF(HAVE_IRSSI) 248 | 249 | IF(HAVE_HEXCHAT) 250 | ADD_LIBRARY(hexchatotr SHARED xchat_otr.c otr_util.c otr_ops.c otr_key.c ${PROJECT_BINARY_DIR}/xchat-formats.c) 251 | TARGET_LINK_LIBRARIES(hexchatotr ${GLIB_LIBRARIES} ${LIBOTR_LIBRARIES}) 252 | SET_TARGET_PROPERTIES(hexchatotr PROPERTIES 253 | COMPILE_FLAGS -DTARGET_XCHAT 254 | OUTPUT_NAME "hexchatotr" 255 | LINK_FLAGS "${MAIN_LDFLAGS}") 256 | IF(APPLE) 257 | SET_TARGET_PROPERTIES(hexchatotr PROPERTIES SUFFIX ".so") 258 | ENDIF(APPLE) 259 | ENDIF(HAVE_HEXCHAT) 260 | 261 | # cscope 262 | 263 | FILE(GLOB CSANDHS *.c *.h) 264 | ADD_CSCOPE_TARGET("${CSANDHS}" "${IRSSIOTR_INCLUDE_DIRS}") 265 | 266 | # Install / CPack 267 | 268 | IF(CMAKE_INSTALL_TYPE MATCHES "package-.*") 269 | INCLUDE(Packaging.cmake) 270 | ELSEIF(CMAKE_INSTALL_TYPE MATCHES "home") 271 | INSTALL(TARGETS irssiotr DESTINATION "$ENV{HOME}/.irssi/modules") 272 | ELSE(CMAKE_INSTALL_TYPE MATCHES "package-.*") 273 | IF(HAVE_IRSSI) 274 | INSTALL(TARGETS irssiotr DESTINATION lib${LIB_SUFFIX}/irssi/modules) 275 | ENDIF(HAVE_IRSSI) 276 | IF(HAVE_HEXCHAT) 277 | INSTALL(TARGETS hexchatotr DESTINATION lib${LIB_SUFFIX}/hexchat/plugins) 278 | ENDIF(HAVE_HEXCHAT) 279 | INSTALL(FILES README LICENSE DESTINATION ${DOCDIR}) 280 | ENDIF(CMAKE_INSTALL_TYPE MATCHES "package-.*") 281 | 282 | # Source tarball 283 | ADD_CUSTOM_TARGET(src-tarball 284 | ${PROJECT_SOURCE_DIR}/mksrcpackage.sh ${PROJECT_SOURCE_DIR} 285 | ${IRSSIOTR_VERSION}) 286 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | Version 0.3 2 | * create queries for OTR messages if otr_createqueries is set 3 | * finish conversations on unload unless otr_finishonunload is off 4 | * added settings otr_policy, otr_policy_known and otr_ignore 5 | * fixed two segfault sources 6 | * key generation now operates on a temp file 7 | * the .irssi/otr dir now gets created with mode 700 8 | * commands now take an optional nick@server argument 9 | (for single message window users) 10 | * changed loglevel of otr_log (heartbeats) and otr_finish 11 | * moved to the new public statusbar-item.h header 12 | 13 | Version 0.2 14 | 15 | * fixed multiple server problem. 16 | * fixed fragmentation problem (seen with pidgin over IRC). 17 | -------------------------------------------------------------------------------- /HOWTO_PACKAGE: -------------------------------------------------------------------------------- 1 | You can let cmake generate a package for you. But don't expect it to be in 2 | full conformance with your distribution. 3 | 4 | You'll need cmake >= 2.6. In theory, all you should have to do is: 5 | 6 | $ cmake -DCMAKE_INSTALL_TYPE=package-deb /path/to/src 7 | $ sudo make package 8 | 9 | For an RPM it should be package-rpm and for TGZ...you can imagine. 10 | 11 | I'm not sure yet if the RPMs/DEBs generated by cmake/CPack are 100% OK. You can 12 | tweak the settings in Packaging-{RPM,DEB}.cmake. If you wanna see how CPack does 13 | it and what variables affect it, check out: 14 | 15 | /usr/share/cmake/Modules/CPackDeb.cmake 16 | /usr/share/cmake/Modules/CPackRPM.cmake 17 | 18 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | ---------- INSTALL ---------- 2 | 3 | Usually the following will do: 4 | 5 | $ cmake /path/to/src 6 | $ make 7 | $ sudo make install 8 | 9 | If you want to install libotr.so into your home folder 10 | (~/.irssi/modules/libotr.so) run 11 | 12 | $ cmake -DCMAKE_INSTALL_TYPE=home /path/to/src 13 | 14 | instead. 15 | 16 | ---------- RUNTIME DEPENDENCIES ---------- 17 | 18 | * libotr >= 3.1.0. Fragmentation has been introduced in that version so 19 | nothing smaller will work. 20 | 21 | * glib. Will work with < 2.13 but since there are no regexes available 22 | HTML stripping (OTR spits out HTML sometimes) and nick ignoring and 23 | setting otr_policy won't work. 24 | 25 | * irssi. Obviously ;) 26 | 27 | ---------- BUILD-TIME ONLY DEPENDENCIES ---------- 28 | 29 | * cmake. Sry for that, but I'm not an autofoo fan. If you're running 30 | < cmake-2.4.7 then configure will try to download a missing module 31 | (pkgconfig) from the cmake-2.4.7 sources. Should work. 32 | 33 | * pkg-config, python and wget. 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /Packaging-DEB.cmake: -------------------------------------------------------------------------------- 1 | INSTALL(TARGETS irssiotr DESTINATION lib${LIB_SUFFIX}/irssi/modules) 2 | INSTALL(FILES README LICENSE DESTINATION ${DOCDIR}) 3 | 4 | SET(CPACK_GENERATOR DEB) 5 | #SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64") 6 | SET(CPACK_DEBIAN_PACKAGE_SECTION "net") 7 | SET(CPACK_DEBIAN_PACKAGE_DEPENDS "irssi, libotr2 (>= 3.1.0)") 8 | -------------------------------------------------------------------------------- /Packaging-RPM.cmake: -------------------------------------------------------------------------------- 1 | INSTALL(TARGETS irssiotr DESTINATION lib${LIB_SUFFIX}/irssi/modules) 2 | INSTALL(FILES README DESTINATION ${DOCDIR}) 3 | 4 | SET(CPACK_GENERATOR RPM) 5 | SET(CPACK_RPM_PACKAGE_DEBUG) 6 | SET(CPACK_RPM_PACKAGE_LICENSE "GPLv2") 7 | SET(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}) 8 | 9 | EXECUTE_PROCESS(COMMAND bash -c 10 | "ARCH=`which arch` && $ARCH | tr -d '\n'" 11 | OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE) 12 | 13 | #IF(CMAKE_SIZEOF_VOID_P EQUAL 8) 14 | # SET(CPACK_RPM_PACKAGE_ARCHITECTURE i386) 15 | #ELSE 16 | # SET(CPACK_RPM_PACKAGE_ARCHITECTURE i386) 17 | #ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 8) 18 | 19 | SET(CPACK_RPM_PACKAGE_RELEASE 1) 20 | SET(CPACK_RPM_PACKAGE_GROUP "unknown") 21 | SET(CPACK_RPM_FILE_NAME 22 | ${CPACK_PACKAGE_FILE_NAME}-${CPACK_RPM_PACKAGE_RELEASE}.${CPACK_RPM_PACKAGE_ARCHITECTURE}) 23 | SET(CPACK_PACKAGE_FILE_NAME ${CPACK_RPM_FILE_NAME}) 24 | -------------------------------------------------------------------------------- /Packaging.cmake: -------------------------------------------------------------------------------- 1 | SET(CPACK_PACKAGE_CONTACT "Ulim ") 2 | SET(CPACK_PACKAGE_VENDOR ${CPACK_PACKAGE_CONTACT}) 3 | 4 | SET(CPACK_RESOURCE_FILE_LICENSE ${PROJECT_SOURCE_DIR}/LICENSE) 5 | SET(CPACK_RESOURCE_FILE_README ${PROJECT_SOURCE_DIR}/README) 6 | 7 | SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY 8 | "Off-The-Record Messaging (OTR) for irssi") 9 | 10 | SET(CPACK_PACKAGE_FILE_NAME 11 | ${CMAKE_PROJECT_NAME}-${IRSSIOTR_VERSION}) 12 | 13 | SET(CPACK_GENERATOR TGZ) 14 | 15 | SET(CPACK_PACKAGE_VERSION ${IRSSIOTR_VERSION}) 16 | 17 | IF(CMAKE_INSTALL_TYPE STREQUAL "package-rpm") 18 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6) 19 | INCLUDE(Packaging-RPM.cmake) 20 | ELSEIF(CMAKE_INSTALL_TYPE STREQUAL "package-deb") 21 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6) 22 | INCLUDE(Packaging-DEB.cmake) 23 | ELSEIF(CMAKE_INSTALL_TYPE STREQUAL "package-tgz") 24 | INSTALL(TARGETS irssiotr DESTINATION irssi/lib/modules) 25 | INSTALL(FILES README LICENSE DESTINATION ${DOCDIR}) 26 | ELSE(CMAKE_INSTALL_TYPE STREQUAL "package-rpm") 27 | MESSAGE(FATAL_ERROR "Unknown build type '${CMAKE_INSTALL_TYPE}'") 28 | ENDIF(CMAKE_INSTALL_TYPE STREQUAL "package-rpm") 29 | 30 | 31 | 32 | #ENDIF(CMAKE_INSTALL_TYPE STREQUAL "package-tgz") 33 | #ENDIF(CMAKE_INSTALL_TYPE STREQUAL "package-deb") 34 | 35 | #SET(CPACK_PACKAGE_DESCRIPTION_FILE ${PROJECT_SOURCE_DIR}/README) 36 | #SET(CPACK_PACKAGE_VERSION_MAJOR "0") 37 | #SET(CPACK_PACKAGE_VERSION_MINOR "1") 38 | #SET(CPACK_PACKAGE_VERSION_PATCH "0") 39 | #SET(CPACK_PACKAGE_FILE_NAME 40 | # ${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}) 41 | 42 | INCLUDE(CPack) 43 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Quick start: Do "/load otr", write "?OTR?" to your OTR buddy, wait until the now 2 | ongoing key generation finishs and write "?OTR?" again. You should "go secure". 3 | 4 | Key generation happens in a seperate process and its duration mainly depends on 5 | the available entropy. On my desktop it takes about 6 Minutes, about 2 Minutes 6 | if I run "du /" in parallel and on an idle server system it can even take an 7 | hour. 8 | 9 | The default OTR policy of irssi-otr is now something between manual and 10 | opportunistic. Manual means you have to start it yourself by issueing "?OTR?", 11 | opportunistic means both peers send some magic whitespace and start OTR once 12 | they receive this whitespace from the other side. irssi-otr uses a mode in 13 | between where we are not sending whitespace as an announcement (as in 14 | opportunistic) but we still handle whitespace if we see it from the other side 15 | (I'm calling it handlews). Therefore if your peer uses opportunistic the 16 | handshake should still start automatically once he writes something. 17 | 18 | You can now set the OTR policy per peer via the otr_policy /setting. It's a 19 | comma seperated list of "@ " pairs where @ 20 | is interpreted as a glob pattern, i.e. you can use wildcard "*" and joker "?" as 21 | you would in a shell. The policy can be one of never, manual, handlews (the 22 | default), opportunistic, and always. Be aware that the opportunistic policy 23 | fails with some IRC servers since they strip off the whitespace. The always 24 | policy has the nice side effect that the first line you type will already be 25 | encrypted. 26 | 27 | If a fingerprint can be found for someone, i.e. someone you had an OTR 28 | conversation with before, then the otr_policy_known setting applies after 29 | otr_policy. It has the same syntax. The default is "* always", i.e. enforce OTR 30 | with anyone you've used OTR with before. 31 | 32 | Should you finish an OTR session via "/otr finish" and should the active policy 33 | be always or opportunistic then it will be temporarily set back to handlews. 34 | Otherwise OTR would start again right away which is probably not what you want. 35 | This is however reset once you close the query window. 36 | 37 | To make sure that you are actually talking to your buddy, you can agree on a 38 | secret somehow and then one does "/otr auth ". Shortly afterwards the 39 | other one will be asked to do the same and you're done. The traditional 40 | alternative, comparing fingerprints over a secure line, can also be used. Use 41 | "/otr trust" once you're sure they match. 42 | 43 | I also strongly recommend to do "/statusbar window add otr" so you're informed 44 | about what's going on. 45 | 46 | In "~/.irssi/otr/otr.{key,fp}" you'll find the fingerprints and your private 47 | keys(should you at any point be interested). 48 | 49 | Commands: 50 | 51 | /otr genkey nick@irc.server.com 52 | Manually generate a key for the given account(also done on demand) 53 | /otr auth [@] 54 | Initiate or respond to an authentication challenge 55 | /otr authabort [@] 56 | Abort any ongoing authentication 57 | /otr trust [@] 58 | Trust the fingerprint of the user in the current window. 59 | You should only do this after comparing fingerprints over a secure line 60 | /otr debug 61 | Switch debug mode on/off 62 | /otr contexts 63 | List all OTR contexts along with their fingerprints and status 64 | /otr finish [@] 65 | Finish an OTR conversation 66 | /otr version 67 | Display irssi-otr version. Might be a git commit 68 | 69 | Settings: 70 | 71 | otr_policy 72 | Comma-separated list of "@ " pairs. See comments 73 | above. 74 | otr_policy_known 75 | Same syntax as otr_policy. Only applied where a fingerprint is 76 | available. 77 | otr_ignore 78 | Conversations with nicks that match this regular expression completely 79 | bypass libotr. It is very unlikely that you need to touch this setting, 80 | just use the OTR policy never to prevent OTR sessions with some nicks. 81 | otr_finishonunload 82 | If true running OTR sessions are finished on /unload and /quit. 83 | otr_createqueries 84 | If true queries are automatically created for OTR log messages. 85 | -------------------------------------------------------------------------------- /README.hexchat: -------------------------------------------------------------------------------- 1 | The README file is written for irssi but what's said there mostly applies to 2 | Hexchat as well. The only difference is that Hexchat doesn't support 3 | adding /settings, so in order to see and change the current settings you'll have 4 | to use the "/otr set" command. Without arguments it will show the current 5 | settings and if supplied with a setting name and a value it will change the 6 | given setting. There is no persistence, i.e. each time you start Hexchat the 7 | hardcoded defaults will be active. Please use standard Hexchat scripting magic 8 | to change the defaults to your liking on startup. It seems overkill to have a 9 | config parser/writer just for this plugin and it is fortunately not neccessary. 10 | -------------------------------------------------------------------------------- /README.irssi-headers: -------------------------------------------------------------------------------- 1 | statusbar-item.h is an irssi header; 2 | hence it is licensed under the same license as irssi (GPLv2). 3 | If you want to know why it is here, check out irssi FS#535. 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | This is the XChat OTR plugin ported to Hexchat along with several bug fixes. 3 | 4 | It depends on libotr 3.2.1 which is no longer available in Debian Testing and 5 | Ubuntu 14.04. You can download it from here 6 | 7 | https://otr.cypherpunks.ca/libotr-3.2.1.tar.gz 8 | 9 | If the link above doesn't work, you can clone it from my archive 10 | 11 | git clone https://github.com/adhux/libotr-3.2.1.git 12 | 13 | and install it with the following commands 14 | 15 | sudo apt-get install libgcrypt11-dev 16 | cd libotr-3.2.1 17 | ./configure 18 | make 19 | sudo make install 20 | 21 | Then install hexchat-otr with these commands 22 | 23 | sudo apt-get install cmake libglib2.0-dev build-essential 24 | git clone https://github.com/adhux/hexchat-otr.git 25 | cd hexchat-otr 26 | cmake . 27 | make 28 | cp libhexchatotr.so ~/.config/hexchat/addons/ 29 | 30 | 31 | Future plans: fix the /me bug and add libotr 4.0.0 support. 32 | 33 | 34 | -------------------------------------------------------------------------------- /README.xchat: -------------------------------------------------------------------------------- 1 | The README file is written for irssi but what's said there mostly applies to 2 | xchat as well. The only difference is that xchat doesn't support adding 3 | /settings, so in order to see and change the current settings you'll have to use 4 | the "/otr set" command. Without arguments it will show the current settings and 5 | if supplied with a setting name and a value it will change the given setting. 6 | There is no persistence, i.e. each time you start xchat the hardcoded defaults 7 | will be active. Please use standard xchat scripting magic to change the defaults 8 | to your liking on startup. It seems overkill to have a config parser/writer just 9 | for this plugin and it is fortunately not neccessary. 10 | -------------------------------------------------------------------------------- /cmake-extensions/COPYING-CMAKE-SCRIPTS: -------------------------------------------------------------------------------- 1 | Redistribution and use in source and binary forms, with or without 2 | modification, are permitted provided that the following conditions 3 | are met: 4 | 5 | 1. Redistributions of source code must retain the copyright 6 | notice, this list of conditions and the following disclaimer. 7 | 2. Redistributions in binary form must reproduce the copyright 8 | notice, this list of conditions and the following disclaimer in the 9 | documentation and/or other materials provided with the distribution. 10 | 3. The name of the author may not be used to endorse or promote products 11 | derived from this software without specific prior written permission. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /cmake-extensions/FindLibGcrypt.cmake: -------------------------------------------------------------------------------- 1 | # This is from KDE SVN, I just changed LIBGCRYPT_LIBRARIES to LIBGCRYPT_LDFLAGS 2 | # cause that's what it is at least on my system - Uli 3 | 4 | # - Try to find the Gcrypt library 5 | # Once run this will define 6 | # 7 | # LIBGCRYPT_FOUND - set if the system has the gcrypt library 8 | # LIBGCRYPT_CFLAGS - the required gcrypt compilation flags 9 | # LIBGCRYPT_LDFLAGS - the linker libraries needed to use the gcrypt library 10 | # 11 | # Copyright (c) 2006 Brad Hards 12 | # 13 | # Redistribution and use is allowed according to the terms of the BSD license. 14 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 15 | 16 | # libgcrypt is moving to pkg-config, but earlier version don't have it 17 | 18 | #search in typical paths for libgcrypt-config 19 | FIND_PROGRAM(LIBGCRYPTCONFIG_EXECUTABLE NAMES libgcrypt-config) 20 | 21 | #reset variables 22 | set(LIBGCRYPT_LDFLAGS) 23 | set(LIBGCRYPT_CFLAGS) 24 | 25 | # if libgcrypt-config has been found 26 | IF(LIBGCRYPTCONFIG_EXECUTABLE) 27 | 28 | EXEC_PROGRAM(${LIBGCRYPTCONFIG_EXECUTABLE} ARGS --libs RETURN_VALUE _return_VALUE OUTPUT_VARIABLE LIBGCRYPT_LDFLAGS) 29 | 30 | EXEC_PROGRAM(${LIBGCRYPTCONFIG_EXECUTABLE} ARGS --cflags RETURN_VALUE _return_VALUE OUTPUT_VARIABLE LIBGCRYPT_CFLAGS) 31 | 32 | IF(${LIBGCRYPT_CFLAGS} MATCHES "\n") 33 | SET(LIBGCRYPT_CFLAGS " ") 34 | ENDIF(${LIBGCRYPT_CFLAGS} MATCHES "\n") 35 | 36 | IF(LIBGCRYPT_LDFLAGS AND LIBGCRYPT_CFLAGS) 37 | SET(LIBGCRYPT_FOUND TRUE) 38 | ENDIF(LIBGCRYPT_LDFLAGS AND LIBGCRYPT_CFLAGS) 39 | 40 | ENDIF(LIBGCRYPTCONFIG_EXECUTABLE) 41 | 42 | if (LIBGCRYPT_FOUND) 43 | if (NOT LibGcrypt_FIND_QUIETLY) 44 | message(STATUS "Found libgcrypt: ${LIBGCRYPT_LDFLAGS}") 45 | endif (NOT LibGcrypt_FIND_QUIETLY) 46 | else (LIBGCRYPT_FOUND) 47 | if (LibGcrypt_FIND_REQUIRED) 48 | message(FATAL_ERROR "Could not find libgcrypt libraries") 49 | endif (LibGcrypt_FIND_REQUIRED) 50 | endif (LIBGCRYPT_FOUND) 51 | 52 | MARK_AS_ADVANCED(LIBGCRYPT_CFLAGS LIBGCRYPT_LDFLAGS) 53 | -------------------------------------------------------------------------------- /cmake-extensions/FindLibOTR.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Uli Meis 3 | # 4 | # Mostly taken from cmake findcurl, version stuff from kopete 5 | # 6 | # - Find libotr 7 | # Find the libotr headers and library. 8 | # 9 | # LIBOTR_INCLUDE_DIR 10 | # LIBOTR_LIBRARIES 11 | # LIBOTR_FOUND 12 | 13 | # Look for the header file. 14 | FIND_PATH(LIBOTR_INCLUDE_DIR NAMES libotr/version.h) 15 | MARK_AS_ADVANCED(LIBOTR_INCLUDE_DIR) 16 | 17 | # Look for the library. 18 | FIND_LIBRARY(LIBOTR_LIBRARY NAMES otr) 19 | MARK_AS_ADVANCED(LIBOTR_LIBRARY) 20 | 21 | # Copy the results to the output variables. 22 | IF(LIBOTR_INCLUDE_DIR AND LIBOTR_LIBRARY) 23 | SET(LIBOTR_FOUND 1) 24 | SET(LIBOTR_LIBRARIES ${LIBOTR_LIBRARY}) 25 | SET(LIBOTR_INCLUDE_DIRS ${LIBOTR_INCLUDE_DIR}) 26 | EXECUTE_PROCESS(COMMAND grep "OTRL_VERSION" 27 | "${LIBOTR_INCLUDE_DIR}/libotr/version.h" OUTPUT_VARIABLE output) 28 | STRING(REGEX MATCH "OTRL_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+" 29 | LIBOTR_VERSION "${output}") 30 | STRING(REGEX REPLACE "^OTRL_VERSION \"" "" LIBOTR_VERSION "${LIBOTR_VERSION}") 31 | MESSAGE(STATUS " found libotr, version ${LIBOTR_VERSION}" ) 32 | ELSE(LIBOTR_INCLUDE_DIR AND LIBOTR_LIBRARY) 33 | SET(LIBOTR_FOUND 0) 34 | SET(LIBOTR_LIBRARIES) 35 | SET(LIBOTR_INCLUDE_DIRS) 36 | ENDIF(LIBOTR_INCLUDE_DIR AND LIBOTR_LIBRARY) 37 | 38 | # Report the results. 39 | IF(NOT LIBOTR_FOUND) 40 | SET(LIBOTR_DIR_MESSAGE 41 | "LIBOTR was not found. Make sure LIBOTR_LIBRARY and LIBOTR_INCLUDE_DIR are set.") 42 | IF(NOT LIBOTR_FIND_QUIETLY) 43 | MESSAGE(STATUS "${LIBOTR_DIR_MESSAGE}") 44 | ELSE(NOT LIBOTR_FIND_QUIETLY) 45 | IF(LIBOTR_FIND_REQUIRED) 46 | MESSAGE(FATAL_ERROR "${LIBOTR_DIR_MESSAGE}") 47 | ENDIF(LIBOTR_FIND_REQUIRED) 48 | ENDIF(NOT LIBOTR_FIND_QUIETLY) 49 | ENDIF(NOT LIBOTR_FOUND) 50 | -------------------------------------------------------------------------------- /cmake-extensions/Git.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Uli Meis 3 | # 4 | # Handy macro for fetching current tag or commit of a git repo. 5 | # 6 | MACRO(FIND_GIT_TAGORCOMMIT GITDIR CMAKEVAR) 7 | EXECUTE_PROCESS(COMMAND bash -c 8 | "GITCOMMIT=`git log | head -n1 | cut -d' ' -f2`;\\ 9 | if [ -z \"$GITCOMMIT\" ]; then exit 1;fi; \\ 10 | GITTAG=`cd .git/refs/tags && grep $GITCOMMIT * | cut -d: -f1` ;\\ 11 | if [ -n \"$GITTAG\" ]; then \\ 12 | echo -n $GITTAG | tr -d v; else \\ 13 | echo -n git-$GITCOMMIT;fi" 14 | WORKING_DIRECTORY ${GITDIR} 15 | OUTPUT_VARIABLE GIT_TAGORCOMMIT 16 | RESULT_VARIABLE GIT_TAGORCOMMITRET) 17 | IF(GIT_TAGORCOMMITRET EQUAL 0) 18 | SET(${CMAKEVAR} ${GIT_TAGORCOMMIT}) 19 | ENDIF(GIT_TAGORCOMMITRET EQUAL 0) 20 | ENDMACRO(FIND_GIT_TAGORCOMMIT) 21 | -------------------------------------------------------------------------------- /cmake-extensions/cscope.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Uli Meis 3 | # 4 | # Handy macro for generating the cscope database 5 | # 6 | 7 | MACRO(ADD_CSCOPE_TARGET CSCOPE_SOURCES CSCOPE_INCLUDES) 8 | ADD_CUSTOM_COMMAND( 9 | OUTPUT cscope.out 10 | DEPENDS ${CSCOPE_SOURCES} 11 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 12 | COMMAND 13 | echo '${CSCOPE_SOURCES}' | tr ' ' '\\n' >cscope.files 14 | COMMAND 15 | cscope -b `echo ${CSCOPE_INCLUDES} | xargs -n1 bash -c 'echo -I$$0'`) 16 | ADD_CUSTOM_TARGET(cscope DEPENDS cscope.out) 17 | ENDMACRO(ADD_CSCOPE_TARGET) 18 | -------------------------------------------------------------------------------- /formats.txt: -------------------------------------------------------------------------------- 1 | Keys 2 | kg_failed Key generation for %s: failed: %s (%s) 3 | kg_completed Key generation for %s: completed in %d seconds. Reloading keys 4 | kg_aborted_dup Key generation for %s: aborted. Key generation for %s still in progress 5 | kg_aborted_dir Key generation for %s: aborted, failed creating directory %s: %s 6 | kg_mkdir created directory %s 7 | kg_pipe Key generation for %s: error creating pipe: %s 8 | kg_fork Key generation for %s: fork() error: %s 9 | kg_initiated Key generation for %s: initiated. This might take several minutes or on some systems even an hour. If you wanna check that something is happening, see if there are two processes of your IRC client. 10 | kg_exited Key generation for %s: child terminated for unknown reason 11 | kg_exitsig Key generation for %s: child was killed by signal %s 12 | kg_pollerr Key generation for %s: error poll()ing child: %s 13 | kg_abort Key generation for %s: aborted 14 | kg_needacc I need an account name. Try something like /otr genkey mynick@irc.server.net 15 | kg_noabort No ongoing key generation to abort 16 | key_not_found no private keys found 17 | key_loaded private keys loaded 18 | key_load_error Error loading private keys: %s (%s) 19 | Fingerprints 20 | fp_saved fingerprints saved 21 | fp_save_error Error saving fingerprints: %s (%s) 22 | fp_not_found no fingerprints found 23 | fp_loaded fingerprints loaded 24 | fp_load_error Error loading fingerprints: %s (%s) 25 | fp_trust Trusting fingerprint from %s 26 | Callbacks 27 | ops_notify_bug BUG() in ops_notify 28 | ops_notify title: %s prim: %s sec: %s 29 | ops_display_bug BUG() in ops_display 30 | ops_display msg: %s 31 | ops_sec gone %%9secure%%9 32 | ops_fpcomp Your peer is not authenticated. To make sure you're talking to the right guy you can either agree on a secret and use the authentication described in %9/otr auth%9, or use the traditional way and compare fingerprints over a secure line (e.g. telephone) and subsequently enter %9/otr trust%9. Your fingerprint is: %s. %s's fingerprint: %s 33 | ops_insec gone %9insecure%9 34 | ops_still_reply still %%9secure%9 (is reply) 35 | ops_still_no_reply still %%9secure%9 (is not reply) 36 | ops_log log msg: %s 37 | ops_inject Couldn't inject message from %s for %s: %s 38 | SendingReceiving 39 | send_failed send failed: msg=%s 40 | send_change couldn't find context also OTR changed the outgoing message(BUG?) 41 | send_fragment failed to fragment message: msg=%s 42 | send_converted OTR converted sent message to %s 43 | receive_ignore_query ignoring rest of OTR default query msg 44 | receive_dequeued dequeued msg of length %d 45 | receive_queued queued msg of length %d 46 | receive_ignore ignoring protocol message of length %d, acc=%s, from=%s: %s 47 | receive_converted OTR converted received message 48 | otr_better_two %s has requested an Off-the-Record private conversation. However, you do not have a plugin to support that. 49 | otr_better_three See http://otr.cypherpunks.ca/ for more information. 50 | Context 51 | ctx_not_found couldn't find context: acc=%s nick=%s 52 | ctx_not_create couldn't create/find context: acc=%s from=%s 53 | Authentication 54 | auth_aborted_ongoing Ongoing authentication aborted 55 | auth_aborted Authentication aborted 56 | auth_responding Responding to authentication request... 57 | auth_initiated Initiated authentication... 58 | auth_have_old %s wanted to authenticate but an old authentication was still ongoing. Old authentication will be aborted, please try again. 59 | auth_peer %s wants to authenticate. Type /otr auth to complete. 60 | auth_peer_reply_wrong %s replied to an auth we didn't start. 61 | auth_peer_replied %s replied to our auth request... 62 | auth_peer_wrong_smp3 %s sent a wrong authentication message (SMP3). 63 | auth_peer_wrong_smp4 %s sent a wrong authentication message (SMP4). 64 | auth_successful Authentication successful! 65 | auth_failed Authentication failed! 66 | auth_needenc You need to establish an OTR session before you can authenticate. 67 | Commands 68 | cmd_otr We're alive 69 | cmd_qnotfound Failed: Can't get nick and server of current query window. (Or maybe you're doing this in the status window?) 70 | cmd_auth Please agree on a secret with your peer and then initiate the authentication with /otr auth or let him initiate. Should you initiate your peer will after a little while be instructed to enter the secret as well. Once he has done so the authentication will finish up. Should you have both typed in the same secret the authentication should be successful. 71 | cmd_debug_on Debug mode is on 72 | cmd_debug_off Debug mode is off 73 | cmd_finish Finished conversation with %s@%s. 74 | cmd_finishall_none No conversations to finish. 75 | cmd_version This is irssi-otr version %s 76 | peer_finished %s has finished the OTR conversation. If you want to continue talking enter %9/otr finish%9 for plaintext or ?OTR? to restart OTR. 77 | Contexts 78 | ctx_ctx_unencrypted %%9%20s%%9 %30s plaintext 79 | ctx_ctx_encrypted %%9%20s%%9 %30s %gencrypted%n 80 | ctx_ctx_finished %%9%20s%%9 %30s finished 81 | ctx_ctx_unknown %%9%20s%%9 %30s unknown state(BUG?) 82 | ctx_fps_no %s %rnot authenticated%n 83 | ctx_fps_smp %s %gauthenticated%n via shared secret (SMP) 84 | ctx_fps_man %s %gauthenticated%n manually 85 | ctx_noctxs No active OTR contexts found 86 | Statusbar 87 | st_plaintext {sb plaintext} 88 | st_untrusted {sb %rOTR(not auth'ed)%n} 89 | st_trust_smp {sb %gOTR%n} 90 | st_trust_manual {sb %gOTR%n} 91 | st_smp_wait_2 {sb {hilight awaiting auth reply...}} 92 | st_smp_have_2 {sb {hilight finalizing auth... (won't happen with libotr 3.1(bug), ask the other guy to initiate)}} 93 | st_smp_failed {sb {hilight auth failed}} 94 | st_smp_finalize {sb {hilight finalizing auth...}} 95 | st_smp_unknown {sb {hilight unknown auth state!}} 96 | st_finished {sb finished} 97 | st_unknown {sb {hilight state unknown (BUG!)}} 98 | -------------------------------------------------------------------------------- /io-config.h.in: -------------------------------------------------------------------------------- 1 | #cmakedefine HAVE_STRSIGNAL 2 | #cmakedefine HAVE_GREGEX_H 3 | #define IRSSIOTR_VERSION "${IRSSIOTR_VERSION}" 4 | -------------------------------------------------------------------------------- /irssi_otr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Off-the-Record Messaging (OTR) module for the irssi IRC client 3 | * Copyright (C) 2008 Uli Meis 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA 18 | */ 19 | 20 | #include "otr.h" 21 | 22 | int debug = FALSE; 23 | 24 | #ifdef HAVE_GREGEX_H 25 | GRegex *regex_nickignore = NULL; 26 | #endif 27 | 28 | void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg) { 29 | ircctx->send_message( 30 | ircctx,recipient,msg,GPOINTER_TO_INT(SEND_TARGET_NICK)); 31 | } 32 | 33 | /* 34 | * Pipes all outgoing private messages through OTR 35 | */ 36 | static void sig_server_sendmsg(SERVER_REC *server, const char *target, 37 | const char *msg, void *target_type_p) 38 | { 39 | if (GPOINTER_TO_INT(target_type_p)==SEND_TARGET_NICK) { 40 | char *otrmsg; 41 | 42 | #ifdef HAVE_GREGEX_H 43 | if (g_regex_match(regex_nickignore,target,0,NULL)) 44 | return; 45 | #endif 46 | otrmsg = otr_send(server,msg,target); 47 | if (otrmsg&&(otrmsg!=msg)) { 48 | signal_continue(4,server,target,otrmsg,target_type_p); 49 | otrl_message_free(otrmsg); 50 | } else if (!otrmsg) 51 | signal_stop(); 52 | } 53 | } 54 | 55 | /* 56 | * Pipes all incoming private messages through OTR 57 | */ 58 | static void sig_message_private(SERVER_REC *server, const char *msg, 59 | const char *nick, const char *address) 60 | { 61 | char *newmsg; 62 | 63 | #ifdef HAVE_GREGEX_H 64 | if (g_regex_match(regex_nickignore,nick,0,NULL)) 65 | return; 66 | #endif 67 | 68 | newmsg = otr_receive(server,msg,nick); 69 | 70 | if (newmsg&&(newmsg!=msg)) { 71 | signal_continue(4,server,newmsg,nick,address); 72 | otrl_message_free(newmsg); 73 | } else if (newmsg==NULL) 74 | signal_stop(); 75 | } 76 | 77 | /* 78 | * Finish an OTR conversation when its query is closed. 79 | */ 80 | static void sig_query_destroyed(QUERY_REC *query) { 81 | if (query&&query->server&&query->server->connrec) { 82 | otr_finish(query->server,query->name,NULL,FALSE); 83 | } 84 | } 85 | 86 | /* 87 | * /otr 88 | */ 89 | static void cmd_otr(const char *data,void *server,WI_ITEM_REC *item) 90 | { 91 | if (*data == '\0') 92 | otr_noticest(TXT_CMD_OTR); 93 | else { 94 | command_runsub("otr", data, server, item); 95 | } 96 | } 97 | 98 | /* used to handle a bunch of commands */ 99 | static void cmd_generic(const char *cmd, const char *args, WI_ITEM_REC *item) 100 | { 101 | QUERY_REC *query = QUERY(item); 102 | 103 | if (*args == '\0') 104 | args = NULL; 105 | 106 | if (!(query&&query->server&&query->server->connrec)) 107 | query = NULL; 108 | 109 | if (strcmp(cmd,"finish")==0) { 110 | if (args) { 111 | otr_finish(NULL,NULL,args,TRUE); 112 | statusbar_items_redraw("otr"); 113 | } else if (query) { 114 | otr_finish(query->server,query->name,NULL,TRUE); 115 | statusbar_items_redraw("otr"); 116 | } else 117 | otr_noticest(TXT_CMD_QNOTFOUND); 118 | } else if (strcmp(cmd,"trust")==0) { 119 | if (args) { 120 | otr_trust(NULL,NULL,args); 121 | statusbar_items_redraw("otr"); 122 | } else if (query) { 123 | otr_trust(query->server,query->name,NULL); 124 | statusbar_items_redraw("otr"); 125 | } else 126 | otr_noticest(TXT_CMD_QNOTFOUND); 127 | } else if (strcmp(cmd,"authabort")==0) { 128 | if (args) { 129 | otr_authabort(NULL,NULL,args); 130 | statusbar_items_redraw("otr"); 131 | } else if (query) { 132 | otr_authabort(query->server,query->name,NULL); 133 | statusbar_items_redraw("otr"); 134 | } else 135 | otr_noticest(TXT_CMD_QNOTFOUND); 136 | } else if (strcmp(cmd,"auth")==0) { 137 | if (args) { 138 | char *second = strchr(args,' '); 139 | char *add = strchr(args,'@'); 140 | if (add&&second&&(addserver,query->name,NULL,args); 146 | } else { 147 | otr_noticest(TXT_CMD_QNOTFOUND); 148 | } 149 | } else if (query) { 150 | otr_notice(query->server,query->name, 151 | TXT_CMD_AUTH); 152 | } else { 153 | otr_noticest(TXT_CMD_AUTH); 154 | } 155 | } 156 | } 157 | 158 | /* 159 | * /otr finish [peername] 160 | */ 161 | static void cmd_finish(const char *data, void *server, WI_ITEM_REC *item) 162 | { 163 | cmd_generic("finish",data,item); 164 | } 165 | 166 | /* 167 | * /otr trust [peername] 168 | */ 169 | static void cmd_trust(const char *data, void *server, WI_ITEM_REC *item) 170 | { 171 | cmd_generic("trust",data,item); 172 | } 173 | 174 | /* 175 | * /otr genkey nick@irc.server.com 176 | */ 177 | static void cmd_genkey(const char *data, void *server, WI_ITEM_REC *item) 178 | { 179 | if (strcmp(data,"abort")==0) 180 | keygen_abort(FALSE); 181 | else if (strchr(data,'@')) 182 | keygen_run(data); 183 | else 184 | otr_noticest(TXT_KG_NEEDACC); 185 | } 186 | 187 | /* 188 | * /otr auth [peername] 189 | */ 190 | static void cmd_auth(const char *data, void *server, WI_ITEM_REC *item) 191 | { 192 | cmd_generic("auth",data,item); 193 | } 194 | 195 | /* 196 | * /otr authabort [peername] 197 | */ 198 | static void cmd_authabort(const char *data, void *server, WI_ITEM_REC *item) 199 | { 200 | cmd_generic("authabort",data,item); 201 | } 202 | 203 | /* 204 | * /otr debug 205 | */ 206 | static void cmd_debug(const char *data, void *server, WI_ITEM_REC *item) 207 | { 208 | debug = !debug; 209 | otr_noticest(debug ? TXT_CMD_DEBUG_ON : TXT_CMD_DEBUG_OFF); 210 | } 211 | 212 | /* 213 | * /otr help 214 | */ 215 | static void cmd_help(const char *data, void *server, WI_ITEM_REC *item) 216 | { 217 | printtext(NULL,NULL,MSGLEVEL_CRAP,otr_help); 218 | } 219 | 220 | /* 221 | * /otr version 222 | */ 223 | static void cmd_version(const char *data, void *server, WI_ITEM_REC *item) 224 | { 225 | otr_noticest(TXT_CMD_VERSION,IRSSIOTR_VERSION); 226 | } 227 | 228 | /* 229 | * /otr contexts 230 | */ 231 | static void cmd_contexts(const char *data, void *server, WI_ITEM_REC *item) 232 | { 233 | struct ctxlist_ *ctxlist = otr_contexts(),*ctxnext = ctxlist; 234 | struct fplist_ *fplist,*fpnext; 235 | 236 | if (!ctxlist) 237 | printformat(NULL,NULL,MSGLEVEL_CRAP,TXT_CTX_NOCTXS); 238 | 239 | while (ctxlist) { 240 | printformat(NULL,NULL,MSGLEVEL_CRAP, 241 | TXT_CTX_CTX_UNENCRYPTED+ctxlist->state, 242 | ctxlist->username, 243 | ctxlist->accountname); 244 | 245 | fplist = ctxlist->fplist; 246 | while (fplist) { 247 | printformat(NULL,NULL,MSGLEVEL_CRAP, 248 | TXT_CTX_FPS_NO+fplist->authby, 249 | fplist->fp); 250 | fplist = fplist->next; 251 | } 252 | ctxlist = ctxlist->next; 253 | } 254 | while ((ctxlist = ctxnext)) { 255 | ctxnext = ctxlist->next; 256 | fpnext = ctxlist->fplist; 257 | while ((fplist = fpnext)) { 258 | fpnext = fplist->next; 259 | g_free(fplist->fp); 260 | g_free(fplist); 261 | } 262 | g_free(ctxlist); 263 | } 264 | } 265 | 266 | /* 267 | * Optionally finish conversations on /quit. We're already doing this on unload 268 | * but the quit handler terminates irc connections before unloading. 269 | */ 270 | static void cmd_quit(const char *data, void *server, WI_ITEM_REC *item) 271 | { 272 | if (settings_get_bool("otr_finishonunload")) 273 | otr_finishall(); 274 | } 275 | 276 | /* 277 | * otr statusbar 278 | */ 279 | static void otr_statusbar(struct SBAR_ITEM_REC *item, int get_size_only) 280 | { 281 | WI_ITEM_REC *wi = active_win->active; 282 | QUERY_REC *query = QUERY(wi); 283 | int formatnum=0; 284 | 285 | if (query&&query->server&&query->server->connrec) 286 | formatnum = otr_getstatus(query->server->nick,query->name,query->server->connrec->address); 287 | 288 | statusbar_item_default_handler( 289 | item, 290 | get_size_only, 291 | formatnum ? formats[formatnum].def : ""," ",FALSE); 292 | } 293 | 294 | void otr_query_create(SERVER_REC *server, const char *nick) 295 | { 296 | if (!server||!nick|| 297 | !settings_get_bool("otr_createqueries")|| 298 | query_find(server, nick)) 299 | return; 300 | 301 | irc_query_create(server->tag, nick, TRUE); 302 | } 303 | 304 | static void read_settings(void) 305 | { 306 | otr_setpolicies(settings_get_str("otr_policy"),FALSE); 307 | otr_setpolicies(settings_get_str("otr_policy_known"),TRUE); 308 | #ifdef HAVE_GREGEX_H 309 | if (regex_nickignore) 310 | g_regex_unref(regex_nickignore); 311 | regex_nickignore = g_regex_new(settings_get_str("otr_ignore"),0,0,NULL); 312 | #endif 313 | 314 | } 315 | 316 | /* 317 | * irssi init() 318 | */ 319 | void otr_init(void) 320 | { 321 | module_register(MODULE_NAME, "core"); 322 | 323 | theme_register(formats); 324 | 325 | if (otrlib_init()) 326 | return; 327 | 328 | signal_add_first("server sendmsg", (SIGNAL_FUNC) sig_server_sendmsg); 329 | signal_add_first("message private", (SIGNAL_FUNC) sig_message_private); 330 | signal_add("query destroyed", (SIGNAL_FUNC) sig_query_destroyed); 331 | 332 | command_bind("otr", NULL, (SIGNAL_FUNC) cmd_otr); 333 | command_bind("otr debug", NULL, (SIGNAL_FUNC) cmd_debug); 334 | command_bind("otr trust", NULL, (SIGNAL_FUNC) cmd_trust); 335 | command_bind("otr finish", NULL, (SIGNAL_FUNC) cmd_finish); 336 | command_bind("otr genkey", NULL, (SIGNAL_FUNC) cmd_genkey); 337 | command_bind("otr auth", NULL, (SIGNAL_FUNC) cmd_auth); 338 | command_bind("otr authabort", NULL, (SIGNAL_FUNC) cmd_authabort); 339 | command_bind("otr help", NULL, (SIGNAL_FUNC) cmd_help); 340 | command_bind("otr contexts", NULL, (SIGNAL_FUNC) cmd_contexts); 341 | command_bind("otr version", NULL, (SIGNAL_FUNC) cmd_version); 342 | 343 | command_bind_first("quit", NULL, (SIGNAL_FUNC) cmd_quit); 344 | 345 | settings_add_str("otr", "otr_policy",IO_DEFAULT_POLICY); 346 | settings_add_str("otr", "otr_policy_known",IO_DEFAULT_POLICY_KNOWN); 347 | settings_add_str("otr", "otr_ignore",IO_DEFAULT_IGNORE); 348 | settings_add_bool("otr", "otr_finishonunload",TRUE); 349 | settings_add_bool("otr", "otr_createqueries",TRUE); 350 | read_settings(); 351 | signal_add("setup changed", (SIGNAL_FUNC) read_settings); 352 | 353 | statusbar_item_register("otr", NULL, otr_statusbar); 354 | 355 | statusbar_items_redraw("window"); 356 | 357 | } 358 | 359 | /* 360 | * irssi deinit() 361 | */ 362 | void otr_deinit(void) 363 | { 364 | #ifdef HAVE_GREGEX_H 365 | g_regex_unref(regex_nickignore); 366 | #endif 367 | 368 | signal_remove("server sendmsg", (SIGNAL_FUNC) sig_server_sendmsg); 369 | signal_remove("message private", (SIGNAL_FUNC) sig_message_private); 370 | signal_remove("query destroyed", (SIGNAL_FUNC) sig_query_destroyed); 371 | 372 | command_unbind("otr", (SIGNAL_FUNC) cmd_otr); 373 | command_unbind("otr debug", (SIGNAL_FUNC) cmd_debug); 374 | command_unbind("otr trust", (SIGNAL_FUNC) cmd_trust); 375 | command_unbind("otr finish", (SIGNAL_FUNC) cmd_finish); 376 | command_unbind("otr genkey", (SIGNAL_FUNC) cmd_genkey); 377 | command_unbind("otr auth", (SIGNAL_FUNC) cmd_auth); 378 | command_unbind("otr authabort", (SIGNAL_FUNC) cmd_authabort); 379 | command_unbind("otr help", (SIGNAL_FUNC) cmd_help); 380 | command_unbind("otr contexts", (SIGNAL_FUNC) cmd_contexts); 381 | command_unbind("otr version", (SIGNAL_FUNC) cmd_version); 382 | 383 | command_unbind("quit", (SIGNAL_FUNC) cmd_quit); 384 | 385 | signal_remove("setup changed", (SIGNAL_FUNC) read_settings); 386 | 387 | statusbar_item_unregister("otr"); 388 | 389 | if (settings_get_bool("otr_finishonunload")) 390 | otr_finishall(); 391 | 392 | otrlib_deinit(); 393 | 394 | theme_unregister(); 395 | } 396 | 397 | IRC_CTX *server_find_address(char *address) 398 | { 399 | GSList *tmp; 400 | 401 | g_return_val_if_fail(address != NULL, NULL); 402 | if (*address == '\0') return NULL; 403 | 404 | for (tmp = servers; tmp != NULL; tmp = tmp->next) { 405 | SERVER_REC *server = tmp->data; 406 | 407 | if (g_strcasecmp(server->connrec->address, address) == 0) 408 | return server; 409 | } 410 | 411 | return NULL; 412 | } 413 | 414 | char *lvlstring[] = { 415 | "NOTICE", 416 | "DEBUG" 417 | }; 418 | 419 | 420 | void otr_log(IRC_CTX *server, const char *nick, 421 | int level, const char *format, ...) { 422 | va_list params; 423 | va_start( params, format ); 424 | char msg[LOGMAX], *s = msg; 425 | 426 | if ((level==LVL_DEBUG)&&!debug) 427 | return; 428 | 429 | s += sprintf(s,"%s","%9OTR%9"); 430 | 431 | if (level!=LVL_NOTICE) 432 | s += sprintf(s,"(%s)",lvlstring[level]); 433 | 434 | s += sprintf(s,": "); 435 | 436 | if( vsnprintf( s, LOGMAX, format, params ) < 0 ) 437 | sprintf( s, "internal error parsing error string (BUG)" ); 438 | va_end( params ); 439 | 440 | printtext(server, nick, MSGLEVEL_MSGS, msg); 441 | } 442 | -------------------------------------------------------------------------------- /irssi_otr.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | #define IRC_CTX SERVER_REC 19 | 20 | static IRC_CTX *IRCCTX_DUP(IRC_CTX *ircctx) __attribute__ ((unused)); 21 | 22 | static IRC_CTX *IRCCTX_DUP(IRC_CTX *ircctx) { 23 | server_ref(ircctx); 24 | return ircctx; 25 | } 26 | 27 | static IRC_CTX *IRCCTX_FREE(IRC_CTX *ircctx) __attribute__ ((unused)); 28 | 29 | static IRC_CTX *IRCCTX_FREE(IRC_CTX *ircctx) 30 | { 31 | server_unref(ircctx); 32 | return ircctx; 33 | } 34 | 35 | void otr_query_create(IRC_CTX *ircctx, const char *nick); 36 | 37 | #define IRCCTX_ADDR(ircctx) ircctx->connrec->address 38 | #define IRCCTX_NICK(ircctx) ircctx->nick 39 | 40 | #define otr_noticest(formatnum,...) \ 41 | printformat(NULL,NULL,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__) 42 | 43 | #define otr_notice(ircctx,nick,formatnum,...) { \ 44 | otr_query_create(ircctx,nick); \ 45 | printformat(ircctx,nick,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__);} 46 | 47 | #define otr_infost(formatnum,...) \ 48 | printformat(NULL,NULL,MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__) 49 | 50 | #define otr_info(server,nick,formatnum,...) { \ 51 | otr_query_create(ircctx,nick); \ 52 | printformat(ircctx,nick,MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__);} 53 | 54 | #define otr_debug(ircctx,nick,formatnum,...) { \ 55 | if (debug) { \ 56 | otr_query_create(ircctx,nick); \ 57 | printformat(ircctx,nick,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__); } } 58 | -------------------------------------------------------------------------------- /makeformats.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Uli Meis 4 | # 5 | # Just a short script to generate our FORMAT_REC 6 | # 7 | 8 | import sys,os,re 9 | 10 | lines = map(lambda x: x.strip(),open(sys.argv[1],"r").readlines()) 11 | 12 | hdr = open("otr-formats.h","w") 13 | src = open("otr-formats.c","w") 14 | srcx = open("xchat-formats.c","w") 15 | 16 | src.write('#include "otr.h"\n'); 17 | srcx.write('#include "otr.h"\n'); 18 | 19 | src.write("""char *otr_help = "%s";\n""" % "\\n".join( 20 | ["%9- OTR help -%9"]+ 21 | [re.sub('^(/otr.*)$','%_\\1%_', 22 | re.sub('^(otr_[a-z_]*)$','%_\\1%_', 23 | re.sub('"([^"]*)"','\\"%_\\1%_\\"', 24 | x.replace('\n','').replace("\t"," ") 25 | ))) 26 | for x in open(sys.argv[2],"r").readlines()] 27 | +["%9- End of OTR help -%9"] 28 | )) 29 | 30 | src.write('FORMAT_REC formats[] = {\n') 31 | srcx.write('FORMAT_REC formats[] = {\n') 32 | 33 | src.write('{ MODULE_NAME, "otr", 0}\n') 34 | srcx.write('{ MODULE_NAME, "otr", 0}\n') 35 | 36 | hdr.write("extern char *otr_help;\n\n"); 37 | 38 | hdr.write("enum {\n") 39 | 40 | hdr.write("TXT_OTR_MODULE_NAME") 41 | 42 | fills = 0 43 | 44 | section = None 45 | 46 | for line in lines: 47 | src.write(",\n") 48 | srcx.write(",\n") 49 | 50 | e = line.split("\t") 51 | 52 | if len(e)==1: 53 | # Section name 54 | section = e[0] 55 | src.write("""{ NULL, "%s", 0 }\n""" % (e[0])) 56 | srcx.write("""{ NULL, "%s", 0 }\n""" % (e[0])) 57 | 58 | hdr.write(",\nTXT_OTR_FILL_%d" % fills) 59 | 60 | fills += 1 61 | 62 | continue 63 | 64 | params = [] 65 | fo = e[1] 66 | new = "" 67 | last=0 68 | i=0 69 | srcx.write("""{ "%s", "%s", 0""" % (e[0],fo.replace("%%9","").replace("%9","").replace("%g","").replace("%n",""))) 70 | for m in re.finditer("(^|[^%])%([0-9]*)[ds]",fo): 71 | if m.group()[-1]=='d': 72 | params += ['1'] 73 | else: 74 | params += ['0'] 75 | new += fo[last:m.start()+len(m.group(1))].replace('%%','%')+"$" 76 | if m.group(2): new+= "[%s]" % m.group(2) 77 | new += "%d" % i 78 | last = m.end() 79 | i += 1 80 | 81 | new += fo[last:].replace('%%','%') 82 | 83 | e[1] = new 84 | e += [len(params)] + params 85 | 86 | #print "Handling line %s with elen %d" % (line,len(e)) 87 | 88 | premsg = "" 89 | if e[1][0] != "{" and section!="Nickignore" and section!="Contexts": 90 | premsg = "%9OTR%9: " 91 | 92 | src.write("""{ "%s", "%s%s", %s""" % (e[0],premsg,e[1],e[2])) 93 | 94 | if len(params)>0: 95 | src.write(", { %s }" % ", ".join(params)) 96 | 97 | src.write("}") 98 | srcx.write("}") 99 | 100 | hdr.write(",\n") 101 | 102 | hdr.write("TXT_%s" % e[0].upper()) 103 | 104 | hdr.write(""" 105 | }; 106 | 107 | extern FORMAT_REC formats[]; 108 | """) 109 | 110 | src.write(""", 111 | { NULL, NULL, 0 } 112 | }; 113 | """) 114 | 115 | srcx.write(""", 116 | { NULL, NULL, 0 } 117 | }; 118 | """) 119 | 120 | hdr.close() 121 | src.close() 122 | srcx.close() 123 | -------------------------------------------------------------------------------- /mksrcpackage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -z "$2" ]; then echo "Syntax: $0 "; exit 1;fi 3 | SDIR="$1" 4 | #VER=`(cd "$SDIR/.git/refs/tags/" && ls -t)|head -n1|sed -e 's/.//'` 5 | VER=$2 6 | 7 | PKG=irc-otr-$VER.tar 8 | HDIR=irc-otr-$VER 9 | mkdir "$HDIR" &&\ 10 | (cd "$SDIR" && git archive --format=tar --prefix=irc-otr-$VER/ HEAD )>$PKG &&\ 11 | (cd "$HDIR" && ln -s ../irssi-headers &&\ 12 | echo -e "SET(IRSSIOTR_VERSION $VER)" >tarballdefs.cmake) &&\ 13 | tar rhf $PKG "$HDIR" &&\ 14 | rm $HDIR/{irssi-headers,tarballdefs.cmake} &&\ 15 | rmdir $HDIR &&\ 16 | gzip $PKG 17 | 18 | PKG=irssi-otr-$VER.tar 19 | HDIR=irssi-otr-$VER 20 | mkdir "$HDIR" &&\ 21 | (cd "$SDIR" && git archive --format=tar --prefix=irssi-otr-$VER/ HEAD )>$PKG &&\ 22 | (cd "$HDIR" && ln -s ../irssi-headers &&\ 23 | echo -e "SET(IRSSIOTR_VERSION $VER)\nSET(BUILDFOR irssi)" >tarballdefs.cmake) &&\ 24 | tar rhf $PKG "$HDIR" &&\ 25 | rm $HDIR/{irssi-headers,tarballdefs.cmake} &&\ 26 | rmdir $HDIR &&\ 27 | gzip $PKG 28 | 29 | PKG=xchat-otr-$VER.tar 30 | HDIR=xchat-otr-$VER 31 | mkdir "$HDIR" &&\ 32 | (cd "$SDIR" && git archive --format=tar --prefix=xchat-otr-$VER/ HEAD )>$PKG &&\ 33 | (cd "$HDIR" && echo -e "SET(IRSSIOTR_VERSION $VER)\nSET(BUILDFOR xchat)" >tarballdefs.cmake) &&\ 34 | tar rhf $PKG "$HDIR" &&\ 35 | rm $HDIR/tarballdefs.cmake &&\ 36 | rmdir $HDIR &&\ 37 | gzip $PKG 38 | -------------------------------------------------------------------------------- /otr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Off-the-Record Messaging (OTR) module for the irssi IRC client 3 | * Copyright (C) 2008 Uli Meis 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | /* OTR */ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | /* glib */ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | /* irssi */ 38 | 39 | #ifdef TARGET_IRSSI 40 | #include 41 | #endif 42 | 43 | /* xchat */ 44 | 45 | #ifdef TARGET_XCHAT 46 | #include 47 | #endif 48 | 49 | /* log stuff */ 50 | 51 | #define LOGMAX 1024 52 | 53 | #define LVL_NOTICE 0 54 | #define LVL_DEBUG 1 55 | 56 | #define otr_logst(level,format,...) \ 57 | otr_log(NULL,NULL,level,format, ## __VA_ARGS__) 58 | 59 | void otr_log(IRC_CTX *server, const char *to, 60 | int level, const char *format, ...); 61 | 62 | /* own */ 63 | 64 | #include "io-config.h" 65 | 66 | /* irssi module name */ 67 | #define MODULE_NAME "otr" 68 | 69 | #include "otr-formats.h" 70 | 71 | /* 72 | * maybe this should be configurable? 73 | * I believe bitlbee has something >500. 74 | */ 75 | #define OTR_MAX_MSG_SIZE 400 76 | 77 | /* otr protocol id */ 78 | #define PROTOCOLID "IRC" 79 | 80 | #define KEYFILE "/otr/otr.key" 81 | #define TMPKEYFILE "/otr/otr.key.tmp" 82 | #define FPSFILE "/otr/otr.fp" 83 | 84 | /* some defaults */ 85 | #define IO_DEFAULT_POLICY "*@localhost opportunistic,*bitlbee* opportunistic,*@im.* opportunistic, *serv@irc* never" 86 | #define IO_DEFAULT_POLICY_KNOWN "* always" 87 | #define IO_DEFAULT_IGNORE "xmlconsole[0-9]*" 88 | 89 | /* one for each OTR context (=communication pair) */ 90 | struct co_info { 91 | char *msgqueue; /* holds partially reconstructed base64 92 | messages */ 93 | IRC_CTX *ircctx; /* irssi server object for this peer */ 94 | int received_smp_init; /* received SMP init msg */ 95 | int smp_failed; /* last SMP failed */ 96 | char better_msg_two[256]; /* what the second line of the "better" 97 | default query msg should like. Eat it 98 | up when it comes in */ 99 | int finished; /* true after you've /otr finished */ 100 | }; 101 | 102 | /* these are returned by /otr contexts */ 103 | 104 | struct fplist_ { 105 | char *fp; 106 | enum { NOAUTH,AUTHSMP,AUTHMAN } authby; 107 | struct fplist_ *next; 108 | }; 109 | 110 | struct ctxlist_ { 111 | char *username; 112 | char *accountname; 113 | enum { STUNENCRYPTED,STENCRYPTED,STFINISHED,STUNKNOWN } state; 114 | struct fplist_ *fplist; 115 | struct ctxlist_ *next; 116 | }; 117 | 118 | /* policy list generated from /set otr_policy */ 119 | 120 | struct plistentry { 121 | GPatternSpec *namepat; 122 | OtrlPolicy policy; 123 | }; 124 | 125 | /* used by the logging functions below */ 126 | extern int debug; 127 | 128 | void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg); 129 | IRC_CTX *server_find_address(char *address); 130 | 131 | /* init stuff */ 132 | 133 | int otrlib_init(); 134 | void otrlib_deinit(); 135 | void otr_initops(); 136 | void otr_setpolicies(const char *policies, int known); 137 | 138 | /* basic send/receive/status stuff */ 139 | 140 | char *otr_send(IRC_CTX *server,const char *msg,const char *to); 141 | char *otr_receive(IRC_CTX *server,const char *msg,const char *from); 142 | int otr_getstatus(char *mynick, char *nick, char *server); 143 | ConnContext *otr_getcontext(const char *accname,const char *nick,int create,void *data); 144 | 145 | /* user interaction */ 146 | 147 | void otr_trust(IRC_CTX *server, char *nick, const char *peername); 148 | void otr_finish(IRC_CTX *server, char *nick, const char *peername, int inquery); 149 | void otr_auth(IRC_CTX *server, char *nick, const char *peername, const char *secret); 150 | void otr_authabort(IRC_CTX *server, char *nick, const char *peername); 151 | struct ctxlist_ *otr_contexts(); 152 | void otr_finishall(); 153 | 154 | 155 | /* key/fingerprint stuff */ 156 | 157 | void keygen_run(const char *accname); 158 | void keygen_abort(); 159 | void key_load(); 160 | void fps_load(); 161 | void otr_writefps(); 162 | 163 | -------------------------------------------------------------------------------- /otr_key.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Off-the-Record Messaging (OTR) module for the irssi IRC client 3 | * Copyright (C) 2008 Uli Meis 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA 18 | */ 19 | 20 | #define _GNU_SOURCE 21 | 22 | #include "otr.h" 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | extern OtrlUserState otr_state; 31 | 32 | typedef enum { KEYGEN_NO, KEYGEN_RUNNING } keygen_status_t; 33 | 34 | struct { 35 | keygen_status_t status; 36 | char *accountname; 37 | char *protocol; 38 | time_t started; 39 | GIOChannel *ch[2]; 40 | guint cpid,cwid; 41 | pid_t pid; 42 | } kg_st = {.status = KEYGEN_NO }; 43 | 44 | void keygen_childwatch(GPid pid,gint status, gpointer data) { 45 | struct pollfd pfd = { 46 | .fd = g_io_channel_unix_get_fd(kg_st.ch[0]), 47 | .events = POLLIN }; 48 | int ret; 49 | 50 | /* nothing to do if keygen_complete has already been called */ 51 | if (data) 52 | return; 53 | 54 | kg_st.pid = 0; 55 | 56 | ret = poll(&pfd,1,0); 57 | 58 | /* data is there, let's wait for keygen_complete to be called */ 59 | if (ret == 1) 60 | return; 61 | 62 | /* no data, report error and reset kg_st */ 63 | if (ret==0) { 64 | if (WIFSIGNALED(status)) { 65 | char sigstr[16]; 66 | 67 | sprintf(sigstr, 68 | #ifndef HAVE_STRSIGNAL 69 | "%d",WTERMSIG(status)); 70 | #else 71 | "%s",strsignal(WTERMSIG(status))); 72 | #endif 73 | otr_noticest(TXT_KG_EXITSIG, 74 | kg_st.accountname, 75 | sigstr); 76 | } 77 | else 78 | otr_noticest(TXT_KG_EXITED,kg_st.accountname); 79 | } else if (ret==-1) 80 | otr_noticest(TXT_KG_POLLERR,kg_st.accountname,strerror(errno)); 81 | 82 | keygen_abort(FALSE); 83 | } 84 | 85 | /* 86 | * Installed as g_io_watch and called when the key generation 87 | * process finishs. 88 | */ 89 | gboolean keygen_complete(GIOChannel *source, GIOCondition condition, 90 | gpointer data) 91 | { 92 | gcry_error_t err; 93 | const char *irssidir = get_irssi_dir(); 94 | char *filename = g_strconcat(irssidir,KEYFILE,NULL); 95 | char *tmpfilename = g_strconcat(irssidir,TMPKEYFILE,NULL); 96 | 97 | read(g_io_channel_unix_get_fd(kg_st.ch[0]),&err,sizeof(err)); 98 | 99 | g_io_channel_shutdown(kg_st.ch[0],FALSE,NULL); 100 | g_io_channel_shutdown(kg_st.ch[1],FALSE,NULL); 101 | g_io_channel_unref(kg_st.ch[0]); 102 | g_io_channel_unref(kg_st.ch[1]); 103 | 104 | if (err) 105 | otr_noticest(TXT_KG_FAILED, 106 | kg_st.accountname, 107 | gcry_strerror(err), 108 | gcry_strsource(err)); 109 | else { 110 | /* reload keys */ 111 | otr_noticest(TXT_KG_COMPLETED, 112 | kg_st.accountname, 113 | time(NULL)-kg_st.started); 114 | rename(tmpfilename,filename); 115 | //otrl_privkey_forget_all(otr_state); <-- done by lib 116 | key_load(); 117 | } 118 | 119 | g_source_remove(kg_st.cwid); 120 | kg_st.cwid = g_child_watch_add(kg_st.pid,keygen_childwatch,(void*)1); 121 | 122 | kg_st.status = KEYGEN_NO; 123 | g_free(kg_st.accountname); 124 | 125 | g_free(filename); 126 | g_free(tmpfilename); 127 | 128 | return FALSE; 129 | } 130 | 131 | /* 132 | * Run key generation in a seperate process (takes ages). 133 | * The other process will rewrite the key file, we shouldn't 134 | * change anything till it's done and we've reloaded the keys. 135 | */ 136 | void keygen_run(const char *accname) 137 | { 138 | gcry_error_t err; 139 | int ret; 140 | int fds[2]; 141 | char *filename = g_strconcat(get_irssi_dir(),TMPKEYFILE,NULL); 142 | char *dir = dirname(g_strdup(filename)); 143 | 144 | if (kg_st.status!=KEYGEN_NO) { 145 | if (strcmp(accname,kg_st.accountname)!=0) 146 | otr_noticest(TXT_KG_ABORTED_DUP, 147 | accname,kg_st.accountname); 148 | return; 149 | } 150 | 151 | if (!g_file_test(dir, G_FILE_TEST_EXISTS)) { 152 | if (g_mkdir(dir,S_IRWXU)) { 153 | otr_noticest(TXT_KG_ABORTED_DIR, 154 | accname,dir,strerror(errno)); 155 | g_free(dir); 156 | g_free(filename); 157 | return; 158 | } else 159 | otr_noticest(TXT_KG_MKDIR,dir); 160 | } 161 | g_free(dir); 162 | 163 | if (pipe(fds) != 0) { 164 | otr_noticest(TXT_KG_PIPE, 165 | accname,strerror(errno)); 166 | g_free(filename); 167 | return; 168 | } 169 | 170 | kg_st.ch[0] = g_io_channel_unix_new(fds[0]); 171 | kg_st.ch[1] = g_io_channel_unix_new(fds[1]); 172 | 173 | kg_st.accountname = g_strdup(accname); 174 | kg_st.protocol = PROTOCOLID; 175 | kg_st.started = time(NULL); 176 | 177 | if ((ret = fork())) { 178 | g_free(filename); 179 | if (ret==-1) { 180 | otr_noticest(TXT_KG_FORK, 181 | accname,strerror(errno)); 182 | return; 183 | } 184 | 185 | kg_st.status = KEYGEN_RUNNING; 186 | kg_st.pid = ret; 187 | 188 | otr_noticest(TXT_KG_INITIATED, 189 | accname); 190 | 191 | kg_st.cpid = g_io_add_watch(kg_st.ch[0], G_IO_IN, 192 | (GIOFunc) keygen_complete, NULL); 193 | kg_st.cwid = g_child_watch_add(kg_st.pid,keygen_childwatch,NULL); 194 | 195 | kg_st.started = time(NULL); 196 | return; 197 | } 198 | 199 | /* child */ 200 | 201 | err = otrl_privkey_generate(otr_state,filename,accname,PROTOCOLID); 202 | write(fds[1],&err,sizeof(err)); 203 | 204 | //g_free(filename); 205 | _exit(0); 206 | } 207 | 208 | /* 209 | * Abort ongoing key generation. 210 | */ 211 | void keygen_abort(int ignoreidle) 212 | { 213 | if (kg_st.status!=KEYGEN_RUNNING) { 214 | if (!ignoreidle) 215 | otr_noticest(TXT_KG_NOABORT); 216 | return; 217 | } 218 | 219 | otr_noticest(TXT_KG_ABORT,kg_st.accountname); 220 | 221 | g_source_remove(kg_st.cpid); 222 | g_source_remove(kg_st.cwid); 223 | g_free(kg_st.accountname); 224 | 225 | if (kg_st.pid!=0) { 226 | kill(kg_st.pid,SIGTERM); 227 | g_child_watch_add(kg_st.pid,keygen_childwatch,(void*)1); 228 | } 229 | 230 | kg_st.status = KEYGEN_NO; 231 | } 232 | 233 | /* 234 | * Write fingerprints to file. 235 | */ 236 | void otr_writefps() 237 | { 238 | gcry_error_t err; 239 | char *filename = g_strconcat(get_irssi_dir(),FPSFILE,NULL); 240 | 241 | err = otrl_privkey_write_fingerprints(otr_state,filename); 242 | 243 | if (err == GPG_ERR_NO_ERROR) { 244 | otr_noticest(TXT_FP_SAVED); 245 | } else { 246 | otr_noticest(TXT_FP_SAVE_ERROR, 247 | gcry_strerror(err), 248 | gcry_strsource(err)); 249 | } 250 | g_free(filename); 251 | } 252 | 253 | /* 254 | * Load private keys. 255 | */ 256 | void key_load() 257 | { 258 | gcry_error_t err; 259 | char *filename = g_strconcat(get_irssi_dir(),KEYFILE,NULL); 260 | 261 | if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { 262 | otr_noticest(TXT_KEY_NOT_FOUND); 263 | return; 264 | } 265 | 266 | err = otrl_privkey_read(otr_state, filename); 267 | 268 | if (err == GPG_ERR_NO_ERROR) { 269 | otr_noticest(TXT_KEY_LOADED); 270 | } else { 271 | otr_noticest(TXT_KEY_LOAD_ERROR, 272 | gcry_strerror(err), 273 | gcry_strsource(err)); 274 | } 275 | g_free(filename); 276 | } 277 | 278 | /* 279 | * Load fingerprints. 280 | */ 281 | void fps_load() 282 | { 283 | gcry_error_t err; 284 | char *filename = g_strconcat(get_irssi_dir(),FPSFILE,NULL); 285 | 286 | if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { 287 | otr_noticest(TXT_FP_NOT_FOUND); 288 | return; 289 | } 290 | 291 | err = otrl_privkey_read_fingerprints(otr_state,filename,NULL,NULL); 292 | 293 | if (err == GPG_ERR_NO_ERROR) { 294 | otr_noticest(TXT_FP_LOADED); 295 | } else { 296 | otr_noticest(TXT_FP_LOAD_ERROR, 297 | gcry_strerror(err), 298 | gcry_strsource(err)); 299 | } 300 | g_free(filename); 301 | } 302 | 303 | -------------------------------------------------------------------------------- /otr_ops.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Off-the-Record Messaging (OTR) module for the irssi IRC client 3 | * Copyright (C) 2008 Uli Meis 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA 18 | */ 19 | 20 | #include "otr.h" 21 | 22 | OtrlMessageAppOps otr_ops; 23 | extern OtrlUserState otr_state; 24 | extern GSList *plistunknown,*plistknown; 25 | 26 | OtrlPolicy IO_DEFAULT_OTR_POLICY = 27 | OTRL_POLICY_MANUAL|OTRL_POLICY_WHITESPACE_START_AKE; 28 | 29 | /* 30 | * Return policy for given context based on the otr_policy /setting 31 | */ 32 | OtrlPolicy ops_policy(void *opdata, ConnContext *context) 33 | { 34 | struct co_info *coi = context->app_data; 35 | char *server = strchr(context->accountname,'@')+1; 36 | OtrlPolicy op = IO_DEFAULT_OTR_POLICY; 37 | GSList *pl; 38 | char fullname[1024]; 39 | 40 | sprintf(fullname, "%s@%s", context->username, server); 41 | 42 | /* loop through otr_policy */ 43 | 44 | if (plistunknown) { 45 | pl = plistunknown; 46 | do { 47 | struct plistentry *ple = pl->data; 48 | 49 | if (g_pattern_match_string(ple->namepat,fullname)) 50 | op = ple->policy; 51 | 52 | } while ((pl = g_slist_next(pl))); 53 | } 54 | 55 | if (plistknown&&context->fingerprint_root.next) { 56 | pl = plistknown; 57 | 58 | /* loop through otr_policy_known */ 59 | 60 | do { 61 | struct plistentry *ple = pl->data; 62 | 63 | if (g_pattern_match_string(ple->namepat,fullname)) 64 | op = ple->policy; 65 | 66 | } while ((pl = g_slist_next(pl))); 67 | } 68 | 69 | if (coi && coi->finished && 70 | (op == OTRL_POLICY_OPPORTUNISTIC || 71 | op == OTRL_POLICY_ALWAYS)) 72 | op = OTRL_POLICY_MANUAL|OTRL_POLICY_WHITESPACE_START_AKE; 73 | return op; 74 | } 75 | 76 | /* 77 | * Request for key generation. 78 | * The lib actually expects us to be finished before the call returns. 79 | * Since this can take more than an hour on some systems there isn't even 80 | * a point in trying... 81 | */ 82 | void ops_create_privkey(void *opdata, const char *accountname, 83 | const char *protocol) 84 | { 85 | keygen_run(accountname); 86 | } 87 | 88 | /* 89 | * Inject OTR message. 90 | * Deriving the server is currently a hack, 91 | * need to derive the server from accountname. 92 | */ 93 | void ops_inject_msg(void *opdata, const char *accountname, 94 | const char *protocol, const char *recipient, const char *message) 95 | { 96 | IRC_CTX *a_serv; 97 | char *msgcopy = g_strdup(message); 98 | 99 | /* OTR sometimes gives us multiple lines 100 | * (e.g. the default query (a.k.a. "better") message) */ 101 | g_strdelimit (msgcopy,"\n",' '); 102 | a_serv = opdata; 103 | if (!a_serv) { 104 | otr_notice(a_serv,recipient,TXT_OPS_INJECT, 105 | accountname,recipient,message); 106 | } else { 107 | irc_send_message(a_serv, recipient, msgcopy); 108 | } 109 | g_free(msgcopy); 110 | } 111 | 112 | /* 113 | * OTR notification. Haven't seen one yet. 114 | */ 115 | void ops_notify(void *opdata, OtrlNotifyLevel level, const char *accountname, 116 | const char *protocol, const char *username, 117 | const char *title, const char *primary, 118 | const char *secondary) 119 | { 120 | ConnContext *co = otr_getcontext(accountname,username,FALSE,NULL); 121 | IRC_CTX *server = opdata; 122 | struct co_info *coi; 123 | if (co) { 124 | coi = co->app_data; 125 | server = coi->ircctx; 126 | } else 127 | otr_notice(server,username,TXT_OPS_NOTIFY_BUG); 128 | 129 | otr_notice(server,username,TXT_OPS_NOTIFY, 130 | title,primary,secondary); 131 | } 132 | 133 | #ifdef HAVE_GREGEX_H 134 | 135 | /* This is kind of messy. */ 136 | const char *convert_otr_msg(const char *msg) 137 | { 138 | GRegex *regex_bold = g_regex_new("]*)?>",0,0,NULL); 139 | GRegex *regex_del = g_regex_new("]*)?>",0,0,NULL); 140 | gchar *msgnohtml = 141 | g_regex_replace_literal(regex_del,msg,-1,0,"",0,NULL); 142 | 143 | msg = g_regex_replace_literal(regex_bold,msgnohtml,-1,0,"*",0,NULL); 144 | 145 | g_free(msgnohtml); 146 | g_regex_unref(regex_del); 147 | g_regex_unref(regex_bold); 148 | 149 | return msg; 150 | } 151 | 152 | #endif 153 | 154 | /* 155 | * OTR message. E.g. "following has been transmitted in clear: ...". 156 | * We're trying to kill the ugly HTML. 157 | */ 158 | int ops_display_msg(void *opdata, const char *accountname, 159 | const char *protocol, const char *username, 160 | const char *msg) 161 | { 162 | ConnContext *co = otr_getcontext(accountname,username,FALSE,opdata); 163 | IRC_CTX *server = opdata; 164 | struct co_info *coi; 165 | 166 | if (co) { 167 | coi = co->app_data; 168 | server = coi->ircctx; 169 | } else 170 | otr_notice(server,username,TXT_OPS_DISPLAY_BUG); 171 | 172 | #ifdef HAVE_GREGEX_H 173 | msg = convert_otr_msg(msg); 174 | otr_notice(server,username,TXT_OPS_DISPLAY,msg); 175 | g_free((char*)msg); 176 | #else 177 | otr_notice(server,username,TXT_OPS_DISPLAY,msg); 178 | #endif 179 | 180 | return 0; 181 | } 182 | 183 | /* 184 | * Gone secure. 185 | */ 186 | void ops_secure(void *opdata, ConnContext *context) 187 | { 188 | struct co_info *coi = context->app_data; 189 | char * trust = context->active_fingerprint->trust ? : ""; 190 | char ownfp[45],peerfp[45]; 191 | 192 | otr_notice(coi->ircctx, 193 | context->username,TXT_OPS_SEC); 194 | if (*trust!='\0') 195 | return; 196 | 197 | /* not authenticated. 198 | * Let's print out the fingerprints for comparison */ 199 | 200 | otrl_privkey_hash_to_human(peerfp, 201 | context->active_fingerprint->fingerprint); 202 | 203 | otr_notice(coi->ircctx,context->username,TXT_OPS_FPCOMP, 204 | otrl_privkey_fingerprint(otr_state, 205 | ownfp, 206 | context->accountname, 207 | PROTOCOLID), 208 | context->username, 209 | peerfp); 210 | } 211 | 212 | /* 213 | * Gone insecure. 214 | */ 215 | void ops_insecure(void *opdata, ConnContext *context) 216 | { 217 | struct co_info *coi = context->app_data; 218 | otr_notice(coi->ircctx, 219 | context->username,TXT_OPS_INSEC); 220 | } 221 | 222 | /* 223 | * Still secure? Need to find out what that means... 224 | */ 225 | void ops_still_secure(void *opdata, ConnContext *context, int is_reply) 226 | { 227 | struct co_info *coi = context->app_data; 228 | otr_notice(coi->ircctx, 229 | context->username,is_reply ? 230 | TXT_OPS_STILL_REPLY : 231 | TXT_OPS_STILL_NO_REPLY); 232 | } 233 | 234 | /* 235 | * OTR log message. IIRC heartbeats are of this category. 236 | */ 237 | void ops_log(void *opdata, const char *message) 238 | { 239 | // otr_infost(TXT_OPS_LOG,message); 240 | } 241 | 242 | /* 243 | * Really critical with IRC. 244 | * Unfortunately, we can't tell our peer which size to use. 245 | * (reminds me of MTU determination...) 246 | */ 247 | int ops_max_msg(void *opdata, ConnContext *context) 248 | { 249 | return OTR_MAX_MSG_SIZE; 250 | } 251 | 252 | /* 253 | * A context changed. 254 | * I believe this is not happening for the SMP expects. 255 | */ 256 | void ops_up_ctx_list(void *opdata) 257 | { 258 | statusbar_items_redraw("otr"); 259 | } 260 | 261 | /* 262 | * Save fingerprint changes. 263 | */ 264 | void ops_writefps(void *data) 265 | { 266 | otr_writefps(); 267 | } 268 | 269 | int ops_is_logged_in(void *opdata, const char *accountname, 270 | const char *protocol, const char *recipient) 271 | { 272 | /*TODO register a handler for event 401 no such nick and set 273 | * a variable offline=TRUE. Reset it to false in otr_receive and 274 | * otr_send */ 275 | return TRUE; 276 | } 277 | 278 | /* 279 | * Initialize our OtrlMessageAppOps 280 | */ 281 | void otr_initops() { 282 | memset(&otr_ops,0,sizeof(otr_ops)); 283 | 284 | otr_ops.policy = ops_policy; 285 | otr_ops.create_privkey = ops_create_privkey; 286 | otr_ops.inject_message = ops_inject_msg; 287 | otr_ops.notify = ops_notify; 288 | otr_ops.display_otr_message = ops_display_msg; 289 | otr_ops.gone_secure = ops_secure; 290 | otr_ops.gone_insecure = ops_insecure; 291 | otr_ops.still_secure = ops_still_secure; 292 | otr_ops.log_message = ops_log; 293 | otr_ops.max_message_size = ops_max_msg; 294 | otr_ops.update_context_list = ops_up_ctx_list; 295 | otr_ops.write_fingerprints = ops_writefps; 296 | otr_ops.is_logged_in = ops_is_logged_in; 297 | } 298 | -------------------------------------------------------------------------------- /otr_util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Off-the-Record Messaging (OTR) module for the irssi IRC client 3 | * Copyright (C) 2008 Uli Meis 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA 18 | */ 19 | 20 | #include "otr.h" 21 | 22 | #include 23 | 24 | OtrlUserState otr_state = NULL; 25 | extern OtrlMessageAppOps otr_ops; 26 | static int otrinited = FALSE; 27 | GSList *plistunknown = NULL; 28 | GSList *plistknown = NULL; 29 | 30 | #ifdef HAVE_GREGEX_H 31 | GRegex *regex_policies; 32 | #endif 33 | 34 | /* 35 | * init otr lib. 36 | */ 37 | int otrlib_init() 38 | { 39 | 40 | if (!otrinited) { 41 | OTRL_INIT; 42 | otrinited = TRUE; 43 | } 44 | 45 | otr_state = otrl_userstate_create(); 46 | 47 | /* load keys and fingerprints */ 48 | 49 | key_load(); 50 | fps_load(); 51 | 52 | otr_initops(); 53 | 54 | #ifdef HAVE_GREGEX_H 55 | regex_policies = 56 | g_regex_new("([^,]+) (never|manual|handlews|opportunistic|always)" 57 | "(,|$)",0,0,NULL); 58 | #endif 59 | 60 | return otr_state==NULL; 61 | } 62 | 63 | /* 64 | * deinit otr lib. 65 | */ 66 | void otrlib_deinit() 67 | { 68 | if (otr_state) { 69 | otr_writefps(); 70 | otrl_userstate_free(otr_state); 71 | otr_state = NULL; 72 | } 73 | 74 | keygen_abort(TRUE); 75 | 76 | otr_setpolicies("",FALSE); 77 | otr_setpolicies("",TRUE); 78 | 79 | #ifdef HAVE_GREGEX_H 80 | g_regex_unref(regex_policies); 81 | #endif 82 | 83 | } 84 | 85 | 86 | /* 87 | * Free our app data. 88 | */ 89 | void context_free_app_info(void *data) 90 | { 91 | struct co_info *coi = data; 92 | if (coi->msgqueue) { 93 | g_free(coi->msgqueue); 94 | } 95 | if (coi->ircctx) 96 | IRCCTX_FREE(coi->ircctx); 97 | } 98 | 99 | /* 100 | * Add app data to context. 101 | * See struct co_info for details. 102 | */ 103 | void context_add_app_info(void *data,ConnContext *co) 104 | { 105 | IRC_CTX *ircctx = IRCCTX_DUP(data); 106 | struct co_info *coi = g_malloc(sizeof(struct co_info)); 107 | 108 | memset(coi,0,sizeof(struct co_info)); 109 | co->app_data = coi; 110 | co->app_data_free = context_free_app_info; 111 | 112 | coi->ircctx = ircctx; 113 | sprintf(coi->better_msg_two,formats[TXT_OTR_BETTER_TWO].def,co->accountname); 114 | } 115 | 116 | /* 117 | * Get a context from a pair. 118 | */ 119 | ConnContext *otr_getcontext(const char *accname,const char *nick, 120 | int create,void *data) 121 | { 122 | ConnContext *co = otrl_context_find( 123 | otr_state, 124 | nick, 125 | accname, 126 | PROTOCOLID, 127 | create, 128 | NULL, 129 | context_add_app_info, 130 | data); 131 | 132 | /* context came from a fingerprint */ 133 | if (co&&data&&!co->app_data) 134 | context_add_app_info(data,co); 135 | 136 | return co; 137 | } 138 | 139 | /* 140 | * Hand the given message to OTR. 141 | * Returns NULL if OTR handled the message and 142 | * the original message otherwise. 143 | */ 144 | char *otr_send(IRC_CTX *ircctx, const char *msg,const char *to) 145 | { 146 | const char *nick = IRCCTX_NICK(ircctx); 147 | const char *address = IRCCTX_ADDR(ircctx); 148 | gcry_error_t err; 149 | char *newmessage = NULL; 150 | ConnContext *co; 151 | char accname[256]; 152 | 153 | sprintf(accname, "%s@%s", nick, address); 154 | 155 | err = otrl_message_sending( 156 | otr_state, 157 | &otr_ops, 158 | ircctx, 159 | accname, 160 | PROTOCOLID, 161 | to, 162 | msg, 163 | NULL, 164 | &newmessage, 165 | context_add_app_info, 166 | ircctx); 167 | 168 | if (err != 0) { 169 | otr_notice(ircctx,to,TXT_SEND_FAILED,msg); 170 | return NULL; 171 | } 172 | 173 | if (newmessage==NULL) 174 | return (char*)msg; 175 | 176 | /* OTR message. Need to do fragmentation */ 177 | 178 | if (!(co = otr_getcontext(accname,to,FALSE,ircctx))) { 179 | otr_notice(ircctx,to,TXT_SEND_CHANGE); 180 | return NULL; 181 | } 182 | 183 | err = otrl_message_fragment_and_send( 184 | &otr_ops, 185 | ircctx, 186 | co, 187 | newmessage, 188 | OTRL_FRAGMENT_SEND_ALL, 189 | NULL); 190 | 191 | if (err != 0) { 192 | otr_notice(ircctx,to,TXT_SEND_FRAGMENT,msg); 193 | } else 194 | otr_debug(ircctx,to,TXT_SEND_CONVERTED,newmessage); 195 | 196 | return NULL; 197 | } 198 | 199 | struct ctxlist_ *otr_contexts() { 200 | ConnContext *context; 201 | Fingerprint *fprint; 202 | struct ctxlist_ *ctxlist = NULL, *ctxhead = NULL; 203 | struct fplist_ *fplist,*fphead; 204 | char fp[41]; 205 | char *trust; 206 | int i; 207 | 208 | for(context = otr_state->context_root; context; 209 | context = context->next) { 210 | if (!ctxlist) 211 | ctxhead = ctxlist = g_malloc0(sizeof(struct ctxlist_)); 212 | else 213 | ctxlist = ctxlist->next = g_malloc0(sizeof(struct 214 | ctxlist_)); 215 | switch (context->msgstate) { 216 | case OTRL_MSGSTATE_PLAINTEXT: ctxlist->state = STUNENCRYPTED;break; 217 | case OTRL_MSGSTATE_ENCRYPTED: ctxlist->state = STENCRYPTED;break; 218 | case OTRL_MSGSTATE_FINISHED: ctxlist->state = STFINISHED;break; 219 | default: ctxlist->state = STUNKNOWN;break; 220 | } 221 | ctxlist->username = context->username; 222 | ctxlist->accountname = context->accountname; 223 | 224 | fplist = fphead = NULL; 225 | for (fprint = context->fingerprint_root.next; fprint; 226 | fprint = fprint->next) { 227 | if (!fplist) 228 | fphead = fplist = g_malloc0(sizeof(struct 229 | fplist_)); 230 | else 231 | fplist = fplist->next = g_malloc0(sizeof(struct 232 | fplist_)); 233 | trust = fprint->trust ? : ""; 234 | for(i=0;i<20;++i) 235 | sprintf(fp+i*2, "%02x", 236 | fprint->fingerprint[i]); 237 | fplist->fp = g_strdup(fp); 238 | if (*trust=='\0') 239 | fplist->authby = NOAUTH; 240 | else if (strcmp(trust,"smp")==0) 241 | fplist->authby = AUTHSMP; 242 | else 243 | fplist->authby = AUTHMAN; 244 | } 245 | 246 | ctxlist->fplist = fphead; 247 | } 248 | return ctxhead; 249 | } 250 | 251 | /* 252 | * Get the OTR status of this conversation. 253 | */ 254 | int otr_getstatus(char *mynick, char *nick, char *server) 255 | { 256 | ConnContext *co; 257 | char accname[128]; 258 | struct co_info *coi; 259 | 260 | sprintf(accname, "%s@%s", mynick, server); 261 | 262 | if (!(co = otr_getcontext(accname,nick,FALSE,NULL))) { 263 | return 0; 264 | } 265 | 266 | coi = co->app_data; 267 | 268 | switch (co->msgstate) { 269 | case OTRL_MSGSTATE_PLAINTEXT: 270 | return TXT_ST_PLAINTEXT; 271 | case OTRL_MSGSTATE_ENCRYPTED: { 272 | char *trust = co->active_fingerprint->trust; 273 | int ex = co->smstate->nextExpected; 274 | 275 | if (trust&&(*trust!='\0')) 276 | return strcmp(trust,"smp")==0 ? TXT_ST_TRUST_SMP : TXT_ST_TRUST_MANUAL; 277 | 278 | switch (ex) { 279 | case OTRL_SMP_EXPECT1: 280 | return TXT_ST_UNTRUSTED; 281 | case OTRL_SMP_EXPECT2: 282 | return TXT_ST_SMP_WAIT_2; 283 | case OTRL_SMP_EXPECT3: 284 | case OTRL_SMP_EXPECT4: 285 | return TXT_ST_SMP_FINALIZE; 286 | default: 287 | return TXT_ST_SMP_UNKNOWN; 288 | } 289 | } 290 | case OTRL_MSGSTATE_FINISHED: 291 | return TXT_ST_FINISHED; 292 | default: 293 | return TXT_ST_UNKNOWN; 294 | } 295 | } 296 | 297 | /* 298 | * Finish the conversation. 299 | */ 300 | void otr_finish(IRC_CTX *ircctx, char *nick, const char *peername, int inquery) 301 | { 302 | ConnContext *co; 303 | char accname[128]; 304 | struct co_info *coi; 305 | char *pserver = NULL; 306 | 307 | if (peername) { 308 | pserver = strchr(peername,'@'); 309 | if (!pserver) 310 | return; 311 | ircctx = server_find_address(pserver+1); 312 | if (!ircctx) 313 | return; 314 | *pserver = '\0'; 315 | nick = (char*)peername; 316 | } 317 | 318 | sprintf((char*)accname, "%s@%s", IRCCTX_NICK(ircctx), IRCCTX_ADDR(ircctx)); 319 | 320 | if (!(co = otr_getcontext(accname,nick,FALSE,NULL))) { 321 | if (inquery) 322 | otr_noticest(TXT_CTX_NOT_FOUND, 323 | accname,nick); 324 | if (peername) 325 | *pserver = '@'; 326 | return; 327 | } 328 | 329 | otrl_message_disconnect(otr_state,&otr_ops,ircctx,accname, 330 | PROTOCOLID,nick); 331 | 332 | if (inquery) { 333 | otr_info(ircctx,nick,TXT_CMD_FINISH,nick,IRCCTX_ADDR(ircctx)); 334 | } else { 335 | otr_infost(TXT_CMD_FINISH,nick,IRCCTX_ADDR(ircctx)); 336 | } 337 | 338 | coi = co->app_data; 339 | 340 | /* finish if /otr finish has been issued. Reset if 341 | * we're called cause the query window has been closed. */ 342 | if (coi) 343 | coi->finished = inquery; 344 | 345 | if (peername) 346 | *pserver = '@'; 347 | } 348 | 349 | void otr_finishall() 350 | { 351 | ConnContext *context; 352 | int finished=0; 353 | 354 | for(context = otr_state->context_root; context; 355 | context = context->next) { 356 | struct co_info *coi = context->app_data; 357 | 358 | if (context->msgstate!=OTRL_MSGSTATE_ENCRYPTED) 359 | continue; 360 | 361 | otrl_message_disconnect(otr_state,&otr_ops,coi->ircctx, 362 | context->accountname, 363 | PROTOCOLID, 364 | context->username); 365 | 366 | otr_infost(TXT_CMD_FINISH,context->username, 367 | IRCCTX_ADDR(coi->ircctx)); 368 | finished++; 369 | } 370 | 371 | if (!finished) 372 | otr_infost(TXT_CMD_FINISHALL_NONE); 373 | } 374 | 375 | /* 376 | * Trust our peer. 377 | */ 378 | void otr_trust(IRC_CTX *ircctx, char *nick, const char *peername) 379 | { 380 | ConnContext *co; 381 | char accname[128]; 382 | struct co_info *coi; 383 | char *pserver = NULL; 384 | 385 | if (peername) { 386 | pserver = strchr(peername,'@'); 387 | if (!pserver) 388 | return; 389 | ircctx = server_find_address(pserver+1); 390 | if (!ircctx) 391 | return; 392 | *pserver = '\0'; 393 | nick = (char*)peername; 394 | } 395 | 396 | sprintf((char*)accname, "%s@%s", IRCCTX_NICK(ircctx), IRCCTX_ADDR(ircctx)); 397 | 398 | if (!(co = otr_getcontext(accname,nick,FALSE,NULL))) { 399 | otr_noticest(TXT_CTX_NOT_FOUND, 400 | accname,nick); 401 | if (peername) 402 | *pserver = '@'; 403 | return; 404 | } 405 | 406 | otrl_context_set_trust(co->active_fingerprint,"manual"); 407 | 408 | coi = co->app_data; 409 | coi->smp_failed = FALSE; 410 | 411 | otr_notice(ircctx,nick,TXT_FP_TRUST,nick); 412 | 413 | if (peername) 414 | *pserver = '@'; 415 | } 416 | 417 | /* 418 | * Abort any ongoing SMP authentication. 419 | */ 420 | void otr_abort_auth(ConnContext *co, IRC_CTX *ircctx, const char *nick) 421 | { 422 | struct co_info *coi; 423 | 424 | coi = co->app_data; 425 | 426 | coi->received_smp_init = FALSE; 427 | 428 | otr_notice(ircctx,nick, 429 | co->smstate->nextExpected!=OTRL_SMP_EXPECT1 ? 430 | TXT_AUTH_ABORTED_ONGOING : 431 | TXT_AUTH_ABORTED); 432 | 433 | otrl_message_abort_smp(otr_state,&otr_ops,ircctx,co); 434 | } 435 | 436 | /* 437 | * implements /otr authabort 438 | */ 439 | void otr_authabort(IRC_CTX *ircctx, char *nick, const char *peername) 440 | { 441 | ConnContext *co; 442 | char accname[128]; 443 | char *pserver = NULL; 444 | 445 | if (peername) { 446 | pserver = strchr(peername,'@'); 447 | if (!pserver) 448 | return; 449 | ircctx = server_find_address(pserver+1); 450 | if (!ircctx) 451 | return; 452 | *pserver = '\0'; 453 | nick = (char*)peername; 454 | } 455 | 456 | sprintf((char*)accname, "%s@%s", IRCCTX_NICK(ircctx), IRCCTX_ADDR(ircctx)); 457 | 458 | if (!(co = otr_getcontext(accname,nick,FALSE,NULL))) { 459 | otr_noticest(TXT_CTX_NOT_FOUND, 460 | accname,nick); 461 | if (peername) 462 | *pserver = '@'; 463 | return; 464 | } 465 | 466 | otr_abort_auth(co,ircctx,nick); 467 | 468 | if (peername) 469 | *pserver = '@'; 470 | } 471 | 472 | /* 473 | * Initiate or respond to SMP authentication. 474 | */ 475 | void otr_auth(IRC_CTX *ircctx, char *nick, const char *peername, const char *secret) 476 | { 477 | ConnContext *co; 478 | char accname[128]; 479 | struct co_info *coi; 480 | char *pserver = NULL; 481 | 482 | if (peername) { 483 | pserver = strchr(peername,'@'); 484 | if (!pserver) 485 | return; 486 | ircctx = server_find_address(pserver+1); 487 | if (!ircctx) 488 | return; 489 | *pserver = '\0'; 490 | nick = (char*)peername; 491 | } 492 | 493 | sprintf((char*)accname, "%s@%s", IRCCTX_NICK(ircctx), IRCCTX_ADDR(ircctx)); 494 | 495 | if (!(co = otr_getcontext(accname,nick,FALSE,NULL))) { 496 | otr_noticest(TXT_CTX_NOT_FOUND, 497 | accname,nick); 498 | if (peername) 499 | *pserver = '@'; 500 | return; 501 | } 502 | 503 | if (co->msgstate!=OTRL_MSGSTATE_ENCRYPTED) { 504 | otr_notice(ircctx,nick,TXT_AUTH_NEEDENC); 505 | return; 506 | } 507 | 508 | coi = co->app_data; 509 | 510 | /* Aborting an ongoing auth */ 511 | if (co->smstate->nextExpected!=OTRL_SMP_EXPECT1) 512 | otr_abort_auth(co,ircctx,nick); 513 | 514 | coi->smp_failed = FALSE; 515 | 516 | /* reset trust level */ 517 | if (co->active_fingerprint) { 518 | char *trust = co->active_fingerprint->trust; 519 | if (trust&&(*trust!='\0')) { 520 | otrl_context_set_trust(co->active_fingerprint, ""); 521 | otr_writefps(); 522 | } 523 | } 524 | 525 | if (!coi->received_smp_init) 526 | otrl_message_initiate_smp( 527 | otr_state, 528 | &otr_ops, 529 | ircctx, 530 | co, 531 | (unsigned char*)secret, 532 | strlen(secret)); 533 | else 534 | otrl_message_respond_smp( 535 | otr_state, 536 | &otr_ops, 537 | ircctx, 538 | co, 539 | (unsigned char*)secret, 540 | strlen(secret)); 541 | 542 | otr_notice(ircctx,nick, 543 | coi->received_smp_init ? 544 | TXT_AUTH_RESPONDING : 545 | TXT_AUTH_INITIATED); 546 | 547 | statusbar_items_redraw("otr"); 548 | 549 | if (peername) 550 | *pserver = '@'; 551 | } 552 | 553 | /* 554 | * Handles incoming TLVs of the SMP authentication type. We're not only updating 555 | * our own state but also giving libotr a leg up so it gets through the auth. 556 | */ 557 | void otr_handle_tlvs(OtrlTLV *tlvs, ConnContext *co, 558 | struct co_info *coi, 559 | IRC_CTX *ircctx, const char *from) 560 | { 561 | int abort = FALSE; 562 | 563 | OtrlTLV *tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1); 564 | if (tlv) { 565 | if (co->smstate->nextExpected != OTRL_SMP_EXPECT1) { 566 | otr_notice(ircctx,from,TXT_AUTH_HAVE_OLD, 567 | from); 568 | abort = TRUE; 569 | } else { 570 | otr_notice(ircctx,from,TXT_AUTH_PEER, 571 | from); 572 | coi->received_smp_init = TRUE; 573 | } 574 | } 575 | 576 | tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP2); 577 | if (tlv) { 578 | if (co->smstate->nextExpected != OTRL_SMP_EXPECT2) { 579 | otr_notice(ircctx,from, 580 | TXT_AUTH_PEER_REPLY_WRONG, 581 | from); 582 | abort = TRUE; 583 | } else { 584 | otr_notice(ircctx,from, 585 | TXT_AUTH_PEER_REPLIED, 586 | from); 587 | co->smstate->nextExpected = OTRL_SMP_EXPECT4; 588 | } 589 | } 590 | 591 | tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP3); 592 | if (tlv) { 593 | if (co->smstate->nextExpected != OTRL_SMP_EXPECT3) { 594 | otr_notice(ircctx,from, 595 | TXT_AUTH_PEER_WRONG_SMP3, 596 | from); 597 | abort = TRUE; 598 | } else { 599 | char *trust = co->active_fingerprint->trust; 600 | if (trust&&(*trust!='\0')) { 601 | otr_notice(ircctx,from, 602 | TXT_AUTH_SUCCESSFUL); 603 | } else { 604 | otr_notice(ircctx,from, 605 | TXT_AUTH_FAILED); 606 | coi->smp_failed = TRUE; 607 | } 608 | co->smstate->nextExpected = OTRL_SMP_EXPECT1; 609 | coi->received_smp_init = FALSE; 610 | } 611 | } 612 | 613 | tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP4); 614 | if (tlv) { 615 | if (co->smstate->nextExpected != OTRL_SMP_EXPECT4) { 616 | otr_notice(ircctx,from, 617 | TXT_AUTH_PEER_WRONG_SMP4, 618 | from); 619 | abort = TRUE; 620 | } else { 621 | char *trust = co->active_fingerprint->trust; 622 | if (trust&&(*trust!='\0')) { 623 | otr_notice(ircctx,from, 624 | TXT_AUTH_SUCCESSFUL); 625 | } else { 626 | /* unreachable since 4 is never sent out on 627 | * error */ 628 | otr_notice(ircctx,from, 629 | TXT_AUTH_FAILED); 630 | coi->smp_failed = TRUE; 631 | } 632 | co->smstate->nextExpected = OTRL_SMP_EXPECT1; 633 | coi->received_smp_init = FALSE; 634 | } 635 | } 636 | if (abort) 637 | otr_abort_auth(co,ircctx,from); 638 | 639 | tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED); 640 | if (tlv) 641 | otr_notice(ircctx,from,TXT_PEER_FINISHED,from); 642 | 643 | statusbar_items_redraw("otr"); 644 | } 645 | 646 | /* 647 | * Hand the given message to OTR. 648 | * Returns NULL if its an OTR protocol message and 649 | * the (possibly) decrypted message otherwise. 650 | */ 651 | char *otr_receive(IRC_CTX *ircctx, const char *msg,const char *from) 652 | { 653 | int ignore_message; 654 | char *newmessage = NULL; 655 | char accname[256]; 656 | char *lastmsg; 657 | ConnContext *co; 658 | struct co_info *coi; 659 | OtrlTLV *tlvs; 660 | 661 | sprintf(accname, "%s@%s", IRCCTX_NICK(ircctx), IRCCTX_ADDR(ircctx)); 662 | 663 | if (!(co = otr_getcontext(accname,from,TRUE,ircctx))) { 664 | otr_noticest(TXT_CTX_NOT_CREATE, 665 | accname,from); 666 | return NULL; 667 | } 668 | 669 | coi = co->app_data; 670 | 671 | /* Really lame but I don't see how you could do this in a generic 672 | * way unless the IRC server would somehow mark continuation messages. 673 | */ 674 | if ((strcmp(msg,coi->better_msg_two)==0)|| 675 | (strcmp(msg,formats[TXT_OTR_BETTER_THREE].def)==0)) { 676 | otr_debug(ircctx,from,TXT_RECEIVE_IGNORE_QUERY); 677 | return NULL; 678 | } 679 | 680 | /* The server might have split lines that were too long 681 | * (bitlbee does that). The heuristic is simple: If we can find ?OTR: 682 | * in the message but it doesn't end with a ".", queue it and wait 683 | * for the rest. 684 | */ 685 | lastmsg = co->app_data; 686 | 687 | if (coi->msgqueue) { /* already something in the queue */ 688 | strcpy(coi->msgqueue+strlen(coi->msgqueue),msg); 689 | 690 | /* wait for more? */ 691 | if ((strlen(msg)>OTR_MAX_MSG_SIZE)&& 692 | (msg[strlen(msg)-1]!='.')&& 693 | (msg[strlen(msg)-1]!=',')) 694 | return NULL; 695 | 696 | otr_debug(ircctx,from,TXT_RECEIVE_DEQUEUED, 697 | strlen(coi->msgqueue)); 698 | 699 | msg = coi->msgqueue; 700 | coi->msgqueue = NULL; 701 | 702 | /* this is freed thru our caller by otrl_message_free. 703 | * Currently ok since that just uses free(). 704 | */ 705 | 706 | } else if (strstr(msg,"?OTR:")&& 707 | (strlen(msg)>OTR_MAX_MSG_SIZE)&& 708 | (msg[strlen(msg)-1]!='.')&& 709 | (msg[strlen(msg)-1]!=',')) { 710 | coi->msgqueue = malloc(4096*sizeof(char)); 711 | strcpy(coi->msgqueue,msg); 712 | otr_debug(ircctx,from,TXT_RECEIVE_QUEUED,strlen(msg)); 713 | return NULL; 714 | } 715 | 716 | ignore_message = otrl_message_receiving( 717 | otr_state, 718 | &otr_ops, 719 | ircctx, 720 | accname, 721 | PROTOCOLID, 722 | from, 723 | msg, 724 | &newmessage, 725 | &tlvs, 726 | NULL, 727 | NULL); 728 | 729 | if (tlvs) 730 | otr_handle_tlvs(tlvs,co,coi,ircctx,from); 731 | 732 | if (ignore_message) { 733 | otr_debug(ircctx,from, 734 | TXT_RECEIVE_IGNORE, strlen(msg),accname,from,msg); 735 | return NULL; 736 | } 737 | 738 | if (newmessage) 739 | otr_debug(ircctx,from,TXT_RECEIVE_CONVERTED); 740 | 741 | return newmessage ? : (char*)msg; 742 | } 743 | 744 | void otr_setpolicies(const char *policies, int known) 745 | { 746 | #ifdef HAVE_GREGEX_H 747 | GMatchInfo *match_info; 748 | GSList *plist = known ? plistknown : plistunknown; 749 | 750 | if (plist) { 751 | GSList *p = plist; 752 | do { 753 | struct plistentry *ple = p->data; 754 | g_pattern_spec_free(ple->namepat); 755 | g_free(p->data); 756 | } while ((p = g_slist_next(p))); 757 | 758 | g_slist_free(plist); 759 | plist = NULL; 760 | } 761 | 762 | g_regex_match(regex_policies,policies,0,&match_info); 763 | 764 | while(g_match_info_matches(match_info)) { 765 | struct plistentry *ple = (struct plistentry *)g_malloc0(sizeof(struct plistentry)); 766 | char *pol = g_match_info_fetch(match_info, 2); 767 | 768 | ple->namepat = g_pattern_spec_new(g_match_info_fetch(match_info, 1)); 769 | 770 | switch (*pol) { 771 | case 'n': 772 | ple->policy = OTRL_POLICY_NEVER; 773 | break; 774 | case 'm': 775 | ple->policy = OTRL_POLICY_MANUAL; 776 | break; 777 | case 'h': 778 | ple->policy = OTRL_POLICY_MANUAL|OTRL_POLICY_WHITESPACE_START_AKE; 779 | break; 780 | case 'o': 781 | ple->policy = OTRL_POLICY_OPPORTUNISTIC; 782 | break; 783 | case 'a': 784 | ple->policy = OTRL_POLICY_ALWAYS; 785 | break; 786 | } 787 | 788 | plist = g_slist_append(plist,ple); 789 | 790 | g_free(pol); 791 | 792 | g_match_info_next(match_info, NULL); 793 | } 794 | 795 | g_match_info_free(match_info); 796 | 797 | if (known) 798 | plistknown = plist; 799 | else 800 | plistunknown = plist; 801 | #endif 802 | } 803 | -------------------------------------------------------------------------------- /tarballdefs.cmake: -------------------------------------------------------------------------------- 1 | SET(IRSSIOTR_VERSION 0.3) 2 | SET(BUILDFOR xchat) 3 | -------------------------------------------------------------------------------- /xchat_otr.c: -------------------------------------------------------------------------------- 1 | #include "otr.h" 2 | 3 | int debug = 0; 4 | 5 | #ifdef HAVE_GREGEX_H 6 | GRegex *regex_nickignore = NULL; 7 | #endif 8 | 9 | hexchat_plugin *ph; 10 | 11 | static char set_policy[512] = IO_DEFAULT_POLICY; 12 | static char set_policy_known[512] = IO_DEFAULT_POLICY_KNOWN; 13 | static char set_ignore[512] = IO_DEFAULT_IGNORE; 14 | static int set_finishonunload = TRUE; 15 | 16 | int extract_nick(char *nick, char *line) 17 | { 18 | char *excl; 19 | 20 | if (*line++ != ':') 21 | return FALSE; 22 | 23 | strcpy(nick,line); 24 | 25 | if ((excl = strchr(nick,'!'))) 26 | *excl = '\0'; 27 | 28 | return TRUE; 29 | 30 | } 31 | 32 | void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg) { 33 | hexchat_commandf(ph, "PRIVMSG %s :%s", recipient, msg); 34 | } 35 | 36 | int cmd_otr(char *word[], char *word_eol[], void *userdata) 37 | { 38 | const char *own_nick = hexchat_get_info(ph, "nick"); 39 | char *target = (char*)hexchat_get_info(ph, "channel"); 40 | const char *server = hexchat_get_info(ph, "server"); 41 | IRC_CTX ircctxs = { 42 | .nick = (char*)own_nick, 43 | .address = (char*)server }, 44 | *ircctx = &ircctxs; 45 | 46 | char *cmd = word[2]; 47 | 48 | if (strcmp(cmd,"debug")==0) { 49 | debug = !debug; 50 | otr_noticest(debug ? TXT_CMD_DEBUG_ON : TXT_CMD_DEBUG_OFF); 51 | } else if (strcmp(cmd,"version")==0) { 52 | otr_noticest(TXT_CMD_VERSION,IRSSIOTR_VERSION); 53 | } else if (strcmp(cmd,"finish")==0) { 54 | if (word[3]&&*word[3]) 55 | otr_finish(NULL,NULL,word[3],TRUE); 56 | else 57 | otr_finish(ircctx,target,NULL,TRUE); 58 | } else if (strcmp(cmd,"trust")==0) { 59 | if (word[3]&&*word[3]) 60 | otr_trust(NULL,NULL,word[3]); 61 | else 62 | otr_trust(ircctx,target,NULL); 63 | } else if (strcmp(cmd,"authabort")==0) { 64 | if (word[3]&&*word[3]) 65 | otr_authabort(NULL,NULL,word[3]); 66 | else 67 | otr_authabort(ircctx,target,NULL); 68 | } else if (strcmp(cmd,"genkey")==0) { 69 | if (word[3]&&*word[3]) { 70 | if (strcmp(word[3],"abort")==0) 71 | keygen_abort(FALSE); 72 | else if (strchr(word[3],'@')) 73 | keygen_run(word[3]); 74 | else 75 | otr_noticest(TXT_KG_NEEDACC); 76 | } else { 77 | otr_noticest(TXT_KG_NEEDACC); 78 | } 79 | } else if (strcmp(cmd,"auth")==0) { 80 | if (!word[3]||!*word[3]) { 81 | otr_notice(ircctx,target, 82 | TXT_CMD_AUTH); 83 | } else if (word[4]&&*word[4]&&strchr(word[3],'@')) 84 | otr_auth(NULL,NULL,word_eol[4],word[3]); 85 | else 86 | otr_auth(ircctx,target,NULL,word_eol[3]); 87 | } else if (strcmp(cmd,"set")==0) { 88 | if (strcmp(word[3],"policy")==0) { 89 | otr_setpolicies(word_eol[4],FALSE); 90 | strcpy(set_policy,word_eol[4]); 91 | } else if (strcmp(word[3],"policy_known")==0) { 92 | otr_setpolicies(word_eol[4],TRUE); 93 | strcpy(set_policy_known,word_eol[4]); 94 | } else if (strcmp(word[3],"ignore")==0) { 95 | #ifdef HAVE_GREGEX_H 96 | if (regex_nickignore) 97 | g_regex_unref(regex_nickignore); 98 | regex_nickignore = g_regex_new(word_eol[4],0,0,NULL); 99 | strcpy(set_ignore,word_eol[4]); 100 | #endif 101 | } else if (strcmp(word[3],"finishonunload")==0) { 102 | set_finishonunload = (strcasecmp(word[4],"true")==0); 103 | } else { 104 | hexchat_printf(ph, "policy: %s\n" 105 | "policy_known: %s\nignore: %s\n" 106 | "finishonunload: %s\n", 107 | set_policy,set_policy_known,set_ignore, 108 | set_finishonunload ? "true" : "false"); 109 | } 110 | 111 | } 112 | 113 | return HEXCHAT_EAT_ALL; 114 | } 115 | 116 | int hook_outgoing(char *word[], char *word_eol[], void *userdata) 117 | { 118 | const char *own_nick = hexchat_get_info(ph, "nick"); 119 | const char *channel = hexchat_get_info(ph, "channel"); 120 | const char *server = hexchat_get_info(ph, "server"); 121 | char newmsg[512]; 122 | char *otrmsg; 123 | IRC_CTX ircctx = { 124 | .nick = (char*)own_nick, 125 | .address = (char*)server }; 126 | 127 | if ((*channel == '&')||(*channel == '#')) 128 | return HEXCHAT_EAT_NONE; 129 | 130 | #ifdef HAVE_GREGEX_H 131 | if (g_regex_match(regex_nickignore,channel,0,NULL)) 132 | return HEXCHAT_EAT_NONE; 133 | #endif 134 | otrmsg = otr_send(&ircctx,word_eol[1],channel); 135 | 136 | if (otrmsg==word_eol[1]) 137 | return HEXCHAT_EAT_NONE; 138 | 139 | hexchat_emit_print(ph, "Your Message", own_nick, word_eol[1], NULL, NULL); 140 | 141 | if (!otrmsg) 142 | return HEXCHAT_EAT_ALL; 143 | 144 | snprintf(newmsg, 511, "PRIVMSG %s :%s", channel, otrmsg); 145 | 146 | otrl_message_free(otrmsg); 147 | hexchat_command(ph, newmsg); 148 | 149 | return HEXCHAT_EAT_ALL; 150 | } 151 | 152 | int hook_privmsg(char *word[], char *word_eol[], void *userdata) 153 | { 154 | char nick[256]; 155 | char *newmsg; 156 | const char *server = hexchat_get_info(ph, "server"); 157 | const char *own_nick = hexchat_get_info(ph, "nick"); 158 | IRC_CTX ircctx = { 159 | .nick = (char*)own_nick, 160 | .address = (char*)server }; 161 | hexchat_context *query_ctx; 162 | 163 | char *chanmsg = word[3]; 164 | if ((*chanmsg == '&')||(*chanmsg == '#')) 165 | return HEXCHAT_EAT_NONE; 166 | if (!extract_nick(nick,word[1])) 167 | return HEXCHAT_EAT_NONE; 168 | 169 | #ifdef HAVE_GREGEX_H 170 | if (g_regex_match(regex_nickignore,nick,0,NULL)) 171 | return HEXCHAT_EAT_NONE; 172 | #endif 173 | 174 | newmsg = otr_receive(&ircctx,word_eol[2],nick); 175 | 176 | if (!newmsg) { 177 | return HEXCHAT_EAT_ALL; 178 | } 179 | 180 | if (newmsg==word_eol[2]) { 181 | return HEXCHAT_EAT_NONE; 182 | } 183 | 184 | query_ctx = hexchat_find_context(ph, server, nick); 185 | if(query_ctx==NULL) { 186 | hexchat_commandf(ph, "query %s", nick); 187 | query_ctx = hexchat_find_context(ph, server, nick); 188 | } 189 | 190 | #ifdef HAVE_GREGEX_H 191 | GRegex *regex_quot = g_regex_new(""",0,0,NULL); 192 | GRegex *regex_amp = g_regex_new("&",0,0,NULL); 193 | GRegex *regex_lt = g_regex_new("<",0,0,NULL); 194 | GRegex *regex_gt = g_regex_new(">",0,0,NULL); 195 | char *quotfix = g_regex_replace_literal(regex_quot,newmsg,-1,0,"\"",0,NULL); 196 | char *ampfix = g_regex_replace_literal(regex_amp,quotfix,-1,0,"&",0,NULL); 197 | char *ltfix = g_regex_replace_literal(regex_lt,ampfix,-1,0,"<",0,NULL); 198 | char *gtfix = g_regex_replace_literal(regex_gt,ltfix,-1,0,">",0,NULL); 199 | newmsg = gtfix; 200 | 201 | g_regex_unref(regex_quot); 202 | g_regex_unref(regex_amp); 203 | g_regex_unref(regex_lt); 204 | g_regex_unref(regex_gt); 205 | #endif 206 | 207 | if (query_ctx) 208 | hexchat_set_context(ph, query_ctx); 209 | 210 | hexchat_emit_print(ph, "Private Message", nick, newmsg, NULL, NULL); 211 | 212 | hexchat_command(ph, "GUI COLOR 2"); 213 | otrl_message_free(newmsg); 214 | 215 | return HEXCHAT_EAT_ALL; 216 | } 217 | 218 | void hexchat_plugin_get_info(char **name, char **desc, char **version, void **reserved) 219 | { 220 | *name = PNAME; 221 | *desc = PDESC; 222 | *version = PVERSION; 223 | } 224 | 225 | int hexchat_plugin_init(hexchat_plugin *plugin_handle, 226 | char **plugin_name, 227 | char **plugin_desc, 228 | char **plugin_version, 229 | char *arg) 230 | { 231 | ph = plugin_handle; 232 | 233 | *plugin_name = PNAME; 234 | *plugin_desc = PDESC; 235 | *plugin_version = PVERSION; 236 | 237 | if (otrlib_init()) 238 | return 0; 239 | 240 | hexchat_hook_server(ph, "PRIVMSG", HEXCHAT_PRI_NORM, hook_privmsg, 0); 241 | hexchat_hook_command(ph, "", HEXCHAT_PRI_NORM, hook_outgoing, 0, 0); 242 | hexchat_hook_command(ph, "otr", HEXCHAT_PRI_NORM, cmd_otr, 0, 0); 243 | 244 | otr_setpolicies(IO_DEFAULT_POLICY,FALSE); 245 | otr_setpolicies(IO_DEFAULT_POLICY_KNOWN,TRUE); 246 | 247 | #ifdef HAVE_GREGEX_H 248 | if (regex_nickignore) 249 | g_regex_unref(regex_nickignore); 250 | regex_nickignore = g_regex_new(IO_DEFAULT_IGNORE,0,0,NULL); 251 | #endif 252 | 253 | hexchat_print(ph, "Hexchat OTR loaded successfully!\n"); 254 | 255 | return 1; 256 | } 257 | 258 | int hexchat_plugin_deinit() 259 | { 260 | #ifdef HAVE_GREGEX_H 261 | g_regex_unref(regex_nickignore); 262 | #endif 263 | 264 | if (set_finishonunload) 265 | otr_finishall(); 266 | 267 | otrlib_deinit(); 268 | 269 | return 1; 270 | } 271 | 272 | void printformat(IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...) 273 | { 274 | va_list params; 275 | va_start( params, fnum ); 276 | char msg[LOGMAX], *s = msg; 277 | hexchat_context *find_query_ctx; 278 | char *server = NULL; 279 | 280 | if (ircctx) 281 | server = ircctx->address; 282 | 283 | if (server&&nick) { 284 | find_query_ctx = hexchat_find_context(ph, server, nick); 285 | if(find_query_ctx==NULL) { 286 | // no query window yet, let's open one 287 | hexchat_commandf(ph, "query %s", nick); 288 | find_query_ctx = hexchat_find_context(ph, server, nick); 289 | } 290 | } else { 291 | find_query_ctx = hexchat_find_context(ph, 292 | NULL, 293 | hexchat_get_info(ph, 294 | "network") ? 295 | : 296 | hexchat_get_info(ph,"server")); 297 | } 298 | 299 | hexchat_set_context(ph, find_query_ctx); 300 | 301 | if( vsnprintf( s, LOGMAX, formats[fnum].def, params ) < 0 ) 302 | sprintf( s, "internal error parsing error string (BUG)" ); 303 | va_end( params ); 304 | hexchat_printf(ph, "OTR: %s", s); 305 | } 306 | 307 | IRC_CTX *server_find_address(char *address) 308 | { 309 | static IRC_CTX ircctx; 310 | 311 | ircctx.address = address; 312 | 313 | return &ircctx; 314 | } 315 | -------------------------------------------------------------------------------- /xchat_otr.h: -------------------------------------------------------------------------------- 1 | #include "hexchat-plugin.h" 2 | 3 | #define PNAME "Hexchat OTR" 4 | #define PDESC "Off-The-Record Messaging for Hexchat" 5 | #define PVERSION IRSSIOTR_VERSION 6 | 7 | #define MAX_FORMAT_PARAMS 10 8 | 9 | 10 | struct _IRC_CTX { 11 | char *nick; 12 | char *address; 13 | }; 14 | 15 | typedef struct _IRC_CTX IRC_CTX; 16 | 17 | struct _FORMAT_REC { 18 | char *tag; 19 | char *def; 20 | 21 | int params; 22 | int paramtypes[MAX_FORMAT_PARAMS]; 23 | }; 24 | 25 | typedef struct _FORMAT_REC FORMAT_REC; 26 | 27 | enum { MSGLEVEL_CRAP, MSGLEVEL_MSGS } lvls; 28 | 29 | extern hexchat_plugin *ph; /* plugin handle */ 30 | 31 | #define statusbar_items_redraw(name) ; 32 | #define get_irssi_dir() hexchat_get_info(ph,"configdir") 33 | 34 | void printformat(IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...); 35 | 36 | #define otr_noticest(formatnum,...) \ 37 | printformat(NULL,NULL,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__) 38 | 39 | #define otr_notice(server,nick,formatnum,...) \ 40 | printformat(server,nick,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__) 41 | 42 | #define otr_infost(formatnum,...) \ 43 | printformat(NULL,NULL,MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__) 44 | 45 | #define otr_info(server,nick,formatnum,...) \ 46 | printformat(server,nick,MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__) 47 | 48 | #define otr_debug(server,nick,formatnum,...) { \ 49 | if (debug) \ 50 | printformat(server,nick, \ 51 | MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__); \ 52 | } 53 | #define IRCCTX_DUP(ircctx) g_memdup(ircctx,sizeof(IRC_CTX)); 54 | #define IRCCTX_ADDR(ircctx) ircctx->address 55 | #define IRCCTX_NICK(ircctx) ircctx->nick 56 | #define IRCCTX_FREE(ircctx) g_free(ircctx) 57 | --------------------------------------------------------------------------------