void IMAPMessagePartContentHandler::extract
	(utility::outputStream& os, utility::progressListener* progress) const
{
	shared_ptr <IMAPMessage> msg = constCast <IMAPMessage>(m_message.lock());
	shared_ptr <messagePart> part = constCast <messagePart>(m_part.lock());

	// No decoding to perform
	if (!isEncoded())
	{
		msg->extractImpl(part, os, progress, 0, -1, IMAPMessage::EXTRACT_BODY);
	}
	// Need to decode data
	else
	{
		// Extract part contents to temporary buffer
		std::ostringstream oss;
		utility::outputStreamAdapter tmp(oss);

		msg->extractImpl(part, tmp, NULL, 0, -1, IMAPMessage::EXTRACT_BODY);

		// Encode temporary buffer to output stream
		utility::inputStreamStringAdapter is(oss.str());
		utility::progressListenerSizeAdapter plsa(progress, getLength());

		shared_ptr <utility::encoder::encoder> theDecoder = m_encoding.getEncoder();
		theDecoder->decode(is, os, &plsa);
	}
}
void IMAPMessagePartContentHandler::extract
(utility::outputStream& os, utility::progressListener* progress) const
{
    ref <IMAPMessage> msg = m_message.acquire().constCast <IMAPMessage>();
    ref <part> part = m_part.acquire().constCast <class part>();

    // No decoding to perform
    if (!isEncoded())
    {
        msg->extractPart(part, os, progress);
    }
    // Need to decode data
    else
    {
        // Extract part contents to temporary buffer
        std::ostringstream oss;
        utility::outputStreamAdapter tmp(oss);

        msg->extractPart(part, tmp, NULL);

        // Encode temporary buffer to output stream
        utility::inputStreamStringAdapter is(oss.str());
        utility::progressListenerSizeAdapter plsa(progress, getLength());

        ref <utility::encoder::encoder> theDecoder = m_encoding.getEncoder();
        theDecoder->decode(is, os, &plsa);
    }
}
void streamContentHandler::extract(utility::outputStream& os,
	utility::progressListener* progress) const
{
	if (!m_stream)
		return;

	// No decoding to perform
	if (!isEncoded())
	{
		m_stream->reset();  // may not work...

		if (progress)
			utility::bufferedStreamCopy(*m_stream, os, getLength(), progress);
		else
			utility::bufferedStreamCopy(*m_stream, os);
	}
	// Need to decode data
	else
	{
		ref <encoder> theDecoder = m_encoding.getEncoder();

		m_stream->reset();  // may not work...

		utility::progressListenerSizeAdapter plsa(progress, getLength());

		theDecoder->decode(*m_stream, os, &plsa);
	}
}
void streamContentHandler::generate(utility::outputStream& os, const vmime::encoding& enc,
	const string::size_type maxLineLength) const
{
	if (!m_stream)
		return;

	// Managed data is already encoded
	if (isEncoded())
	{
		// The data is already encoded but the encoding specified for
		// the generation is different from the current one. We need
		// to re-encode data: decode from input buffer to temporary
		// buffer, and then re-encode to output stream...
		if (m_encoding != enc)
		{
			ref <utility::encoder::encoder> theDecoder = m_encoding.getEncoder();
			ref <utility::encoder::encoder> theEncoder = enc.getEncoder();

			theEncoder->getProperties()["maxlinelength"] = maxLineLength;
			theEncoder->getProperties()["text"] = (m_contentType.getType() == mediaTypes::TEXT);

			m_stream->reset();  // may not work...

			std::ostringstream oss;
			utility::outputStreamAdapter tempOut(oss);

			theDecoder->decode(*m_stream, tempOut);

			string str = oss.str();
			utility::inputStreamStringAdapter tempIn(str);

			theEncoder->encode(tempIn, os);
		}
		// No encoding to perform
		else
		{
			m_stream->reset();  // may not work...

			utility::bufferedStreamCopy(*m_stream, os);
		}
	}
	// Need to encode data before
	else
	{
		ref <utility::encoder::encoder> theEncoder = enc.getEncoder();
		theEncoder->getProperties()["maxlinelength"] = maxLineLength;
		theEncoder->getProperties()["text"] = (m_contentType.getType() == mediaTypes::TEXT);

		m_stream->reset();  // may not work...

		theEncoder->encode(*m_stream, os);
	}
}
예제 #5
0
void CryptStream::_writeHeader () {
	assert (_mode == WRITE);
	assert (_file_bio); // Operate on _file_bio
	
	char buf[header_buf_size+1];
	// Write this header directly to the file, without encoding or encryption
	const int offset = header_buf_size;
	std::string hexIV = uc2hex((const unsigned char*)_iv.c_str(), _iv.length());
	int r = snprintf (buf, header_buf_size-1, "*167110* # v:%i # c:%.1i # e:%.1i # o:%i # ciph:%.30s # iv:%.256s # count:%i #",
						this->_version, isEncrypted(), isEncoded(), offset, EVP_CIPHER_name(_cipher),
						hexIV.c_str(), _pbkdfIterationCount);
	memset(buf+r, '*', header_buf_size-r-1);
	buf[header_buf_size-1] = '\n';
	BIO_write(_file_bio, buf, header_buf_size);
}
예제 #6
0
void stringContentHandler::generate(utility::outputStream& os,
	const vmime::encoding& enc, const size_t maxLineLength) const
{
	// Managed data is already encoded
	if (isEncoded())
	{
		// The data is already encoded but the encoding specified for
		// the generation is different from the current one. We need
		// to re-encode data: decode from input buffer to temporary
		// buffer, and then re-encode to output stream...
		if (m_encoding != enc)
		{
			shared_ptr <utility::encoder::encoder> theDecoder = m_encoding.getEncoder();
			shared_ptr <utility::encoder::encoder> theEncoder = enc.getEncoder();

			theEncoder->getProperties()["maxlinelength"] = maxLineLength;
			theEncoder->getProperties()["text"] = (m_contentType.getType() == mediaTypes::TEXT);

			utility::inputStreamStringProxyAdapter in(m_string);

			std::ostringstream oss;
			utility::outputStreamAdapter tempOut(oss);

			theDecoder->decode(in, tempOut);

			string str = oss.str();
			utility::inputStreamStringAdapter tempIn(str);

			theEncoder->encode(tempIn, os);
		}
		// No encoding to perform
		else
		{
			m_string.extract(os);
		}
	}
	// Need to encode data before
	else
	{
		shared_ptr <utility::encoder::encoder> theEncoder = enc.getEncoder();
		theEncoder->getProperties()["maxlinelength"] = maxLineLength;
		theEncoder->getProperties()["text"] = (m_contentType.getType() == mediaTypes::TEXT);

		utility::inputStreamStringProxyAdapter in(m_string);

		theEncoder->encode(in, os);
	}
}
예제 #7
0
void stringContentHandler::extract(utility::outputStream& os,
	utility::progressListener* progress) const
{
	// No decoding to perform
	if (!isEncoded())
	{
		m_string.extract(os, 0, m_string.length(), progress);
	}
	// Need to decode data
	else
	{
		ref <utility::encoder::encoder> theDecoder = m_encoding.getEncoder();

		utility::inputStreamStringProxyAdapter in(m_string);
		utility::progressListenerSizeAdapter plsa(progress, getLength());

		theDecoder->decode(in, os, &plsa);
	}
}
void IMAPMessagePartContentHandler::generate
	(utility::outputStream& os, const vmime::encoding& enc, size_t maxLineLength) const
{
	shared_ptr <IMAPMessage> msg = constCast <IMAPMessage>(m_message.lock());
	shared_ptr <messagePart> part = constCast <messagePart>(m_part.lock());

	// Data is already encoded
	if (isEncoded())
	{
		// The data is already encoded but the encoding specified for
		// the generation is different from the current one. We need
		// to re-encode data: decode from input buffer to temporary
		// buffer, and then re-encode to output stream...
		if (m_encoding != enc)
		{
			// Extract part contents to temporary buffer
			std::ostringstream oss;
			utility::outputStreamAdapter tmp(oss);

			msg->extractPart(part, tmp, NULL);

			// Decode to another temporary buffer
			utility::inputStreamStringProxyAdapter in(oss.str());

			std::ostringstream oss2;
			utility::outputStreamAdapter tmp2(oss2);

			shared_ptr <utility::encoder::encoder> theDecoder = m_encoding.getEncoder();
			theDecoder->decode(in, tmp2);

			// Reencode to output stream
			string str = oss2.str();
			utility::inputStreamStringAdapter tempIn(str);

			shared_ptr <utility::encoder::encoder> theEncoder = enc.getEncoder();
			theEncoder->getProperties()["maxlinelength"] = maxLineLength;
			theEncoder->getProperties()["text"] = (m_contentType.getType() == mediaTypes::TEXT);

			theEncoder->encode(tempIn, os);
		}
		// No encoding to perform
		else
		{
			msg->extractPart(part, os);
		}
	}
	// Need to encode data before
	else
	{
		// Extract part contents to temporary buffer
		std::ostringstream oss;
		utility::outputStreamAdapter tmp(oss);

		msg->extractPart(part, tmp, NULL);

		// Encode temporary buffer to output stream
		shared_ptr <utility::encoder::encoder> theEncoder = enc.getEncoder();
		theEncoder->getProperties()["maxlinelength"] = maxLineLength;
		theEncoder->getProperties()["text"] = (m_contentType.getType() == mediaTypes::TEXT);

		utility::inputStreamStringAdapter is(oss.str());

		theEncoder->encode(is, os);
	}
}
예제 #9
0
/* urls can't contain null pointer, caller must ensure this */
static enum phish_status phishingCheck(const struct cl_engine* engine,struct url_check* urls)
{
	struct url_check host_url;
	enum phish_status rc=CL_PHISH_NODECISION;
	int phishy=0;
	const struct phishcheck* pchk = (const struct phishcheck*) engine->phishcheck;

	if(!urls->realLink.data)
		return CL_PHISH_CLEAN;

	cli_dbgmsg("Phishcheck:Checking url %s->%s\n", urls->realLink.data,
		urls->displayLink.data);

	if(!strcmp(urls->realLink.data,urls->displayLink.data))
		return CL_PHISH_CLEAN;/* displayed and real URL are identical -> clean */

	if((rc = cleanupURLs(urls))) {
		if(isPhishing(rc))/* not allowed to decide this is phishing */
			return CL_PHISH_CLEAN;
		return rc;/* URLs identical after cleanup */
	}

	if(whitelist_check(engine,urls,0))
		return CL_PHISH_WHITELISTED;/* if url is whitelist don't perform further checks */

	if((!isURL(pchk, urls->displayLink.data) || !isRealURL(pchk, urls->realLink.data) )&&
			( (phishy&PHISHY_NUMERIC_IP && !isNumericURL(pchk, urls->displayLink.data)) ||
			  !(phishy&PHISHY_NUMERIC_IP))) {
		cli_dbgmsg("Displayed 'url' is not url:%s\n",urls->displayLink.data);
		return CL_PHISH_TEXTURL;
	}

	if(urls->flags&DOMAINLIST_REQUIRED && domainlist_match(engine,urls->realLink.data,urls->displayLink.data,NULL,0,&urls->flags))
		phishy |= DOMAIN_LISTED;
	else {
		/* although entire url is not listed, the host might be,
		 * so defer phishing decisions till we know if host is listed*/
	}

	
	url_check_init(&host_url);

	if((rc = url_get_host(pchk, urls,&host_url,DOMAIN_DISPLAY,&phishy))) {
		free_if_needed(&host_url);
		if(isPhishing(rc))
			return CL_PHISH_CLEAN;
		return rc;
	}


	if(urls->flags&DOMAINLIST_REQUIRED) {
		if(!(phishy&DOMAIN_LISTED)) {
			if(domainlist_match(engine,host_url.displayLink.data,host_url.realLink.data,&urls->pre_fixup,1,&urls->flags))
				phishy |= DOMAIN_LISTED;
			else {
			}
		}
	}

	/* link type filtering must occur after last domainlist_match */
	if(urls->link_type & LINKTYPE_IMAGE && !(urls->flags&CHECK_IMG_URL))
		return CL_PHISH_HOST_NOT_LISTED;/* its listed, but this link type is filtered */

	if(urls->flags & DOMAINLIST_REQUIRED && !(phishy & DOMAIN_LISTED) ) {
		urls->flags &= urls->always_check_flags;
		if(!urls->flags) {
				free_if_needed(&host_url);
				return CL_PHISH_HOST_NOT_LISTED;
			}
		}

	if(urls->flags&CHECK_CLOAKING) {
		/*Checks if URL is cloaked.
		Should we check if it contains another http://, https://?
		No because we might get false positives from redirect services.*/
		if(strchr(urls->realLink.data,0x1)) {
			free_if_needed(&host_url);
			return CL_PHISH_CLOAKED_NULL;
		}
		if(isEncoded(urls->displayLink.data)) {
			free_if_needed(&host_url);
			return CL_PHISH_HEX_URL;
		}
	}


	if(urls->displayLink.data[0]=='\0') {
		free_if_needed(&host_url);
		return CL_PHISH_CLEAN;
	}

	if(urls->flags&CHECK_SSL && isSSL(urls->displayLink.data) && !isSSL(urls->realLink.data)) {
		free_if_needed(&host_url);
		return CL_PHISH_SSL_SPOOF;
	}

	if(!urls->flags&CHECK_CLOAKING && urls->flags & DOMAINLIST_REQUIRED && !(phishy&DOMAIN_LISTED) ) {
		free_if_needed(&host_url);
		return CL_PHISH_HOST_NOT_LISTED;
	}

	if((rc = url_get_host(pchk, urls,&host_url,DOMAIN_REAL,&phishy)))
	{
		free_if_needed(&host_url);
		return rc;
	}

	if(urls->flags&DOMAINLIST_REQUIRED && !(phishy&DOMAIN_LISTED)) {
		free_if_needed(&host_url);
		return CL_PHISH_HOST_NOT_LISTED;
	}

	if(whitelist_check(engine,&host_url,1)) {
		free_if_needed(&host_url);
		return CL_PHISH_HOST_WHITELISTED;
	}


	if(urls->flags&HOST_SUFFICIENT) {
		if(!strcmp(urls->realLink.data,urls->displayLink.data)) {
			free_if_needed(&host_url);
			return CL_PHISH_HOST_OK;
		}


		if(urls->flags&DOMAIN_SUFFICIENT) {
			struct url_check domain_url;
			url_check_init(&domain_url);
			url_get_domain(pchk, &host_url,&domain_url);
			if(!strcmp(domain_url.realLink.data,domain_url.displayLink.data)) {
				free_if_needed(&host_url);
				free_if_needed(&domain_url);
				return CL_PHISH_DOMAIN_OK;
			}
			free_if_needed(&domain_url);
		}

		free_if_needed(&host_url);
	}/*HOST_SUFFICIENT*/
	/*we failed to find a reason why the 2 URLs are different, this is definitely phishing*/
	if(urls->flags&DOMAINLIST_REQUIRED && !(phishy&DOMAIN_LISTED))
		return CL_PHISH_HOST_NOT_LISTED;
	return phishy_map(phishy,CL_PHISH_NOMATCH);
}