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 );
102 s<<
OWNERPREFIX<<
"<owner_name, optional>"<<std::endl;
103 s<<
KEYPREFIX<<
"<key, leave empty if generated>"<<std::endl;
112 if(keyFileName.empty()){
116 m_fileName = keyFileName;
119 m_principalName.clear();
120 m_principalKey.clear();
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) );
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 = m_services.insert( std::make_pair( sdata[0],
ServiceCredentials() ) ).first;
158 iS->second.connectionString = sdata[1];
159 iS->second.userName = sdata[2];
160 iS->second.password = sdata[3];
166 if( m_principalName.empty() || m_principalKey.empty() ){
170 if( !m_owner.empty() ){
172 if(m_owner != currentUser ){
173 m_principalName.clear();
174 m_principalKey.clear();
177 std::string msg =
"Provided key is invalid for user=" + currentUser;
182 std::string msg =
"Required Key File \""+m_fileName+
"\" is missing or unreadable.";
191 if(inputFileName.empty()){
195 m_principalName.clear();
196 m_principalKey.clear();
199 std::ifstream
inputFile (inputFileName.c_str());
201 std::map<std::string,std::string> params;
208 m_principalName = line.substr(2);
209 }
else if ( line.substr(0,2)==
KEYPREFIX ){
210 m_principalKey = line.substr(2);
212 m_owner = line.substr(2);
220 m_services.insert( std::make_pair( serviceName, creds ) );
226 if( m_principalKey.empty() && generatedKeySize){
228 m_principalKey = gen.
make( generatedKeySize );
232 std::string msg =
"Provided Input File \""+inputFileName+
"\n is invalid.";
240 out <<
KEYPREFIX<<m_principalKey<<std::endl;
242 for( std::map< std::string, ServiceCredentials >::const_iterator iS = m_services.begin();
243 iS != m_services.end(); iS++ ){
252 std::ofstream
outFile ( m_fileName.c_str(),std::ios::binary);
256 if( !m_principalName.empty() ){
259 if( !m_principalKey.empty() ){
262 if( !m_owner.empty() ){
265 for( std::map< std::string, ServiceCredentials >::const_iterator iD = m_services.begin();
266 iD != m_services.end(); ++iD ){
275 size_t outSize = cipher.
encrypt( content.str(),
out );
276 outFile.write( reinterpret_cast<char*>(out),outSize);
280 msg +=
"Provided Key File \""+m_fileName+
"\n is invalid.";
294 std::map< std::string, ServiceCredentials >::iterator iK = m_services.find( serviceName );
295 if( iK == m_services.end() ){
298 iK->second.connectionString = connectionString;
299 iK->second.userName = userName;
300 iK->second.password = password;
static const std::string FILE_PATH
void addService(const std::string &serviceName, const std::string &connectionString, const std::string &userName, const std::string &password)
static const std::string KEYPREFIX("K=")
std::string makeWithRandomSize(size_t maxSize)
static std::string templateFile()
std::string connectionString
void addDefaultService(const std::string &connectionString)
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=")
std::string decrypt(const unsigned char *input, size_t inputSize)
static const std::string serviceName
static const std::string SERVICEPREFIX("S=")
static const std::string DATEPREFIX("D=")
static const char * b64str
static const std::string KEY_HEADER("Cond_Authentication_Key")
constexpr char LineSeparator
static const std::string DEFAULT_SERVICE("Cond_Default_Service")
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)
size_t createFromInputFile(const std::string &inputFileName, size_t generatedKeySize=0)
void list(std::ostream &out)
constexpr char ItemSeparator
static const std::string PASSWORDPREFIX("P=")
size_t init(const std::string &keyFileName, const std::string &password, bool readMode=true)
void throwException(std::string const &message, std::string const &methodName)
static const std::string OWNERPREFIX("O=")
std::string make(size_t keySize)
static const std::string CONNECTIONPREFIX("C=")
static const std::string NAMEPREFIX("N=")
static const std::string keyFile("/nfshome0/hcalsw/.ReadOMDSKey")
static const std::string FILE_NAME