From d41c4d4a554aa893460b9da6670e7b87bf73c83c Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Wed, 8 Nov 2017 16:07:39 +0100
Subject: Initial commit
---
LICENSE | 13 +
README.adoc | 54 +++
meson.build | 3 +
pdf-simple-sign.cpp | 976 ++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 1046 insertions(+)
create mode 100644 LICENSE
create mode 100644 README.adoc
create mode 100644 meson.build
create mode 100644 pdf-simple-sign.cpp
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..c949ca2
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,13 @@
+Copyright (c) 2017, Přemysl Janouch
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/README.adoc b/README.adoc
new file mode 100644
index 0000000..5e09599
--- /dev/null
+++ b/README.adoc
@@ -0,0 +1,54 @@
+pdf-simple-sign
+===============
+:compact-option:
+
+'pdf-simple-sign' is a simple open source PDF signer intended for documents
+generated by Cairo. As such, it currently comes with some restrictions:
+
+ * the document may not have any forms or signatures already, as they will be
+ overwitten
+ * the document may not employ cross-reference streams, or must constitute
+ a hybrid-reference file at least
+ * the document may not be newer than PDF 1.6 already, or it will get downgraded
+ to that version
+ * the signature may take at most 4 kilobytes as a compile-time limit,
+ which should be enough space even for one intermediate certificate
+
+The signature is attached to the first page and has no appearance.
+
+I don't aim to extend the functionality any further. The project is fairly
+self-contained and it should be easy to grasp and change to suit to your needs.
+
+Building
+--------
+Build dependencies: Meson, a C++11 compiler, pkg-config +
+Runtime dependencies: libcrypto
+
+ $ git clone https://github.com/pjanouch/pdf-simple-sign.git
+ $ cd pdf-simple-sign
+ $ meson builddir
+ $ cd builddir
+ $ ninja
+
+Usage
+-----
+
+ $ ./pdf-simple-sign document.pdf document.signed.pdf KeyAndCerts.p12 password
+
+Contributing and Support
+------------------------
+Use this project's GitHub to report any bugs, request features, or submit pull
+requests. If you want to discuss this project, or maybe just hang out with
+the developer, feel free to join me at irc://irc.janouch.name, channel #dev.
+
+Bitcoin donations: 12r5uEWEgcHC46xd64tt3hHt9EUvYYDHe9
+
+License
+-------
+'pdf-simple-sign' is written by Přemysl Janouch .
+
+You may use the software under the terms of the ISC license, the text of which
+is included within the package, or, at your option, you may relicense the work
+under the MIT or the Modified BSD License, as listed at the following site:
+
+http://www.gnu.org/licenses/license-list.html
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..2d2cec3
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,3 @@
+project('pdf-simple-sign', 'cpp', default_options : ['cpp_std=c++11'])
+cryptodep = dependency('libcrypto')
+executable('pdf-simple-sign', 'pdf-simple-sign.cpp', dependencies : cryptodep)
diff --git a/pdf-simple-sign.cpp b/pdf-simple-sign.cpp
new file mode 100644
index 0000000..e95aaa2
--- /dev/null
+++ b/pdf-simple-sign.cpp
@@ -0,0 +1,976 @@
+// vim: set sw=2 ts=2 sts=2 et tw=100:
+//
+// pdf-simple-sign: simple PDF signer
+//
+// Copyright (c) 2017, Přemysl Janouch
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+//
+
+#include
+#include
+#undef NDEBUG
+#include
+
+#include
+#include