summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-07-17 16:52:45 +0100
committerCarl Hetherington <cth@carlh.net>2014-07-17 16:52:45 +0100
commit9026320cc48e9c200d33aae9e8f601f29542e186 (patch)
treeab1f49dd88bf2b1006ca42fd7f753f46aca03fa6 /src
parent3d77daab7639c06d1cdbeb852559fc4be5671819 (diff)
Get Signer to take a PEM string rather than a filename.
Diffstat (limited to 'src')
-rw-r--r--src/signer.cc5
-rw-r--r--src/signer.h8
-rw-r--r--src/util.cc20
-rw-r--r--src/util.h1
4 files changed, 29 insertions, 5 deletions
diff --git a/src/signer.cc b/src/signer.cc
index 8f0114a2..a0d9912a 100644
--- a/src/signer.cc
+++ b/src/signer.cc
@@ -114,7 +114,10 @@ Signer::add_signature_value (xmlpp::Node* parent, string ns) const
throw MiscError ("could not create signature context");
}
- signature_context->signKey = xmlSecCryptoAppKeyLoad (_key.string().c_str(), xmlSecKeyDataFormatPem, 0, 0, 0);
+ signature_context->signKey = xmlSecCryptoAppKeyLoadMemory (
+ reinterpret_cast<const unsigned char *> (_key.c_str()), _key.size(), xmlSecKeyDataFormatPem, 0, 0, 0
+ );
+
if (signature_context->signKey == 0) {
throw FileError ("could not load private key file", _key, 0);
}
diff --git a/src/signer.h b/src/signer.h
index 6e258f8d..92745ff2 100644
--- a/src/signer.h
+++ b/src/signer.h
@@ -42,9 +42,9 @@ class Signer : public boost::noncopyable
{
public:
/** @param c Certificate chain to sign with.
- * @param k Key to sign with.
+ * @param k Key to sign with as a PEM-format string.
*/
- Signer (CertificateChain c, boost::filesystem::path k)
+ Signer (CertificateChain c, std::string k)
: _certificates (c)
, _key (k)
{}
@@ -60,8 +60,8 @@ private:
/** Certificate chain to sign with */
CertificateChain _certificates;
- /** Filename of signer key */
- boost::filesystem::path _key;
+ /** Key to sign with as a PEM-format string */
+ std::string _key;
};
}
diff --git a/src/util.cc b/src/util.cc
index 3d37454f..9758db9c 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -368,3 +368,23 @@ dcp::ids_equal (string a, string b)
trim (b);
return a == b;
}
+
+string
+dcp::file_to_string (boost::filesystem::path p)
+{
+ uintmax_t len = boost::filesystem::file_size (p);
+ char* c = new char[len];
+
+ FILE* f = fopen_boost (p, "r");
+ if (!f) {
+ return "";
+ }
+
+ fread (c, 1, len, f);
+ fclose (f);
+
+ string s (c);
+ delete[] c;
+
+ return s;
+}
diff --git a/src/util.h b/src/util.h
index d3f212c7..33fd79a3 100644
--- a/src/util.h
+++ b/src/util.h
@@ -88,6 +88,7 @@ extern void add_signer (xmlpp::Element* parent, CertificateChain const & certifi
extern int base64_decode (std::string const & in, unsigned char* out, int out_length);
extern boost::optional<boost::filesystem::path> relative_to_root (boost::filesystem::path root, boost::filesystem::path file);
extern FILE * fopen_boost (boost::filesystem::path, std::string);
+extern std::string file_to_string (boost::filesystem::path);
template <class F, class T>
std::list<boost::shared_ptr<T> >