vendredi 1 mars 2019

AWS S3Client works BUT S3EncryptionClient FAILS - NoSuchKey: The Specified Key Does not Exist

This may be a bug with C++ AWS SDK. I am able to upload, list, and then download items from my bucket just fine. I can also upload with the encryption client, list, and download with the vanilla client just fine. Naturally files are encrypted at this point... BUT if I try to list and download with the encryption client, it says there's no such key!

    std::vector<std::string> files = GetList(); // uses s3 list object
    Aws::Client::ClientConfiguration config;
    config.region = '{region}'

    const size_t keyLen = keyFile->GetKeyLength();
    const auto key = std::string(keyFile->GetKey(), keyLen);

    char to_uchar[keyLen];
    std::copy(key.begin(), key.end(), to_uchar);
    to_uchar[keyLen] = 0;

    // AES256
    auto encryption = Aws::MakeShared<Aws::S3Encryption::Materials::SimpleEncryptionMaterials>(to_uchar, keyLen);

    #ifdef UNDER_MACOS
        CryptoConfiguration cryptoConfiguration(StorageMethod::METADATA, CryptoMode::ENCRYPTION_ONLY);
    #else
        CryptoConfiguration cryptoConfiguration(StorageMethod::METADATA, CryptoMode::STRICT_AUTHENTICATED_ENCRYPTION);
    #endif

    //Aws::S3::S3Client s3(config); // <--- this works!
    Aws::S3Encryption::S3EncryptionClient s3(encryption, cryptoConfiguration, config); // <-- this doesn't work!

    for(auto key : files) {
        Aws::S3::Model::GetObjectRequest req;
        req.WithBucket("{BUCKET}");
        req.WithKey(key.c_str());
        auto res = s3.GetObject(req);

        if(res.IsSuccess()) {
            Aws::OFStream local_file;
            std::string loc = "outputdir/"+key.first;
            local_file.open(loc.c_str(), std::ios::out | std::ios::binary);
            local_file << res.GetResult().GetBody().rdbuf();
        } else {
            std::cout << "S3 get `" + key.first + "` request failed with error (" << res.GetError().GetExceptionName() << "): \"" << res.GetError().GetMessage() << "\"" << std::endl;
        }
    }

Again, with regular S3 client it is fine. With S3EncryptionClient, this is my output for every file:

S3 get `fake_file_XYZ` request failed with error (NoSuchKey): "The specified key does not exist."

But my aws CLI shows that it does!

Aucun commentaire:

Enregistrer un commentaire