Wiadomość napisana w dniu 2008-04-24, o godz 17:45, przez Jason Castonguay: >>> OK, the problem is, that wpkg client scrambles it's password in >>> settings.xml file. I'd like to have random passowrd for each >>> server I manage. There is no problem to generate settings.xml >>> file (and thus ease installation on wpkg client on workstation), >>> but do you know what algorithm is used to scrable password? I'd >>> like to recreate it my script. >> Currently, there is no tool for creating the password (other than >> wpkginst.exe). >> But it would be a good idea to create one (command line), both for >> Windows and UNIX. > > Its ugly, but quick. > > > > $ g++ xmlsettings.cc > > $ ./a.out asdf > MYTmDw== > :0? > > $ ./a.out MYTmDw== > Ha7WBK5a4BA= > asdf > > > -- > Jason Castonguay > Greenpeace USA > System Administrator > 702 H Street, NW > Suite 300 > Washington, DC > 20001 > // Copyright (C) 2001-2002 Open Source Telecom Corporation. > // > // This program is free software; you can redistribute it and/or > modify > // it under the terms of the GNU General Public License as published > by > // the Free Software Foundation; either version 2 of the License, or > // (at your option) any later version. > // > // This program is distributed in the hope that it will be useful, > // but WITHOUT ANY WARRANTY; without even the implied warranty of > // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > // GNU General Public License for more details. > // > // You should have received a copy of the GNU General Public License > // along with this program; if not, write to the Free Software > // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA > 02111-1307, USA. > > > #include <iostream> > #include <string> > > > using namespace std; > > class CXmlSettings > { > public: > static std::string Crypt(std::string str); > static std::string Decrypt(std::string str); > > CXmlSettings(void); > virtual ~CXmlSettings(void); > > private: > > static size_t b64Encode(const unsigned char *src, size_t srcsize, > char *dst, size_t dstsize); > > > static size_t b64Decode(const char *src, > unsigned char *dst, size_t dstsize); > > > }; > > > static const unsigned char alphabet[65] = > "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; > > size_t CXmlSettings::b64Encode(const unsigned char *src, size_t > srcsize, > char *dst, size_t dstsize) > { > if (!dstsize) return 0; > > char* pdst = dst; > unsigned bits; > > while(srcsize >= 3 && dstsize > 4) > { > bits = (((unsigned)src[0])<<16) | (((unsigned)src[1])<<8) > | ((unsigned)src[2]); > src += 3; > srcsize -= 3; > *(pdst++) = alphabet[bits >> 18]; > *(pdst++) = alphabet[(bits >> 12) & 0x3f]; > *(pdst++) = alphabet[(bits >> 6) & 0x3f]; > *(pdst++) = alphabet[bits & 0x3f]; > dstsize -= 4; > } > if (srcsize && dstsize > 4) > { > bits = ((unsigned)src[0])<<16; > *(pdst++) = alphabet[bits >> 18]; > if (srcsize == 1) > { > *(pdst++) = alphabet[(bits >> 12) & 0x3f]; > *(pdst++) = '='; > } > else > { > bits |= ((unsigned)src[1])<<8; > *(pdst++) = alphabet[(bits >> 12) & 0x3f]; > *(pdst++) = alphabet[(bits >> 6) & 0x3f]; > } > *(pdst++) = '='; > } > *pdst = 0; > return pdst-dst; > } > > size_t CXmlSettings::b64Decode(const char *src, unsigned char *dst, > size_t dstsize) > { > char decoder[256]; > int i, bits, c; > > unsigned char *pdst = dst; > > for (i = 0; i < 256; ++i) > decoder[i] = 64; > for (i = 0; i < 64 ; ++i) > decoder[alphabet[i]] = i; > > bits = 1; > > while(*src) > { > c = (unsigned char)(*(src++)); > if (c == '=') > { > if (bits & 0x40000) > { > if (dstsize < 2) break; > *(pdst++) = (bits >> 10); > *(pdst++) = (bits >> 2) & 0xff; > break; > } > if (bits & 0x1000 && dstsize) > *(pdst++) = (bits >> 4); > break; > } > // skip invalid chars > if (decoder[c] == 64) > continue; > bits = (bits << 6) + decoder[c]; > if (bits & 0x1000000) > { > if (dstsize < 3) break; > *(pdst++) = (bits >> 16); > *(pdst++) = (bits >> 8) & 0xff; > *(pdst++) = (bits & 0xff); > bits = 1; > dstsize -= 3; > } > } > return pdst-dst; > } > > > > > #define BUFFER_LENGTH 1024 > #define KEY_LENGTH 40 > > static unsigned char key[] = { > 0x50, > 0xF7, > 0x82, > 0x69, > 0xEA, > 0x2D, > 0xDD, > 0x2D, > 0x6A, > 0xB4, > 0x33, > 0x8F, > 0xD5, > 0xC7, > 0x90, > 0x9C, > 0x22, > 0x95, > 0x61, > 0xE5, > 0x65, > 0xF6, > 0xB0, > 0x4B, > 0x94, > 0x47, > 0xB0, > 0xBD, > 0x73, > 0x58, > 0x56, > 0x87, > 0x79, > 0x7B, > 0xE6, > 0xB0, > 0xD2, > 0x20, > 0x28, > 0xE1 > }; > > std::string CXmlSettings::Crypt(std::string str) > { > char* buffer = (char *) malloc(BUFFER_LENGTH); > char destination[BUFFER_LENGTH]; > size_t destinationLength = BUFFER_LENGTH; > int length = str.length(); > strcpy(buffer,str.c_str()); > > > int idx = 0; > > for (int i = 0; i < length; i++) > { > buffer[i] ^= key[idx]; > idx++; > if (idx > KEY_LENGTH - 1) > idx = 0; > } > > CXmlSettings::b64Encode((const unsigned char > *)buffer,length,destination,destinationLength); > > if(destinationLength<BUFFER_LENGTH) > destination[destinationLength] = 0; > > //std::string strResult(destination); > std::string strResult = destination; > return strResult; > } > > std::string CXmlSettings::Decrypt(std::string str) > { > char* buffer = (char *) malloc(BUFFER_LENGTH); > char destination[BUFFER_LENGTH] = {0}; > size_t destinationLength; > size_t length = str.length(); > > strcpy(buffer,str.c_str()); > destinationLength = CXmlSettings::b64Decode((const char *)buffer, > (unsigned char *) destination,length); > > int idx = 0; > > for (int i = 0; i < destinationLength; i++) > { > destination[i] ^= key[idx]; > idx++; > if (idx > KEY_LENGTH - 1) > idx = 0; > } > > if(destinationLength<BUFFER_LENGTH) > destination[destinationLength] = 0; > > std::string strResult = destination; > return strResult; > } > > > > > CXmlSettings::CXmlSettings(void) > { > > } > > CXmlSettings::~CXmlSettings(void) > { > } > > > int main(int argc, char *argv[]) > { > cout<<CXmlSettings::Crypt(argv[1])<<endl > <<CXmlSettings::Decrypt(argv[1])<<endl; > > return 0; > } Thank you - that's great code :) I'm really no programmer - but could we add this code to next relase of wpkg-client? Best regards --- Grzegorz Marszałek graf0 at post.pl |