This commit is contained in:
parent
1d4ffa2602
commit
26b6b53b8c
12 changed files with 152 additions and 41 deletions
21
Makefile
21
Makefile
|
@ -3,27 +3,26 @@ CXX = g++
|
||||||
LD = g++
|
LD = g++
|
||||||
CXXFLAGS = -std=c++17 -Wall -Werror -Wpointer-arith -Wfatal-errors
|
CXXFLAGS = -std=c++17 -Wall -Werror -Wpointer-arith -Wfatal-errors
|
||||||
CFLAGS = -Wall -Werror -Wpointer-arith -Wfatal-errors
|
CFLAGS = -Wall -Werror -Wpointer-arith -Wfatal-errors
|
||||||
DEBUG = -g
|
|
||||||
|
|
||||||
prefix=/usr/local
|
#prefix=/usr/local
|
||||||
|
|
||||||
OBJECTS = build/memdb.o build/spmemvfs.o build/crypto.o build/Manager.o build/Database.o
|
OBJECTS = build/memdb.o build/spmemvfs.o build/crypto.o build/Manager.o build/Database.o
|
||||||
|
|
||||||
all: build/shepherd
|
all: shepherd
|
||||||
|
|
||||||
build/shepherd: build/shepherd.o $(OBJECTS)
|
build/shepherd: build/shepherd.o $(OBJECTS)
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
@echo link $@
|
@echo link $@
|
||||||
@$(LD) $(CXXFLAGS) $^ -o $@ -lsqlite3 -lsodium -lstdc++fs
|
@$(LD) $(CXXFLAGS) $^ -o $@ -lsqlite3 -lsodium -lstdc++fs
|
||||||
|
|
||||||
build/test: build/testmemvfs.o $(OBJECTS)
|
build/test: build/shepherd.o $(OBJECTS)
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
@echo link $@
|
@echo link $@
|
||||||
@$(LD) $(CXXFLAGS) $^ -o $@ -lsqlite3 -lsodium -lstdc++fs
|
@$(LD) $(CXXFLAGS) $^ -o $@ -lsqlite3 -lsodium -lstdc++fs
|
||||||
|
|
||||||
build/%.o: src/%.cpp src/%.h
|
build/%.o: src/%.cpp src/%.h
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
@echo complie $@
|
@echo compile $@
|
||||||
@$(CXX) $(CXXFLAGS) -c -o $@ $<
|
@$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
build/%.o: src/%.c src/%.h
|
build/%.o: src/%.c src/%.h
|
||||||
|
@ -36,15 +35,17 @@ rsa: rsa.cpp
|
||||||
$(CC) $(CFLAGS) rsa.cpp -o bin/rsa -lssl -lcrypto
|
$(CC) $(CFLAGS) rsa.cpp -o bin/rsa -lssl -lcrypto
|
||||||
|
|
||||||
install: build/shepherd
|
install: build/shepherd
|
||||||
install -m 0755 $@ $(prefix)/bin
|
install -m 0755 $^ $(DESTDIR)/usr/bin
|
||||||
|
|
||||||
.PHONY: test
|
shepherd: build/shepherd
|
||||||
test:
|
|
||||||
test/test.sh test/test.db
|
#.PHONY: test
|
||||||
|
#test: build/test
|
||||||
|
# test/test.sh test/test.db
|
||||||
|
|
||||||
# remove produced files, invoke as "make clean"
|
# remove produced files, invoke as "make clean"
|
||||||
clean:
|
clean:
|
||||||
@echo clean build*
|
@echo clean build/*
|
||||||
@rm -f build/*
|
@rm -f build/*
|
||||||
|
|
||||||
#%.o : %.cpp
|
#%.o : %.cpp
|
||||||
|
|
6
debian/README.Debian
vendored
Normal file
6
debian/README.Debian
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
shepherd for Debian
|
||||||
|
------------------
|
||||||
|
|
||||||
|
<possible notes regarding this package - if none, delete this file>
|
||||||
|
|
||||||
|
-- jedi <pkg@j3d1.de> Mon, 14 Dec 2020 20:11:42 +0100
|
10
debian/README.source
vendored
Normal file
10
debian/README.source
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
shepherd for Debian
|
||||||
|
------------------
|
||||||
|
|
||||||
|
<this file describes information about the source package, see Debian policy
|
||||||
|
manual section 4.14. You WILL either need to modify or delete this file>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- jedi <pkg@j3d1.de> Mon, 14 Dec 2020 20:11:42 +0100
|
||||||
|
|
5
debian/changelog
vendored
Normal file
5
debian/changelog
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
shepherd (0.9-1) unstable; urgency=medium
|
||||||
|
|
||||||
|
* Initial release
|
||||||
|
|
||||||
|
-- jedi <pkg@j3d1.de> Mon, 14 Dec 2020 19:32:43 +0100
|
16
debian/control
vendored
Normal file
16
debian/control
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
Source: shepherd
|
||||||
|
Section: unknown
|
||||||
|
Priority: optional
|
||||||
|
Maintainer: jedi <pkg@j3d1.de>
|
||||||
|
Build-Depends: debhelper-compat (= 13), libsodium-dev, libsqlite3-dev
|
||||||
|
Standards-Version: 4.5.1
|
||||||
|
Homepage: https://git.neulandlabor.de/j3d1/shepherd
|
||||||
|
#Vcs-Browser: https://salsa.debian.org/debian/shepherd
|
||||||
|
#Vcs-Git: https://salsa.debian.org/debian/shepherd.git
|
||||||
|
Rules-Requires-Root: no
|
||||||
|
|
||||||
|
Package: shepherd
|
||||||
|
Architecture: any
|
||||||
|
Depends: ${shlibs:Depends}, ${misc:Depends}, libsodium23, libsqlite3-0
|
||||||
|
Description: <insert up to 60 chars description>
|
||||||
|
<insert long description, indented with spaces>
|
43
debian/copyright
vendored
Normal file
43
debian/copyright
vendored
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||||
|
Upstream-Name: shepherd
|
||||||
|
Upstream-Contact: <preferred name and address to reach the upstream project>
|
||||||
|
Source: <url://example.com>
|
||||||
|
|
||||||
|
Files: *
|
||||||
|
Copyright: <years> <put author's name and email here>
|
||||||
|
<years> <likewise for another author>
|
||||||
|
License: <special license>
|
||||||
|
<Put the license of the package here indented by 1 space>
|
||||||
|
<This follows the format of Description: lines in control file>
|
||||||
|
.
|
||||||
|
<Including paragraphs>
|
||||||
|
|
||||||
|
# If you want to use GPL v2 or later for the /debian/* files use
|
||||||
|
# the following clauses, or change it to suit. Delete these two lines
|
||||||
|
Files: debian/*
|
||||||
|
Copyright: 2020 jedi <pkg@j3d1.de>
|
||||||
|
License: GPL-2+
|
||||||
|
This package is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
.
|
||||||
|
This package is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
.
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
.
|
||||||
|
On Debian systems, the complete text of the GNU General
|
||||||
|
Public License version 2 can be found in "/usr/share/common-licenses/GPL-2".
|
||||||
|
|
||||||
|
# Please also look if there are files or directories which have a
|
||||||
|
# different copyright/license attached and list them here.
|
||||||
|
# Please avoid picking licenses with terms that are more restrictive than the
|
||||||
|
# packaged work, as it may make Debian's contributions unacceptable upstream.
|
||||||
|
#
|
||||||
|
# If you need, there are some extra license texts available in two places:
|
||||||
|
# /usr/share/debhelper/dh_make/licenses/
|
||||||
|
# /usr/share/common-licenses/
|
1
debian/dirs
vendored
Normal file
1
debian/dirs
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
usr/bin
|
25
debian/rules
vendored
Executable file
25
debian/rules
vendored
Executable file
|
@ -0,0 +1,25 @@
|
||||||
|
#!/usr/bin/make -f
|
||||||
|
# See debhelper(7) (uncomment to enable)
|
||||||
|
# output every command that modifies files on the build system.
|
||||||
|
#export DH_VERBOSE = 1
|
||||||
|
|
||||||
|
|
||||||
|
# see FEATURE AREAS in dpkg-buildflags(1)
|
||||||
|
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
|
||||||
|
|
||||||
|
# see ENVIRONMENT in dpkg-buildflags(1)
|
||||||
|
# package maintainers to append CFLAGS
|
||||||
|
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
|
||||||
|
# package maintainers to append LDFLAGS
|
||||||
|
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
|
||||||
|
|
||||||
|
|
||||||
|
%:
|
||||||
|
dh $@
|
||||||
|
|
||||||
|
|
||||||
|
# dh_make generated override targets
|
||||||
|
# This is example for Cmake (See https://bugs.debian.org/641051 )
|
||||||
|
#override_dh_auto_configure:
|
||||||
|
# dh_auto_configure -- \
|
||||||
|
# -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)
|
1
debian/source/format
vendored
Normal file
1
debian/source/format
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
3.0 (quilt)
|
|
@ -2,6 +2,7 @@
|
||||||
// Created by jedi on 3/16/19.
|
// Created by jedi on 3/16/19.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
@ -11,10 +12,12 @@
|
||||||
|
|
||||||
#define CONTEXT "SHEPHERD"
|
#define CONTEXT "SHEPHERD"
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
namespace shepherd::crypto {
|
namespace shepherd::crypto {
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
static char getch() {
|
static char getch() {
|
||||||
char buf = 0;
|
char buf = 0;
|
||||||
struct termios old = {0};
|
struct termios old = {0};
|
||||||
|
@ -70,18 +73,15 @@ namespace shepherd::crypto {
|
||||||
|
|
||||||
kdf_t ret;
|
kdf_t ret;
|
||||||
|
|
||||||
|
|
||||||
//master key
|
//master key
|
||||||
if (crypto_pwhash
|
if (crypto_pwhash
|
||||||
(ret.master_key, sizeof ret.master_key, secret.c_str(), secret.size(), file->salt,
|
(ret.master_key, sizeof ret.master_key, secret.c_str(), secret.size(), file->salt,
|
||||||
crypto_pwhash_OPSLIMIT_INTERACTIVE, crypto_pwhash_MEMLIMIT_INTERACTIVE,
|
crypto_pwhash_OPSLIMIT_INTERACTIVE, crypto_pwhash_MEMLIMIT_INTERACTIVE,
|
||||||
crypto_pwhash_ALG_DEFAULT) != 0) {
|
crypto_pwhash_ALG_DEFAULT) != 0) {
|
||||||
/* out of memory */
|
/* out of memory */
|
||||||
std::cerr << "errör" << std::endl;
|
abort();
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//used key
|
//used key
|
||||||
crypto_kdf_derive_from_key(ret.key, sizeof ret.key, 2, CONTEXT, ret.master_key);
|
crypto_kdf_derive_from_key(ret.key, sizeof ret.key, 2, CONTEXT, ret.master_key);
|
||||||
|
|
||||||
|
@ -107,6 +107,10 @@ namespace shepherd::crypto {
|
||||||
}
|
}
|
||||||
|
|
||||||
void save(const std::string filename, bytes buf) {
|
void save(const std::string filename, bytes buf) {
|
||||||
|
fs::path p(filename);
|
||||||
|
if(!fs::exists(p.parent_path())){
|
||||||
|
fs::create_directory(p.parent_path());
|
||||||
|
}
|
||||||
std::ofstream ofs(filename, std::ios::out | std::ios::binary);
|
std::ofstream ofs(filename, std::ios::out | std::ios::binary);
|
||||||
ofs.write((char *) buf.data(), buf.size());
|
ofs.write((char *) buf.data(), buf.size());
|
||||||
ofs.close();
|
ofs.close();
|
||||||
|
@ -180,7 +184,7 @@ namespace shepherd::crypto {
|
||||||
file->nonce, pw_key.key) != 0) {
|
file->nonce, pw_key.key) != 0) {
|
||||||
/* message forged! */
|
/* message forged! */
|
||||||
|
|
||||||
std::cerr << "errör" << std::endl;
|
std::cerr << "could not decrypting file" << std::endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,13 @@ namespace shepherd{
|
||||||
std::cerr << "no dbfile found" << std::endl;
|
std::cerr << "no dbfile found" << std::endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}else{
|
}else if(std::filesystem::exists("/home/jedi/.shepherd/passwd.db")){
|
||||||
std::cerr << "Error: No such file" << std::endl;
|
std::cerr << "Error: No such file " << path_ << std::endl;
|
||||||
|
std::cerr << "importing old version " << std::endl;
|
||||||
buf_ = crypto::load("/home/jedi/.shepherd/passwd.db");
|
buf_ = crypto::load("/home/jedi/.shepherd/passwd.db");
|
||||||
|
}else{
|
||||||
|
std::cerr << "Error: No such file" << path_ << std::endl;
|
||||||
|
std::cerr << "creating new db" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
mem_->total = mem_->used = buf_.size();
|
mem_->total = mem_->used = buf_.size();
|
||||||
|
|
|
@ -12,17 +12,12 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
constexpr unsigned int arg(const char* str, int h = 0) {
|
|
||||||
return !str[h] ? 5381 : (arg(str, h + 1) * 33) ^ str[h];
|
|
||||||
}
|
|
||||||
|
|
||||||
using namespace shepherd;
|
using namespace shepherd;
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
srand(time(NULL));
|
|
||||||
int opt, index;
|
int opt, index;
|
||||||
string file = getenv("HOME");
|
const string home = getenv("HOME");
|
||||||
file += "/.shepherd/passwd.herd";
|
string file = home + "/.shepherd/passwd.herd";
|
||||||
|
|
||||||
const struct option longopts[] = {
|
const struct option longopts[] = {
|
||||||
{"version", no_argument, 0, 'v'},
|
{"version", no_argument, 0, 'v'},
|
||||||
|
@ -88,34 +83,30 @@ int main(int argc, char *argv[]) {
|
||||||
std::string pw = crypto::read_pw();
|
std::string pw = crypto::read_pw();
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
//char c;
|
|
||||||
//while (std::cin.get(c)) // loop getting single characters
|
|
||||||
// std::cout << c;
|
|
||||||
|
|
||||||
//std::cin.close();
|
|
||||||
|
|
||||||
/*if(!std::filesystem::exists("~/.shepherd/passwd.herd")){
|
|
||||||
std::cerr << "default file not found" << std::endl;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//shepherd::memdb db(file,"foo");
|
//shepherd::memdb db(file,"foo");
|
||||||
|
|
||||||
//db.save();
|
|
||||||
//exit(0);
|
|
||||||
|
|
||||||
{
|
try {
|
||||||
Manager mg(file, pw);
|
Manager mg(file, pw);
|
||||||
|
|
||||||
switch (argc - optind) {
|
switch (argc - optind) {
|
||||||
case 0:
|
case 0:
|
||||||
mg.show();
|
cerr << "Usage: "<< endl;
|
||||||
|
cerr << "\t" << argv[0] << " <account identifier>" << endl;
|
||||||
|
cerr << "\t" << argv[0] << " gen <account identifier>" << endl;
|
||||||
|
cerr << "\t" << argv[0] << " add <account identifier>" << endl;
|
||||||
|
cerr << "\t" << argv[0] << " del <account identifier>" << endl;
|
||||||
|
cerr << "\t" << argv[0] << " all" << endl;
|
||||||
|
cerr << "\t" << argv[0] << " clear all" << endl;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
mg.get(argv[optind]);
|
mg.get(argv[optind]);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (!strcmp(argv[optind], "clear")) {
|
if (!strcmp(argv[optind], "all")) {
|
||||||
|
mg.show();
|
||||||
|
} else if (!strcmp(argv[optind], "clear")) {
|
||||||
if (!strcmp(argv[optind + 1], "all")) {
|
if (!strcmp(argv[optind + 1], "all")) {
|
||||||
mg.clear();
|
mg.clear();
|
||||||
cerr << file << " cleared" << endl;
|
cerr << file << " cleared" << endl;
|
||||||
|
@ -134,7 +125,11 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} catch(...){
|
||||||
|
cerr << "unhandled error" << endl;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
exit (EXIT_SUCCESS);
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue