Page MenuHome GnuPG

No OneTemporary

diff --git a/src/Makefile.am b/src/Makefile.am
index 32e3045c..7af66325 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,113 +1,115 @@
# Makefile.am for GPGMEPP.
# Copyright (C) 2016 Bundesamt für Sicherheit in der Informationstechnik
# Software engineering by Intevation GmbH
#
# This file is part of GPGMEPP.
#
# GPGME-CL 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.
#
# GPGME-CL 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA
EXTRA_DIST = GpgmeppConfig.cmake.in.in GpgmeppConfigVersion.cmake.in \
gpgmepp_version.h.in GpgmeppConfig-w32.cmake.in.in
lib_LTLIBRARIES = libgpgmepp.la
main_sources = \
exception.cpp context.cpp key.cpp trustitem.cpp data.cpp callbacks.cpp \
eventloopinteractor.cpp editinteractor.cpp \
keylistresult.cpp keygenerationresult.cpp importresult.cpp \
decryptionresult.cpp verificationresult.cpp \
signingresult.cpp encryptionresult.cpp \
engineinfo.cpp gpgsetexpirytimeeditinteractor.cpp \
gpgsetownertrusteditinteractor.cpp gpgsignkeyeditinteractor.cpp \
gpgadduserideditinteractor.cpp gpggencardkeyinteractor.cpp \
+ gpgaddexistingsubkeyeditinteractor.cpp \
defaultassuantransaction.cpp \
scdgetinfoassuantransaction.cpp gpgagentgetinfoassuantransaction.cpp \
statusconsumerassuantransaction.cpp \
vfsmountresult.cpp configuration.cpp tofuinfo.cpp swdbresult.cpp
gpgmepp_headers = \
configuration.h context.h data.h decryptionresult.h \
defaultassuantransaction.h editinteractor.h encryptionresult.h \
engineinfo.h error.h eventloopinteractor.h exception.h global.h \
gpgadduserideditinteractor.h gpgagentgetinfoassuantransaction.h \
gpgmefw.h gpgsetexpirytimeeditinteractor.h \
gpgsetownertrusteditinteractor.h gpgsignkeyeditinteractor.h \
gpggencardkeyinteractor.h \
+ gpgaddexistingsubkeyeditinteractor.h \
importresult.h keygenerationresult.h key.h keylistresult.h \
notation.h result.h scdgetinfoassuantransaction.h signingresult.h \
statusconsumerassuantransaction.h \
trustitem.h verificationresult.h vfsmountresult.h gpgmepp_export.h \
tofuinfo.h swdbresult.h
private_gpgmepp_headers = \
result_p.h context_p.h util.h callbacks.h data_p.h
interface_headers= \
interfaces/assuantransaction.h interfaces/dataprovider.h \
interfaces/passphraseprovider.h interfaces/progressprovider.h \
interfaces/statusconsumer.h
gpgmeppincludedir = $(includedir)/gpgme++
gpgmeppinclude_HEADERS = $(gpgmepp_headers)
nobase_gpgmeppinclude_HEADERS = $(interface_headers)
nodist_gpgmeppinclude_HEADERS = gpgmepp_version.h
libgpgmepp_la_SOURCES = $(main_sources) $(gpgmepp_headers) context_vanilla.cpp \
$(interface_headers) $(private_gpgmepp_headers)
AM_CPPFLAGS = -I$(top_builddir)/src @GPG_ERROR_CFLAGS@ @LIBASSUAN_CFLAGS@ \
-DBUILDING_GPGMEPP -Wsuggest-override \
-Wzero-as-null-pointer-constant
libgpgmepp_la_LIBADD = ../../../src/libgpgme.la @LIBASSUAN_LIBS@
libgpgmepp_la_LDFLAGS = -no-undefined -version-info \
@LIBGPGMEPP_LT_CURRENT@:@LIBGPGMEPP_LT_REVISION@:@LIBGPGMEPP_LT_AGE@
if HAVE_MACOS_SYSTEM
libsuffix=.dylib
else
libsuffix=.so
endif
if HAVE_W32_SYSTEM
GpgmeppConfig.cmake: GpgmeppConfig-w32.cmake.in
sed -e 's|[@]resolved_bindir@|$(bindir)|g' < "$<" | \
sed -e 's|[@]resolved_libdir@|$(libdir)|g' | \
sed -e 's|[@]resolved_includedir@|$(includedir)|g' > $@
else
GpgmeppConfig.cmake: GpgmeppConfig.cmake.in
sed -e 's|[@]resolved_libdir@|$(libdir)|g' < "$<" | \
sed -e 's|[@]libsuffix@|$(libsuffix)|g' | \
sed -e 's|[@]resolved_includedir@|$(includedir)|g' > $@
endif
install-cmake-files: GpgmeppConfig.cmake GpgmeppConfigVersion.cmake
-$(INSTALL) -d $(DESTDIR)$(libdir)/cmake/Gpgmepp
$(INSTALL) -m 644 GpgmeppConfig.cmake \
$(DESTDIR)$(libdir)/cmake/Gpgmepp/GpgmeppConfig.cmake
$(INSTALL) -m 644 GpgmeppConfigVersion.cmake \
$(DESTDIR)$(libdir)/cmake/Gpgmepp/GpgmeppConfigVersion.cmake
uninstall-cmake-files:
-rm $(DESTDIR)$(libdir)/cmake/Gpgmepp/GpgmeppConfigVersion.cmake
-rm $(DESTDIR)$(libdir)/cmake/Gpgmepp/GpgmeppConfig.cmake
-rmdir $(DESTDIR)$(libdir)/cmake/Gpgmepp/
install-data-local: install-cmake-files
uninstall-local: uninstall-cmake-files
CLEANFILES = GpgmeppConfig.cmake GpgmeppConfigVersion.cmake \
gpgmepp_version.h GpgmeppConfig.cmake.in
diff --git a/src/gpgaddexistingsubkeyeditinteractor.cpp b/src/gpgaddexistingsubkeyeditinteractor.cpp
new file mode 100644
index 00000000..547e613d
--- /dev/null
+++ b/src/gpgaddexistingsubkeyeditinteractor.cpp
@@ -0,0 +1,209 @@
+/*
+ gpgaddexistingsubkeyeditinteractor.cpp - Edit Interactor to add an existing subkey to an OpenPGP key
+ Copyright (c) 2022 g10 Code GmbH
+ Software engineering by Ingo Klöcker <dev@ingo-kloecker.de>
+
+ This file is part of GPGME++.
+
+ GPGME++ is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ GPGME++ 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with GPGME++; see the file COPYING.LIB. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifdef HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include "gpgaddexistingsubkeyeditinteractor.h"
+
+#include "error.h"
+
+#include <gpgme.h>
+
+// avoid conflict (msvc)
+#ifdef ERROR
+# undef ERROR
+#endif
+
+using namespace GpgME;
+
+class GpgAddExistingSubkeyEditInteractor::Private
+{
+ enum {
+ START = EditInteractor::StartState,
+ COMMAND,
+ ADD_EXISTING_KEY,
+ KEYGRIP,
+ FLAGS,
+ VALID,
+ KEY_CREATED,
+ QUIT,
+ SAVE,
+
+ ERROR = EditInteractor::ErrorState
+ };
+
+ GpgAddExistingSubkeyEditInteractor *const q = nullptr;
+
+public:
+ Private(GpgAddExistingSubkeyEditInteractor *q, const std::string &keygrip)
+ : q{q}
+ , keygrip{keygrip}
+ {
+ }
+
+ const char *action(Error &err) const;
+ unsigned int nextState(unsigned int statusCode, const char *args, Error &err) const;
+
+ std::string keygrip;
+ std::string expiry;
+};
+
+const char *GpgAddExistingSubkeyEditInteractor::Private::action(Error &err) const
+{
+ switch (q->state()) {
+ case COMMAND:
+ return "addkey";
+ case ADD_EXISTING_KEY:
+ return "keygrip";
+ case KEYGRIP:
+ return keygrip.c_str();
+ case FLAGS:
+ return "Q"; // do not toggle any usage flags
+ case VALID:
+ return expiry.empty() ? "0" : expiry.c_str();
+ case QUIT:
+ return "quit";
+ case SAVE:
+ return "Y";
+ case START:
+ case KEY_CREATED:
+ case ERROR:
+ return nullptr;
+ default:
+ err = Error::fromCode(GPG_ERR_GENERAL);
+ return nullptr;
+ }
+}
+
+unsigned int GpgAddExistingSubkeyEditInteractor::Private::nextState(unsigned int status, const char *args, Error &err) const
+{
+ using std::strcmp;
+
+ static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL);
+ static const Error NO_KEY_ERROR = Error::fromCode(GPG_ERR_NO_KEY);
+ static const Error INV_TIME_ERROR = Error::fromCode(GPG_ERR_INV_TIME);
+
+ if (q->needsNoResponse(status)) {
+ return q->state();
+ }
+
+ switch (q->state()) {
+ case START:
+ if (status == GPGME_STATUS_GET_LINE &&
+ strcmp(args, "keyedit.prompt") == 0) {
+ return COMMAND;
+ }
+ err = GENERAL_ERROR;
+ return ERROR;
+ case COMMAND:
+ if (status == GPGME_STATUS_GET_LINE &&
+ strcmp(args, "keygen.algo") == 0) {
+ return ADD_EXISTING_KEY;
+ }
+ err = GENERAL_ERROR;
+ return ERROR;
+ case ADD_EXISTING_KEY:
+ if (status == GPGME_STATUS_GET_LINE &&
+ strcmp(args, "keygen.keygrip") == 0) {
+ return KEYGRIP;
+ }
+ err = GENERAL_ERROR;
+ return ERROR;
+ case KEYGRIP:
+ if (status == GPGME_STATUS_GET_LINE &&
+ strcmp(args, "keygen.flags") == 0) {
+ return FLAGS;
+ } else if (status == GPGME_STATUS_GET_LINE &&
+ strcmp(args, "keygen.keygrip")) {
+ err = NO_KEY_ERROR;
+ return ERROR;
+ }
+ err = GENERAL_ERROR;
+ return ERROR;
+ case FLAGS:
+ if (status == GPGME_STATUS_GET_LINE &&
+ strcmp(args, "keygen.valid") == 0) {
+ return VALID;
+ }
+ err = GENERAL_ERROR;
+ return ERROR;
+ case VALID:
+ if (status == GPGME_STATUS_KEY_CREATED) {
+ return KEY_CREATED;
+ }
+ if (status == GPGME_STATUS_GET_LINE &&
+ strcmp(args, "keyedit.prompt") == 0) {
+ return QUIT;
+ } else if (status == GPGME_STATUS_GET_LINE &&
+ strcmp(args, "keygen.valid")) {
+ err = INV_TIME_ERROR;
+ return ERROR;
+ }
+ err = GENERAL_ERROR;
+ return ERROR;
+ case KEY_CREATED:
+ return QUIT;
+ case QUIT:
+ if (status == GPGME_STATUS_GET_BOOL &&
+ strcmp(args, "keyedit.save.okay") == 0) {
+ return SAVE;
+ }
+ err = GENERAL_ERROR;
+ return ERROR;
+ case ERROR:
+ if (status == GPGME_STATUS_GET_LINE &&
+ strcmp(args, "keyedit.prompt") == 0) {
+ return QUIT;
+ }
+ err = q->lastError();
+ return ERROR;
+ default:
+ err = GENERAL_ERROR;
+ return ERROR;
+ }
+}
+
+GpgAddExistingSubkeyEditInteractor::GpgAddExistingSubkeyEditInteractor(const std::string &keygrip)
+ : EditInteractor{}
+ , d{new Private{this, keygrip}}
+{
+}
+
+GpgAddExistingSubkeyEditInteractor::~GpgAddExistingSubkeyEditInteractor() = default;
+
+void GpgAddExistingSubkeyEditInteractor::setExpiry(const std::string &timeString)
+{
+ d->expiry = timeString;
+}
+
+const char *GpgAddExistingSubkeyEditInteractor::action(Error &err) const
+{
+ return d->action(err);
+}
+
+unsigned int GpgAddExistingSubkeyEditInteractor::nextState(unsigned int status, const char *args, Error &err) const
+{
+ return d->nextState(status, args, err);
+}
diff --git a/src/gpgaddexistingsubkeyeditinteractor.h b/src/gpgaddexistingsubkeyeditinteractor.h
new file mode 100644
index 00000000..c30f18e4
--- /dev/null
+++ b/src/gpgaddexistingsubkeyeditinteractor.h
@@ -0,0 +1,59 @@
+/*
+ gpgaddexistingsubkeyeditinteractor.h - Edit Interactor to add an existing subkey to an OpenPGP key
+ Copyright (c) 2022 g10 Code GmbH
+ Software engineering by Ingo Klöcker <dev@ingo-kloecker.de>
+
+ This file is part of GPGME++.
+
+ GPGME++ is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ GPGME++ 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with GPGME++; see the file COPYING.LIB. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef __GPGMEPP_GPGADDEXISTINGSUBKEYEDITINTERACTOR_H__
+#define __GPGMEPP_GPGADDEXISTINGSUBKEYEDITINTERACTOR_H__
+
+#include "editinteractor.h"
+
+#include <memory>
+
+namespace GpgME
+{
+
+class GPGMEPP_EXPORT GpgAddExistingSubkeyEditInteractor : public EditInteractor
+{
+public:
+ /** Edit interactor to add the existing subkey with keygrip \a keygrip
+ * to the key a key edit operation is working on.
+ **/
+ explicit GpgAddExistingSubkeyEditInteractor(const std::string &keygrip);
+ ~GpgAddExistingSubkeyEditInteractor() override;
+
+ /** Sets the validity period of the added subkey. Use "0" for no expiration
+ * or a simplified ISO date string ("yyyymmddThhmmss") for setting an
+ * expiration date. */
+ void setExpiry(const std::string &timeString);
+
+private:
+ const char *action(Error &err) const override;
+ unsigned int nextState(unsigned int statusCode, const char *args, Error &err) const override;
+
+private:
+ class Private;
+ const std::unique_ptr<Private> d;
+};
+
+} // namespace GpgME
+
+#endif // __GPGMEPP_GPGADDEXISTINGSUBKEYEDITINTERACTOR_H__

File Metadata

Mime Type
text/x-diff
Expires
Mon, Dec 8, 3:26 AM (8 h, 14 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
40/ca/e5dd9dc9edf1775adcfe57977237

Event Timeline