+ FileReader reader(filename);
+ std::string ret = reader.GetString();
+ if (ret.empty())
+ throw Exception("Cannot read file " + filename);
+ return ret;
+ }
+
+ public:
+ static reference<Profile> Create(const std::string& profilename, ConfigTag* tag)
+ {
+ std::string certstr = ReadFile(tag->getString("certfile", "cert.pem"));
+ std::string keystr = ReadFile(tag->getString("keyfile", "key.pem"));
+
+ std::auto_ptr<DHParams> dh;
+ int gendh = tag->getInt("gendh");
+ if (gendh)
+ {
+ gendh = (gendh < 1024 ? 1024 : gendh);
+ dh = DHParams::Generate(gendh);
+ }
+ else
+ dh = DHParams::Import(ReadFile(tag->getString("dhfile", "dhparams.pem")));
+
+ // Use default priority string if this tag does not specify one
+ std::string priostr = tag->getString("priority", "NORMAL");
+ unsigned int mindh = tag->getInt("mindhbits", 1024);
+ std::string hashstr = tag->getString("hash", "md5");
+
+ // Load trusted CA and revocation list, if set
+ std::auto_ptr<X509CertList> ca;
+ std::auto_ptr<X509CRL> crl;
+ std::string filename = tag->getString("cafile");
+ if (!filename.empty())
+ {
+ ca.reset(new X509CertList(ReadFile(filename)));
+
+ filename = tag->getString("crlfile");
+ if (!filename.empty())
+ crl.reset(new X509CRL(ReadFile(filename)));
+ }
+
+ return new Profile(profilename, certstr, keystr, dh, mindh, hashstr, priostr, ca, crl);
+ }