19 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
44 struct passwd* userp = ::getpwuid(::getuid());
46 char* uName = userp->pw_name;
51 if(loginName.empty()){
59 std::stringstream
str( line );
66 paramName = item.substr(0,2);
67 paramValue = item.substr(2);
68 params.insert( std::make_pair( paramName, paramValue ) );
76 ::srand( m_iteration+2 );
81 for(
size_t i=0;
i<keySize;
i++ ){
89 ::srand( m_iteration+2 );
100 s<<
OWNERPREFIX<<
"<owner_name, optional>"<<std::endl;
101 s<<
KEYPREFIX<<
"<key, leave empty if generated>"<<std::endl;
110 if(keyFileName.empty()){
114 m_fileName = keyFileName;
117 m_principalName.clear();
118 m_principalKey.clear();
125 size_t fsize =
keyFile.tellg();
126 unsigned char* buff = (
unsigned char*)malloc( fsize );
127 keyFile.seekg (0, std::ios::beg);
128 keyFile.read (reinterpret_cast<char*>(buff), fsize);
137 std::stringstream
str( content.substr(
KEY_HEADER.size()+1) );
143 m_principalName = line.substr(2);
144 }
else if ( line.substr(0,2)==
KEYPREFIX ){
145 m_principalKey = line.substr(2);
147 m_owner = line.substr(2);
149 std::stringstream serviceStr( line.substr(2) );
150 std::vector<std::string> sdata;
151 while( serviceStr.good() ){
155 std::map< std::string, ServiceCredentials >::iterator iS = m_services.insert( std::make_pair( sdata[0],
ServiceCredentials() ) ).first;
156 iS->second.connectionString = sdata[1];
157 iS->second.userName = sdata[2];
158 iS->second.password = sdata[3];
164 if( m_principalName.empty() || m_principalKey.empty() ){
168 if( !m_owner.empty() ){
170 if(m_owner != currentUser ){
171 m_principalName.clear();
172 m_principalKey.clear();
175 std::string msg =
"Provided key is invalid for user=" + currentUser;
180 std::string msg =
"Required Key File \""+m_fileName+
"\" is missing or unreadable.";
189 if(inputFileName.empty()){
193 m_principalName.clear();
194 m_principalKey.clear();
197 std::ifstream
inputFile (inputFileName.c_str());
199 std::map<std::string,std::string> params;
206 m_principalName = line.substr(2);
207 }
else if ( line.substr(0,2)==
KEYPREFIX ){
208 m_principalKey = line.substr(2);
210 m_owner = line.substr(2);
218 m_services.insert( std::make_pair( serviceName, creds ) );
224 if( m_principalKey.empty() && generatedKeySize){
226 m_principalKey = gen.
make( generatedKeySize );
230 std::string msg =
"Provided Input File \""+inputFileName+
"\n is invalid.";
238 out <<
KEYPREFIX<<m_principalKey<<std::endl;
240 for( std::map< std::string, ServiceCredentials >::const_iterator iS = m_services.begin();
241 iS != m_services.end(); iS++ ){
250 std::ofstream
outFile ( m_fileName.c_str(),std::ios::binary);
254 if( !m_principalName.empty() ){
257 if( !m_principalKey.empty() ){
260 if( !m_owner.empty() ){
263 for( std::map< std::string, ServiceCredentials >::const_iterator iD = m_services.begin();
264 iD != m_services.end(); ++iD ){
273 size_t outSize = cipher.
encrypt( content.str(),
out );
274 outFile.write( reinterpret_cast<char*>(out),outSize);
278 msg +=
"Provided Key File \""+m_fileName+
"\n is invalid.";
292 std::map< std::string, ServiceCredentials >::iterator iK = m_services.find( serviceName );
293 if( iK == m_services.end() ){
296 iK->second.connectionString = connectionString;
297 iK->second.userName = userName;
298 iK->second.password = password;
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()
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)