|
|
@ -1,67 +1,67 @@
|
|
|
|
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc
|
|
|
|
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc
|
|
|
|
index 3eeea86..2a6923c 100644
|
|
|
|
index 3475afe..f93ba0d 100644
|
|
|
|
--- a/libqpdf/QPDF.cc
|
|
|
|
--- a/libqpdf/QPDF.cc
|
|
|
|
+++ b/libqpdf/QPDF.cc
|
|
|
|
+++ b/libqpdf/QPDF.cc
|
|
|
|
@@ -11,6 +11,10 @@
|
|
|
|
@@ -19,6 +19,10 @@
|
|
|
|
#include <string.h>
|
|
|
|
#include <qpdf/QPDF_Null.hh>
|
|
|
|
#include <memory.h>
|
|
|
|
#include <qpdf/QPDF_Dictionary.hh>
|
|
|
|
|
|
|
|
|
|
|
|
+#ifdef USE_CRYPTO_GNUTLS
|
|
|
|
+#ifdef HAVE_GNUTLS
|
|
|
|
+# include <gnutls/crypto.h>
|
|
|
|
+# include <gnutls/crypto.h>
|
|
|
|
+#endif
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+
|
|
|
|
#include <qpdf/QTC.hh>
|
|
|
|
std::string QPDF::qpdf_version = "7.1.1";
|
|
|
|
#include <qpdf/QUtil.hh>
|
|
|
|
|
|
|
|
#include <qpdf/Pipeline.hh>
|
|
|
|
static char const* EMPTY_PDF =
|
|
|
|
@@ -262,7 +266,13 @@ QPDF::processFile(char const* filename, char const* password)
|
|
|
|
@@ -139,7 +143,13 @@ QPDF::processFile(char const* filename, char const* password)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FileInputSource* fi = new FileInputSource();
|
|
|
|
FileInputSource* fi = new FileInputSource();
|
|
|
|
fi->setFilename(filename);
|
|
|
|
fi->setFilename(filename);
|
|
|
|
+#ifdef USE_CRYPTO_GNUTLS
|
|
|
|
+#ifdef HAVE_GNUTLS
|
|
|
|
+ GNUTLS_FIPS140_SET_LAX_MODE();
|
|
|
|
+ GNUTLS_FIPS140_SET_LAX_MODE();
|
|
|
|
+#endif
|
|
|
|
+#endif
|
|
|
|
processInputSource(fi, password);
|
|
|
|
processInputSource(fi, password);
|
|
|
|
+#ifdef USE_CRYPTO_GNUTLS
|
|
|
|
+#ifdef HAVE_GNUTLS
|
|
|
|
+ GNUTLS_FIPS140_SET_STRICT_MODE();
|
|
|
|
+ GNUTLS_FIPS140_SET_STRICT_MODE();
|
|
|
|
+#endif
|
|
|
|
+#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
@@ -271,7 +281,13 @@ QPDF::processFile(char const* description, FILE* filep,
|
|
|
|
@@ -148,7 +158,13 @@ QPDF::processFile(char const* description, FILE* filep,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FileInputSource* fi = new FileInputSource();
|
|
|
|
FileInputSource* fi = new FileInputSource();
|
|
|
|
fi->setFile(description, filep, close_file);
|
|
|
|
fi->setFile(description, filep, close_file);
|
|
|
|
+#ifdef USE_CRYPTO_GNUTLS
|
|
|
|
+#ifdef HAVE_GNUTLS
|
|
|
|
+ GNUTLS_FIPS140_SET_LAX_MODE();
|
|
|
|
+ GNUTLS_FIPS140_SET_LAX_MODE();
|
|
|
|
+#endif
|
|
|
|
+#endif
|
|
|
|
processInputSource(fi, password);
|
|
|
|
processInputSource(fi, password);
|
|
|
|
+#ifdef USE_CRYPTO_GNUTLS
|
|
|
|
+#ifdef HAVE_GNUTLS
|
|
|
|
+ GNUTLS_FIPS140_SET_STRICT_MODE();
|
|
|
|
+ GNUTLS_FIPS140_SET_STRICT_MODE();
|
|
|
|
+#endif
|
|
|
|
+#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc
|
|
|
|
diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc
|
|
|
|
index 689fef7..57df1eb 100644
|
|
|
|
index 0544640..48fe50d 100644
|
|
|
|
--- a/libqpdf/QPDFWriter.cc
|
|
|
|
--- a/libqpdf/QPDFWriter.cc
|
|
|
|
+++ b/libqpdf/QPDFWriter.cc
|
|
|
|
+++ b/libqpdf/QPDFWriter.cc
|
|
|
|
@@ -24,6 +24,10 @@
|
|
|
|
@@ -23,6 +23,10 @@
|
|
|
|
#include <algorithm>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
|
|
+#ifdef USE_CRYPTO_GNUTLS
|
|
|
|
+#ifdef HAVE_GNUTLS
|
|
|
|
+#include <gnutls/crypto.h>
|
|
|
|
+#include <gnutls/crypto.h>
|
|
|
|
+#endif
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+
|
|
|
|
QPDFWriter::Members::Members(QPDF& pdf) :
|
|
|
|
QPDFWriter::Members::Members(QPDF& pdf) :
|
|
|
|
pdf(pdf),
|
|
|
|
pdf(pdf),
|
|
|
|
filename("unspecified"),
|
|
|
|
filename(0),
|
|
|
|
@@ -321,6 +325,13 @@ void
|
|
|
|
@@ -323,6 +327,13 @@ void
|
|
|
|
QPDFWriter::setDeterministicID(bool val)
|
|
|
|
QPDFWriter::setDeterministicID(bool val)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this->m->deterministic_id = val;
|
|
|
|
this->m->deterministic_id = val;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+#ifdef USE_CRYPTO_GNUTLS
|
|
|
|
+#ifdef HAVE_GNUTLS
|
|
|
|
+ if (val)
|
|
|
|
+ if (val)
|
|
|
|
+ GNUTLS_FIPS140_SET_LAX_MODE();
|
|
|
|
+ GNUTLS_FIPS140_SET_LAX_MODE();
|
|
|
|
+ else
|
|
|
|
+ else
|
|
|
@ -70,12 +70,12 @@ index 689fef7..57df1eb 100644
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
@@ -342,6 +353,13 @@ void
|
|
|
|
@@ -344,6 +355,13 @@ void
|
|
|
|
QPDFWriter::setPreserveEncryption(bool val)
|
|
|
|
QPDFWriter::setPreserveEncryption(bool val)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this->m->preserve_encryption = val;
|
|
|
|
this->m->preserve_encryption = val;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+#ifdef USE_CRYPTO_GNUTLS
|
|
|
|
+#ifdef HAVE_GNUTLS
|
|
|
|
+ if (val)
|
|
|
|
+ if (val)
|
|
|
|
+ GNUTLS_FIPS140_SET_STRICT_MODE();
|
|
|
|
+ GNUTLS_FIPS140_SET_STRICT_MODE();
|
|
|
|
+ else
|
|
|
|
+ else
|
|
|
@ -84,32 +84,8 @@ index 689fef7..57df1eb 100644
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
@@ -2301,12 +2319,23 @@ QPDFWriter::generateID()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+#ifdef USE_CRYPTO_GNUTLS
|
|
|
|
|
|
|
|
+ unsigned oldmode = gnutls_fips140_mode_enabled();
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
+ gnutls_fips140_set_mode(GNUTLS_FIPS140_LAX, GNUTLS_FIPS140_SET_MODE_THREAD);
|
|
|
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
MD5 m;
|
|
|
|
|
|
|
|
m.encodeString(seed.c_str());
|
|
|
|
|
|
|
|
MD5::Digest digest;
|
|
|
|
|
|
|
|
m.digest(digest);
|
|
|
|
|
|
|
|
result = std::string(reinterpret_cast<char*>(digest),
|
|
|
|
|
|
|
|
sizeof(MD5::Digest));
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
+#ifdef USE_CRYPTO_GNUTLS
|
|
|
|
|
|
|
|
+ gnutls_fips140_set_mode(static_cast<gnutls_fips_mode_t>(oldmode), GNUTLS_FIPS140_SET_MODE_THREAD);
|
|
|
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If /ID already exists, follow the spec: use the original first
|
|
|
|
|
|
|
|
diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc
|
|
|
|
diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc
|
|
|
|
index 2ff48df..ce6fb31 100644
|
|
|
|
index fd717c3..9b38914 100644
|
|
|
|
--- a/libqpdf/QPDF_encryption.cc
|
|
|
|
--- a/libqpdf/QPDF_encryption.cc
|
|
|
|
+++ b/libqpdf/QPDF_encryption.cc
|
|
|
|
+++ b/libqpdf/QPDF_encryption.cc
|
|
|
|
@@ -1,6 +1,8 @@
|
|
|
|
@@ -1,6 +1,8 @@
|
|
|
@ -125,40 +101,18 @@ index 2ff48df..ce6fb31 100644
|
|
|
|
#include <assert.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
|
|
+#ifdef USE_CRYPTO_GNUTLS
|
|
|
|
+#ifdef HAVE_GNUTLS
|
|
|
|
+# include <gnutls/crypto.h>
|
|
|
|
+# include <gnutls/crypto.h>
|
|
|
|
+#endif
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+
|
|
|
|
static unsigned char const padding_string[] = {
|
|
|
|
static unsigned char const padding_string[] = {
|
|
|
|
0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41,
|
|
|
|
0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41,
|
|
|
|
0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08,
|
|
|
|
0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08,
|
|
|
|
@@ -380,10 +386,21 @@ QPDF::compute_data_key(std::string const& encryption_key,
|
|
|
|
@@ -1084,6 +1090,12 @@ QPDF::getKeyForObject(int objid, int generation, bool use_aes)
|
|
|
|
result += "sAlT";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+#ifdef USE_CRYPTO_GNUTLS
|
|
|
|
|
|
|
|
+ unsigned oldmode = gnutls_fips140_mode_enabled();
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
+ gnutls_fips140_set_mode(GNUTLS_FIPS140_LAX, GNUTLS_FIPS140_SET_MODE_THREAD);
|
|
|
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
MD5 md5;
|
|
|
|
|
|
|
|
md5.encodeDataIncrementally(result.c_str(), result.length());
|
|
|
|
|
|
|
|
MD5::Digest digest;
|
|
|
|
|
|
|
|
md5.digest(digest);
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
+#ifdef USE_CRYPTO_GNUTLS
|
|
|
|
|
|
|
|
+ gnutls_fips140_set_mode(static_cast<gnutls_fips_mode_t>(oldmode), GNUTLS_FIPS140_SET_MODE_THREAD);
|
|
|
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
return std::string(reinterpret_cast<char*>(digest),
|
|
|
|
|
|
|
|
std::min(result.length(), toS(16)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1150,6 +1167,12 @@ QPDF::getKeyForObject(
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
QPDF::decryptString(std::string& str, int objid, int generation)
|
|
|
|
QPDF::decryptString(std::string& str, int objid, int generation)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
+#ifdef USE_CRYPTO_GNUTLS
|
|
|
|
+#ifdef HAVE_GNUTLS
|
|
|
|
+ unsigned oldmode = gnutls_fips140_mode_enabled();
|
|
|
|
+ unsigned oldmode = gnutls_fips140_mode_enabled();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ gnutls_fips140_set_mode(GNUTLS_FIPS140_LAX, GNUTLS_FIPS140_SET_MODE_THREAD);
|
|
|
|
+ gnutls_fips140_set_mode(GNUTLS_FIPS140_LAX, GNUTLS_FIPS140_SET_MODE_THREAD);
|
|
|
@ -167,22 +121,22 @@ index 2ff48df..ce6fb31 100644
|
|
|
|
if (objid == 0)
|
|
|
|
if (objid == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
@@ -1230,6 +1253,10 @@ QPDF::decryptString(std::string& str, int objid, int generation)
|
|
|
|
@@ -1162,6 +1174,10 @@ QPDF::decryptString(std::string& str, int objid, int generation)
|
|
|
|
QUtil::int_to_string(objid) + " " +
|
|
|
|
QUtil::int_to_string(objid) + " " +
|
|
|
|
QUtil::int_to_string(generation) + ": " + e.what());
|
|
|
|
QUtil::int_to_string(generation) + ": " + e.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+#ifdef USE_CRYPTO_GNUTLS
|
|
|
|
+#ifdef HAVE_GNUTLS
|
|
|
|
+ gnutls_fips140_set_mode(static_cast<gnutls_fips_mode_t>(oldmode), GNUTLS_FIPS140_SET_MODE_THREAD);
|
|
|
|
+ gnutls_fips140_set_mode(static_cast<gnutls_fips_mode_t>(oldmode), GNUTLS_FIPS140_SET_MODE_THREAD);
|
|
|
|
+#endif
|
|
|
|
+#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
@@ -1240,6 +1267,12 @@ QPDF::decryptStream(PointerHolder<EncryptionParameters> encp,
|
|
|
|
@@ -1169,6 +1185,12 @@ QPDF::decryptStream(Pipeline*& pipeline, int objid, int generation,
|
|
|
|
QPDFObjectHandle& stream_dict,
|
|
|
|
QPDFObjectHandle& stream_dict,
|
|
|
|
std::vector<PointerHolder<Pipeline> >& heap)
|
|
|
|
std::vector<PointerHolder<Pipeline> >& heap)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
+#ifdef USE_CRYPTO_GNUTLS
|
|
|
|
+#ifdef HAVE_GNUTLS
|
|
|
|
+ unsigned oldmode = gnutls_fips140_mode_enabled();
|
|
|
|
+ unsigned oldmode = gnutls_fips140_mode_enabled();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ gnutls_fips140_set_mode(GNUTLS_FIPS140_LAX, GNUTLS_FIPS140_SET_MODE_THREAD);
|
|
|
|
+ gnutls_fips140_set_mode(GNUTLS_FIPS140_LAX, GNUTLS_FIPS140_SET_MODE_THREAD);
|
|
|
@ -191,12 +145,12 @@ index 2ff48df..ce6fb31 100644
|
|
|
|
std::string type;
|
|
|
|
std::string type;
|
|
|
|
if (stream_dict.getKey("/Type").isName())
|
|
|
|
if (stream_dict.getKey("/Type").isName())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -1361,6 +1394,10 @@ QPDF::decryptStream(PointerHolder<EncryptionParameters> encp,
|
|
|
|
@@ -1297,6 +1319,10 @@ QPDF::decryptStream(Pipeline*& pipeline, int objid, int generation,
|
|
|
|
toI(key.length()));
|
|
|
|
key.length());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
heap.push_back(pipeline);
|
|
|
|
heap.push_back(pipeline);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+#ifdef USE_CRYPTO_GNUTLS
|
|
|
|
+#ifdef HAVE_GNUTLS
|
|
|
|
+ gnutls_fips140_set_mode(static_cast<gnutls_fips_mode_t>(oldmode), GNUTLS_FIPS140_SET_MODE_THREAD);
|
|
|
|
+ gnutls_fips140_set_mode(static_cast<gnutls_fips_mode_t>(oldmode), GNUTLS_FIPS140_SET_MODE_THREAD);
|
|
|
|
+#endif
|
|
|
|
+#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|