Skip to content

Commit

Permalink
Merge branch 'main' into update-java-read-me
Browse files Browse the repository at this point in the history
  • Loading branch information
vphan916 authored Sep 23, 2024
2 parents c16a5f1 + 56fc75d commit fba7f41
Show file tree
Hide file tree
Showing 15 changed files with 299 additions and 115 deletions.
69 changes: 32 additions & 37 deletions .github/workflows/build-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ jobs:
- os: macos-13
target: x86_64-apple-darwin

# - os: windows-2022
# target: x86_64-pc-windows-msvc
- os: macos-13
target: aarch64-apple-darwin

- os: windows-2022
target: x86_64-pc-windows-msvc

- os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
Expand All @@ -52,16 +55,6 @@ jobs:
brew install nlohmann-json
brew install boost
- name: Cache vcpkg
if: runner.os == 'Windows'
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: C:/vcpkg/
key: vcpkg-${{ runner.os }}-${{ matrix.settings.target }}
restore-keys: |
vcpkg-${{ runner.os }}-
vcpkg-
- name: Export GitHub Actions cache environment variables
if: runner.os == 'Windows'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
Expand All @@ -70,22 +63,6 @@ jobs:
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Install libraries for Windows
if: runner.os == 'Windows' && steps.cache.outputs.cache-hit != 'true'
env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
run: |
vcpkg install boost --binarysource="clear;x-gha,readwrite"
vcpkg install nlohmann-json --binarysource="clear;x-gha,readwrite"
shell: pwsh

- name: Save cache
if: runner.os == 'Windows'
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: C:/vcpkg/
key: vcpkg-${{ runner.os }}-${{ matrix.settings.target }}

- name: Download schemas
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
Expand Down Expand Up @@ -114,6 +91,20 @@ jobs:
Get-Acl languages/cpp/include/* | Format-List
- name: Ensure bitwarden-c is in include folder
working-directory: languages/cpp
shell: bash
run: |
mv include/release/* include/
if [[ '${{ runner.os }}' == 'macOS' || '${{ runner.os }}' == 'Linux' ]]; then
ls include/libbitwarden_c.* || { echo "Missing libbitwarden_c.*"; exit 1; }
fi
if [[ '${{ runner.os }}' == 'Windows' ]]; then
ls include/bitwarden_c.dll || { echo "Missing bitwarden_c.dll"; exit 1; }
ls include/bitwarden_c.dll.lib || { echo "Missing bitwarden_c.dll.lib"; exit 1; }
fi
rmdir include/release
- name: Build unix
working-directory: languages/cpp
if: runner.os == 'macOS' || runner.os == 'Linux'
Expand All @@ -139,24 +130,28 @@ jobs:
if: runner.os == 'Windows'
working-directory: languages/cpp
env:
BOOST_INCLUDE_DIR: C:\vcpkg\installed\x64-windows\include\boost
NLOHMANN_JSON_INCLUDE_DIR: C:\vcpkg\installed\x64-windows\include\nlohmann-json
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
run: |
mkdir build
cd build
$DNLOHMANN_PATH="C:\vcpkg\installed\x64-windows\include\nlohmann-json"
$DBOOST_PATH="C:\vcpkg\installed\x64-windows\include\boost"
$DTARGET="include/libbitwarden_c.dll"
cmake .. -DNLOHMANN=$DNLOHMANN_PATH -DBOOST=$DBOOST_PATH -DTARGET="include/libbitwarden_c.dll" -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/languages/cpp/ -DBUILD_TESTING=OFF
cmake --build .
$env:DTARGET="include\bitwarden_c.dll.lib"
cmake .. -DTARGET="$env:DTARGET" -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT\scripts\buildsystems\vcpkg.cmake"
cmake --build . --config Release
shell: pwsh

- name: Copy artifacts
working-directory: languages/cpp/build
shell: bash
run: |
mkdir artifacts
cp libbitwarden_c.* artifacts
cp libBitwardenClient.* artifacts
if [[ '${{ runner.os }}' == 'macOS' || '${{ runner.os }}' == 'Linux' ]]; then
cp libbitwarden_c.* artifacts
cp libBitwardenClient.* artifacts
fi
if [[ '${{ runner.os }}' == 'Windows' ]]; then
cp */BitwardenClient.* artifacts
cp ../include/bitwarden_c.{lib,dll.lib,dll} artifacts
fi
- name: Upload C++ package for ${{ matrix.settings.target }}
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/publish-php.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Publish PHP SDK
run-name: Publish PHP SDK ${{ inputs.release_type }}

Expand Down Expand Up @@ -29,9 +30,9 @@ jobs:
- name: Branch check
if: ${{ inputs.release_type != 'Dry Run' }}
run: |
if [[ "$GITHUB_REF" != "refs/heads/rc" ]] && [[ "$GITHUB_REF" != "refs/heads/hotfix-rc" ]]; then
if [[ "$GITHUB_REF" != "refs/heads/main" ]]; then
echo "==================================="
echo "[!] Can only release from the 'rc' or 'hotfix-rc' branches"
echo "[!] Can only release from the 'main' branch"
echo "==================================="
exit 1
fi
Expand Down Expand Up @@ -123,7 +124,7 @@ jobs:
working-directory: sm-sdk-php
run: |
git add .
git commit -m "Update Go SDK to ${{ github.sha }}"
git commit -m "Update PHP SDK to ${{ github.sha }}"
if [[ "${{ inputs.release_type }}" == "Dry Run" ]]; then
echo "==================================="
Expand All @@ -135,7 +136,7 @@ jobs:
git push origin main
fi
- name: Create release tag on SDK Go repo
- name: Create release tag on PHP SDK repo
if: ${{ inputs.release_type != 'Dry Run' }}
working-directory: sm-sdk-php
run: |
Expand Down Expand Up @@ -177,7 +178,7 @@ jobs:
with:
workflow: build-rust-cross-platform.yml
workflow_conclusion: success
branch: ${{ inputs.release_type == 'Dry Run' && 'main' || github.ref_name }}
branch: main
artifacts: libbitwarden_c_files-x86_64-apple-darwin
skip_unpack: true

Expand All @@ -186,7 +187,7 @@ jobs:
with:
workflow: build-rust-cross-platform.yml
workflow_conclusion: success
branch: ${{ inputs.release_type == 'Dry Run' && 'main' || github.ref_name }}
branch: main
artifacts: libbitwarden_c_files-aarch64-apple-darwin
skip_unpack: true

Expand All @@ -195,7 +196,7 @@ jobs:
with:
workflow: build-rust-cross-platform.yml
workflow_conclusion: success
branch: ${{ inputs.release_type == 'Dry Run' && 'main' || github.ref_name }}
branch: main
artifacts: libbitwarden_c_files-x86_64-unknown-linux-gnu
skip_unpack: true

Expand All @@ -204,7 +205,7 @@ jobs:
with:
workflow: build-rust-cross-platform.yml
workflow_conclusion: success
branch: ${{ inputs.release_type == 'Dry Run' && 'main' || github.ref_name }}
branch: main
artifacts: libbitwarden_c_files-x86_64-pc-windows-msvc
skip_unpack: true

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ languages/java/src/main/java/com/bitwarden/sdk/schema
languages/js/sdk-client/src/schemas.ts
languages/python/bitwarden_sdk/schemas.py
support/schemas

# Cmake build files
languages/cpp/cmake-build-debug
17 changes: 8 additions & 9 deletions crates/bitwarden-crypto/src/keys/shareable_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::pin::Pin;
use aes::cipher::typenum::U64;
use generic_array::GenericArray;
use hmac::Mac;
use zeroize::{Zeroize, Zeroizing};
use zeroize::Zeroizing;

use crate::{
keys::SymmetricCryptoKey,
Expand All @@ -20,18 +20,17 @@ pub fn derive_shareable_key(
info: Option<&str>,
) -> SymmetricCryptoKey {
// Because all inputs are fixed size, we can unwrap all errors here without issue
let mut res = PbkdfSha256Hmac::new_from_slice(format!("bitwarden-{}", name).as_bytes())
.expect("hmac new_from_slice should not fail")
.chain_update(secret)
.finalize()
.into_bytes();
let res = Zeroizing::new(
PbkdfSha256Hmac::new_from_slice(format!("bitwarden-{}", name).as_bytes())
.expect("hmac new_from_slice should not fail")
.chain_update(secret)
.finalize()
.into_bytes(),
);

let mut key: Pin<Box<GenericArray<u8, U64>>> =
hkdf_expand(&res, info).expect("Input is a valid size");

// Zeroize the temporary buffer
res.zeroize();

SymmetricCryptoKey::try_from(key.as_mut_slice()).expect("Key is a valid size")
}

Expand Down
14 changes: 12 additions & 2 deletions languages/cpp/CMakeBuild.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
## Introduction

Cmake is used to build the C++ Bitwarden client library. Output should be placed in the build directory.

The output contains two dynamic libraries:

- The C++ client `BitwardenClient`
Expand All @@ -20,7 +19,8 @@ See how to use these libraries in the [example use guide](./examples/ExampleUse.

## Build Commands

One should be in the root directory of the C++ wrapper (the same level where is CMakeLists.txt placed). Paths of the three libraries should be placed inside the cmake build command:
One should be in the root directory of the C++ wrapper (the same level where is CMakeLists.txt placed). Paths of the
three libraries should be placed inside the cmake build command:

```bash
mkdir -p build
Expand All @@ -29,6 +29,16 @@ cmake .. -DNLOHMANN=/path/to/include/nlohmann -DBOOST=/path/to/include/boost -DT
cmake --build .
```

## IDE Support

You may need to manually set the CMake `TARGET` variable for your IDE. For CLion, add the following to the CMake options
settings:

```bash
# macOS example
-DTARGET=../../target/release/libbitwarden_c.dylib
```

## Example

### macOS
Expand Down
1 change: 1 addition & 0 deletions languages/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.15)
project(BitwardenClient)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

# Set placeholders to be passed from command line
set(NLOHMANN_JSON_INCLUDE_DIR_PLACEHOLDER ${NLOHMANN})
Expand Down
33 changes: 24 additions & 9 deletions languages/cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ bitwardenSettings.set_identity_url("<bitwarden-identity>");

```c++
std::string accessToken = "<access-token>";
std::string stateFile = "<state-file>";
// Optional - argument in BitwardenClient
BitwardenClient bitwardenClient = BitwardenClient(bitwardenSettings);
bitwardenClient.accessTokenLogin(accessToken);
bitwardenClient.loginAccessToken(accessToken, stateFile);
```

### Create new project

```c++
boost::uuids::uuid organizationUuid = boost::uuids::string_generator()("<organization-id>");
ProjectResponse projectResponseCreate = bitwardenClient.createProject(organizationUuid, "TestProject");
boost::uuids::uuid projectId = boost::uuids::string_generator()(projectResponseCreate.get_id());
```

### List all projects
Expand All @@ -43,21 +45,19 @@ ProjectsResponse projectResponseList = bitwardenClient.listProjects(organization
### Get project details

```c++
boost::uuids::uuid projectId = boost::uuids::string_generator()(projectResponseCreate.get_id());
ProjectResponse projectResponseGet = bitwardenClient.getProject(projectId);
```

### Update project

```c++
boost::uuids::uuid projectId = boost::uuids::string_generator()(projectResponseCreate.get_id());
ProjectResponse projectResponseUpdate = bitwardenClient.updateProject(projectId, organizationUuid, "TestProjectUpdated");
ProjectResponse projectResponseUpdate = bitwardenClient.updateProject(organizationUuid, projectId, "TestProjectUpdated");
```

### Delete projects

```c++
SecretsDeleteResponse secretsDeleteResponse = bitwardenClient.deleteSecrets({secretId});
ProjectsDeleteResponse projectsDeleteResponse = bitwardenClient.deleteProjects({projectId});
```
### Add new secret
Expand All @@ -66,7 +66,8 @@ SecretsDeleteResponse secretsDeleteResponse = bitwardenClient.deleteSecrets({sec
std::string key = "key";
std::string value = "value";
std::string note = "note";
SecretResponse secretResponseCreate = bitwardenClient.createSecret(key, value, note, organizationUuid, {projectId});
SecretResponse secretResponseCreate = bitwardenClient.createSecret(organizationUuid, key, value, note, {projectId});
boost::uuids::uuid secretId = boost::uuids::string_generator()(secretResponseCreate.get_id());
```

### List secrets
Expand All @@ -77,14 +78,28 @@ SecretIdentifiersResponse secretIdentifiersResponse = bitwardenClient.listSecret

### Get secret details

```
boost::uuids::uuid secretId = boost::uuids::string_generator()(secretResponseCreate.get_id());
```c++
SecretResponse secretResponseGet = bitwardenClient.getSecret(secretId);
```

### Get multiple secrets by ids

```c++
std::vector<boost::uuids::uuid> secretIds = {secretId, secretId2};
SecretsResponse secretsResponseGet = bitwardenClient.getSecrets(secretIds);
```
### Update secret
```c++
SecretResponse secretResponseUpdate = bitwardenClient.updateSecret(organizationUuid, secretId, "key2", "value2", "note2", {projectId});
```

### Sync secrets

```c++
SecretResponse secretResponseUpdate = bitwardenClient.updateSecret(secretId, "key2", "value2", "note2", organizationUuid, {projectId});
std::chrono::system_clock::time_point lastSyncedDate = std::chrono::system_clock::now();
SecretsSyncResponse secretsSyncResponse = bitwardenClient.sync(orgnizationUuid, lastSyncedDate);
```

# Delete secrets
Expand Down
Loading

0 comments on commit fba7f41

Please sign in to comment.