18 static const char*
b64str =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
43 struct passwd* userp = ::getpwuid(::getuid());
45 char* uName = userp->pw_name;
50 if (loginName.empty()) {
58 std::stringstream
str(line);
64 if (item.size() > 3) {
65 paramName = item.substr(0, 2);
66 paramValue = item.substr(2);
67 params.insert(std::make_pair(paramName, paramValue));
75 ::srand(m_iteration + 2);
80 for (
size_t i = 0;
i < keySize;
i++) {
88 ::srand(m_iteration + 2);
98 s <<
NAMEPREFIX <<
"<principal_name>" << std::endl;
99 s <<
OWNERPREFIX <<
"<owner_name, optional>" << std::endl;
100 s <<
KEYPREFIX <<
"<key, leave empty if generated>" << std::endl;
103 <<
"<user0_name>;" <<
PASSWORDPREFIX <<
"<password0>;" << std::endl;
105 <<
"<user1_name>;" <<
PASSWORDPREFIX <<
"<password1>;" << std::endl;
107 <<
"<user2_name>;" <<
PASSWORDPREFIX <<
"<password2>;" << std::endl;
112 if (keyFileName.empty()) {
116 m_fileName = keyFileName;
119 m_principalName.clear();
120 m_principalKey.clear();
125 std::ifstream
keyFile(m_fileName.c_str(),
std::ios::in | std::ios::binary | std::ios::ate);
127 size_t fsize =
keyFile.tellg();
128 unsigned char* buff = (
unsigned char*)malloc(fsize);
129 keyFile.seekg(0, std::ios::beg);
130 keyFile.read(reinterpret_cast<char*>(buff), fsize);
139 std::stringstream
str(content.substr(
KEY_HEADER.size() + 1));
143 if (line.size() > 3) {
145 m_principalName = line.substr(2);
146 }
else if (line.substr(0, 2) ==
KEYPREFIX) {
147 m_principalKey = line.substr(2);
149 m_owner = line.substr(2);
151 std::stringstream serviceStr(line.substr(2));
152 std::vector<std::string> sdata;
153 while (serviceStr.good()) {
157 std::map<std::string, ServiceCredentials>::iterator iS =
159 iS->second.connectionString = sdata[1];
160 iS->second.userName = sdata[2];
161 iS->second.password = sdata[3];
167 if (m_principalName.empty() || m_principalKey.empty()) {
171 if (!m_owner.empty()) {
173 if (m_owner != currentUser) {
174 m_principalName.clear();
175 m_principalKey.clear();
178 std::string msg =
"Provided key is invalid for user=" + currentUser;
183 std::string msg =
"Required Key File \"" + m_fileName +
"\" is missing or unreadable.";
192 if (inputFileName.empty()) {
196 m_principalName.clear();
197 m_principalKey.clear();
200 std::ifstream
inputFile(inputFileName.c_str());
202 std::map<std::string, std::string>
params;
207 if (line.size() > 3) {
209 m_principalName = line.substr(2);
210 }
else if (line.substr(0, 2) ==
KEYPREFIX) {
211 m_principalKey = line.substr(2);
213 m_owner = line.substr(2);
221 m_services.insert(std::make_pair(serviceName, creds));
227 if (m_principalKey.empty() && generatedKeySize) {
229 m_principalKey = gen.
make(generatedKeySize);
233 std::string msg =
"Provided Input File \"" + inputFileName +
"\n is invalid.";
240 out <<
NAMEPREFIX << m_principalName << std::endl;
241 out <<
KEYPREFIX << m_principalKey << std::endl;
243 for (std::map<std::string, ServiceCredentials>::const_iterator iS = m_services.begin(); iS != m_services.end();
247 out <<
USERPREFIX << iS->second.userName <<
";";
253 std::ofstream
outFile(m_fileName.c_str(), std::ios::binary);
257 if (!m_principalName.empty()) {
260 if (!m_principalKey.empty()) {
263 if (!m_owner.empty()) {
266 for (std::map<std::string, ServiceCredentials>::const_iterator iD = m_services.begin(); iD != m_services.end();
276 size_t outSize = cipher.
encrypt(content.str(),
out);
277 outFile.write(reinterpret_cast<char*>(out), outSize);
281 msg +=
"Provided Key File \"" + m_fileName +
"\n is invalid.";
295 std::map<std::string, ServiceCredentials>::iterator iK = m_services.find(serviceName);
296 if (iK == m_services.end()) {
static const std::string KEYPREFIX("K=")
size_t init(const std::string &keyFileName, const std::string &password, bool readMode=true)
ret
prodAgent to be discontinued
void addService(const std::string &serviceName, const std::string &connectionString, const std::string &userName, const std::string &password)
void parseLineForNamedParams(const std::string &line, std::map< std::string, std::string > ¶ms)
S make(const edm::ParameterSet &cfg)
std::string getLoginName()
static const std::string USERPREFIX("U=")
static const std::string serviceName
void throwException(const std::string &message, const std::string &methodName)
static const std::string SERVICEPREFIX("S=")
std::string connectionString
static const std::string DATEPREFIX("D=")
size_t createFromInputFile(const std::string &inputFileName, size_t generatedKeySize=0)
static const char * b64str
static const std::string KEY_HEADER("Cond_Authentication_Key")
static const std::string DEFAULT_SERVICE("Cond_Default_Service")
static std::string templateFile()
size_t encrypt(const std::string &input, unsigned char *&output)
def gen(fragment, howMuch)
Production test section ####.
void addDefaultService(const std::string &connectionString)
static const std::string PASSWORDPREFIX("P=")
static const std::string OWNERPREFIX("O=")
std::string makeWithRandomSize(size_t maxSize)
std::string make(size_t keySize)
static const std::string CONNECTIONPREFIX("C=")
std::string decrypt(const unsigned char *input, size_t inputSize)
static const std::string NAMEPREFIX("N=")
static const std::string keyFile("/nfshome0/hcalsw/.ReadOMDSKey")
void list(std::ostream &out)