Esempio n. 1
0
void Base64TestCase::EncodeDecode0to255()
{
    unsigned char buff[256];
    generatePatternedData(buff, 256, 0, 1);
    wxString str = wxBase64Encode(buff, 256);
    wxMemoryBuffer mbuff = wxBase64Decode(str);
    CPPUNIT_ASSERT(memcmp(mbuff.GetData(), buff, mbuff.GetDataLen()) == 0);

    mbuff = wxBase64Decode(encoded0to255);
    CPPUNIT_ASSERT(memcmp(mbuff.GetData(), buff, mbuff.GetDataLen()) == 0);
}
Esempio n. 2
0
void Base64TestCase::EncodeDecodeRandom()
{
    size_t size = rand() * 3000 / RAND_MAX + 11;
    unsigned char *buff = new unsigned char[size];
    generateRandomData(buff, size);
    wxString str = wxBase64Encode(buff, size);
    wxMemoryBuffer mbuff = wxBase64Decode(str);
    CPPUNIT_ASSERT(memcmp(mbuff.GetData(), buff, mbuff.GetDataLen()) == 0);

    generateGibberish(buff, size);
    char *buff2 = new char[size];
    size_t realsize = size;
    CPPUNIT_ASSERT(wxBase64Decode(buff2, realsize, (char *)buff, size));
    CPPUNIT_ASSERT(wxBase64Encode(buff2, size, buff2, realsize));
}
Esempio n. 3
0
void Base64TestCase::EncodeDecodeA()
{
    const wxString str = wxBase64Encode("A", 1);
    CPPUNIT_ASSERT_EQUAL(wxString("QQ=="), str);

    wxMemoryBuffer buf = wxBase64Decode(str);
    CPPUNIT_ASSERT_EQUAL(1, buf.GetDataLen());
    CPPUNIT_ASSERT_EQUAL('A', *(char *)buf.GetData());

    char cbuf[10];
    memset(cbuf, (char)-1, sizeof(cbuf));
    CPPUNIT_ASSERT_EQUAL( 1, wxBase64Decode(cbuf, 1, str) );
    CPPUNIT_ASSERT_EQUAL( 'A', cbuf[0] );
    CPPUNIT_ASSERT_EQUAL( (char)-1, cbuf[1] );
    CPPUNIT_ASSERT_EQUAL( (char)-1, cbuf[2] );
}
Esempio n. 4
0
void Base64TestCase::EncodeDecodePatternC()
{
    unsigned char buff[11];
    generatePatternedData(buff, 11, 1, 0, 2);
    wxString str = wxBase64Encode(buff, 11);
    wxMemoryBuffer mbuff = wxBase64Decode(str);
    CPPUNIT_ASSERT(memcmp(mbuff.GetData(), buff, mbuff.GetDataLen()) == 0);
}
Esempio n. 5
0
bool wxDatabaseConfig::DoReadBinary(const wxString& key, wxMemoryBuffer* buf) const
{
	wxCHECK_MSG(buf, false, wxT("NULL buffer"));

	wxString str;
	if (!Read(key, &str)) return false;
	*buf = wxBase64Decode(str);
	return true;
}
Esempio n. 6
0
void Base64TestCase::EncodeDecodeAB()
{
    const wxString str = wxBase64Encode("AB", 2);
    CPPUNIT_ASSERT_EQUAL(wxString("QUI="), str);

    wxMemoryBuffer buf = wxBase64Decode(str);
    CPPUNIT_ASSERT_EQUAL(2, buf.GetDataLen());
    CPPUNIT_ASSERT_EQUAL('A', buf[0]);
    CPPUNIT_ASSERT_EQUAL('B', buf[1]);

    char cbuf[10];
    memset(cbuf, (char)-1, sizeof(cbuf));
    CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, wxBase64Decode(cbuf, 1, str) );
    CPPUNIT_ASSERT_EQUAL( 2, wxBase64Decode(cbuf, 2, str) );
    CPPUNIT_ASSERT_EQUAL( 'A', cbuf[0] );
    CPPUNIT_ASSERT_EQUAL( 'B', cbuf[1] );
    CPPUNIT_ASSERT_EQUAL( (char)-1, cbuf[2] );
    CPPUNIT_ASSERT_EQUAL( (char)-1, cbuf[3] );
}
Esempio n. 7
0
void Base64TestCase::EncodeDecodeEmpty()
{
    char shouldBeEmpty[10];
    shouldBeEmpty[0] = '\0';
    size_t len = 10;

    CPPUNIT_ASSERT(wxBase64Encode(shouldBeEmpty, len, "", 0) != wxCONV_FAILED);
    CPPUNIT_ASSERT_EQUAL('\0', shouldBeEmpty[0]);

    CPPUNIT_ASSERT(wxBase64Decode(shouldBeEmpty, len, "") != wxCONV_FAILED);
    CPPUNIT_ASSERT_EQUAL('\0', shouldBeEmpty[0]);

    wxMemoryBuffer bufmt;
    wxString resultEmpty = wxBase64Encode(bufmt);
    CPPUNIT_ASSERT(resultEmpty.empty());

    bufmt = wxBase64Decode(resultEmpty);
    CPPUNIT_ASSERT_EQUAL(0, bufmt.GetDataLen());
}
Esempio n. 8
0
void CUpdater::ProcessNotification(std::unique_ptr<CNotification> && notification)
{
	if (state_ != UpdaterState::checking && state_ != UpdaterState::newversion_downloading) {
		return;
	}

	switch (notification->GetID())
	{
	case nId_asyncrequest:
		{
			auto pData = unique_static_cast<CAsyncRequestNotification>(std::move(notification));
			if (pData->GetRequestID() == reqId_fileexists) {
				static_cast<CFileExistsNotification *>(pData.get())->overwriteAction = CFileExistsNotification::resume;
			}
			else if (pData->GetRequestID() == reqId_certificate) {
				auto & certNotification = static_cast<CCertificateNotification &>(*pData.get());
				if (m_use_internal_rootcert) {
					auto certs = certNotification.GetCertificates();
					if( certs.size() > 1 ) {
						auto ca = certs.back();

						unsigned int ca_data_length{};
						unsigned char const* ca_data = ca.GetRawData(ca_data_length);

						wxMemoryBuffer updater_root = wxBase64Decode(s_update_cert, wxNO_LEN, wxBase64DecodeMode_SkipWS);
						if( ca_data_length == updater_root.GetDataLen() && !memcmp(ca_data, updater_root.GetData(), ca_data_length) ) {
							certNotification.m_trusted = true;
						}
					}
				}
				else {
					certNotification.m_trusted = true;
				}
			}
			engine_->SetAsyncRequestReply(std::move(pData));
		}
		break;
	case nId_data:
		ProcessData(static_cast<CDataNotification&>(*notification.get()));
		break;
	case nId_operation:
		ProcessOperation(static_cast<COperationNotification const&>(*notification.get()));
		break;
	case nId_logmsg:
		{
			auto const& msg = static_cast<CLogmsgNotification const&>(*notification.get());
			log_ += msg.msg + _T("\n");
		}
		break;
	default:
		break;
	}
}
Esempio n. 9
0
void Base64TestCase::DecodeInvalid()
{
    size_t rc, posErr;
    rc = wxBase64Decode(NULL, 0, "one two!", wxNO_LEN,
                        wxBase64DecodeMode_Strict, &posErr);
    CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, rc);
    CPPUNIT_ASSERT_EQUAL( 3, posErr );

    rc = wxBase64Decode(NULL, 0, "one two!", wxNO_LEN,
                        wxBase64DecodeMode_SkipWS, &posErr);
    CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, rc);
    CPPUNIT_ASSERT_EQUAL( 7, posErr );

    rc = wxBase64Decode(NULL, 0, "? QQ==", wxNO_LEN,
                        wxBase64DecodeMode_SkipWS, &posErr);
    CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, rc);
    CPPUNIT_ASSERT_EQUAL( 0, posErr );

    const size_t POS_INVALID = (size_t)-1;
    posErr = POS_INVALID;
    rc = wxBase64Decode(NULL, 0, " QQ==", wxNO_LEN,
                        wxBase64DecodeMode_SkipWS, &posErr);
    CPPUNIT_ASSERT_EQUAL( 1, rc );
    CPPUNIT_ASSERT_EQUAL( POS_INVALID, posErr );

    rc = wxBase64Decode(NULL, 0, "? QQ==", wxNO_LEN,
                        wxBase64DecodeMode_Relaxed, &posErr);
    CPPUNIT_ASSERT_EQUAL( 1, rc );
    CPPUNIT_ASSERT_EQUAL( POS_INVALID, posErr );

    CPPUNIT_ASSERT( !wxBase64Decode("wxGetApp()").GetDataLen() );
}
Esempio n. 10
0
void Base64TestCase::EncodeDecodeABCD()
{
    const wxString str = wxBase64Encode("ABCD", 4);
    CPPUNIT_ASSERT_EQUAL(wxString("QUJDRA=="), str);

    wxMemoryBuffer buf = wxBase64Decode(str);
    CPPUNIT_ASSERT_EQUAL(4, buf.GetDataLen());
    CPPUNIT_ASSERT_EQUAL('A', buf[0]);
    CPPUNIT_ASSERT_EQUAL('B', buf[1]);
    CPPUNIT_ASSERT_EQUAL('C', buf[2]);
    CPPUNIT_ASSERT_EQUAL('D', buf[3]);

    char cbuf[10];
    memset(cbuf, (char)-1, sizeof(cbuf));
    CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, wxBase64Decode(cbuf, 3, str) );
    CPPUNIT_ASSERT_EQUAL( 4, wxBase64Decode(cbuf, 4, str) );
    CPPUNIT_ASSERT_EQUAL( 'A', cbuf[0] );
    CPPUNIT_ASSERT_EQUAL( 'B', cbuf[1] );
    CPPUNIT_ASSERT_EQUAL( 'C', cbuf[2] );
    CPPUNIT_ASSERT_EQUAL( 'D', cbuf[3] );
    CPPUNIT_ASSERT_EQUAL( (char)-1, cbuf[4] );
    CPPUNIT_ASSERT_EQUAL( (char)-1, cbuf[5] );
}
wxString ProjectUpdater::GetCommandLine(const wxString & cmd)
{
	if(m_cmd==wxEmptyString)
	{
		wxString service = wxFileConfig::Get()->Read( wxT("sys.network.smb.service") );
		wxString smbclient = wxFileConfig::Get()->Read( wxT("sys.utils.smbclient.program") );

		if(service != wxEmptyString)
		{
			wxString username = wxFileConfig::Get()->Read( wxT("sys.network.smb.username") );
			wxString password_enc = wxFileConfig::Get()->Read( wxT("sys.network.smb.password") );
			wxString domain  = wxFileConfig::Get()->Read( wxT("sys.network.smb.domain") );

			wxMemoryBuffer mb( wxBase64Decode(password_enc) ) ;
			wxString password((const char *)mb.GetData(), mb.GetDataLen());

			m_cmd = wxString::Format(wxT("%s \"%s\" ") , smbclient, service);

			if(password != wxEmptyString)
			{
				m_cmd += wxString::Format(wxT(" \"%s\"") , password) ;
			}
			else
			{
				// if no password configed, avoid prompt in shell
				m_cmd += wxT(" -N")  ;
			}

			if(username != wxEmptyString)
			{
				m_cmd += wxString::Format(wxT(" -U \"%s\"") , username) ;
			}

			if(domain != wxEmptyString)
			{
				m_cmd += wxString::Format(wxT(" -W \"%s\"") , domain) ;
				m_cmd += wxString::Format(wxT(" -n \"%s\"") , domain) ;
			}


		}
	}
	
	return wxString::Format("%s -c \"%s\"",
					m_cmd,
					cmd ) ;

}
Esempio n. 12
0
bool CUserList::addUser( const wxString& strUser, bool bUnpackNote )
{
    wxString strToken;
    wxString user;
    wxString password;
    wxString fullname;
    wxString strNote;
    vscpEventFilter filter;
    wxString userRights;
    wxString allowedRemotes;
    wxString allowedEvents;
    
    wxStringTokenizer tkz( strUser, _(";") );
    
    // user
    if ( tkz.HasMoreTokens() ) {
        user = tkz.GetNextToken();
    }
    
    // password
    if ( tkz.HasMoreTokens() ) {
        password = tkz.GetNextToken();
    }
    
    // fullname
    if ( tkz.HasMoreTokens() ) {
        fullname = tkz.GetNextToken();
    }
    
    // filter
    if ( tkz.HasMoreTokens() ) {
        vscp_readFilterFromString( &filter, tkz.GetNextToken() );
    }
    
    // mask
    if ( tkz.HasMoreTokens() ) {
        vscp_readMaskFromString( &filter, tkz.GetNextToken() );
    }
    
    // user rights
    if ( tkz.HasMoreTokens() ) {
        userRights = tkz.GetNextToken();
    }
    
    // allowed remotes
    if ( tkz.HasMoreTokens() ) {
        allowedRemotes = tkz.GetNextToken();
    }
    
    // allowed events
    if ( tkz.HasMoreTokens() ) {
        allowedEvents = tkz.GetNextToken();
    }
    
    // note
    if ( tkz.HasMoreTokens() ) {
        if ( bUnpackNote ) {
            
            wxString wxstr = tkz.GetNextToken();
 
            size_t len = wxBase64Decode( NULL, 0, wxstr );
            if ( 0 == len ) return false;
            uint8_t *pbuf = new uint8_t[len];
            if ( NULL == pbuf ) return false;
            len = wxBase64Decode( pbuf, len, wxstr );
            strNote = wxString::FromUTF8( (const char *)pbuf, len );
            delete [] pbuf;
        }
        else {
            strNote = tkz.GetNextToken();
        }
    }
            
    return addUser( user,
                        password, 
                        fullname,
                        strNote,
                        &filter,
                        userRights,
                        allowedRemotes,
                        allowedEvents );
}
Esempio n. 13
0
bool CUserItem::setFromString( wxString userSettings )
{
    wxString strToken;
    wxStringTokenizer tkz( userSettings, _(";") ); 
    
    // name
    if ( tkz.HasMoreTokens() ) {
        strToken = tkz.GetNextToken();
        strToken.Trim();
        strToken.Trim(false);
        if ( strToken.Length() ) {
            setUser( strToken );
            fixName();
        }
    }
    
    // password
    if ( tkz.HasMoreTokens() ) {
        strToken = tkz.GetNextToken();
        strToken.Trim();
        strToken.Trim(false);
        if ( strToken.Length() ) {
            setPassword( strToken );
        }
    }
    
    // fullname
    if ( tkz.HasMoreTokens() ) {
        strToken = tkz.GetNextToken();
        strToken.Trim();
        strToken.Trim(false);
        if ( strToken.Length() ) {
            setFullname( strToken );
        }
    }
    
    // filter
    if ( tkz.HasMoreTokens() ) {
        strToken = tkz.GetNextToken();
        strToken.Trim();
        strToken.Trim(false);
        if ( strToken.Length() ) {
            setFilterFromString( strToken );
        }
    }
    
    // mask
    if ( tkz.HasMoreTokens() ) {
        strToken = tkz.GetNextToken();
        setFilterFromString( strToken );
    }
    
    // rights
    if ( tkz.HasMoreTokens() ) {
        strToken = tkz.GetNextToken();
        strToken.Trim();
        strToken.Trim(false);
        if ( strToken.Length() ) {
            setUserRightsFromString( strToken );
        }
    }
        
    // remotes
    if ( tkz.HasMoreTokens() ) {
        strToken = tkz.GetNextToken();
        setAllowedRemotesFromString( strToken );
    }
    
    // events
    if ( tkz.HasMoreTokens() ) {
        strToken = tkz.GetNextToken();
        strToken.Trim();
        strToken.Trim(false);
        if ( strToken.Length() ) {
            setAllowedEventsFromString( strToken );
        }
    }    
    
    // note
    if ( tkz.HasMoreTokens() ) {
        strToken = tkz.GetNextToken();        
        strToken.Trim();
        strToken.Trim(false);
        if ( strToken.Length() ) {
            size_t len = wxBase64Decode( NULL, 0, strToken );
            if ( 0 == len ) return false;
            uint8_t *pbuf = new uint8_t[len];
            if ( NULL == pbuf ) return false;
            len = wxBase64Decode( pbuf, len, strToken );
            strToken = wxString::FromUTF8( (const char *)pbuf, len );
            delete [] pbuf;        
        
            setNote( strToken );
        }
    }
    
    return true;
}
Esempio n. 14
0
bool GetServer(pugi::xml_node node, CServer& server)
{
	wxASSERT(node);

	wxString host = GetTextElement(node, "Host");
	if (host.empty())
		return false;

	int port = GetTextElementInt(node, "Port");
	if (port < 1 || port > 65535)
		return false;

	if (!server.SetHost(host, port))
		return false;

	int const protocol = GetTextElementInt(node, "Protocol");
	if (protocol < 0 || protocol > ServerProtocol::MAX_VALUE) {
		return false;
	}
	server.SetProtocol(static_cast<ServerProtocol>(protocol));

	int type = GetTextElementInt(node, "Type");
	if (type < 0 || type >= SERVERTYPE_MAX)
		return false;

	server.SetType((enum ServerType)type);

	int logonType = GetTextElementInt(node, "Logontype");
	if (logonType < 0)
		return false;

	server.SetLogonType((enum LogonType)logonType);

	if (server.GetLogonType() != ANONYMOUS) {
		wxString user = GetTextElement(node, "User");

		wxString pass, key;
		if ((long)NORMAL == logonType || (long)ACCOUNT == logonType) {
			auto  passElement = node.child("Pass");
			if (passElement) {
				pass = GetTextElement(passElement);

				wxString encoding = GetTextAttribute(passElement, "encoding");

				if (encoding == _T("base64")) {
					wxMemoryBuffer buf = wxBase64Decode(pass);
					if (!buf.IsEmpty()) {
						pass = wxString::FromUTF8(static_cast<const char*>(buf.GetData()), buf.GetDataLen());
					}
					else {
						pass.clear();
					}
				}
				else if (!encoding.empty()) {
					pass.clear();
					server.SetLogonType(ASK);
				}
			}
		} else if ((long)KEY == logonType) {
			key = GetTextElement(node, "Keyfile");

			// password should be empty if we're using a key file
			pass = wxString();

			server.SetKeyFile(key);
		}

		if (!server.SetUser(user, pass))
			return false;

		if ((long)ACCOUNT == logonType) {
			wxString account = GetTextElement(node, "Account");
			if (account.empty())
				return false;
			if (!server.SetAccount(account))
				return false;
		}
	}

	int timezoneOffset = GetTextElementInt(node, "TimezoneOffset");
	if (!server.SetTimezoneOffset(timezoneOffset))
		return false;

	wxString pasvMode = GetTextElement(node, "PasvMode");
	if (pasvMode == _T("MODE_PASSIVE"))
		server.SetPasvMode(MODE_PASSIVE);
	else if (pasvMode == _T("MODE_ACTIVE"))
		server.SetPasvMode(MODE_ACTIVE);
	else
		server.SetPasvMode(MODE_DEFAULT);

	int maximumMultipleConnections = GetTextElementInt(node, "MaximumMultipleConnections");
	server.MaximumMultipleConnections(maximumMultipleConnections);

	wxString encodingType = GetTextElement(node, "EncodingType");
	if (encodingType == _T("Auto"))
		server.SetEncodingType(ENCODING_AUTO);
	else if (encodingType == _T("UTF-8"))
		server.SetEncodingType(ENCODING_UTF8);
	else if (encodingType == _T("Custom")) {
		wxString customEncoding = GetTextElement(node, "CustomEncoding");
		if (customEncoding.empty())
			return false;
		if (!server.SetEncodingType(ENCODING_CUSTOM, customEncoding))
			return false;
	}
	else
		server.SetEncodingType(ENCODING_AUTO);

	if (CServer::SupportsPostLoginCommands(server.GetProtocol())) {
		std::vector<wxString> postLoginCommands;
		auto element = node.child("PostLoginCommands");
		if (element) {
			for (auto commandElement = element.child("Command"); commandElement; commandElement = commandElement.next_sibling("Command")) {
				wxString command = ConvLocal(commandElement.child_value());
				if (!command.empty()) {
					postLoginCommands.push_back(command);
				}
			}
		}
		if (!server.SetPostLoginCommands(postLoginCommands))
			return false;
	}

	server.SetBypassProxy(GetTextElementInt(node, "BypassProxy", false) == 1);
	server.SetName(GetTextElement_Trimmed(node, "Name"));

	if (server.GetName().empty())
		server.SetName(GetTextElement_Trimmed(node));

	return true;
}