mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 12:00:56 +01:00
initial commit
This commit is contained in:
9
src/Makefile.am
Normal file
9
src/Makefile.am
Normal file
@@ -0,0 +1,9 @@
|
||||
EXTRA_DIST = z85util.c
|
||||
|
||||
AM_CFLAGS = -I../libpcp -Wall -g
|
||||
|
||||
bin_PROGRAMS = pcp1
|
||||
|
||||
pcp1_LDADD = ../libpcp/.libs/libpcp1.a
|
||||
pcp1_SOURCES = pcp.c keymgmt.c keyprint.c readpass.c encryption.c z85util.c
|
||||
|
||||
561
src/Makefile.in
Normal file
561
src/Makefile.in
Normal file
@@ -0,0 +1,561 @@
|
||||
# Makefile.in generated by automake 1.12.4 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994-2012 Free Software Foundation, Inc.
|
||||
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
@SET_MAKE@
|
||||
|
||||
VPATH = @srcdir@
|
||||
am__make_dryrun = \
|
||||
{ \
|
||||
am__dry=no; \
|
||||
case $$MAKEFLAGS in \
|
||||
*\\[\ \ ]*) \
|
||||
echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \
|
||||
| grep '^AM OK$$' >/dev/null || am__dry=yes;; \
|
||||
*) \
|
||||
for am__flg in $$MAKEFLAGS; do \
|
||||
case $$am__flg in \
|
||||
*=*|--*) ;; \
|
||||
*n*) am__dry=yes; break;; \
|
||||
esac; \
|
||||
done;; \
|
||||
esac; \
|
||||
test $$am__dry = yes; \
|
||||
}
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkglibexecdir = $(libexecdir)/@PACKAGE@
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
install_sh_DATA = $(install_sh) -c -m 644
|
||||
install_sh_PROGRAM = $(install_sh) -c
|
||||
install_sh_SCRIPT = $(install_sh) -c
|
||||
INSTALL_HEADER = $(INSTALL_DATA)
|
||||
transform = $(program_transform_name)
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
bin_PROGRAMS = pcp1$(EXEEXT)
|
||||
subdir = src
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
|
||||
$(top_srcdir)/config/depcomp
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/config/libtool.m4 \
|
||||
$(top_srcdir)/config/ltoptions.m4 \
|
||||
$(top_srcdir)/config/ltsugar.m4 \
|
||||
$(top_srcdir)/config/ltversion.m4 \
|
||||
$(top_srcdir)/config/lt~obsolete.m4 $(top_srcdir)/configure.ac
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
mkinstalldirs = $(install_sh) -d
|
||||
CONFIG_HEADER = $(top_builddir)/libpcp/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
CONFIG_CLEAN_VPATH_FILES =
|
||||
am__installdirs = "$(DESTDIR)$(bindir)"
|
||||
PROGRAMS = $(bin_PROGRAMS)
|
||||
am_pcp1_OBJECTS = pcp.$(OBJEXT) keymgmt.$(OBJEXT) keyprint.$(OBJEXT) \
|
||||
readpass.$(OBJEXT) encryption.$(OBJEXT) z85util.$(OBJEXT)
|
||||
pcp1_OBJECTS = $(am_pcp1_OBJECTS)
|
||||
pcp1_DEPENDENCIES = ../libpcp/.libs/libpcp1.a
|
||||
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/libpcp
|
||||
depcomp = $(SHELL) $(top_srcdir)/config/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
am__mv = mv -f
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
|
||||
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
|
||||
$(LDFLAGS) -o $@
|
||||
SOURCES = $(pcp1_SOURCES)
|
||||
DIST_SOURCES = $(pcp1_SOURCES)
|
||||
am__can_run_installinfo = \
|
||||
case $$AM_UPDATE_INFO_DIR in \
|
||||
n|no|NO) false;; \
|
||||
*) (install-info --version) >/dev/null 2>&1;; \
|
||||
esac
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AMTAR = @AMTAR@
|
||||
AR = @AR@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
CC = @CC@
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
DLLTOOL = @DLLTOOL@
|
||||
DSYMUTIL = @DSYMUTIL@
|
||||
DUMPBIN = @DUMPBIN@
|
||||
ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
FGREP = @FGREP@
|
||||
GREP = @GREP@
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
LD = @LD@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LIPO = @LIPO@
|
||||
LN_S = @LN_S@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
MANIFEST_TOOL = @MANIFEST_TOOL@
|
||||
MKDIR_P = @MKDIR_P@
|
||||
NM = @NM@
|
||||
NMEDIT = @NMEDIT@
|
||||
OBJDUMP = @OBJDUMP@
|
||||
OBJEXT = @OBJEXT@
|
||||
OTOOL = @OTOOL@
|
||||
OTOOL64 = @OTOOL64@
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_STRING = @PACKAGE_STRING@
|
||||
PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
||||
PACKAGE_URL = @PACKAGE_URL@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
RANLIB = @RANLIB@
|
||||
SED = @SED@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
VERSION = @VERSION@
|
||||
abs_builddir = @abs_builddir@
|
||||
abs_srcdir = @abs_srcdir@
|
||||
abs_top_builddir = @abs_top_builddir@
|
||||
abs_top_srcdir = @abs_top_srcdir@
|
||||
ac_ct_AR = @ac_ct_AR@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
bindir = @bindir@
|
||||
build = @build@
|
||||
build_alias = @build_alias@
|
||||
build_cpu = @build_cpu@
|
||||
build_os = @build_os@
|
||||
build_vendor = @build_vendor@
|
||||
builddir = @builddir@
|
||||
datadir = @datadir@
|
||||
datarootdir = @datarootdir@
|
||||
docdir = @docdir@
|
||||
dvidir = @dvidir@
|
||||
exec_prefix = @exec_prefix@
|
||||
host = @host@
|
||||
host_alias = @host_alias@
|
||||
host_cpu = @host_cpu@
|
||||
host_os = @host_os@
|
||||
host_vendor = @host_vendor@
|
||||
htmldir = @htmldir@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localedir = @localedir@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
oldincludedir = @oldincludedir@
|
||||
pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
top_build_prefix = @top_build_prefix@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
EXTRA_DIST = z85util.c
|
||||
AM_CFLAGS = -I../libpcp -Wall -g
|
||||
pcp1_LDADD = ../libpcp/.libs/libpcp1.a
|
||||
pcp1_SOURCES = pcp.c keymgmt.c keyprint.c readpass.c encryption.c z85util.c
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .lo .o .obj
|
||||
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
|
||||
@for dep in $?; do \
|
||||
case '$(am__configure_deps)' in \
|
||||
*$$dep*) \
|
||||
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
|
||||
&& { if test -f $@; then exit 0; else break; fi; }; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \
|
||||
$(am__cd) $(top_srcdir) && \
|
||||
$(AUTOMAKE) --gnu src/Makefile
|
||||
.PRECIOUS: Makefile
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
*config.status*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
|
||||
*) \
|
||||
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
|
||||
esac;
|
||||
|
||||
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
$(top_srcdir)/configure: $(am__configure_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(am__aclocal_m4_deps):
|
||||
install-binPROGRAMS: $(bin_PROGRAMS)
|
||||
@$(NORMAL_INSTALL)
|
||||
@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
|
||||
if test -n "$$list"; then \
|
||||
echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \
|
||||
$(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \
|
||||
fi; \
|
||||
for p in $$list; do echo "$$p $$p"; done | \
|
||||
sed 's/$(EXEEXT)$$//' | \
|
||||
while read p p1; do if test -f $$p || test -f $$p1; \
|
||||
then echo "$$p"; echo "$$p"; else :; fi; \
|
||||
done | \
|
||||
sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \
|
||||
-e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
|
||||
sed 'N;N;N;s,\n, ,g' | \
|
||||
$(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
|
||||
{ d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
|
||||
if ($$2 == $$4) files[d] = files[d] " " $$1; \
|
||||
else { print "f", $$3 "/" $$4, $$1; } } \
|
||||
END { for (d in files) print "f", d, files[d] }' | \
|
||||
while read type dir files; do \
|
||||
if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
|
||||
test -z "$$files" || { \
|
||||
echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \
|
||||
$(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \
|
||||
} \
|
||||
; done
|
||||
|
||||
uninstall-binPROGRAMS:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
|
||||
files=`for p in $$list; do echo "$$p"; done | \
|
||||
sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
|
||||
-e 's/$$/$(EXEEXT)/' `; \
|
||||
test -n "$$list" || exit 0; \
|
||||
echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \
|
||||
cd "$(DESTDIR)$(bindir)" && rm -f $$files
|
||||
|
||||
clean-binPROGRAMS:
|
||||
@list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \
|
||||
echo " rm -f" $$list; \
|
||||
rm -f $$list || exit $$?; \
|
||||
test -n "$(EXEEXT)" || exit 0; \
|
||||
list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
|
||||
echo " rm -f" $$list; \
|
||||
rm -f $$list
|
||||
pcp1$(EXEEXT): $(pcp1_OBJECTS) $(pcp1_DEPENDENCIES) $(EXTRA_pcp1_DEPENDENCIES)
|
||||
@rm -f pcp1$(EXEEXT)
|
||||
$(LINK) $(pcp1_OBJECTS) $(pcp1_LDADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/encryption.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/keymgmt.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/keyprint.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pcp.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readpass.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/z85util.Po@am__quote@
|
||||
|
||||
.c.o:
|
||||
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
|
||||
|
||||
.c.obj:
|
||||
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
|
||||
|
||||
.c.lo:
|
||||
@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
||||
clean-libtool:
|
||||
-rm -rf .libs _libs
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
|
||||
END { if (nonempty) { for (i in files) print i; }; }'`; \
|
||||
mkid -fID $$unique
|
||||
tags: TAGS
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
set x; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
|
||||
END { if (nonempty) { for (i in files) print i; }; }'`; \
|
||||
shift; \
|
||||
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
|
||||
test -n "$$unique" || unique=$$empty_fix; \
|
||||
if test $$# -gt 0; then \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
"$$@" $$unique; \
|
||||
else \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
$$unique; \
|
||||
fi; \
|
||||
fi
|
||||
ctags: CTAGS
|
||||
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
|
||||
END { if (nonempty) { for (i in files) print i; }; }'`; \
|
||||
test -z "$(CTAGS_ARGS)$$unique" \
|
||||
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
|
||||
$$unique
|
||||
|
||||
GTAGS:
|
||||
here=`$(am__cd) $(top_builddir) && pwd` \
|
||||
&& $(am__cd) $(top_srcdir) \
|
||||
&& gtags -i $(GTAGS_ARGS) "$$here"
|
||||
|
||||
cscopelist: $(HEADERS) $(SOURCES) $(LISP)
|
||||
list='$(SOURCES) $(HEADERS) $(LISP)'; \
|
||||
case "$(srcdir)" in \
|
||||
[\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
|
||||
*) sdir=$(subdir)/$(srcdir) ;; \
|
||||
esac; \
|
||||
for i in $$list; do \
|
||||
if test -f "$$i"; then \
|
||||
echo "$(subdir)/$$i"; \
|
||||
else \
|
||||
echo "$$sdir/$$i"; \
|
||||
fi; \
|
||||
done >> $(top_builddir)/cscope.files
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
|
||||
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
|
||||
list='$(DISTFILES)'; \
|
||||
dist_files=`for file in $$list; do echo $$file; done | \
|
||||
sed -e "s|^$$srcdirstrip/||;t" \
|
||||
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
|
||||
case $$dist_files in \
|
||||
*/*) $(MKDIR_P) `echo "$$dist_files" | \
|
||||
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
|
||||
sort -u` ;; \
|
||||
esac; \
|
||||
for file in $$dist_files; do \
|
||||
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
|
||||
if test -d $$d/$$file; then \
|
||||
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
|
||||
if test -d "$(distdir)/$$file"; then \
|
||||
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
|
||||
fi; \
|
||||
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
|
||||
cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
|
||||
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
|
||||
fi; \
|
||||
cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
|
||||
else \
|
||||
test -f "$(distdir)/$$file" \
|
||||
|| cp -p $$d/$$file "$(distdir)/$$file" \
|
||||
|| exit 1; \
|
||||
fi; \
|
||||
done
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
all-am: Makefile $(PROGRAMS)
|
||||
installdirs:
|
||||
for dir in "$(DESTDIR)$(bindir)"; do \
|
||||
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
|
||||
done
|
||||
install: install-am
|
||||
install-exec: install-exec-am
|
||||
install-data: install-data-am
|
||||
uninstall: uninstall-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
|
||||
installcheck: installcheck-am
|
||||
install-strip:
|
||||
if test -z '$(STRIP)'; then \
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
install; \
|
||||
else \
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
|
||||
fi
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
|
||||
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
|
||||
|
||||
maintainer-clean-generic:
|
||||
@echo "This command is intended for maintainers to use"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
clean: clean-am
|
||||
|
||||
clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am
|
||||
|
||||
distclean: distclean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
distclean-am: clean-am distclean-compile distclean-generic \
|
||||
distclean-tags
|
||||
|
||||
dvi: dvi-am
|
||||
|
||||
dvi-am:
|
||||
|
||||
html: html-am
|
||||
|
||||
html-am:
|
||||
|
||||
info: info-am
|
||||
|
||||
info-am:
|
||||
|
||||
install-data-am:
|
||||
|
||||
install-dvi: install-dvi-am
|
||||
|
||||
install-dvi-am:
|
||||
|
||||
install-exec-am: install-binPROGRAMS
|
||||
|
||||
install-html: install-html-am
|
||||
|
||||
install-html-am:
|
||||
|
||||
install-info: install-info-am
|
||||
|
||||
install-info-am:
|
||||
|
||||
install-man:
|
||||
|
||||
install-pdf: install-pdf-am
|
||||
|
||||
install-pdf-am:
|
||||
|
||||
install-ps: install-ps-am
|
||||
|
||||
install-ps-am:
|
||||
|
||||
installcheck-am:
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
|
||||
mostlyclean-libtool
|
||||
|
||||
pdf: pdf-am
|
||||
|
||||
pdf-am:
|
||||
|
||||
ps: ps-am
|
||||
|
||||
ps-am:
|
||||
|
||||
uninstall-am: uninstall-binPROGRAMS
|
||||
|
||||
.MAKE: install-am install-strip
|
||||
|
||||
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
|
||||
clean-generic clean-libtool cscopelist ctags distclean \
|
||||
distclean-compile distclean-generic distclean-libtool \
|
||||
distclean-tags distdir dvi dvi-am html html-am info info-am \
|
||||
install install-am install-binPROGRAMS install-data \
|
||||
install-data-am install-dvi install-dvi-am install-exec \
|
||||
install-exec-am install-html install-html-am install-info \
|
||||
install-info-am install-man install-pdf install-pdf-am \
|
||||
install-ps install-ps-am install-strip installcheck \
|
||||
installcheck-am installdirs maintainer-clean \
|
||||
maintainer-clean-generic mostlyclean mostlyclean-compile \
|
||||
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
|
||||
tags uninstall uninstall-am uninstall-binPROGRAMS
|
||||
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
||||
247
src/encryption.c
Normal file
247
src/encryption.c
Normal file
@@ -0,0 +1,247 @@
|
||||
#include "encryption.h"
|
||||
|
||||
int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd) {
|
||||
FILE *in = NULL;
|
||||
FILE *out = NULL;
|
||||
pcp_pubkey_t *public = NULL;
|
||||
pcp_key_t *secret = NULL;
|
||||
|
||||
if(useid) {
|
||||
HASH_FIND_STR(pcpkey_hash, id, secret);
|
||||
if(secret == NULL) {
|
||||
fatal("Could not find a secret key with id 0x%s in vault %s!\n",
|
||||
id, vault->filename);
|
||||
goto errde3;
|
||||
}
|
||||
}
|
||||
else {
|
||||
secret = pcp_find_primary_secret();
|
||||
if(secret == NULL) {
|
||||
fatal("Could not find a secret key in vault %s!\n", id, vault->filename);
|
||||
goto errde3;
|
||||
}
|
||||
}
|
||||
|
||||
if(infile == NULL)
|
||||
in = stdin;
|
||||
else {
|
||||
if((in = fopen(infile, "rb")) == NULL) {
|
||||
fatal("Could not open input file %s\n", infile);
|
||||
goto errde2;
|
||||
}
|
||||
}
|
||||
|
||||
if(outfile == NULL)
|
||||
out = stdout;
|
||||
else {
|
||||
if((out = fopen(outfile, "wb+")) == NULL) {
|
||||
fatal("Could not open output file %s\n", outfile);
|
||||
goto errde2;
|
||||
}
|
||||
}
|
||||
|
||||
if(secret->secret[0] == 0) {
|
||||
// encrypted, decrypt it
|
||||
char *passphrase;
|
||||
if(passwd == NULL) {
|
||||
pcp_readpass(&passphrase,
|
||||
"Enter passphrase to decrypt your secret key", NULL, 1);
|
||||
}
|
||||
else {
|
||||
passphrase = ucmalloc(strlen(passwd)+1);
|
||||
strncpy(passphrase, passwd, strlen(passwd)+1);
|
||||
}
|
||||
|
||||
secret = pcpkey_decrypt(secret, passphrase);
|
||||
if(secret == NULL)
|
||||
goto errde3;
|
||||
}
|
||||
|
||||
char *encoded = pcp_readz85file(in);
|
||||
if(encoded == NULL)
|
||||
goto errde2;
|
||||
|
||||
size_t clen;
|
||||
unsigned char *combined = pcp_z85_decode((char *)encoded, &clen);
|
||||
|
||||
if(combined == NULL)
|
||||
goto errde1;
|
||||
|
||||
char *senderid = ucmalloc(17);
|
||||
memcpy(senderid, combined, 16);
|
||||
senderid[16] = '\0';
|
||||
|
||||
HASH_FIND_STR(pcppubkey_hash, senderid, public);
|
||||
if(public == NULL) {
|
||||
fatal("Could not find a public key with id 0x%s in vault %s!\n",
|
||||
senderid, vault->filename);
|
||||
goto errde0;
|
||||
}
|
||||
|
||||
if(debug) {
|
||||
fprintf(stderr, "Using secret key:\n");
|
||||
pcpkey_printshortinfo(secret);
|
||||
fprintf(stderr, "Using publickey:\n");
|
||||
pcppubkey_printshortinfo(public);
|
||||
}
|
||||
|
||||
unsigned char *encrypted = ucmalloc(clen - 16);
|
||||
memcpy(encrypted, &combined[16], clen - 16);
|
||||
|
||||
size_t dlen;
|
||||
unsigned char *decrypted = pcp_box_decrypt(secret, public,
|
||||
encrypted, clen - 16, &dlen);
|
||||
|
||||
if(decrypted != NULL) {
|
||||
fwrite(decrypted, dlen, 1, out);
|
||||
fclose(out);
|
||||
if(ferror(out) != 0) {
|
||||
fatal("Failed to write decrypted output!\n");
|
||||
}
|
||||
free(decrypted);
|
||||
}
|
||||
|
||||
fprintf(stderr, "Decrypted %d bytes from 0x%s successfully\n",
|
||||
(int)dlen, senderid);
|
||||
|
||||
free(encrypted);
|
||||
|
||||
errde0:
|
||||
free(senderid);
|
||||
free(combined);
|
||||
|
||||
errde1:
|
||||
free(encoded);
|
||||
|
||||
errde2:
|
||||
|
||||
errde3:
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int pcpencrypt(char *id, char *infile, char *outfile, char *passwd) {
|
||||
FILE *in = NULL;
|
||||
FILE *out = NULL;
|
||||
pcp_pubkey_t *public = NULL;
|
||||
pcp_key_t *secret = NULL;
|
||||
|
||||
// look if we've got that key
|
||||
HASH_FIND_STR(pcppubkey_hash, id, public);
|
||||
if(public == NULL) {
|
||||
fatal("Could not find a public key with id 0x%s in vault %s!\n",
|
||||
id, vault->filename);
|
||||
goto erren3;
|
||||
}
|
||||
|
||||
secret = pcp_find_primary_secret();
|
||||
if(secret == NULL) {
|
||||
fatal("Could not find a secret key in vault %s!\n", id, vault->filename);
|
||||
goto erren2;
|
||||
}
|
||||
|
||||
if(infile == NULL)
|
||||
in = stdin;
|
||||
else {
|
||||
if((in = fopen(infile, "rb")) == NULL) {
|
||||
fatal("Could not open input file %s\n", infile);
|
||||
goto erren1;
|
||||
}
|
||||
}
|
||||
|
||||
if(outfile == NULL)
|
||||
out = stdout;
|
||||
else {
|
||||
if((out = fopen(outfile, "wb+")) == NULL) {
|
||||
fatal("Could not open output file %s\n", outfile);
|
||||
goto erren1;
|
||||
}
|
||||
}
|
||||
|
||||
if(secret->secret[0] == 0) {
|
||||
// encrypted, decrypt it
|
||||
char *passphrase;
|
||||
if(passwd == NULL) {
|
||||
pcp_readpass(&passphrase,
|
||||
"Enter passphrase to decrypt your secret key", NULL, 1);
|
||||
}
|
||||
else {
|
||||
passphrase = ucmalloc(strlen(passwd)+1);
|
||||
strncpy(passphrase, passwd, strlen(passwd)+1);
|
||||
}
|
||||
secret = pcpkey_decrypt(secret, passphrase);
|
||||
if(secret == NULL)
|
||||
goto erren2;
|
||||
}
|
||||
|
||||
if(debug) {
|
||||
fprintf(stderr, "Using secret key:\n");
|
||||
pcpkey_printshortinfo(secret);
|
||||
fprintf(stderr, "Using publickey:\n");
|
||||
pcppubkey_printshortinfo(public);
|
||||
}
|
||||
|
||||
unsigned char *input = NULL;
|
||||
size_t inputBufSize = 0;
|
||||
unsigned char byte[1];
|
||||
|
||||
while(!feof(in)) {
|
||||
if(!fread(&byte, 1, 1, in))
|
||||
break;
|
||||
unsigned char *tmp = realloc(input, inputBufSize + 1);
|
||||
input = tmp;
|
||||
memmove(&input[inputBufSize], byte, 1);
|
||||
inputBufSize ++;
|
||||
}
|
||||
fclose(in);
|
||||
|
||||
if(inputBufSize == 0) {
|
||||
fatal("Input file is empty!\n");
|
||||
goto erren1;
|
||||
}
|
||||
|
||||
size_t ciphersize;
|
||||
unsigned char *cipher = pcp_box_encrypt(secret, public, input,
|
||||
inputBufSize, &ciphersize);
|
||||
if(cipher == NULL)
|
||||
goto erren1;
|
||||
|
||||
size_t zlen;
|
||||
size_t clen = ciphersize + 16;
|
||||
unsigned char *combined = ucmalloc(clen);
|
||||
memcpy(combined, secret->id, 16);
|
||||
memcpy(&combined[16], cipher, clen - 16);
|
||||
|
||||
// combined consists of:
|
||||
// keyid|nonce|cipher
|
||||
char *encoded = pcp_z85_encode(combined, clen, &zlen);
|
||||
|
||||
if(encoded == NULL)
|
||||
goto erren0;
|
||||
|
||||
fprintf(out, "%s\n%s\n%s\n", PCP_ENFILE_HEADER, encoded, PCP_ENFILE_FOOTER);
|
||||
if(ferror(out) != 0) {
|
||||
fatal("Failed to write encrypted output!\n");
|
||||
}
|
||||
|
||||
fprintf(stderr, "Encrypted %d bytes for 0x%s successfully\n",
|
||||
(int)inputBufSize, id);
|
||||
|
||||
fclose(out);
|
||||
free(encoded);
|
||||
free(combined);
|
||||
free(cipher);
|
||||
return 0;
|
||||
|
||||
erren0:
|
||||
free(cipher);
|
||||
|
||||
erren1:
|
||||
|
||||
erren2:
|
||||
|
||||
erren3:
|
||||
|
||||
return 1;
|
||||
}
|
||||
18
src/encryption.h
Normal file
18
src/encryption.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef _HAVE_ENCRYPTION_H
|
||||
#define _HAVE_ENCRYPTION_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "key.h"
|
||||
#include "crypto.h"
|
||||
#include "pcp.h"
|
||||
#include "uthash.h"
|
||||
#include "z85.h"
|
||||
#include "keyprint.h"
|
||||
|
||||
int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd);
|
||||
int pcpencrypt(char *id, char *infile, char *outfile, char *passwd);
|
||||
|
||||
#endif // _HAVE_ENCRYPTION_H
|
||||
510
src/keymgmt.c
Normal file
510
src/keymgmt.c
Normal file
@@ -0,0 +1,510 @@
|
||||
#include "keymgmt.h"
|
||||
|
||||
|
||||
|
||||
char *pcp_getstdin(const char *prompt) {
|
||||
char line[1024];
|
||||
char *out;
|
||||
|
||||
fprintf(stderr, "%s: ", prompt);
|
||||
|
||||
if (fgets(line, 1024, stdin) == NULL) {
|
||||
fatal("Cannot read from stdin");
|
||||
goto errgst;
|
||||
}
|
||||
|
||||
line[strcspn(line, "\r\n")] = '\0';
|
||||
|
||||
if ((out = strdup(line)) == NULL) {
|
||||
fatal("Cannot allocate memory");
|
||||
goto errgst;
|
||||
}
|
||||
|
||||
return out;
|
||||
|
||||
errgst:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int pcp_storekey (pcp_key_t *key) {
|
||||
if(vault->isnew == 1 || HASH_COUNT(pcpkey_hash) == 0) {
|
||||
key->type = PCP_KEY_TYPE_MAINSECRET;
|
||||
}
|
||||
|
||||
if(pcpvault_additem(vault, key, sizeof(pcp_key_t), key->type, 1) == 0) {
|
||||
if(vault->isnew)
|
||||
fprintf(stderr, "new vault created, ");
|
||||
fprintf(stderr, "key 0x%s added to %s.\n", key->id, vault->filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void pcp_keygen(char *passwd) {
|
||||
pcp_key_t *k = pcpkey_new ();
|
||||
|
||||
char *owner = pcp_getstdin("Enter the name of the key owner");
|
||||
memcpy(k->owner, owner, strlen(owner) + 1);
|
||||
|
||||
char *mail = pcp_getstdin("Enter the email address of the key owner");
|
||||
memcpy(k->mail, mail, strlen(mail) + 1);
|
||||
|
||||
if(debug)
|
||||
pcp_dumpkey(k);
|
||||
|
||||
char *passphrase;
|
||||
if(passwd == NULL) {
|
||||
pcp_readpass(&passphrase,
|
||||
"Enter passphrase for key encryption",
|
||||
"Enter the passphrase again", 1);
|
||||
}
|
||||
else {
|
||||
passphrase = ucmalloc(strlen(passwd)+1);
|
||||
strncpy(passphrase, passwd, strlen(passwd)+1);
|
||||
}
|
||||
|
||||
pcp_key_t *key = pcpkey_encrypt(k, passphrase);
|
||||
|
||||
if(key != NULL) {
|
||||
if(pcp_storekey(key) == 0) {
|
||||
fprintf(stderr, "Generated new secret key:\n");
|
||||
pcpkey_printshortinfo(key);
|
||||
}
|
||||
}
|
||||
|
||||
free(k);
|
||||
free(mail);
|
||||
free(owner);
|
||||
}
|
||||
|
||||
|
||||
void pcp_listkeys() {
|
||||
pcp_key_t *k;
|
||||
|
||||
int nkeys = HASH_COUNT(pcpkey_hash) + HASH_COUNT(pcppubkey_hash);
|
||||
|
||||
if(nkeys > 0) {
|
||||
printf("Key ID Type Creation Time Owner\n");
|
||||
|
||||
for(k=pcpkey_hash; k != NULL; k=(pcp_key_t*)(k->hh.next)) {
|
||||
pcpkey_printlineinfo(k);
|
||||
}
|
||||
|
||||
pcp_pubkey_t *p;
|
||||
for(p=pcppubkey_hash; p != NULL; p=(pcp_pubkey_t*)(p->hh.next)) {
|
||||
pcppubkey_printlineinfo(p);
|
||||
}
|
||||
}
|
||||
else {
|
||||
fatal("The key vault file %s doesn't contain any keys so far.\n", vault->filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char *pcp_normalize_id(char *keyid) {
|
||||
char *id = ucmalloc(17);
|
||||
int len = strnlen(keyid, 24);
|
||||
|
||||
if(len == 16) {
|
||||
memcpy(id, keyid, 17);
|
||||
}
|
||||
else if(len < 16) {
|
||||
fatal("Specified key id %s is too short!\n", keyid);
|
||||
free(id);
|
||||
return NULL;
|
||||
}
|
||||
else if(len > 18) {
|
||||
fatal("Specified key id %s is too long!\n", keyid);
|
||||
free(id);
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
if(keyid[0] == '0' && keyid[1] == 'x' && len == 18) {
|
||||
int i;
|
||||
for(i=0; i<16; ++i) {
|
||||
id[i] = keyid[i+2];
|
||||
}
|
||||
id[16] = 0;
|
||||
}
|
||||
else {
|
||||
fatal("Specified key id %s is too long!\n", keyid);
|
||||
free(id);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
pcp_key_t *pcp_find_primary_secret() {
|
||||
pcp_key_t *key = NULL;
|
||||
pcp_key_t *k;
|
||||
for(k=pcpkey_hash; k != NULL; k=(pcp_key_t*)(k->hh.next)) {
|
||||
if(k->type == PCP_KEY_TYPE_MAINSECRET) {
|
||||
key = ucmalloc(sizeof(pcp_key_t));
|
||||
memcpy(key, k, sizeof(pcp_key_t));
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
// no primary? whoops
|
||||
int nkeys = HASH_COUNT(pcpkey_hash);
|
||||
if(nkeys == 1) {
|
||||
for(k=pcpkey_hash; k != NULL; k=(pcp_key_t*)(k->hh.next)) {
|
||||
key = ucmalloc(sizeof(pcp_key_t));
|
||||
memcpy(key, k, sizeof(pcp_key_t));
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void pcp_exportsecret(char *keyid, int useid, char *outfile) {
|
||||
pcp_key_t *key = NULL;
|
||||
|
||||
if(useid == 1) {
|
||||
// look if we've got that one
|
||||
HASH_FIND_STR(pcpkey_hash, keyid, key);
|
||||
if(key == NULL) {
|
||||
fatal("Could not find a secret key with id 0x%s in vault %s!\n", keyid, vault->filename);
|
||||
free(key);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// look for our primary key
|
||||
key = pcp_find_primary_secret();
|
||||
if(key == NULL) {
|
||||
fatal("There's no primary secret key in the vault %s!\n", vault->filename);
|
||||
}
|
||||
}
|
||||
|
||||
if(key != NULL) {
|
||||
FILE *out;
|
||||
if(outfile == NULL) {
|
||||
out = stdout;
|
||||
}
|
||||
else {
|
||||
if((out = fopen(outfile, "wb+")) == NULL) {
|
||||
fatal("Could not create output file %s", outfile);
|
||||
out = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(out != NULL) {
|
||||
if(debug)
|
||||
pcp_dumpkey(key);
|
||||
else
|
||||
pcpkey_print(key, out);
|
||||
}
|
||||
|
||||
free(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void pcp_exportpublic(char *keyid, int useid, char *outfile) {
|
||||
pcp_pubkey_t *key = NULL;
|
||||
|
||||
if(useid == 1) {
|
||||
// look if we've got that one
|
||||
HASH_FIND_STR(pcppubkey_hash, keyid, key);
|
||||
if(key == NULL) {
|
||||
// maybe it's a secret key?
|
||||
pcp_key_t *s = NULL;
|
||||
HASH_FIND_STR(pcpkey_hash, keyid, s);
|
||||
if(s == NULL) {
|
||||
fatal("Could not find a public key with id 0x%s in vault %s!\n", keyid, vault->filename);
|
||||
free(s);
|
||||
}
|
||||
else {
|
||||
key = pcpkey_pub_from_secret(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// look for the primary secret
|
||||
pcp_key_t *s = NULL;
|
||||
s = pcp_find_primary_secret();
|
||||
if(s == NULL) {
|
||||
fatal("There's no primary secret key in the vault %s!\n", vault->filename);
|
||||
free(s);
|
||||
}
|
||||
else {
|
||||
key = pcpkey_pub_from_secret(s);
|
||||
}
|
||||
}
|
||||
|
||||
if(key != NULL) {
|
||||
FILE *out;
|
||||
if(outfile == NULL) {
|
||||
out = stdout;
|
||||
}
|
||||
else {
|
||||
if((out = fopen(outfile, "wb+")) == NULL) {
|
||||
fatal("Could not create output file %s", outfile);
|
||||
out = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(out != NULL) {
|
||||
pcppubkey_print(key, out);
|
||||
fprintf(stderr, "public key exported.\n");
|
||||
}
|
||||
|
||||
free(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int pcp_importsecret (vault_t *vault, FILE *in) {
|
||||
size_t clen;
|
||||
char *z85 = pcp_readz85file(in);
|
||||
|
||||
if(z85 == NULL)
|
||||
return -1;
|
||||
|
||||
unsigned char *z85decoded = pcp_z85_decode((char *)z85, &clen);
|
||||
free(z85);
|
||||
|
||||
if(z85decoded == NULL) {
|
||||
fatal("Error: could not decode input - it's probably not Z85.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(clen != sizeof(pcp_key_t)) {
|
||||
fatal("Error: decoded input didn't result to a proper sized key! (got %d bytes)\n", clen);
|
||||
free(z85decoded);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// all good now
|
||||
pcp_key_t *key = (pcp_key_t *)z85decoded;
|
||||
if(debug)
|
||||
pcp_dumpkey(key);
|
||||
|
||||
if(pcp_sanitycheck_key(key) == 0) {
|
||||
if(key->secret[0] != 0) {
|
||||
// unencrypted, encrypt it
|
||||
fprintf(stderr, "Key to be imported is unencrypted.\n");
|
||||
char *passphrase;
|
||||
pcp_readpass(&passphrase, "Enter passphrase for key encryption", NULL, 1);
|
||||
key = pcpkey_encrypt(key, passphrase);
|
||||
}
|
||||
int nkeys = HASH_COUNT(pcpkey_hash);
|
||||
if(nkeys == 0)
|
||||
key->type = PCP_KEY_TYPE_MAINSECRET;
|
||||
|
||||
if(pcpvault_additem(vault, (void *)key, sizeof(pcp_key_t),
|
||||
PCP_KEY_TYPE_SECRET, 1) == 0) {
|
||||
fprintf(stderr, "key 0x%s added to %s.\n", key->id, vault->filename);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int pcp_importpublic (vault_t *vault, FILE *in) {
|
||||
size_t clen;
|
||||
char *z85 = pcp_readz85file(in);
|
||||
|
||||
if(z85 == NULL)
|
||||
return -1;
|
||||
|
||||
unsigned char *z85decoded = pcp_z85_decode((char *)z85, &clen);
|
||||
free(z85);
|
||||
|
||||
if(z85decoded == NULL) {
|
||||
fatal("Error: could not decode input - it's probably not Z85 (got %d bytes)\n", clen);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(clen != sizeof(pcp_pubkey_t)) {
|
||||
fatal("Error: decoded input didn't result to a proper sized key!\n", clen);
|
||||
free(z85decoded);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// all good now
|
||||
pcp_pubkey_t *pub = (pcp_pubkey_t *)z85decoded;
|
||||
if(debug)
|
||||
pcp_dumppubkey(pub);
|
||||
if(pcp_sanitycheck_pub(pub) == 0) {
|
||||
if(pcpvault_additem(vault, (void *)pub, sizeof(pcp_pubkey_t), PCP_KEY_TYPE_PUBLIC, 1) == 0) {
|
||||
fprintf(stderr, "key 0x%s added to %s.\n", pub->id, vault->filename);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pcp_sanitycheck_pub(pcp_pubkey_t *key) {
|
||||
if(key->public[0] == 0) {
|
||||
fatal("Pubkey sanity check: public key contained in key seems to be empty!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(key->type != PCP_KEY_TYPE_PUBLIC) {
|
||||
fatal("Pubkey sanity check: key type is not PUBLIC (expected: %02x, got: %02x)!\n",
|
||||
PCP_KEY_TYPE_PUBLIC, key->type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(key->version != PCP_KEY_VERSION) {
|
||||
fatal("Pubkey sanity check: unknown key version (expected: %08X, got: %08X)!\n",
|
||||
PCP_KEY_VERSION, key->version);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(key->serial <= 0) {
|
||||
fatal("Pubkey sanity check: invalid serial number: %08X!\n", key->serial);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(key->id[16] != '\0') {
|
||||
char *got = ucmalloc(17);
|
||||
memcpy(got, key->id, 17);
|
||||
got[16] = '\0';
|
||||
fatal("Pubkey sanity check: invalid key id (expected 16 bytes, got: %s)!\n", got);
|
||||
free(got);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct tm *c;
|
||||
time_t t = (time_t)key->ctime;
|
||||
c = localtime(&t);
|
||||
if(c->tm_year <= 0 || c->tm_year > 1100) {
|
||||
// well, I'm perhaps overacting here :)
|
||||
fatal("Pubkey sanity check: invalid creation timestamp (got year %04d)!\n", c->tm_year + 1900);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pcp_pubkey_t *maybe = pcppubkey_exists(key->id);
|
||||
if(maybe != NULL) {
|
||||
fatal("Pubkey sanity check: there already exists a key with the id 0x%s\n", key->id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int pcp_sanitycheck_key(pcp_key_t *key) {
|
||||
if(key->encrypted[0] == 0) {
|
||||
fatal("Secretkey sanity check: secret key contained in key seems to be empty!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(key->type != PCP_KEY_TYPE_SECRET && key->type != PCP_KEY_TYPE_MAINSECRET) {
|
||||
fatal("Secretkey sanity check: key type is not SECRET (expected: %02x, got: %02x)!\n",
|
||||
PCP_KEY_TYPE_SECRET, key->type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(key->version != PCP_KEY_VERSION) {
|
||||
fatal("Secretkey sanity check: unknown key version (expected: %08X, got: %08X)!\n",
|
||||
PCP_KEY_VERSION, key->version);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(key->serial <= 0) {
|
||||
fatal("Secretkey sanity check: invalid serial number: %08X!\n", key->serial);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(key->id[16] != '\0') {
|
||||
char *got = ucmalloc(17);
|
||||
memcpy(got, key->id, 17);
|
||||
got[16] = '\0';
|
||||
fatal("Secretkey sanity check: invalid key id (expected 16 bytes, got: %s)!\n", got);
|
||||
free(got);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct tm *c;
|
||||
time_t t = (time_t)key->ctime;
|
||||
c = localtime(&t);
|
||||
if(c->tm_year <= 0 || c->tm_year > 1100) {
|
||||
// well, I'm perhaps overacting here :)
|
||||
fatal("Secretkey sanity check: invalid creation timestamp (got year %04d)!\n", c->tm_year + 1900);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pcp_key_t *maybe = pcpkey_exists(key->id);
|
||||
if(maybe != NULL) {
|
||||
fatal("Secretkey sanity check: there already exists a key with the id 0x%s\n", key->id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pcpdelete_key(char *keyid) {
|
||||
pcp_pubkey_t *p = pcppubkey_exists(keyid);
|
||||
|
||||
if(p != NULL) {
|
||||
// delete public
|
||||
HASH_DEL(pcppubkey_hash, p);
|
||||
free(p);
|
||||
vault->unsafed = 1;
|
||||
fprintf(stderr, "Public key deleted.\n");
|
||||
}
|
||||
else {
|
||||
pcp_key_t *s = pcpkey_exists(keyid);
|
||||
if(s != NULL) {
|
||||
// delete secret
|
||||
HASH_DEL(pcpkey_hash, s);
|
||||
free(s);
|
||||
vault->unsafed = 1;
|
||||
fprintf(stderr, "Secret key deleted.\n");
|
||||
}
|
||||
else {
|
||||
fatal("No key with id 0x%s found!\n", keyid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pcpedit_key(char *keyid) {
|
||||
pcp_key_t *key = pcpkey_exists(keyid);
|
||||
|
||||
if(key != NULL) {
|
||||
if(key->secret[0] == 0) {
|
||||
char *passphrase;
|
||||
pcp_readpass(&passphrase, "Enter passphrase to decrypt the key", NULL, 1);
|
||||
key = pcpkey_decrypt(key, passphrase);
|
||||
}
|
||||
|
||||
if(key != NULL) {
|
||||
char *owner = pcp_getstdin("Enter the name of the key owner");
|
||||
memcpy(key->owner, owner, strlen(owner) + 1);
|
||||
|
||||
char *mail = pcp_getstdin("Enter the email address of the key owner");
|
||||
memcpy(key->mail, mail, strlen(mail) + 1);
|
||||
|
||||
char *passphrase;
|
||||
pcp_readpass(&passphrase, "Enter passphrase for key encryption", NULL, 1);
|
||||
key = pcpkey_encrypt(key, passphrase);
|
||||
|
||||
if(key != NULL) {
|
||||
if(debug)
|
||||
pcp_dumpkey(key);
|
||||
|
||||
vault->unsafed = 1; // will be safed automatically
|
||||
fprintf(stderr, "Key key changed.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
fatal("No key with id 0x%s found!\n", keyid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
35
src/keymgmt.h
Normal file
35
src/keymgmt.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef _HAVE_KEYMGMT_H
|
||||
#define _HAVE_KEYMGMT_H
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "randomart.h"
|
||||
#include "mac.h"
|
||||
#include "key.h"
|
||||
#include "pcp.h"
|
||||
#include "vault.h"
|
||||
#include "defines.h"
|
||||
#include "readpass.h"
|
||||
#include "keyprint.h"
|
||||
|
||||
#define _WITH_GETLINE
|
||||
|
||||
char *pcp_getstdin(const char *prompt);
|
||||
int pcp_storekey (pcp_key_t *key);
|
||||
void pcp_keygen();
|
||||
void pcp_listkeys();
|
||||
void pcp_exportsecret(char *keyid, int useid, char *outfile);
|
||||
void pcp_exportpublic(char *keyid, int useid, char *outfile);
|
||||
char *pcp_normalize_id(char *keyid);
|
||||
pcp_key_t *pcp_find_primary_secret();
|
||||
int pcp_importpublic (vault_t *vault, FILE *in);
|
||||
int pcp_sanitycheck_pub(pcp_pubkey_t *key);
|
||||
int pcp_importsecret (vault_t *vault, FILE *in);
|
||||
int pcp_sanitycheck_key(pcp_key_t *key);
|
||||
void pcpdelete_key(char *keyid);
|
||||
|
||||
|
||||
#endif // _HAVE_KEYMGMT_H
|
||||
250
src/keyprint.c
Normal file
250
src/keyprint.c
Normal file
@@ -0,0 +1,250 @@
|
||||
#include "keyprint.h"
|
||||
|
||||
|
||||
void pcptext_key(char *keyid) {
|
||||
pcp_key_t *s = pcpkey_exists(keyid);
|
||||
if(s != NULL) {
|
||||
pcpkey_print(s, stdout);
|
||||
free(s);
|
||||
}
|
||||
else {
|
||||
pcp_pubkey_t *p = pcppubkey_exists(keyid);
|
||||
if(p != NULL) {
|
||||
pcppubkey_print(p, stdout);
|
||||
free(p);
|
||||
}
|
||||
else {
|
||||
fatal("No key with id 0x%s found!\n", keyid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pcptext_vault(vault_t *vault) {
|
||||
printf(" Key vault: %s\n", vault->filename);
|
||||
printf("Vault version: %08X\n", vault->version);
|
||||
printf(" Checksum: ");
|
||||
|
||||
int i;
|
||||
unsigned char *hash = vault->checksum;
|
||||
for ( i = 0;i <15 ;++i) printf("%02X:",(unsigned int) hash[i]);
|
||||
printf("%02X", hash[15]);
|
||||
printf("\n ");
|
||||
for ( i = 16;i <31 ;++i) printf("%02X:",(unsigned int) hash[i]);
|
||||
printf("%02X", hash[31]);
|
||||
printf("\n");
|
||||
free(hash);
|
||||
|
||||
printf(" Secret keys: %d\n", HASH_COUNT(pcpkey_hash));
|
||||
printf(" Public keys: %d\n", HASH_COUNT(pcppubkey_hash));
|
||||
}
|
||||
|
||||
void pcpkey_printlineinfo(pcp_key_t *key) {
|
||||
struct tm *c;
|
||||
time_t t = (time_t)key->ctime;
|
||||
c = localtime(&t);
|
||||
printf("0x%s %s %04d-%02d-%02dT%02d:%02d:%02d %s <%s>\n",
|
||||
key->id,
|
||||
(key->type == PCP_KEY_TYPE_MAINSECRET) ? "primary" : " secret",
|
||||
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
||||
c->tm_hour, c->tm_min, c->tm_sec,
|
||||
key->owner, key->mail);
|
||||
}
|
||||
|
||||
void pcppubkey_printlineinfo(pcp_pubkey_t *key) {
|
||||
struct tm *c;
|
||||
time_t t = (time_t)key->ctime;
|
||||
c = localtime(&t);
|
||||
printf("0x%s public %04d-%02d-%02dT%02d:%02d:%02d %s <%s>\n",
|
||||
key->id,
|
||||
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
||||
c->tm_hour, c->tm_min, c->tm_sec,
|
||||
key->owner, key->mail);
|
||||
}
|
||||
|
||||
|
||||
void pcpkey_print(pcp_key_t *key, FILE* out) {
|
||||
size_t zlen;
|
||||
char *z85encoded = pcp_z85_encode((unsigned char*)key, sizeof(pcp_key_t), &zlen);
|
||||
|
||||
struct tm *c;
|
||||
time_t t = (time_t)key->ctime;
|
||||
c = localtime(&t);
|
||||
|
||||
fprintf(out, "%s\n", PCP_KEY_HEADER);
|
||||
|
||||
fprintf(out, " Generated by: %s Version %d.%d.%d\n",
|
||||
PCP_ME, PCP_VERSION_MAJOR, PCP_VERSION_MINOR, PCP_VERSION_PATCH);
|
||||
|
||||
fprintf(out, " Cipher: %s\n", PCP_KEY_PRIMITIVE);
|
||||
|
||||
fprintf(out, " Key-ID: 0x%s\n", key->id);
|
||||
|
||||
//2004-06-14T23:34:30.
|
||||
fprintf(out, " Creation Time: %04d-%02d-%02dT%02d:%02d:%02d\n",
|
||||
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
||||
c->tm_hour, c->tm_min, c->tm_sec);
|
||||
|
||||
fprintf(out, " Serial Number: 0x%08X\n", key->serial);
|
||||
fprintf(out, " Key Version: 0x%08X\n", key->version);
|
||||
|
||||
fprintf(out, "\n%s\n", z85encoded);
|
||||
|
||||
fprintf(out, "%s\n", PCP_KEY_FOOTER);
|
||||
|
||||
free(z85encoded);
|
||||
}
|
||||
|
||||
void pcppubkey_print(pcp_pubkey_t *key, FILE* out) {
|
||||
size_t zlen;
|
||||
char *z85encoded = pcp_z85_encode((unsigned char*)key, sizeof(pcp_pubkey_t), &zlen);
|
||||
|
||||
struct tm *c;
|
||||
time_t t = (time_t)key->ctime;
|
||||
c = localtime(&t);
|
||||
|
||||
fprintf(out, "%s\n", PCP_PUBKEY_HEADER);
|
||||
|
||||
fprintf(out, " Generated by: %s Version %d.%d.%d\n",
|
||||
PCP_ME, PCP_VERSION_MAJOR, PCP_VERSION_MINOR, PCP_VERSION_PATCH);
|
||||
|
||||
fprintf(out, " Cipher: %s\n", PCP_KEY_PRIMITIVE);
|
||||
|
||||
fprintf(out, " Owner: %s\n", key->owner);
|
||||
fprintf(out, " Mail: %s\n", key->mail);
|
||||
|
||||
fprintf(out, " Key-ID: 0x%s\n", key->id);
|
||||
fprintf(out, " Public-Key: %s\n", pcp_z85_encode(key->public, 32, &zlen));
|
||||
|
||||
//2004-06-14T23:34:30.
|
||||
fprintf(out, " Creation Time: %04d-%02d-%02dT%02d:%02d:%02d\n",
|
||||
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
||||
c->tm_hour, c->tm_min, c->tm_sec);
|
||||
|
||||
unsigned char *hash = pcppubkey_getchecksum(key);
|
||||
fprintf(out, " Checksum: ");
|
||||
|
||||
int i;
|
||||
for ( i = 0;i <15 ;++i) fprintf(out, "%02X:",(unsigned int) hash[i]);
|
||||
fprintf(out, "%02X", hash[15]);
|
||||
fprintf(out, "\n ");
|
||||
for ( i = 16;i <31 ;++i) fprintf(out, "%02X:",(unsigned int) hash[i]);
|
||||
fprintf(out, "%02X", hash[31]);
|
||||
fprintf(out, "\n");
|
||||
fprintf(out, " Serial Number: 0x%08X\n", key->serial);
|
||||
fprintf(out, " Key Version: 0x%08X\n", key->version);
|
||||
|
||||
char *r = pcppubkey_get_art(key);
|
||||
fprintf(out, " Random Art ID: ");
|
||||
for (i=0; i<strlen(r); ++i) {
|
||||
if(r[i] == '\n') {
|
||||
fprintf(out, "\n ");
|
||||
}
|
||||
else {
|
||||
fprintf(out, "%c", r[i]);
|
||||
}
|
||||
}
|
||||
fprintf(out, "\n");
|
||||
|
||||
fprintf(out, "\n%s\n", z85encoded);
|
||||
|
||||
fprintf(out, "%s\n", PCP_PUBKEY_FOOTER);
|
||||
|
||||
free(hash);
|
||||
free(r);
|
||||
free(z85encoded);
|
||||
}
|
||||
|
||||
|
||||
void pcp_dumpkey(pcp_key_t *k) {
|
||||
int i;
|
||||
|
||||
printf("Dumping pcp_key_t raw values:\n");
|
||||
printf(" public: ");
|
||||
for ( i = 0;i < 32;++i) printf("%02x",(unsigned int) k->public[i]);
|
||||
printf("\n");
|
||||
|
||||
printf(" secret: ");
|
||||
for ( i = 0;i < 32;++i) printf("%02x",(unsigned int) k->secret[i]);
|
||||
printf("\n");
|
||||
|
||||
printf(" nonce: ");
|
||||
for ( i = 0;i < 24;++i) printf("%02x",(unsigned int) k->nonce[i]);
|
||||
printf("\n");
|
||||
|
||||
printf("encrypted: ");
|
||||
for ( i = 0;i < 48;++i) printf("%02x",(unsigned int) k->encrypted[i]);
|
||||
printf("\n");
|
||||
|
||||
printf(" owner: %s\n", k->owner);
|
||||
|
||||
printf(" mail: %s\n", k->mail);
|
||||
|
||||
printf(" id: %s\n", k->id);
|
||||
|
||||
printf(" ctime: %ld\n", k->ctime);
|
||||
|
||||
printf(" version: 0x%08X\n", k->version);
|
||||
|
||||
printf(" serial: 0x%08X\n", k->serial);
|
||||
|
||||
printf(" type: 0x%02X\n", k->type);
|
||||
}
|
||||
|
||||
|
||||
void pcp_dumppubkey(pcp_pubkey_t *k) {
|
||||
int i;
|
||||
printf("Dumping pcp_pubkey_t raw values:\n");
|
||||
printf(" public: ");
|
||||
for ( i = 0;i < 32;++i) printf("%02x",(unsigned int) k->public[i]);
|
||||
printf("\n");
|
||||
|
||||
printf(" owner: %s\n", k->owner);
|
||||
|
||||
printf(" mail: %s\n", k->mail);
|
||||
|
||||
printf(" id: %s\n", k->id);
|
||||
|
||||
printf(" ctime: %ld\n", k->ctime);
|
||||
|
||||
printf(" version: 0x%08X\n", k->version);
|
||||
|
||||
printf(" serial: 0x%08X\n", k->serial);
|
||||
|
||||
printf(" type: 0x%02X\n", k->type);
|
||||
}
|
||||
|
||||
void pcpkey_printshortinfo(pcp_key_t *key) {
|
||||
int i;
|
||||
printf(" Key-ID: 0x%s\n", key->id);
|
||||
printf(" Owner: %s\n", key->owner);
|
||||
char *r = pcpkey_get_art(key);
|
||||
printf(" Random Art ID: ");
|
||||
for (i=0; i<strlen(r); ++i) {
|
||||
if(r[i] == '\n') {
|
||||
printf("\n ");
|
||||
}
|
||||
else {
|
||||
printf("%c", r[i]);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
free(r);
|
||||
}
|
||||
|
||||
void pcppubkey_printshortinfo(pcp_pubkey_t *key) {
|
||||
int i;
|
||||
printf(" Key-ID: 0x%s\n", key->id);
|
||||
printf(" Owner: %s\n", key->owner);
|
||||
char *r = pcpkey_get_art(key);
|
||||
printf(" Random Art ID: ");
|
||||
for (i=0; i<strlen(r); ++i) {
|
||||
if(r[i] == '\n') {
|
||||
printf("\n ");
|
||||
}
|
||||
else {
|
||||
printf("%c", r[i]);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
free(r);
|
||||
}
|
||||
23
src/keyprint.h
Normal file
23
src/keyprint.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef _HAVE_PCP_KEYPRINT_H
|
||||
#define _HAVE_PCP_KEYPRINT_H
|
||||
|
||||
#include "mem.h"
|
||||
#include "key.h"
|
||||
#include "vault.h"
|
||||
|
||||
void pcp_dumpkey(pcp_key_t *k);
|
||||
void pcp_dumppubkey(pcp_pubkey_t *k);
|
||||
|
||||
void pcpkey_print(pcp_key_t *key, FILE *out);
|
||||
void pcppubkey_print(pcp_pubkey_t *key, FILE *out);
|
||||
|
||||
void pcpkey_printshortinfo(pcp_key_t *key);
|
||||
void pcppubkey_printshortinfo(pcp_pubkey_t *key);
|
||||
|
||||
void pcpkey_printlineinfo(pcp_key_t *key);
|
||||
void pcppubkey_printlineinfo(pcp_pubkey_t *key);
|
||||
|
||||
void pcptext_key(char *keyid);
|
||||
void pcptext_vault(vault_t *vault);
|
||||
|
||||
#endif // _HAVE_PCP_KEYPRINT_H
|
||||
339
src/pcp.c
Normal file
339
src/pcp.c
Normal file
@@ -0,0 +1,339 @@
|
||||
#include "pcp.h"
|
||||
#include "defines.h"
|
||||
|
||||
void usage() {
|
||||
fprintf(stderr, PCP_HELP_INTRO);
|
||||
fprintf(stderr, PCP_HELP);
|
||||
version();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void version() {
|
||||
fprintf(stderr, "pcp version %d.%d.%d\n",
|
||||
PCP_VERSION_MAJOR, PCP_VERSION_MINOR, PCP_VERSION_PATCH);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
char *default_vault() {
|
||||
char *path = ucmalloc(1024);;
|
||||
snprintf(path, 1024, "%s/.pcpvault", getenv("HOME"));
|
||||
return path;
|
||||
}
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
int opt, mode, usevault, useid;
|
||||
char *vaultfile = default_vault();
|
||||
char *outfile = NULL;
|
||||
char *infile = NULL;
|
||||
char *keyid = NULL;
|
||||
char *id = NULL;
|
||||
char *xpass = NULL;
|
||||
FILE *in;
|
||||
|
||||
PCP_EXIT = 0;
|
||||
errno = 0;
|
||||
debug = 0;
|
||||
mode = 0;
|
||||
usevault = 0;
|
||||
useid = 0;
|
||||
|
||||
static struct option longopts[] = {
|
||||
// generics
|
||||
{ "vault", required_argument, NULL, 'V' },
|
||||
{ "outfile", required_argument, NULL, 'O' },
|
||||
{ "infile", required_argument, NULL, 'I' },
|
||||
{ "keyid", required_argument, NULL, 'i' },
|
||||
{ "text", required_argument, NULL, 't' },
|
||||
{ "xpass", required_argument, NULL, 'x' },
|
||||
|
||||
// key management
|
||||
{ "keygen", no_argument, NULL, 'k' },
|
||||
{ "listkeys", no_argument, NULL, 'l' },
|
||||
{ "export-secret", no_argument, NULL, 's' },
|
||||
{ "export-public", no_argument, NULL, 'p' },
|
||||
{ "import-secret", no_argument, NULL, 'S' },
|
||||
{ "import-public", no_argument, NULL, 'P' },
|
||||
{ "remove-key", no_argument, NULL, 'r' },
|
||||
{ "edit-key", no_argument, NULL, 'E' },
|
||||
|
||||
// crypto
|
||||
{ "encrypt", no_argument, NULL, 'e' },
|
||||
{ "decrypt", no_argument, NULL, 'd' },
|
||||
|
||||
// encoding
|
||||
{ "z85-encode", no_argument, NULL, 'z' },
|
||||
{ "z85-decode", no_argument, NULL, 'Z' },
|
||||
|
||||
// globals
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "version", no_argument, NULL, 'f' },
|
||||
{ "debug", no_argument, NULL, 'D' },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
while ((opt = getopt_long(argc, argv, "klV:vdehsO:i:I:pSPrtEx:DzZ",
|
||||
longopts, NULL)) != -1) {
|
||||
|
||||
switch (opt) {
|
||||
|
||||
case 'k':
|
||||
mode += PCP_MODE_KEYGEN;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'l':
|
||||
mode += PCP_MODE_LISTKEYS;
|
||||
usevault = 1;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
mode += PCP_MODE_EXPORT_SECRET;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'p':
|
||||
mode += PCP_MODE_EXPORT_PUBLIC;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'P':
|
||||
mode += PCP_MODE_IMPORT_PUBLIC;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'S':
|
||||
mode += PCP_MODE_IMPORT_SECRET;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'r':
|
||||
mode += PCP_MODE_DELETE_KEY;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 't':
|
||||
mode += PCP_MODE_TEXT;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'E':
|
||||
mode += PCP_MODE_EDIT;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'e':
|
||||
mode += PCP_MODE_ENCRYPT;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'd':
|
||||
mode += PCP_MODE_DECRYPT;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'z':
|
||||
mode += PCP_MODE_ZENCODE;
|
||||
break;
|
||||
case 'Z':
|
||||
mode += PCP_MODE_ZDECODE;
|
||||
break;
|
||||
|
||||
|
||||
case 'V':
|
||||
strncpy(vaultfile, optarg, 1024);
|
||||
break;
|
||||
case 'O':
|
||||
outfile = ucmalloc(strlen(optarg)+1);
|
||||
strncpy(outfile, optarg, strlen(optarg)+1);
|
||||
break;
|
||||
case 'I':
|
||||
infile = ucmalloc(strlen(optarg)+1);
|
||||
strncpy(infile, optarg, strlen(optarg)+1);
|
||||
break;
|
||||
case 'i':
|
||||
keyid = ucmalloc(19);
|
||||
strncpy(keyid, optarg, 19);
|
||||
useid = 1;
|
||||
break;
|
||||
case 'x':
|
||||
xpass = ucmalloc(strlen(optarg)+1);
|
||||
strncpy(xpass, optarg, strlen(optarg)+1);
|
||||
break;
|
||||
|
||||
|
||||
case 'D':
|
||||
debug = 1;
|
||||
break;
|
||||
case 'v':
|
||||
version();
|
||||
case 'h':
|
||||
usage();
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
|
||||
if(usevault == 1) {
|
||||
pcp_inithashes();
|
||||
vault = pcpvault_init(vaultfile);
|
||||
if(vault != NULL) {
|
||||
switch (mode) {
|
||||
case PCP_MODE_KEYGEN:
|
||||
pcp_keygen(xpass);
|
||||
if(xpass != NULL)
|
||||
free(xpass);
|
||||
break;
|
||||
|
||||
case PCP_MODE_LISTKEYS:
|
||||
pcp_listkeys();
|
||||
break;
|
||||
|
||||
case PCP_MODE_EXPORT_SECRET:
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id != NULL) {
|
||||
pcp_exportsecret(id, useid, outfile);
|
||||
free(id);
|
||||
}
|
||||
}
|
||||
else {
|
||||
pcp_exportsecret(NULL, useid, outfile);
|
||||
}
|
||||
break;
|
||||
|
||||
case PCP_MODE_EXPORT_PUBLIC:
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id != NULL) {
|
||||
pcp_exportpublic(id, useid, outfile);
|
||||
free(id);
|
||||
}
|
||||
}
|
||||
else {
|
||||
pcp_exportpublic(NULL, useid, outfile);
|
||||
}
|
||||
break;
|
||||
|
||||
case PCP_MODE_IMPORT_PUBLIC:
|
||||
if(infile == NULL)
|
||||
in = stdin;
|
||||
else {
|
||||
if((in = fopen(infile, "rb")) == NULL) {
|
||||
fatal("Could not open input file %s\n", infile);
|
||||
free(infile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
pcp_importpublic(vault, in);
|
||||
break;
|
||||
|
||||
case PCP_MODE_IMPORT_SECRET:
|
||||
if(infile == NULL)
|
||||
in = stdin;
|
||||
else {
|
||||
if((in = fopen(infile, "rb")) == NULL) {
|
||||
fatal("Could not open input file %s\n", infile);
|
||||
free(infile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
pcp_importsecret(vault, in);
|
||||
break;
|
||||
|
||||
case PCP_MODE_DELETE_KEY:
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id != NULL) {
|
||||
pcpdelete_key(id);
|
||||
free(id);
|
||||
}
|
||||
}
|
||||
else {
|
||||
fatal("You need to specify a key id (--keyid)!\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case PCP_MODE_TEXT:
|
||||
if(! useid) {
|
||||
pcptext_vault(vault);
|
||||
}
|
||||
else {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id != NULL) {
|
||||
pcptext_key(id);
|
||||
free(id);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case PCP_MODE_EDIT:
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id != NULL) {
|
||||
pcpedit_key(id);
|
||||
free(id);
|
||||
}
|
||||
}
|
||||
else {
|
||||
fatal("You need to specify a key id (--keyid)!\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case PCP_MODE_ENCRYPT:
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id != NULL) {
|
||||
pcpencrypt(id, infile, outfile, xpass);
|
||||
free(id);
|
||||
if(xpass != NULL)
|
||||
free(xpass);
|
||||
}
|
||||
}
|
||||
else {
|
||||
fatal("You need to specify a key id (--keyid)!\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case PCP_MODE_DECRYPT:
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id != NULL) {
|
||||
pcpdecrypt(id, useid, infile, outfile, xpass);
|
||||
free(id);
|
||||
}
|
||||
}
|
||||
else {
|
||||
pcpdecrypt(NULL, useid, infile, outfile, xpass);
|
||||
}
|
||||
if(xpass != NULL)
|
||||
free(xpass);
|
||||
break;
|
||||
|
||||
default:
|
||||
//
|
||||
goto ELSEMODE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
pcpvault_close(vault);
|
||||
pcp_cleanhashes();
|
||||
ucfree(vaultfile);
|
||||
}
|
||||
else {
|
||||
ELSEMODE:
|
||||
switch (mode) {
|
||||
case PCP_MODE_ZENCODE:
|
||||
pcpz85_encode(infile, outfile);
|
||||
break;
|
||||
|
||||
case PCP_MODE_ZDECODE:
|
||||
pcpz85_decode(infile, outfile);
|
||||
break;
|
||||
|
||||
default:
|
||||
// mode params mixed
|
||||
fatal("Sorry, invalid combinatin of commandline parameters!\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fatals_ifany();
|
||||
return PCP_EXIT;
|
||||
|
||||
}
|
||||
64
src/pcp.h
Normal file
64
src/pcp.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef _HAVE_PCP_H
|
||||
#define _HAVE_PCP_H
|
||||
|
||||
#define _BSD_SOURCE
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
|
||||
// lib
|
||||
#include "mem.h"
|
||||
#include "z85.h"
|
||||
#include "zmq_z85.h"
|
||||
#include "z85util.h"
|
||||
#include "version.h"
|
||||
#include "vault.h"
|
||||
|
||||
// subs
|
||||
#include "keymgmt.h"
|
||||
#include "usage.h"
|
||||
#include "encryption.h"
|
||||
|
||||
// operation modi
|
||||
// perl -e '$x=0; while ($x<100000) { $x++; $x *= 1.7; printf "0x%08X: %d\n", $x, $x }'
|
||||
#define PCP_MODE_KEYGEN 0x00000001
|
||||
#define PCP_MODE_LISTKEYS 0x00000004
|
||||
#define PCP_MODE_EXPORT_SECRET 0x00000009
|
||||
#define PCP_MODE_EXPORT_PUBLIC 0x00000011
|
||||
#define PCP_MODE_IMPORT_SECRET 0x00000020
|
||||
#define PCP_MODE_IMPORT_PUBLIC 0x00000038
|
||||
#define PCP_MODE_DELETE_KEY 0x00000061
|
||||
#define PCP_MODE_TEXT 0x000000A6
|
||||
#define PCP_MODE_EDIT 0x0000011D
|
||||
#define PCP_MODE_ENCRYPT 0x000001E7
|
||||
#define PCP_MODE_DECRYPT 0x0000033D
|
||||
#define PCP_MODE_ZENCODE 0x00000584
|
||||
#define PCP_MODE_ZDECODE 0x00000962
|
||||
|
||||
/*
|
||||
0x00000962
|
||||
0x00000FF6
|
||||
0x00001B25
|
||||
0x00002E27
|
||||
0x00004E77
|
||||
0x00008566
|
||||
0x0000E2CA
|
||||
0x0001818C
|
||||
0x00028F70
|
||||
*/
|
||||
|
||||
#define PCP_HELP_INTRO \
|
||||
"This is Pretty Curved Privacy. Licensed under the GPLv3. This\n"\
|
||||
"is BETA software. Use with care. NOT intended for production\n"\
|
||||
"use.\n"
|
||||
|
||||
vault_t *vault;
|
||||
int debug;
|
||||
|
||||
void version();
|
||||
void usage();
|
||||
char *default_vault();
|
||||
|
||||
#endif // _HAVE_PCP_H
|
||||
133
src/readpass.c
Normal file
133
src/readpass.c
Normal file
@@ -0,0 +1,133 @@
|
||||
/*-
|
||||
* Copyright 2009 Colin Percival
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#include "readpass.h"
|
||||
|
||||
/**
|
||||
* tarsnap_getpass(passwd, prompt, confirmprompt, devtty)
|
||||
* If ${devtty} is non-zero, read a password from /dev/tty if possible; if
|
||||
* not, read from stdin. If reading from a tty (either /dev/tty or stdin),
|
||||
* disable echo and prompt the user by printing ${prompt} to stderr. If
|
||||
* ${confirmprompt} is non-NULL, read a second password (prompting if a
|
||||
* terminal is being used) and repeat until the user enters the same password
|
||||
* twice. Return the password as a malloced NUL-terminated string via
|
||||
* ${passwd}. The obscure name is to avoid namespace collisions due to the
|
||||
* getpass / readpass / readpassphrase / etc. functions in various libraries.
|
||||
*/
|
||||
int
|
||||
pcp_readpass(char ** passwd, const char * prompt,
|
||||
const char * confirmprompt, int devtty)
|
||||
{
|
||||
FILE * readfrom;
|
||||
char passbuf[MAXPASSLEN];
|
||||
char confpassbuf[MAXPASSLEN];
|
||||
struct termios term, term_old;
|
||||
int usingtty;
|
||||
|
||||
/*
|
||||
* If devtty != 0, try to open /dev/tty; if that fails, or if devtty
|
||||
* is zero, we'll read the password from stdin instead.
|
||||
*/
|
||||
if ((devtty == 0) || ((readfrom = fopen("/dev/tty", "r")) == NULL))
|
||||
readfrom = stdin;
|
||||
|
||||
/* If we're reading from a terminal, try to disable echo. */
|
||||
if ((usingtty = isatty(fileno(readfrom))) != 0) {
|
||||
if (tcgetattr(fileno(readfrom), &term_old)) {
|
||||
fatal("Cannot read terminal settings");
|
||||
goto err1;
|
||||
}
|
||||
memcpy(&term, &term_old, sizeof(struct termios));
|
||||
term.c_lflag = (term.c_lflag & ~ECHO) | ECHONL;
|
||||
if (tcsetattr(fileno(readfrom), TCSANOW, &term)) {
|
||||
fatal("Cannot set terminal settings");
|
||||
goto err1;
|
||||
}
|
||||
}
|
||||
|
||||
retry:
|
||||
/* If we have a terminal, prompt the user to enter the password. */
|
||||
if (usingtty)
|
||||
fprintf(stderr, "%s: ", prompt);
|
||||
|
||||
/* Read the password. */
|
||||
if (fgets(passbuf, MAXPASSLEN, readfrom) == NULL) {
|
||||
fatal("Cannot read password");
|
||||
goto err2;
|
||||
}
|
||||
|
||||
/* Confirm the password if necessary. */
|
||||
if (confirmprompt != NULL) {
|
||||
if (usingtty)
|
||||
fprintf(stderr, "%s: ", confirmprompt);
|
||||
if (fgets(confpassbuf, MAXPASSLEN, readfrom) == NULL) {
|
||||
fatal("Cannot read password");
|
||||
goto err2;
|
||||
}
|
||||
if (strcmp(passbuf, confpassbuf)) {
|
||||
fprintf(stderr,
|
||||
"Passwords mismatch, please try again\n");
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
|
||||
/* Terminate the string at the first "\r" or "\n" (if any). */
|
||||
passbuf[strcspn(passbuf, "\r\n")] = '\0';
|
||||
|
||||
/* If we changed terminal settings, reset them. */
|
||||
if (usingtty)
|
||||
tcsetattr(fileno(readfrom), TCSANOW, &term_old);
|
||||
|
||||
/* Close /dev/tty if we opened it. */
|
||||
if (readfrom != stdin)
|
||||
fclose(readfrom);
|
||||
|
||||
/* Copy the password out. */
|
||||
if ((*passwd = strdup(passbuf)) == NULL) {
|
||||
fatal("Cannot allocate memory");
|
||||
goto err1;
|
||||
}
|
||||
|
||||
/* Zero any stored passwords. */
|
||||
memset(passbuf, 0, MAXPASSLEN);
|
||||
memset(confpassbuf, 0, MAXPASSLEN);
|
||||
|
||||
/* Success! */
|
||||
return (0);
|
||||
|
||||
err2:
|
||||
/* Reset terminal settings if necessary. */
|
||||
if (usingtty)
|
||||
tcsetattr(fileno(readfrom), TCSAFLUSH, &term_old);
|
||||
err1:
|
||||
/* Close /dev/tty if we opened it. */
|
||||
if (readfrom != stdin)
|
||||
fclose(readfrom);
|
||||
|
||||
/* Failure! */
|
||||
return (-1);
|
||||
}
|
||||
55
src/readpass.h
Normal file
55
src/readpass.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*-
|
||||
* Copyright 2009 Colin Percival
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file was originally written by Colin Percival as part of the Tarsnap
|
||||
* online backup system.
|
||||
*/
|
||||
#ifndef _READPASS_H_
|
||||
#define _READPASS_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
#define MAXPASSLEN 2048
|
||||
|
||||
/**
|
||||
* tarsnap_getpass(passwd, prompt, confirmprompt, devtty)
|
||||
* If ${devtty} is non-zero, read a password from /dev/tty if possible; if
|
||||
* not, read from stdin. If reading from a tty (either /dev/tty or stdin),
|
||||
* disable echo and prompt the user by printing ${prompt} to stderr. If
|
||||
* ${confirmprompt} is non-NULL, read a second password (prompting if a
|
||||
* terminal is being used) and repeat until the user enters the same password
|
||||
* twice. Return the password as a malloced NUL-terminated string via
|
||||
* ${passwd}. The obscure name is to avoid namespace collisions due to the
|
||||
* getpass / readpass / readpassphrase / etc. functions in various libraries.
|
||||
*/
|
||||
int pcp_readpass(char **, const char *, const char *, int);
|
||||
|
||||
#endif /* !_READPASS_H_ */
|
||||
74
src/usage.h
Normal file
74
src/usage.h
Normal file
@@ -0,0 +1,74 @@
|
||||
#ifndef _HAVE_USAGE_H
|
||||
#define _HAVE_USAGE_H
|
||||
#define PCP_HELP "\n" \
|
||||
"Usage: pcp1 [options]\n" \
|
||||
"\n" \
|
||||
"General Options:\n" \
|
||||
"-V --vault <vaultfile> Specify an alternate vault file.\n" \
|
||||
" The deault vault is ~/.pcpvault.\n" \
|
||||
"-O --outfile <file> Output file. If not specified, stdout\n" \
|
||||
" will be used.\n" \
|
||||
"-I --infile <file> Input file. If not specified, stdin\n" \
|
||||
" will be used.\n" \
|
||||
"-i --keyid <id> Specify a key id to import/export.\n" \
|
||||
"-t --text Print textual representation of some\n" \
|
||||
" item. Either -V or -i must be specified\n" \
|
||||
" as well.\n" \
|
||||
"-h --help Print this help message.\n" \
|
||||
"-v --version Print program version.\n" \
|
||||
"-D --debug Enable debug output.\n" \
|
||||
"\n" \
|
||||
"Keymanagement Options:\n" \
|
||||
"-k --keygen Generate a CURVE25519 secret key. If\n" \
|
||||
" the generated key is the first one in\n" \
|
||||
" your vault, it will become the primary\n" \
|
||||
" secret key.\n" \
|
||||
"-l --listkeys List all keys currently stored in your\n" \
|
||||
" vault. Only the key id's and some info\n" \
|
||||
" about the keys will be printed, not the\n" \
|
||||
" actual keys.\n" \
|
||||
"-r --remove-key Remove a key from the vault. Requires\n" \
|
||||
" option -i <keyid>.\n" \
|
||||
"-s --export-secret Export a secret key. If your vault only\n" \
|
||||
" contains one secret key, this one will\n" \
|
||||
" be exported. If a key id have been\n" \
|
||||
" specified (-i), this one will be used.\n" \
|
||||
" If there are more than one secret keys\n" \
|
||||
" in the vault and no key id has been\n" \
|
||||
" given, export the primary secret key.\n" \
|
||||
" Use -O to export to a file.\n" \
|
||||
"-p --export-public Export a public key. If no key id have\n" \
|
||||
" been specified, the public part of your\n" \
|
||||
" primary secret key will be exported.\n" \
|
||||
" Use -O to export to a file.\n" \
|
||||
"-S --import-secret Import a secret key. Use -I to import\n" \
|
||||
" from a file.\n" \
|
||||
"-P --import-public Import a public key. Use -I to import\n" \
|
||||
" from a file.\n" \
|
||||
"\n" \
|
||||
"Encryption Options:\n" \
|
||||
"-e --encrypt Encrypt a message. Read from stdin or\n" \
|
||||
" specified via -I. A keyid (-i) of the\n" \
|
||||
" public key of the receipient must be\n" \
|
||||
" specified. Output to stdout or written\n" \
|
||||
" to the file specified via -O.\n" \
|
||||
"-d --decrypt Decrypt a message. Read from stdin or\n" \
|
||||
" specified via -I. Output to stdout or\n" \
|
||||
" written to the file specified via -O.\n" \
|
||||
" The primary secret key will be used for\n" \
|
||||
" decryption, if there is no primary and\n" \
|
||||
" just one secret key in the vault, this\n" \
|
||||
" one will be used. Otherwise you'll have\n" \
|
||||
" to specify the keyid (-i) of the key.\n" \
|
||||
"\n" \
|
||||
"Encoding Options:\n" \
|
||||
"-z --z85-encode Encode something to Z85 encoding. Use\n" \
|
||||
" -I and -O respectively, otherwise it\n" \
|
||||
" stdin/stdout.\n" \
|
||||
"-Z --z85-decode Decode something from Z85 encoding. Use\n" \
|
||||
" -I and -O respectively, otherwise it\n" \
|
||||
" stdin/stdout\n" \
|
||||
"\n" \
|
||||
"\n" \
|
||||
"\n"
|
||||
#endif
|
||||
10
src/usage.sh
Executable file
10
src/usage.sh
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
(echo "#ifndef _HAVE_USAGE_H"; echo "#define _HAVE_USAGE_H") > usage.h
|
||||
|
||||
echo -n "#define PCP_HELP " >> usage.h
|
||||
|
||||
cat usage.txt | sed -e 's/^/"/' -e 's/$/\\n" \\/' >> usage.h
|
||||
|
||||
echo "\"\\n\"" >> usage.h
|
||||
echo "#endif" >> usage.h
|
||||
70
src/usage.txt
Normal file
70
src/usage.txt
Normal file
@@ -0,0 +1,70 @@
|
||||
|
||||
Usage: pcp1 [options]
|
||||
|
||||
General Options:
|
||||
-V --vault <vaultfile> Specify an alternate vault file.
|
||||
The deault vault is ~/.pcpvault.
|
||||
-O --outfile <file> Output file. If not specified, stdout
|
||||
will be used.
|
||||
-I --infile <file> Input file. If not specified, stdin
|
||||
will be used.
|
||||
-i --keyid <id> Specify a key id to import/export.
|
||||
-t --text Print textual representation of some
|
||||
item. Either -V or -i must be specified
|
||||
as well.
|
||||
-h --help Print this help message.
|
||||
-v --version Print program version.
|
||||
-D --debug Enable debug output.
|
||||
|
||||
Keymanagement Options:
|
||||
-k --keygen Generate a CURVE25519 secret key. If
|
||||
the generated key is the first one in
|
||||
your vault, it will become the primary
|
||||
secret key.
|
||||
-l --listkeys List all keys currently stored in your
|
||||
vault. Only the key id's and some info
|
||||
about the keys will be printed, not the
|
||||
actual keys.
|
||||
-r --remove-key Remove a key from the vault. Requires
|
||||
option -i <keyid>.
|
||||
-s --export-secret Export a secret key. If your vault only
|
||||
contains one secret key, this one will
|
||||
be exported. If a key id have been
|
||||
specified (-i), this one will be used.
|
||||
If there are more than one secret keys
|
||||
in the vault and no key id has been
|
||||
given, export the primary secret key.
|
||||
Use -O to export to a file.
|
||||
-p --export-public Export a public key. If no key id have
|
||||
been specified, the public part of your
|
||||
primary secret key will be exported.
|
||||
Use -O to export to a file.
|
||||
-S --import-secret Import a secret key. Use -I to import
|
||||
from a file.
|
||||
-P --import-public Import a public key. Use -I to import
|
||||
from a file.
|
||||
|
||||
Encryption Options:
|
||||
-e --encrypt Encrypt a message. Read from stdin or
|
||||
specified via -I. A keyid (-i) of the
|
||||
public key of the receipient must be
|
||||
specified. Output to stdout or written
|
||||
to the file specified via -O.
|
||||
-d --decrypt Decrypt a message. Read from stdin or
|
||||
specified via -I. Output to stdout or
|
||||
written to the file specified via -O.
|
||||
The primary secret key will be used for
|
||||
decryption, if there is no primary and
|
||||
just one secret key in the vault, this
|
||||
one will be used. Otherwise you'll have
|
||||
to specify the keyid (-i) of the key.
|
||||
|
||||
Encoding Options:
|
||||
-z --z85-encode Encode something to Z85 encoding. Use
|
||||
-I and -O respectively, otherwise it
|
||||
stdin/stdout.
|
||||
-Z --z85-decode Decode something from Z85 encoding. Use
|
||||
-I and -O respectively, otherwise it
|
||||
stdin/stdout
|
||||
|
||||
|
||||
119
src/z85util.c
Normal file
119
src/z85util.c
Normal file
@@ -0,0 +1,119 @@
|
||||
#include "z85util.h"
|
||||
|
||||
int pcpz85_encode(char *infile, char *outfile) {
|
||||
FILE *in;
|
||||
FILE *out;
|
||||
|
||||
if(infile == NULL)
|
||||
in = stdin;
|
||||
else {
|
||||
if((in = fopen(infile, "rb")) == NULL) {
|
||||
fatal("Could not open input file %s\n", infile);
|
||||
goto errz1;
|
||||
}
|
||||
}
|
||||
|
||||
if(outfile == NULL)
|
||||
out = stdout;
|
||||
else {
|
||||
if((out = fopen(outfile, "wb+")) == NULL) {
|
||||
fatal("Could not open output file %s\n", outfile);
|
||||
goto errz1;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char *input = NULL;
|
||||
size_t inputBufSize = 0;
|
||||
unsigned char byte[1];
|
||||
|
||||
while(!feof(in)) {
|
||||
if(!fread(&byte, 1, 1, in))
|
||||
break;
|
||||
unsigned char *tmp = realloc(input, inputBufSize + 1);
|
||||
input = tmp;
|
||||
memmove(&input[inputBufSize], byte, 1);
|
||||
inputBufSize ++;
|
||||
}
|
||||
fclose(in);
|
||||
|
||||
if(inputBufSize == 0) {
|
||||
fatal("Input file is empty!\n");
|
||||
goto errz2;
|
||||
}
|
||||
|
||||
size_t zlen;
|
||||
char *encoded = pcp_z85_encode(input, inputBufSize, &zlen);
|
||||
|
||||
if(encoded != NULL) {
|
||||
fprintf(out, "%s\n%s\n%s\n", PCP_ZFILE_HEADER, encoded, PCP_ZFILE_FOOTER);
|
||||
if(ferror(out) != 0) {
|
||||
fatal("Failed to write z85 output!\n");
|
||||
}
|
||||
free(encoded);
|
||||
goto errz2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
errz2:
|
||||
free(input);
|
||||
|
||||
errz1:
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int pcpz85_decode(char *infile, char *outfile) {
|
||||
FILE *in;
|
||||
FILE *out;
|
||||
|
||||
if(infile == NULL)
|
||||
in = stdin;
|
||||
else {
|
||||
if((in = fopen(infile, "rb")) == NULL) {
|
||||
fatal("Could not open input file %s\n", infile);
|
||||
goto errdz1;
|
||||
}
|
||||
}
|
||||
|
||||
if(outfile == NULL)
|
||||
out = stdout;
|
||||
else {
|
||||
if((out = fopen(outfile, "wb+")) == NULL) {
|
||||
fatal("Could not open output file %s\n", outfile);
|
||||
goto errdz1;
|
||||
}
|
||||
}
|
||||
|
||||
char *encoded = pcp_readz85file(in);
|
||||
|
||||
if(encoded == NULL)
|
||||
goto errdz1;
|
||||
|
||||
size_t clen;
|
||||
unsigned char *decoded = pcp_z85_decode(encoded, &clen);
|
||||
|
||||
if(decoded == NULL)
|
||||
goto errdz2;
|
||||
|
||||
fwrite(decoded, clen, 1, out);
|
||||
fclose(out);
|
||||
if(ferror(out) != 0) {
|
||||
fatal("Failed to write decoded output!\n");
|
||||
goto errdz3;
|
||||
}
|
||||
|
||||
free(decoded);
|
||||
return 0;
|
||||
|
||||
errdz3:
|
||||
free(decoded);
|
||||
|
||||
errdz2:
|
||||
free(encoded);
|
||||
|
||||
errdz1:
|
||||
return 1;
|
||||
}
|
||||
19
src/z85util.h
Normal file
19
src/z85util.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef _HAVE_PCP_Z85
|
||||
#define _HAVE_PCP_Z85
|
||||
|
||||
#define _BSD_SOURCE
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "mem.h"
|
||||
#include "z85.h"
|
||||
#include "zmq_z85.h"
|
||||
#include "defines.h"
|
||||
|
||||
int pcpz85_encode(char *infile, char *outfile);
|
||||
int pcpz85_decode(char *infile, char *outfile);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user