microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22.75k stars 6.29k forks source link

[LibArchive] Builded library on Windows can't produce AES256/128 encrypted zip file #21001

Closed alwendya closed 2 years ago

alwendya commented 2 years ago

I used VCPKG to build libarchive 3.5.2#1 with triplet x64-windows-static and the following addon :

When I use LibArchive (following LibArchive code sample) to create zip file , tar file, 7z file, it work fine. I intended to use encryption to zip file and it works for the ZipCrypt encryption (function archive_write_set_options(a, "encryption=zipcrypt")). But when I use the other parameter for AES128 or 256 (archive_write_set_options(a, "encryption=aes128")) I get an error code encryption not supported. Backtracking source file I managed to find in the file archive_cryptor_private.h the code #elif defined(HAVE_LIBCRYPTO) supposing openssl is needed for AES encryption to work. I linked libssl.lib end libcrytpo.lib build by vcpkg, compilation is fine but I still got the error during code execution.

Anyone got this problem ?

Here is the whole library linked in VS2019 :

Here is the code used :

        struct archive* a;
        struct archive_entry* entry;
        a = archive_write_new();
        archive_write_set_format_zip(a);
        archive_write_add_filter_none(a);
        archive_write_set_options(a, "compression-level=6");
        int ResOUT = archive_write_set_options(a, "encryption=aes128"); 
        // ResOUT return ARCHIVE_FAILED, using "encryption=zipcrypt" return ARCHIVE_OK;
        if (ResOUT != ARCHIVE_OK) {
            std::cout << "Error setting encryption to aes128, cancelling...\n"
            << archive_error_string(a) << "\n";
            return false; }
        ResOUT = archive_write_set_passphrase(a, "passwordpassword");
        ResOUT = archive_write_open_filename(a, CheminComplet.c_str());
        struct _stati64 st64;
        int st_result = _stati64("d:\\dummyfile.dum", &st64);
        entry = archive_entry_new(); // Note 2
        archive_entry_set_pathname(entry, "\\Infile.dum");
        archive_entry_set_size(entry, st64.st_size); // Note 3
        archive_entry_set_filetype(entry, AE_IFREG);
        archive_entry_set_perm(entry, 0644);
        archive_write_header(a, entry);
        FILE* FSource = NULL;
        errno_t err = fopen_s(&FSource,"d:\\dummyfile.dum", "rb");
        std::vector<UINT8> vecBUFFER;
        vecBUFFER.resize(4*1024*1024);//4mb reading
        fread_s(&vecBUFFER[0], vecBUFFER.size(), sizeof(UINT8), vecBUFFER.size(), FSource);
        archive_write_data(a, &vecBUFFER[0], vecBUFFER.size());
        fclose(FSource);
        archive_entry_free(entry);
        archive_write_close(a);
        archive_write_free(a);
PhoebeHui commented 2 years ago

@alwendya, I reported an issue to Upstream to confirm this issue, see https://github.com/libarchive/libarchive/issues/1607.

alwendya commented 2 years ago

@PhoebeHui , thanks for your implication and for searching the root of this issue. Hope the LibArchive Teams will answer quickly to solve it. Thanks again to you and the Vcpkg team!

alwendya commented 2 years ago

By the way, do you think there is a possibility to provide a temporary patch file ? ( I tried to create one by myself but I'm not a pro in GIT patch file and sadly, it's not working...)

JackBoosY commented 2 years ago

By the way, do you think there is a possibility to provide a temporary patch file ? ( I tried to create one by myself but I'm not a pro in GIT patch file and sadly, it's not working...)

Yeah we can do that, but need the upstream approval first.

ra-dave commented 2 years ago

Is there any movement on this?

JackBoosY commented 2 years ago

Close this PR until upstream fixes this.