pax_global_header00006660000000000000000000000064142121240630014505gustar00rootroot0000000000000052 comment=ffdddbb4ec2cd839c0303f3214de9a202a135ef1 GTKCrypto-1.0.2/000077500000000000000000000000001421212406300133335ustar00rootroot00000000000000GTKCrypto-1.0.2/.ci/000077500000000000000000000000001421212406300140045ustar00rootroot00000000000000GTKCrypto-1.0.2/.ci/install_gtkcrypto.sh000066400000000000000000000002401421212406300201100ustar00rootroot00000000000000#!/bin/bash set -e __compile_and_install() { cmake .. -DCMAKE_INSTALL_PREFIX=/usr make -j2 make install } mkdir build && cd "$_" __compile_and_install GTKCrypto-1.0.2/.circleci/000077500000000000000000000000001421212406300151665ustar00rootroot00000000000000GTKCrypto-1.0.2/.circleci/config.yml000066400000000000000000000031061421212406300171560ustar00rootroot00000000000000version: 2.0 jobs: ubuntu2004: docker: - image: ubuntu:20.04 steps: - checkout - run: apt update && DEBIAN_FRONTEND=noninteractive apt -y install git gcc clang cmake libgcrypt20-dev libgtk-3-dev libgpgme-dev - run: chmod +x .ci/install_gtkcrypto.sh && .ci/install_gtkcrypto.sh ubuntuLatestRolling: docker: - image: ubuntu:rolling steps: - checkout - run: apt update && DEBIAN_FRONTEND=noninteractive apt -y install git gcc clang cmake libgcrypt20-dev libgtk-3-dev libgpgme-dev - run: chmod +x .ci/install_gtkcrypto.sh && .ci/install_gtkcrypto.sh debianLatestStable: docker: - image: debian:latest steps: - checkout - run: apt update && apt -y install git gcc clang cmake libgcrypt20-dev libgtk-3-dev libgpgme-dev - run: chmod +x .ci/install_gtkcrypto.sh && .ci/install_gtkcrypto.sh fedoraLatestStable: docker: - image: fedora:latest steps: - checkout - run: dnf -y update && dnf -y install git gcc clang cmake make libgcrypt-devel gtk3-devel gpgme-devel - run: chmod +x .ci/install_gtkcrypto.sh && .ci/install_gtkcrypto.sh archlinux: docker: - image: archlinux:latest steps: - checkout - run: pacman -Syu --noconfirm && pacman -S --noconfirm pkg-config git gtk3 libgcrypt gcc clang cmake make gpgme - run: chmod +x .ci/install_gtkcrypto.sh && .ci/install_gtkcrypto.sh workflows: version: 2 build: jobs: - ubuntu2004 - ubuntuLatestRolling - debianLatestStable - fedoraLatestStable - archlinux GTKCrypto-1.0.2/.github/000077500000000000000000000000001421212406300146735ustar00rootroot00000000000000GTKCrypto-1.0.2/.github/workflows/000077500000000000000000000000001421212406300167305ustar00rootroot00000000000000GTKCrypto-1.0.2/.github/workflows/codeql-analysis.yml000066400000000000000000000020401421212406300225370ustar00rootroot00000000000000name: "CodeQL" on: push: branches: [ master ] pull_request: # The branches below must be a subset of the branches above branches: [ master ] schedule: - cron: '24 5 * * 6' jobs: analyze: name: Analyze runs-on: ubuntu-latest permissions: actions: read contents: read security-events: write strategy: fail-fast: false matrix: language: [ 'cpp' ] steps: - name: Checkout repository uses: actions/checkout@v2 - name: Initialize CodeQL uses: github/codeql-action/init@v1 with: languages: ${{ matrix.language }} - name: Install Dependencies run: | sudo apt update && DEBIAN_FRONTEND=noninteractive sudo apt -y install git gcc clang cmake libgcrypt20-dev libgtk-3-dev libgpgme-dev git clone https://github.com/paolostivanin/GTKCrypto ./GTKCrypto - name: Build run: | mkdir build && cd $_ cmake .. make - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v1 GTKCrypto-1.0.2/.gitignore000066400000000000000000000004661421212406300153310ustar00rootroot00000000000000.idea/ cmake-build-debug/ build/ tests/ .flatpak-builder/ TODO # Object files *.o *.ko *.obj *.elf # Precompiled Headers *.gch *.pch # Libraries *.lib *.a *.la *.lo # Shared objects (inc. Windows DLLs) *.dll *.so *.so.* *.dylib # Executables *.exe *.out *.app *.i*86 *.x86_64 *.hex # Debug files *.dSYM/ GTKCrypto-1.0.2/CMakeLists.txt000066400000000000000000000071131421212406300160750ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.5) project(GTKCrypto) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) set(GTKCRYPTO_VERSION_MAJOR "1") set(GTKCRYPTO_VERSION_MINOR "0") set(GTKCRYPTO_VERSION_PATCH "2") set(GTKCRYPTO_VERSION "${GTKCRYPTO_VERSION_MAJOR}.${GTKCRYPTO_VERSION_MINOR}.${GTKCRYPTO_VERSION_PATCH}") set(CMAKE_C_STANDARD 11) set(CMAKE_C_FLAGS "-Wall -Wextra -O2 -Wformat=2 -Wmissing-format-attribute -fstack-protector-strong -Wundef -Wmissing-format-attribute") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color=always -Wstrict-prototypes -Wunreachable-code") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wchar-subscripts -Wwrite-strings -Wpointer-arith -Wbad-function-cast -Wcast-align") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=format-security -Werror=implicit-function-declaration -Wno-sign-compare") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2") # libgpgme need Largefile support set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64") if(CMAKE_COMPILER_IS_GNUCC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pie -fPIE") endif() if(CMAKE_SYSTEM_NAME STREQUAL "Linux") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-add-needed -Wl,--as-needed -Wl,--no-undefined") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro,-z,now") set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-add-needed -Wl,--as-needed") set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-z,relro,-z,now") endif() find_package(PkgConfig REQUIRED) find_package(Gcrypt 1.7.0 REQUIRED) find_package(Gpgme 1.8.0 REQUIRED) pkg_check_modules(GTK3 REQUIRED gtk+-3.0>=3.20.0) include_directories(${GTK3_INCLUDE_DIRS} ${GCRYPT_INCLUDE_DIR} ${GPGME_INCLUDE_DIR}) link_directories(${GTK3_LIBRARY_DIRS} ${GCRYPT_LIBRARY_DIR} ${GPGME_LIBRARY_DIR}) add_definitions(${GTK3_CFLAGS_OTHER} ${GCRYPT_CFLAGS_OTHER} ${GPGME_CFLAGS_OTHER}) set(HEADER_FILES src/common-callbacks.h src/common-widgets.h src/crypt-common.h src/decrypt-files-cb.h src/encrypt-files-cb.h src/gpgme-misc.h src/gtkcrypto.h src/hash.h src/main.h src/misc-style.h src/cleanup.h) set(SOURCE_FILES src/main.c src/message-dialog.c src/compare-file-hash-cb.c src/compute-hash-cb.c src/choose-file.c src/common-callbacks.c src/hash.c src/misc-style.c src/get-file-size.c src/spinner.c src/common-widgets.c src/encrypt-file.c src/mcw-sensitivity.c src/hmac.c src/decrypt-file.c src/crypt-common.c src/decrypt-files-cb.c src/gpgme-misc.c src/sign-file-cb.c src/verify-signature-cb.c src/encrypt-files-cb.c src/app.c src/cleanup.c src/text-cb.c src/get-builder.c) add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES}) target_link_libraries(${PROJECT_NAME} ${GTK3_LIBRARIES} ${GCRYPT_LIBRARIES} ${GPGME_LIBRARIES}) set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "gtkcrypto") install(TARGETS ${PROJECT_NAME} DESTINATION bin) install(FILES data/com.github.paolostivanin.GTKCrypto.desktop DESTINATION share/applications) install(FILES data/com.github.paolostivanin.GTKCrypto.appdata.xml DESTINATION share/metainfo) install(FILES src/ui/gtkcrypto.ui DESTINATION share/gtkcrypto) install(FILES data/icons/com.github.paolostivanin.GTKCrypto.svg DESTINATION share/icons/hicolor/scalable/apps) GTKCrypto-1.0.2/LICENSE000066400000000000000000001017721421212406300143500ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. GTKCrypto - Encrypt, sign and compute hashes of a given file. Copyright (C) 2018 Paolo Stivanin This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . GTKCrypto-1.0.2/README.md000066400000000000000000000053661421212406300146240ustar00rootroot00000000000000# GTKCrypto CircleCI ## Features * Encrypt and decrypt files using AES, Twofish, Serpent or Camellia using either CBC or CTR mode. Key size for all algorithms is 256 bits. * Encrypt and decrypt text using one of the aforementioned algorithms; * Sign a given file using one of your GPG keys. Of course you can also verify the signature for a given file; * Compute hashes for a chosen file (MD5, GOST94, SHA1, SHA2, SHA3, and Whirlpool); ## Security * Encrypt-then-MAC. The plain text is encrypted and then the MAC of the encrypted text is computed and appended to the cipher text. * Confidentiality is given by AES/Twofish/Serpent/Camellia operating in either CBC or CTR mode using a key size of 256 bits; * Integrity is given by the MAC calculation (MAC = HMAC+SHA3-512); * The input key is derived using PBKDF2 with 100'000 iterations and using SHA3-512 as hash algo; * The key is temporarily stored inside a portion of secure memory which is erased before the program exits; ### Text Encryption * Encrypt-then-TAG * Plaintext is encrypted using AES-256 in GCM mode * The input key is derived using PBKDF2 with 150'000 iterations and using SHA3-256 as hash algo; * Data is always stored in a secure memory pool allocated by Gcrypt * The resulting buffer has the following structure: `base64(IV,SALT,encrypt(plaintext),TAG)` ## Requirements |Name|Min Version| |----|-----------| |GTK+|3.20| |Glib|2.48.0| |libgcrypt|1.7.0| |gpgme|1.8.0| ## Screenshots ![Main window](/data/screenshots/mainwin.png?raw=true "Main window") ## How to compile * `$ git clone https://github.com/paolostivanin/GTKCrypto.git` * `$ cd GTKCrypto` * `$ mkdir build && cd $_` * `$ cmake -DCMAKE_INSTALL_PREFIX=/usr ..` * `$ make` * `$ sudo make install` ## How can I trust your program? Don't trust me, trust the code. But if you really want to be sure that I'm not doing things in the wrong way, then you can just encrypt a file using GTKCrypto and write your own decryption program. This is a relatively quick and easy task to achieve, just be sure to first understand the structure of the encrypted file (spoiler: `enc_file = metadata + encrypted_data + HMAC`). More info [HERE](https://github.com/paolostivanin/GTKCrypto/blob/master/src/crypt-common.h). ## Testing * Before each release, I run PVS Studio in order to catch even more errors and/or corner cases * With every commit to master, GTKCrypto is compiled in CircleCI against different distros ## Latest version Stable and pre-release versions can be found [HERE](https://github.com/paolostivanin/GTKCrypto/releases) ## Notes This software is licensed under the GNU General Public License version 3 and above. GTKCrypto-1.0.2/SECURITY.md000066400000000000000000000014451421212406300151300ustar00rootroot00000000000000# Security Policy ## Supported Versions The following list describes whether a version is eligible or not for security updates. | Version | Supported | EOL | | ------- | ------------------ |------| | 1.0.x | :heavy_check_mark: | - | ## Reporting a Vulnerability In case you should find a vulnerability, please report it privately to me via [e-mail](mailto:paolostivanin@users.noreply.github.com). The following is the workflow: - security issue is found, e-mail is sent to me - within 24 hours I will reply to your e-mail with some info like, for example, whether it actually is a security issue and how serious it is - within 15 days I will develop and ship a fix - once the update is out I will open a [security advisory](https://github.com/paolostivanin/GTKCrypto/security/advisories) GTKCrypto-1.0.2/cmake/000077500000000000000000000000001421212406300144135ustar00rootroot00000000000000GTKCrypto-1.0.2/cmake/FindGcrypt.cmake000066400000000000000000000030401421212406300174630ustar00rootroot00000000000000# Copyright (C) 2011 Felix Geyer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 or (at your option) # version 3 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . find_path(GCRYPT_INCLUDE_DIR gcrypt.h) find_library(GCRYPT_LIBRARIES gcrypt) mark_as_advanced(GCRYPT_LIBRARIES GCRYPT_INCLUDE_DIR) if(GCRYPT_INCLUDE_DIR AND EXISTS "${GCRYPT_INCLUDE_DIR}/gcrypt.h") file(STRINGS "${GCRYPT_INCLUDE_DIR}/gcrypt.h" GCRYPT_H REGEX "^#define GCRYPT_VERSION \"[^\"]*\"$") string(REGEX REPLACE "^.*GCRYPT_VERSION \"([0-9]+).*$" "\\1" GCRYPT_VERSION_MAJOR "${GCRYPT_H}") string(REGEX REPLACE "^.*GCRYPT_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" GCRYPT_VERSION_MINOR "${GCRYPT_H}") string(REGEX REPLACE "^.*GCRYPT_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" GCRYPT_VERSION_PATCH "${GCRYPT_H}") set(GCRYPT_VERSION_STRING "${GCRYPT_VERSION_MAJOR}.${GCRYPT_VERSION_MINOR}.${GCRYPT_VERSION_PATCH}") endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Gcrypt DEFAULT_MSG GCRYPT_LIBRARIES GCRYPT_INCLUDE_DIR) GTKCrypto-1.0.2/cmake/FindGpgme.cmake000066400000000000000000000015231421212406300172560ustar00rootroot00000000000000find_path(GPGME_INCLUDE_DIR gpgme.h) find_library(GPGME_LIBRARIES gpgme) mark_as_advanced(GPGME_LIBRARIES GPGME_INCLUDE_DIR) if(GPGME_INCLUDE_DIR AND EXISTS "${GPGME_INCLUDE_DIR}/gpgme.h") file(STRINGS "${GPGME_INCLUDE_DIR}/gcrypt.h" GPGME_H REGEX "^#define GPGME_VERSION \"[^\"]*\"$") string(REGEX REPLACE "^.*GPGME_VERSION \"([0-9]+).*$" "\\1" GPGME_VERSION_MAJOR "${GPGME_H}") string(REGEX REPLACE "^.*GPGME_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" GPGME_VERSION_MINOR "${GPGME_H}") string(REGEX REPLACE "^.*GPGME_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" GPGME_VERSION_PATCH "${GPGME_H}") set(GPGME_VERSION_STRING "${GPGME_VERSION_MAJOR}.${GPGME_VERSION_MINOR}.${GPGME_VERSION_PATCH}") endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Gpgme DEFAULT_MSG GPGME_LIBRARIES GPGME_INCLUDE_DIR) GTKCrypto-1.0.2/data/000077500000000000000000000000001421212406300142445ustar00rootroot00000000000000GTKCrypto-1.0.2/data/com.github.paolostivanin.GTKCrypto.appdata.xml000066400000000000000000000077641421212406300251660ustar00rootroot00000000000000 com.github.paolostivanin.GTKCrypto.desktop CC-BY-4.0 GPL-3.0+ GTKCrypto GTK+ application for encrypting files and computing hashes aes twofish serpent md5 sha2 sha3 gost

GTKCrypto allows you to encrypt and sign files or text. Moreover, given a file, different types of hash can be computed and files can also be compared to check whether or not their content is the same. Supported cipher algorithms: AES, Twofish, Serpent and Camellia, all using 256 bits key and operating in either CBC or CTR mode. Supported hash algorithms: MD5, SHA-1, SHA-2, SHA-3, GOST, Whirlpool.

com.github.paolostivanin.GTKCrypto.desktop Main window https://cdn.rawgit.com/paolostivanin/GTKCrypto/b131382b/data/screenshots/mainwin.png https://github.com/paolostivanin/GTKCrypto info@paolostivanin.com gtkcrypto none none none none none none none none none none none none none none none none none none none none

GTKCrypto 1.0.2 brings some fixes

  • fix double free when decrypting a file
  • fix incorrect version set on header bar
  • fix UI bug when listing GPG keys
  • fix signature verification workflow
  • fix UI file path

GTKCrypto 1.0.1 brings some small fixes

  • force enable large file support via CMakeLists.txt (fix issue on non x86_64 archs)
  • fix possible memory leaks
  • improve performance when listing gpg keys
https://github.com/paolostivanin/GTKCrypto/releases/tag/v1.0.0
GTKCrypto-1.0.2/data/com.github.paolostivanin.GTKCrypto.desktop000066400000000000000000000003771421212406300244170ustar00rootroot00000000000000[Desktop Entry] Type=Application Exec=gtkcrypto Icon=com.github.paolostivanin.GTKCrypto Keywords=aes;twofish;serpent;sha2;sha3;md5;gost; Terminal=false Name=GTKCrypto Comment=Encrypt, sign and compute hashes of a given file Categories=GTK;GNOME;Utility; GTKCrypto-1.0.2/data/icons/000077500000000000000000000000001421212406300153575ustar00rootroot00000000000000GTKCrypto-1.0.2/data/icons/com.github.paolostivanin.GTKCrypto.svg000066400000000000000000000656251421212406300246670ustar00rootroot00000000000000 background Layer 1 GTKCrypto-1.0.2/data/screenshots/000077500000000000000000000000001421212406300166045ustar00rootroot00000000000000GTKCrypto-1.0.2/data/screenshots/mainwin.png000066400000000000000000000361001421212406300207540ustar00rootroot00000000000000‰PNG  IHDRÁkçÐz÷ ÊzTXtRaw profile type exifxÚ˜ir#É Fÿç)|„Ü<rA„oàãû’ÚÓc{Âa²%RÅbU&ðmèôþñwOãÑrÏ©ѹæÌ<úê«o4=âýæ§òs¿éÌ?’×ç÷ç‘Nùuø·æþzWêïÇ^‹ýéBýûîeÿþÁÏñªºPýziqÞ—þ}¡õý¦4ÿ‡;Ï¥’û¿þ¶ïø÷§Œ>UFšwÖš[«¯M~Ê×ÝZn¥i3^ûç÷¨qdð>ñûs•øÅÝ…åïµøzåBe•øàçøgí»ò8þ¹U|@±âZéÏ[Éõ냟¿5£ý~ü§?ôY^ã`ûÃÅæîÌ_5&ýUg>ÛúC¡{ÿ~W?¾F¶ôÇå¹_uŸ3ºõ @ç7Â~6_¾Ï¦=ö0rÀšgâÍøzËk<'%=`[¾Ÿ¶7ë=¥d/•g¼Æ£•YN^{±TÆç ò¹+—§ž­H­µ×Z^í|áqìýZKù¾­|nü²&îý8©s±^ÞÿÿLÿë‰î'JT‚ÐúUxÖU£-±ÙBâ…Óú§­_E¿ üïþ ¤QOýú&2R¾Ú8ŠGÉ•ÒÖŠÇ6ÛσEP¾Ò(åÍsÔI½oITf´ªcÕÕn­Ðh4ˆØ¤jµ²K™§ÔÑ+¤«»FÍ¿×ÿµîÉÿíñëôRþb£?.‰††žÏƾ UËÍÞ8gjc¶>>rifÁŸrãç.ïg÷7çi_|AÙÉžÏf꫞q²¶Ü£"[¡SY×$s’?¡~Ýîö2ä5ÐŒí§çŒÖwÜõ…j÷[uÁq5ï¦çõ-û\n²XYëîýI¯Û9Á¸¤§7XØ(÷ÜSPC¥ìÔÙNŸÂcÝñÑul¡{Zç[~ÛôŽ r§gZ»¬’î¤Eú¢kº[€ƒì+ULƃU§ØFpY¸êÔ«c=}ùLnÆ–Êîtq IoGQ-hÆ÷Ò>²÷¢ç&kø¦íPpb°lÊÌíä%³_¡@‹/SŸ´Ê[-ðGë<§èÒ(Y¶³ Rr¦±,¹Vòéln¾§-ShÖ>¯%৘äÞÕµ …¾‹…—ûµ^U¦R«§ó¬Rv»HL”?¾þ¦{pîÔÓ­¦+}ÑÍ£^ÏÌóÂË{&›ì¸6uÛWëÏ;]E¹Z¹{ú<ŠÂÏ2¼ö—>ýâIJ­S!m—…)ùÎÝO{+·ÉùOüÕ ˆ"Mße#Vç5yRôîõØÚzûŒËl:Tžßy] °™õ~qµmôEW gÁ\}w×Åçz`$½EV,Qöõn½ó•C#p™nу˵C»Yñï»ì_w°×£½?¤ ="M&gmªq7ŒyYîm½NÛâ>¯¸r÷0Ä¡R²'í”WI—ëL×±s¾4¶¢2g³=M/ß½¬Irp/{³…¬Þ\ú•¶l-hó¡<¾œ€DtÙ|ó!9ï6ÆÞ5Ã;Œ]A¬Ê9ˆzk º qÁ.¡ (8H®7K4Ðn©krùËWy‡ |LŠÉÉ(]Þk,÷ò¬ïó 1k\ëwõ>ç\öê ÎÆ…êABNêîuïC:¶eƒ¸õH÷e@ ñ¸¢–tU–ø@·}l´ ¸ ›ƒ®;a»¸–(Mkû˜¡:²±²ÒÀ(Ÿ ë*žpB§!^2*%«‚áªEIJ¼gùâæÜÄh¦Yl€j ƒb×zR¹ÚšcèÊ^ b;;‰¼QÙíFN€Í}¶.´•mÆ4œ˜s•ã˜âáUn—;t?óÃò0{|Š„AÈ]ñ¨;nß{cR;}´ŠBò´¼>-oˆ+˼³«ŽCŸ¨¤ŽÝŽí&ýmï£/Ø»ŸQ %ÒE´¢—âÂðRÓèNåîk2æ (ü»vͨ¯½TÎ“á ƒ2܃ò>רÇfÛ2š ìCð‘ÐÆ(È 0½í:²”‡£7¤šWõ=Pj팣¨@9á`‰ D|][N“‰˜´àöPDåå¢S|fcnÖ =D6°84p-EBÓÊg±•- È,†#þ@¢¬a@,|Qþá‚ŒÔ ¤[H ÌTYËþôJ~Aêq‡u˜I¾QA¨8½*I?8ˆ’²EBc¾:ö*,ùXN!hèEAùp\ݨæ/ ¦DÁÏ:í°MH}×?Å\ æÞùˆåÍì!ÄÊå´¯ ¨Ü^ñ‹"`ø\¨à)÷"ç%ÃøG0¤½…>é±l@ø‡Â@Wõçô#£rû(5سú…±‡„öU]Öt!ŒzˆC*3‚9 ,SËmò¹ùqÁ£?úeÍ&@6‡ IÂIòk¨û$åŽ3,še8t]¯£Lô±Îò0Êám"ÔGØãG[H"¬ù–}g¡ÉˆÈ\/ØE·Ùk3<*ûÀô6°‰ægqˆçDÅ&Š·xxœMÍ%( 9<N¿GÑÇÑ6¬“­"39Ñj'àäUÁ;y²Ñ 2R—”±Å¹„“–&Ûx tÃX¤9Ó\Z…µ¶áŸ,Œr(ÝÄ¿q^ þf‡2ŠŠ`i:ëÅPy²A•n“X3ÖAôÙz/~S…û;§íJÔ ©Ô×Ò¡Œe\ˆV€þœw“Þj‰ôsÞÆB*± þºš-´† ¨‡Íñp‘}—Ò…yÒÜ.ftº7¦>BÐÁU1hQ36©0²"”¯Bù“!r"48ÌÇ9æÂ]eCYÂAFò¤Ûh‚Íùtøzpuë ¤‘ª;iĘ´É(úcI'´†"áÔíK°)G»é(4·–gká`¨eE£˜’’Å`]‚.Eì#tÕ1©Q)aYw¯Üõê´åtQ"æjè%Òÿvg-•P4ÚX Mî‚g÷Ãr#HÅ­Úc_Z‰*d¸Øõ5CKÑbÒ›%v“ èPˆéÇ A%ôòe`“?ÑÓ‚%H‰íjŸÈv0—*©ßÞÐíýp™Æ;²ØZ¸ïúÆàpÄR0†°]V>¤†ê9 £|«'ˆ)ëZ/„m´TÁ†›àHG„<|a#>RéK·)ƒ–âl#öÏÍÎI&-h7ðaüʲ]cz†t;ÜEbJæÁ"é_…ÌÄÞD£WŽ[±³½I„䬃H„¼2E÷! ö‚oÇwñXtm a7Èn£^™¤ðÔA;¤øˆÞLš ¨4>…ý °/TíÍVÁ:a¿ãâ}”Dh*ÄéÁcAA¼Þ'çG$GÕÄóG›=Ò;¤y•a"hŸ)+ mÉh8Ò§«Ôy¯ZZ ‚=î %NDB˜ZË¢5®¢¹T58ä,däÂM?%šLª3q†Á]ÿô”Ž*Ç´Ç)Ïn’”É{¤ Ý* îŽþͰ1¢ “–¥— σ·Æ°‚Ú T¾œ*ã ÷Nôá@L$ÄQFr†hå _äz†¨Á,f r¶À߈`¸+̬Qý„©LˆA¦Ÿ ‚pWÂ׸•š\ßq•®'’i,{_ø~„—ì‡u·Ý™×è$Ms:œ ­&E‘ä¼¢(€;ü °RPdŒŒ:ä¸èåXÍd504*´C˜÷9Ë ;p 1ÎŒ¬½7~Óü…Ö€ ÆÅÑ•p"ð8™ç*3= ®È©9¦F!¡ä}P„³øSI¶¤—w˜Úˆ1'Ý ä˜%Lƒ2¼ˆÈðr‰æÏÜz{˜Ú.¡)JH$a/cƒ¤™¨vâvLìŒè„ öB€v”ŸÐíÎƧà&*@u}þsBITÛáOà IDATxœíw\çÀßËbË’,P\Uq/°V[·­ÖþZ­{´n­ÚÖZkkkÕ¶ÖªTÄ=ꪣÃUjEÄ (0Ã#ã’{Æ-BÏ÷×»7ož»{òÜ{¹ã{„ƒƒCttôèÑ£¥R)à ‚Ëåž|üøÜ©.ÎΆ´‰DÛ~ÝqêÌY„P €Æ6©iis,"Iék;§¦§oß¹K ,œ÷qýš™9ÆÌ¡³þyþ¯¿;„µÿzõjw„Ƹ °ÐËÓ!4vÔȱ£F"„þ¹xé«ußF 0kú4õNH’ü|Íšªêêe‹…µkGÏ<úûñ7oöîÕsõgŸ:¶h¢0–H$F ÞpnÞ¾}êÌÙÖAA:’xϾý555k¿üâõˆˆâ’’ÉÓfœ8ýÇ{ïNpws«G3ãÒgPd§ŽÖ½–þ~V…Ÿ­þòþƒ‡·®^©_‡FaŒwìúËå®Yõ9@!‚ è2œ­?o{–’:ì!ãF¢çPïÞ»ÏÎÎö‹OWÒ „b„µ5B¨ÿà!›¶þ¸#ê·‘oŸ»`áÒ•ŸöyíF,ÝlwÌÞ>ƒ"/]¹‚ê3(r×îè/¿þfèÈÑïMžò×?Bó-yøø1BhÄØ·ÇŒ—~—D"ùeÇÎw?˜ILRŽ0rРï¾^ûÕŸk[‘Ht=6¶eK×Áƒ!„ÜZ¶28R&“)¢z¥fF'(0ðÑã'ó—,-//¯¨¨X°dÙýÜCf´*,**¯¨nÓÆÛKõØd8.]¦¿âË—,QÌÌËË«©© qrtÔø®ÓgÎ;qÂÇË«uP½?âîÞ¥ݾs‡ÇãõéÕ‹~³ÿ@fVvx·®ü|þ×ß­OHxkØP:ãÿ÷ÆÓ;øjíÁ#G[´hñZçÎ?ùhᢜœ\ÅDZX¬ýûé<RnÔZÑ&$8!TPPPfFgÛÖüZù¦gdÎ_²tþ’¥©iiÞ^^?oÙ\ïv,Ë~þ!äæ^[„ݵÿÐaz:(0ðÀžÝ†trñò„P`@€µµ•bfn!¤¨@êXñx1Q»ZµòEUUUq¹œ;ññ¡òŠŠ§ÏžõíÝÇÖÖ–néííµ“Åbûó¯o7llØðaÃ^©“Å æÙÚÚ^ºr埋—3ÝZ¶DåñùÚÞåàà@'BÈÞÞ¾G÷p>?ŸÏÏ»OQ8rÐ@EKk+k‹…Ø¿BèyNŽzo©ii¡Þ½zÒåáõÈ„PfV¶ákA×ËÊÊJÅœêêj„[K×z43:c„Ç£_r¹\õN dÄ ð÷c±ˆÔ´4zgG øùÊ埯\þJx{y-^0!´iëV>?Ÿžéï׊Íf§¦¥x"68bB(.>þö8.—Ó·Ooõ6ôÝ›V<+õE"±!DQý’Ëå"„¬m¬ _ z˜–žA½Ø1tä^uò63:‚ÒÒ.JKÏ  xž“3oñAii½;4ZYYY5Š$ek¾^WT\LÏ$IÙ«ö3|ذýûUW×|ùÍ:¹\Žâr¹ãÇ¥(jÍ7ßæä¾—ÐKÕé×·—Ëù/îî»w{t··³S,V éù/î.B(((!Äæ°BB¡nà~#–N£ÿîÄ!„‚Û´Ñyì­Û—ÿ½Šjka·Ò²² /!„*„Â.]²²²Ô¿¿áÍŽ¥+>ÍÊÎ رí§Û~ È~þ|Éò•õîИçösgÎ|’˜”˜œILJLJÚ³—>ÿŸ9mêƒGŸ>{öÁÔimZ·vrtLKÏïÞmÕÊêo··³ë{ëEQÊ2„PI‰`êÌYíBC¯ßˆe±XïMjÛºuÂýßnØØ3<|ú”{„‡·mÓ&19yÆÜ}}|®^¿îààðîøwJK£vïV B™™ë7nîÓ»gûÐv+>_…1 ð œ6åÃû}·qã…K—3³²JJS'Orvv*)ÒìÕ·ý+’šܶíÏ[6·pp@íØöÓüÅKSRSëÝ¡1sÈÎÎv÷ŽíGŸ¸qófFfË k×î!ƒG¼ùæ+õãäèøÙòO–®ütßÁƒ=ºwïÒ¹“MÔöm‡‹½u;#3“ÏÏ÷÷óëÔ±ƒ¶G нu›ÃáôïÛGy¾««kË–-¯ßˆõókõÑìY­ƒ‚BS'OæçÄ'$s˜§‡ÇÖ~Ú¾=þ^BAaaïž=æ4Wù”°ººZñƒ{Qqñ™óç]\œûôêÖ¾X,ñôð@uêÐáç-›wíŽ~’˜èííý¿‰ïŽ7!ääähH³%á¿[c©TJZ88ÞC„X,®_‡DUU•Q#4 ž¥¤N5»WÊ"ú Š4ü 0œ¦yÍõÚèÅÉÐÐ4ͺxù Aý4‘F§ æPbrrŸß¾];W׆ý¡ išã!À”4Á:˜È!€)CS ‡¦@L˜90r` äÀÈ!€)mw€pD"QcÇX6œÊÊŠÆŽ°l8þy¶±c,¢  ¿±c,8/˜90r` äÀÈ!€)CS ‡¦@L˜¢Çû1æóóJKðàéf—ËuqqõööÑmîÖs­#//W"‘„…u´±±1v„€¹#Õ$&>¶¶¶öööÕÑLO*-¼öZ·‚Â+ïYjZMMM§Ò22´MdfgWVV†µk÷<7×À‰Ðàࢢ²òr'J‚ Më òò ½••U…EEþ55"'üZùÊdr~~¾¡ç9¹Þ^^ÛÀ ww[[›Ì¬l'ìÓÒ3Zºº:99êhéêú4%ÅÙÉÉÃÝÝÀ ?_ßÄädå‰@RF‡Þ¿Owé©C ñݺ…ÇÅß ¶··ÓÑhbTUU?MIéѽ۽{w»ví®£¥~šL&óôð°³³e¢,;;[_o™L¿QSÿyAp¿lóD"‘òýucÌÏÏoåëcŒ¨KÂÀýnÐïC­|u ©€¦ŠûÝ :$“‘0j†¸ß ªCüü†} `ž¸ß ªC¾>>P‡š!îwƒçæs^vò3»cö)ϱ±¶>~ø€‰ÃJ¥½|lŠõð<ÜÝ£wnG-]ùYçŽ'¿ÿB装K&Ž{@¿¾¦Š·ž¸ß =/óõñf’àr¹ÂÂ~Ú¼I1#,ª©6qQÑ1l6{ö Õç@jS"Q Bh`ÿþ~­|é¯5›Íær¹æ_Ú Üï˼Íe…1b±ˆšš:.[ÓÇÆårYl¶†ÏÕ޻ÉdŠç‡bŒÍe“jÇÀýnбL&3—cÆ[±ju×.ãîgee{zzΚ>¥cX½èÌù?ÿ¾p‘¾Ü6{Æ4O«V‰Œ¸qóÖÓ””e ðó þ¹|yûÖèöO“6nù1&jÇÊ/¾ìݳÇí;q™YÙ¾ÞÞ³¦O ŽÙðÌù?BgÎ?nìû'Þ’å+ûw5ü-•ù2¹üàá#×coI$’^=ç8Ù|.o¸ß <–˜É± !DÉ)‘ÒÓI8l6‡ÃAq8œ/[´Ð××wïþýë7m‰Þñ Ç;uæìÕë±kV­rws»w?ÁÙÉ cÌáp¢öì?wÎÒE ìììÚ‹Å»÷îËÏ/ðôô@ÝMHˆŒD÷yåêµO/ö÷ó=xô÷Õk¿‰úuÛ¼¹³1B6{颅ÕÕU*‚o•ð¸ý¬4‡Ëåò”Ó‹žþ-:¦B(ܵSÔW뾋Þwà£Y3tŽûÝÀßÍ%BO’’&¼?Yñ·ÿðÅ¢7öñö’‘Ò)“&UUUåäæQuüäéË{{y°X¨O¯žVVµÏ½›1åÃ×##œœØ,–ƒ½}ÇawèEwââ7ztP ?ÆhæÔ½¼<¯Ýˆ­¬¬”Éd¤LVXX nˆW ïìù¿t¬‹X"ùëÂÅ„)9Bhæ´)wîÆkC1ÇÀýnP"e239xc„»tê¸kû6ÅœªªêÊÊÚÇב$IŸ1Q”ØÖÆFJJ‹Š‹«ª«½==éùÊW1Â5/ãEE p=6vÄ›ÃrrsÅbqÛÖAômwR©”Ä…ÂŽa ‹j7ÖpÌRO(ÒOؤ—+Þ‚1ÂçççS5oÑEUUUf²©BîwƒÆC…­|Ìåz…q~¾GƘ "±c,%I.GmMënœÞ½zlß¹«ººúˆ4ß·I`+=ƒCÂSààÐ!´{Çö–µÏp%X,–ù ÜïÕ!o3:/ÓXj¡:';a/„PJJjûv¡ºÛÙÚ¶oßîþÃGqñ÷fOŸ¦(6ÕÕÕŠfÉOŸ9cŒ0–É5}Gu„‡TaŒ±«‹³½Ýß. ià0%îwË»'Ÿ¢(±D¢ü§£±µµõàˆAQ{bróø"‘(þ^‚¶§Êåòˆ.^þ·¨¸¸m›ÖŠù‡Žý~ûNœP(’ËåiéÏRêÿLL£#—ô8^ýuˆ¢¨ç9¹/\߸`„Ÿ$%Mœ4E1ÇÚÚúPLí£)üòyÐ!Œ‘L&[<Þ/;w}¾f-I’A¾¾¾î<žJcš^=Âúeû˜Ñ£$J™Ñ3¼û¡£¿—íCC¶ÿ´•$IŒñð7‡>|üxîÂÅ}zõœ7g–rx©v«Xˆ¦½=fôw7¥¥g,žÿñ˜‘Ãy\nô¾…EEÎNNcGTÎàÆ%_àmÀC®õß Û¶mHnßLÎíí휜•çPæóóBnnî"QâDÉÛÛG (‘H$,ËÑÑÉÚÚš ’$ËÊJe2™Jc‹5uÖÜUŸ®ô÷£ç|µn}Ä ãÇe³ÙR©´¼¼Œ•³X,W'‰ÊÊ^>ÕÛÞÞÁÆÆ¦¸¸H=ò–-ÝÄbý‰666ÎÎ.b±¨´´!doooggÏá°årªªªÒ|žVPXèéᑚúŒé½°c6›e&ã¡ÊJ¡â,L…¢¢Bå—yyµO1—Ë奥Ýi'&bŒÛ¶nM’RÅLIªÍär¹ÆDÑžrûššššš¥wUVVVj|WãbàéåPN.ßÃÝÝQ™5ÿÅÝí߯¯Túò@†k‰fñý1=îwCrˆòôpÃXã1¾é@QÔ­ÿî,[´°îšb„¨&¿îÚ0p¿T‡X,s9–5Aœ?uR (¡/³ÓlÛ²¹ººZÛá©Écà~7ä¼ çæñÝÝÌ⼬Ayþ<[eŸÏo”HÌ÷»AuÈÝÍ­É×!@÷»!uHÎf³ší˜ 9Ãf³(Jÿí†^/³³³µ³µe`1T×Ôº»µÔÛ’½lÙ2‹KJŠ­­­mmm9\NFfÖóœ{{û¬ìçNØÚØæòùYÙÏ œÈ/(ÈÌʶâYé(.¤gfr8 ÔÀ ‚ *„•iéNTUW§¤¥S®©©1p‚$eRRú,%ÕÀ ¹\žü,E,–` ë`¬¤§O«kDlÛÀ ae••/1)ÙÀ [[›Ç‰Ieå®Î.ööv6["‘xxxêHýî˜üü<77w++k½ù41$qqq‘··#wŒ··@Püðá}x¼P3ÄÆÆ& ÈËKÏíð¼€)–wï`n@L˜^X@+à…˜bL/¬X,ª1ùÿ´‹Å2Ä «'‡H’”ËåZnš8ô~×;ŒÑ½Ì|Ä1€é1dïÃyÀƒî2A€åu` Ô!€)P‡¦@˜bн°f‚²uÕÕÕÅ¿U«Q#Þ ïÖ­Q‚i&jXC°¤:¤°®bLåäæÝ¼}{Ý÷›F>eÒû¦¦™¨a Á’rHa]%ÂÓÃí½ ït [´ì“þ}{š8–f¢†5K:–ÑЛž¢(’$C‚ÛvéÜùòÕëtép¬‚¶á°¨:„ªD" NMO×íX5lƒbñçöÎÎNB¡iw¬‚¶¡±¤:„_X•g—”øµj¥Ã± j؆ÆòÆC*¤¤¤…w;VA ÛÐè?–a³Aa]Uððñ“ŒÌÌ·†ÅJŽÕÂZ òóù¿TÃjè­îÊ)«aûõé­hF«ai’Ÿ> ðo…•Ô°zƒ|¹½\¤Ø´ÚÂ6ŒCfE­V,~ž“ûǹó·l]±l ›ÍBa-ŽUPÃ64yaM‡!(¤°Ax{y¶iÝ:jû/Ž-ÿƒ«Ñ±JQ¨aƒ¼°&‹F7 ),ÆH.—I¥¤PX¡òvŽUPÃ2Á8^XãÅÃÖU¥6« †mP,)‡L¨aëA^XÄa€¶~@z ¨aë‡A^XÄa&€¶@˜ã!€)P‡¦èÉ!.—+“ÉèÛ_€fˆ\.çr¹ºÛèÉ!W>?¼°Í…Vw3ðÂZ/,`",ìÞÀ ˜90¼°€VÀ 0¼°SÀ 0¼°€/,` àº=À¨CS L:0êÀ‹wǨ€1þûÂ¥¿.\àóó9\®_+ß oëÞõ5TWËZoš¡öU/M­8õÇß/-_º8$8XTS“˜üÔÅÙ™^e-k½i†ÚW½4µº|õꌩSÚ‡†Êd¤uïžár¹œþ¥UEËZOšŸöU/MíXFQ8=#£G÷®ôKåŸY•µ¬E>öû¿×nÔÔÔôìž’š¶bé"¿V­V¬ZݵKçø„ûYYÙžžž³¦Oé¦þ)“£©j_õbI4C5bøác¿oݶýIbEQÊ‹ZVŒñÁ#ÇâîÞÛðí×û£w·ppxž“Ãb±1ÆçÁ£ÇË-<}üXïžáë7m‘H$Ê ÚWÅŸL&Sï_yÓýSPX´'jçÁ˜èÒÒòè}t #äeñö˜Q?nÚ (-ýtõšy‹—]¹v]ý‚±\.?sþÏË–¸»¹q¹ìÏU^úÆàÁ>Þ^2R:eÒ¤ªªªœÜ<•·77í«^šÚx¨ªª*¸m›ŸØœÇÏ;}æÜÏÛwdggO™ôÁ‹åc\T\,•J}¼½hSlEER¾$Iϧ(±­””*of¨}ÕKS!„$‰D"q°·Ÿ=cZË–-9¢”C½H‘XÌÓùßwc‚ ¤z _sӾꥩÕ!$IVTT8¶p°âY½\Œ0Æîîî'11©KçNJïÀXIûrnÝ— í«æO­³c%íëÁ‘Æ[9󢩇¶ïúíʵëÙÏs‚Òø„û»cö s˜J6‹5zÄ𻣟¥¤VT8iô0š’öU/–ä…Õ‹\.nÛæß«×÷8$‹==<&Nxç­¡C«ªhÕáK-댩bŒ¿Û´™@Äë‘!„z‘²,#„ëºc›¡öU/–ä…5{{{[‡Ãb2™\ù,ÊZV‚ èßi ‹ŠÆN˜xxï«"‹õööJ”–lzÚW½4)/¬!è¬*ïxŒqYYiYB%&'{¸»[Yñ(ŠR‘Åæååªõßì´¯zij9d ……ÙÏs:„µ +÷:ò¿w'Àmãõ¦™zÐÄbñÙ?ÿúù×.ÎÎcF|ãõˆ&\'šfZ‡Ú´ÚõËÏ<O&“WUU …‘ÓL½°b±„¯Æ¢™Ö!Àˆ4Óñ`D L/,  ðÂŒ/,ÀðÂ&¢©Ýû˜È!€)CSÀ h¼°SÀ 0¼°SÀ ð¦®ÛL:0êÀ¨CS Liü:{ëöÈ·'¨ü{×ý‡ßô¡ìVXºò³}ÓÓEíڽ罧ÎúxAVösÝoÄÿõÏÅK?yç½&Nžºüó/âî«÷i,¤R)­8j4~êÛ»·ï—»÷"P̼1p ›Åz¥OW6³^¸|åÁ£Ç‡÷î!6…åºûih›¬ QÑ1l6{öŒiFì³iü"Ô¯oß;ñ÷ è¯øÄ[ÿÝùtù²Wýhe3kaaahHBc9Ö÷;{ƒÛdëÂårYlv“$4¾ c<°¿oÖ/%IZLö,%U&“µ •ËeH»WuŪÕC"#nܼõ4%eÙÂáÝ»)̬¿FíþëŸ ¡KW®øx{¿18òŸË—·oýþÄ'‰I·üµCq9º!l²EÅ8x'.¾D puq?n ­±ŠÙðÌù?BgÎ?nìû'L5wþGsºvéŒÊÌÊ^¼|åéc‡5® y*f¿!„ºtêÀb±>|Ô½[W„ÐwïF (“Õ^¦ù-:¦B(ܵSÔW뾋Þwà£Y3B'jÏÞùsç,]´ÀÎÎ+™Y—/Yäâì,(-]³ês¹\ö<'g÷Þ}ùùžž¡» ‘ƒ”WmÔˆá¿îŠ*,*z=bPûv¡Ê·:(úD¥@·WuÆ”_Œpvrb³ê¬ˆP($IR.“”””8ØÛwìv7!^z'.¾ß>ÊíÈ&ûö˜Ñ¡Ám1Æýúô NMKGUVVÊd2R&+,,Ð+"R^A³UÌšEÂìßwÃæ­sfNÏ~ž#‹B‚ÛÒuH·W#¬vSJ­>+MËd²ˆ®ÇÆŽxsXNn®X,nÛ:HùrtÙd ®ÅÞLJ~ZYY™™™%ëÛWÅ Y7j\»@i›+¯ Ù*fT—WUÍáJÏT|¡±Rðv¶¶íÛ·»ÿðQ\ü½ÙÓ§i[)#Úd33³J‚ysçH¥™LV'6Œer™¢½µµP(T,Bаëvk¶ŠY³!„0Æýûõ¹tåj…P¨¬¼4–WU.—G pñò¿EÅÅêJ͆°Éº¹µ”J¥‡Ž-..¾{3ùÙ3Å"w7·{ ÷ËÊÊÅ B¨SX‡ÓgÏ—ýsQ[‡f«˜5#/lûv¡¦† ŒTù1F‡W•Â*á½4³ÒG好z„ÿôËö1£G©ôß@6YgçEóçÅìÛäøñ.:õîÙCÑÏð7‡>|üxîÂÅ}zõœ7gÖô©“7þðã‚%Ÿ8;;s(ÇSt¥²‚橘5#/,A^^^555ååå*‹4zUU®¨®™ÕÑщÍfÑZV‹5uÖÜUŸ®ô÷Sï¿!l²ööö-‚HÄ#©TB·a±X..®<O$•••²X,gg+++Š’WWW;8´àóó4® ¶MÑ X’cœ—§ú€^U‡+ªkf-//SYú81cܶuk’T½VÕ@6YmÝÊårånåryII±â¥P(Ô¶‚ºCm,Ì(‡šÿâîöï×W*­ÿU °Éj¤¹xÐ(Šºõße‹2Y°Éj¤¹Ô!‚ Ο:)”ÐÏ^­`“ÕH3òÂ>žÍ°°Éj¤¹Ô! áh.ã! á€:0¼°€.À 0¼°SÀ ˜s¹÷°\ ‡¦@L/, ðÂL/,ÀðÂL/,`À ˜¸n0êÀ¨î›IDATCS L:0Å\Ü1z9ùÇ™Ý1û”çØX[?|ÀÄaÐ’!§<óßë76mùQ½ñ€~}W,]̼3Çbê—ËíöÓæMŠ9a‘É=רt}=bÐ[Ck=!ÃFŽú~Ý7;uBÉ)™D,fÞ¿™c19„0b±ˆšš:ŠÓǦQéJ’d­a!DrJ¦ˆóU#´De¬ÅËh4n\ZVzÑ™óþ}ábYyyhpðìÓ<=ÁC_ÿæ†%‡(ŒóóõüŠBË*‹1ÆR’ärÔÖ±îÒ«ŒE!ÛXÕç.<2WŠ¢\œ0Æl6Û¢£ÿX†Í„k¿ š)-Aa„½<<B))©ºcŒ••±ýúôV4«®®V´I~ú,À¿ÆX¡tÕgÝ02×ÂZ òóùô"‘H´iëO ç}|êÌٌ̬Ÿ«§Óc„2(ŠK$Ê:[[[޵'&7/‰âï%ˆµüT£M{èØï·ïÄ …§ÿ(++Я/RSºêk—¹Æ8Ô¾]»oûཉ¿ìÜEßðõªý›fä…Õ FøIRÒÄISs¬­­Å즧յ¬2™lñüy¿ìÜõùšµ$IøúúºóxHƒMV³2¶gx÷CG/Ú‡†lÿi+I’c¥«æP ¹>z’xãæ­½¿íª¬Ž=Ɤ—NŸ=7fäCú77ÌÈ «{{''Gå9…5úSZV‹åèèdmmMI’ee¥2™L£lU]ûÕºõƒŽ7–¬”——Ñ£r¥«zœ>>¾%%Å*úbu™«•••«k˹\N„»»GMMuee¥ÞþM%yauSY)Tœ…© MË*—ËKKºÓhTÆÊHRý ¦¢tU'77GSðª2W±X¬ˆc¬ø ½ý›!“C Šº2×›þº3~’‘™ùÖСX»{Ô°FÁ9d&ÔJaÅâç9¹œ;¿qËÖË–°Ù,¤Ý½ jXÓ`^X…– o/Ï6­[Gmÿű…ƒâ¿o5ºW)Š5¬ ° /¬B ‹1’ËeR))V(‘‘&÷*BÔ°Ìi"^XRX¥6ªîUjX“`9d@ [oÀƒ†¨a™u!PÃ2¼°µ€¶Þ@˜ã!€)P‡¦€ÐxaF€` xaa1÷~f äÀÈ!€)à…´^X€)à…˜^X€)à…ŒxaS×í¦@˜u` Ô!€)P‡¦˜¯;æYJê‰Óddf•–•¹µlÙ«gøÔI˜>ŒWµ´žüãÌwâ6|ûòÌ¥+>пïèÃ_õÓ—¶j@ÿ~#Þöªo4%fZ‡N9{ìÄÉ)“&Íœ6ÍÎÎ6ùéÓ²²òF‰äU-­\.—Íá¨„Êæp¸\n=âgs8\N}ÞhJÌ1‡²²³ý}ïo»\]œI’¤(Ü»g‚`)ÿ¡ÉxeK+íISo_µ™A FÄeÇNœ3r¤½]MMmÒÈåJ<ŒOœ>séÊ¿ååå¡¡!sfLóôð@­XµºsÇŽ ÷dçä´òõ™;sFJjÚ_.—tk?îlZ¿ºbÕjuÛ+Bhꬹó?šÓµKg„PfVöâå+O;¬nÕ! 5Š¢b¼_"¸º¸Œ7fÈàHzÑ£'‰ûÊÎ~îèèØ3¼ûÌiSèù“.\¾’••íéé9kú”ŽaaŒ7°‘1GZVöóà¶­e2RãÒ#¿¿yëöw_µ/ú·Ÿ¹V*•bŒ9ÎãÄÄËŸ>v¸]hÈÒ•ŸålZÿí=»«ªªöì;@¿¶½Î›3çø¡ýááÝW¯ý¦B(ijX,‡C·a±ÙôŠÏ›;{ìèQãǽuõʬéS1Æ¿EÇí‰Úy0&º´´<úE· B”œ‰ÅÊ%§õAxyz._ºäÔÑó¦Oݾ뷬ìlŒ±D"ùú»ï‡ Ž<{òø–ß2DÑ[~~ÁÒ…óO?Ö»gøúM[$‰±··ŒC&cÌÏÏ·³µÕ¸T.—Ÿ:snå'ËZººZ[ñ>[¾LJ’´f!ôÆàÁ^žž2™lÚ‡bŒßÿŽ­µïïNH~úLщºíU[0*–Vm†Wž$%Mx²òŸò§¿=fthp[Œq¿>½CC‚SÓÒBB±XÜíµ×$±“c‹ @Eû·Þæëã##¥S&MªªªÊÉÍ{µ Úð˜ãxÈÕÅ%ŸÜV}QAaI’^žî´%H.—wêÆÏ/ ƒ$I’>b³X¡òò2;[„µ••X,V¬ˆvÛ«âkWWCûb(£Ãðª#Ü¥SÇ]Û·)Ïœ6{®bXSPPp-öfRòÓÊÊÊÌÌ,Yß¾cww·~}úÌ™¿°Ûk]† ޤ©4¤TJ¯E‰mml¤¤Ôô{D7æ8 ¸wÿ~ä ê‹(Š¢(J"‘°_nØl¶µµêÿ¾½¸Y¥öî;]]ÉöªwÏè0¼ÖùtŒóóëÌ|™¾$¹üóÕ=ºw7f´¿Ÿßw6Ñ1RõíÚ5OSRþ8{nó?· \³ê3•»1ÆAH×-…‚9އ&Œ{ëö½ûÔyzxñ$)™~IQÔÓg)þ~XÍöZ'v¥eÚl¯Ö6ÖB¡ðEåö/-­: ¯/?WMa‹•”Ö™™Y%Á¼¹sÚ…ó¸Å|Œqi©À×Ûë“Å ÷íÞõàÑã<>_ãJ©õÝà!‡LOûv!îû‡ŽKMK/..¹s7þÒ•B{ÌÈ;¢v§¦¥WT£÷íwppx­K—Wê_£íµSX‡ÓgÏ—ýsQÑXÙÒŠµ^ ÄÍ­¥T*=tähqqñõØ›ÉÏjÇI"‘èÂå+üüü¢ââk×oð¸Ü–®®¯Ôs#bŽ^X‘HôÑì™Ý»uýýÄÉ —¯H$R/OÏþ}ûБ̚>•Ãå~¿y‹”$»w}mˆïÄâÚÿÁU±½bŒé—ôwI±H£íuúÔÉøqÁ’Oœ‡¿9”ÇãÑíU,­ ¯ÊÁÓ¥C}£a„)Šrqv^4^̾ýGŽïÒ©Sïž=èùÕÕ5÷<:täXuM·×7_­±²²¢;Q^)¬fœ5Ì× kcccggÏår ‚Éd"‘ˆV’Ñ¢…£­­ B„D")//£·©ŠíÕ××·°°¾ÓÊÊÊÕÕ•vRé°½:;»XYYQ”¼ººÚÁ¡ŸŸ‡4Y`5 hØÛ;ØØØ¨H9ÝÝÝkjjc³··wphA„D"ÆI¥’ªª*6›íääÌãñX,–L& +èNWY)oo DbZoµ{akjj¿1*ƒ1.//+//S™¯b{ÍÉy)g‹Åyy/O‰µÙ^KJŠ/é§É M–VZ¥¥¶………J 4¼]&“)º••RxdÍ óÍ¡l¯F§zÐÀöjdš]Û«Ñiv^X°½fW‡£Ó ÇC€‘:0¼°€.À 0¼°SÀ ˜s¼÷°, ‡¦@L/, ðÂL/,ÀðÂL/,`À ˜¸n0êÀ¨CS L:0ÅÝ1Èl¤°õ¼°0}2)l=/¬L¼f%…­à…mtL/…Õáj]±jõȈ7o=MIY¶pAx÷nà…UÇì #include #include "main.h" #include "gtkcrypto.h" static GtkWidget *get_main_window (GtkBuilder *builder); void activate (GtkApplication *app, gpointer user_data __attribute__((unused))) { GtkBuilder *builder = get_builder_from_path (PARTIAL_PATH_TO_UI_FILE); if (builder == NULL) { return; } GtkWidget *main_window = get_main_window (builder); gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (main_window)); if (!gcry_check_version (GCRYPT_MIN_VERSION)) { show_message_dialog (main_window, "The required version of GCrypt is 1.7.0 or greater.", GTK_MESSAGE_ERROR); return; } if (gcry_control (GCRYCTL_INIT_SECMEM, SECURE_MEMORY_POOL_SIZE, 0)) { show_message_dialog (main_window, "Couldn't initialize secure memory.\n", GTK_MESSAGE_ERROR); g_application_quit (G_APPLICATION (app)); return; } gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "encfile_btn")), "clicked", G_CALLBACK (encrypt_files_cb), main_window); g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "decfile_btn")), "clicked", G_CALLBACK (decrypt_files_cb), main_window); g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "sigfile_btn")), "clicked", G_CALLBACK (sign_file_cb), main_window); g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "versig_btn")), "clicked", G_CALLBACK (verify_signature_cb), main_window); g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "enctxt_btn")), "clicked", G_CALLBACK (txt_cb), NULL); g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "dectxt_btn")), "clicked", G_CALLBACK (txt_cb), NULL); g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "chash_btn")), "clicked", G_CALLBACK (compute_hash_cb), main_window); g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "cmphash_btn")), "clicked", G_CALLBACK (compare_files_hash_cb), main_window); g_object_unref (builder); gtk_widget_show_all (main_window); } static GtkWidget * get_main_window (GtkBuilder *builder) { GtkWidget *window = GTK_WIDGET (gtk_builder_get_object(builder, "mainwin")); gchar *header_bar_text = g_malloc0 (strlen (APP_NAME) + strlen (APP_VERSION) + 2); g_snprintf (header_bar_text, strlen (APP_NAME) +1 + strlen (APP_VERSION) + 1, "%s %s", APP_NAME, APP_VERSION); GtkWidget *header_bar = (GTK_WIDGET (gtk_builder_get_object(builder, "main_hb"))); gtk_header_bar_set_title (GTK_HEADER_BAR (header_bar), header_bar_text); return window; }GTKCrypto-1.0.2/src/choose-file.c000066400000000000000000000027701421212406300164710ustar00rootroot00000000000000#include GSList * choose_file (GtkWidget *main_window, const gchar *title, gboolean select_multiple) { GSList *data = NULL; GtkWidget *dialog = gtk_file_chooser_dialog_new (title, GTK_WINDOW (main_window), GTK_FILE_CHOOSER_ACTION_OPEN, "OK", GTK_RESPONSE_ACCEPT, "Cancel", GTK_RESPONSE_CANCEL, NULL); gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), select_multiple); gint result = gtk_dialog_run (GTK_DIALOG (dialog)); switch (result) { case GTK_RESPONSE_ACCEPT: if (select_multiple == TRUE) { data = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (dialog)); } else { gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); data = g_slist_append (data, filename); } gtk_widget_destroy (dialog); break; case GTK_RESPONSE_CANCEL: gtk_widget_destroy (dialog); break; default: break; } return data; } gchar * get_filename_from_list (GSList *list) { gchar *filename = NULL; if (list != NULL) { filename = g_strdup (g_slist_nth_data (list, 0)); } g_slist_free_full (list, g_free); return filename; }GTKCrypto-1.0.2/src/cleanup.c000066400000000000000000000016661421212406300157260ustar00rootroot00000000000000#include #include #include "crypt-common.h" void crypto_keys_cleanup (CryptoKeys *encryption_keys) { gcry_free (encryption_keys->derived_key); gcry_free (encryption_keys->crypto_key); gcry_free (encryption_keys->hmac_key); g_free (encryption_keys); } void gfile_cleanup (GFile *ifile, GFile *ofile) { g_object_unref(ifile); g_object_unref(ofile); } void gstream_cleanup (GFileInputStream *istream, GFileOutputStream *ostream) { if (istream != NULL) { g_input_stream_close (G_INPUT_STREAM (istream), NULL, NULL); g_object_unref (istream); } if (ostream != NULL) { g_output_stream_close (G_OUTPUT_STREAM (ostream), NULL, NULL); g_object_unref (ostream); } } void data_cleanup (gpointer data1, gpointer data2, gpointer data3) { g_free (data1); g_free (data2); g_free (data3); }GTKCrypto-1.0.2/src/cleanup.h000066400000000000000000000006351421212406300157260ustar00rootroot00000000000000#pragma once void crypto_keys_cleanup (CryptoKeys *encryption_keys); void gfile_cleanup (GFile *ifile, GFile *ofile); void gstream_cleanup (GFileInputStream *istream, GFileOutputStream *ostream); void data_cleanup (gpointer data1, gpointer data2, gpointer data3);GTKCrypto-1.0.2/src/common-callbacks.c000066400000000000000000000017531421212406300175010ustar00rootroot00000000000000#include #include "common-callbacks.h" void toggle_changed_cb (GtkToggleButton *button, gpointer user_data) { GtkWidget *popover = user_data; gtk_widget_set_visible (popover, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))); } void toggle_active_cb (gpointer user_data) { GtkToggleButton *menu = user_data; if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (menu))) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (menu), FALSE); } } void copy_to_clipboard_cb (GtkEntry *entry, GtkEntryIconPosition icon_pos __attribute__((unused)), GdkEvent *event __attribute__((unused)), gpointer user_data __attribute__((unused))) { gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1); gtk_editable_copy_clipboard (GTK_EDITABLE (entry)); gtk_editable_set_position (GTK_EDITABLE (entry), 0); } GTKCrypto-1.0.2/src/common-callbacks.h000066400000000000000000000006751421212406300175100ustar00rootroot00000000000000#pragma once G_BEGIN_DECLS void toggle_changed_cb (GtkToggleButton *toggle_btn, gpointer user_data); void toggle_active_cb (gpointer user_data); void copy_to_clipboard_cb (GtkEntry *entry, GtkEntryIconPosition, GdkEvent *event, gpointer user_data); G_END_DECLSGTKCrypto-1.0.2/src/common-widgets.c000066400000000000000000000022411421212406300172210ustar00rootroot00000000000000#include GtkWidget * create_dialog (GtkWidget *main_window, const gchar *widget_name, const gchar *title) { static GtkWidget *dialog = NULL; dialog = gtk_dialog_new (); gtk_widget_set_name (dialog, widget_name); gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (main_window)); gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE); if (title != NULL) { gtk_window_set_title (GTK_WINDOW (dialog), title); } return dialog; } GtkWidget * create_header_bar (GtkWidget *dialog, const gchar *title) { static GtkWidget *header_bar = NULL; header_bar = gtk_header_bar_new(); gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (header_bar), FALSE); gtk_header_bar_set_title (GTK_HEADER_BAR (header_bar), title); gtk_header_bar_set_has_subtitle (GTK_HEADER_BAR (header_bar), FALSE); gtk_window_set_titlebar (GTK_WINDOW (dialog), header_bar); return header_bar; } void set_label_message (GtkWidget *message_label, const gchar *message) { gtk_label_set_markup (GTK_LABEL (message_label), message); }GTKCrypto-1.0.2/src/common-widgets.h000066400000000000000000000006711421212406300172330ustar00rootroot00000000000000#pragma once #include G_BEGIN_DECLS GtkWidget *create_header_bar (GtkWidget *dialog, const gchar *title); GtkWidget *create_dialog (GtkWidget *main_window, const gchar *widget_name, const gchar *title); void set_label_message (GtkWidget *message_label, const gchar *message); G_END_DECLSGTKCrypto-1.0.2/src/compare-file-hash-cb.c000066400000000000000000000326531421212406300201450ustar00rootroot00000000000000#include #include #include "gtkcrypto.h" #include "common-callbacks.h" #include "common-widgets.h" #include "hash.h" #include "misc-style.h" typedef struct compare_hash_widgets_t { GtkWidget *main_window; GtkWidget *cancel_btn; GtkWidget *radio_button[6]; GtkWidget *header_bar_menu; GtkWidget *file1_hash_entry; GtkWidget *file2_hash_entry; GtkWidget *spinner_entry1; GtkWidget *spinner_entry2; gboolean entry1_changed; gboolean entry2_changed; } HashWidgets; typedef struct compare_hash_thread_data_t { GtkEntry *entry; gchar *filename; gint hash_algo; gint digest_size; HashWidgets *widgets_data; } ThreadData; static void select_file_cb (GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkEvent *event, gpointer user_data); static void do_header_bar (GtkWidget *dialog, HashWidgets *widgets); static GtkWidget *create_popover (GtkWidget *parent, GtkPositionType pos, HashWidgets *widgets); static void entry_changed_cb (GtkWidget *btn, gpointer user_data); static gpointer exec_thread (gpointer); void compare_files_hash_cb (GtkWidget *button __attribute__((unused)), gpointer user_data) { HashWidgets *hash_widgets = g_new0 (HashWidgets, 1); hash_widgets->main_window = (GtkWidget *)user_data; hash_widgets->entry1_changed = FALSE; hash_widgets->entry2_changed = FALSE; GtkWidget *dialog = create_dialog (hash_widgets->main_window, "dialog", NULL); hash_widgets->cancel_btn = gtk_dialog_add_button (GTK_DIALOG (dialog), "Cancel", GTK_RESPONSE_CANCEL); gtk_widget_set_margin_top (hash_widgets->cancel_btn, 10); gtk_widget_set_size_request (dialog, 600, -1); do_header_bar (dialog, hash_widgets); GtkWidget *content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); GtkWidget *grid = gtk_grid_new (); gtk_container_add (GTK_CONTAINER (content_area), grid); hash_widgets->file1_hash_entry = gtk_entry_new (); gtk_widget_set_name (hash_widgets->file1_hash_entry, "file1_he_name"); hash_widgets->file2_hash_entry = gtk_entry_new (); gtk_widget_set_name (hash_widgets->file2_hash_entry, "file2_he_name"); gtk_editable_set_editable (GTK_EDITABLE (hash_widgets->file1_hash_entry), FALSE); gtk_editable_set_editable (GTK_EDITABLE (hash_widgets->file2_hash_entry), FALSE); gtk_widget_set_hexpand (hash_widgets->file1_hash_entry, TRUE); gtk_widget_set_hexpand (hash_widgets->file2_hash_entry, TRUE); PangoData *pango_data = get_pango_monospace_attr (); gtk_entry_set_attributes (GTK_ENTRY (hash_widgets->file1_hash_entry), pango_data->attrs); gtk_entry_set_attributes (GTK_ENTRY (hash_widgets->file2_hash_entry), pango_data->attrs); gtk_entry_set_icon_from_icon_name (GTK_ENTRY (hash_widgets->file1_hash_entry), GTK_ENTRY_ICON_SECONDARY, "document-open-symbolic"); gtk_entry_set_icon_from_icon_name (GTK_ENTRY (hash_widgets->file2_hash_entry), GTK_ENTRY_ICON_SECONDARY, "document-open-symbolic"); hash_widgets->spinner_entry1 = create_spinner(); hash_widgets->spinner_entry2 = create_spinner(); gtk_grid_set_row_spacing (GTK_GRID (grid), 10); gtk_grid_set_column_spacing (GTK_GRID (grid), 5); gtk_grid_attach (GTK_GRID (grid), hash_widgets->file1_hash_entry, 0, 1, 4, 1); gtk_grid_attach (GTK_GRID (grid), hash_widgets->file2_hash_entry, 0, 2, 4, 1); gtk_grid_attach_next_to (GTK_GRID (grid), hash_widgets->spinner_entry1, hash_widgets->file1_hash_entry, GTK_POS_RIGHT, 1, 1); gtk_grid_attach_next_to (GTK_GRID (grid), hash_widgets->spinner_entry2, hash_widgets->file2_hash_entry, GTK_POS_RIGHT, 1, 1); g_signal_connect (hash_widgets->file1_hash_entry, "icon-press", G_CALLBACK (select_file_cb), hash_widgets); g_signal_connect (hash_widgets->file2_hash_entry, "icon-press", G_CALLBACK (select_file_cb), hash_widgets); g_signal_connect_swapped (dialog, "button-press-event", G_CALLBACK (toggle_active_cb), hash_widgets->header_bar_menu); g_signal_connect (hash_widgets->file1_hash_entry, "changed", G_CALLBACK (entry_changed_cb), hash_widgets); g_signal_connect (hash_widgets->file2_hash_entry, "changed", G_CALLBACK (entry_changed_cb), hash_widgets); gtk_widget_show_all (dialog); gint result = gtk_dialog_run (GTK_DIALOG (dialog)); switch (result) { case GTK_RESPONSE_CANCEL: gtk_widget_destroy (dialog); pango_data_free (pango_data); g_free (hash_widgets); break; default: break; } } static void select_file_cb (GtkEntry *entry, GtkEntryIconPosition icon_pos __attribute__((unused)), GdkEvent *event __attribute__((unused)), gpointer user_data) { ThreadData *thread_data = g_new0 (ThreadData, 1); HashWidgets *hash_widgets = user_data; thread_data->widgets_data = hash_widgets; GSList *list = choose_file (hash_widgets->main_window, "Pick file to compare", FALSE); gchar *filename = get_filename_from_list (list); if (filename == NULL) { g_free (thread_data); return; } gint hash_algo = -1, digest_size = -1; for (gint i = 0; i < 6; i++) { if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (hash_widgets->radio_button[i]))) { if (g_strcmp0 (gtk_widget_get_name (hash_widgets->radio_button[i]), "md5_radio_btn") == 0) { hash_algo = GCRY_MD_MD5; digest_size = MD5_DIGEST_SIZE; } else if (g_strcmp0 (gtk_widget_get_name (hash_widgets->radio_button[i]), "sha1_radio_btn") == 0) { hash_algo = GCRY_MD_SHA1; digest_size = SHA1_DIGEST_SIZE; } else if (g_strcmp0 (gtk_widget_get_name (hash_widgets->radio_button[i]), "sha256_radio_btn") == 0) { hash_algo = GCRY_MD_SHA256; digest_size = SHA256_DIGEST_SIZE; } else if (g_strcmp0 (gtk_widget_get_name (hash_widgets->radio_button[i]), "sha512_radio_btn") == 0) { hash_algo = GCRY_MD_SHA512; digest_size = SHA512_DIGEST_SIZE; } else if (g_strcmp0 (gtk_widget_get_name (hash_widgets->radio_button[i]), "sha3_256_radio_btn") == 0) { hash_algo = GCRY_MD_SHA3_256; digest_size = SHA3_256_DIGEST_SIZE; } else if (g_strcmp0 (gtk_widget_get_name (hash_widgets->radio_button[i]), "sha3_512_radio_btn") == 0) { hash_algo = GCRY_MD_SHA3_512; digest_size = SHA3_512_DIGEST_SIZE; } } } thread_data->entry = entry; thread_data->digest_size = digest_size; thread_data->hash_algo = hash_algo; thread_data->filename = filename; if (g_strcmp0 (gtk_widget_get_name (GTK_WIDGET (entry)), "file1_he_name") == 0) { start_spinner (hash_widgets->spinner_entry1); } else { start_spinner (hash_widgets->spinner_entry2); } g_thread_new (NULL, exec_thread, thread_data); } #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wreturn-type" static gpointer exec_thread (gpointer user_data) { ThreadData *data = user_data; if (gtk_widget_get_sensitive (data->widgets_data->cancel_btn)) { gtk_widget_set_sensitive (data->widgets_data->cancel_btn, FALSE); } gchar *hash = get_file_hash (data->filename, data->hash_algo, data->digest_size); if (hash == NULL) { show_message_dialog (data->widgets_data->main_window, "Error during hash computation", GTK_MESSAGE_ERROR); g_free (data->filename); g_free (data); g_thread_exit (NULL); } if (g_strcmp0 (gtk_widget_get_name (GTK_WIDGET (data->entry)), "file1_he_name") == 0) { //-V774 gtk_entry_set_text (GTK_ENTRY (data->widgets_data->file1_hash_entry), hash); //-V774 stop_spinner (data->widgets_data->spinner_entry1); //-V774 } else { gtk_entry_set_text (GTK_ENTRY (data->widgets_data->file2_hash_entry), hash); //-V774 stop_spinner (data->widgets_data->spinner_entry2); //-V774 } if (!gtk_widget_get_sensitive (data->widgets_data->cancel_btn)) { //-V774 /* if cancel_btn is non-sensitive AND both the gtk_entry have have text inside them, THEN cancel_btn becomes + sensitive again. */ if ((data->widgets_data->entry1_changed) && (data->widgets_data->entry2_changed)) { //-V774 gtk_widget_set_sensitive (data->widgets_data->cancel_btn, TRUE); //-V774 } } g_free (data->filename); //-V774 g_free (hash); g_free (data); //-V586 g_thread_exit ((gpointer) 0); } //-V591 #pragma GCC diagnostic pop static void do_header_bar (GtkWidget *dialog, HashWidgets *widgets) { GtkWidget *header_bar = create_header_bar (dialog, "Compare Hash"); GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_style_context_add_class (gtk_widget_get_style_context (box), "linked"); GIcon *icon = g_themed_icon_new ("emblem-system-symbolic"); GtkWidget *image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_BUTTON); g_object_unref (icon); widgets->header_bar_menu = gtk_toggle_button_new (); gtk_container_add (GTK_CONTAINER (widgets->header_bar_menu), image); gtk_widget_set_tooltip_text (GTK_WIDGET (widgets->header_bar_menu), "Settings"); GtkWidget *popover = create_popover (widgets->header_bar_menu, GTK_POS_TOP, widgets); gtk_popover_set_modal (GTK_POPOVER (popover), TRUE); g_signal_connect (widgets->header_bar_menu, "toggled", G_CALLBACK (toggle_changed_cb), popover); gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (widgets->header_bar_menu)); } static GtkWidget * create_popover (GtkWidget *parent, GtkPositionType pos, HashWidgets *widgets) { const gchar *algo[] = {"MD5", "SHA1", "SHA2-256", "SHA2-512", "SHA3-256", "SHA3-512"}; GtkWidget *box[4]; box[0] = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4); box[1] = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4); box[2] = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4); box[3] = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); gtk_box_set_homogeneous (GTK_BOX (box[3]), FALSE); GtkWidget *popover = gtk_popover_new (parent); gtk_popover_set_position (GTK_POPOVER (popover), pos); widgets->radio_button[0] = gtk_radio_button_new_with_label_from_widget (NULL, algo[0]); for (gint i = 1, j = 1; i < 6; i++, j++) { widgets->radio_button[i] = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON (widgets->radio_button[0]), algo[j]); } gtk_widget_set_name (widgets->radio_button[0], "md5_radio_btn"); gtk_widget_set_name (widgets->radio_button[1], "sha1_radio_btn"); gtk_widget_set_name (widgets->radio_button[2], "sha256_radio_btn"); gtk_widget_set_name (widgets->radio_button[3], "sha512_radio_btn"); gtk_widget_set_name (widgets->radio_button[4], "sha3_256_radio_btn"); gtk_widget_set_name (widgets->radio_button[5], "sha3_512_radio_btn"); for (gint i = 0; i < 2; i++) gtk_box_pack_start (GTK_BOX (box[0]), widgets->radio_button[i], TRUE, TRUE, 0); for (gint i = 2; i < 4; i++) gtk_box_pack_start (GTK_BOX (box[1]), widgets->radio_button[i], FALSE, TRUE, 0); for (gint i = 4; i < 6; i++) gtk_box_pack_start (GTK_BOX (box[2]), widgets->radio_button[i], FALSE, TRUE, 0); GtkWidget *vline1 = gtk_separator_new (GTK_ORIENTATION_VERTICAL); GtkWidget *vline2 = gtk_separator_new (GTK_ORIENTATION_VERTICAL); gtk_box_pack_start (GTK_BOX (box[3]), box[0], FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box[3]), vline1, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box[3]), box[1], FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box[3]), vline2, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box[3]), box[2], FALSE, FALSE, 0); for (gint i = 0; i < 6; i++) { g_signal_connect_swapped (widgets->radio_button[i], "clicked", G_CALLBACK(toggle_active_cb), widgets->header_bar_menu); } g_object_set (widgets->radio_button[0], "active", TRUE, NULL); gtk_container_add (GTK_CONTAINER (popover), box[3]); gtk_container_set_border_width (GTK_CONTAINER (popover), 4); gtk_widget_show_all (box[3]); return popover; } static void entry_changed_cb (GtkWidget *btn, gpointer user_data) { HashWidgets *data = user_data; if (g_strcmp0 (gtk_widget_get_name (btn), "file1_he_name") == 0) { data->entry1_changed = TRUE; } else { data->entry2_changed = TRUE; } if (data->entry1_changed == TRUE && data->entry2_changed == TRUE) { const gchar *hash1 = gtk_entry_get_text (GTK_ENTRY (data->file1_hash_entry)); const gchar *hash2 = gtk_entry_get_text (GTK_ENTRY (data->file2_hash_entry)); if (g_strcmp0 (hash1, hash2) != 0) { set_css (HASH_ERR_CSS, data->file1_hash_entry); set_css (HASH_ERR_CSS, data->file2_hash_entry); } else { set_css (HASH_OK_CSS, data->file1_hash_entry); set_css (HASH_OK_CSS, data->file2_hash_entry); } } }GTKCrypto-1.0.2/src/compute-hash-cb.c000066400000000000000000000221131421212406300172440ustar00rootroot00000000000000#include #include #include "gtkcrypto.h" #include "common-callbacks.h" #include "common-widgets.h" #include "hash.h" #include "misc-style.h" typedef struct compute_hash_widgets_t { GtkWidget *main_window; GtkWidget *cancel_btn; GtkWidget *check_button[AVAILABLE_HASH_TYPE]; GtkWidget *hash_entry[AVAILABLE_HASH_TYPE]; GtkWidget *spinner[AVAILABLE_HASH_TYPE]; gchar *filename; GThreadPool *thread_pool; GHashTable *hash_table; } ComputeHashData; typedef struct compute_hash_thread_data_t { GtkWidget *ck_btn; gint hash_algo; gint digest_size; ComputeHashData *widgets; } ThreadData; static void prepare_hash_computation_cb (GtkWidget *ck_btn, gpointer user_data); static void exec_thread (gpointer pushed_data, gpointer user_data); static gboolean is_last_thread (GThreadPool *tp); static GtkWidget *get_entry_from_check_btn (GtkWidget *ck_btn, ComputeHashData *data); void compute_hash_cb (GtkWidget *button __attribute((unused)), gpointer user_data) { const gchar *ck_btn_labels[] = {"MD5", "SHA-1", "GOST94", "SHA-256", "SHA3-256", "SHA-384", "SHA3-384", "SHA-512", "SHA3-512", "WHIRLPOOL"}; ComputeHashData *hash_widgets = g_new0 (ComputeHashData, 1); hash_widgets->main_window = (GtkWidget *) user_data; GSList *list = choose_file (hash_widgets->main_window, "Choose file", FALSE); hash_widgets->filename = get_filename_from_list (list); if (hash_widgets->filename == NULL) { g_free (hash_widgets); return; } GtkWidget *dialog = create_dialog (hash_widgets->main_window, "dialog_hash", "Compute Hash"); hash_widgets->cancel_btn = gtk_dialog_add_button (GTK_DIALOG (dialog), "Cancel", GTK_RESPONSE_CANCEL); gtk_widget_set_margin_top (hash_widgets->cancel_btn, 10); gtk_widget_set_size_request (dialog, 800, -1); PangoData *pango_data = get_pango_monospace_attr (); for (gint i = 0; i < AVAILABLE_HASH_TYPE; i++) { hash_widgets->check_button[i] = gtk_check_button_new_with_label (ck_btn_labels[i]); gtk_widget_set_name (hash_widgets->check_button[i], ck_btn_labels[i]); hash_widgets->spinner[i] = create_spinner (); gtk_widget_set_name (hash_widgets->spinner[i], ck_btn_labels[i]); hash_widgets->hash_entry[i] = gtk_entry_new (); gtk_widget_set_name (hash_widgets->hash_entry[i], ck_btn_labels[i]); gtk_editable_set_editable (GTK_EDITABLE (hash_widgets->hash_entry[i]), FALSE); gtk_widget_set_hexpand (hash_widgets->hash_entry[i], TRUE); gtk_entry_set_attributes (GTK_ENTRY (hash_widgets->hash_entry[i]), pango_data->attrs); gtk_entry_set_icon_from_icon_name (GTK_ENTRY (hash_widgets->hash_entry[i]), GTK_ENTRY_ICON_SECONDARY, "edit-copy-symbolic"); gtk_entry_set_icon_tooltip_text (GTK_ENTRY (hash_widgets->hash_entry[i]), GTK_ENTRY_ICON_SECONDARY, "Copy to clipboard"); g_signal_connect (hash_widgets->hash_entry[i], "icon-press", G_CALLBACK (copy_to_clipboard_cb), NULL); g_signal_connect (hash_widgets->check_button[i], "toggled", G_CALLBACK (prepare_hash_computation_cb), hash_widgets); } GtkWidget *content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); GtkWidget *grid = gtk_grid_new (); gtk_container_add (GTK_CONTAINER (content_area), grid); gtk_grid_set_row_spacing (GTK_GRID (grid), 10); gtk_grid_set_column_spacing (GTK_GRID (grid), 5); for (gint i = 0, j = 0; i < AVAILABLE_HASH_TYPE; i++, j++) { gtk_grid_attach (GTK_GRID (grid), hash_widgets->check_button[i], 0, j, 1, 1); gtk_grid_attach_next_to (GTK_GRID (grid), hash_widgets->hash_entry[i], hash_widgets->check_button[i], GTK_POS_RIGHT, 4, 1); gtk_grid_attach_next_to (GTK_GRID (grid), hash_widgets->spinner[i], hash_widgets->hash_entry[i], GTK_POS_RIGHT, 1, 1); } hash_widgets->thread_pool = g_thread_pool_new (exec_thread, NULL, (gint)g_get_num_processors (), FALSE, NULL); hash_widgets->hash_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); gtk_widget_show_all (dialog); gint result = gtk_dialog_run (GTK_DIALOG (dialog)); switch (result) { case GTK_RESPONSE_CANCEL: gtk_widget_destroy (dialog); pango_data_free (pango_data); g_thread_pool_free (hash_widgets->thread_pool, FALSE, FALSE); g_hash_table_remove_all (hash_widgets->hash_table); g_hash_table_unref (hash_widgets->hash_table); g_free (hash_widgets->filename); g_free (hash_widgets); break; default: break; } } static void prepare_hash_computation_cb (GtkWidget *ck_btn, gpointer user_data) { ComputeHashData *data = user_data; if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ck_btn))) { gtk_entry_set_text (GTK_ENTRY (get_entry_from_check_btn (ck_btn, data)), ""); return; } gpointer value = g_hash_table_lookup (data->hash_table, gtk_widget_get_name (ck_btn)); if (value != NULL) { gtk_entry_set_text (GTK_ENTRY (get_entry_from_check_btn (ck_btn, data)), (gchar *) value); return; } ThreadData *thread_data = g_new0 (ThreadData, 1); gint hash_algo = -1, digest_size = -1; if (g_strcmp0 (gtk_widget_get_name (ck_btn), "MD5") == 0) { hash_algo = GCRY_MD_MD5; digest_size = MD5_DIGEST_SIZE; } else if (g_strcmp0 (gtk_widget_get_name (ck_btn), "SHA-1") == 0) { hash_algo = GCRY_MD_SHA1; digest_size = SHA1_DIGEST_SIZE; } else if (g_strcmp0 (gtk_widget_get_name (ck_btn), "GOST94") == 0) { hash_algo = GCRY_MD_GOSTR3411_94; digest_size = GOST94_DIGEST_SIZE; } else if (g_strcmp0 (gtk_widget_get_name (ck_btn), "SHA-256") == 0) { hash_algo = GCRY_MD_SHA256; digest_size = SHA256_DIGEST_SIZE; } else if (g_strcmp0 (gtk_widget_get_name (ck_btn), "SHA3-256") == 0) { hash_algo = GCRY_MD_SHA3_256; digest_size = SHA3_256_DIGEST_SIZE; } else if (g_strcmp0 (gtk_widget_get_name (ck_btn), "SHA-384") == 0) { hash_algo = GCRY_MD_SHA384; digest_size = SHA384_DIGEST_SIZE; } else if (g_strcmp0 (gtk_widget_get_name (ck_btn), "SHA3-384") == 0) { hash_algo = GCRY_MD_SHA3_384; digest_size = SHA3_384_DIGEST_SIZE; } else if (g_strcmp0 (gtk_widget_get_name (ck_btn), "SHA-512") == 0) { hash_algo = GCRY_MD_SHA512; digest_size = SHA512_DIGEST_SIZE; } else if (g_strcmp0 (gtk_widget_get_name (ck_btn), "SHA3-512") == 0) { hash_algo = GCRY_MD_SHA3_512; digest_size = SHA3_512_DIGEST_SIZE; } else if (g_strcmp0 (gtk_widget_get_name (ck_btn), "WHIRLPOOL") == 0) { hash_algo = GCRY_MD_WHIRLPOOL; digest_size = WHIRLPOOL_DIGEST_SIZE; } for (gint i = 0; i < AVAILABLE_HASH_TYPE; i++) { if (g_strcmp0 (gtk_widget_get_name (ck_btn), gtk_widget_get_name (data->spinner[i])) == 0) { start_spinner (data->spinner[i]); break; } } thread_data->ck_btn = ck_btn; thread_data->digest_size = digest_size; thread_data->hash_algo = hash_algo; thread_data->widgets = data; g_thread_pool_push (data->thread_pool, thread_data, NULL); } static void exec_thread (gpointer pushed_data, gpointer user_data __attribute__((unused))) { ThreadData *data = pushed_data; if (gtk_widget_get_sensitive (data->widgets->cancel_btn)) { gtk_widget_set_sensitive (data->widgets->cancel_btn, FALSE); } gchar *hash = get_file_hash (data->widgets->filename, data->hash_algo, data->digest_size); if (hash == NULL) { show_message_dialog (data->widgets->main_window, "Error during hash computation", GTK_MESSAGE_ERROR); } else { for (gint i = 0; i < AVAILABLE_HASH_TYPE; i++) { if (g_strcmp0 (gtk_widget_get_name (data->ck_btn), gtk_widget_get_name (data->widgets->hash_entry[i])) == 0) { gtk_entry_set_text (GTK_ENTRY (data->widgets->hash_entry[i]), hash); g_hash_table_insert (data->widgets->hash_table, g_strdup ((gchar *) gtk_widget_get_name (data->ck_btn)), g_strdup (hash)); stop_spinner (data->widgets->spinner[i]); break; } } } if (!gtk_widget_get_sensitive (data->widgets->cancel_btn) && is_last_thread (data->widgets->thread_pool)) { gtk_widget_set_sensitive (data->widgets->cancel_btn, TRUE); } g_free (hash); g_free (data); } //-V591 static gboolean is_last_thread (GThreadPool *tp) { if (g_thread_pool_get_num_threads (tp) == 1) { return TRUE; } else { return FALSE; } } static GtkWidget * get_entry_from_check_btn (GtkWidget *ck_btn, ComputeHashData *data) { for (gint i = 0; i < AVAILABLE_HASH_TYPE; i++) { if (g_strcmp0 (gtk_widget_get_name (ck_btn), gtk_widget_get_name (data->hash_entry[i])) == 0) { return data->hash_entry[i]; } } return NULL; } GTKCrypto-1.0.2/src/crypt-common.c000066400000000000000000000020101421212406300167060ustar00rootroot00000000000000#include #include #include "crypt-common.h" gboolean setup_keys (const gchar *pwd, gsize algo_key_len, Metadata *header_metadata, CryptoKeys *keys) { keys->derived_key = gcry_malloc_secure (algo_key_len + HMAC_KEY_SIZE); if (keys->derived_key == NULL) { return FALSE; } if (gcry_kdf_derive (pwd, (gsize) g_utf8_strlen (pwd, -1) + 1, GCRY_KDF_PBKDF2, GCRY_MD_SHA512, header_metadata->salt, KDF_SALT_SIZE, KDF_ITERATIONS, algo_key_len + HMAC_KEY_SIZE, keys->derived_key) != 0) { return FALSE; } keys->crypto_key = gcry_malloc_secure (algo_key_len); if (keys->crypto_key == NULL) { return FALSE; } memcpy (keys->crypto_key, keys->derived_key, algo_key_len); keys->hmac_key = gcry_malloc_secure (HMAC_KEY_SIZE); if (keys->hmac_key == NULL) { return FALSE; } memcpy (keys->hmac_key, keys->derived_key + algo_key_len, HMAC_KEY_SIZE); return TRUE; } GTKCrypto-1.0.2/src/crypt-common.h000066400000000000000000000012031421212406300167160ustar00rootroot00000000000000#pragma once // The encryption/decryption key is derived using PBKDF2 with SHA512 while the HMAC function uses `SHA_3_512`. #define MAX_IV_SIZE 16 #define HMAC_KEY_SIZE 64 #define KDF_ITERATIONS 100000 #define KDF_SALT_SIZE 32 typedef struct header_metadata_t { guint8 iv[MAX_IV_SIZE]; gsize iv_size; guint8 salt[KDF_SALT_SIZE]; gint algo; gint algo_mode; guint8 padding_value; } Metadata; typedef struct key_t { guchar *derived_key; guchar *crypto_key; guchar *hmac_key; } CryptoKeys; gboolean setup_keys (const gchar *pwd, gsize algo_key_len, Metadata *header_metadata, CryptoKeys *encryption_keys); GTKCrypto-1.0.2/src/decrypt-file.c000066400000000000000000000255361421212406300166700ustar00rootroot00000000000000#include #include #include #include "gtkcrypto.h" #include "hash.h" #include "crypt-common.h" #include "cleanup.h" static GFile *get_g_file_with_encrypted_data (GFileInputStream *in_stream, goffset file_size); static gboolean compare_hmac (guchar *hmac_key, guchar *original_hmac, GFile *encrypted_data); gpointer decrypt (Metadata *header_metadata, CryptoKeys *dec_keys, GFile *enc_data, goffset enc_data_size, GFileOutputStream *ostream); gpointer decrypt_file (const gchar *input_file_path, const gchar *pwd) { GError *err = NULL; gchar *err_msg = NULL; goffset file_size = get_file_size (input_file_path); if (file_size == -1) { return g_strdup ("Couldn't get the file size."); } if (file_size < (goffset) (sizeof (Metadata) + SHA512_DIGEST_SIZE)) { return g_strdup ("The selected file is not encrypted."); } GFile *in_file = g_file_new_for_path (input_file_path); GFileInputStream *in_stream = g_file_read (in_file, NULL, &err); if (err != NULL) { err_msg = g_strdup (err->message); g_clear_error (&err); g_object_unref (in_file); g_input_stream_close (G_INPUT_STREAM (in_stream), NULL, NULL); g_object_unref (in_stream); return err_msg; } gchar *output_file_path; if (!g_str_has_suffix (input_file_path, ".enc")) { g_printerr ("The selected file may not be encrypted\n"); output_file_path = g_strconcat (input_file_path, ".decrypted", NULL); } else { output_file_path = g_strndup (input_file_path, (gsize) g_utf8_strlen (input_file_path, -1) - 4); // remove .enc } GFile *out_file = g_file_new_for_path (output_file_path); GFileOutputStream *out_stream = g_file_append_to (out_file, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &err); if (err != NULL) { err_msg = g_strdup (err->message); g_clear_error (&err); gfile_cleanup (in_file, out_file); gstream_cleanup (in_stream, out_stream); g_free (output_file_path); return err_msg; } Metadata *header_metadata = g_new0 (Metadata, 1); CryptoKeys *decryption_keys = g_new0 (CryptoKeys, 1); gssize rw_len = g_input_stream_read (G_INPUT_STREAM (in_stream), header_metadata, sizeof (Metadata), NULL, &err); if (rw_len == -1) { err_msg = g_strdup (err->message); g_clear_error (&err); crypto_keys_cleanup (decryption_keys); gfile_cleanup (in_file, out_file); gstream_cleanup (in_stream, out_stream); data_cleanup (header_metadata, output_file_path, NULL); return err_msg; } guchar *original_hmac = g_malloc0 (SHA512_DIGEST_SIZE); if (!g_seekable_seek (G_SEEKABLE (in_stream), file_size - SHA512_DIGEST_SIZE, G_SEEK_SET, NULL, &err)) { err_msg = g_strdup (err->message); g_clear_error (&err); crypto_keys_cleanup (decryption_keys); gfile_cleanup (in_file, out_file); gstream_cleanup (in_stream, out_stream); data_cleanup (header_metadata, output_file_path, original_hmac); return err_msg; } rw_len = g_input_stream_read (G_INPUT_STREAM (in_stream), original_hmac, SHA512_DIGEST_SIZE, NULL, &err); if (rw_len == -1) { err_msg = g_strdup (err->message); g_clear_error (&err); crypto_keys_cleanup (decryption_keys); gfile_cleanup (in_file, out_file); gstream_cleanup (in_stream, out_stream); data_cleanup (header_metadata, output_file_path, original_hmac); return err_msg; } if (!g_seekable_seek (G_SEEKABLE (in_stream), 0, G_SEEK_SET, NULL, &err)) { err_msg = g_strdup (err->message); g_clear_error (&err); crypto_keys_cleanup (decryption_keys); gfile_cleanup (in_file, out_file); gstream_cleanup (in_stream, out_stream); data_cleanup (header_metadata, output_file_path, original_hmac); return err_msg; } GFile *file_encrypted_data = get_g_file_with_encrypted_data (in_stream, file_size); if (file_encrypted_data == NULL) { crypto_keys_cleanup (decryption_keys); gfile_cleanup (in_file, out_file); gstream_cleanup (in_stream, out_stream); data_cleanup (header_metadata, output_file_path, original_hmac); return g_strdup ("Couldn't get the encrypted data from the file."); } if (!setup_keys (pwd, gcry_cipher_get_algo_keylen (header_metadata->algo), header_metadata, decryption_keys)) { g_object_unref (file_encrypted_data); crypto_keys_cleanup (decryption_keys); gfile_cleanup (in_file, out_file); gstream_cleanup (in_stream, out_stream); data_cleanup (header_metadata, output_file_path, original_hmac); return g_strdup ("Error during key derivation or during memory allocation."); } if (!compare_hmac (decryption_keys->hmac_key, original_hmac, file_encrypted_data)) { g_object_unref (file_encrypted_data); crypto_keys_cleanup (decryption_keys); gfile_cleanup (in_file, out_file); gstream_cleanup (in_stream, out_stream); data_cleanup (header_metadata, output_file_path, original_hmac); return g_strdup ("HMAC differs from the one stored inside the file.\nEither the password is wrong or the file has been corrupted."); } gchar *msg = decrypt (header_metadata, decryption_keys, file_encrypted_data, file_size - sizeof (Metadata) - SHA512_DIGEST_SIZE, out_stream); if (msg != NULL) { return msg; } g_unlink (g_file_get_path (file_encrypted_data)); g_object_unref (file_encrypted_data); crypto_keys_cleanup (decryption_keys); gfile_cleanup (in_file, out_file); gstream_cleanup (in_stream, out_stream); data_cleanup (header_metadata, output_file_path, original_hmac); return NULL; } static GFile * get_g_file_with_encrypted_data (GFileInputStream *in_stream, goffset file_size) { GError *err = NULL; GFileIOStream *ostream; gssize read_len; guchar *buf; goffset len_file_data = file_size - SHA512_DIGEST_SIZE; gsize done_size = 0; GFile *tmp_encrypted_file = g_file_new_tmp (NULL, &ostream, &err); if (tmp_encrypted_file == NULL) { g_printerr ("%s\n", err->message); return NULL; } GFileOutputStream *out_enc_stream = g_file_append_to (tmp_encrypted_file, G_FILE_CREATE_NONE, NULL, &err); if (out_enc_stream == NULL) { g_printerr ("%s\n", err->message); return NULL; } if (len_file_data < FILE_BUFFER) { buf = g_malloc0 ((gsize)len_file_data); g_input_stream_read (G_INPUT_STREAM (in_stream), buf, (gsize)len_file_data, NULL, &err); g_output_stream_write (G_OUTPUT_STREAM (out_enc_stream), buf, (gsize)len_file_data, NULL, &err); } else { buf = g_malloc (FILE_BUFFER); while (done_size < len_file_data) { if ((len_file_data - done_size) > FILE_BUFFER) { read_len = g_input_stream_read (G_INPUT_STREAM (in_stream), buf, FILE_BUFFER, NULL, &err); } else { read_len = g_input_stream_read (G_INPUT_STREAM (in_stream), buf, len_file_data - done_size, NULL, &err); } if (read_len == -1) { g_printerr ("%s\n", err->message); return NULL; } g_output_stream_write (G_OUTPUT_STREAM (out_enc_stream), buf, (gsize)read_len, NULL, &err); done_size += read_len; memset (buf, 0, FILE_BUFFER); } } gstream_cleanup (NULL, out_enc_stream); g_free (buf); return tmp_encrypted_file; } static gboolean compare_hmac (guchar *hmac_key, guchar *original_hmac, GFile *encrypted_data) { gchar *path = g_file_get_path (encrypted_data); if (calculate_hmac (path, hmac_key, original_hmac) == HMAC_MISMATCH) { return FALSE; } else { return TRUE; } } gpointer decrypt (Metadata *header_metadata, CryptoKeys *dec_keys, GFile *enc_data, goffset enc_data_size, GFileOutputStream *ostream) { gcry_cipher_hd_t hd; gcry_cipher_open (&hd, header_metadata->algo, header_metadata->algo_mode, 0); gcry_cipher_setkey (hd, dec_keys->crypto_key, gcry_cipher_get_algo_keylen (header_metadata->algo)); if (header_metadata->algo_mode == GCRY_CIPHER_MODE_CBC) { gcry_cipher_setiv (hd, header_metadata->iv, header_metadata->iv_size); } else { gcry_cipher_setctr (hd, header_metadata->iv, header_metadata->iv_size); } GError *err = NULL; gchar *err_msg = NULL; GFileInputStream *in_stream = g_file_read (enc_data, NULL, &err); if (err != NULL) { err_msg = g_strdup (err->message); g_clear_error (&err); return err_msg; } if (!g_seekable_seek (G_SEEKABLE (in_stream), sizeof (Metadata), G_SEEK_SET, NULL, &err)) { err_msg = g_strdup (err->message); g_clear_error (&err); return err_msg; } guchar *enc_buf = g_try_malloc0 (FILE_BUFFER); guchar *dec_buf = g_try_malloc0 (FILE_BUFFER); if (enc_buf == NULL || dec_buf == NULL) { if (enc_buf != NULL) g_free (enc_buf); if (dec_buf != NULL) g_free (dec_buf); return g_strdup ("Error during memory allocation."); } goffset done_size = 0; gssize read_len; while (done_size < enc_data_size) { if ((enc_data_size - done_size) <= FILE_BUFFER) { read_len = g_input_stream_read (G_INPUT_STREAM (in_stream), enc_buf, (gsize)enc_data_size - done_size, NULL, &err); gcry_cipher_decrypt (hd, dec_buf, (gsize)read_len, enc_buf, (gsize)read_len); g_output_stream_write (G_OUTPUT_STREAM (ostream), dec_buf, (gsize)read_len - header_metadata->padding_value, NULL, &err); } else { read_len = g_input_stream_read (G_INPUT_STREAM (in_stream), enc_buf, FILE_BUFFER, NULL, &err); gcry_cipher_decrypt (hd, dec_buf, (gsize)read_len, enc_buf, (gsize)read_len); g_output_stream_write (G_OUTPUT_STREAM (ostream), dec_buf, (gsize)read_len, NULL, &err); } memset (dec_buf, 0, FILE_BUFFER); memset (enc_buf, 0, FILE_BUFFER); done_size += read_len; } gcry_cipher_close (hd); g_free (enc_buf); g_free (dec_buf); g_input_stream_close (G_INPUT_STREAM (in_stream), NULL, NULL); g_object_unref (in_stream); return NULL; }GTKCrypto-1.0.2/src/decrypt-files-cb.c000066400000000000000000000127601421212406300174300ustar00rootroot00000000000000#include #include #include "gtkcrypto.h" #include "decrypt-files-cb.h" static gboolean check_tp (gpointer data); static void prepare_multi_decryption_cb (GtkWidget *widget, DecryptWidgets *data); static void exec_thread (gpointer data, gpointer user_data); static void cancel_clicked_cb (GtkWidget *btn, gpointer user_data); void decrypt_files_cb (GtkWidget *btn __attribute__((unused)), gpointer user_data) { GtkBuilder *builder = get_builder_from_path (PARTIAL_PATH_TO_UI_FILE); if (builder == NULL) { return; } DecryptWidgets *decrypt_widgets = g_new0 (DecryptWidgets, 1); decrypt_widgets->main_window = (GtkWidget *)user_data; decrypt_widgets->running_threads = 0; decrypt_widgets->files_not_decrypted = 0; decrypt_widgets->first_run = TRUE; decrypt_widgets->files_list = choose_file (decrypt_widgets->main_window, "Choose file(s) to decrypt", TRUE); if (decrypt_widgets->files_list == NULL) { g_free (decrypt_widgets); return; } decrypt_widgets->dialog = GTK_WIDGET (gtk_builder_get_object (builder, "dec_pwd_diag")); decrypt_widgets->ok_btn = GTK_WIDGET (gtk_builder_get_object (builder, "ok_btn_dec_pwd_diag")); decrypt_widgets->cancel_btn = GTK_WIDGET (gtk_builder_get_object (builder, "cancel_btn_dec_pwd_diag")); decrypt_widgets->entry_pwd = GTK_WIDGET (gtk_builder_get_object (builder, "dec_pwd_entry")); decrypt_widgets->message_label = GTK_WIDGET (gtk_builder_get_object (builder, "dec_label")); decrypt_widgets->spinner = GTK_WIDGET (gtk_builder_get_object (builder, "dec_spinner")); decrypt_widgets->ck_btn_delete = GTK_WIDGET (gtk_builder_get_object (builder, "check_btn_delfile")); g_object_unref (builder); gtk_widget_show_all (decrypt_widgets->dialog); gtk_widget_hide (decrypt_widgets->spinner); g_signal_connect (decrypt_widgets->entry_pwd, "activate", G_CALLBACK (prepare_multi_decryption_cb), decrypt_widgets); g_signal_connect (decrypt_widgets->ok_btn, "clicked", G_CALLBACK (prepare_multi_decryption_cb), decrypt_widgets); g_signal_connect (decrypt_widgets->cancel_btn, "clicked", G_CALLBACK (cancel_clicked_cb), decrypt_widgets); decrypt_widgets->source_id = g_timeout_add (500, check_tp, decrypt_widgets); gtk_dialog_run (GTK_DIALOG (decrypt_widgets->dialog)); } static gboolean check_tp (gpointer data) { DecryptWidgets *widgets = (DecryptWidgets *)data; if (widgets->running_threads == 0 && widgets->first_run == FALSE) { g_thread_pool_free (widgets->thread_pool, FALSE, TRUE); guint list_len = g_slist_length (widgets->files_list); // TODO show failed files gchar *msg = g_strdup_printf ("%u/%u file(s) successfully decrypted.", list_len - widgets->files_not_decrypted, list_len); show_message_dialog (widgets->main_window, msg, GTK_MESSAGE_INFO); g_free (msg); cancel_clicked_cb (NULL, widgets); return FALSE; } else { return TRUE; } } void prepare_multi_decryption_cb (GtkWidget *widget __attribute__((unused)), DecryptWidgets *data) { ThreadData *thread_data = g_new0 (ThreadData, 1); thread_data->dialog = data->dialog; thread_data->spinner = data->spinner; thread_data->list_len = g_slist_length (data->files_list); thread_data->pwd = gtk_entry_get_text (GTK_ENTRY (data->entry_pwd)); thread_data->delete_file = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->ck_btn_delete)); thread_data->widgets = data; gtk_label_set_label (GTK_LABEL (data->message_label), "Decrypting file(s)..."); gtk_widget_show (thread_data->spinner); start_spinner (thread_data->spinner); change_widgets_sensitivity (4, FALSE, &data->ok_btn, &data->cancel_btn, &data->entry_pwd, &data->ck_btn_delete); g_mutex_init (&thread_data->mutex); data->thread_pool = g_thread_pool_new (exec_thread, thread_data, (gint)g_get_num_processors (), TRUE, NULL); for (guint i = 0; i < thread_data->list_len; i++) { g_thread_pool_push (data->thread_pool, g_slist_nth_data (data->files_list, i), NULL); } gtk_dialog_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_DELETE_EVENT); } static void exec_thread (gpointer data, gpointer user_data) { const gchar *filename = (gchar *)data; ThreadData *thread_data = user_data; g_mutex_lock (&thread_data->mutex); thread_data->widgets->running_threads++; g_mutex_unlock (&thread_data->mutex); gpointer ret = decrypt_file (filename, thread_data->pwd); if (ret != NULL) { g_mutex_lock (&thread_data->mutex); thread_data->widgets->files_not_decrypted++; g_mutex_unlock (&thread_data->mutex); } if (thread_data->delete_file && ret == NULL) { g_unlink (filename); } g_mutex_lock (&thread_data->mutex); thread_data->widgets->running_threads--; thread_data->widgets->first_run = FALSE; g_mutex_unlock (&thread_data->mutex); } static void cancel_clicked_cb (GtkWidget *btn __attribute__((unused)), gpointer user_data) { DecryptWidgets *decrypt_widgets = user_data; g_source_remove (decrypt_widgets->source_id); gtk_widget_destroy (decrypt_widgets->dialog); g_slist_free_full (decrypt_widgets->files_list, g_free); g_free (decrypt_widgets); }GTKCrypto-1.0.2/src/decrypt-files-cb.h000066400000000000000000000013301421212406300174240ustar00rootroot00000000000000#pragma once typedef struct decrypt_file_widgets_t { GtkWidget *main_window; GtkWidget *dialog; GtkWidget *entry_pwd; GtkWidget *ck_btn_delete; GtkWidget *cancel_btn; GtkWidget *ok_btn; GtkWidget *spinner; GtkWidget *message_label; GSList *files_list; GThreadPool *thread_pool; guint running_threads; guint files_not_decrypted; guint source_id; gboolean first_run; } DecryptWidgets; typedef struct dec_thread_data_t { DecryptWidgets *widgets; GtkWidget *dialog; GtkWidget *spinner; const gchar *pwd; GMutex mutex; guint list_len; gboolean delete_file; } ThreadData; gpointer decrypt_file (const gchar *input_file_path, const gchar *pwd); GTKCrypto-1.0.2/src/encrypt-file.c000066400000000000000000000274141421212406300166770ustar00rootroot00000000000000#include #include #include "gtkcrypto.h" #include "hash.h" #include "crypt-common.h" #include "cleanup.h" static void set_algo_and_mode (Metadata *header_metadata, const gchar *algo, const gchar *algo_mode); static void set_number_of_blocks_and_padding_bytes (goffset file_size, gsize block_length, gint64 *num_of_blocks, gint *num_of_padding_bytes); static gchar *encrypt_using_cbc_mode (Metadata *header_metadata, gcry_cipher_hd_t *hd, goffset file_size, gint64 num_of_blocks, gint num_of_padding_bytes, gsize block_length, GFileInputStream *in_stream, GFileOutputStream *out_stream); static gchar *encrypt_using_ctr_mode (Metadata *header_metadata, gcry_cipher_hd_t *hd, goffset file_size, GFileInputStream *in_stream, GFileOutputStream *out_stream); gpointer encrypt_file (const gchar *input_file_path, const gchar *pwd, const gchar *algo, const gchar *algo_mode) { Metadata *header_metadata = g_new0 (Metadata, 1); CryptoKeys *encryption_keys = g_new0 (CryptoKeys, 1); set_algo_and_mode (header_metadata, algo, algo_mode); gsize algo_key_len = gcry_cipher_get_algo_keylen (header_metadata->algo); gsize algo_blk_len = gcry_cipher_get_algo_blklen (header_metadata->algo); header_metadata->iv_size = algo_blk_len; // iv must be the same size as the block size gcry_create_nonce (header_metadata->iv, header_metadata->iv_size); gcry_create_nonce (header_metadata->salt, KDF_SALT_SIZE); if (!setup_keys (pwd, algo_key_len, header_metadata, encryption_keys)) { g_free (encryption_keys); g_free (header_metadata); return g_strdup ("Couldn't setup the encryption keys, exiting..."); } goffset filesize = get_file_size (input_file_path); GError *err = NULL; gchar *err_msg = NULL; GFile *in_file = g_file_new_for_path (input_file_path); GFileInputStream *in_stream = g_file_read (in_file, NULL, &err); if (err != NULL) { crypto_keys_cleanup (encryption_keys); g_free (header_metadata); g_object_unref (in_file); err_msg = g_strdup (err->message); g_clear_error (&err); return err_msg; } gchar *output_file_path = g_strconcat (input_file_path, ".enc", NULL); GFile *out_file = g_file_new_for_path (output_file_path); GFileOutputStream *out_stream = g_file_append_to (out_file, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &err); if (err != NULL) { crypto_keys_cleanup (encryption_keys); gfile_cleanup (in_file, out_file); gstream_cleanup (in_stream, out_stream); data_cleanup (header_metadata, output_file_path, NULL); err_msg = g_strdup (err->message); g_clear_error (&err); return err_msg; } gcry_cipher_hd_t hd; gcry_cipher_open (&hd, header_metadata->algo, header_metadata->algo_mode, 0); gcry_cipher_setkey (hd, encryption_keys->crypto_key, algo_key_len); gint64 number_of_blocks; gint number_of_padding_bytes; gchar *ret_msg; if (header_metadata->algo_mode == GCRY_CIPHER_MODE_CBC) { set_number_of_blocks_and_padding_bytes (filesize, algo_blk_len, &number_of_blocks, &number_of_padding_bytes); gcry_cipher_setiv (hd, header_metadata->iv, header_metadata->iv_size); ret_msg = encrypt_using_cbc_mode (header_metadata, &hd, filesize, number_of_blocks, number_of_padding_bytes, algo_blk_len, in_stream, out_stream); } else { gcry_cipher_setctr (hd, header_metadata->iv, header_metadata->iv_size); ret_msg = encrypt_using_ctr_mode (header_metadata, &hd, filesize, in_stream, out_stream); } if (ret_msg != NULL) { crypto_keys_cleanup (encryption_keys); gfile_cleanup (in_file, out_file); gstream_cleanup (in_stream, out_stream); data_cleanup (header_metadata, output_file_path, NULL); return g_strdup (ret_msg); } gcry_cipher_close (hd); guchar *hmac = calculate_hmac (output_file_path, encryption_keys->hmac_key, NULL); gssize written_bytes = g_output_stream_write (G_OUTPUT_STREAM (out_stream), hmac, SHA512_DIGEST_SIZE, NULL, &err); if (written_bytes == -1) { crypto_keys_cleanup (encryption_keys); gfile_cleanup (in_file, out_file); gstream_cleanup (in_stream, out_stream); data_cleanup (header_metadata, output_file_path, hmac); err_msg = g_strdup (err->message); g_clear_error (&err); return err_msg; } crypto_keys_cleanup (encryption_keys); data_cleanup (header_metadata, output_file_path, hmac); gfile_cleanup (in_file, out_file); gstream_cleanup (in_stream, out_stream); return NULL; } static void set_algo_and_mode (Metadata *header_metadata, const gchar *algo, const gchar *algo_mode) { if (g_strcmp0 (algo, "aes_rbtn_widget") == 0) { header_metadata->algo = GCRY_CIPHER_AES256; } else if (g_strcmp0 (algo, "camellia_rbtn_widget") == 0) { header_metadata->algo = GCRY_CIPHER_CAMELLIA256; } else if (g_strcmp0 (algo, "serpent_rbtn_widget") == 0) { header_metadata->algo = GCRY_CIPHER_SERPENT256; } else { header_metadata->algo = GCRY_CIPHER_TWOFISH; } if (g_strcmp0 (algo_mode, "cbc_rbtn_widget") == 0) { header_metadata->algo_mode = GCRY_CIPHER_MODE_CBC; } else { header_metadata->algo_mode = GCRY_CIPHER_MODE_CTR; } } static void set_number_of_blocks_and_padding_bytes (goffset file_size, gsize block_length, gint64 *num_of_blocks, gint *num_of_padding_bytes) { gint64 file_blocks = file_size / block_length; gint spare_bytes = (gint) (file_size % block_length); // number of bytes left which didn't filled up a block if (spare_bytes > 0) { *num_of_blocks = file_blocks + 1; *num_of_padding_bytes = (gint) (block_length - spare_bytes); } else { *num_of_blocks = file_blocks; *num_of_padding_bytes = spare_bytes; } } static gchar * encrypt_using_cbc_mode (Metadata *header_metadata, gcry_cipher_hd_t *hd, goffset file_size, gint64 num_of_blocks, gint num_of_padding_bytes, gsize block_length, GFileInputStream *in_stream, GFileOutputStream *out_stream) { GError *err = NULL; gchar *err_msg = NULL; guchar padding[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; header_metadata->padding_value = padding[num_of_padding_bytes]; guchar *buffer = g_try_malloc0 ((gsize)(file_size < FILE_BUFFER ? (num_of_blocks * block_length) : FILE_BUFFER)); guchar *enc_buffer = g_try_malloc0 ((gsize)(file_size < FILE_BUFFER ? (num_of_blocks * block_length) : FILE_BUFFER)); if (buffer == NULL || enc_buffer == NULL) { if (buffer != NULL) g_free (buffer); if (enc_buffer != NULL) g_free (enc_buffer); return g_strdup ("Couldn't allocate memory"); } if (g_output_stream_write (G_OUTPUT_STREAM (out_stream), header_metadata, sizeof (Metadata), NULL, &err) == -1) { g_free (buffer); g_free (enc_buffer); err_msg = g_strdup (err->message); g_clear_error (&err); return err_msg; } gssize read_len; gint64 done_blocks = 0; while (done_blocks < num_of_blocks) { goffset remaining_bytes = ((num_of_blocks - done_blocks) * block_length); if (remaining_bytes > FILE_BUFFER) { read_len = g_input_stream_read (G_INPUT_STREAM (in_stream), buffer, FILE_BUFFER, NULL, &err); done_blocks += (read_len / block_length); } else { read_len = g_input_stream_read (G_INPUT_STREAM (in_stream), buffer, (gsize)remaining_bytes, NULL, &err); for (gsize j = (gsize)read_len, i = (block_length - num_of_padding_bytes); i < block_length; i++) { buffer[j] = header_metadata->padding_value; j++; } read_len += num_of_padding_bytes; done_blocks += (read_len / block_length); } if (read_len == -1) { g_free (buffer); g_free (enc_buffer); err_msg = g_strdup (err->message); g_clear_error (&err); return err_msg; } gcry_cipher_encrypt (*hd, enc_buffer, (gsize)read_len, buffer, (gsize)read_len); if (g_output_stream_write (G_OUTPUT_STREAM (out_stream), enc_buffer, (gsize)read_len, NULL, &err) != read_len) { g_free (buffer); g_free (enc_buffer); return g_strdup ("Error while trying to write encrypted data to the output file"); } memset (buffer, 0, (gsize)read_len); memset (enc_buffer, 0, (gsize)read_len); } g_free (buffer); g_free (enc_buffer); return NULL; } static gchar * encrypt_using_ctr_mode (Metadata *header_metadata, gcry_cipher_hd_t *hd, goffset file_size, GFileInputStream *in_stream, GFileOutputStream *out_stream) { GError *err = NULL; gchar *err_msg = NULL; if (g_output_stream_write (G_OUTPUT_STREAM (out_stream), header_metadata, sizeof (Metadata), NULL, &err) == -1) { err_msg = g_strdup (err->message); g_clear_error (&err); return err_msg; } guchar *buffer = g_try_malloc0 ((gsize)(file_size < FILE_BUFFER ? file_size : FILE_BUFFER)); guchar *enc_buffer = g_try_malloc0 ((gsize)(file_size < FILE_BUFFER ? file_size : FILE_BUFFER)); if (buffer == NULL || enc_buffer == NULL) { if (buffer != NULL) g_free (buffer); if (enc_buffer != NULL) g_free (enc_buffer); return g_strdup ("Couldn't allocate memory"); } goffset done_size = 0; gssize read_len; while (done_size < file_size) { if ((file_size - done_size) > FILE_BUFFER) { read_len = g_input_stream_read (G_INPUT_STREAM (in_stream), buffer, FILE_BUFFER, NULL, &err); } else { read_len = g_input_stream_read (G_INPUT_STREAM (in_stream), buffer, (gsize)file_size - done_size, NULL, &err); } if (read_len == -1) { g_free (buffer); g_free (enc_buffer); err_msg = g_strdup (err->message); g_clear_error (&err); return err_msg; } gcry_cipher_encrypt (*hd, enc_buffer, (gsize)read_len, buffer, (gsize)read_len); if (g_output_stream_write (G_OUTPUT_STREAM (out_stream), enc_buffer, (gsize)read_len, NULL, &err) == -1) { g_free (buffer); g_free (enc_buffer); err_msg = g_strdup (err->message); g_clear_error (&err); return err_msg; } memset (buffer, 0, (gsize)read_len); memset (enc_buffer, 0, (gsize)read_len); done_size += read_len; } g_free (buffer); g_free (enc_buffer); return NULL; } GTKCrypto-1.0.2/src/encrypt-files-cb.c000066400000000000000000000211751421212406300174420ustar00rootroot00000000000000#include #include "gtkcrypto.h" #include "encrypt-files-cb.h" #include "common-callbacks.h" static gboolean check_tp (gpointer data); static void entry_activated_cb (GtkWidget *entry, gpointer user_data); static gboolean check_pwd (GtkWidget *main_window, GtkWidget *entry, GtkWidget *retype_entry); static void prepare_multi_encryption (const gchar *algo, const gchar *algo_mode, EncryptWidgets *data); static void exec_thread (gpointer data, gpointer user_data); static void cancel_clicked_cb (GtkWidget *btn, gpointer user_data); void encrypt_files_cb (GtkWidget *btn __attribute__((__unused__)), gpointer user_data) { GtkBuilder *builder = get_builder_from_path (PARTIAL_PATH_TO_UI_FILE); if (builder == NULL) { return; } EncryptWidgets *encrypt_widgets = g_new0 (EncryptWidgets, 1); encrypt_widgets->main_window = (GtkWidget *)user_data; encrypt_widgets->running_threads = 0; encrypt_widgets->files_not_encrypted = 0; encrypt_widgets->first_run = TRUE; encrypt_widgets->files_list = choose_file (encrypt_widgets->main_window, "Choose file(s) to encrypt", TRUE); if (encrypt_widgets->files_list == NULL) { g_free (encrypt_widgets); return; } encrypt_widgets->dialog = GTK_WIDGET (gtk_builder_get_object (builder, "enc_pwd_diag")); encrypt_widgets->ok_btn = GTK_WIDGET (gtk_builder_get_object (builder, "ok_btn_pwd_diag")); encrypt_widgets->cancel_btn = GTK_WIDGET (gtk_builder_get_object (builder, "cancel_btn_pwd_diag")); encrypt_widgets->entry_pwd = GTK_WIDGET (gtk_builder_get_object (builder, "pwd_entry1")); encrypt_widgets->entry_pwd_retype = GTK_WIDGET (gtk_builder_get_object (builder, "pwd_entry2")); encrypt_widgets->message_label = GTK_WIDGET (gtk_builder_get_object (builder, "enc_label")); encrypt_widgets->spinner = GTK_WIDGET (gtk_builder_get_object (builder, "enc_spinner")); encrypt_widgets->header_bar_menu = GTK_WIDGET (gtk_builder_get_object (builder, "enc_menu_btn")); GtkWidget *popover_menu = GTK_WIDGET (gtk_builder_get_object (builder, "enc_popmenu")); encrypt_widgets->radio_btns_algo_list = gtk_radio_button_get_group (GTK_RADIO_BUTTON (gtk_builder_get_object (builder, "aes_rbtn"))); encrypt_widgets->radio_btns_mode_list = gtk_radio_button_get_group (GTK_RADIO_BUTTON (gtk_builder_get_object (builder, "ctr_rbtn"))); gtk_container_add (GTK_CONTAINER (encrypt_widgets->header_bar_menu), GTK_WIDGET (gtk_builder_get_object (builder, "menu_image"))); g_object_unref (builder); gtk_widget_show_all (encrypt_widgets->dialog); gtk_widget_hide (encrypt_widgets->spinner); g_signal_connect (encrypt_widgets->entry_pwd_retype, "activate", G_CALLBACK (entry_activated_cb), encrypt_widgets); g_signal_connect (encrypt_widgets->ok_btn, "clicked", G_CALLBACK (entry_activated_cb), encrypt_widgets); g_signal_connect (encrypt_widgets->cancel_btn, "clicked", G_CALLBACK (cancel_clicked_cb), encrypt_widgets); g_signal_connect (encrypt_widgets->header_bar_menu, "toggled", G_CALLBACK (toggle_changed_cb), popover_menu); g_signal_connect_swapped (encrypt_widgets->dialog, "button-press-event", G_CALLBACK (toggle_active_cb), encrypt_widgets->header_bar_menu); encrypt_widgets->source_id = g_timeout_add (500, check_tp, encrypt_widgets); gtk_dialog_run (GTK_DIALOG (encrypt_widgets->dialog)); } static gboolean check_tp (gpointer data) { EncryptWidgets *widgets = (EncryptWidgets *)data; if (widgets->running_threads == 0 && widgets->first_run == FALSE) { g_thread_pool_free (widgets->thread_pool, FALSE, TRUE); guint list_len = g_slist_length (widgets->files_list); // TODO show failed files gchar *msg = g_strdup_printf ("%u/%u file(s) successfully encrypted.", list_len - widgets->files_not_encrypted, list_len); show_message_dialog (widgets->main_window, msg, GTK_MESSAGE_INFO); g_free (msg); cancel_clicked_cb (NULL, widgets); return FALSE; } else { return TRUE; } } static void entry_activated_cb (GtkWidget *entry __attribute__((unused)), gpointer user_data) { EncryptWidgets *encrypt_widgets = user_data; const gchar *algo = NULL, *mode = NULL; if (!check_pwd (encrypt_widgets->main_window, encrypt_widgets->entry_pwd, encrypt_widgets->entry_pwd_retype)) { return; } else { for (guint i = 0; i < g_slist_length (encrypt_widgets->radio_btns_algo_list); i++) { if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (g_slist_nth_data (encrypt_widgets->radio_btns_algo_list, i)))) { algo = gtk_widget_get_name (g_slist_nth_data (encrypt_widgets->radio_btns_algo_list, i)); break; } } for (guint i = 0; i < g_slist_length (encrypt_widgets->radio_btns_mode_list); i++) { if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (g_slist_nth_data (encrypt_widgets->radio_btns_mode_list, i)))) { mode = gtk_widget_get_name (g_slist_nth_data (encrypt_widgets->radio_btns_mode_list, i)); break; } } prepare_multi_encryption (algo, mode, encrypt_widgets); } } static gboolean check_pwd (GtkWidget *main_window, GtkWidget *entry, GtkWidget *retype_entry) { const gchar *text_entry = gtk_entry_get_text (GTK_ENTRY (entry)); const gchar *text_retype_entry = gtk_entry_get_text (GTK_ENTRY (retype_entry)); gint cmp_retval = g_strcmp0 (text_entry, text_retype_entry); if (cmp_retval != 0) { show_message_dialog (main_window, "Passwords are different, try again...", GTK_MESSAGE_ERROR); return FALSE; } else if (g_utf8_strlen (text_entry, -1) < 8) { show_message_dialog (main_window, "Password is too short (less than 8 chars). Please choose a stronger password.", GTK_MESSAGE_ERROR); return FALSE; } else { return TRUE; } } static void prepare_multi_encryption (const gchar *algo, const gchar *algo_mode, EncryptWidgets *data) { ThreadData *thread_data = g_new0 (ThreadData, 1); thread_data->dialog = data->dialog; thread_data->spinner = data->spinner; thread_data->list_len = g_slist_length (data->files_list); thread_data->algo_btn_name = algo; thread_data->algo_mode_btn_name = algo_mode; thread_data->pwd = gtk_entry_get_text (GTK_ENTRY (data->entry_pwd)); thread_data->widgets = data; gtk_label_set_label (GTK_LABEL (data->message_label), "Encrypting file(s)..."); gtk_widget_show (thread_data->spinner); start_spinner (thread_data->spinner); change_widgets_sensitivity (4, FALSE, &data->ok_btn, &data->cancel_btn, &data->entry_pwd, &data->entry_pwd_retype); g_mutex_init (&thread_data->mutex); data->thread_pool = g_thread_pool_new (exec_thread, thread_data, g_get_num_processors (), TRUE, NULL); for (guint i = 0; i < thread_data->list_len; i++) { g_thread_pool_push (data->thread_pool, g_slist_nth_data (data->files_list, i), NULL); } gtk_dialog_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_DELETE_EVENT); } static void exec_thread (gpointer data, gpointer user_data) { const gchar *filename = (gchar *)data; ThreadData *thread_data = user_data; g_mutex_lock (&thread_data->mutex); thread_data->widgets->running_threads++; g_mutex_unlock (&thread_data->mutex); gpointer ret = encrypt_file (filename, thread_data->pwd, thread_data->algo_btn_name, thread_data->algo_mode_btn_name); if (ret != NULL) { g_mutex_lock (&thread_data->mutex); thread_data->widgets->files_not_encrypted++; g_mutex_unlock (&thread_data->mutex); // TODO deal with error } g_mutex_lock (&thread_data->mutex); thread_data->widgets->running_threads--; thread_data->widgets->first_run = FALSE; g_mutex_unlock (&thread_data->mutex); } static void cancel_clicked_cb (GtkWidget *btn __attribute__((__unused__)), gpointer user_data) { EncryptWidgets *encrypt_widgets = user_data; g_source_remove (encrypt_widgets->source_id); gtk_widget_destroy (encrypt_widgets->dialog); g_slist_free_full (encrypt_widgets->files_list, g_free); g_free (encrypt_widgets); }GTKCrypto-1.0.2/src/encrypt-files-cb.h000066400000000000000000000016241421212406300174440ustar00rootroot00000000000000#pragma once typedef struct encrypt_file_widgets_t { GtkWidget *main_window; GtkWidget *dialog; GtkWidget *entry_pwd; GtkWidget *entry_pwd_retype; GtkWidget *cancel_btn; GtkWidget *ok_btn; GSList *radio_btns_algo_list; GSList *radio_btns_mode_list; GtkWidget *header_bar_menu; GtkWidget *spinner; GtkWidget *message_label; GSList *files_list; GThreadPool *thread_pool; guint running_threads; guint files_not_encrypted; guint source_id; gboolean first_run; } EncryptWidgets; typedef struct enc_thread_data_t { GMutex mutex; GtkWidget *dialog; GtkWidget *spinner; guint list_len; const gchar *algo_btn_name; const gchar *algo_mode_btn_name; const gchar *pwd; EncryptWidgets *widgets; } ThreadData; gpointer encrypt_file (const gchar *input_file_path, const gchar *pwd, const gchar *algo, const gchar *algo_mode);GTKCrypto-1.0.2/src/get-builder.c000066400000000000000000000014761421212406300165010ustar00rootroot00000000000000#include static gchar *get_ui_path (const gchar *partial_path); GtkBuilder * get_builder_from_path (const gchar *partial_path) { gchar *ui_file_path = get_ui_path (partial_path); if (ui_file_path == NULL) { g_printerr ("Couldn't locate the ui file.\n"); return NULL; } return gtk_builder_new_from_file (ui_file_path); } static gchar * get_ui_path (const gchar *partial_path) { gchar *path_to_ui_file = NULL; if (g_file_test (g_strconcat ("/usr/", partial_path, NULL), G_FILE_TEST_EXISTS)) { path_to_ui_file = g_strconcat ("/usr/", partial_path, NULL); } else if (g_file_test (g_strconcat ("/usr/local/", partial_path, NULL), G_FILE_TEST_EXISTS)) { path_to_ui_file = g_strconcat ("/usr/local/", partial_path, NULL); } return path_to_ui_file; }GTKCrypto-1.0.2/src/get-file-size.c000066400000000000000000000012311421212406300167270ustar00rootroot00000000000000#include goffset get_file_size (const gchar *file_path) { GFileInfo *info; GFile *file; GError *error = NULL; const gchar *attributes = "standard::*"; GFileQueryInfoFlags flags = G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS; GCancellable *cancellable = NULL; goffset file_size; file = g_file_new_for_path (file_path); info = g_file_query_info (G_FILE (file), attributes, flags, cancellable, &error); if (info == NULL) { g_printerr ("%s\n", error->message); g_clear_error (&error); return -1; } file_size = g_file_info_get_size (info); g_object_unref (file); return file_size; }GTKCrypto-1.0.2/src/gpgme-misc.c000066400000000000000000000250101421212406300163140ustar00rootroot00000000000000#include #include #include #include #include "gpgme-misc.h" static void init_gpgme (void); static void cleanup (FILE *f1, GFile *f2, GFileOutputStream *ostream, gchar *buf, gpgme_key_t *sk, gpgme_ctx_t *ctx); gpointer sign_file (const gchar *input_file_path, const gchar *fpr) { gpgme_ctx_t context; gpgme_error_t error = gpgme_new (&context); if (error) { g_printerr ("%s: %s\n", gpgme_strsource (error), gpgme_strerror (error)); return GPGME_ERROR; } gpgme_set_armor (context, 0); error = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP); if (error) { g_printerr ("%s: %s\n", gpgme_strsource (error), gpgme_strerror (error)); gpgme_release (context); return GPGME_ERROR; } const char *keyring_dir = gpgme_get_dirinfo ("homedir"); error = gpgme_ctx_set_engine_info (context, GPGME_PROTOCOL_OpenPGP, NULL, keyring_dir); if (error) { g_printerr ("%s: %s\n", gpgme_strsource (error), gpgme_strerror (error)); gpgme_release (context); return GPGME_ERROR; } gpgme_key_t signing_key; error = gpgme_get_key (context, fpr, &signing_key, 1); if (error) { g_printerr ("%s: %s\n", gpgme_strsource (error), gpgme_strerror (error)); gpgme_release (context); return GPGME_ERROR; } error = gpgme_signers_add (context, signing_key); if (error) { g_printerr ("%s: %s\n", gpgme_strsource (error), gpgme_strerror (error)); cleanup (NULL, NULL, NULL, NULL, &signing_key, &context); return GPGME_ERROR; } FILE *infp = g_fopen (input_file_path, "r"); if (infp == NULL) { g_printerr ("Couldn't open input file\n"); cleanup (NULL, NULL, NULL, NULL, &signing_key, &context); return FILE_OPEN_ERROR; } gpgme_data_t clear_text; error = gpgme_data_new_from_stream (&clear_text, infp); if (error) { g_printerr ("%s: %s\n", gpgme_strsource (error), gpgme_strerror (error)); cleanup (infp, NULL, NULL, NULL, &signing_key, &context); return GPGME_ERROR; } gpgme_data_t signed_text; error = gpgme_data_new (&signed_text); if (error) { g_printerr ("%s: %s\n", gpgme_strsource (error), gpgme_strerror (error)); cleanup (infp, NULL, NULL, NULL, &signing_key, &context); return GPGME_ERROR; } error = gpgme_op_sign (context, clear_text, signed_text, GPGME_SIG_MODE_DETACH); if (error) { g_printerr ("%s: %s\n", gpgme_strsource (error), gpgme_strerror (error)); cleanup (infp, NULL, NULL, NULL, &signing_key, &context); return GPGME_ERROR; } gpgme_sign_result_t result = gpgme_op_sign_result (context); if (result->invalid_signers) { g_printerr ("Invalid signer found: %s\n", result->invalid_signers->fpr); cleanup (infp, NULL, NULL, NULL, &signing_key, &context); return GPGME_ERROR; } if (!result->signatures || result->signatures->next) { g_printerr ("Unexpected number of signatures created\n"); cleanup (infp, NULL, NULL, NULL, &signing_key, &context); return GPGME_ERROR; } if (gpgme_data_seek (signed_text, 0, SEEK_SET) == -1) { g_printerr ("gpgme_data_seek error\n"); cleanup (infp, NULL, NULL, NULL, &signing_key, &context); return GPGME_ERROR; } gchar *buffer = g_try_malloc0 (SIG_MAXLEN); if (buffer == NULL) { g_printerr ("Couldn't allocate memory\n"); cleanup (infp, NULL, NULL, NULL, &signing_key, &context); return MEMORY_ALLOCATION_ERROR; } gssize nbytes = gpgme_data_read (signed_text, buffer, SIG_MAXLEN); if (nbytes == -1) { g_printerr ("Error while reading data\n"); cleanup (infp, NULL, NULL, NULL, &signing_key, &context); return GPGME_ERROR; } GError *gerr = NULL; gchar *output_file_path = g_strconcat (input_file_path, ".sig", NULL); GFile *fpout = g_file_new_for_path (output_file_path); GFileOutputStream *ostream = g_file_append_to (fpout, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &gerr); if (gerr != NULL) { g_printerr ("Couldn't open output file for writing\n"); cleanup (infp, fpout, NULL, output_file_path, &signing_key, &context); g_clear_error (&gerr); return FILE_OPEN_ERROR; } gssize wbytes = g_output_stream_write (G_OUTPUT_STREAM (ostream), buffer, (gsize)nbytes, NULL, &gerr); if (wbytes == -1) { g_printerr ("Couldn't write the request number of bytes (%s)\n", gerr->message); cleanup (infp, fpout, ostream, output_file_path, &signing_key, &context); return FILE_WRITE_ERROR; } cleanup (infp, fpout, ostream, output_file_path, &signing_key, &context); return SIGN_OK; } GSList * get_available_keys () { init_gpgme (); gpgme_ctx_t ctx; gpgme_key_t key; gpgme_error_t err = gpgme_new (&ctx); if (err) { g_printerr ("%s: %s\n", gpgme_strsource (err), gpgme_strerror (err)); return GPGME_ERROR; } err = gpgme_op_keylist_start (ctx, NULL, 1); if (err) { g_printerr ("%s: %s\n", gpgme_strsource (err), gpgme_strerror (err)); gpgme_release (ctx); return GPGME_ERROR; } GSList *list = NULL; KeyInfo *key_info; while (1) { err = gpgme_op_keylist_next (ctx, &key); if (err) { break; } key_info = g_new0 (KeyInfo, 1); key_info->key_id = g_strdup (key->subkeys->keyid); if (key->uids && key->uids->name) { key_info->name = g_strdup (key->uids->name); } else { key_info->name = g_strdup ("none"); } if (key->uids && key->uids->email) { key_info->email = g_strdup (key->uids->email); } else { key_info->email = g_strdup ("none"); } key_info->key_fpr = g_strdup (key->subkeys->fpr); gssize bytes_to_copy = (gssize)sizeof(KeyInfo) + g_utf8_strlen (key_info->name, -1) + g_utf8_strlen (key_info->email, -1) + g_utf8_strlen (key_info->key_id, -1) + g_utf8_strlen (key_info->key_fpr, -1) + 4; list = g_slist_append (list, g_memdupX (key_info, (guint)bytes_to_copy)); g_free (key_info); gpgme_key_release (key); } gpgme_release (ctx); return list; } gpointer verify_signature (const gchar *signed_file_path, const gchar *detached_signature_path) { init_gpgme (); gpgme_ctx_t ctx; gpgme_signature_t sig; gpgme_data_t signature_data, signed_data; gpgme_error_t error = gpgme_new (&ctx); if (error) { g_printerr ("%s: %s\n", gpgme_strsource (error), gpgme_strerror (error)); return GPGME_ERROR; } gpgme_set_armor (ctx, 1); error = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP); if (error) { g_printerr ("%s: %s\n", gpgme_strsource (error), gpgme_strerror (error)); gpgme_release (ctx); return GPGME_ERROR; } const char *keyring_dir = gpgme_get_dirinfo ("homedir"); error = gpgme_ctx_set_engine_info (ctx, GPGME_PROTOCOL_OpenPGP, NULL, keyring_dir); if (error) { g_printerr ("%s: %s\n", gpgme_strsource (error), gpgme_strerror (error)); gpgme_release (ctx); return GPGME_ERROR; } FILE *sig_fp = g_fopen (detached_signature_path, "r"); if (sig_fp == NULL) { g_printerr ("Couldn't open detached signature file\n"); gpgme_release (ctx); return FILE_OPEN_ERROR; } FILE *sig_data_fp = g_fopen (signed_file_path, "r"); if (sig_data_fp == NULL) { g_printerr ("Couldn't open signed file\n"); gpgme_release (ctx); fclose (sig_fp); return FILE_OPEN_ERROR; } error = gpgme_data_new_from_stream (&signature_data, sig_fp); if (error) { g_printerr ("%s: %s\n", gpgme_strsource (error), gpgme_strerror (error)); fclose (sig_fp); fclose (sig_data_fp); gpgme_release (ctx); return GPGME_ERROR; } error = gpgme_data_new_from_stream (&signed_data, sig_data_fp); if (error) { g_printerr ("%s: %s\n", gpgme_strsource (error), gpgme_strerror (error)); fclose (sig_fp); fclose (sig_data_fp); gpgme_release (ctx); gpgme_data_release (signature_data); return GPGME_ERROR; } error = gpgme_op_verify (ctx, signature_data, signed_data, NULL); gpgme_data_release (signature_data); gpgme_data_release (signed_data); fclose (sig_fp); fclose (sig_data_fp); if (error != GPG_ERR_NO_ERROR) { g_printerr ("%s: %s\n", gpgme_strsource (error), gpgme_strerror (error)); gpgme_release (ctx); return GPGME_ERROR; } gpgme_verify_result_t result = gpgme_op_verify_result (ctx); if (!result) { g_printerr ("%s: %s\n", gpgme_strsource (error), gpgme_strerror (error)); gpgme_release (ctx); return GPGME_ERROR; } sig = result->signatures; if (!sig) { gpgme_release (ctx); return NO_GPG_KEYS_AVAILABLE; } for (; sig; sig = sig->next) { if ((sig->summary & GPGME_SIGSUM_VALID) || (sig->summary & GPGME_SIGSUM_GREEN)) { gpgme_release (ctx); return SIGNATURE_OK; } else if (sig->summary == 0 && sig->status == GPG_ERR_NO_ERROR) { // Valid but key is not certified with a trusted signature gpgme_release (ctx); return SIGNATURE_OK_KEY_NOT_TRUSTED; } } gpgme_release (ctx); return BAD_SIGNATURE; } static void init_gpgme () { setlocale (LC_ALL, ""); gpgme_check_version (NULL); gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL)); #ifdef LC_MESSAGES gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL)); #endif } static void cleanup (FILE *f1, GFile *f2, GFileOutputStream *ostream, gchar *buf, gpgme_key_t *sk, gpgme_ctx_t *ctx) { if (f1 != NULL) { fclose (f1); } if (f2 != NULL) { g_object_unref (f2); } if (ostream != NULL) { g_output_stream_close (G_OUTPUT_STREAM (ostream), NULL, NULL); g_object_unref (ostream); } g_free (buf); if (sk != NULL) { gpgme_key_release (*sk); } if (ctx != NULL) { gpgme_release (*ctx); } } GTKCrypto-1.0.2/src/gpgme-misc.h000066400000000000000000000020101421212406300163140ustar00rootroot00000000000000#pragma once #define SIG_MAXLEN 4096 #define SIGNATURE_OK_KEY_NOT_TRUSTED ((gpointer) 2) #define SIGNATURE_OK ((gpointer) 1) #define SIGN_OK ((gpointer) 0) #define GPGME_ERROR ((gpointer) -1) #define FILE_OPEN_ERROR ((gpointer) -2) #define FILE_WRITE_ERROR ((gpointer) -3) #define MEMORY_ALLOCATION_ERROR ((gpointer) -4) #define NO_GPG_KEYS_AVAILABLE ((gpointer) -5) #define BAD_SIGNATURE ((gpointer) -6) #if GLIB_CHECK_VERSION(2, 68, 0) #define g_memdupX g_memdup2 #else #define g_memdupX g_memdup #endif typedef struct _key_info_t { gchar *name; gchar *email; gchar *key_id; gchar *key_fpr; } KeyInfo; GSList *get_available_keys (void); gpointer sign_file (const gchar *input_file_path, const gchar *fpr); gpointer verify_signature (const gchar *detached_signature_path, const gchar *signed_file_path); GTKCrypto-1.0.2/src/gtkcrypto.h000066400000000000000000000016071421212406300163250ustar00rootroot00000000000000#pragma once #define PARTIAL_PATH_TO_UI_FILE "share/gtkcrypto/gtkcrypto.ui" void show_message_dialog (GtkWidget *parent, const gchar *message, GtkMessageType); GSList *choose_file (GtkWidget *parent, const gchar *title, gboolean select_multiple); gchar *get_filename_from_list (GSList *list); gchar *get_file_hash (const gchar *file_path, gint hash_algo, gint digest_size); goffset get_file_size (const gchar *file_path); GtkWidget *create_spinner (void); void start_spinner (GtkWidget *spinner); void stop_spinner (GtkWidget *spinner); void change_widgets_sensitivity (gint number_of_widgets, gboolean value, GtkWidget **widget, ...); GtkBuilder *get_builder_from_path (const gchar *partial_path); GTKCrypto-1.0.2/src/hash.c000066400000000000000000000067231421212406300152210ustar00rootroot00000000000000#define _GNU_SOURCE #include #include #include #include #include #include #include "hash.h" #include "gtkcrypto.h" gchar * get_file_hash (const gchar *filename, gint hash_algo, gint digest_size) { const gchar *name = gcry_md_algo_name (hash_algo); gint algo = gcry_md_map_name (name); gcry_md_hd_t hd; gcry_md_open (&hd, algo, 0); gpointer status = compute_hash (&hd, filename); if (status == MAP_FAILED) { g_printerr ("mmap error\n"); return NULL; } else if (status == MUNMAP_FAILED) { g_printerr ("munmap error\n"); return NULL; } else if (status == HASH_ERROR) { return NULL; } else { return finalize_hash (&hd, algo, digest_size); } } gpointer compute_hash (gcry_md_hd_t *hd, const gchar *filename) { guint8 *addr; gint ret_val = 0; gsize done_size = 0, diff = 0, offset = 0; goffset file_size = get_file_size (filename); if (file_size == -1) { g_printerr ("Error while getting file size\n"); return HASH_ERROR; } gint fd = g_open (filename, O_RDONLY | O_NOFOLLOW); if (fd == -1) { g_printerr ("%s\n", g_strerror (errno)); return HASH_ERROR; } if (file_size < FILE_BUFFER) { addr = mmap (NULL, (gsize)file_size, PROT_READ, MAP_FILE | MAP_SHARED, fd, 0); if (addr == MAP_FAILED) { g_close (fd, NULL); return MAP_FAILED; } gcry_md_write (*hd, addr, (gsize) file_size); ret_val = munmap (addr, (gsize) file_size); if (ret_val == -1) { g_close (fd, NULL); return MUNMAP_FAILED; } g_close (fd, NULL); return HASH_COMPUTED; } else { while (file_size > done_size) { addr = mmap (NULL, FILE_BUFFER, PROT_READ, MAP_FILE | MAP_SHARED, fd, offset); if (addr == MAP_FAILED) { g_close (fd, NULL); return MAP_FAILED; } gcry_md_write (*hd, addr, FILE_BUFFER); done_size += FILE_BUFFER; diff = file_size - done_size; offset += FILE_BUFFER; if (diff < FILE_BUFFER) { addr = mmap (NULL, diff, PROT_READ, MAP_FILE | MAP_SHARED, fd, offset); if (addr == MAP_FAILED) { g_close (fd, NULL); return MAP_FAILED; } gcry_md_write (*hd, addr, diff); ret_val = munmap (addr, diff); if (ret_val == -1) { g_close (fd, NULL); return MUNMAP_FAILED; } break; } ret_val = munmap (addr, FILE_BUFFER); if (ret_val == -1) { g_close (fd, NULL); return MUNMAP_FAILED; } } g_close (fd, NULL); return HASH_COMPUTED; } } gchar * finalize_hash (gcry_md_hd_t *hd, gint algo, gint digest_size) { gcry_md_final (*hd); gchar *finalized_hash = g_malloc0 ((gsize) digest_size * 2 + 1); guchar *hash = gcry_md_read (*hd, algo); for (gint i = 0; i < digest_size; i++) { g_sprintf (finalized_hash + (i * 2), "%02x", hash[i]); } finalized_hash[digest_size * 2] = '\0'; gcry_md_close (*hd); return finalized_hash; } GTKCrypto-1.0.2/src/hash.h000066400000000000000000000020231421212406300152130ustar00rootroot00000000000000#pragma once #define HASH_COMPUTED ((gpointer) 10) #define HASH_ERROR ((gpointer) 11) #define MUNMAP_FAILED ((gpointer) 12) #define HMAC_OK ((gpointer) 13) #define HMAC_MISMATCH ((gpointer) 14) #define FILE_BUFFER 67108864 // 64 MiB #define AVAILABLE_HASH_TYPE 10 #define MD5_DIGEST_SIZE 16 #define SHA1_DIGEST_SIZE 20 #define GOST94_DIGEST_SIZE 32 #define SHA256_DIGEST_SIZE 32 #define SHA3_256_DIGEST_SIZE 32 #define SHA384_DIGEST_SIZE 48 #define SHA3_384_DIGEST_SIZE 48 #define SHA512_DIGEST_SIZE 64 #define SHA3_512_DIGEST_SIZE 64 #define WHIRLPOOL_DIGEST_SIZE 64 gpointer compute_hash (gcry_md_hd_t *hd, const gchar *file_path); gchar *finalize_hash (gcry_md_hd_t *hd, gint algo, gint digest_size); guchar *calculate_hmac (const gchar *file_path, const guchar *key, guchar *user_hmac); GTKCrypto-1.0.2/src/hmac.c000066400000000000000000000111221421212406300151730ustar00rootroot00000000000000#include #include #include "crypt-common.h" #include "hash.h" #include "gtkcrypto.h" guchar * calculate_hmac (const gchar *file_path, const guchar *key, guchar *user_hmac) { gsize mac_len = gcry_mac_get_algo_maclen (GCRY_MAC_HMAC_SHA3_512); guchar *hmac = g_try_malloc0 (mac_len); if (hmac == NULL) { g_printerr ("Unable to allocate enough memory for the HMAC\n"); return NULL; } gcry_mac_hd_t mac; gcry_error_t err = gcry_mac_open (&mac, GCRY_MAC_HMAC_SHA3_512, 0, NULL); if (err) { g_printerr ("mac_open error: %s/%s\n", gcry_strsource (err), gcry_strerror (err)); g_free (hmac); return NULL; } err = gcry_mac_setkey (mac, key, HMAC_KEY_SIZE); if (err) { g_printerr ("mac_setkey error: %s/%s\n", gcry_strsource (err), gcry_strerror (err)); gcry_mac_close (mac); g_free (hmac); return NULL; } guchar *buf; goffset file_size = get_file_size (file_path); if (file_size < FILE_BUFFER) { buf = g_try_malloc0 ((gsize)file_size); } else { buf = g_try_malloc0 (FILE_BUFFER); } if (buf == NULL) { g_printerr ("Error during memory allocation (hmac's buffer)\n"); gcry_mac_close (mac); g_free (hmac); return NULL; } GError *gerr = NULL; GFile *file = g_file_new_for_path (file_path); GFileInputStream *istream = g_file_read (file, NULL, &gerr); if (gerr != NULL) { g_printerr ("%s\n", gerr->message); g_object_unref (file); gcry_mac_close (mac); g_free (hmac); g_free (buf); g_clear_error (&gerr); return NULL; } gssize read_len; goffset done_size = 0; while (done_size < file_size) { if ((file_size - done_size) < FILE_BUFFER) { read_len = g_input_stream_read (G_INPUT_STREAM (istream), buf, (gsize)file_size - done_size, NULL, &gerr); if (read_len == -1) { g_printerr ("%s\n", gerr->message); g_free (buf); g_free (hmac); return NULL; } err = gcry_mac_write (mac, buf, (gsize)read_len); if (err) { g_printerr ("mac_write error: %s/%s\n", gcry_strsource (err), gcry_strerror (err)); gcry_mac_close (mac); g_free (buf); g_free (hmac); g_input_stream_close (G_INPUT_STREAM (istream), NULL, NULL); g_object_unref (istream); g_object_unref (file); return NULL; } break; } else { read_len = g_input_stream_read (G_INPUT_STREAM (istream), buf, FILE_BUFFER, NULL, &gerr); if (read_len == -1) { g_printerr ("%s\n", gerr->message); gcry_mac_close (mac); g_free (buf); g_free (hmac); return NULL; } err = gcry_mac_write (mac, buf, (gsize)read_len); } if (err) { g_printerr ("mac_write error: %s/%s\n", gcry_strsource (err), gcry_strerror (err)); gcry_mac_close (mac); g_free (buf); g_free (hmac); g_input_stream_close (G_INPUT_STREAM (istream), NULL, NULL); g_object_unref (istream); g_object_unref (file); return NULL; } done_size += FILE_BUFFER; } if (user_hmac != NULL) { err = gcry_mac_verify (mac, user_hmac, mac_len); gcry_mac_close (mac); g_free (buf); g_free (hmac); g_input_stream_close (G_INPUT_STREAM (istream), NULL, NULL); g_object_unref (istream); g_object_unref (file); if (err) { g_printerr ("HMAC verification failed: %s/%s\n", gcry_strsource (err), gcry_strerror (err)); return HMAC_MISMATCH; } else { return HMAC_OK; } } else { err = gcry_mac_read (mac, hmac, &mac_len); if (err) { g_printerr ("mac_read error: %s/%s\n", gcry_strsource(err), gcry_strerror(err)); gcry_mac_close (mac); g_free (buf); g_free (hmac); g_input_stream_close (G_INPUT_STREAM (istream), NULL, NULL); g_object_unref (istream); g_object_unref (file); return NULL; } } gcry_mac_close (mac); g_free (buf); g_input_stream_close (G_INPUT_STREAM (istream), NULL, NULL); g_object_unref (istream); g_object_unref (file); return hmac; } GTKCrypto-1.0.2/src/main.c000066400000000000000000000007411421212406300152140ustar00rootroot00000000000000#include #include "main.h" gint main (gint argc, gchar **argv) { GtkApplication *app; gint status; app = gtk_application_new ("com.github.paolostivanin.GTKCrypto", G_APPLICATION_FLAGS_NONE); g_set_application_name (APP_NAME); g_set_prgname (APP_NAME); g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); status = g_application_run (G_APPLICATION (app), argc, argv); g_object_unref (app); return status; } GTKCrypto-1.0.2/src/main.h000066400000000000000000000014431421212406300152210ustar00rootroot00000000000000#pragma once #define APP_NAME "GTKCrypto" #define APP_VERSION "1.0.2" #define GCRYPT_MIN_VERSION "1.7.0" #define SECURE_MEMORY_POOL_SIZE 32768 void activate (GtkApplication *app, gpointer user_data); void encrypt_files_cb (GtkWidget *button, gpointer user_data); void decrypt_files_cb (GtkWidget *button, gpointer user_data); void sign_file_cb (GtkWidget *button, gpointer user_data); void verify_signature_cb (GtkWidget *button, gpointer user_data); void txt_cb (GtkWidget *button, gpointer user_data); void compute_hash_cb (GtkWidget *button, gpointer user_data); void compare_files_hash_cb (GtkWidget *button, gpointer user_data); GTKCrypto-1.0.2/src/mcw-sensitivity.c000066400000000000000000000006201421212406300174420ustar00rootroot00000000000000#include void change_widgets_sensitivity (gint argc, gboolean value, GtkWidget **widget, ...) { gint i = 0; va_list ptr; va_start (ptr, widget); while (i < argc) { if (gtk_widget_get_sensitive (*widget) != value) { gtk_widget_set_sensitive (*widget, value); } widget = va_arg (ptr, GtkWidget **); i++; } va_end (ptr); }GTKCrypto-1.0.2/src/message-dialog.c000066400000000000000000000007611421212406300171530ustar00rootroot00000000000000#include void show_message_dialog (GtkWidget *parent, const gchar *message, GtkMessageType message_type) { static GtkWidget *dialog = NULL; dialog = gtk_message_dialog_new (parent == NULL ? NULL : GTK_WINDOW(parent), GTK_DIALOG_MODAL, message_type, GTK_BUTTONS_OK, "%s", message); gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG(dialog), message); gtk_dialog_run (GTK_DIALOG(dialog)); gtk_widget_destroy (dialog); }GTKCrypto-1.0.2/src/misc-style.c000066400000000000000000000024431421212406300163620ustar00rootroot00000000000000#include #include "misc-style.h" void set_css (gint css_type, GtkWidget *widget) { GError *err = NULL; const gchar *data = NULL; GtkCssProvider *css = gtk_css_provider_new (); if (css_type == HASH_ERR_CSS) { data = "#file1_he_name, #file2_he_name { font-family: \"monospace\"; background: #FA5858;}"; } else if (css_type == HASH_OK_CSS) { data = "#file1_he_name, #file2_he_name {font-family: \"monospace\"; background: limegreen;}"; } gtk_css_provider_load_from_data (css, data, -1, &err); gtk_style_context_add_provider (gtk_widget_get_style_context (widget), GTK_STYLE_PROVIDER (css), GTK_STYLE_PROVIDER_PRIORITY_USER); g_object_unref (css); } PangoData * get_pango_monospace_attr () { PangoData *pango_data = g_new0 (PangoData, 1); pango_data->attrs = pango_attr_list_new (); pango_data->font_desc = pango_font_description_new (); pango_font_description_set_family (pango_data->font_desc, "monospace"); pango_data->attr = pango_attr_font_desc_new (pango_data->font_desc); pango_attr_list_insert (pango_data->attrs, pango_data->attr); return pango_data; } void pango_data_free (PangoData *data) { pango_font_description_free (data->font_desc); pango_attr_list_unref (data->attrs); g_free (data); }GTKCrypto-1.0.2/src/misc-style.h000066400000000000000000000005121421212406300163620ustar00rootroot00000000000000#pragma once #define HASH_ERR_CSS 101 #define HASH_OK_CSS 102 typedef struct _pango_data { PangoAttrList *attrs; PangoFontDescription *font_desc; PangoAttribute *attr; } PangoData; void set_css (gint css_type, GtkWidget *widget); PangoData *get_pango_monospace_attr (void); void pango_data_free (PangoData *data);GTKCrypto-1.0.2/src/sign-file-cb.c000066400000000000000000000164651421212406300165410ustar00rootroot00000000000000#include #include "common-widgets.h" #include "gtkcrypto.h" #include "gpgme-misc.h" typedef struct sign_file_widgets_t { GtkWidget *main_window; GtkWidget *dialog; GtkWidget *combo_box; GtkWidget *cancel_btn; GtkWidget *ok_btn; GtkWidget *spinner; GtkWidget *message_label; gchar *filename; GSList *gpg_keys; GSList *to_free; GThread *sign_thread; } SignFileWidgets; typedef struct sign_thread_data_t { GtkWidget *dialog; GtkWidget *spinner; GtkWidget *message_label; const gchar *filename; const gchar *key_fingerprint; } ThreadData; static void prepare_signing_cb (GtkWidget *btn, gpointer user_data); static gpointer exec_thread (gpointer user_data); static void cancel_clicked_cb (GtkWidget *btn, gpointer user_data); void sign_file_cb (GtkWidget *btn __attribute__((unused)), gpointer user_data) { SignFileWidgets *sign_file_widgets = g_new0 (SignFileWidgets, 1); sign_file_widgets->sign_thread = NULL; sign_file_widgets->main_window = user_data; // TODO multiple files sign GSList *list = choose_file (sign_file_widgets->main_window, "Choose File", FALSE); sign_file_widgets->filename = get_filename_from_list (list); if (sign_file_widgets->filename == NULL) { g_free (sign_file_widgets); return; } sign_file_widgets->dialog = create_dialog (sign_file_widgets->main_window, "sign_fl_diag", "Select GPG key"); sign_file_widgets->cancel_btn = gtk_button_new_with_label ("Cancel"); sign_file_widgets->ok_btn = gtk_button_new_with_label ("OK"); gtk_widget_set_size_request (sign_file_widgets->dialog, 800, -1); sign_file_widgets->message_label = gtk_label_new (""); sign_file_widgets->spinner = create_spinner (); sign_file_widgets->gpg_keys = get_available_keys (); if (sign_file_widgets->gpg_keys == NULL) { show_message_dialog (sign_file_widgets->main_window, "No GPG keys available", GTK_MESSAGE_INFO); g_free (sign_file_widgets); return; } sign_file_widgets->combo_box = gtk_combo_box_text_new (); gtk_widget_set_hexpand (sign_file_widgets->combo_box, TRUE); gtk_widget_set_hexpand (sign_file_widgets->message_label, TRUE); gchar *str; sign_file_widgets->to_free = NULL; for (guint i = 0; i < g_slist_length (sign_file_widgets->gpg_keys); i++) { KeyInfo *key_data = g_slist_nth_data (sign_file_widgets->gpg_keys, i); if (g_utf8_strlen (key_data->name, -1) + g_utf8_strlen (key_data->email, -1) > 128) { str = g_strconcat ("Name and email too long. Key ID: ", key_data->key_id, NULL); } else { str = g_strconcat (key_data->name, " <", key_data->email, "> (", key_data->key_id, ")", NULL); } sign_file_widgets->to_free = g_slist_append (sign_file_widgets->to_free, g_strdup (str)); g_free (str); gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (sign_file_widgets->combo_box), key_data->key_fpr, (gchar *) g_slist_nth_data (sign_file_widgets->to_free, i)); } GtkWidget *grid = gtk_grid_new (); gtk_grid_set_row_spacing (GTK_GRID (grid), 10); gtk_grid_attach (GTK_GRID (grid), sign_file_widgets->combo_box, 0, 0, 4, 1); gtk_grid_attach (GTK_GRID (grid), sign_file_widgets->message_label, 0, 1, 2, 1); gtk_grid_attach_next_to (GTK_GRID (grid), sign_file_widgets->spinner, sign_file_widgets->message_label, GTK_POS_RIGHT, 1, 1); GtkWidget *hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5); gtk_box_pack_end (GTK_BOX(hbox), sign_file_widgets->ok_btn, TRUE, TRUE, 0); gtk_box_pack_end (GTK_BOX(hbox), sign_file_widgets->cancel_btn, TRUE, TRUE, 0); gtk_grid_attach (GTK_GRID (grid), hbox, 3, 4, 1, 1); gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (sign_file_widgets->dialog))), grid); gtk_widget_show_all (sign_file_widgets->dialog); gtk_widget_hide (sign_file_widgets->spinner); g_signal_connect (sign_file_widgets->ok_btn, "clicked", G_CALLBACK (prepare_signing_cb), sign_file_widgets); g_signal_connect (sign_file_widgets->combo_box, "changed", G_CALLBACK (prepare_signing_cb), sign_file_widgets); g_signal_connect (sign_file_widgets->cancel_btn, "clicked", G_CALLBACK (cancel_clicked_cb), sign_file_widgets); gint result = gtk_dialog_run (GTK_DIALOG (sign_file_widgets->dialog)); switch (result) { case GTK_RESPONSE_DELETE_EVENT: if (sign_file_widgets->sign_thread != NULL) { gpointer status = g_thread_join (sign_file_widgets->sign_thread); if (status != SIGN_OK) { show_message_dialog (sign_file_widgets->main_window, "Couldn't sign file", GTK_MESSAGE_ERROR); } else { gchar *info_message = g_strconcat ("File ", sign_file_widgets->filename, " has been successfully signed\n" "(GPG key fingerprint: ", gtk_combo_box_get_active_id (GTK_COMBO_BOX (sign_file_widgets->combo_box)), ")", NULL); show_message_dialog (sign_file_widgets->dialog, info_message, GTK_MESSAGE_INFO); g_free (info_message); } } g_slist_free_full (sign_file_widgets->gpg_keys, g_free); g_slist_free_full (sign_file_widgets->to_free, g_free); gtk_widget_destroy (sign_file_widgets->dialog); g_free (sign_file_widgets->filename); g_free (sign_file_widgets); break; default: break; } } static void cancel_clicked_cb (GtkWidget *btn __attribute__((unused)), gpointer user_data) { SignFileWidgets *data = user_data; g_slist_free_full (data->gpg_keys, g_free); g_slist_free_full (data->to_free, g_free); gtk_widget_destroy (data->dialog); g_free (data->filename); g_free (data); } static void prepare_signing_cb (GtkWidget *btn __attribute__((unused)), gpointer user_data) { SignFileWidgets *data = user_data; ThreadData *thread_data = g_new0 (ThreadData, 1); thread_data->dialog = data->dialog; thread_data->spinner = data->spinner; thread_data->message_label = data->message_label; thread_data->filename = data->filename; thread_data->key_fingerprint = gtk_combo_box_get_active_id (GTK_COMBO_BOX (data->combo_box)); gtk_widget_show (thread_data->spinner); start_spinner (thread_data->spinner); change_widgets_sensitivity (3, FALSE, &data->ok_btn, &data->cancel_btn, &data->combo_box); data->sign_thread = g_thread_new (NULL, exec_thread, thread_data); } #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wreturn-type" static gpointer exec_thread (gpointer user_data) { ThreadData *data = user_data; gchar *basename = g_path_get_basename (data->filename); gchar *message = g_strconcat ("Signing ", basename, "...", NULL); set_label_message (data->message_label, message); gpointer status = sign_file (data->filename, data->key_fingerprint); gtk_dialog_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_DELETE_EVENT); g_free (data); g_free (basename); g_free (message); g_thread_exit (status); } //-V591 #pragma GCC diagnostic pop GTKCrypto-1.0.2/src/spinner.c000066400000000000000000000004461421212406300157500ustar00rootroot00000000000000#include #include "gtkcrypto.h" GtkWidget * create_spinner () { return gtk_spinner_new (); } void start_spinner (GtkWidget *spinner) { gtk_spinner_start (GTK_SPINNER (spinner)); } void stop_spinner (GtkWidget *spinner) { gtk_spinner_stop (GTK_SPINNER (spinner)); }GTKCrypto-1.0.2/src/text-cb.c000066400000000000000000000343141421212406300156410ustar00rootroot00000000000000#include #include #include "gtkcrypto.h" #include "main.h" #define AES256_KEY_SIZE 32 #define AES256_BLOCK_SIZE 16 #define AES256_IV_SIZE AES256_BLOCK_SIZE #define TAG_SIZE AES256_BLOCK_SIZE #define KDF_ITERATIONS 150000 #define KDF_SALT_SIZE 32 typedef struct _txt_data { GtkWidget *diag; GtkWidget *entry1; GtkWidget *entry2; GtkTextBuffer *txt_buf; gchar *text_from_buffer; } TxtData; typedef struct _crypt_data { gcry_cipher_hd_t hd; guint8 *iv; guint8 *salt; guint8 *derived_key; } CryptData; static void enc_txt (GtkWidget *btn, gpointer user_data); static void dec_txt (GtkWidget *btn, gpointer user_data); static void load_text_from_buffer (TxtData *txt_data); static gchar *check_pwd (GtkEntry *entry1, GtkEntry *entry2); static gboolean is_b64_encoded (const gchar *text); static gint get_bytes_in_buffer (GtkTextBuffer *buf); static void prepare_crypto (CryptData *crypt_data); static gpg_error_t derive_and_set_cipher_data (TxtData *txt_data, CryptData *crypt_data); static void show_dialog_with_data (gchar *data); static void show_error_and_cleanup (GtkWidget *diag, gchar *err_msg, CryptData *crypt_data); void txt_cb (GtkWidget *btn, gpointer user_data __attribute__((unused))) { GtkBuilder *builder = get_builder_from_path (PARTIAL_PATH_TO_UI_FILE); if (builder == NULL) { return; } TxtData *txt_data = g_new0 (TxtData, 1); txt_data->diag = GTK_WIDGET(gtk_builder_get_object (builder, "text_diag")); GtkWidget *ok_btn = GTK_WIDGET(gtk_builder_get_object (builder, "txt_btn_ok")); txt_data->entry1 = GTK_WIDGET(gtk_builder_get_object (builder, "pwd_entry1_txt")); txt_data->entry2 = GTK_WIDGET(gtk_builder_get_object (builder, "pwd_entry2_txt")); txt_data->txt_buf = GTK_TEXT_BUFFER(gtk_builder_get_object (builder, "text_buf")); g_object_unref (builder); if (g_strcmp0 (gtk_widget_get_name (btn), "dectxt_btn") == 0) { gtk_widget_destroy (txt_data->entry2); } gtk_widget_show_all (txt_data->diag); if (g_strcmp0 (gtk_widget_get_name (btn), "enctxt_btn") == 0) { g_signal_connect (ok_btn, "clicked", G_CALLBACK (enc_txt), txt_data); } else { g_signal_connect (ok_btn, "clicked", G_CALLBACK (dec_txt), txt_data); } gint result = gtk_dialog_run (GTK_DIALOG(txt_data->diag)); switch (result) { case GTK_RESPONSE_CANCEL: default: gtk_widget_destroy (txt_data->diag); g_free (txt_data); break; } } static void enc_txt (GtkWidget *btn __attribute__((unused)), gpointer user_data) { CryptData *crypt_data = g_new0 (CryptData, 1); TxtData *txt_data = (TxtData *)user_data; gchar *err_msg = check_pwd (GTK_ENTRY(txt_data->entry1), GTK_ENTRY(txt_data->entry2)); if (err_msg != NULL) { show_error_and_cleanup (txt_data->diag, err_msg, NULL); g_free (crypt_data); return; } gint text_size_in_bytes = get_bytes_in_buffer (txt_data->txt_buf); if (text_size_in_bytes == -1) { err_msg = g_strdup_printf ("Input data (%d input size) is too large (%d max size).\n", text_size_in_bytes, SECURE_MEMORY_POOL_SIZE); show_error_and_cleanup (txt_data->diag, err_msg, NULL); g_free (crypt_data); return; } load_text_from_buffer (txt_data); if (!g_utf8_validate (txt_data->text_from_buffer, -1, NULL)) { show_message_dialog (txt_data->diag, "Input is not valid utf8, exiting.", GTK_MESSAGE_ERROR); g_free (crypt_data); g_free (txt_data->text_from_buffer); return; } prepare_crypto (crypt_data); gcry_create_nonce (crypt_data->iv, AES256_IV_SIZE); gcry_create_nonce (crypt_data->salt, KDF_SALT_SIZE); gpg_error_t err = derive_and_set_cipher_data (txt_data, crypt_data); if (err != 0) { err_msg = g_strdup_printf ("%s\n", gcry_strerror (err)); show_error_and_cleanup (txt_data->diag, err_msg, crypt_data); g_free (txt_data->text_from_buffer); gcry_cipher_close (crypt_data->hd); return; } guchar *enc_buf = gcry_calloc ((gsize)text_size_in_bytes, 1); err = gcry_cipher_encrypt (crypt_data->hd, enc_buf, (gsize)text_size_in_bytes, txt_data->text_from_buffer, (gsize)text_size_in_bytes); g_free (txt_data->text_from_buffer); if (err != 0) { err_msg = g_strdup_printf ("Couldn't encrypt given input: %s\n", gcry_strerror (err)); show_error_and_cleanup (txt_data->diag, err_msg, crypt_data); gcry_free (enc_buf); gcry_cipher_close (crypt_data->hd); return; } gsize final_buf_size = (gsize)text_size_in_bytes + TAG_SIZE + AES256_IV_SIZE + KDF_SALT_SIZE; guchar *final_buf = gcry_calloc (final_buf_size, 1); memcpy (final_buf, crypt_data->iv, AES256_IV_SIZE); memcpy (final_buf + AES256_IV_SIZE, crypt_data->salt, KDF_SALT_SIZE); memcpy (final_buf + AES256_IV_SIZE + KDF_SALT_SIZE, enc_buf, (gsize)text_size_in_bytes); guint8 tag[TAG_SIZE]; err = gcry_cipher_gettag (crypt_data->hd, tag, TAG_SIZE); if (err != 0) { err_msg = g_strdup_printf ("Couldn't get tag: %s\n", gcry_strerror (err)); show_error_and_cleanup (txt_data->diag, err_msg, crypt_data); gcry_free (enc_buf); gcry_free (final_buf); gcry_cipher_close (crypt_data->hd); return; } gcry_cipher_close (crypt_data->hd); memcpy (final_buf + AES256_IV_SIZE + KDF_SALT_SIZE + (gsize)text_size_in_bytes, tag, TAG_SIZE); gint state = 0, save = 0, b64_encoded_data_len = 0; gsize data_size = (final_buf_size / 3 + 1) * 4 + 4; gchar *b64_encoded_buf = g_malloc0 (data_size + (data_size / 72 + 1)); b64_encoded_data_len += (gint)g_base64_encode_step (final_buf, final_buf_size, TRUE, b64_encoded_buf, &state, &save); b64_encoded_data_len += (gint)g_base64_encode_close (TRUE, b64_encoded_buf + b64_encoded_data_len, &state, &save); b64_encoded_buf[b64_encoded_data_len] = '\0'; show_dialog_with_data (b64_encoded_buf); g_free (b64_encoded_buf); gcry_free (final_buf); gcry_free (enc_buf); gcry_free (crypt_data->derived_key); gcry_free (crypt_data->iv); gcry_free (crypt_data->salt); g_free (crypt_data); gtk_dialog_response (GTK_DIALOG(txt_data->diag), GTK_RESPONSE_CANCEL); } static void dec_txt (GtkWidget *btn __attribute__((unused)), gpointer user_data) { CryptData *crypt_data = g_new0 (CryptData, 1); TxtData *txt_data = (TxtData *)user_data; gchar *err_msg = check_pwd (GTK_ENTRY(txt_data->entry1), NULL); if (err_msg != NULL) { show_error_and_cleanup (txt_data->diag, err_msg, NULL); g_free (crypt_data); return; } gint num_of_chars = gtk_text_buffer_get_char_count (txt_data->txt_buf); if ((num_of_chars / 4 * 3) > SECURE_MEMORY_POOL_SIZE) { err_msg = g_strdup_printf ("Input data (%d input size) is too large (%d max size).\n", num_of_chars / 4 * 3, SECURE_MEMORY_POOL_SIZE); show_error_and_cleanup (txt_data->diag, err_msg, NULL); g_free (crypt_data); return; } load_text_from_buffer (txt_data); if (!g_str_is_ascii (txt_data->text_from_buffer)) { err_msg = g_strdup ("The input data contains invalid chars (only ASCII chars allowed)"); show_error_and_cleanup (txt_data->diag, err_msg, NULL); g_free (crypt_data); g_free (txt_data->text_from_buffer); return; } if (!is_b64_encoded (txt_data->text_from_buffer)) { err_msg = g_strdup ("The given input is NOT base64 encoded"); show_error_and_cleanup (txt_data->diag, err_msg, NULL); g_free (crypt_data); g_free (txt_data->text_from_buffer); return; } prepare_crypto (crypt_data); gsize out_len = 0; guchar *encrypted_buf = g_base64_decode (txt_data->text_from_buffer, &out_len); g_free (txt_data->text_from_buffer); memcpy (crypt_data->iv, encrypted_buf, AES256_IV_SIZE); memcpy (crypt_data->salt, encrypted_buf + AES256_IV_SIZE, KDF_SALT_SIZE); gpg_error_t err = derive_and_set_cipher_data (txt_data, crypt_data); if (err != 0) { err_msg = g_strdup_printf ("%s\n", gcry_strerror (err)); show_error_and_cleanup (txt_data->diag, err_msg, crypt_data); g_free (encrypted_buf); gcry_cipher_close (crypt_data->hd); return; } gsize enc_body_len = out_len - AES256_IV_SIZE - KDF_SALT_SIZE - TAG_SIZE; guchar *enc_body = g_malloc0 (enc_body_len); memcpy (enc_body, encrypted_buf + AES256_IV_SIZE + KDF_SALT_SIZE, enc_body_len); gchar *plain_buf = gcry_calloc_secure (enc_body_len, 1); gcry_cipher_decrypt (crypt_data->hd, plain_buf, enc_body_len, enc_body, enc_body_len); guint8 tag[TAG_SIZE]; memcpy (tag, encrypted_buf + (out_len - TAG_SIZE), TAG_SIZE); err = gcry_cipher_checktag (crypt_data->hd, tag, TAG_SIZE); if (err != 0) { err_msg = g_strdup_printf ("Error: %s\nEither the password is wrong or the data is corrupted.\n", gcry_strerror (err)); show_error_and_cleanup (txt_data->diag, err_msg, crypt_data); g_free (encrypted_buf); g_free (enc_body); gcry_free (plain_buf); gcry_cipher_close (crypt_data->hd); return; } gcry_cipher_close (crypt_data->hd); show_dialog_with_data (plain_buf); g_free (encrypted_buf); g_free (enc_body); gcry_free (plain_buf); gcry_free (crypt_data->derived_key); gcry_free (crypt_data->iv); gcry_free (crypt_data->salt); g_free (crypt_data); gtk_dialog_response (GTK_DIALOG(txt_data->diag), GTK_RESPONSE_CANCEL); } static gchar * check_pwd (GtkEntry *entry1, GtkEntry *entry2) { if (gtk_entry_get_text_length (entry1) < 8) { return g_strdup ("Password must be at least 8 characters long\n"); } if (entry2 != NULL && g_strcmp0 (gtk_entry_get_text (entry1), gtk_entry_get_text (entry2)) != 0) { return g_strdup ("Passwords do not match\n"); } return NULL; } static gboolean is_b64_encoded (const gchar *text) { static const guint8 b64_alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; gsize data_len = strlen (text), found = 0, b64_alphabet_len = sizeof(b64_alphabet); for (gint i = 0; i < data_len; i++) { for (gint j = 0; j < b64_alphabet_len; j++) { if (text[i] == b64_alphabet[j] || text[i] == '=' || text[i] == '\n') { found++; break; } } } if (found == data_len) { return TRUE; } return FALSE; } static void show_error_and_cleanup (GtkWidget *diag, gchar *err_msg, CryptData *crypt_data) { show_message_dialog (diag, err_msg, GTK_MESSAGE_ERROR); g_free (err_msg); if (crypt_data != NULL) { gcry_free (crypt_data->iv); gcry_free (crypt_data->salt); gcry_free (crypt_data->derived_key); g_free (crypt_data); } } static void load_text_from_buffer (TxtData *txt_data) { GtkTextIter start, end; gtk_text_buffer_get_bounds (txt_data->txt_buf, &start, &end); txt_data->text_from_buffer = gtk_text_buffer_get_text (txt_data->txt_buf, &start, &end, FALSE); } static gint get_bytes_in_buffer (GtkTextBuffer *buf) { gint total_bytes = 0, done_lines = 0; GtkTextIter iter; gint lines = gtk_text_buffer_get_line_count (buf); while (lines > done_lines) { gtk_text_buffer_get_start_iter (buf, &iter); total_bytes += gtk_text_iter_get_bytes_in_line (&iter); if (total_bytes > SECURE_MEMORY_POOL_SIZE) { return -1; } gtk_text_iter_forward_line (&iter); done_lines++; } return total_bytes + 1; // +1 for the null-terminator } static void prepare_crypto (CryptData *crypt_data) { gint algo = gcry_cipher_map_name ("aes256"); crypt_data->iv = gcry_calloc (AES256_IV_SIZE, 1); crypt_data->salt = gcry_calloc (KDF_SALT_SIZE, 1); crypt_data->derived_key = gcry_calloc_secure (AES256_KEY_SIZE, 1); gcry_cipher_open (&crypt_data->hd, algo, GCRY_CIPHER_MODE_GCM, 0); } static gpg_error_t derive_and_set_cipher_data (TxtData *txt_data, CryptData *crypt_data) { gpg_error_t err = gcry_kdf_derive (gtk_entry_get_text (GTK_ENTRY (txt_data->entry1)), gtk_entry_get_text_length (GTK_ENTRY (txt_data->entry1)) + 1, GCRY_KDF_PBKDF2, GCRY_MD_SHA3_256, crypt_data->salt, KDF_SALT_SIZE, KDF_ITERATIONS, AES256_KEY_SIZE, crypt_data->derived_key); if (err != 0) { g_printerr ("Couldn't derive key\n"); return err; } err = gcry_cipher_setkey (crypt_data->hd, crypt_data->derived_key, AES256_KEY_SIZE); if (err != 0) { g_printerr ("Couldn't set cipher key\n"); return err; } err = gcry_cipher_setiv (crypt_data->hd, crypt_data->iv, AES256_IV_SIZE); if (err != 0) { g_printerr ("Couldn't set cipher iv\n"); return err; } return err; } static void show_dialog_with_data (gchar *data) { GtkBuilder *builder = get_builder_from_path (PARTIAL_PATH_TO_UI_FILE); if (builder == NULL) { return; } GtkWidget *diag = GTK_WIDGET(gtk_builder_get_object (builder, "data_diag")); GtkTextBuffer *text_buf = GTK_TEXT_BUFFER(gtk_builder_get_object(builder,"data_text_buf")); g_object_unref (builder); gtk_widget_show_all (diag); gtk_text_buffer_set_text (text_buf, data, -1); gint result = gtk_dialog_run (GTK_DIALOG(diag)); switch (result) { case GTK_RESPONSE_OK: break; default: break; } gtk_widget_destroy (diag); }GTKCrypto-1.0.2/src/ui/000077500000000000000000000000001421212406300145375ustar00rootroot00000000000000GTKCrypto-1.0.2/src/ui/gtkcrypto.ui000066400000000000000000001413671421212406300171400ustar00rootroot00000000000000 False True False 2 True False vertical True False Cipher center False True 0 True False False True 1 AES256 aes_rbtn_widget True True False True True False True 2 Twofish twofish_rbtn_widget True True False True aes_rbtn False True 3 Serpent serpent_rbtn_widget True True False True aes_rbtn False True 4 Camellia camellia_rbtn_widget True True False True aes_rbtn False True 5 True True 0 True False vertical False True 1 True False vertical True False Mode center False True 0 True False False True 1 CTR ctr_rbtn_widget True True False True True False True 2 CBC cbc_rbtn_widget True True False True ctr_rbtn False True 3 False True 2 main 1 False 10 GTKCrypto center center False True False False True True False vertical 4 True Encrypt File True True True False True 0 Decrypt File True True True False True 1 Sign File True True True False True 2 Verify Signature True True True False True 3 Encrypt Text enctxt_btn True True True False True 4 Decrypt Text dectxt_btn True True True False True 5 Compute Hash True True True False True 6 Compare Hash True True True False True 7 600 False 5 Compute Hash True True dialog mainwin False vertical 2 False end Cancel True True True 4 True True 1 False False 0 True False 4 5 True False MD5 0 0 True False SHA-1 0 1 True False GOST94 0 2 True False SHA-256 0 3 True False SHA3-256 0 4 True False SHA-384 0 5 True False SHA3-384 0 6 True False SHA-512 0 7 True False SHA3-512 0 8 True False WHIRLPOOL 0 9 True True True False edit-copy-symbolic 1 0 True True False edit-copy-symbolic 1 1 True True False edit-copy-symbolic 1 2 True True False edit-copy-symbolic 1 3 True True False edit-copy-symbolic 1 4 True True False edit-copy-symbolic 1 5 True True False edit-copy-symbolic 1 6 True True False edit-copy-symbolic 1 7 True True False edit-copy-symbolic 1 8 True True False edit-copy-symbolic 1 9 True True 1 300 False 4 Decryption Password True center dialog center mainwin False vertical 2 False 4 end Cancel True True True True True 0 OK True True True True True 1 False False 0 True False 4 Type the decryption password. center False True 0 True False vertical True True 255 False Type password... False True 0 Delete encrypted file True True False True False True 1 True False True False True True 0 True False False True 1 False True 2 True True 1 300 False 4 True center dialog center mainwin True False Encryption Password False True True True enc_popmenu False vertical 2 False end Cancel True True True True True 0 OK True True True True True 1 False False 0 True False 4 Type the encryption password. Please note that the password <b>can't</b> be recovered. True center False True 0 True False 4 vertical 5 True True 255 False Type password... False True 0 True True 255 False Retype password... False True 1 True False True False True True 0 True False False True 1 False True 2 True True 1 True False open-menu-symbolic 400 350 False Encrypt/Decrypt Text center True dialog center mainwin False vertical 5 False end Cancel True True True True True 0 OK True True True True True 1 False False 2 True True in True False True True text_buf True True True 0 True False True True False Type Password... password True True 0 True True False Retype Password... password True True 1 False True 2 txt_btn_cancel 600 300 False center True dialog center text_diag False vertical 2 False end OK True True True True True 1 False False 0 True True in True False True True data_text_buf True True True 1 data_diag_ok_btn GTKCrypto-1.0.2/src/verify-signature-cb.c000066400000000000000000000224761421212406300201660ustar00rootroot00000000000000#include #include "common-widgets.h" #include "gtkcrypto.h" #include "gpgme-misc.h" #define MAX_SIG_FILE_SIZE 4096 typedef struct verify_signature_widgets_t { GtkWidget *main_window; GtkWidget *dialog; GtkWidget *cancel_btn; GtkWidget *signed_file_entry; GtkWidget *signature_file_entry; GtkWidget *spinner; GtkWidget *message_label; GThread *thread; struct { gchar *entry1_filename; gchar *entry2_filename; gboolean entry1_changed; gboolean entry2_changed; } entry_data; } VerifyWidgets; typedef struct verify_signature_thread_data_t { GtkWidget *dialog; GtkWidget *spinner; GtkWidget *message_label; gchar *signed_file; gchar *signature_file; } ThreadData; static void select_file_cb (GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkEvent *event, gpointer user_data); static void cancel_btn_clicked_cb (GtkWidget *btn, gpointer user_data); static void entry_changed_cb (GtkWidget *btn, gpointer user_data); static gpointer exec_thread (gpointer user_data); void verify_signature_cb (GtkWidget *btn __attribute__((unused)), gpointer user_data) { VerifyWidgets *verify_widgets = g_new0 (VerifyWidgets, 1); verify_widgets->thread = NULL; verify_widgets->entry_data.entry1_changed = FALSE; verify_widgets->entry_data.entry2_changed = FALSE; verify_widgets->main_window = user_data; verify_widgets->dialog = create_dialog (verify_widgets->main_window, "ver_sig_dialog", "Verify Signature"); verify_widgets->cancel_btn = gtk_dialog_add_button (GTK_DIALOG (verify_widgets->dialog), "Cancel", GTK_RESPONSE_CANCEL); gtk_widget_set_margin_top (verify_widgets->cancel_btn, 10); gtk_widget_set_size_request (verify_widgets->dialog, 600, -1); verify_widgets->signed_file_entry = gtk_entry_new (); gtk_widget_set_name (GTK_WIDGET (verify_widgets->signed_file_entry), "signed_file_entry"); gtk_entry_set_placeholder_text (GTK_ENTRY (verify_widgets->signed_file_entry), "Choose signed file"); gtk_editable_set_editable (GTK_EDITABLE (verify_widgets->signed_file_entry), FALSE); gtk_widget_set_hexpand (verify_widgets->signed_file_entry, TRUE); gtk_entry_set_icon_from_icon_name (GTK_ENTRY (verify_widgets->signed_file_entry), GTK_ENTRY_ICON_SECONDARY, "document-open-symbolic"); verify_widgets->signature_file_entry = gtk_entry_new (); gtk_widget_set_name (GTK_WIDGET (verify_widgets->signature_file_entry), "signature_file_entry"); gtk_entry_set_placeholder_text (GTK_ENTRY (verify_widgets->signature_file_entry), "Choose signature (.sig) file"); gtk_editable_set_editable (GTK_EDITABLE (verify_widgets->signature_file_entry), FALSE); gtk_widget_set_hexpand (verify_widgets->signature_file_entry, TRUE); gtk_entry_set_icon_from_icon_name (GTK_ENTRY (verify_widgets->signature_file_entry), GTK_ENTRY_ICON_SECONDARY, "document-open-symbolic"); verify_widgets->message_label = gtk_label_new (""); verify_widgets->spinner = create_spinner (); GtkWidget *grid = gtk_grid_new (); gtk_grid_set_row_spacing (GTK_GRID (grid), 10); gtk_grid_attach (GTK_GRID (grid), verify_widgets->signed_file_entry, 0, 0, 4, 1); gtk_grid_attach (GTK_GRID (grid), verify_widgets->signature_file_entry, 0, 1, 4, 1); gtk_grid_attach (GTK_GRID (grid), verify_widgets->message_label, 0, 2, 3, 1); gtk_grid_attach_next_to (GTK_GRID (grid), verify_widgets->spinner, verify_widgets->message_label, GTK_POS_RIGHT, 1, 1); gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (verify_widgets->dialog))), grid); g_signal_connect (verify_widgets->signed_file_entry, "icon-press", G_CALLBACK (select_file_cb), verify_widgets); g_signal_connect (verify_widgets->signature_file_entry, "icon-press", G_CALLBACK (select_file_cb), verify_widgets); g_signal_connect (verify_widgets->cancel_btn, "clicked", G_CALLBACK (cancel_btn_clicked_cb), verify_widgets); g_signal_connect (verify_widgets->signed_file_entry, "changed", G_CALLBACK (entry_changed_cb), verify_widgets); g_signal_connect (verify_widgets->signature_file_entry, "changed", G_CALLBACK (entry_changed_cb), verify_widgets); gtk_widget_show_all (verify_widgets->dialog); gint result = gtk_dialog_run (GTK_DIALOG (verify_widgets->dialog)); switch (result) { case GTK_RESPONSE_DELETE_EVENT: if (verify_widgets->thread != NULL) { gpointer status = g_thread_join (verify_widgets->thread); if (status == BAD_SIGNATURE) { show_message_dialog (verify_widgets->main_window, "Bad signature for the given file", GTK_MESSAGE_WARNING); } else if (status == GPGME_ERROR || status == FILE_OPEN_ERROR) { show_message_dialog (verify_widgets->main_window, "An error occurred while checking the signature", GTK_MESSAGE_WARNING); } else { if (status == SIGNATURE_OK) { show_message_dialog (verify_widgets->main_window, "Signature OK for the given file", GTK_MESSAGE_INFO); } else { show_message_dialog (verify_widgets->main_window, "Signature OK for the given file but the key is not certified with a trusted signature", GTK_MESSAGE_INFO); } } } gtk_widget_destroy (verify_widgets->dialog); g_free (verify_widgets->entry_data.entry1_filename); g_free (verify_widgets->entry_data.entry2_filename); g_free (verify_widgets); break; default: break; } } static void cancel_btn_clicked_cb (GtkWidget *btn __attribute__((unused)), gpointer user_data) { VerifyWidgets *verify_widgets = user_data; gtk_widget_destroy (verify_widgets->dialog); g_free (verify_widgets); } static void select_file_cb (GtkEntry *entry, GtkEntryIconPosition icon_pos __attribute__((unused)), GdkEvent *event __attribute__((unused)), gpointer user_data) { VerifyWidgets *verify_widgets = user_data; GSList *list = choose_file (verify_widgets->main_window, "Choose file", FALSE); gchar *filename = get_filename_from_list (list); if (filename == NULL) { return; } if (g_strcmp0 (gtk_widget_get_name (GTK_WIDGET (entry)), "signed_file_entry") == 0) { verify_widgets->entry_data.entry1_filename = g_strdup (filename); } else { verify_widgets->entry_data.entry2_filename = g_strdup (filename); } gtk_entry_set_text (entry, filename); g_free (filename); } static void entry_changed_cb (GtkWidget *btn, gpointer user_data) { VerifyWidgets *verify_widgets = user_data; if (g_strcmp0 (gtk_widget_get_name (btn), "signed_file_entry") == 0) { verify_widgets->entry_data.entry1_changed = TRUE; } else { verify_widgets->entry_data.entry2_changed = TRUE; } if (verify_widgets->entry_data.entry1_changed == TRUE && verify_widgets->entry_data.entry2_changed == TRUE) { if (get_file_size (verify_widgets->entry_data.entry2_filename) > MAX_SIG_FILE_SIZE) { show_message_dialog (verify_widgets->main_window, "The chosen file is not a detached signature.", GTK_MESSAGE_ERROR); gtk_dialog_response (GTK_DIALOG (verify_widgets->dialog), GTK_RESPONSE_DELETE_EVENT); } else { ThreadData *thread_data = g_new0 (ThreadData, 1); thread_data->dialog = verify_widgets->dialog; thread_data->spinner = verify_widgets->spinner; thread_data->message_label = verify_widgets->message_label; thread_data->signed_file = verify_widgets->entry_data.entry1_filename; thread_data->signature_file = verify_widgets->entry_data.entry2_filename; gtk_widget_show (thread_data->spinner); start_spinner (thread_data->spinner); if (gtk_widget_get_sensitive (verify_widgets->signed_file_entry) != FALSE) { gtk_widget_set_sensitive (verify_widgets->signed_file_entry, FALSE); } if (gtk_widget_get_sensitive (verify_widgets->signature_file_entry) != FALSE) { gtk_widget_set_sensitive (verify_widgets->signature_file_entry, FALSE); } verify_widgets->thread = g_thread_new (NULL, exec_thread, thread_data); } } } #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wreturn-type" static gpointer exec_thread (gpointer user_data) { ThreadData *data = user_data; set_label_message (data->message_label, "Checking signature..."); gpointer status = verify_signature (data->signed_file, data->signature_file); gtk_dialog_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_DELETE_EVENT); g_free (data); g_thread_exit (status); } //-V591 #pragma GCC diagnostic pop