7 Commits

Author SHA1 Message Date
77879e6521 Fix rate limiting issue in example.cpp by adding delays between API calls 2025-08-28 21:49:34 +02:00
3b4d591eff Fix type conversion warnings in base58.cpp and improve CMake syntax 2025-08-28 21:43:46 +02:00
4add1edd11 Update CMakeLists.txt for cross-platform compatibility and improve build scripts
- Add cross-platform support for Windows (vcpkg) and Linux (system packages)
- Improve dependency handling for cryptopp and nlohmann-json
- Update build scripts for better release management
- Enhance CHANGELOG.md with latest version information
2025-08-28 21:29:16 +02:00
5493c0dcf3 Merge branch 'main' of https://gitea.medisoftware.org/Markus/lib-privatebin 2025-08-28 21:26:36 +02:00
cd7e957692 Fix compiler warnings and improve code quality
- Replace unsafe strcpy with strcpy_s for better security
- Fix DLL binding issues by adding PRIVATEBIN_API macros
- Add explicit type casts to resolve size conversion warnings
- Replace unsafe getenv with _dupenv_s for better security
- Add PRIVATEBINAPI_EXPORTS definition in CMakeLists.txt
- Improve CMake configuration for better build compatibility
2025-08-28 21:25:25 +02:00
d712d3a9d8 Update README with comprehensive Linux build instructions and compatibility information 2025-08-28 20:40:46 +02:00
000fde485f Fix CMakeLists.txt for Linux compatibility while preserving Windows vcpkg support 2025-08-28 20:37:34 +02:00
13 changed files with 192 additions and 49 deletions

View File

@ -20,7 +20,7 @@
- **IMPROVED**: Enhanced build documentation with platform-specific instructions
- **IMPROVED**: Better project structure and organization
s## v0.1.1.3 (2025-08-28)
## v0.1.1.3 (2025-08-28)
### New Features
- **File Upload Functionality**: New `upload_file()` function added

View File

@ -17,8 +17,16 @@ elseif(UNIX)
endif()
# Handle dependencies
find_package(cryptopp CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
if(WIN32)
# Windows: Use vcpkg packages
find_package(cryptopp CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
else()
# Linux: Use system packages
find_package(PkgConfig REQUIRED)
pkg_check_modules(CRYPTOPP REQUIRED libcryptopp)
pkg_check_modules(NLOHMANN_JSON REQUIRED nlohmann_json)
endif()
# Add library sources
set(SOURCES
@ -40,22 +48,42 @@ set(HEADERS
# Create the shared library
add_library(privatebinapi SHARED ${SOURCES} ${HEADERS})
# Define PRIVATEBINAPI_EXPORTS for the library build
target_compile_definitions(privatebinapi PRIVATE PRIVATEBINAPI_EXPORTS)
# Include directories
target_include_directories(privatebinapi PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
)
# Explicitly include vcpkg directories
target_include_directories(privatebinapi PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/vcpkg_installed/x64-windows/include
)
# Platform-specific include directories
if(WIN32)
# Windows: Include vcpkg directories
target_include_directories(privatebinapi PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/vcpkg_installed/x64-windows/include
)
endif()
# Link dependencies
target_link_libraries(privatebinapi PRIVATE
cryptopp::cryptopp
nlohmann_json::nlohmann_json
${PLATFORM_LIBS}
)
if(WIN32)
# Windows: Use vcpkg targets
target_link_libraries(privatebinapi PRIVATE
cryptopp::cryptopp
nlohmann_json::nlohmann_json
${PLATFORM_LIBS}
)
else()
# Linux: Use system libraries
target_link_libraries(privatebinapi PRIVATE
${CRYPTOPP_LIBRARIES}
${NLOHMANN_JSON_LIBRARIES}
${PLATFORM_LIBS}
)
target_include_directories(privatebinapi PRIVATE
${CRYPTOPP_INCLUDE_DIRS}
${NLOHMANN_JSON_INCLUDE_DIRS}
)
endif()
# Install targets
install(TARGETS privatebinapi
@ -84,12 +112,11 @@ if(ENABLE_LLVM_COVERAGE)
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
add_link_options(-fprofile-instr-generate)
# Helper variables for report tools (can be overridden from environment)
# Helper variables for report tools
set(LLVM_PROFDATA "llvm-profdata" CACHE STRING "Path to llvm-profdata")
set(LLVM_COV "llvm-cov" CACHE STRING "Path to llvm-cov")
# Custom target to run tests and produce coverage report
# Usage: cmake --build build --target coverage_llvm --config Release
add_custom_target(
coverage_llvm
COMMAND ${CMAKE_COMMAND} -E env
@ -110,4 +137,4 @@ if(ENABLE_LLVM_COVERAGE)
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS privatebinapi
)
endif()
endif()

105
README.md
View File

@ -119,9 +119,11 @@ This script:
- Configures CMake with proper toolchain
- Builds the project using MSVC compiler
### Linux/macOS Build Script
### Linux Build Scripts
#### Automated Build Script
**File:** `scripts/build.sh`
**Requirements:** CMake, C++17 compiler, vcpkg
**Requirements:** CMake, C++17 compiler, system packages
```bash
# Make executable and run from project root
@ -129,6 +131,54 @@ chmod +x scripts/build.sh
./scripts/build.sh
```
This script:
- Automatically detects and installs required dependencies
- Configures CMake with Unix Makefiles
- Builds the project in Release configuration
#### Manual Linux Build (Recommended)
**Requirements:** CMake 3.10+, GCC/Clang with C++17 support, system packages
```bash
# Install dependencies (Fedora/RHEL/CentOS)
sudo dnf install cmake gcc-c++ libcurl-devel cryptopp-devel json-devel
# Install dependencies (Ubuntu/Debian)
sudo apt install cmake g++ libcurl4-openssl-dev libcrypto++-dev nlohmann-json3-dev
# Build the project
mkdir build
cd build
cmake ..
make -j$(nproc)
# Run tests
ctest --verbose
# Run example
./example/example
```
**Linux Dependencies:**
- **libcurl-devel** - HTTP client library
- **cryptopp-devel** - Cryptographic library
- **json-devel** - JSON parsing library
- **cmake** - Build system
- **gcc-c++** - C++17 compiler
### macOS Build Script
**File:** `scripts/build.sh`
**Requirements:** CMake, C++17 compiler, Homebrew packages
```bash
# Install dependencies via Homebrew
brew install cmake cryptopp nlohmann-json curl
# Make executable and run from project root
chmod +x scripts/build.sh
./scripts/build.sh
```
This script:
- Bootstraps vcpkg if not present
- Configures CMake with Unix Makefiles
@ -140,8 +190,9 @@ This script:
- CMake 3.10+
- C++17 compatible compiler
- Crypto++ (via vcpkg)
- nlohmann/json (via vcpkg)
- **Windows:** Crypto++ and nlohmann/json (via vcpkg)
- **Linux:** libcurl, cryptopp, and nlohmann-json (via system packages)
- **macOS:** libcurl, cryptopp, and nlohmann/json (via Homebrew)
### Compilation
@ -157,14 +208,43 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\build_windows.ps1
scripts\build_thinkpad.bat
```
#### Linux/macOS - Build via scripts/build.sh
#### Linux - Automated Build via scripts/build.sh
```bash
# Requires: CMake, C++17 compiler, vcpkg
# Requires: CMake, C++17 compiler, system packages
chmod +x scripts/build.sh
./scripts/build.sh
```
#### Manual Build
#### Linux - Manual Build (Recommended)
```bash
# Install dependencies (Fedora/RHEL/CentOS)
sudo dnf install cmake gcc-c++ libcurl-devel cryptopp-devel json-devel
# Install dependencies (Ubuntu/Debian)
sudo apt install cmake g++ libcurl4-openssl-dev libcrypto++-dev nlohmann-json3-dev
# Build the project
mkdir build
cd build
cmake ..
make -j$(nproc)
# Run tests and examples
ctest --verbose
./example/example
```
#### macOS - Build via scripts/build.sh
```bash
# Install dependencies via Homebrew
brew install cmake cryptopp nlohmann-json curl
# Requires: CMake, C++17 compiler, Homebrew packages
chmod +x scripts/build.sh
./scripts/build.sh
```
#### Manual Build (All Platforms)
```bash
mkdir build
cd build
@ -172,7 +252,9 @@ cmake ..
cmake --build . --config Release
```
**Note:** The manual build method requires you to have all dependencies (CMake, compiler, vcpkg) properly configured. For most users, the platform-specific build scripts are recommended.
**Note:** The manual build method requires you to have all dependencies properly configured. For most users, the platform-specific build scripts are recommended.
**Linux Compatibility:** The project has been tested and successfully builds on Fedora Linux with system packages. It automatically detects the platform and uses appropriate dependency resolution methods (vcpkg for Windows, system packages for Linux/macOS).
## Usage
@ -382,6 +464,13 @@ See [LICENSE](LICENSE) for details.
## Changelog
### v0.1.1.6 (2025-08-28)
- **NEW**: Full Linux compatibility with system packages
- **NEW**: Automatic platform detection (Windows: vcpkg, Linux: system packages)
- **IMPROVED**: Enhanced Linux build documentation and instructions
- **IMPROVED**: Better dependency management for cross-platform builds
- **FIXED**: CMakeLists.txt now works on both Windows and Linux without manual configuration
### v0.1.1.5 (2025-08-28)
- **NEW**: Enhanced text format support (plaintext, syntax highlighting, markdown)
- **NEW**: Comprehensive format testing in examples and integration tests

View File

@ -3,6 +3,14 @@
#include <cstring>
#include <string>
#include <cstdlib>
#include <chrono>
#include <thread>
// Helper function to wait between API calls to avoid rate limiting
void wait_between_calls() {
std::cout << "[privatebinapi] Waiting 12 seconds to avoid rate limiting..." << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(12));
}
int main(int argc, char* argv[]) {
std::cout << "PrivateBin API C++ DLL Example" << std::endl;
@ -129,6 +137,9 @@ int main(int argc, char* argv[]) {
std::cout << "✗ Plaintext paste failed. Error code: " << result << std::endl;
}
// Wait between API calls to avoid rate limiting
wait_between_calls();
// Test 2: Syntax highlighting format
std::cout << "\n2. Testing syntax highlighting format..." << std::endl;
char* code_paste_url = nullptr;
@ -167,6 +178,9 @@ int main() {
std::cout << "✗ Syntax highlighting paste failed. Error code: " << result << std::endl;
}
// Wait between API calls to avoid rate limiting
wait_between_calls();
// Test 3: Markdown format
std::cout << "\n3. Testing markdown format..." << std::endl;
char* markdown_paste_url = nullptr;
@ -213,6 +227,9 @@ int result = create_paste(server_url, content, password, expiration, format,
std::cout << "✗ Markdown paste failed. Error code: " << result << std::endl;
}
// Wait between API calls to avoid rate limiting
wait_between_calls();
// Test 4: Interactive format selection
std::cout << "\n4. Interactive format selection..." << std::endl;
char* interactive_paste_url = nullptr;

View File

@ -31,3 +31,4 @@ Get-ChildItem -LiteralPath $OutDir -File | Format-Table Name,Length -AutoSize

View File

@ -36,3 +36,4 @@ Get-ChildItem -LiteralPath $BinDir -File | ForEach-Object {

View File

@ -44,3 +44,4 @@ if ($resp.StatusCode -ge 200 -and $resp.StatusCode -lt 300) {

View File

@ -46,3 +46,4 @@ foreach ($f in $files) {

View File

@ -77,3 +77,4 @@ Write-Host 'Release notes updated with links.'

View File

@ -16,18 +16,19 @@ std::string Base58::encode(const std::vector<unsigned char>& data) {
}
// Convert to base58
std::vector<unsigned char> digits((data.size() - leading_zeros) * 138 / 100 + 1);
size_t digits_size = (data.size() - leading_zeros) * 138 / 100 + 1;
std::vector<unsigned char> digits(digits_size);
size_t digitslen = 1;
for (size_t i = leading_zeros; i < data.size(); i++) {
unsigned int carry = data[i];
size_t carry = static_cast<size_t>(data[i]);
for (size_t j = 0; j < digitslen; j++) {
carry += (unsigned int)(digits[j]) << 8;
digits[j] = carry % 58;
carry += static_cast<size_t>(digits[j]) << 8;
digits[j] = static_cast<unsigned char>(carry % 58);
carry /= 58;
}
while (carry > 0) {
digits[digitslen++] = carry % 58;
digits[digitslen++] = static_cast<unsigned char>(carry % 58);
carry /= 58;
}
}
@ -56,22 +57,23 @@ std::vector<unsigned char> Base58::decode(const std::string& encoded) {
}
// Convert from base58
std::vector<unsigned char> bytes((encoded.length() - leading_ones) * 733 / 1000 + 1);
size_t bytes_size = (encoded.length() - leading_ones) * 733 / 1000 + 1;
std::vector<unsigned char> bytes(bytes_size);
size_t byteslen = 1;
for (size_t i = leading_ones; i < encoded.length(); i++) {
unsigned int carry = ALPHABET.find(encoded[i]);
size_t carry = static_cast<size_t>(ALPHABET.find(encoded[i]));
if (carry == std::string::npos) {
throw std::invalid_argument("Invalid character in Base58 string");
}
for (size_t j = 0; j < byteslen; j++) {
carry += (unsigned int)(bytes[j]) * 58;
bytes[j] = carry & 0xff;
carry += static_cast<size_t>(bytes[j]) * 58;
bytes[j] = static_cast<unsigned char>(carry & 0xff);
carry >>= 8;
}
while (carry > 0) {
bytes[byteslen++] = carry & 0xff;
bytes[byteslen++] = static_cast<unsigned char>(carry & 0xff);
carry >>= 8;
}
}

View File

@ -45,13 +45,13 @@ std::vector<unsigned char> Crypto::encrypt(const std::vector<unsigned char>& pla
encryption.EncryptAndAuthenticate(
ciphertext.data(),
auth_tag.data(),
auth_tag.size(),
static_cast<int>(auth_tag.size()),
iv.data(),
iv.size(),
static_cast<int>(iv.size()),
nullptr,
0, // Additional authenticated data
plaintext.data(),
plaintext.size()
static_cast<int>(plaintext.size())
);
return ciphertext;
@ -79,13 +79,13 @@ std::vector<unsigned char> Crypto::decrypt(const std::vector<unsigned char>& cip
bool valid = decryption.DecryptAndVerify(
plaintext.data(),
auth_tag.data(),
auth_tag.size(),
static_cast<int>(auth_tag.size()),
iv.data(),
iv.size(),
static_cast<int>(iv.size()),
nullptr,
0, // Additional authenticated data
ciphertext.data(),
ciphertext.size()
static_cast<int>(ciphertext.size())
);
if(!valid) {

View File

@ -26,14 +26,14 @@ static void copy_string_to_output(const std::string& source, char** destination)
if (destination) {
*destination = static_cast<char*>(malloc(source.length() + 1));
if (*destination) {
std::strcpy(*destination, source.c_str());
strcpy_s(*destination, source.length() + 1, source.c_str());
}
}
}
extern "C" {
int create_paste(const char* server_url, const char* content,
PRIVATEBIN_API int create_paste(const char* server_url, const char* content,
const char* password, const char* expiration,
const char* format, int burn_after_reading,
int open_discussion, char** paste_url,
@ -128,10 +128,10 @@ int create_paste(const char* server_url, const char* content,
}
}
int upload_file(const char* server_url, const char* file_path,
const char* password, const char* expiration,
int burn_after_reading, int open_discussion,
char** paste_url, char** delete_token) {
PRIVATEBIN_API int upload_file(const char* server_url, const char* file_path,
const char* password, const char* expiration,
int burn_after_reading, int open_discussion,
char** paste_url, char** delete_token) {
if (!server_url || !file_path) {
return ERROR_INVALID_INPUT;
@ -248,7 +248,7 @@ int upload_file(const char* server_url, const char* file_path,
}
}
int get_paste(const char* server_url, const char* paste_id,
PRIVATEBIN_API int get_paste(const char* server_url, const char* paste_id,
const char* key, char** content) {
if (!server_url || !paste_id || !key || !content) {
@ -305,7 +305,7 @@ int get_paste(const char* server_url, const char* paste_id,
}
}
int delete_paste(const char* server_url, const char* paste_id,
PRIVATEBIN_API int delete_paste(const char* server_url, const char* paste_id,
const char* delete_token) {
if (!server_url || !paste_id || !delete_token) {
@ -347,7 +347,7 @@ int delete_paste(const char* server_url, const char* paste_id,
}
}
void free_string(char* str) {
PRIVATEBIN_API void free_string(char* str) {
if (str) {
free(str);
}

View File

@ -21,9 +21,12 @@ static bool extract_paste_id_and_key(const std::string& full_url, std::string& p
}
int main() {
const char* it = std::getenv("PRIVATEBIN_IT");
char* it = nullptr;
size_t len = 0;
_dupenv_s(&it, &len, "PRIVATEBIN_IT");
if (!it || std::string(it) == "0") {
std::cout << "[test] PRIVATEBIN_IT not set; skipping integration test." << std::endl;
free(it);
return 0; // treat as success when integration testing is disabled
}