SVNからのミラー
諏訪子 <suwako@076.moe>、2026-01-21 04:47
コミット 81a90a99e1cf4c79ec1df1258b9ca4ad3fc7b5e1
・ファイルを見る
47個のファイル、+2619 -0
追加
CHANGELOG.md
| @@ -0,0 +1,15 @@ | ||
| 1 | +# 1.1.1 (2025年03月13日) | |
| 2 | +* OTPで、秘密鍵を自動的に大文字にする様に | |
| 3 | + | |
| 4 | +# 1.1.0 (2024年12月17日) | |
| 5 | +* パスワード表示で、「OpenPGP」かどうかの確認の追加 | |
| 6 | +* 侵害されたパスワードの確認の追加 | |
| 7 | +* 複数サイトで同じパスワードを利用かどうか、パスワードの長さ、又はパスワードの強さの確認 | |
| 8 | +* パスワードを表示・非表示にする機能性の追加(デフォルトは非表示) | |
| 9 | +* ワンタイムパスワード(OTP)の場合、自動的に更新する様に | |
| 10 | +* アプリケーションアイコンの追加 | |
| 11 | +* ライトモードの追加 | |
| 12 | +* コンフィグファイルの追加 | |
| 13 | + | |
| 14 | +# 1.0.0 (2024年09月24日) | |
| 15 | +* 開始 |
追加
LICENSE.txt
| @@ -0,0 +1,13 @@ | ||
| 1 | +Copyright © 2018-2024 by 076.moe | |
| 2 | + | |
| 3 | +Permission to use, copy, modify, and/or distribute this software for any | |
| 4 | +purpose with or without fee is hereby granted, provided that the above | |
| 5 | +copyright notice and this permission notice appear in all copies. | |
| 6 | + | |
| 7 | +THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD | |
| 8 | +TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 9 | +FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR | |
| 10 | +CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, | |
| 11 | +DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | |
| 12 | +ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | |
| 13 | +SOFTWARE. |
追加
Makefile
| @@ -0,0 +1,126 @@ | ||
| 1 | +UNAME_S != uname -s | |
| 2 | +UNAME_M != uname -m | |
| 3 | +OS = ${UNAME_S} | |
| 4 | +ARCH = ${UNAME_M} | |
| 5 | + | |
| 6 | +.if ${UNAME_S} == "OpenBSD" | |
| 7 | +OS = openbsd | |
| 8 | +.elif ${UNAME_S} == "NetBSD" | |
| 9 | +OS = netbsd | |
| 10 | +.elif ${UNAME_S} == "FreeBSD" | |
| 11 | +OS = freebsd | |
| 12 | +.elif ${UNAME_S} == "Dragonfly" | |
| 13 | +OS = dragonfly | |
| 14 | +.elif ${UNAME_S} == "Linux" | |
| 15 | +OS = linux | |
| 16 | +.endif | |
| 17 | + | |
| 18 | +.if ${UNAME_M} == "x86_64" | |
| 19 | +ARCH = amd64 | |
| 20 | +.endif | |
| 21 | + | |
| 22 | +NAME != cat main.cc | grep "const char \*sofname" | awk '{print $$5}' |\ | |
| 23 | + sed "s/\"//g" | sed "s/;//" | |
| 24 | +VERSION != cat main.cc | grep "const char \*version" | awk '{print $$5}' |\ | |
| 25 | + sed "s/\"//g" | sed "s/;//" | |
| 26 | + | |
| 27 | +PREFIX = /usr/local | |
| 28 | +.if ${OS} == "linux" | |
| 29 | +PREFIX = /usr | |
| 30 | +.endif | |
| 31 | + | |
| 32 | +CC = c++ | |
| 33 | +FILES = main.cc src/*.cc | |
| 34 | + | |
| 35 | +.if ${OS} == "openbsd" | |
| 36 | +DEPS = pkg_add fltk gpgme gpgme-qt gnupg pinentry | |
| 37 | +.elif ${OS} == "netbsd" | |
| 38 | +DEPS = pkgin install fltk gpgme gpgmepp gnupg pinentry pinentry-fltk | |
| 39 | +.elif ${OS} == "freebsd" | |
| 40 | +DEPS = pkg install fltk gpgme gpgme-cpp gnupg pinentry pinentry-fltk | |
| 41 | +.elif ${OS} == "linux" | |
| 42 | +DEPS = xbps-install fltk fltk-devel gpgme gpgmepp gpgmepp-devel gnupg pinentry bmake | |
| 43 | +.endif | |
| 44 | + | |
| 45 | +CFLAGS = -Wall -Wextra -Wno-non-c-typedef-for-linkage -Wno-unused-parameter\ | |
| 46 | + -Wno-cast-function-type\ | |
| 47 | + -I/usr/include -L/usr/lib | |
| 48 | +.if ${OS} == "freebsd" || ${OS} == "openbsd" || ${OS} == "netbsd" || ${OS} == "dragonfly | |
| 49 | +CFLAGS += -I/usr/local/include -L/usr/local/lib | |
| 50 | +.endif | |
| 51 | +.if ${OS} == "netbsd" | |
| 52 | +CFLAGS += -I/usr/X11R7/include -L/usr/X11R7/lib -I/usr/pkg/include -L/usr/pkg/lib | |
| 53 | +.elif ${OS} == "openbsd" | |
| 54 | +CFLAGS += -I/usr/X11R6/include -L/usr/X11R6/lib | |
| 55 | +.endif | |
| 56 | + | |
| 57 | +LDFLAGS = -lfltk_images -lfltk -lX11 -lassuan -lgpgmepp -lgpgme -lcrypto -lgpg-error | |
| 58 | + | |
| 59 | +.if ${OS} == "openbsd" | |
| 60 | +LDFLAGS += -lc++abi -lpthread -lm -lc\ | |
| 61 | + -lXcursor -lXfixes -lXext -lXft -lfontconfig -lXinerama -lXdmcp -lXau\ | |
| 62 | + -lz -lxcb -lXrender -lexpat -lfreetype -lc++ -lintl -liconv -lpng -ljpeg | |
| 63 | +.elif ${OS} == "freebsd" | |
| 64 | +LDFLAGS += -lcxxrt -lm -lXrender -lXcursor -lXfixes -lXext -lXft -lfontconfig\ | |
| 65 | + -lXinerama -lthr -lz -lxcb -lfreetype -lexpat -lXau -lXdmcp\ | |
| 66 | + -lbz2 -lbrotlidec -lbrotlicommon -lc++ -lgcc -lc -lgpgme -lassuan\ | |
| 67 | + -lintl -lpng16 | |
| 68 | +.elif ${OS} == "netbsd" | |
| 69 | +LDFLAGS += -lstdc++ -lpthread -lm -lc -lXft -lxcb -lfontconfig -lfreetype\ | |
| 70 | + -lXau -lXdmcp -lXcursor -lXrandr -lXext -lXrender -lXfixes -lXinerama -lX11\ | |
| 71 | + -lexpat -lz -lbz2 -lgcc -lassuan -lintl | |
| 72 | +.elif ${OS} == "linux" | |
| 73 | +LDFLAGS += -lstdc++ -lgcc -lc -lXft -lXext -lXrender -lfontconfig -lXinerama\ | |
| 74 | + -lxcb -lfreetype -lpng16 -lz -lexpat -lXau -lXdmcp -lbz2\ | |
| 75 | + -lbrotlidec -lbrotlicommon -lassuan | |
| 76 | +.endif | |
| 77 | + | |
| 78 | +all: | |
| 79 | + ${CC} -O3 ${CFLAGS} -o ${NAME}\ | |
| 80 | + ${FILES} -static ${LDFLAGS} | |
| 81 | + strip ${NAME} | |
| 82 | + | |
| 83 | +depend: | |
| 84 | + ${DEPS} | |
| 85 | + | |
| 86 | +debug: | |
| 87 | + ${CC} -g ${CFLAGS} -o ${NAME} ${FILES} ${LDFLAGS} | |
| 88 | + | |
| 89 | +clean: | |
| 90 | + rm -rf ${NAME} | |
| 91 | + | |
| 92 | +dist: | |
| 93 | + mkdir -p ${NAME}-${VERSION} release/src release/desktop | |
| 94 | + cp -R LICENSE.txt Makefile README.md CHANGELOG.md logo.png\ | |
| 95 | + main.* src icons ${NAME}.desktop ${NAME}-${VERSION} | |
| 96 | + tar zcfv release/src/${NAME}-${VERSION}.tar.gz ${NAME}-${VERSION} | |
| 97 | + cp ${NAME}.desktop release/desktop | |
| 98 | + rm -rf ${NAME}-${VERSION} | |
| 99 | + | |
| 100 | +release: | |
| 101 | + mkdir -p release/bin/${VERSION}/${OS}/${ARCH} | |
| 102 | + ${CC} -O3 ${CFLAGS} -o release/bin/${VERSION}/${OS}/${ARCH}/${NAME} ${FILES}\ | |
| 103 | + -static ${LDFLAGS} | |
| 104 | + strip release/bin/${VERSION}/${OS}/${ARCH}/${NAME} | |
| 105 | + | |
| 106 | +publish: | |
| 107 | + rsync -rtvzP release/bin/${VERSION} 192.168.0.143:/zroot/repo/bin/${NAME} | |
| 108 | + rsync -rtvzP release/src/* 192.168.0.143:/zroot/repo/src/${NAME} | |
| 109 | + rsync -rtvzP release/desktop/* 192.168.0.143:/zroot/repo/desktop | |
| 110 | + rsync -rtvzP release/icons/* 192.168.0.143:/zroot/repo/icons | |
| 111 | + | |
| 112 | +install: | |
| 113 | + mkdir -p ${DESTDIR}${PREFIX}/bin ${DESTDIR}${PREFIX}/share/applications | |
| 114 | + cp -f ${NAME} ${DESTDIR}${PREFIX}/bin | |
| 115 | + cp -f ${NAME}.desktop ${DESTDIR}${PREFIX}/share/applications | |
| 116 | +.if ${OS} == "linux" | |
| 117 | + sed -i 's/\/local//' ${DESTDIR}${PREFIX}/share/applications/${NAME}.desktop | |
| 118 | +.endif | |
| 119 | + cp -rf icons/076 ${DESTDIR}${PREFIX}/share/icons | |
| 120 | + chmod 755 ${DESTDIR}${PREFIX}/bin/${NAME} | |
| 121 | + | |
| 122 | +uninstall: | |
| 123 | + rm -f ${DESTDIR}${PREFIX}/share/applications/${NAME}.desktop | |
| 124 | + rm -f ${DESTDIR}${PREFIX}/bin/${NAME} | |
| 125 | + | |
| 126 | +.PHONY: all debug clean dist release publish install uninstall |
追加
README.md
| @@ -0,0 +1,25 @@ | ||
| 1 | +# simpas | |
| 2 | +シンプルなパスワードマネージャー Simple Password Manager\ | |
| 3 | +GUI版のsp | |
| 4 | + | |
| 5 | +## インストールする方法 | Installation | |
| 6 | +### BSD | |
| 7 | +```sh | |
| 8 | +doas make depends | |
| 9 | +make | |
| 10 | +doas make install | |
| 11 | +``` | |
| 12 | + | |
| 13 | +### Void Linux | |
| 14 | +```sh | |
| 15 | +sudo bmake depends | |
| 16 | +bmake | |
| 17 | +sudo bmake install | |
| 18 | +``` | |
| 19 | + | |
| 20 | +### Alpine Linux | |
| 21 | +```sh | |
| 22 | +sudo apk add fltk fltk-dev gpgme gpgmepp gnupg pinentry bmake | |
| 23 | +bmake | |
| 24 | +sudo bmake install | |
| 25 | +``` |
バイナリファイル
バイナリファイル
バイナリファイル
バイナリファイル
バイナリファイル
バイナリファイル
バイナリファイル
バイナリファイル
バイナリファイル
バイナリファイル
バイナリファイル
バイナリファイル
バイナリファイル
バイナリファイル
| @@ -0,0 +1,75 @@ | ||
| 1 | +[Icon Theme] | |
| 2 | +Name=076 Icons | |
| 3 | +Comment=076 Icons | |
| 4 | +Inherits=default | |
| 5 | +Directories=128x128,18x18,24x24,32x32,48x48,64x64,8x8,16x16,22x22,256x256,42x42,512x512,84x84,96x96 | |
| 6 | + | |
| 7 | +[128x128] | |
| 8 | +Size=128 | |
| 9 | +Context=Icons | |
| 10 | +Type=Fixed | |
| 11 | + | |
| 12 | +[18x18] | |
| 13 | +Size=18 | |
| 14 | +Context=Icons | |
| 15 | +Type=Fixed | |
| 16 | + | |
| 17 | +[24x24] | |
| 18 | +Size=24 | |
| 19 | +Context=Icons | |
| 20 | +Type=Fixed | |
| 21 | + | |
| 22 | +[32x32] | |
| 23 | +Size=32 | |
| 24 | +Context=Icons | |
| 25 | +Type=Fixed | |
| 26 | + | |
| 27 | +[48x48] | |
| 28 | +Size=48 | |
| 29 | +Context=Icons | |
| 30 | +Type=Fixed | |
| 31 | + | |
| 32 | +[64x64] | |
| 33 | +Size=64 | |
| 34 | +Context=Icons | |
| 35 | +Type=Fixed | |
| 36 | + | |
| 37 | +[8x8] | |
| 38 | +Size=8 | |
| 39 | +Context=Icons | |
| 40 | +Type=Fixed | |
| 41 | + | |
| 42 | +[16x16] | |
| 43 | +Size=16 | |
| 44 | +Context=Icons | |
| 45 | +Type=Fixed | |
| 46 | + | |
| 47 | +[22x22] | |
| 48 | +Size=22 | |
| 49 | +Context=Icons | |
| 50 | +Type=Fixed | |
| 51 | + | |
| 52 | +[256x256] | |
| 53 | +Size=256 | |
| 54 | +Context=Icons | |
| 55 | +Type=Fixed | |
| 56 | + | |
| 57 | +[42x42] | |
| 58 | +Size=42 | |
| 59 | +Context=Icons | |
| 60 | +Type=Fixed | |
| 61 | + | |
| 62 | +[512x512] | |
| 63 | +Size=512 | |
| 64 | +Context=Icons | |
| 65 | +Type=Fixed | |
| 66 | + | |
| 67 | +[84x84] | |
| 68 | +Size=84 | |
| 69 | +Context=Icons | |
| 70 | +Type=Fixed | |
| 71 | + | |
| 72 | +[96x96] | |
| 73 | +Size=96 | |
| 74 | +Context=Icons | |
| 75 | +Type=Fixed |
追加
logo.png
バイナリファイル
追加
main.cc
| @@ -0,0 +1,362 @@ | ||
| 1 | +#include "src/addpass.hh" | |
| 2 | +#include "src/delpass.hh" | |
| 3 | +#include "src/editpass.hh" | |
| 4 | +#include "src/genpass.hh" | |
| 5 | +#include "src/initpass.hh" | |
| 6 | +#include "src/showpass.hh" | |
| 7 | +#include "src/vulnpass.hh" | |
| 8 | +#include "src/chkpass.hh" | |
| 9 | +#include "src/common.hh" | |
| 10 | +#include "main.hh" | |
| 11 | + | |
| 12 | +#undef Status | |
| 13 | +#undef None | |
| 14 | +#include <FL/Fl.H> | |
| 15 | +#include <FL/Fl_Box.H> | |
| 16 | +#include <FL/Fl_Widget.H> | |
| 17 | +#include <FL/Fl_Window.H> | |
| 18 | +#include <FL/Fl_Select_Browser.H> | |
| 19 | +#include <FL/Fl_Text_Display.H> | |
| 20 | +#include <FL/Fl_Text_Buffer.H> | |
| 21 | +#include <FL/Fl_Button.H> | |
| 22 | +#include <FL/Fl_Check_Button.H> | |
| 23 | +#include <FL/Fl_Input.H> | |
| 24 | +#include <FL/Fl_Secret_Input.H> | |
| 25 | +#include <FL/Fl_Hold_Browser.H> | |
| 26 | +#include <FL/Fl_Copy_Surface.H> | |
| 27 | +#include <FL/Fl_PNG_Image.H> | |
| 28 | + | |
| 29 | +#include <dirent.h> | |
| 30 | +#include <sys/stat.h> | |
| 31 | + | |
| 32 | +#include <string> | |
| 33 | +#include <vector> | |
| 34 | + | |
| 35 | +Fl_Select_Browser *browser = nullptr; | |
| 36 | +Fl_Text_Display *textview = nullptr; | |
| 37 | +Fl_Text_Buffer *textbuf = nullptr; | |
| 38 | +Fl_Input *searchfield = nullptr; | |
| 39 | +Fl_Check_Button *hidechk = nullptr; | |
| 40 | +Fl_Button *showbtn = nullptr; | |
| 41 | + | |
| 42 | +Addpass a; | |
| 43 | +Chkpass c; | |
| 44 | +Delpass d; | |
| 45 | +Editpass e; | |
| 46 | +Genpass g; | |
| 47 | +Initpass i; | |
| 48 | +Showpass s; | |
| 49 | +Vulnpass v; | |
| 50 | + | |
| 51 | +const char *sofname = "simpas"; | |
| 52 | +const char *intname = "SimPas"; | |
| 53 | +const char *version = "1.1.1"; | |
| 54 | +const char *basedof = "sp-1.5.1"; | |
| 55 | + | |
| 56 | +std::vector<std::string> fullpaths; | |
| 57 | +std::vector<std::string> dispaths; | |
| 58 | +std::vector<std::string> filterpaths; | |
| 59 | +int browseId; | |
| 60 | +bool isPassHidden = true; | |
| 61 | +std::string realpass = ""; | |
| 62 | + | |
| 63 | +void browse(std::string &path, bool isNew) { | |
| 64 | + std::string cont = s.exec(path.c_str(), false); | |
| 65 | + realpass = cont; | |
| 66 | + | |
| 67 | + if (isNew) browseId = browser->size(); | |
| 68 | + browser->value(browseId); | |
| 69 | + | |
| 70 | + if (!cont.empty()) { | |
| 71 | + if (isPassHidden) { | |
| 72 | + std::string lang = Common::getlang(); | |
| 73 | + if (lang.compare(0, 2, "en") == 0) { | |
| 74 | + textbuf->text("(Hidden, please click the \"show\" button to reveal)"); | |
| 75 | + } else { | |
| 76 | + textbuf->text("(非表示、「表示」ボタンをクリックして確認して下さい)"); | |
| 77 | + } | |
| 78 | + showbtn->activate(); | |
| 79 | + showbtn->label((Common::getlang().compare(0, 2, "en") == 0) ? | |
| 80 | + "Show password" : "パスワードの表示"); | |
| 81 | + } else { | |
| 82 | + textbuf->text(cont.c_str()); | |
| 83 | + showbtn->label((Common::getlang().compare(0, 2, "en") == 0) ? | |
| 84 | + "Hide password" : "パスワードを隠す"); | |
| 85 | + showbtn->activate();} | |
| 86 | + Editpass::setFile(path); | |
| 87 | + Delpass::setFile(path); | |
| 88 | + d.btn->activate(); | |
| 89 | + e.btn->activate(); | |
| 90 | + } | |
| 91 | +} | |
| 92 | + | |
| 93 | +void hide_cb(Fl_Widget *w, void *) { | |
| 94 | + isPassHidden = ((Fl_Check_Button *)w)->value(); | |
| 95 | + int idx = browser->value(); | |
| 96 | + | |
| 97 | + if (isPassHidden && idx > 0) { | |
| 98 | + showbtn->activate(); | |
| 99 | + showbtn->label((Common::getlang().compare(0, 2, "en") == 0) ? | |
| 100 | + "Show password" : "パスワードの表示"); | |
| 101 | + } else { | |
| 102 | + showbtn->deactivate(); | |
| 103 | + showbtn->label((Common::getlang().compare(0, 2, "en") == 0) ? | |
| 104 | + "Hide password" : "パスワードを隠す"); | |
| 105 | + } | |
| 106 | + | |
| 107 | + showbtn->label((Common::getlang().compare(0, 2, "en") == 0) ? | |
| 108 | + "Show password" : "パスワードの表示"); | |
| 109 | + | |
| 110 | + if (idx > 0) { | |
| 111 | + std::string path = filterpaths[idx - 1]; | |
| 112 | + browse(path, false); | |
| 113 | + } | |
| 114 | +} | |
| 115 | + | |
| 116 | +void clearpaths(bool isReset, std::string &path) { | |
| 117 | + fullpaths.clear(); | |
| 118 | + dispaths.clear(); | |
| 119 | + if (isReset) { | |
| 120 | + std::string mockpath = ""; | |
| 121 | + Editpass::setFile(mockpath); | |
| 122 | + Delpass::setFile(mockpath); | |
| 123 | + d.btn->deactivate(); | |
| 124 | + e.btn->deactivate(); | |
| 125 | + } | |
| 126 | +} | |
| 127 | + | |
| 128 | +void updatelist() { | |
| 129 | + browser->clear(); | |
| 130 | + filterpaths.clear(); | |
| 131 | + std::string searchtxt = searchfield->value(); | |
| 132 | + for (size_t i = 0; i < dispaths.size(); ++i) { | |
| 133 | + if (dispaths[i].find(searchtxt) != std::string::npos) { | |
| 134 | + browser->add(dispaths[i].c_str()); | |
| 135 | + filterpaths.push_back(fullpaths[i]); | |
| 136 | + } | |
| 137 | + } | |
| 138 | + textbuf->text(""); | |
| 139 | +} | |
| 140 | + | |
| 141 | +void search_cb(Fl_Widget *, void *) { | |
| 142 | + std::string mockpath = ""; | |
| 143 | + Editpass::setFile(mockpath); | |
| 144 | + Delpass::setFile(mockpath); | |
| 145 | + d.btn->deactivate(); | |
| 146 | + e.btn->deactivate(); | |
| 147 | + updatelist(); | |
| 148 | +} | |
| 149 | + | |
| 150 | +void copy_cb(Fl_Widget *, void *) { | |
| 151 | + if (!realpass.empty()) { | |
| 152 | + Fl::copy(realpass.c_str(), realpass.length(), 1, Fl::clipboard_plain_text); | |
| 153 | + } else { | |
| 154 | + Fl::copy("", 0, 1, Fl::clipboard_plain_text); | |
| 155 | + } | |
| 156 | +} | |
| 157 | + | |
| 158 | +void browser_cb(Fl_Widget *w, void *) { | |
| 159 | + (void)w; | |
| 160 | + int idx = browser->value(); | |
| 161 | + if (idx == 0) return; | |
| 162 | + browseId = idx; | |
| 163 | + | |
| 164 | + std::string path = filterpaths[idx - 1]; | |
| 165 | + browse(path, false); | |
| 166 | +} | |
| 167 | + | |
| 168 | +void show_cb(Fl_Widget *, void *) { | |
| 169 | + int idx = browser->value(); | |
| 170 | + if (idx == 0) return; | |
| 171 | + std::string path = filterpaths[idx - 1]; | |
| 172 | + | |
| 173 | + if (isPassHidden) { | |
| 174 | + std::string cont = s.exec(path.c_str(), false); | |
| 175 | + realpass = cont; | |
| 176 | + textbuf->text(cont.c_str()); | |
| 177 | + | |
| 178 | + std::string lang = Common::getlang(); | |
| 179 | + if (lang.compare(0, 2, "en") == 0) { | |
| 180 | + showbtn->label("Hide password"); | |
| 181 | + } else { | |
| 182 | + showbtn->label("パスワードを隠す"); | |
| 183 | + } | |
| 184 | + isPassHidden = false; | |
| 185 | + } else { | |
| 186 | + std::string lang = Common::getlang(); | |
| 187 | + if (lang.compare(0, 2, "en") == 0) { | |
| 188 | + textbuf->text("(Hidden, please click the \"show\" button to reveal)"); | |
| 189 | + showbtn->label("Show password"); | |
| 190 | + } else { | |
| 191 | + textbuf->text("(非表示、「表示」ボタンをクリックして確認して下さい)"); | |
| 192 | + showbtn->label("パスワードの表示"); | |
| 193 | + } | |
| 194 | + isPassHidden = true; | |
| 195 | + } | |
| 196 | +} | |
| 197 | + | |
| 198 | +void scandir(const std::string &dpath, const std::string &rpath, | |
| 199 | + std::vector<std::string> &fpaths) { | |
| 200 | + DIR *dir = opendir(dpath.c_str()); | |
| 201 | + if (!dir) return; | |
| 202 | + | |
| 203 | + struct dirent *entry; | |
| 204 | + while ((entry = readdir(dir)) != nullptr) { | |
| 205 | + std::string name = entry->d_name; | |
| 206 | + if (name == "." || name == ".." || name == ".gpg-id") continue; | |
| 207 | + | |
| 208 | + std::string fpath = std::string(dpath) + "/" + name; | |
| 209 | + struct stat s; | |
| 210 | + if (stat(fpath.c_str(), &s) != 0) { | |
| 211 | + closedir(dir); | |
| 212 | + return; | |
| 213 | + } | |
| 214 | + | |
| 215 | + if (S_ISDIR(s.st_mode)) { | |
| 216 | + scandir(fpath, rpath, fpaths); | |
| 217 | + } else if (name.find(".gpg") != std::string::npos) { | |
| 218 | + std::string rel = fpath.substr(rpath.size() + 1); | |
| 219 | + fpaths.push_back(rel); | |
| 220 | + fullpaths.push_back(fpath); | |
| 221 | + | |
| 222 | + std::string disname = rel.substr(0, rel.rfind(".gpg")); | |
| 223 | + dispaths.push_back(disname); | |
| 224 | + } | |
| 225 | + } | |
| 226 | + | |
| 227 | + closedir(dir); | |
| 228 | +} | |
| 229 | + | |
| 230 | +void init_cb(Fl_Widget *w, void *data) { | |
| 231 | + i.exec(i.gpgid->value()); | |
| 232 | + i.btn->deactivate(); | |
| 233 | + ((Initpass *)data)->cancel_cb(w, data); | |
| 234 | +} | |
| 235 | + | |
| 236 | +void init_dialog_cb(Fl_Widget *w, void *) { | |
| 237 | + (void)w; | |
| 238 | + std::string lang = Common::getlang(); | |
| 239 | + Fl_Window *dialog = new Fl_Window(450, 120, | |
| 240 | + (lang.compare(0, 2, "en") == 0 ? | |
| 241 | + "Initialize password" : "パスワードの初期設定")); | |
| 242 | + | |
| 243 | + i.gpgid = new Fl_Input(90, 20, 300, 30, | |
| 244 | + (lang.compare(0, 2, "en") == 0 ? "GPG secret key:" : "gpg秘密鍵:")); | |
| 245 | + dialog->add(i.gpgid); | |
| 246 | + | |
| 247 | + Fl_Button *startbtn = new Fl_Button(185, 70, 80, 30, | |
| 248 | + (lang.compare(0, 2, "en") == 0 ? "Start" : "開始")); | |
| 249 | + | |
| 250 | + startbtn->callback(init_cb, dialog); | |
| 251 | + | |
| 252 | + dialog->add(startbtn); | |
| 253 | + | |
| 254 | + dialog->end(); | |
| 255 | + dialog->set_modal(); | |
| 256 | + dialog->show(); | |
| 257 | +} | |
| 258 | + | |
| 259 | +void set_dark_theme() { | |
| 260 | + Fl::background(35, 32, 35); | |
| 261 | + Fl::background2(68, 59, 68); | |
| 262 | + Fl::foreground(252, 252, 252); | |
| 263 | +} | |
| 264 | + | |
| 265 | +int main(int argc, char **argv) { | |
| 266 | + std::string lang = Common::getlang(); | |
| 267 | + std::string windowtit = std::string(intname) + " " + version; | |
| 268 | + Fl_Window *window = new Fl_Window(790, 740, windowtit.c_str()); | |
| 269 | + | |
| 270 | + set_dark_theme(); | |
| 271 | + | |
| 272 | +#if defined(__linux) | |
| 273 | + const char *iconPath = "/usr/share/icons/076/512x512/simpas.png"; | |
| 274 | +#else | |
| 275 | + const char *iconPath = "/usr/local/share/icons/076/512x512/simpas.png"; | |
| 276 | +#endif | |
| 277 | + | |
| 278 | + Fl_PNG_Image *icon = new Fl_PNG_Image(iconPath); | |
| 279 | + | |
| 280 | + window->icon(icon); | |
| 281 | + | |
| 282 | + searchfield = new Fl_Input( | |
| 283 | + (lang.compare(0, 2, "en") == 0 ? 70 : 50), 10, | |
| 284 | + (lang.compare(0, 2, "en") == 0 ? 710 : 730), 30, | |
| 285 | + (lang.compare(0, 2, "en") == 0 ? "Search:" : "検索:")); | |
| 286 | + searchfield->callback(search_cb); | |
| 287 | + | |
| 288 | + browser = new Fl_Select_Browser(10, 50, 380, 500); | |
| 289 | + textview = new Fl_Text_Display(400, 50, 380, 500); | |
| 290 | + textbuf = new Fl_Text_Buffer(); | |
| 291 | + textview->buffer(textbuf); | |
| 292 | + | |
| 293 | + browser->callback(browser_cb); | |
| 294 | + | |
| 295 | + Fl_Button *copybtn = new Fl_Button(400, 600, 150, 30, | |
| 296 | + (lang.compare(0, 2, "en") == 0 ? "Copy password" : "パスワードのコピー")); | |
| 297 | + copybtn->callback(copy_cb); | |
| 298 | + | |
| 299 | + a.btn = new Fl_Button(10, 560, 150, 30, | |
| 300 | + (lang.compare(0, 2, "en") == 0 ? "Add password" : "パスワードの追加")); | |
| 301 | + a.btn->callback(a.dialog_cb); | |
| 302 | + | |
| 303 | + d.btn = new Fl_Button(10, 600, 150, 30, | |
| 304 | + (lang.compare(0, 2, "en") == 0 ? "Delete password" : "パスワードの削除")); | |
| 305 | + d.btn->deactivate(); | |
| 306 | + d.btn->callback(d.dialog_cb); | |
| 307 | + | |
| 308 | + e.btn = new Fl_Button(400, 560, 150, 30, | |
| 309 | + (lang.compare(0, 2, "en") == 0 ? "Edit password" : "パスワードの編集")); | |
| 310 | + e.btn->deactivate(); | |
| 311 | + e.btn->callback(e.dialog_cb); | |
| 312 | + | |
| 313 | + hidechk = new Fl_Check_Button(560, 560, 150, 30, | |
| 314 | + (lang.compare(0, 2, "en") == 0 ? "Hide password" : "パスワードを隠す")); | |
| 315 | + hidechk->set(); | |
| 316 | + hidechk->callback(hide_cb); | |
| 317 | + | |
| 318 | + showbtn = new Fl_Button(560, 600, 150, 30, | |
| 319 | + (lang.compare(0, 2, "en") == 0 ? "Show password" : "パスワードの表示")); | |
| 320 | + showbtn->deactivate(); | |
| 321 | + showbtn->callback(show_cb); | |
| 322 | + | |
| 323 | + g.btn = new Fl_Button(10, 640, 150, 30, | |
| 324 | + (lang.compare(0, 2, "en") == 0 ? "Generate password" : "パスワードの作成")); | |
| 325 | + g.btn->callback(g.dialog_cb); | |
| 326 | + | |
| 327 | + i.btn = new Fl_Button(10, 680, 150, 30, | |
| 328 | + (lang.compare(0, 2, "en") == 0 ? | |
| 329 | + "Initialize password" : | |
| 330 | + "パスワードの初期設定")); | |
| 331 | + | |
| 332 | + v.btn = new Fl_Button(170, 560, 200, 30, | |
| 333 | + (lang.compare(0, 2, "en") == 0 ? "Check for breach" : "漏洩されたかの確認")); | |
| 334 | + v.btn->callback(v.dialog_cb); | |
| 335 | + | |
| 336 | + c.btn = new Fl_Button(170, 600, 200, 30, | |
| 337 | + (lang.compare(0, 2, "en") == 0 ? | |
| 338 | + "Check for unsafe passwords" : "不安定的なパスワードの確認")); | |
| 339 | + c.btn->callback(c.dialog_cb); | |
| 340 | + | |
| 341 | + std::string gpgidpath = Common::getbasedir(true) + ".gpg-id"; | |
| 342 | + | |
| 343 | + struct stat buf; | |
| 344 | + if (stat(gpgidpath.c_str(), &buf) == 0) { | |
| 345 | + i.btn->deactivate(); | |
| 346 | + } | |
| 347 | + i.btn->callback(init_dialog_cb); | |
| 348 | + | |
| 349 | + std::string bothver = windowtit + " (" + std::string(basedof) + ")"; | |
| 350 | + Fl_Box *versionlabel = new Fl_Box(FL_NO_BOX, 620, 700, 160, 30, bothver.c_str()); | |
| 351 | + versionlabel->align(FL_ALIGN_RIGHT | FL_ALIGN_INSIDE); | |
| 352 | + | |
| 353 | + std::vector<std::string> fpaths; | |
| 354 | + std::string rdir = Common::getbasedir(false); | |
| 355 | + scandir(rdir, rdir, fpaths); | |
| 356 | + updatelist(); | |
| 357 | + | |
| 358 | + window->end(); | |
| 359 | + window->show(argc, argv); | |
| 360 | + | |
| 361 | + return Fl::run(); | |
| 362 | +} |
追加
main.hh
| @@ -0,0 +1,24 @@ | ||
| 1 | +#ifndef MAIN_HH | |
| 2 | +#define MAIN_HH | |
| 3 | + | |
| 4 | +#include <vector> | |
| 5 | +#include <string> | |
| 6 | + | |
| 7 | +extern std::vector<std::string> fullpaths; | |
| 8 | +extern std::vector<std::string> dispaths; | |
| 9 | +extern int browseId; | |
| 10 | +extern bool isPassHidden; | |
| 11 | +extern std::string realpass; | |
| 12 | + | |
| 13 | +class Fl_Text_Display; | |
| 14 | +class Fl_Text_Buffer; | |
| 15 | + | |
| 16 | +extern Fl_Text_Display *textview; | |
| 17 | +extern Fl_Text_Buffer *textbuf; | |
| 18 | + | |
| 19 | +void browse(std::string &path, bool isNew); | |
| 20 | +void clearpaths(bool isReset, std::string &path); | |
| 21 | +void updatelist(); | |
| 22 | +void scandir(const std::string& dir, const std::string& root, std::vector<std::string>& paths); | |
| 23 | + | |
| 24 | +#endif |
| @@ -0,0 +1,12 @@ | ||
| 1 | +[Desktop Entry] | |
| 2 | +Type=Application | |
| 3 | +Name=SimPas | |
| 4 | +GenericName=Simple Password Manager | |
| 5 | +GenericName[ja]=シンプルなパスワードマネージャー | |
| 6 | +Exec=simpas %F | |
| 7 | +Icon=/usr/local/share/icons/076/512x512/simpas | |
| 8 | +StartupNotify=true | |
| 9 | +Terminal=false | |
| 10 | +Type=Application | |
| 11 | +Categories=Application;Utility;System;Security;DeskopUtility; | |
| 12 | +Keywords=password;password manager;security;otp;password generator; |
| @@ -0,0 +1,307 @@ | ||
| 1 | +#include "common.hh" | |
| 2 | +#include "addpass.hh" | |
| 3 | +#include "../main.hh" | |
| 4 | + | |
| 5 | +#include <gpgme++/context.h> | |
| 6 | +#include <gpgme++/data.h> | |
| 7 | +#include <gpgme++/encryptionresult.h> | |
| 8 | + | |
| 9 | +#undef None | |
| 10 | +#include <FL/Fl_Window.H> | |
| 11 | +#include <FL/fl_ask.H> | |
| 12 | + | |
| 13 | +#include <fstream> | |
| 14 | + | |
| 15 | +#include <unistd.h> | |
| 16 | + | |
| 17 | +Addpass add; | |
| 18 | + | |
| 19 | +struct InputData { | |
| 20 | + Fl_Input *txtin; | |
| 21 | + Fl_Secret_Input *pass1; | |
| 22 | + Fl_Secret_Input *pass2; | |
| 23 | + Fl_Window *dialog; | |
| 24 | +}; | |
| 25 | + | |
| 26 | +bool Addpass::exec(const std::string &file, const std::string &pass, bool isEdit) { | |
| 27 | + std::string lang = Common::getlang(); | |
| 28 | + | |
| 29 | + std::string basedir = Common::getbasedir(true); | |
| 30 | + std::string ext = ".gpg"; | |
| 31 | + | |
| 32 | + std::string gpgoutfile = (isEdit ? file : basedir + file + ext); | |
| 33 | + | |
| 34 | + if (access(gpgoutfile.c_str(), F_OK) != -1) { | |
| 35 | + std::string err = (lang.compare(0, 2, "en") == 0 ? | |
| 36 | + "Password already exist." : | |
| 37 | + "パスワードが既に存在しています。"); | |
| 38 | + fl_alert("%s", err.c_str()); | |
| 39 | + return false; | |
| 40 | + } | |
| 41 | + | |
| 42 | + try { | |
| 43 | + // GPGMEライブラリを設置 | |
| 44 | + std::setlocale(LC_ALL, ""); | |
| 45 | + GpgME::initializeLibrary(); | |
| 46 | + GpgME::setDefaultLocale(LC_CTYPE, std::setlocale(LC_CTYPE, NULL)); | |
| 47 | + | |
| 48 | + GpgME::Error err; | |
| 49 | + if (err) { | |
| 50 | + std::string ero = (lang.compare(0, 2, "en") == 0 ? | |
| 51 | + "Failed to generate GPGME" : | |
| 52 | + "GPGエラーの設置に失敗"); | |
| 53 | + fl_alert("%s: %s", ero.c_str(), gpg_strerror(err.code())); | |
| 54 | + return false; | |
| 55 | + } | |
| 56 | + | |
| 57 | + // GPGMEを創作 | |
| 58 | + std::unique_ptr<GpgME::Context> ctx = | |
| 59 | + GpgME::Context::create(GpgME::Protocol::OpenPGP); | |
| 60 | + | |
| 61 | + // GPGMEは非対話的モードに設定 | |
| 62 | + err = ctx->setPinentryMode(GpgME::Context::PinentryMode::PinentryLoopback); | |
| 63 | + if (err) { | |
| 64 | + std::string ero = (lang.compare(0, 2, "en") == 0 ? | |
| 65 | + "Failed to set pinentry mode" : | |
| 66 | + "pinentryモードを設定に失敗"); | |
| 67 | + fl_alert("%s: %s", ero.c_str(), gpg_strerror(err.code())); | |
| 68 | + return false; | |
| 69 | + } | |
| 70 | + | |
| 71 | + // パスワードからデータオブジェクトを創作 | |
| 72 | + GpgME::Data in(pass.c_str(), strlen(pass.c_str()), false); | |
| 73 | + GpgME::Data out; | |
| 74 | + | |
| 75 | + // 鍵を受け取る | |
| 76 | + std::string keypath = basedir + ".gpg-id"; | |
| 77 | + std::ifstream keyfile(keypath, std::ios::binary); | |
| 78 | + if (!keyfile.is_open()) { | |
| 79 | + std::string ero = (lang.compare(0, 2, "en") == 0 ? | |
| 80 | + "Failed to open .gpg-id file" : | |
| 81 | + ".gpg-idファイルを開くに失敗"); | |
| 82 | + fl_alert("%s", ero.c_str()); | |
| 83 | + return false; | |
| 84 | + } | |
| 85 | + | |
| 86 | + std::string keyid; | |
| 87 | + std::string line; | |
| 88 | + while (std::getline(keyfile, line)) { | |
| 89 | + line.erase(line.find_last_not_of(" \n\r\t") + 1); | |
| 90 | + if (!line.empty()) keyid = line; | |
| 91 | + } | |
| 92 | + | |
| 93 | + keyfile.close(); | |
| 94 | + | |
| 95 | + if (keyid.empty()) { | |
| 96 | + std::string ero = (lang.compare(0, 2, "en") == 0 ? | |
| 97 | + "The .gpg-id file is empty or invalid" : | |
| 98 | + ".gpg-idファイルは空か無効です"); | |
| 99 | + fl_alert("%s", ero.c_str()); | |
| 100 | + return false; | |
| 101 | + } | |
| 102 | + | |
| 103 | + GpgME::Key key = ctx->key(keyid.c_str(), err); | |
| 104 | + if (key.isNull()) { | |
| 105 | + std::string ero = (lang.compare(0, 2, "en") == 0 ? | |
| 106 | + "Failed to get key" : | |
| 107 | + "鍵を受取に失敗"); | |
| 108 | + fl_alert("%s", ero.c_str()); | |
| 109 | + return false; | |
| 110 | + } | |
| 111 | + | |
| 112 | + // 暗号化 | |
| 113 | + std::vector<GpgME::Key> keys = {key}; | |
| 114 | + | |
| 115 | + GpgME::EncryptionResult res = | |
| 116 | + ctx->encrypt(keys, in, out, GpgME::Context::AlwaysTrust); | |
| 117 | + if (res.error()) { | |
| 118 | + std::string ero = (lang.compare(0, 2, "en") == 0 ? | |
| 119 | + "Failed to encrypt" : | |
| 120 | + "暗号化に失敗"); | |
| 121 | + fl_alert("%s: %s", ero.c_str(), res.error().asString()); | |
| 122 | + return false; | |
| 123 | + } | |
| 124 | + | |
| 125 | + // ディレクトリを創作 | |
| 126 | + std::string dirpath = (isEdit ? file : basedir + file); | |
| 127 | + auto lastsla = dirpath.find_last_of('/'); | |
| 128 | + if (lastsla != std::string::npos) { | |
| 129 | + dirpath = dirpath.substr(0, lastsla); | |
| 130 | + | |
| 131 | + try { | |
| 132 | + Common common; | |
| 133 | + common.mkdir_r(dirpath, 0755); | |
| 134 | + } catch (const std::runtime_error &e) { | |
| 135 | + std::string ero = (lang.compare(0, 2, "en") == 0 ? | |
| 136 | + "Failed to create directory" : | |
| 137 | + "ディレクトリを創作に失敗"); | |
| 138 | + fl_alert("%s: %s", ero.c_str(), e.what()); | |
| 139 | + return false; | |
| 140 | + } | |
| 141 | + } | |
| 142 | + | |
| 143 | + // 暗号化したファイルを開く | |
| 144 | + std::ofstream gpgpath(gpgoutfile, std::ios::binary); | |
| 145 | + if (!gpgpath.is_open()) { | |
| 146 | + std::string ero = (lang.compare(0, 2, "en") == 0 ? | |
| 147 | + "Failed to write file '" + gpgoutfile + "'." : | |
| 148 | + "「" + gpgoutfile + "」ファイルを書き込めません。"); | |
| 149 | + fl_alert("%s", ero.c_str()); | |
| 150 | + return false; | |
| 151 | + } | |
| 152 | + | |
| 153 | + // データが保存したかどうか確認 | |
| 154 | + ssize_t encrypted_data_size = out.seek(0, SEEK_END); | |
| 155 | + if (encrypted_data_size <= 0) { | |
| 156 | + std::string ero = (lang.compare(0, 2, "en") == 0 ? | |
| 157 | + "Failed to store the data" : | |
| 158 | + "データを保存に失敗"); | |
| 159 | + fl_alert("%s", ero.c_str()); | |
| 160 | + return false; | |
| 161 | + } | |
| 162 | + | |
| 163 | + // 復号化したパスワードを表示する | |
| 164 | + out.seek(0, SEEK_SET); | |
| 165 | + | |
| 166 | + char buffer[512]; | |
| 167 | + ssize_t read_bytes; | |
| 168 | + while ((read_bytes = out.read(buffer, sizeof(buffer))) > 0) { | |
| 169 | + gpgpath.write(buffer, read_bytes); | |
| 170 | + } | |
| 171 | + | |
| 172 | + gpgpath.close(); | |
| 173 | + | |
| 174 | + if (gpgpath.fail()) { | |
| 175 | + std::string ero = (lang.compare(0, 2, "en") == 0 ? | |
| 176 | + "Failed to write encrypted data to file" : | |
| 177 | + "暗号化データを書き込めません。"); | |
| 178 | + fl_alert("%s", ero.c_str()); | |
| 179 | + return false; | |
| 180 | + } | |
| 181 | + } catch (const std::exception &e) { | |
| 182 | + std::string err = (lang.compare(0, 2, "en") == 0 ? | |
| 183 | + "Error" : | |
| 184 | + "エラー"); | |
| 185 | + fl_alert("%s: %s", err.c_str(), e.what()); | |
| 186 | + return false; | |
| 187 | + } | |
| 188 | + | |
| 189 | + if (isEdit) return true; | |
| 190 | + | |
| 191 | + std::string msg = (lang.compare(0, 2, "en") == 0 ? | |
| 192 | + "The password got saved." : | |
| 193 | + "パスワードを保存出来ました"); | |
| 194 | + fl_alert("%s", msg.c_str()); | |
| 195 | + | |
| 196 | + return true; | |
| 197 | +} | |
| 198 | + | |
| 199 | +void Addpass::add_cb(Fl_Widget *, void *data) { | |
| 200 | + InputData *inputs = (InputData *)data; | |
| 201 | + std::string lang = Common::getlang(); | |
| 202 | + | |
| 203 | + if (inputs) { | |
| 204 | + file = inputs->txtin->value(); | |
| 205 | + if (file.empty()) { | |
| 206 | + std::string err = | |
| 207 | + (lang.compare(0, 2, "en") == 0 ? | |
| 208 | + "Please fill in the path." : | |
| 209 | + "パスをご入力下さい。"); | |
| 210 | + fl_alert("%s", err.c_str()); | |
| 211 | + return; | |
| 212 | + } | |
| 213 | + inputpass1 = inputs->pass1->value(); | |
| 214 | + if (inputpass1.empty()) { | |
| 215 | + std::string err = | |
| 216 | + (lang.compare(0, 2, "en") == 0 ? | |
| 217 | + "Please fill in the password." : | |
| 218 | + "パスワードをご入力下さい。"); | |
| 219 | + fl_alert("%s", err.c_str()); | |
| 220 | + return; | |
| 221 | + } | |
| 222 | + inputpass2 = inputs->pass2->value(); | |
| 223 | + if (inputpass2.empty()) { | |
| 224 | + std::string err = | |
| 225 | + (lang.compare(0, 2, "en") == 0 ? | |
| 226 | + "Please fill in the password (confirm)." : | |
| 227 | + "パスワード (確認)をご入力下さい。"); | |
| 228 | + fl_alert("%s", err.c_str()); | |
| 229 | + return; | |
| 230 | + } | |
| 231 | + | |
| 232 | + if (inputpass1 != inputpass2) { | |
| 233 | + std::string err = | |
| 234 | + (lang.compare(0, 2, "en") == 0 ? | |
| 235 | + "Password does not match." : | |
| 236 | + "パスワードが一致していません。"); | |
| 237 | + fl_alert("%s", err.c_str()); | |
| 238 | + return; | |
| 239 | + } | |
| 240 | + | |
| 241 | + if (exec(file, inputpass1, false)) { | |
| 242 | + inputs->dialog->hide(); | |
| 243 | + } | |
| 244 | + } else { | |
| 245 | + std::string err = | |
| 246 | + (lang.compare(0, 2, "en") == 0 ? | |
| 247 | + "Please fill in all the fields." : | |
| 248 | + "全てのフィールドをご入力下さい。"); | |
| 249 | + fl_alert("%s", err.c_str()); | |
| 250 | + } | |
| 251 | +} | |
| 252 | + | |
| 253 | +void Addpass::dialog_cb(Fl_Widget *w, void *) { | |
| 254 | + (void)w; | |
| 255 | + std::string lang = Common::getlang(); | |
| 256 | + Fl_Window *dialog = new Fl_Window(400, 200, | |
| 257 | + (lang.compare(0, 2, "en") == 0 ? "Add password" : "パスワードの追加")); | |
| 258 | + | |
| 259 | + Fl_Input *txtin = new Fl_Input(150, 20, 180, 30, | |
| 260 | + (lang.compare(0, 2, "en") == 0 ? "Path:" : "パス:")); | |
| 261 | + dialog->add(txtin); | |
| 262 | + | |
| 263 | + Fl_Secret_Input *pass1 = new Fl_Secret_Input(150, 60, 180, 30, | |
| 264 | + (lang.compare(0, 2, "en") == 0 ? "Password:" : "パスワード:")); | |
| 265 | + Fl_Secret_Input *pass2 = new Fl_Secret_Input(150, 100, 180, 30, | |
| 266 | + (lang.compare(0, 2, "en") == 0 ? "Password (confirm):" : "パスワード (確認):")); | |
| 267 | + dialog->add(pass1); | |
| 268 | + dialog->add(pass2); | |
| 269 | + | |
| 270 | + InputData *inputs = new InputData(); | |
| 271 | + inputs->txtin = txtin; | |
| 272 | + inputs->pass1 = pass1; | |
| 273 | + inputs->pass2 = pass2; | |
| 274 | + inputs->dialog = dialog; | |
| 275 | + | |
| 276 | + Fl_Button *okbtn = new Fl_Button(60, 150, 80, 30, "OK"); | |
| 277 | + Fl_Button *cancelbtn = new Fl_Button(160, 150, 80, 30, | |
| 278 | + (lang.compare(0, 2, "en") == 0 ? "Cancel" : "キャンセル")); | |
| 279 | + | |
| 280 | + okbtn->callback(static_ok_cb, inputs); | |
| 281 | + cancelbtn->callback(static_cancel_cb, dialog); | |
| 282 | + | |
| 283 | + dialog->add(okbtn); | |
| 284 | + dialog->add(cancelbtn); | |
| 285 | + | |
| 286 | + dialog->end(); | |
| 287 | + dialog->set_modal(); | |
| 288 | + dialog->show(); | |
| 289 | +} | |
| 290 | + | |
| 291 | +void Addpass::static_ok_cb(Fl_Widget *w, void *data) { | |
| 292 | + (void)w; | |
| 293 | + InputData *inputs = (InputData *)data; | |
| 294 | + | |
| 295 | + add.add_cb(nullptr, inputs); | |
| 296 | + std::vector<std::string> fpaths; | |
| 297 | + std::string rdir = Common::getbasedir(false); | |
| 298 | + std::string curpath = rdir + "/" + inputs->txtin->value() + ".gpg"; | |
| 299 | + clearpaths(false, curpath); | |
| 300 | + scandir(rdir, rdir, fpaths); | |
| 301 | + updatelist(); | |
| 302 | + browse(curpath, true); | |
| 303 | +} | |
| 304 | + | |
| 305 | +void Addpass::static_cancel_cb(Fl_Widget *w, void *data) { | |
| 306 | + ((Addpass *)data)->cancel_cb(w, data); | |
| 307 | +} |
| @@ -0,0 +1,28 @@ | ||
| 1 | +#ifndef ADDPASS_HH | |
| 2 | +#define ADDPASS_HH | |
| 3 | + | |
| 4 | +#include <FL/Fl_Button.H> | |
| 5 | +#include <FL/Fl_Input.H> | |
| 6 | +#include <FL/Fl_Secret_Input.H> | |
| 7 | + | |
| 8 | +#include "dialog.hh" | |
| 9 | + | |
| 10 | +#include <string> | |
| 11 | + | |
| 12 | +class Addpass : public Dialog { | |
| 13 | + public: | |
| 14 | + Fl_Button *btn = nullptr; | |
| 15 | + std::string file; | |
| 16 | + std::string inputpass1; | |
| 17 | + std::string inputpass2; | |
| 18 | + | |
| 19 | + static void dialog_cb(Fl_Widget *w, void *); | |
| 20 | + void add_cb(Fl_Widget *, void *); | |
| 21 | + bool exec(const std::string &file, const std::string &pass, bool isEdit); | |
| 22 | + | |
| 23 | + private: | |
| 24 | + static void static_ok_cb(Fl_Widget *w, void *data); | |
| 25 | + static void static_cancel_cb(Fl_Widget *w, void *data); | |
| 26 | +}; | |
| 27 | + | |
| 28 | +#endif |
| @@ -0,0 +1,53 @@ | ||
| 1 | +#include "base32.hh" | |
| 2 | + | |
| 3 | +#include <algorithm> | |
| 4 | +#include <cctype> | |
| 5 | +#include <cstddef> | |
| 6 | +#include <iterator> | |
| 7 | +#include <stdexcept> | |
| 8 | +#include <string> | |
| 9 | + | |
| 10 | +int Base32::char_to_val(char c) { | |
| 11 | + std::string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; | |
| 12 | + auto it = std::find(alphabet.begin(), alphabet.end(), c); | |
| 13 | + return (it != alphabet.end()) ? std::distance(alphabet.begin(), it) : -1; | |
| 14 | +} | |
| 15 | + | |
| 16 | +std::vector<unsigned char> Base32::decode(const std::string &encoded) { | |
| 17 | + std::string encoded_up = encoded; | |
| 18 | + for (auto &c : encoded_up) { | |
| 19 | + c = std::toupper(static_cast<unsigned char>(c)); | |
| 20 | + } | |
| 21 | + | |
| 22 | + size_t encoded_len = encoded_up.length(); | |
| 23 | + size_t padding = 0; | |
| 24 | + for (int i = encoded_len - 1; i >= 0 && encoded_up[i] == '='; --i) { | |
| 25 | + ++padding; | |
| 26 | + } | |
| 27 | + | |
| 28 | + size_t out_len = (encoded_len - padding) * 5 / 8; | |
| 29 | + if (out_len == 0) return {}; | |
| 30 | + | |
| 31 | + std::vector<unsigned char> decoded(out_len); | |
| 32 | + | |
| 33 | + int buffer = 0, bits_left = 0, count = 0; | |
| 34 | + Base32 b32; | |
| 35 | + for (size_t i = 0; i < encoded_len - padding; ++i) { | |
| 36 | + int val = b32.char_to_val(encoded_up[i]); | |
| 37 | + if (val < 0) { | |
| 38 | + throw std::runtime_error("Base32エンコードした文字の中に不正な文字があります。"); | |
| 39 | + } | |
| 40 | + | |
| 41 | + buffer <<= 5; | |
| 42 | + buffer |= val; | |
| 43 | + bits_left += 5; | |
| 44 | + | |
| 45 | + if (bits_left >= 8) { | |
| 46 | + decoded[count++] = static_cast<unsigned char>(buffer >> (bits_left - 8)); | |
| 47 | + bits_left -= 8; | |
| 48 | + } | |
| 49 | + } | |
| 50 | + | |
| 51 | + decoded.resize(count); | |
| 52 | + return decoded; | |
| 53 | +} |
| @@ -0,0 +1,15 @@ | ||
| 1 | +#ifndef BASE32_HH | |
| 2 | +#define BASE32_HH | |
| 3 | + | |
| 4 | +#include <vector> | |
| 5 | +#include <string> | |
| 6 | + | |
| 7 | +class Base32 { | |
| 8 | + public: | |
| 9 | + static std::vector<unsigned char> decode(const std::string &encoded); | |
| 10 | + | |
| 11 | + private: | |
| 12 | + int char_to_val(char c); | |
| 13 | +}; | |
| 14 | + | |
| 15 | +#endif |
| @@ -0,0 +1,279 @@ | ||
| 1 | +#include "common.hh" | |
| 2 | +#include "chkpass.hh" | |
| 3 | +#include "../main.hh" | |
| 4 | +#include "showpass.hh" | |
| 5 | + | |
| 6 | +#include <FL/Fl.H> | |
| 7 | +#include <FL/Fl_Window.H> | |
| 8 | +#include <FL/fl_ask.H> | |
| 9 | +#include <FL/Fl_Box.H> | |
| 10 | +#include <FL/Fl_Button.H> | |
| 11 | +#include <FL/Fl_Text_Display.H> | |
| 12 | +#include <FL/Fl_Text_Buffer.H> | |
| 13 | +#include <FL/Fl_Scrollbar.H> | |
| 14 | + | |
| 15 | +#include <string> | |
| 16 | +#include <thread> | |
| 17 | +#include <algorithm> | |
| 18 | + | |
| 19 | +Chkpass chk; | |
| 20 | +std::vector<std::string> foundRes; | |
| 21 | +std::vector<std::string> duppath; | |
| 22 | +std::vector<std::string> duppasswd; | |
| 23 | + | |
| 24 | +struct InputData { | |
| 25 | + Fl_Radio_Button *all; | |
| 26 | + Fl_Radio_Button *len; | |
| 27 | + Fl_Radio_Button *chr; | |
| 28 | + Fl_Radio_Button *dup; | |
| 29 | + Fl_Window *dialog; | |
| 30 | +}; | |
| 31 | + | |
| 32 | +void Chkpass::lenPass(const std::string &path, const std::string &pass, | |
| 33 | + const std::string &lang) { | |
| 34 | + if (pass.length() > 0 && pass.length() < minimumlen) { | |
| 35 | + std::string res = "【E】"; | |
| 36 | + res += (lang.compare(0, 2, "en") == 0 ? | |
| 37 | + "The password \"" + path + "\" is too short, minimum length should be " + | |
| 38 | + std::to_string(minimumlen) + " characters, recommended is " + | |
| 39 | + std::to_string(recommendlen) + " characters.": | |
| 40 | + "パスワード「" + path + "」は短すぎます。最短パスワードの長さは" + | |
| 41 | + std::to_string(minimumlen) + "文字ですが、勧めが" + | |
| 42 | + std::to_string(recommendlen) + "文字です。"); | |
| 43 | + | |
| 44 | + foundRes.push_back(res); | |
| 45 | + weaklencount++; | |
| 46 | + vulncount++; | |
| 47 | + } else if (pass.length() >= minimumlen && pass.length() < recommendlen) { | |
| 48 | + std::string res = "【W】"; | |
| 49 | + res += (lang.compare(0, 2, "en") == 0 ? | |
| 50 | + "The password \"" + path + "\" is long enough, but for optimal security, " + | |
| 51 | + std::to_string(recommendlen) + " characters is recommended.\n" : | |
| 52 | + "パスワード「" + path + "」の長さは十分ですが、最強のセキュリティには" + | |
| 53 | + std::to_string(recommendlen) + "文字が勧めします。\n"); | |
| 54 | + | |
| 55 | + foundRes.push_back(res); | |
| 56 | + } | |
| 57 | +} | |
| 58 | + | |
| 59 | +void Chkpass::charPass(const std::string &path, const std::string &pass, | |
| 60 | + const std::string &lang) { | |
| 61 | + bool isUpper = false; | |
| 62 | + bool isLower = false; | |
| 63 | + bool isDigit = false; | |
| 64 | + bool isSpecial = false; | |
| 65 | + | |
| 66 | + for (char ch : pass) { | |
| 67 | + if (std::isupper(static_cast<unsigned char>(ch))) isUpper = true; | |
| 68 | + if (std::islower(static_cast<unsigned char>(ch))) isLower = true; | |
| 69 | + if (std::isdigit(static_cast<unsigned char>(ch))) isDigit = true; | |
| 70 | + if (std::find(spchar.begin(), spchar.end(), ch) != spchar.end()) isSpecial = true; | |
| 71 | + } | |
| 72 | + | |
| 73 | + if (!isUpper || !isLower || !isDigit || !isSpecial) { | |
| 74 | + std::string res = "【E】"; | |
| 75 | + res += (lang.compare(0, 2, "en") == 0 ? | |
| 76 | + "The password \"" + path + "\" is too weak! A strong password contains " + | |
| 77 | + "at least 1 uppercase, 1 lowercase, 1 digit, and 1 special character." : | |
| 78 | + "パスワード「" + path + "」は弱すぎます!強いパスワードは最大1大文字、" + | |
| 79 | + "1小文字、1数字、及び1記号の文字が含みます。"); | |
| 80 | + | |
| 81 | + foundRes.push_back(res); | |
| 82 | + weakcharcount++; | |
| 83 | + vulncount++; | |
| 84 | + } | |
| 85 | +} | |
| 86 | + | |
| 87 | +void Chkpass::dupPass(const std::string &path, const std::string &pass, | |
| 88 | + const std::string &lang) { | |
| 89 | + for (std::size_t k = 0; k < duppasswd.size(); k++) { | |
| 90 | + if (pass.compare(duppasswd[k]) == 0) { | |
| 91 | + std::string res = "【E】"; | |
| 92 | + res += (lang.compare(0, 2, "en") == 0 ? | |
| 93 | + "The password \"" + path + "\" is the same as \"" + duppath[k] + "\". " + | |
| 94 | + "For security, please keep passwords unique!": | |
| 95 | + "パスワード「" + path + "」は「" + duppath[k] + "」と一致しています。" + | |
| 96 | + "セキュリティの為、各パスワードはユニークにする様にして下さい!"); | |
| 97 | + | |
| 98 | + foundRes.push_back(res); | |
| 99 | + duppasscount++; | |
| 100 | + vulncount++; | |
| 101 | + } | |
| 102 | + } | |
| 103 | + | |
| 104 | + duppath.push_back(path); | |
| 105 | + duppasswd.push_back(pass); | |
| 106 | +} | |
| 107 | + | |
| 108 | +bool Chkpass::exec() { | |
| 109 | + std::string lang = Common::getlang(); | |
| 110 | + | |
| 111 | + // パスワードをスキャンして | |
| 112 | + Showpass show; | |
| 113 | + | |
| 114 | + for (const auto &dispath : dispaths) { | |
| 115 | + std::string fullpath = Common::getbasedir(true) + dispath + ".gpg"; | |
| 116 | + std::string pass = show.exec(fullpath.c_str(), true); | |
| 117 | + if (pass.empty()) continue; | |
| 118 | + if (pass.rfind("otpauth://totp/", 0) == 0) continue; | |
| 119 | + | |
| 120 | + if (isAll) { | |
| 121 | + lenPass(dispath, pass, lang); | |
| 122 | + charPass(dispath, pass, lang); | |
| 123 | + dupPass(dispath, pass, lang); | |
| 124 | + } else if (isLen) { | |
| 125 | + lenPass(dispath, pass, lang); | |
| 126 | + } else if (isChar) { | |
| 127 | + charPass(dispath, pass, lang); | |
| 128 | + } else if (isDup) { | |
| 129 | + dupPass(dispath, pass, lang); | |
| 130 | + } | |
| 131 | + } | |
| 132 | + | |
| 133 | + return true; | |
| 134 | +} | |
| 135 | + | |
| 136 | +void Chkpass::showRes() { | |
| 137 | + std::string lang = Common::getlang(); | |
| 138 | + | |
| 139 | + std::string res; | |
| 140 | + if (lang.compare(0, 2, "en") == 0) { | |
| 141 | + res = "Weak passwords:\n"; | |
| 142 | + } else { | |
| 143 | + res = "不安定なパスワード:\n"; | |
| 144 | + } | |
| 145 | + | |
| 146 | + for (const auto &path : foundRes) { | |
| 147 | + res += path + "\n"; | |
| 148 | + } | |
| 149 | + | |
| 150 | + if (lang.compare(0, 2, "en") == 0) { | |
| 151 | + res += "Short password count: " + std::to_string(weaklencount) + "\n"; | |
| 152 | + res += "Weak password count: " + std::to_string(weakcharcount) + "\n"; | |
| 153 | + res += "Duplicate password count: " + std::to_string(duppasscount) + "\n"; | |
| 154 | + res += "Total: " + std::to_string(duppath.size()) + "\n"; | |
| 155 | + res += "It's advised to change any of the"; | |
| 156 | + res += "weak passwords as soon as possible!"; | |
| 157 | + } else { | |
| 158 | + res += "短いパスワード数: " + std::to_string(weaklencount) + "\n"; | |
| 159 | + res += "弱いパスワード数: " + std::to_string(weakcharcount) + "\n"; | |
| 160 | + res += "同じパスワード数: " + std::to_string(duppasscount) + "\n"; | |
| 161 | + res += "合計: " + std::to_string(duppath.size()) + "\n"; | |
| 162 | + res += "不安定なパスワードは出来るだけ早く変更する事をお勧めします!"; | |
| 163 | + } | |
| 164 | + | |
| 165 | + Fl_Window *win = new Fl_Window(500, 440, lang.compare(0, 2, "en") == 0 ? | |
| 166 | + "Results" : "結果"); | |
| 167 | + Fl_Text_Display *display = new Fl_Text_Display(10, 10, 480, 380); | |
| 168 | + Fl_Text_Buffer *textbuf = new Fl_Text_Buffer(); | |
| 169 | + | |
| 170 | + textbuf->text(res.c_str()); | |
| 171 | + display->buffer(textbuf); | |
| 172 | + display->scrollbar_width(15); | |
| 173 | + win->resizable(display); | |
| 174 | + | |
| 175 | + Fl_Button *okBtn = new Fl_Button(210, 400, 80, 30, "OK"); | |
| 176 | + okBtn->callback([](Fl_Widget *widget, void *win) { | |
| 177 | + (void)widget; | |
| 178 | + reinterpret_cast<Fl_Window*>(win)->hide(); | |
| 179 | + }, win); | |
| 180 | + | |
| 181 | + win->add(okBtn); | |
| 182 | + | |
| 183 | + win->end(); | |
| 184 | + win->show(); | |
| 185 | +} | |
| 186 | + | |
| 187 | +void Chkpass::chk_cb(Fl_Widget *, void *data) { | |
| 188 | + InputData *inputs = (InputData *)data; | |
| 189 | + std::string lang = Common::getlang(); | |
| 190 | + | |
| 191 | + if (inputs) { | |
| 192 | + isAll = inputs->all->value(); | |
| 193 | + isLen = inputs->len->value(); | |
| 194 | + isChar = inputs->chr->value(); | |
| 195 | + isDup = inputs->dup->value(); | |
| 196 | + } | |
| 197 | + | |
| 198 | + Fl_Window *dialog = new Fl_Window(400, 50, | |
| 199 | + (lang.compare(0, 2, "en") == 0 ? | |
| 200 | + "Checking for weak password" : "不安的なパスワードの確認中")); | |
| 201 | + | |
| 202 | + Fl_Box *box = new Fl_Box(10, 10, 380, 20, | |
| 203 | + (lang.compare(0, 2, "en") == 0 ? | |
| 204 | + "Checking, please wait for a while..." : | |
| 205 | + "確認中。暫くお待ち下さい・・・")); | |
| 206 | + | |
| 207 | + dialog->add(box); | |
| 208 | + | |
| 209 | + dialog->end(); | |
| 210 | + dialog->set_modal(); | |
| 211 | + dialog->show(); | |
| 212 | + | |
| 213 | + std::thread checker([dialog]() { | |
| 214 | + chk.exec(); | |
| 215 | + | |
| 216 | + Fl::lock(); | |
| 217 | + dialog->hide(); | |
| 218 | + chk.showRes(); | |
| 219 | + Fl::unlock(); | |
| 220 | + }); | |
| 221 | + | |
| 222 | + checker.detach(); | |
| 223 | +} | |
| 224 | + | |
| 225 | +void Chkpass::dialog_cb(Fl_Widget *w, void *) { | |
| 226 | + (void)w; | |
| 227 | + | |
| 228 | + std::string lang = Common::getlang(); | |
| 229 | + | |
| 230 | + Fl_Window *dialog = new Fl_Window(390, 145, | |
| 231 | + (lang.compare(0, 2, "en") == 0 ? | |
| 232 | + "Check for weak password" : "不安的なパスワードの確認")); | |
| 233 | + | |
| 234 | + Fl_Radio_Button *all = new Fl_Radio_Button(10, 10, 180, 30, | |
| 235 | + (lang.compare(0, 2, "en") == 0) ? "Everything" : "全部"); | |
| 236 | + Fl_Radio_Button *len = new Fl_Radio_Button(10, 50, 180, 30, | |
| 237 | + (lang.compare(0, 2, "en") == 0) ? "Length" : "長さ"); | |
| 238 | + Fl_Radio_Button *chr = new Fl_Radio_Button(200, 10, 180, 30, | |
| 239 | + (lang.compare(0, 2, "en") == 0) ? "Strength" : "強さ"); | |
| 240 | + Fl_Radio_Button *dup = new Fl_Radio_Button(200, 50, 180, 30, | |
| 241 | + (lang.compare(0, 2, "en") == 0) ? "Duplicate" : "服数度"); | |
| 242 | + | |
| 243 | + dialog->add(all); | |
| 244 | + dialog->add(len); | |
| 245 | + dialog->add(chr); | |
| 246 | + dialog->add(dup); | |
| 247 | + | |
| 248 | + InputData *inputs = new InputData(); | |
| 249 | + inputs->all = all; | |
| 250 | + inputs->len = len; | |
| 251 | + inputs->chr = chr; | |
| 252 | + inputs->dup = dup; | |
| 253 | + inputs->dialog = dialog; | |
| 254 | + | |
| 255 | + Fl_Button *okbtn = new Fl_Button(105, 100, 80, 30, "OK"); | |
| 256 | + Fl_Button *cancelbtn = new Fl_Button(205, 100, 80, 30, | |
| 257 | + (lang.compare(0, 2, "en") == 0 ? "Cancel" : "キャンセル")); | |
| 258 | + | |
| 259 | + okbtn->callback(static_ok_cb, inputs); | |
| 260 | + cancelbtn->callback(static_cancel_cb, dialog); | |
| 261 | + | |
| 262 | + dialog->add(okbtn); | |
| 263 | + dialog->add(cancelbtn); | |
| 264 | + | |
| 265 | + dialog->end(); | |
| 266 | + dialog->set_modal(); | |
| 267 | + dialog->show(); | |
| 268 | +} | |
| 269 | + | |
| 270 | +void Chkpass::static_ok_cb(Fl_Widget *w, void *data) { | |
| 271 | + (void)w; | |
| 272 | + InputData *inputs = (InputData *)data; | |
| 273 | + | |
| 274 | + chk.chk_cb(nullptr, inputs); | |
| 275 | +} | |
| 276 | + | |
| 277 | +void Chkpass::static_cancel_cb(Fl_Widget *w, void *data) { | |
| 278 | + ((Chkpass *)data)->cancel_cb(w, data); | |
| 279 | +} |
| @@ -0,0 +1,45 @@ | ||
| 1 | +#ifndef CHKPASS_HH | |
| 2 | +#define CHKPASS_HH | |
| 3 | + | |
| 4 | +#include <FL/Fl_Button.H> | |
| 5 | +#include <FL/Fl_Radio_Button.H> | |
| 6 | + | |
| 7 | +#include "dialog.hh" | |
| 8 | + | |
| 9 | +#include <string> | |
| 10 | + | |
| 11 | +class Chkpass : public Dialog { | |
| 12 | + public: | |
| 13 | + Fl_Button *btn = nullptr; | |
| 14 | + Fl_Radio_Button *allChk = nullptr; | |
| 15 | + Fl_Radio_Button *lenChk = nullptr; | |
| 16 | + Fl_Radio_Button *charChk = nullptr; | |
| 17 | + Fl_Radio_Button *dupChk = nullptr; | |
| 18 | + bool isAll, isLen, isChar, isDup = false; | |
| 19 | + | |
| 20 | + static void dialog_cb(Fl_Widget *w, void *); | |
| 21 | + void showRes(); | |
| 22 | + void chk_cb(Fl_Widget *, void *); | |
| 23 | + bool exec(); | |
| 24 | + | |
| 25 | + private: | |
| 26 | + int vulncount = 0; | |
| 27 | + int weaklencount = 0; | |
| 28 | + int weakcharcount = 0; | |
| 29 | + int duppasscount = 0; | |
| 30 | + | |
| 31 | + std::size_t minimumlen = 12; | |
| 32 | + std::size_t recommendlen = 64; | |
| 33 | + | |
| 34 | + std::string spchar = "!@#$%^&*()-_=+[]{}|;:'\",.<>?/\\`~"; | |
| 35 | + | |
| 36 | + void lenPass(const std::string &path, const std::string &pass, | |
| 37 | + const std::string &lang); | |
| 38 | + void charPass(const std::string &path, const std::string &pass, | |
| 39 | + const std::string &lang); | |
| 40 | + void dupPass(const std::string &path, const std::string &pass, | |
| 41 | + const std::string &lang); | |
| 42 | + static void static_ok_cb(Fl_Widget *w, void *data); | |
| 43 | + static void static_cancel_cb(Fl_Widget *w, void *data); | |
| 44 | +}; | |
| 45 | +#endif |
| @@ -0,0 +1,82 @@ | ||
| 1 | +#include "common.hh" | |
| 2 | + | |
| 3 | +#include <cstdio> | |
| 4 | +#include <cstdlib> | |
| 5 | +#include <cstring> | |
| 6 | + | |
| 7 | +#include <fstream> | |
| 8 | +#include <iostream> | |
| 9 | +#include <errno.h> | |
| 10 | + | |
| 11 | +std::string Common::getbasedir(bool trailing) { | |
| 12 | + std::string homedir = std::getenv("HOME") ? std::getenv("HOME") : ""; | |
| 13 | + if (homedir.empty()) return ""; | |
| 14 | + | |
| 15 | +#if defined(__HAIKU__) | |
| 16 | + std::string basedir = "/config/settings/sp"; | |
| 17 | + std::string slash = "/"; | |
| 18 | +#elif defined(_WIN32) | |
| 19 | + std::string basedir = "\\AppData\\Local\\076\\sp"; | |
| 20 | + std::string slash = "\\"; | |
| 21 | +#else | |
| 22 | + std::string basedir = "/.local/share/sp"; | |
| 23 | + std::string slash = "/"; | |
| 24 | +#endif | |
| 25 | + | |
| 26 | + return trailing ? (homedir + basedir + slash) : (homedir + basedir); | |
| 27 | +} | |
| 28 | + | |
| 29 | +std::string Common::getlang() { | |
| 30 | + const char *env = std::getenv("SP_LANG"); | |
| 31 | + std::string lang; | |
| 32 | + | |
| 33 | + if (env) lang = env; | |
| 34 | + else lang = "ja"; | |
| 35 | + | |
| 36 | + return lang; | |
| 37 | +} | |
| 38 | + | |
| 39 | +int Common::mkdir_r(const std::string &path, mode_t mode) { | |
| 40 | + char tmp[256]; | |
| 41 | + size_t len; | |
| 42 | + | |
| 43 | + std::snprintf(tmp, sizeof(tmp), "%s", path.c_str()); | |
| 44 | + | |
| 45 | + len = std::strlen(tmp); | |
| 46 | + if (tmp[len - 1] == '/') { | |
| 47 | + tmp[len - 1] = 0; | |
| 48 | + } | |
| 49 | + | |
| 50 | + for (char *p = tmp + 1; *p; p++) { | |
| 51 | + if (*p == '/') { | |
| 52 | + *p = 0; | |
| 53 | + if (mkdir(tmp, mode) != 0 && errno != EEXIST) return -1; | |
| 54 | + *p = '/'; | |
| 55 | + } | |
| 56 | + } | |
| 57 | + | |
| 58 | + if (mkdir(tmp, mode) != 0 && errno != EEXIST) { | |
| 59 | + return -1; | |
| 60 | + } | |
| 61 | + | |
| 62 | + return 0; | |
| 63 | +} | |
| 64 | + | |
| 65 | +void Common::tmpcopy(const std::string &inpath, const std::string &outpath) { | |
| 66 | + std::ifstream src(inpath, std::ios::binary); | |
| 67 | + std::ofstream dst(outpath, std::ios::binary); | |
| 68 | +} | |
| 69 | + | |
| 70 | +std::vector<std::string> Common::explode(const std::string &str, char delimiter) { | |
| 71 | + std::vector<std::string> tokens; | |
| 72 | + std::string token; | |
| 73 | + size_t start = 0, end = 0; | |
| 74 | + | |
| 75 | + while ((end = str.find(delimiter, start)) != std::string::npos) { | |
| 76 | + tokens.push_back(str.substr(start, end - start)); | |
| 77 | + start = end + 1; | |
| 78 | + } | |
| 79 | + tokens.push_back(str.substr(start)); | |
| 80 | + | |
| 81 | + return tokens; | |
| 82 | +} |
| @@ -0,0 +1,18 @@ | ||
| 1 | +#ifndef COMMON_HH | |
| 2 | +#define COMMON_HH | |
| 3 | + | |
| 4 | +#include <vector> | |
| 5 | +#include <string> | |
| 6 | + | |
| 7 | +#include <sys/stat.h> | |
| 8 | + | |
| 9 | +class Common { | |
| 10 | + public: | |
| 11 | + static std::string getbasedir(bool trailing); | |
| 12 | + static std::string getlang(); | |
| 13 | + int mkdir_r(const std::string &path, mode_t mode); | |
| 14 | + void tmpcopy(const std::string &inpath, const std::string &outpath); | |
| 15 | + static std::vector<std::string> explode(const std::string &str, char delimiter); | |
| 16 | +}; | |
| 17 | + | |
| 18 | +#endif |
| @@ -0,0 +1,147 @@ | ||
| 1 | +#include "common.hh" | |
| 2 | +#include "delpass.hh" | |
| 3 | +#include "../main.hh" | |
| 4 | + | |
| 5 | +#include <FL/fl_ask.H> | |
| 6 | +#include <FL/Fl_Input.H> | |
| 7 | + | |
| 8 | +#include <unistd.h> | |
| 9 | + | |
| 10 | +Delpass del; | |
| 11 | + | |
| 12 | +struct InputData { | |
| 13 | + Fl_Input *txtin; | |
| 14 | + Fl_Window *dialog; | |
| 15 | +}; | |
| 16 | + | |
| 17 | +void Delpass::setFile(std::string &f) { | |
| 18 | + del.file = f; | |
| 19 | +} | |
| 20 | + | |
| 21 | +std::string Delpass::getFile() { | |
| 22 | + return file; | |
| 23 | +} | |
| 24 | + | |
| 25 | +bool Delpass::exec(const std::string &file, bool force) { | |
| 26 | + std::string lang = Common::getlang(); | |
| 27 | + | |
| 28 | + std::string basedir = Common::getbasedir(true); | |
| 29 | + std::string ext = ".gpg"; | |
| 30 | + | |
| 31 | + // ファイルが既に存在するかどうか確認 | |
| 32 | + if (access(file.c_str(), F_OK) != 0) { | |
| 33 | + std::string err = (lang.compare(0, 2, "en") == 0 ? | |
| 34 | + "Password does not exist" : | |
| 35 | + "パスワードが存在しません"); | |
| 36 | + fl_alert("%s", err.c_str()); | |
| 37 | + return false; | |
| 38 | + } | |
| 39 | + | |
| 40 | + if (unlink(file.c_str()) == -1) { | |
| 41 | + std::string err = (lang.compare(0, 2, "en") == 0 ? | |
| 42 | + "Password cannot be deleted" : | |
| 43 | + "パスワードを削除出来ませんですた"); | |
| 44 | + fl_alert("%s", err.c_str()); | |
| 45 | + return false; | |
| 46 | + } | |
| 47 | + | |
| 48 | + // 空のディレクトリの場合 | |
| 49 | + std::vector<std::string> tokens = Common::explode(file, '/'); | |
| 50 | + std::string passpath = basedir + tokens[0]; | |
| 51 | + | |
| 52 | + for (size_t i = 1; i < tokens.size(); ++i) { | |
| 53 | + if (i == tokens.size() - 1) continue; | |
| 54 | + passpath += "/" + tokens[i]; | |
| 55 | + } | |
| 56 | + | |
| 57 | + for (int i = tokens.size() - 1; i >= 0; --i) { | |
| 58 | + // ~/.local/share/sp を削除したら危険 | |
| 59 | + if (passpath.compare(0, basedir.size(), basedir) == 0) { | |
| 60 | + break; | |
| 61 | + } | |
| 62 | + | |
| 63 | + // ディレクトリが空じゃない場合、削除を止める | |
| 64 | + if (rmdir(passpath.c_str()) == -1) { | |
| 65 | + break; | |
| 66 | + } | |
| 67 | + | |
| 68 | + size_t last_slash = passpath.find_last_of('/'); | |
| 69 | + if (last_slash != std::string::npos) { | |
| 70 | + passpath.erase(last_slash); | |
| 71 | + } | |
| 72 | + } | |
| 73 | + | |
| 74 | + if (force) return true; | |
| 75 | + | |
| 76 | + std::string msg = (lang.compare(0, 2, "en") == 0 ? | |
| 77 | + "The password got deleted" : | |
| 78 | + "パスワードを削除しました"); | |
| 79 | + fl_alert("%s", msg.c_str()); | |
| 80 | + return true; | |
| 81 | +} | |
| 82 | + | |
| 83 | +void Delpass::delete_cb(Fl_Widget *, void *data) { | |
| 84 | + InputData *inputs = (InputData *)data; | |
| 85 | + | |
| 86 | + if (inputs) { | |
| 87 | + file = inputs->txtin->value(); | |
| 88 | + } | |
| 89 | + | |
| 90 | + exec(file, false); | |
| 91 | + std::vector<std::string> fpaths; | |
| 92 | + std::string rdir = Common::getbasedir(false); | |
| 93 | + | |
| 94 | + std::string mockpath = ""; | |
| 95 | + clearpaths(true, mockpath); | |
| 96 | + scandir(rdir, rdir, fpaths); | |
| 97 | + updatelist(); | |
| 98 | +} | |
| 99 | + | |
| 100 | +void Delpass::dialog_cb(Fl_Widget *w, void *data) { | |
| 101 | + (void)w; | |
| 102 | + (void)data; | |
| 103 | + std::string lang = Common::getlang(); | |
| 104 | + | |
| 105 | + Fl_Input *txtin = new Fl_Input(150, 20, 180, 30, | |
| 106 | + (lang.compare(0, 2, "en") == 0 ? "Path:" : "パス:")); | |
| 107 | + txtin->hide(); | |
| 108 | + txtin->value(del.getFile().c_str()); | |
| 109 | + | |
| 110 | + InputData *inputs = new InputData(); | |
| 111 | + inputs->txtin = txtin; | |
| 112 | + | |
| 113 | + std::string asking = | |
| 114 | + (lang.compare(0, 2, "en") == 0 ? | |
| 115 | + "Are you sure you want to delete the password '" + del.getFile() + "'?" : | |
| 116 | + "パスワード「" + del.getFile() + "」を本当に削除する事が宜しいでしょうか?"); | |
| 117 | + int confirm = fl_choice("%s", | |
| 118 | + (lang.compare(0, 2, "en") == 0 ? "Cancel" : "キャンセル"), | |
| 119 | + (lang.compare(0, 2, "en") == 0 ? "Delete" : "削除"), | |
| 120 | + nullptr, asking.c_str()); | |
| 121 | + | |
| 122 | + if (confirm == 0) { | |
| 123 | + std::string err = (lang.compare(0, 2, "en") == 0 ? | |
| 124 | + "Not deleted" : | |
| 125 | + "削除しませんでした"); | |
| 126 | + fl_alert("%s", err.c_str()); | |
| 127 | + } else { | |
| 128 | + static_ok_cb(w, inputs); | |
| 129 | + } | |
| 130 | +} | |
| 131 | + | |
| 132 | +void Delpass::static_ok_cb(Fl_Widget *w, void *data) { | |
| 133 | + (void)w; | |
| 134 | + InputData *inputs = (InputData *)data; | |
| 135 | + | |
| 136 | + del.delete_cb(nullptr, inputs); | |
| 137 | + std::vector<std::string> fpaths; | |
| 138 | + std::string rdir = Common::getbasedir(false); | |
| 139 | + std::string curpath = ""; | |
| 140 | + clearpaths(true, curpath); | |
| 141 | + scandir(rdir, rdir, fpaths); | |
| 142 | + updatelist(); | |
| 143 | +} | |
| 144 | + | |
| 145 | +void Delpass::static_cancel_cb(Fl_Widget *w, void *data) { | |
| 146 | + ((Delpass *)data)->cancel_cb(w, data); | |
| 147 | +} |
| @@ -0,0 +1,25 @@ | ||
| 1 | +#ifndef DELPASS_HH | |
| 2 | +#define DELPASS_HH | |
| 3 | + | |
| 4 | +#include <FL/Fl_Button.H> | |
| 5 | +#include <string> | |
| 6 | + | |
| 7 | +#include "dialog.hh" | |
| 8 | + | |
| 9 | +class Delpass : public Dialog { | |
| 10 | + public: | |
| 11 | + Fl_Button *btn = nullptr; | |
| 12 | + std::string file; | |
| 13 | + | |
| 14 | + static void dialog_cb(Fl_Widget *w, void *); | |
| 15 | + void delete_cb(Fl_Widget *, void *data); | |
| 16 | + static void setFile(std::string &f); | |
| 17 | + std::string getFile(); | |
| 18 | + bool exec(const std::string &file, bool force); | |
| 19 | + | |
| 20 | + private: | |
| 21 | + static void static_ok_cb(Fl_Widget *w, void *data); | |
| 22 | + static void static_cancel_cb(Fl_Widget *w, void *data); | |
| 23 | +}; | |
| 24 | + | |
| 25 | +#endif |
| @@ -0,0 +1,13 @@ | ||
| 1 | +#include "dialog.hh" | |
| 2 | + | |
| 3 | +#include <FL/Fl_Window.H> | |
| 4 | + | |
| 5 | +void Dialog::ok_cb(Fl_Widget *w, void *dialog) { | |
| 6 | + (void)w; | |
| 7 | + ((Fl_Window *)dialog)->hide(); | |
| 8 | +} | |
| 9 | + | |
| 10 | +void Dialog::cancel_cb(Fl_Widget *w, void *dialog) { | |
| 11 | + (void)w; | |
| 12 | + ((Fl_Window *)dialog)->hide(); | |
| 13 | +} |
| @@ -0,0 +1,12 @@ | ||
| 1 | +#ifndef DIALOG_HH | |
| 2 | +#define DIALOG_HH | |
| 3 | + | |
| 4 | +#include <FL/Fl_Widget.H> | |
| 5 | + | |
| 6 | +class Dialog { | |
| 7 | + public: | |
| 8 | + static void ok_cb(Fl_Widget *w, void *dialog); | |
| 9 | + static void cancel_cb(Fl_Widget *w, void *dialog); | |
| 10 | +}; | |
| 11 | + | |
| 12 | +#endif |
| @@ -0,0 +1,189 @@ | ||
| 1 | +#include "common.hh" | |
| 2 | +#include "editpass.hh" | |
| 3 | +#include "delpass.hh" | |
| 4 | +#include "addpass.hh" | |
| 5 | +#include "../main.hh" | |
| 6 | + | |
| 7 | +#include <FL/Fl_Window.H> | |
| 8 | +#include <FL/fl_ask.H> | |
| 9 | + | |
| 10 | +#include <string> | |
| 11 | +#include <unistd.h> | |
| 12 | +#include <vector> | |
| 13 | + | |
| 14 | +Editpass edit; | |
| 15 | + | |
| 16 | +struct InputData { | |
| 17 | + Fl_Input *txtin; | |
| 18 | + Fl_Secret_Input *pass1; | |
| 19 | + Fl_Secret_Input *pass2; | |
| 20 | + Fl_Window *dialog; | |
| 21 | +}; | |
| 22 | + | |
| 23 | +void Editpass::setFile(std::string &f) { | |
| 24 | + edit.file = f; | |
| 25 | +} | |
| 26 | + | |
| 27 | +std::string Editpass::getFile() { | |
| 28 | + return file; | |
| 29 | +} | |
| 30 | + | |
| 31 | +bool Editpass::exec(const std::string &file, const std::string &pass) { | |
| 32 | + std::string lang = Common::getlang(); | |
| 33 | + | |
| 34 | + Common c; | |
| 35 | + c.tmpcopy(file, "/tmp/simpas-tmp.gpg"); | |
| 36 | + | |
| 37 | + Delpass d; | |
| 38 | + bool isdel = d.exec(file, true); | |
| 39 | + if (!isdel) { | |
| 40 | + std::string err = | |
| 41 | + (lang.compare(0, 2, "en") == 0 ? "Failed to edit." : "編集に失敗。"); | |
| 42 | + fl_alert("%s", err.c_str()); | |
| 43 | + return false; | |
| 44 | + } | |
| 45 | + | |
| 46 | + Addpass a; | |
| 47 | + bool isadd = a.exec(file, pass, true); | |
| 48 | + if (!isadd) { | |
| 49 | + std::string err = | |
| 50 | + (lang.compare(0, 2, "en") == 0 ? "Failed to edit." : "編集に失敗。"); | |
| 51 | + fl_alert("%s", err.c_str()); | |
| 52 | + // TODO: うまく動いているかの確認。それは次のバージョンから・・・ | |
| 53 | + /* std::vector<std::string> tokens = Common::explode(file, '/'); */ | |
| 54 | + /* std::string passpath = tokens[0]; */ | |
| 55 | + | |
| 56 | + /* for (size_t i = 1; i < tokens.size(); ++i) { */ | |
| 57 | + /* if (i == tokens.size() - 1) continue; */ | |
| 58 | + /* passpath += "/" + tokens[i]; */ | |
| 59 | + /* } */ | |
| 60 | + | |
| 61 | + /* for (int i = tokens.size() - 1; i >= 0; ++i) { */ | |
| 62 | + /* if (c.mkdir_r(passpath, 0755) == -1) break; */ | |
| 63 | + | |
| 64 | + /* size_t last_slash = passpath.find_last_of('/'); */ | |
| 65 | + /* if (last_slash != std::string::npos) passpath.erase(last_slash); */ | |
| 66 | + /* } */ | |
| 67 | + c.tmpcopy("/tmp/simpas-tmp.gpg", file); | |
| 68 | + unlink("/tmp/simpas-tmp.gpg"); | |
| 69 | + return false; | |
| 70 | + } | |
| 71 | + | |
| 72 | + std::string msg = | |
| 73 | + (lang.compare(0, 2, "en") == 0 ? "Edit success." : "編集に成功。"); | |
| 74 | + fl_alert("%s", msg.c_str()); | |
| 75 | + unlink("/tmp/simpas-tmp.gpg"); | |
| 76 | + | |
| 77 | + return true; | |
| 78 | +} | |
| 79 | + | |
| 80 | +void Editpass::edit_cb(Fl_Widget *, void *data) { | |
| 81 | + InputData *inputs = (InputData *)data; | |
| 82 | + std::string lang = Common::getlang(); | |
| 83 | + | |
| 84 | + if (inputs) { | |
| 85 | + file = inputs->txtin->value(); | |
| 86 | + if (file.empty()) { | |
| 87 | + std::string err = | |
| 88 | + (lang.compare(0, 2, "en") == 0 ? | |
| 89 | + "Please fill in the path." : | |
| 90 | + "パスをご入力下さい。"); | |
| 91 | + fl_alert("%s", err.c_str()); | |
| 92 | + return; | |
| 93 | + } | |
| 94 | + inputpass1 = inputs->pass1->value(); | |
| 95 | + if (inputpass1.empty()) { | |
| 96 | + std::string err = | |
| 97 | + (lang.compare(0, 2, "en") == 0 ? | |
| 98 | + "Please fill in the password." : | |
| 99 | + "パスワードをご入力下さい。"); | |
| 100 | + fl_alert("%s", err.c_str()); | |
| 101 | + return; | |
| 102 | + } | |
| 103 | + inputpass2 = inputs->pass2->value(); | |
| 104 | + if (inputpass2.empty()) { | |
| 105 | + std::string err = | |
| 106 | + (lang.compare(0, 2, "en") == 0 ? | |
| 107 | + "Please fill in the password (confirm)." : | |
| 108 | + "パスワード (確認)をご入力下さい。"); | |
| 109 | + fl_alert("%s", err.c_str()); | |
| 110 | + return; | |
| 111 | + } | |
| 112 | + | |
| 113 | + if (inputpass1 != inputpass2) { | |
| 114 | + std::string err = | |
| 115 | + (lang.compare(0, 2, "en") == 0 ? | |
| 116 | + "Password does not match." : | |
| 117 | + "パスワードが一致していません。"); | |
| 118 | + fl_alert("%s", err.c_str()); | |
| 119 | + return; | |
| 120 | + } | |
| 121 | + | |
| 122 | + if (exec(file, inputpass1)) { | |
| 123 | + inputs->dialog->hide(); | |
| 124 | + } | |
| 125 | + } else { | |
| 126 | + std::string err = | |
| 127 | + (lang.compare(0, 2, "en") == 0 ? | |
| 128 | + "Please fill in all the fields." : | |
| 129 | + "全てのフィールドをご入力下さい。"); | |
| 130 | + fl_alert("%s", err.c_str()); | |
| 131 | + } | |
| 132 | +} | |
| 133 | + | |
| 134 | +void Editpass::dialog_cb(Fl_Widget *w, void *data) { | |
| 135 | + (void)w; | |
| 136 | + (void)data; | |
| 137 | + std::string lang = Common::getlang(); | |
| 138 | + Fl_Window *dialog = new Fl_Window(400, 160, | |
| 139 | + (lang.compare(0, 2, "en") == 0 ? "Edit password" : "パスワードの編集")); | |
| 140 | + | |
| 141 | + Fl_Input *txtin = new Fl_Input(150, 20, 180, 30, | |
| 142 | + (lang.compare(0, 2, "en") == 0 ? "Path:" : "パス:")); | |
| 143 | + Fl_Secret_Input *pass1 = new Fl_Secret_Input(150, 20, 180, 30, | |
| 144 | + (lang.compare(0, 2, "en") == 0 ? "Password:" : "パスワード:")); | |
| 145 | + Fl_Secret_Input *pass2 = new Fl_Secret_Input(150, 60, 180, 30, | |
| 146 | + (lang.compare(0, 2, "en") == 0 ? "Password (confirm):" : "パスワード (確認):")); | |
| 147 | + dialog->add(pass1); | |
| 148 | + dialog->add(pass2); | |
| 149 | + txtin->hide(); | |
| 150 | + txtin->value(edit.getFile().c_str()); | |
| 151 | + | |
| 152 | + InputData *inputs = new InputData(); | |
| 153 | + inputs->txtin = txtin; | |
| 154 | + inputs->pass1 = pass1; | |
| 155 | + inputs->pass2 = pass2; | |
| 156 | + inputs->dialog = dialog; | |
| 157 | + | |
| 158 | + Fl_Button *okbtn = new Fl_Button(60, 110, 80, 30, "OK"); | |
| 159 | + Fl_Button *cancelbtn = new Fl_Button(160, 110, 80, 30, | |
| 160 | + (lang.compare(0, 2, "en") == 0 ? "Cancel" : "キャンセル")); | |
| 161 | + | |
| 162 | + okbtn->callback(static_ok_cb, inputs); | |
| 163 | + cancelbtn->callback(static_cancel_cb, dialog); | |
| 164 | + | |
| 165 | + dialog->add(okbtn); | |
| 166 | + dialog->add(cancelbtn); | |
| 167 | + | |
| 168 | + dialog->end(); | |
| 169 | + dialog->set_modal(); | |
| 170 | + dialog->show(); | |
| 171 | +} | |
| 172 | + | |
| 173 | +void Editpass::static_ok_cb(Fl_Widget *w, void *data) { | |
| 174 | + (void)w; | |
| 175 | + InputData *inputs = (InputData *)data; | |
| 176 | + | |
| 177 | + edit.edit_cb(nullptr, inputs); | |
| 178 | + std::vector<std::string> fpaths; | |
| 179 | + std::string rdir = Common::getbasedir(false); | |
| 180 | + std::string curpath = inputs->txtin->value(); | |
| 181 | + clearpaths(false, curpath); | |
| 182 | + scandir(rdir, rdir, fpaths); | |
| 183 | + updatelist(); | |
| 184 | + browse(curpath, false); | |
| 185 | +} | |
| 186 | + | |
| 187 | +void Editpass::static_cancel_cb(Fl_Widget *w, void *data) { | |
| 188 | + ((Editpass *)data)->cancel_cb(w, data); | |
| 189 | +} |
| @@ -0,0 +1,30 @@ | ||
| 1 | +#ifndef EDITPASS_HH | |
| 2 | +#define EDITPASS_HH | |
| 3 | + | |
| 4 | +#include <FL/Fl_Button.H> | |
| 5 | +#include <FL/Fl_Input.H> | |
| 6 | +#include <FL/Fl_Secret_Input.H> | |
| 7 | + | |
| 8 | +#include "dialog.hh" | |
| 9 | + | |
| 10 | +#include <string> | |
| 11 | + | |
| 12 | +class Editpass : public Dialog { | |
| 13 | + public: | |
| 14 | + Fl_Button *btn = nullptr; | |
| 15 | + std::string file; | |
| 16 | + std::string inputpass1; | |
| 17 | + std::string inputpass2; | |
| 18 | + | |
| 19 | + static void dialog_cb(Fl_Widget *w, void *); | |
| 20 | + void edit_cb(Fl_Widget *, void *data); | |
| 21 | + static void setFile(std::string &f); | |
| 22 | + std::string getFile(); | |
| 23 | + bool exec(const std::string &file, const std::string &pass); | |
| 24 | + | |
| 25 | + private: | |
| 26 | + static void static_ok_cb(Fl_Widget *w, void *data); | |
| 27 | + static void static_cancel_cb(Fl_Widget *w, void *data); | |
| 28 | +}; | |
| 29 | + | |
| 30 | +#endif |
| @@ -0,0 +1,108 @@ | ||
| 1 | +#include "common.hh" | |
| 2 | +#include "genpass.hh" | |
| 3 | + | |
| 4 | +#include <FL/Fl_Window.H> | |
| 5 | +#include <FL/fl_ask.H> | |
| 6 | + | |
| 7 | +#include <fstream> | |
| 8 | +#include <vector> | |
| 9 | + | |
| 10 | +Genpass gen; | |
| 11 | + | |
| 12 | +std::string Genpass::exec(int count, bool issecure) { | |
| 13 | + std::string lang = Common::getlang(); | |
| 14 | + | |
| 15 | + const std::string charset_risky = | |
| 16 | + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | |
| 17 | + const std::string charset_secure = | |
| 18 | + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()=~-^\\|_@`[{]};:+*<>,./?"; | |
| 19 | + const std::string &charset = issecure ? charset_secure : charset_risky; | |
| 20 | + | |
| 21 | + std::ifstream fp("/dev/random", std::ios_base::binary); | |
| 22 | + if (!fp.is_open()) { | |
| 23 | + std::string err = (lang.compare(0, 2, "en") == 0 ? | |
| 24 | + "Could not open /dev/random" : | |
| 25 | + "/dev/randomを開けられませんでした"); | |
| 26 | + fl_alert("%s", err.c_str()); | |
| 27 | + return ""; | |
| 28 | + } | |
| 29 | + | |
| 30 | + std::vector<char> password(count + 1); | |
| 31 | + for (int i = 0; i < count; ++i) { | |
| 32 | + unsigned char key; | |
| 33 | + fp.read(reinterpret_cast<char *>(&key), sizeof(key)); | |
| 34 | + if (!fp) { | |
| 35 | + std::string err = (lang.compare(0, 2, "en") == 0 ? | |
| 36 | + "Could not read /dev/random" : | |
| 37 | + "/dev/randomから読み込みに失敗"); | |
| 38 | + fl_alert("%s", err.c_str()); | |
| 39 | + fp.close(); | |
| 40 | + std::exit(EXIT_FAILURE); | |
| 41 | + } | |
| 42 | + | |
| 43 | + password[i] = charset[key % charset.size()]; | |
| 44 | + } | |
| 45 | + | |
| 46 | + password[count] = '\0'; | |
| 47 | + fp.close(); | |
| 48 | + | |
| 49 | + return std::string(password.data()); | |
| 50 | +} | |
| 51 | + | |
| 52 | +void Genpass::generate_cb(Fl_Widget *, void *) { | |
| 53 | + int count = std::stoi(gen.counter->value()); | |
| 54 | + bool issecure = gen.securechk->value() > 0; | |
| 55 | + | |
| 56 | + std::string password = gen.exec(count, issecure); | |
| 57 | + gen.res->value(password.c_str()); | |
| 58 | +} | |
| 59 | + | |
| 60 | +void Genpass::dialog_cb(Fl_Widget *w, void *) { | |
| 61 | + (void)w; | |
| 62 | + std::string lang = Common::getlang(); | |
| 63 | + Fl_Window *dialog = new Fl_Window(450, 250, | |
| 64 | + (lang.compare(0, 2, "en") == 0 ? "Generate password" : "パスワードの作成")); | |
| 65 | + | |
| 66 | + gen.counter = new Fl_Input(120, 20, 100, 30, | |
| 67 | + (lang.compare(0, 2, "en") == 0 ? "Length:" : "長さ:")); | |
| 68 | + gen.counter->type(FL_INT_INPUT); | |
| 69 | + gen.counter->value("64"); | |
| 70 | + dialog->add(gen.counter); | |
| 71 | + | |
| 72 | + gen.securechk = new Fl_Check_Button(120, 70, 150, 30, | |
| 73 | + (lang.compare(0, 2, "en") == 0 ? "Secure?" : "安全化?")); | |
| 74 | + gen.securechk->value(1); | |
| 75 | + dialog->add(gen.securechk); | |
| 76 | + | |
| 77 | + gen.genbtn = new Fl_Button(120, 110, 150, 30, | |
| 78 | + (lang.compare(0, 2, "en") == 0 ? "Generate" : "作成")); | |
| 79 | + gen.genbtn->callback(generate_cb); | |
| 80 | + dialog->add(gen.genbtn); | |
| 81 | + | |
| 82 | + gen.res = new Fl_Output(120, 150, 300, 30, | |
| 83 | + (lang.compare(0, 2, "en") == 0 ? "Password:" : "パスワード:")); | |
| 84 | + gen.res->value(""); | |
| 85 | + dialog->add(gen.res); | |
| 86 | + | |
| 87 | + Fl_Button *okbtn = new Fl_Button(60, 200, 80, 30, "OK"); | |
| 88 | + Fl_Button *cancelbtn = new Fl_Button(160, 200, 80, 30, | |
| 89 | + (lang.compare(0, 2, "en") == 0 ? "Cancel" : "キャンセル")); | |
| 90 | + | |
| 91 | + okbtn->callback(static_ok_cb, dialog); | |
| 92 | + cancelbtn->callback(static_cancel_cb, dialog); | |
| 93 | + | |
| 94 | + dialog->add(okbtn); | |
| 95 | + dialog->add(cancelbtn); | |
| 96 | + | |
| 97 | + dialog->end(); | |
| 98 | + dialog->set_modal(); | |
| 99 | + dialog->show(); | |
| 100 | +} | |
| 101 | + | |
| 102 | +void Genpass::static_ok_cb(Fl_Widget *w, void *data) { | |
| 103 | + ((Genpass *)data)->ok_cb(w, data); | |
| 104 | +} | |
| 105 | + | |
| 106 | +void Genpass::static_cancel_cb(Fl_Widget *w, void *data) { | |
| 107 | + ((Genpass *)data)->cancel_cb(w, data); | |
| 108 | +} |
| @@ -0,0 +1,33 @@ | ||
| 1 | +#ifndef GENPASS_HH | |
| 2 | +#define GENPASS_HH | |
| 3 | + | |
| 4 | +#include <FL/Fl_Button.H> | |
| 5 | +#include <FL/Fl_Input.H> | |
| 6 | +#include <FL/Fl_Secret_Input.H> | |
| 7 | +#include <FL/Fl_Check_Button.H> | |
| 8 | +#include <FL/Fl_Button.H> | |
| 9 | +#include <FL/Fl_Output.H> | |
| 10 | + | |
| 11 | +#include <string> | |
| 12 | + | |
| 13 | +#include "dialog.hh" | |
| 14 | + | |
| 15 | +class Genpass : public Dialog { | |
| 16 | + public: | |
| 17 | + Fl_Button *btn = nullptr; | |
| 18 | + | |
| 19 | + std::string exec(int count, bool issecure); | |
| 20 | + static void dialog_cb(Fl_Widget *w, void *); | |
| 21 | + static void generate_cb(Fl_Widget *, void *data); | |
| 22 | + | |
| 23 | + private: | |
| 24 | + Fl_Input *counter = nullptr; | |
| 25 | + Fl_Check_Button *securechk = nullptr; | |
| 26 | + Fl_Button *genbtn = nullptr; | |
| 27 | + Fl_Output *res = nullptr; | |
| 28 | + | |
| 29 | + static void static_ok_cb(Fl_Widget *w, void *data); | |
| 30 | + static void static_cancel_cb(Fl_Widget *w, void *data); | |
| 31 | +}; | |
| 32 | + | |
| 33 | +#endif |
| @@ -0,0 +1,58 @@ | ||
| 1 | +#include "common.hh" | |
| 2 | +#include "initpass.hh" | |
| 3 | + | |
| 4 | +#include <FL/Fl_Window.H> | |
| 5 | +#include <FL/fl_ask.H> | |
| 6 | + | |
| 7 | +#include <cerrno> | |
| 8 | +#include <fstream> | |
| 9 | +#include <iostream> | |
| 10 | +#include <string> | |
| 11 | + | |
| 12 | +#include <sys/stat.h> | |
| 13 | + | |
| 14 | +Initpass init; | |
| 15 | + | |
| 16 | +void Initpass::exec(const std::string &gpgid) { | |
| 17 | + std::string lang = Common::getlang(); | |
| 18 | + std::string basedir = Common::getbasedir(true); | |
| 19 | + | |
| 20 | + Common common; | |
| 21 | + if (common.mkdir_r(basedir, 0755) != 0 && errno != EEXIST) { | |
| 22 | + std::cout << basedir << std::endl; | |
| 23 | + std::string err = (lang.compare(0, 2, "en") == 0 ? | |
| 24 | + "Failed to create directory." : | |
| 25 | + "ディレクトリを作成に失敗。"); | |
| 26 | + fl_alert("%s", err.c_str()); | |
| 27 | + return; | |
| 28 | + } | |
| 29 | + | |
| 30 | + std::string gpgidpath = basedir + "/.gpg-id"; | |
| 31 | + | |
| 32 | + struct stat statbuf; | |
| 33 | + if (stat(gpgidpath.c_str(), &statbuf) == 0) { | |
| 34 | + std::string err = (lang.compare(0, 2, "en") == 0 ? | |
| 35 | + ".gpg-id file already exists." : | |
| 36 | + ".gpg-idファイルは既に存在します。"); | |
| 37 | + fl_alert("%s", err.c_str()); | |
| 38 | + return; | |
| 39 | + } | |
| 40 | + | |
| 41 | + std::ofstream gpgidfile(gpgidpath); | |
| 42 | + if (!gpgidfile.is_open()) { | |
| 43 | + std::string err = (lang.compare(0, 2, "en") == 0 ? | |
| 44 | + "Failed to write .gpg-id file." : | |
| 45 | + ".gpg-idファイルを書き込めません。"); | |
| 46 | + fl_alert("%s", err.c_str()); | |
| 47 | + return; | |
| 48 | + } | |
| 49 | + | |
| 50 | + gpgidfile << gpgid + '\n'; | |
| 51 | + | |
| 52 | + gpgidfile.close(); | |
| 53 | + | |
| 54 | + std::string msg = (lang.compare(0, 2, "en") == 0 ? | |
| 55 | + "Initialization completed." : | |
| 56 | + "初期設定に完了しました。"); | |
| 57 | + fl_alert("%s", msg.c_str()); | |
| 58 | +} |
| @@ -0,0 +1,19 @@ | ||
| 1 | +#ifndef INITPASS_HH | |
| 2 | +#define INITPASS_HH | |
| 3 | + | |
| 4 | +#include <FL/Fl_Button.H> | |
| 5 | +#include <FL/Fl_Input.H> | |
| 6 | + | |
| 7 | +#include <string> | |
| 8 | + | |
| 9 | +#include "dialog.hh" | |
| 10 | + | |
| 11 | +class Initpass : public Dialog { | |
| 12 | + public: | |
| 13 | + Fl_Button *btn = nullptr; | |
| 14 | + Fl_Input *gpgid = nullptr; | |
| 15 | + | |
| 16 | + void exec(const std::string &gpgid); | |
| 17 | +}; | |
| 18 | + | |
| 19 | +#endif |
| @@ -0,0 +1,119 @@ | ||
| 1 | +#include "common.hh" | |
| 2 | +#include "base32.hh" | |
| 3 | +#include "otppass.hh" | |
| 4 | + | |
| 5 | +#include <openssl/hmac.h> | |
| 6 | +#include <openssl/sha.h> | |
| 7 | + | |
| 8 | +#include <FL/fl_ask.H> | |
| 9 | + | |
| 10 | +#if defined(__APPLE) | |
| 11 | +#include <libkern/OSByteOrder.h> | |
| 12 | +#define htobe64(x) OSSwapHostToBigInt64(x) | |
| 13 | +#endif | |
| 14 | + | |
| 15 | +std::vector<unsigned char> Otppass::extract_secret(const std::string &otpauth_url) { | |
| 16 | + std::string lang = Common::getlang(); | |
| 17 | + | |
| 18 | + auto secret_start = otpauth_url.find("secret="); | |
| 19 | + if (secret_start == std::string::npos) { | |
| 20 | + std::string err = (lang.compare(0, 2, "en") == 0 ? | |
| 21 | + "Failed to find secret in the OTPAuth URL" : | |
| 22 | + "OTPAuth URLの中に、シークレットを見つけられませんでした"); | |
| 23 | + fl_alert("%s", err.c_str()); | |
| 24 | + return {}; | |
| 25 | + } | |
| 26 | + secret_start += 7; | |
| 27 | + | |
| 28 | + auto secret_end = otpauth_url.find('&', secret_start); | |
| 29 | + if (secret_end == std::string::npos) { | |
| 30 | + secret_end = otpauth_url.length(); | |
| 31 | + } | |
| 32 | + | |
| 33 | + if (secret_end < secret_start) { | |
| 34 | + std::string err = (lang.compare(0, 2, "en") == 0 ? | |
| 35 | + "Incorrect secret range" : | |
| 36 | + "不正なシークレットの距離"); | |
| 37 | + fl_alert("%s", err.c_str()); | |
| 38 | + return {}; | |
| 39 | + } | |
| 40 | + | |
| 41 | + std::string secret_encoded = | |
| 42 | + otpauth_url.substr(secret_start, secret_end - secret_start); | |
| 43 | + | |
| 44 | + std::vector<unsigned char> secret_decoded; | |
| 45 | + secret_decoded = Base32::decode(secret_encoded.c_str()); | |
| 46 | + | |
| 47 | + if (secret_decoded.empty()) { | |
| 48 | + std::string err = (lang.compare(0, 2, "en") == 0 ? | |
| 49 | + "Failed to decrypt BASE32" : | |
| 50 | + "BASE32の復号化に失敗"); | |
| 51 | + fl_alert("%s", err.c_str()); | |
| 52 | + return {}; | |
| 53 | + } | |
| 54 | + | |
| 55 | + return secret_decoded; | |
| 56 | +} | |
| 57 | + | |
| 58 | +#if defined(__HAIKU__) || defined(__linux) | |
| 59 | +uint64_t Otppass::htobe64(uint64_t counter) { | |
| 60 | + uint64_t res = 0; | |
| 61 | + uint8_t *dest = reinterpret_cast<uint8_t*>(&res); | |
| 62 | + const uint8_t *src = reinterpret_cast<const uint8_t*>(&counter); | |
| 63 | + | |
| 64 | + for (int i = 0; i < 8; ++i) { | |
| 65 | + dest[i] = src[7 - i]; | |
| 66 | + } | |
| 67 | + | |
| 68 | + return res; | |
| 69 | +} | |
| 70 | +#endif | |
| 71 | + | |
| 72 | +uint32_t Otppass::generate_totp(const std::vector<unsigned char> &secret, | |
| 73 | + uint64_t counter) { | |
| 74 | + counter = htobe64(counter); | |
| 75 | + | |
| 76 | + unsigned char hash[SHA_DIGEST_LENGTH]; | |
| 77 | + HMAC( | |
| 78 | + EVP_sha1(), | |
| 79 | + secret.data(), | |
| 80 | + secret.size(), | |
| 81 | + reinterpret_cast<unsigned char *>(&counter), | |
| 82 | + sizeof(counter), | |
| 83 | + hash, | |
| 84 | + NULL | |
| 85 | + ); | |
| 86 | + | |
| 87 | + int offset = hash[SHA_DIGEST_LENGTH - 1] & 0x0F; | |
| 88 | + uint32_t truncated_hash = | |
| 89 | + (hash[offset] & 0x7F) << 24 | | |
| 90 | + (hash[offset + 1] & 0xFF) << 16 | | |
| 91 | + (hash[offset + 2] & 0xFF) << 8 | | |
| 92 | + (hash[offset + 3] & 0xFF); | |
| 93 | + | |
| 94 | + return truncated_hash % 1000000; | |
| 95 | +} | |
| 96 | + | |
| 97 | +std::string Otppass::exec(std::string &secret) { | |
| 98 | + std::string lang = Common::getlang(); | |
| 99 | + | |
| 100 | + try { | |
| 101 | + std::vector<unsigned char> secret_decoded = extract_secret(secret); | |
| 102 | + | |
| 103 | + time_t current_time = time(nullptr); | |
| 104 | + uint64_t counter = current_time / 30; | |
| 105 | + uint32_t otp = | |
| 106 | + generate_totp(secret_decoded, counter); | |
| 107 | + | |
| 108 | + char otpres[7]; | |
| 109 | + std::snprintf(otpres, sizeof(otpres), "%06u", otp); | |
| 110 | + | |
| 111 | + return std::string(otpres); | |
| 112 | + } catch (const std::exception &e) { | |
| 113 | + std::string err = (lang.compare(0, 2, "en") == 0 ? | |
| 114 | + "Error" : | |
| 115 | + "エラー"); | |
| 116 | + fl_alert("%s: %s", err.c_str(), e.what()); | |
| 117 | + return ""; | |
| 118 | + } | |
| 119 | +} |
| @@ -0,0 +1,21 @@ | ||
| 1 | +#ifndef OTPPASS_HH | |
| 2 | +#define OTPPASS_HH | |
| 3 | + | |
| 4 | +#include <cstdint> | |
| 5 | +#include <string> | |
| 6 | +#include <vector> | |
| 7 | + | |
| 8 | +class Otppass { | |
| 9 | + public: | |
| 10 | + std::string exec(std::string &file); | |
| 11 | + | |
| 12 | + private: | |
| 13 | + std::vector<unsigned char> extract_secret(const std::string &otpauth_url); | |
| 14 | +#if defined(__HAIKU__) || defined(__linux) | |
| 15 | + uint64_t htobe64(uint64_t counter); | |
| 16 | +#endif | |
| 17 | + uint32_t generate_totp(const std::vector<unsigned char> &secret, | |
| 18 | + uint64_t counter); | |
| 19 | +}; | |
| 20 | + | |
| 21 | +#endif |
| @@ -0,0 +1,129 @@ | ||
| 1 | +#include "common.hh" | |
| 2 | +#include "showpass.hh" | |
| 3 | +#include "../main.hh" | |
| 4 | +#include "otppass.hh" | |
| 5 | + | |
| 6 | +#include <gpgme++/decryptionresult.h> | |
| 7 | + | |
| 8 | +#undef Status | |
| 9 | +#undef None | |
| 10 | +#include <FL/Fl.H> | |
| 11 | +#include <FL/fl_ask.H> | |
| 12 | +#include <FL/Fl_Text_Buffer.H> | |
| 13 | +#include <FL/Fl_Text_Display.H> | |
| 14 | + | |
| 15 | +void Showpass::otpupdate_cb(void *o) { | |
| 16 | + Showpass *show = static_cast<Showpass *>(o); | |
| 17 | + Otppass otp; | |
| 18 | + | |
| 19 | + if (!show->otpSav.empty()) { | |
| 20 | + std::string dec = otp.exec(show->otpSav); | |
| 21 | + | |
| 22 | + realpass = dec; | |
| 23 | + if (!isPassHidden) { | |
| 24 | + textbuf->text(dec.c_str()); | |
| 25 | + textview->redraw(); | |
| 26 | + } | |
| 27 | + } | |
| 28 | + | |
| 29 | + Fl::repeat_timeout(1.0, otpupdate_cb, o); | |
| 30 | +} | |
| 31 | + | |
| 32 | +std::string Showpass::exec(const char *file, bool stfu) { | |
| 33 | + std::string lang = Common::getlang(); | |
| 34 | + | |
| 35 | + try { | |
| 36 | + std::setlocale(LC_ALL, ""); | |
| 37 | + GpgME::initializeLibrary(); | |
| 38 | + | |
| 39 | + gpg_error_t err = gpg_err_init(); | |
| 40 | + if (err) { | |
| 41 | + if (!stfu) { | |
| 42 | + std::string ero = (lang.compare(0, 2, "en") == 0 ? | |
| 43 | + "Failed to generate GPGME" : | |
| 44 | + "GPGエラーの設置に失敗"); | |
| 45 | + fl_alert("%s: %s", ero.c_str(), gpg_strerror(err)); | |
| 46 | + } | |
| 47 | + return ""; | |
| 48 | + } | |
| 49 | + | |
| 50 | + std::unique_ptr<GpgME::Context> ctx = | |
| 51 | + GpgME::Context::create(GpgME::Protocol::OpenPGP); | |
| 52 | + if (!ctx) { | |
| 53 | + if (!stfu) { | |
| 54 | + std::string ero = (lang.compare(0, 2, "en") == 0 ? | |
| 55 | + "Failed to create GPGME context" : | |
| 56 | + "GPGMEコンテキストの作成に失敗"); | |
| 57 | + fl_alert("%s", ero.c_str()); | |
| 58 | + } | |
| 59 | + return ""; | |
| 60 | + } | |
| 61 | + | |
| 62 | + if (ctx->protocol() != GpgME::Protocol::OpenPGP) { | |
| 63 | + if (!stfu) { | |
| 64 | + std::string ero = (lang.compare(0, 2, "en") == 0 ? | |
| 65 | + "Failed to set OpenPGP protocol" : | |
| 66 | + "OpenPGPプロトコールの設置に失敗"); | |
| 67 | + fl_alert("%s", ero.c_str()); | |
| 68 | + } | |
| 69 | + return ""; | |
| 70 | + } | |
| 71 | + | |
| 72 | + std::ifstream gpgfile(file, std::ios::binary); | |
| 73 | + if (!gpgfile.is_open()) { | |
| 74 | + if (!stfu) { | |
| 75 | + std::string ero = (lang.compare(0, 2, "en") == 0 ? | |
| 76 | + "Unable to open the specified file" : | |
| 77 | + "指定されたファイルを開けません"); | |
| 78 | + fl_alert("%s", ero.c_str()); | |
| 79 | + } | |
| 80 | + return ""; | |
| 81 | + } | |
| 82 | + | |
| 83 | + GpgME::Data in(file); | |
| 84 | + GpgME::Data out; | |
| 85 | + | |
| 86 | + GpgME::DecryptionResult res = ctx->decrypt(in, out); | |
| 87 | + if (res.error()) { | |
| 88 | + if (!stfu) { | |
| 89 | + std::string ero = (lang.compare(0, 2, "en") == 0 ? | |
| 90 | + "Failed to decrypt" : | |
| 91 | + "復号化に失敗"); | |
| 92 | + fl_alert("%s: %s", ero.c_str(), res.error().asString()); | |
| 93 | + } | |
| 94 | + return ""; | |
| 95 | + } | |
| 96 | + | |
| 97 | + std::string dec; | |
| 98 | + char buf[512]; | |
| 99 | + ssize_t read_bytes; | |
| 100 | + | |
| 101 | + out.seek(0, SEEK_SET); | |
| 102 | + | |
| 103 | + while ((read_bytes = out.read(buf, sizeof(buf))) > 0) { | |
| 104 | + dec.append(buf, read_bytes); | |
| 105 | + } | |
| 106 | + | |
| 107 | + if (dec.rfind("otpauth://", 0) == 0 && !stfu) { | |
| 108 | + Otppass o; | |
| 109 | + otpSav = dec; | |
| 110 | + | |
| 111 | + Fl::remove_timeout(otpupdate_cb, this); | |
| 112 | + Fl::add_timeout(1.0, otpupdate_cb, this); | |
| 113 | + | |
| 114 | + return o.exec(dec); | |
| 115 | + } | |
| 116 | + | |
| 117 | + Fl::remove_timeout(otpupdate_cb, this); | |
| 118 | + otpSav = ""; | |
| 119 | + return dec; | |
| 120 | + } catch (const std::exception &e) { | |
| 121 | + if (!stfu) { | |
| 122 | + std::string err = (lang.compare(0, 2, "en") == 0 ? | |
| 123 | + "Error" : | |
| 124 | + "エラー"); | |
| 125 | + fl_alert("%s: %s", err.c_str(), e.what()); | |
| 126 | + } | |
| 127 | + return ""; | |
| 128 | + } | |
| 129 | +} |
| @@ -0,0 +1,21 @@ | ||
| 1 | +#ifndef SHOWPASS_HH | |
| 2 | +#define SHOWPASS_HH | |
| 3 | + | |
| 4 | +#include <gpgme++/context.h> | |
| 5 | +#include <gpgme++/data.h> | |
| 6 | + | |
| 7 | +#include <fstream> | |
| 8 | + | |
| 9 | +class Showpass { | |
| 10 | + public: | |
| 11 | + std::string otpSav = ""; | |
| 12 | + | |
| 13 | + static void otpupdate_cb(void *o); | |
| 14 | + std::string exec(const char *file, bool stfu); | |
| 15 | + | |
| 16 | + private: | |
| 17 | + void clean_up(GpgME::Context &ctx, GpgME::Data &in, GpgME::Data &out, | |
| 18 | + std::ifstream &gpgfile); | |
| 19 | +}; | |
| 20 | + | |
| 21 | +#endif |
| @@ -0,0 +1,198 @@ | ||
| 1 | +#include "common.hh" | |
| 2 | +#include "vulnpass.hh" | |
| 3 | +#include "showpass.hh" | |
| 4 | +#include "../main.hh" | |
| 5 | + | |
| 6 | +#include <FL/Fl.H> | |
| 7 | +#include <FL/Fl_Window.H> | |
| 8 | +#include <FL/fl_ask.H> | |
| 9 | +#include <FL/Fl_Box.H> | |
| 10 | +#include <FL/Fl_Button.H> | |
| 11 | +#include <FL/Fl_Text_Display.H> | |
| 12 | +#include <FL/Fl_Text_Buffer.H> | |
| 13 | +#include <FL/Fl_Scrollbar.H> | |
| 14 | + | |
| 15 | +#include <vector> | |
| 16 | +#include <string> | |
| 17 | +#include <thread> | |
| 18 | + | |
| 19 | +#include <unistd.h> | |
| 20 | +#include <arpa/inet.h> | |
| 21 | +#include <sys/types.h> | |
| 22 | +#include <sys/socket.h> | |
| 23 | +#include <netdb.h> | |
| 24 | +#include <netinet/in.h> | |
| 25 | + | |
| 26 | +Vulnpass vuln; | |
| 27 | +int vulncount = 0; | |
| 28 | +std::vector<std::string> vulnpaths; | |
| 29 | + | |
| 30 | +bool Vulnpass::exec() { | |
| 31 | + std::string lang = Common::getlang(); | |
| 32 | + | |
| 33 | + // pwndサーバに接続 | |
| 34 | + int sock; | |
| 35 | + struct sockaddr_in srv; | |
| 36 | + struct addrinfo hints, *addr; | |
| 37 | + | |
| 38 | + memset(&hints, 0, sizeof(hints)); | |
| 39 | + hints.ai_family = AF_INET; | |
| 40 | + hints.ai_socktype = SOCK_STREAM; | |
| 41 | + | |
| 42 | + int status = getaddrinfo("076.moe", nullptr, &hints, &addr); | |
| 43 | + if (status != 0) { | |
| 44 | + fl_alert("getaddrinfo: %s", gai_strerror(status)); | |
| 45 | + return false; | |
| 46 | + } | |
| 47 | + | |
| 48 | + sock = socket(AF_INET, SOCK_STREAM, 0); | |
| 49 | + if (sock == -1) { | |
| 50 | + fl_alert(lang.compare(0, 2, "en") == 0 ? | |
| 51 | + "Failed to create socket" : "ソケットを作成に失敗"); | |
| 52 | + return false; | |
| 53 | + } | |
| 54 | + | |
| 55 | + srv.sin_addr = ((struct sockaddr_in *)(addr->ai_addr))->sin_addr; | |
| 56 | + srv.sin_family = AF_INET; | |
| 57 | + srv.sin_port = htons(9951); | |
| 58 | + | |
| 59 | + freeaddrinfo(addr); | |
| 60 | + | |
| 61 | + if (connect(sock, (struct sockaddr *)&srv, sizeof(srv)) < 0) { | |
| 62 | + fl_alert(lang.compare(0, 2, "en") == 0 ? | |
| 63 | + "Failed to connect" : "接続に失敗"); | |
| 64 | + close(sock); | |
| 65 | + return false; | |
| 66 | + } | |
| 67 | + | |
| 68 | + // パスワードをスキャンして | |
| 69 | + Showpass show; | |
| 70 | + | |
| 71 | + for (const auto &dispath : dispaths) { | |
| 72 | + std::string fullpath = Common::getbasedir(true) + dispath + ".gpg"; | |
| 73 | + std::string pass = show.exec(fullpath.c_str(), true); | |
| 74 | + if (pass.empty()) continue; | |
| 75 | + | |
| 76 | + if (send(sock, pass.c_str(), pass.length(), 0) < 0) { | |
| 77 | + fl_alert(lang.compare(0, 2, "en") == 0 ? | |
| 78 | + "Failed to send" : "送信に失敗"); | |
| 79 | + close(sock); | |
| 80 | + return false; | |
| 81 | + } | |
| 82 | + | |
| 83 | + char res[256] = {0}; | |
| 84 | + int reslen = recv(sock, res, sizeof(res) - 1, 0); | |
| 85 | + if (reslen < 0) { | |
| 86 | + fl_alert(lang.compare(0, 2, "en") == 0 ? | |
| 87 | + "Failed to retrieve" : "受取に失敗"); | |
| 88 | + close(sock); | |
| 89 | + return false; | |
| 90 | + } | |
| 91 | + | |
| 92 | + res[reslen] = '\0'; | |
| 93 | + std::string response(res); | |
| 94 | + | |
| 95 | + if (response.compare(0, 1, "0") != 0) { | |
| 96 | + vulnpaths.push_back(dispath); | |
| 97 | + vulncount++; | |
| 98 | + } | |
| 99 | + | |
| 100 | + close(sock); | |
| 101 | + | |
| 102 | + // 再接続 | |
| 103 | + sock = socket(AF_INET, SOCK_STREAM, 0); | |
| 104 | + if (sock == -1) { | |
| 105 | + fl_alert(lang.compare(0, 2, "en") == 0 ? | |
| 106 | + "Failed to create socket" : "ソケットを作成に失敗"); | |
| 107 | + return false; | |
| 108 | + } | |
| 109 | + | |
| 110 | + if (connect(sock, (struct sockaddr *)&srv, sizeof(srv)) < 0) { | |
| 111 | + fl_alert(lang.compare(0, 2, "en") == 0 ? | |
| 112 | + "Failed to reconnect" : "再接続に失敗"); | |
| 113 | + close(sock); | |
| 114 | + return false; | |
| 115 | + } | |
| 116 | + } | |
| 117 | + | |
| 118 | + close(sock); | |
| 119 | + | |
| 120 | + return true; | |
| 121 | +} | |
| 122 | + | |
| 123 | +void Vulnpass::showRes() { | |
| 124 | + std::string lang = Common::getlang(); | |
| 125 | + | |
| 126 | + std::string res; | |
| 127 | + if (lang.compare(0, 2, "en") == 0) { | |
| 128 | + res = "Breached passwords:\n"; | |
| 129 | + } else { | |
| 130 | + res = "漏洩したパスワード:\n"; | |
| 131 | + } | |
| 132 | + | |
| 133 | + for (const auto &path : vulnpaths) { | |
| 134 | + res += path + "\n"; | |
| 135 | + } | |
| 136 | + | |
| 137 | + if (lang.compare(0, 2, "en") == 0) { | |
| 138 | + res += "Total: " + std::to_string(vulnpaths.size()) + "\n"; | |
| 139 | + res += "It's advised to change any of the"; | |
| 140 | + res += "breached passwords as soon as possible!"; | |
| 141 | + } else { | |
| 142 | + res += "合計: " + std::to_string(vulnpaths.size()) + "\n"; | |
| 143 | + res += "漏洩したパスワードは出来るだけ早く変更する事をお勧めします!"; | |
| 144 | + } | |
| 145 | + | |
| 146 | + Fl_Window *win = new Fl_Window(500, 440, lang.compare(0, 2, "en") == 0 ? | |
| 147 | + "Results" : "結果"); | |
| 148 | + Fl_Text_Display *display = new Fl_Text_Display(10, 10, 480, 380); | |
| 149 | + Fl_Text_Buffer *textbuf = new Fl_Text_Buffer(); | |
| 150 | + | |
| 151 | + textbuf->text(res.c_str()); | |
| 152 | + display->buffer(textbuf); | |
| 153 | + display->scrollbar_width(15); | |
| 154 | + win->resizable(display); | |
| 155 | + | |
| 156 | + Fl_Button *okBtn = new Fl_Button(210, 400, 80, 30, "OK"); | |
| 157 | + okBtn->callback([](Fl_Widget *widget, void *win) { | |
| 158 | + (void)widget; | |
| 159 | + reinterpret_cast<Fl_Window*>(win)->hide(); | |
| 160 | + }, win); | |
| 161 | + | |
| 162 | + win->add(okBtn); | |
| 163 | + | |
| 164 | + win->end(); | |
| 165 | + win->show(); | |
| 166 | +} | |
| 167 | + | |
| 168 | +void Vulnpass::dialog_cb(Fl_Widget *w, void *) { | |
| 169 | + (void)w; | |
| 170 | + | |
| 171 | + std::string lang = Common::getlang(); | |
| 172 | + | |
| 173 | + Fl_Window *dialog = new Fl_Window(400, 50, | |
| 174 | + (lang.compare(0, 2, "en") == 0 ? | |
| 175 | + "Check for branched password" : "漏洩されたパスワードの確認")); | |
| 176 | + | |
| 177 | + Fl_Box *box = new Fl_Box(10, 10, 380, 20, | |
| 178 | + (lang.compare(0, 2, "en") == 0 ? | |
| 179 | + "Checking, please wait for a while..." : | |
| 180 | + "確認中。暫くお待ち下さい・・・")); | |
| 181 | + | |
| 182 | + dialog->add(box); | |
| 183 | + | |
| 184 | + dialog->end(); | |
| 185 | + dialog->set_modal(); | |
| 186 | + dialog->show(); | |
| 187 | + | |
| 188 | + std::thread checker([dialog]() { | |
| 189 | + vuln.exec(); | |
| 190 | + | |
| 191 | + Fl::lock(); | |
| 192 | + dialog->hide(); | |
| 193 | + vuln.showRes(); | |
| 194 | + Fl::unlock(); | |
| 195 | + }); | |
| 196 | + | |
| 197 | + checker.detach(); | |
| 198 | +} |
| @@ -0,0 +1,18 @@ | ||
| 1 | +#ifndef VULNPASS_HH | |
| 2 | +#define VULNPASS_HH | |
| 3 | + | |
| 4 | +#include <FL/Fl_Button.H> | |
| 5 | + | |
| 6 | +#include "dialog.hh" | |
| 7 | + | |
| 8 | +class Vulnpass : public Dialog { | |
| 9 | + public: | |
| 10 | + Fl_Button *btn = nullptr; | |
| 11 | + | |
| 12 | + static void dialog_cb(Fl_Widget *w, void *); | |
| 13 | + void vuln_cb(Fl_Widget *, void *); | |
| 14 | + bool exec(); | |
| 15 | + void showRes(); | |
| 16 | +}; | |
| 17 | + | |
| 18 | +#endif |