18 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
43 struct passwd* userp = ::getpwuid(::getuid());
45 char* uName = userp->pw_name;
50 if(loginName.empty()){
58 std::stringstream str( line );
65 paramName = item.substr(0,2);
66 paramValue = item.substr(2);
67 params.insert( std::make_pair( paramName, paramValue ) );
80 for(
size_t i=0;
i<keySize;
i++ ){
88 ::srand( m_iteration+2 );
99 s<<
OWNERPREFIX<<
"<owner_name, optional>"<<std::endl;
100 s<<
KEYPREFIX<<
"<key, leave empty if generated>"<<std::endl;
109 if(keyFileName.empty()){
113 m_fileName = keyFileName;
116 m_principalName.clear();
117 m_principalKey.clear();
124 size_t fsize =
keyFile.tellg();
125 unsigned char* buff = (
unsigned char*)malloc( fsize );
126 keyFile.seekg (0, std::ios::beg);
127 keyFile.read (reinterpret_cast<char*>(buff), fsize);
136 std::stringstream str( content.substr(
KEY_HEADER.size()+1) );
142 m_principalName = line.substr(2);
143 }
else if ( line.substr(0,2)==
KEYPREFIX ){
144 m_principalKey = line.substr(2);
146 m_owner = line.substr(2);
148 std::stringstream serviceStr( line.substr(2) );
149 std::vector<std::string> sdata;
150 while( serviceStr.good() ){
154 std::map< std::string, ServiceCredentials >::iterator iS = m_services.insert( std::make_pair( sdata[0],
ServiceCredentials() ) ).first;
155 iS->second.connectionString = sdata[1];
156 iS->second.userName = sdata[2];
157 iS->second.password = sdata[3];
163 if( m_principalName.empty() || m_principalKey.empty() ){
167 if( !m_owner.empty() ){
169 if(m_owner != currentUser ){
170 m_principalName.clear();
171 m_principalKey.clear();
174 std::string msg =
"Provided key is invalid for user=" + currentUser;
179 std::string msg =
"Required Key File \""+m_fileName+
"\" is missing or unreadable.";
188 if(inputFileName.empty()){
192 m_principalName.clear();
193 m_principalKey.clear();
196 std::ifstream
inputFile (inputFileName.c_str());
198 std::map<std::string,std::string> params;
205 m_principalName = line.substr(2);
206 }
else if ( line.substr(0,2)==
KEYPREFIX ){
207 m_principalKey = line.substr(2);
209 m_owner = line.substr(2);
217 m_services.insert( std::make_pair( serviceName, creds ) );
223 if( m_principalKey.empty() && generatedKeySize){
225 m_principalKey = gen.
make( generatedKeySize );
229 std::string msg =
"Provided Input File \""+inputFileName+
"\n is invalid.";
237 out <<
KEYPREFIX<<m_principalKey<<std::endl;
239 for( std::map< std::string, ServiceCredentials >::const_iterator iS = m_services.begin();
240 iS != m_services.end(); iS++ ){
249 std::ofstream
outFile ( m_fileName.c_str(),std::ios::binary);
253 if( !m_principalName.empty() ){
256 if( !m_principalKey.empty() ){
259 if( !m_owner.empty() ){
262 for( std::map< std::string, ServiceCredentials >::const_iterator iD = m_services.begin();
263 iD != m_services.end(); ++iD ){
272 size_t outSize = cipher.
encrypt( content.str(),
out );
273 outFile.write( reinterpret_cast<char*>(out),outSize);
277 msg +=
"Provided Key File \""+m_fileName+
"\n is invalid.";
291 std::map< std::string, ServiceCredentials >::iterator iK = m_services.find( serviceName );
292 if( iK == m_services.end() ){
296 iK->second.userName = userName;
297 iK->second.password = password;
tuple ret
prodAgent to be discontinued
static const std::string KEYPREFIX("K=")
size_t init(const std::string &keyFileName, const std::string &password, bool readMode=true)
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()
tuple maxSize
'/store/data/Commissioning08/BeamHalo/RECO/StuffAlmostToP5_v1/000/061/642/10A0FE34-A67D-DD11-AD05-000...
size_t encrypt(const std::string &input, unsigned char *&output)
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)