Exemple #1
0
void WFileList::SaveProperties()
{
    Enctain::Container cnt = wmain->container;

    cnt.SetGlobalEncryptedProperty("FileListColumns",
                                   std::string((char*)&metasettings, sizeof(metasettings)));

    cnt.SetGlobalEncryptedProperty("FileListDisplayMode",
                                   strWX2STL(wxString::Format(_T("%d"), displaymode)));
}
Exemple #2
0
void WFileList::UpdateItem(unsigned int sfid)
{
    Enctain::Container cnt = wmain->container;

    const std::string& filetype = cnt.GetSubFileProperty(sfid, "Filetype");
    int filetypeimage = 0;
    if (filetype == "text") {
        filetypeimage = 1;
    }

    SetItemImage(sfid, filetypeimage);

    UpdateItemColumns(sfid);

    wmain->UpdateSubFileCaption(sfid);
}
Exemple #3
0
void WFileList::LoadProperties()
{
    Enctain::Container cnt = wmain->container;

    std::string strmetasettings = cnt.GetGlobalEncryptedProperty("FileListColumns");
    if (strmetasettings.size() == sizeof(metasettings))
    {
        memcpy(&metasettings, strmetasettings.data(), sizeof(metasettings));
    }

    wxString strdisplaymode = strSTL2WX(cnt.GetGlobalEncryptedProperty("FileListDisplayMode"));
    unsigned long newdisplaymode;
    if (strdisplaymode.ToULong(&newdisplaymode))
        UpdateDisplayMode(newdisplaymode);
    else
        UpdateDisplayMode(0);
}
Exemple #4
0
void WFileList::ResetItems()
{
    DeleteAllItems();

    Enctain::Container cnt = wmain->container;

    for (unsigned int fi = 0; fi < cnt.CountSubFile(); ++fi)
    {
        const std::string& filetype = cnt.GetSubFileProperty(fi, "Filetype");
        int filetypeimage = 0;
        if (filetype == "text") {
            filetypeimage = 1;
        }

        InsertItem(fi, filetypeimage);

        UpdateItemColumns(fi);
    }
}
Exemple #5
0
void test_enctain(const std::string& filedata, std::string filename)
{
    std::ostringstream memfile;
    filename.size();

    {
	Enctain::Container container;

	container.SetGlobalUnencryptedProperty("prop1", "test abc");

	container.SetGlobalEncryptedProperty("secret1", "blah");

	container.SetGlobalEncryptedProperty("prop2", std::string(255, 'a'));
	container.SetGlobalEncryptedProperty("prop3", std::string(256, 'b'));

	unsigned int sf1 = container.AppendSubFile();

	container.SetSubFileEncryption(sf1, Enctain::ENCRYPTION_NONE);
	container.SetSubFileCompression(sf1, Enctain::COMPRESSION_NONE);

	container.SetSubFileProperty(sf1, "Name", "test1.txt");
	container.SetSubFileProperty(sf1, "MIME-Type", "text/plain");
	container.SetSubFileData(sf1, filedata.data(), filedata.size());

	unsigned int sf2 = container.AppendSubFile();

	container.SetSubFileEncryption(sf2, Enctain::ENCRYPTION_NONE);
	container.SetSubFileCompression(sf2, Enctain::COMPRESSION_ZLIB);

	container.SetSubFileProperty(sf2, "Name", "test2.txt");
	container.SetSubFileProperty(sf2, "MIME-Type", "text/plain");
	container.SetSubFileData(sf2, filedata.data(), filedata.size());

	container.AddKeySlot("oYLiP4Td");

	unsigned int sf3 = container.AppendSubFile();

	container.SetSubFileEncryption(sf3, Enctain::ENCRYPTION_NONE);
	container.SetSubFileCompression(sf3, Enctain::COMPRESSION_BZIP2);

	container.SetSubFileProperty(sf3, "Name", "test3.txt");
	container.SetSubFileProperty(sf3, "MIME-Type", "text/plain");
	container.SetSubFileData(sf3, filedata.data(), filedata.size());

	unsigned int sf4 = container.AppendSubFile();

	container.SetSubFileEncryption(sf4, Enctain::ENCRYPTION_SERPENT256);
	container.SetSubFileCompression(sf4, Enctain::COMPRESSION_NONE);

	container.SetSubFileProperty(sf4, "Name", "test4.txt");
	container.SetSubFileProperty(sf4, "MIME-Type", "text/plain");
	container.SetSubFileData(sf4, filedata.data(), filedata.size());

	unsigned int sf5 = container.AppendSubFile();

	container.SetSubFileEncryption(sf5, Enctain::ENCRYPTION_SERPENT256);
	container.SetSubFileCompression(sf5, Enctain::COMPRESSION_ZLIB);

	container.SetSubFileProperty(sf5, "Name", "test5.txt");
	container.SetSubFileProperty(sf5, "MIME-Type", "text/plain");
	container.SetSubFileData(sf5, filedata.data(), filedata.size());

	container.AddKeySlot("ELO0Eia9");

	unsigned int sf6 = container.AppendSubFile();

	container.SetSubFileEncryption(sf6, Enctain::ENCRYPTION_SERPENT256);
	container.SetSubFileCompression(sf6, Enctain::COMPRESSION_BZIP2);

	container.SetSubFileProperty(sf6, "Name", "test6.txt");
	container.SetSubFileProperty(sf6, "MIME-Type", "text/plain");
	container.SetSubFileData(sf6, filedata.data(), filedata.size());

#if WRITEFILE == 0
	Enctain::DataOutputStream dataout(memfile);
#else
	std::ofstream outstream(filename.c_str());
	Enctain::DataOutputStream dataout(outstream);
#endif

	container.Save(dataout);
    }

    {
	Enctain::Container container;

#if WRITEFILE == 0
	std::istringstream instream(memfile.str());
#else
	std::ifstream instream(filename.c_str());
#endif

	Enctain::DataInputStream datain(instream);
	container.Load(datain, "ELO0Eia9");

	std::string key, val;
	assert( container.GetGlobalUnencryptedPropertyIndex(0, key, val) );
	assert( key == "prop1" && val == "test abc" );
	assert( !container.GetGlobalUnencryptedPropertyIndex(1, key, val) );

	assert( container.GetGlobalEncryptedPropertyIndex(0, key, val) );
	assert( key == "prop2" && val == std::string(255, 'a') );
	assert( container.GetGlobalEncryptedPropertyIndex(1, key, val) );
	assert( key == "prop3" && val == std::string(256, 'b') );
	assert( container.GetGlobalEncryptedPropertyIndex(2, key, val) );
	assert( key == "secret1" && val == "blah" );
	assert( !container.GetGlobalEncryptedPropertyIndex(3, key, val) );

	assert(container.CountSubFile() == 6);

	// subfile 0
	assert( container.GetSubFilePropertyIndex(0, 0, key, val) );
	assert( key == "MIME-Type" && val == "text/plain" );
	assert( container.GetSubFilePropertyIndex(0, 1, key, val) );
	assert( key == "Name" && val == "test1.txt" );
	assert( !container.GetSubFilePropertyIndex(0, 2, key, val) );

	std::string mb;
	container.GetSubFileData(0, mb);
	
	assert( mb == filedata );

	// subfile 1
	assert( container.GetSubFilePropertyIndex(1, 0, key, val) );
	assert( key == "MIME-Type" && val == "text/plain" );
	assert( container.GetSubFilePropertyIndex(1, 1, key, val) );
	assert( key == "Name" && val == "test2.txt" );
	assert( !container.GetSubFilePropertyIndex(1, 2, key, val) );

	container.GetSubFileData(1, mb);
	assert( mb == filedata );

	// subfile 2
	assert( container.GetSubFilePropertyIndex(2, 0, key, val) );
	assert( key == "MIME-Type" && val == "text/plain" );
	assert( container.GetSubFilePropertyIndex(2, 1, key, val) );
	assert( key == "Name" && val == "test3.txt" );
	assert( !container.GetSubFilePropertyIndex(2, 2, key, val) );

	container.GetSubFileData(2, mb);
	assert( mb == filedata );

	// subfile 3
	assert( container.GetSubFilePropertyIndex(3, 0, key, val) );
	assert( key == "MIME-Type" && val == "text/plain" );
	assert( container.GetSubFilePropertyIndex(3, 1, key, val) );
	assert( key == "Name" && val == "test4.txt" );
	assert( !container.GetSubFilePropertyIndex(3, 2, key, val) );

	container.GetSubFileData(3, mb);
	assert( mb == filedata );

	// subfile 4
	assert( container.GetSubFilePropertyIndex(4, 0, key, val) );
	assert( key == "MIME-Type" && val == "text/plain" );
	assert( container.GetSubFilePropertyIndex(4, 1, key, val) );
	assert( key == "Name" && val == "test5.txt" );
	assert( !container.GetSubFilePropertyIndex(4, 2, key, val) );

	container.GetSubFileData(4, mb);
	assert( mb == filedata );

	// subfile 5
	assert( container.GetSubFilePropertyIndex(5, 0, key, val) );
	assert( key == "MIME-Type" && val == "text/plain" );
	assert( container.GetSubFilePropertyIndex(5, 1, key, val) );
	assert( key == "Name" && val == "test6.txt" );
	assert( !container.GetSubFilePropertyIndex(5, 2, key, val) );

	container.GetSubFileData(5, mb);
	assert( mb == filedata );

	// subfile 5 (again)
	assert( container.GetSubFilePropertyIndex(5, 0, key, val) );
	assert( key == "MIME-Type" && val == "text/plain" );
	assert( container.GetSubFilePropertyIndex(5, 1, key, val) );
	assert( key == "Name" && val == "test6.txt" );
	assert( !container.GetSubFilePropertyIndex(5, 2, key, val) );

	container.GetSubFileData(5, mb);
	assert( mb == filedata );
    }
}
Exemple #6
0
void WFileList::UpdateItemColumns(unsigned int fi)
{
    Enctain::Container cnt = wmain->container;

    if (displaymode == 2)
    {
        static const wxString choiceCompression_choices[] = {
            _("None"), _("ZLib"), _("BZ2")
        };

        static const wxString choiceEncryption_choices[] = {
            _("None"), _("Serpent")
        };

        int col = 0;

        if (metasettings.show_filename >= 0) {
            SetItem(fi, col++, strSTL2WX(cnt.GetSubFileProperty(fi, "Name")));
        }

        if (metasettings.show_size >= 0) {
            SetItem(fi, col++, wxString::Format(_T("%u"), cnt.GetSubFileSize(fi)));
        }

        if (metasettings.show_compressed >= 0) {
            SetItem(fi, col++, wxString::Format(_T("%u"), cnt.GetSubFileStorageSize(fi)));
        }

        if (metasettings.show_compression >= 0) {
            unsigned int comp = cnt.GetSubFileCompression(fi);
            if (comp < sizeof(choiceCompression_choices))
                SetItem(fi, col++, choiceCompression_choices[comp]);
            else
                SetItem(fi, col++, _("<unknown>"));
        }

        if (metasettings.show_encryption >= 0) {
            unsigned int encr = cnt.GetSubFileEncryption(fi);
            if (encr < sizeof(choiceEncryption_choices))
                SetItem(fi, col++, choiceEncryption_choices[encr]);
            else
                SetItem(fi, col++, _("<unknown>"));
        }

        if (metasettings.show_mtime >= 0) {
            std::string timestr = cnt.GetSubFileProperty(fi, "MTime");
            if (timestr.size() == sizeof(time_t)) {
                wxDateTime ctime(*(time_t*)timestr.data());
                SetItem(fi, col++, ctime.Format(_("%c")));
            }
        }

        if (metasettings.show_ctime >= 0) {
            std::string timestr = cnt.GetSubFileProperty(fi, "CTime");
            if (timestr.size() == sizeof(time_t)) {
                wxDateTime ctime(*(time_t*)timestr.data());
                SetItem(fi, col++, ctime.Format(_("%c")));
            }
        }

        if (metasettings.show_author >= 0) {
            SetItem(fi, col++, strSTL2WX(cnt.GetSubFileProperty(fi, "Author")));
        }
        if (metasettings.show_subject >= 0) {
            SetItem(fi, col++, strSTL2WX(cnt.GetSubFileProperty(fi, "Subject")));
        }
    }
    else
    {
        SetItem(fi, 0, strSTL2WX(cnt.GetSubFileProperty(fi, "Name")));
    }
}
Exemple #7
0
WFileProperties::WFileProperties(WCryptoTE* parent, int _subfileid, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long WXUNUSED(style))
    : wxDialog(parent, id, title, pos, size, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxTHICK_FRAME),
      wmain(parent), subfileid(_subfileid)
{
    SetMinSize(wxSize(350, 0));

    // begin wxGlade: WFileProperties::WFileProperties
    textIdentifier = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
    textFilename = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
    textAuthor = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
    textSize = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
    textCompressed = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
    textCTime = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
    textMTime = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
    const wxString choiceType_choices[] = {
        _("Binary Data"),
        _("Text File"),
        _("Image File")
    };
    choiceType = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 3, choiceType_choices, 0);
    const wxString choiceCompression_choices[] = {
        _("None"),
        _("ZLib"),
        _("BZ2")
    };
    choiceCompression = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 3, choiceCompression_choices, 0);
    const wxString choiceEncryption_choices[] = {
        _("None (Don't Use)"),
        _("Serpent 256 keybits")
    };
    choiceEncryption = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 2, choiceEncryption_choices, 0);
    textSubject = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
    textDescription = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
    buttonOK = new wxButton(this, wxID_OK, wxEmptyString);
    buttonCancel = new wxButton(this, wxID_CANCEL, wxEmptyString);

    set_properties();
    do_layout();
    // end wxGlade

    Enctain::Container cnt = wmain->container;

    if (subfileid < 0) return;

    textIdentifier->SetValue(wxString::Format(_T("%u"), subfileid));
    SetTitle(wxString::Format(_("Properties of SubFile %u"), subfileid));

    textFilename->SetValue(strSTL2WX(cnt.GetSubFileProperty(subfileid, "Name")));
    textAuthor->SetValue(strSTL2WX(cnt.GetSubFileProperty(subfileid, "Author")));

    textSize->SetValue(wxString::Format(_T("%u"), cnt.GetSubFileSize(subfileid)));
    textCompressed->SetValue(wxString::Format(_T("%u"), cnt.GetSubFileStorageSize(subfileid)));

    std::string timestr = cnt.GetSubFileProperty(subfileid, "CTime");
    if (timestr.size() == sizeof(time_t)) {
        wxDateTime ctime(*(time_t*)timestr.data());
        textCTime->SetValue(ctime.Format(_("%c")));
    }

    timestr = cnt.GetSubFileProperty(subfileid, "MTime");
    if (timestr.size() == sizeof(time_t)) {
        wxDateTime mtime(*(time_t*)timestr.data());
        textMTime->SetValue(mtime.Format(_("%c")));
    }

    const std::string& filetype = cnt.GetSubFileProperty(subfileid, "Filetype");
    if (filetype == "text") {
        choiceType->SetSelection(1);
    }
    else {
        choiceType->SetSelection(0);
    }

    choiceCompression->SetSelection(cnt.GetSubFileCompression(subfileid));
    choiceEncryption->SetSelection(cnt.GetSubFileEncryption(subfileid));

    textSubject->SetValue(strSTL2WX(cnt.GetSubFileProperty(subfileid, "Subject")));
    textDescription->SetValue(strSTL2WX(cnt.GetSubFileProperty(subfileid, "Description")));

    textFilename->SetFocus();
}
Exemple #8
0
void WFileProperties::OnButtonOK(wxCommandEvent& WXUNUSED(event))
{
    Enctain::Container cnt = wmain->container;

    cnt.SetSubFileProperty(subfileid, "Name", strWX2STL(textFilename->GetValue()));
    cnt.SetSubFileProperty(subfileid, "Author", strWX2STL(textAuthor->GetValue()));

    int ifiletype = choiceType->GetSelection();
    if (ifiletype == 1) {
        cnt.SetSubFileProperty(subfileid, "Filetype", "text");
    }
    else {
        cnt.SetSubFileProperty(subfileid, "Filetype", "");
    }

    Enctain::compression_type newcomp = (Enctain::compression_type)choiceCompression->GetSelection();
    Enctain::encryption_type newencr = (Enctain::encryption_type)choiceEncryption->GetSelection();

    if (newcomp != cnt.GetSubFileCompression(subfileid) ||
        newencr != cnt.GetSubFileEncryption(subfileid))
    {
        size_t oldsize = cnt.GetSubFileStorageSize(subfileid);
        size_t realsize = cnt.GetSubFileSize(subfileid);

        cnt.SetSubFileCompressionEncryption(subfileid, newcomp, newencr);

        size_t newsize = cnt.GetSubFileStorageSize(subfileid);

        wmain->UpdateStatusBar(
            wxString::Format(_("Recompressed and reencrypted %u subfile bytes into %u bytes (old size %u)."),
                             realsize, newsize, oldsize)
            );
    }

    cnt.SetSubFileProperty(subfileid, "Subject", strWX2STL(textSubject->GetValue()));
    cnt.SetSubFileProperty(subfileid, "Description", strWX2STL(textDescription->GetValue()));

    EndModal(wxID_OK);
}