diff --git a/.editorconfig b/.editorconfig index 28ef180e8..33fa272b4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,10 +12,10 @@ insert_final_newline = true indent_style = space indent_size = 2 -[*.{ts}] -quote_type = single +[*.ts] +quote_type = double -[*.{rs}] +[*.rs] indent_style = space indent_size = 4 @@ -23,6 +23,6 @@ indent_size = 4 indent_style = space indent_size = 4 -[*.{xml}] +[*.xml] # VS Code XML extension removes the final newline insert_final_newline = false diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 6bb362e8c..e4fbb97b9 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -11,3 +11,8 @@ # Secrets Manager team crates/bitwarden-sm @bitwarden/team-secrets-manager-dev crates/bws @bitwarden/team-secrets-manager-dev + +# BRE Automations +crates/bws/Cargo.toml +crates/bws/scripts/install.ps1 +crates/bws/scripts/install.sh diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index a5e6b294d..e43ad29df 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -6,10 +6,6 @@ -## 📸 Screenshots - - - ## ⏰ Reminders before review - Contributor guidelines followed diff --git a/.github/workflows/build-android.yml b/.github/workflows/build-android.yml index 9de6883f5..7607d530d 100644 --- a/.github/workflows/build-android.yml +++ b/.github/workflows/build-android.yml @@ -25,7 +25,7 @@ jobs: - target: i686-linux-android steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Install rust uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable @@ -46,7 +46,7 @@ jobs: run: cross build -p bitwarden-uniffi --release --target=${{ matrix.settings.target }} - name: Upload artifact - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: android-${{ matrix.settings.target }} path: ./target/${{ matrix.settings.target }}/release/libbitwarden_uniffi.so @@ -57,14 +57,14 @@ jobs: needs: build steps: - name: Checkout repo (PR) - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 if: github.event_name == 'pull_request' with: fetch-depth: 0 ref: ${{ github.event.pull_request.head.ref }} - name: Checkout repo (Push) - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 if: github.event_name == 'push' with: fetch-depth: 0 @@ -80,7 +80,7 @@ jobs: key: cargo-combine-cache - name: Setup Java - uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4.2.2 + uses: actions/setup-java@b36c23c0d998641eff861008f374ee103c25ac73 # v4.4.0 with: distribution: temurin java-version: 17 @@ -102,7 +102,7 @@ jobs: run: ./build-schemas.sh - name: Setup gradle - uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 + uses: gradle/actions/setup-gradle@d156388eb19639ec20ade50009f3d199ce1e2808 # v4.1.0 - name: Publish run: ./gradlew sdk:publish diff --git a/.github/workflows/build-cli-docker.yml b/.github/workflows/build-cli-docker.yml index 8302529c8..83daabf2d 100644 --- a/.github/workflows/build-cli-docker.yml +++ b/.github/workflows/build-cli-docker.yml @@ -5,8 +5,6 @@ on: push: branches: - "main" - - "rc" - - "hotfix-rc" workflow_dispatch: pull_request: @@ -19,18 +17,12 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout Repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Check Branch to Publish - env: - PUBLISH_BRANCHES: "master,rc,hotfix-rc" id: publish-branch-check run: | - REF=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} - - IFS="," read -a publish_branches <<< $PUBLISH_BRANCHES - - if [[ "${publish_branches[*]}" =~ "${REF}" ]]; then + if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then echo "is_publish_branch=true" >> $GITHUB_ENV else echo "is_publish_branch=false" >> $GITHUB_ENV @@ -77,10 +69,8 @@ jobs: run: | REF=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} IMAGE_TAG=$(echo "${REF}" | sed "s#/#-#g") # slash safe branch name - if [[ "${IMAGE_TAG}" == "master" ]]; then + if [[ "${IMAGE_TAG}" == "main" ]]; then IMAGE_TAG=dev - elif [[ ("${IMAGE_TAG}" == "rc") || ("${IMAGE_TAG}" == "hotfix-rc") ]]; then - IMAGE_TAG=rc fi echo "image_tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT @@ -89,16 +79,15 @@ jobs: id: tag-list env: IMAGE_TAG: ${{ steps.tag.outputs.image_tag }} - IS_PUBLISH_BRANCH: ${{ env.is_publish_branch }} run: | - if [[ ("${IMAGE_TAG}" == "dev" || "${IMAGE_TAG}" == "rc") && "${IS_PUBLISH_BRANCH}" == "true" ]]; then + if [[ "${IMAGE_TAG}" == "dev" ]]; then echo "tags=$_AZ_REGISTRY/bws:${IMAGE_TAG},bitwarden/bws:${IMAGE_TAG}" >> $GITHUB_OUTPUT else echo "tags=$_AZ_REGISTRY/bws:${IMAGE_TAG}" >> $GITHUB_OUTPUT fi - name: Build and push Docker image - uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v6.7.0 + uses: docker/build-push-action@32945a339266b759abcbdc89316275140b0fc960 # v6.8.0 with: context: . file: crates/bws/Dockerfile @@ -123,10 +112,7 @@ jobs: needs: build-docker steps: - name: Check if any job failed - if: | - github.ref == 'refs/heads/master' - || github.ref == 'refs/heads/rc' - || github.ref == 'refs/heads/hotfix-rc' + if: github.ref == 'refs/heads/main' env: BUILD_DOCKER_STATUS: ${{ needs.build-docker.result }} run: | diff --git a/.github/workflows/build-cli.yml b/.github/workflows/build-cli.yml index 6dd683142..9ffb3bdea 100644 --- a/.github/workflows/build-cli.yml +++ b/.github/workflows/build-cli.yml @@ -6,8 +6,6 @@ on: push: branches: - "main" - - "rc" - - "hotfix-rc" workflow_dispatch: defaults: @@ -23,7 +21,7 @@ jobs: sign: ${{ steps.sign.outputs.sign }} steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Get Package Version id: retrieve-version @@ -58,7 +56,7 @@ jobs: target: aarch64-pc-windows-msvc steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Install rust uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable @@ -74,7 +72,7 @@ jobs: - name: Build env: TARGET: ${{ matrix.settings.target }} - run: cargo build ${{ matrix.features }} -p bws --release --target=${{ matrix.settings.target }} + run: cargo build -p bws --release --target=${{ matrix.settings.target }} - name: Login to Azure if: ${{ needs.setup.outputs.sign == 'true' }} @@ -123,7 +121,7 @@ jobs: run: 7z a ./bws-${{ matrix.settings.target }}-%_PACKAGE_VERSION%.zip ./target/${{ matrix.settings.target }}/release/bws.exe - name: Upload artifact - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: bws-${{ matrix.settings.target }}-${{ env._PACKAGE_VERSION }}.zip path: ./bws-${{ matrix.settings.target }}-${{ env._PACKAGE_VERSION }}.zip @@ -132,8 +130,7 @@ jobs: build-macos: name: Building CLI for - ${{ matrix.settings.os }} - ${{ matrix.settings.target }} runs-on: ${{ matrix.settings.os || 'ubuntu-latest' }} - needs: - - setup + needs: setup env: _PACKAGE_VERSION: ${{ needs.setup.outputs.package_version }} strategy: @@ -148,7 +145,7 @@ jobs: steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Install rust uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable @@ -164,7 +161,7 @@ jobs: - name: Build env: TARGET: ${{ matrix.settings.target }} - run: cargo build ${{ matrix.features }} -p bws --release --target=${{ matrix.settings.target }} + run: cargo build -p bws --release --target=${{ matrix.settings.target }} - name: Login to Azure uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0 @@ -233,7 +230,7 @@ jobs: xcrun notarytool submit ./bws-${{ matrix.settings.target }}-${{ env._PACKAGE_VERSION }}.zip --keychain-profile "notarytool-profile" --wait - name: Upload artifact - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: bws-${{ matrix.settings.target }}-${{ env._PACKAGE_VERSION }}.zip path: ./bws-${{ matrix.settings.target }}-${{ env._PACKAGE_VERSION }}.zip @@ -242,8 +239,7 @@ jobs: build-linux: name: Building CLI for - ${{ matrix.settings.os }} - ${{ matrix.settings.target }} runs-on: ${{ matrix.settings.os || 'ubuntu-latest' }} - needs: - - setup + needs: setup env: _PACKAGE_VERSION: ${{ needs.setup.outputs.package_version }} strategy: @@ -263,7 +259,7 @@ jobs: target: aarch64-unknown-linux-gnu steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Install rust uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable @@ -271,7 +267,8 @@ jobs: toolchain: stable targets: ${{ matrix.settings.target }} - - uses: goto-bus-stop/setup-zig@7ab2955eb728f5440978d5824358023be3a2802d # v2.2.0 + - name: Set up Zig + uses: goto-bus-stop/setup-zig@abea47f85e598557f500fa1fd2ab7464fcb39406 # v2.2.1 with: version: 0.12.0 @@ -286,13 +283,13 @@ jobs: - name: Build env: TARGET: ${{ matrix.settings.target }} - run: cargo zigbuild ${{ matrix.features }} -p bws --release --target=${{ matrix.settings.target }} + run: cargo zigbuild -p bws --release --target=${{ matrix.settings.target }} - name: Zip linux run: zip -j ./bws-${{ matrix.settings.target }}-${{ env._PACKAGE_VERSION }}.zip ./target/${{ matrix.settings.target }}/release/bws - name: Upload artifact - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: bws-${{ matrix.settings.target }}-${{ env._PACKAGE_VERSION }}.zip path: ./bws-${{ matrix.settings.target }}-${{ env._PACKAGE_VERSION }}.zip @@ -308,7 +305,7 @@ jobs: _PACKAGE_VERSION: ${{ needs.setup.outputs.package_version }} steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Download x86_64-apple-darwin artifact uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 @@ -325,7 +322,7 @@ jobs: unzip bws-x86_64-apple-darwin-${{ env._PACKAGE_VERSION }}.zip -d ./bws-x86_64-apple-darwin unzip bws-aarch64-apple-darwin-${{ env._PACKAGE_VERSION }}.zip -d ./bws-aarch64-apple-darwin - - name: lipo create universal package + - name: Create universal package with lipo run: | mkdir ./bws-macos-universal @@ -375,7 +372,7 @@ jobs: - name: Sign binary env: MACOS_CERTIFICATE_NAME: ${{ steps.retrieve-secrets-macos.outputs.macos-bws-certificate-name }} - run: codesign --sign "$MACOS_CERTIFICATE_NAME" --verbose=3 --force --options=runtime --timestamp ./bws-aarch64-apple-darwin/bws + run: codesign --sign "$MACOS_CERTIFICATE_NAME" --verbose=3 --force --options=runtime --timestamp ./bws-macos-universal/bws - name: Notarize app env: @@ -389,7 +386,7 @@ jobs: xcrun notarytool store-credentials "notarytool-profile" --apple-id "$MACOS_NOTARIZATION_APPLE_ID" --team-id "$MACOS_NOTARIZATION_TEAM_ID" --password "$MACOS_NOTARIZATION_PWD" echo "Creating notarization archive" - zip -j ./bws-macos-universal-${{ env._PACKAGE_VERSION }}.zip ./bws-aarch64-apple-darwin/bws + zip -j ./bws-macos-universal-${{ env._PACKAGE_VERSION }}.zip ./bws-macos-universal/bws codesign --sign "$MACOS_CERTIFICATE_NAME" --verbose=3 --force --options=runtime --timestamp ./bws-macos-universal-${{ env._PACKAGE_VERSION }}.zip @@ -397,7 +394,7 @@ jobs: xcrun notarytool submit ./bws-macos-universal-${{ env._PACKAGE_VERSION }}.zip --keychain-profile "notarytool-profile" --wait - name: Upload artifact - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: bws-macos-universal-${{ env._PACKAGE_VERSION }}.zip path: ./bws-macos-universal-${{ env._PACKAGE_VERSION }}.zip @@ -410,7 +407,7 @@ jobs: - setup steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Install rust uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable @@ -432,7 +429,7 @@ jobs: sed -i.bak 's/\$NAME\$/Bitwarden Secrets Manager CLI/g' THIRDPARTY.html - name: Upload artifact - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: THIRDPARTY.html path: ./crates/bws/THIRDPARTY.html @@ -441,11 +438,10 @@ jobs: manpages: name: Generate manpages runs-on: ubuntu-22.04 - needs: - - setup + needs: setup steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Install rust uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable @@ -464,7 +460,7 @@ jobs: mv $OUT_DIR/manpages . - name: Upload artifact - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: manpages path: ./manpages/* diff --git a/.github/workflows/build-cpp.yml b/.github/workflows/build-cpp.yml index d26d22254..686369366 100644 --- a/.github/workflows/build-cpp.yml +++ b/.github/workflows/build-cpp.yml @@ -30,15 +30,18 @@ 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 steps: - name: Checkout Repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: install dependencies linux if: runner.os == 'Linux' @@ -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 @@ -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: @@ -114,6 +91,18 @@ jobs: Get-Acl languages/cpp/include/* | Format-List + - name: Ensure bitwarden-c is in include folder + working-directory: languages/cpp + shell: bash + run: | + 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 + - name: Build unix working-directory: languages/cpp if: runner.os == 'macOS' || runner.os == 'Linux' @@ -139,27 +128,31 @@ 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@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: libbitwarden_cpp-${{ matrix.settings.target }} path: languages/cpp/build/artifacts diff --git a/.github/workflows/build-dotnet.yml b/.github/workflows/build-dotnet.yml index cd6441d77..bb5d56b6b 100644 --- a/.github/workflows/build-dotnet.yml +++ b/.github/workflows/build-dotnet.yml @@ -23,7 +23,7 @@ jobs: version: ${{ steps.version.outputs.version }} steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Install xmllint run: sudo apt-get install -y libxml2-utils @@ -44,7 +44,7 @@ jobs: steps: - name: Checkout Repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Download C# schemas artifact uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 @@ -92,7 +92,7 @@ jobs: working-directory: languages/csharp/Bitwarden.Sdk - name: Upload NuGet package - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: Bitwarden.Sdk.${{ needs.version.outputs.version }}.nupkg path: | diff --git a/.github/workflows/build-go.yaml b/.github/workflows/build-go.yaml index 4ad7d0345..ffb4d6693 100644 --- a/.github/workflows/build-go.yaml +++ b/.github/workflows/build-go.yaml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout Repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Setup Go environment uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 diff --git a/.github/workflows/build-java.yml b/.github/workflows/build-java.yml index a42663e3f..6994a5a61 100644 --- a/.github/workflows/build-java.yml +++ b/.github/workflows/build-java.yml @@ -1,11 +1,10 @@ +--- name: Build Java SDK on: push: branches: - main - - rc - - hotfix-rc pull_request: workflow_dispatch: @@ -25,7 +24,7 @@ jobs: steps: - name: Checkout Repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Download Java schemas artifact uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 @@ -34,7 +33,7 @@ jobs: path: languages/java/src/main/java/bit/sdk/schema/ - name: Setup Java - uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4.2.2 + uses: actions/setup-java@b36c23c0d998641eff861008f374ee103c25ac73 # v4.4.0 with: distribution: temurin java-version: 17 @@ -66,3 +65,24 @@ jobs: - name: Build Maven run: ./gradlew build working-directory: languages/java + + - name: Upload Java SDK Build + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 + with: + name: build + path: ${{ github.workspace }}/languages/java/build + if-no-files-found: error + + - name: Upload Java SDK Build + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 + with: + name: resources + path: ${{ github.workspace }}/languages/java/src/main/resources + if-no-files-found: error + + - name: Upload Java SDK Build + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 + with: + name: schemas + path: languages/java/src/main/java/bit/sdk/schema + if-no-files-found: error diff --git a/.github/workflows/build-napi.yml b/.github/workflows/build-napi.yml index 5ad1ebd54..41ed1d17d 100644 --- a/.github/workflows/build-napi.yml +++ b/.github/workflows/build-napi.yml @@ -51,10 +51,10 @@ jobs: strip *.node steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Setup Node - uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3 + uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4 with: node-version: 18 cache: "npm" @@ -84,7 +84,7 @@ jobs: run: ${{ matrix.settings.build }} - name: Upload artifact - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: sdk-bitwarden-napi-${{ matrix.settings.target }} path: ${{ github.workspace }}/crates/bitwarden-napi/sdk-napi.*.node diff --git a/.github/workflows/build-python-wheels.yml b/.github/workflows/build-python-wheels.yml index 0f9e2d8bf..b39195679 100644 --- a/.github/workflows/build-python-wheels.yml +++ b/.github/workflows/build-python-wheels.yml @@ -26,7 +26,7 @@ jobs: package_version: ${{ steps.retrieve-version.outputs.package_version }} steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Get Package Version id: retrieve-version @@ -63,10 +63,10 @@ jobs: steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Setup Node - uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3 + uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4 with: node-version: 18 @@ -89,7 +89,7 @@ jobs: - name: Build wheels if: ${{ matrix.settings.target != 'x86_64-unknown-linux-gnu' }} - uses: PyO3/maturin-action@52b28abb0c6729beb388babfc348bf6ff5aaff31 # v1.42.2 + uses: PyO3/maturin-action@2c5c1560848aaa364c3545136054932db5fa27b7 # v1.44.0 with: target: ${{ matrix.settings.target }} args: --release --find-interpreter --sdist @@ -99,7 +99,7 @@ jobs: - name: Build wheels (Linux - x86_64) if: ${{ matrix.settings.target == 'x86_64-unknown-linux-gnu' }} - uses: PyO3/maturin-action@52b28abb0c6729beb388babfc348bf6ff5aaff31 # v1.42.2 + uses: PyO3/maturin-action@2c5c1560848aaa364c3545136054932db5fa27b7 # v1.44.0 with: target: ${{ matrix.settings.target }} args: --release --find-interpreter --sdist @@ -109,14 +109,14 @@ jobs: working-directory: ${{ github.workspace }}/languages/python - name: Upload wheels - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: bitwarden_sdk-${{ env._PACKAGE_VERSION }}-${{ matrix.settings.target }} path: ${{ github.workspace }}/target/wheels/bitwarden_sdk*.whl - name: Upload sdists if: ${{ matrix.settings.target == 'x86_64-unknown-linux-gnu' }} # we only need one sdist - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: bitwarden_sdk-${{ env._PACKAGE_VERSION }}-sdist path: ${{ github.workspace }}/target/wheels/bitwarden_sdk-*.tar.gz diff --git a/.github/workflows/build-ruby.yml b/.github/workflows/build-ruby.yml new file mode 100644 index 000000000..5a3f1a016 --- /dev/null +++ b/.github/workflows/build-ruby.yml @@ -0,0 +1,95 @@ +--- +name: Build Ruby + +on: + pull_request: + push: + branches: + - "main" + workflow_dispatch: + +jobs: + build: + name: Build Ruby + runs-on: ubuntu-22.04 + steps: + - name: Checkout Repository + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Set up Ruby + uses: ruby/setup-ruby@52753b7da854d5c07df37391a986c76ab4615999 # v1.191.0 + with: + ruby-version: 3.2 + + - name: Download artifacts + uses: bitwarden/gh-actions/download-artifacts@main + with: + workflow: generate_schemas.yml + path: languages/ruby/bitwarden_sdk_secrets/lib + workflow_conclusion: success + branch: ${{ github.ref_name }} + artifacts: schemas.rb + + - name: Download x86_64-apple-darwin artifact + uses: bitwarden/gh-actions/download-artifacts@main + with: + workflow: build-rust-cross-platform.yml + path: temp/macos-x64 + workflow_conclusion: success + branch: ${{ github.ref_name }} + artifacts: libbitwarden_c_files-x86_64-apple-darwin + + - name: Download aarch64-apple-darwin artifact + uses: bitwarden/gh-actions/download-artifacts@main + with: + workflow: build-rust-cross-platform.yml + workflow_conclusion: success + branch: ${{ github.ref_name }} + artifacts: libbitwarden_c_files-aarch64-apple-darwin + path: temp/macos-arm64 + + - name: Download x86_64-unknown-linux-gnu artifact + uses: bitwarden/gh-actions/download-artifacts@main + with: + workflow: build-rust-cross-platform.yml + workflow_conclusion: success + branch: ${{ github.ref_name }} + artifacts: libbitwarden_c_files-x86_64-unknown-linux-gnu + path: temp/linux-x64 + + - name: Download x86_64-pc-windows-msvc artifact + uses: bitwarden/gh-actions/download-artifacts@main + with: + workflow: build-rust-cross-platform.yml + workflow_conclusion: success + branch: ${{ github.ref_name }} + artifacts: libbitwarden_c_files-x86_64-pc-windows-msvc + path: temp/windows-x64 + + - name: Copy lib files + run: | + mkdir -p languages/ruby/bitwarden_sdk_secrets/lib/macos-arm64 + mkdir -p languages/ruby/bitwarden_sdk_secrets/lib/linux-x64 + mkdir -p languages/ruby/bitwarden_sdk_secrets/lib/macos-x64 + mkdir -p languages/ruby/bitwarden_sdk_secrets/lib/windows-x64 + + platforms=("macos-arm64" "linux-x64" "macos-x64" "windows-x64") + files=("libbitwarden_c.dylib" "libbitwarden_c.so" "libbitwarden_c.dylib" "bitwarden_c.dll") + + for ((i=0; i<${#platforms[@]}; i++)); do + cp "temp/${platforms[$i]}/${files[$i]}" "languages/ruby/bitwarden_sdk_secrets/lib/${platforms[$i]}/${files[$i]}" + done + + - name: bundle install + run: bundle install + working-directory: languages/ruby/bitwarden_sdk_secrets + + - name: Build gem + run: gem build bitwarden-sdk-secrets.gemspec + working-directory: languages/ruby/bitwarden_sdk_secrets + + - name: Upload artifact + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 + with: + path: bitwarden-sdk-secrets-*.gem + name: bitwarden-sdk-secrets diff --git a/.github/workflows/build-rust-crates.yml b/.github/workflows/build-rust-crates.yml index 068bb9bbd..d4116bcf9 100644 --- a/.github/workflows/build-rust-crates.yml +++ b/.github/workflows/build-rust-crates.yml @@ -7,8 +7,6 @@ on: push: branches: - "main" - - "rc" - - "hotfix-rc" env: CARGO_TERM_COLOR: always @@ -17,7 +15,7 @@ jobs: build: name: Building ${{matrix.package}} for - ${{ matrix.os }} - runs-on: ${{ matrix.settings.os || 'ubuntu-latest' }} + runs-on: ${{ matrix.os || 'ubuntu-latest' }} strategy: fail-fast: false @@ -36,13 +34,12 @@ jobs: steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Install rust uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable with: toolchain: stable - targets: ${{ matrix.settings.target }} - name: Cache cargo registry uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 @@ -61,18 +58,16 @@ jobs: release-dry-run: name: Release dry-run runs-on: ubuntu-latest - if: ${{ github.ref == 'refs/head/main' || github.ref == 'refs/head/rc' || github.ref == 'refs/head/hotfix-rc' }} - needs: - - build + if: ${{ github.ref == 'refs/head/main' }} + needs: build steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Install rust uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable with: toolchain: stable - targets: ${{ matrix.settings.target }} - name: Cache cargo registry uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 diff --git a/.github/workflows/build-rust-cross-platform.yml b/.github/workflows/build-rust-cross-platform.yml index 92ed526f2..1748661b9 100644 --- a/.github/workflows/build-rust-cross-platform.yml +++ b/.github/workflows/build-rust-cross-platform.yml @@ -26,6 +26,9 @@ jobs: target: x86_64-pc-windows-msvc - os: windows-2022 target: x86_64-pc-windows-gnu + # caution: updating the linux runner OS version for GNU + # targets will likely break libbitwarden_c for older OS versions. + # prefer using oldest supported runner for for these targets - os: ubuntu-22.04 target: x86_64-unknown-linux-gnu - os: ubuntu-22.04 @@ -35,7 +38,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Install rust uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable @@ -45,7 +48,7 @@ jobs: - name: Cache cargo registry uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - uses: goto-bus-stop/setup-zig@7ab2955eb728f5440978d5824358023be3a2802d # v2.2.0 + - uses: goto-bus-stop/setup-zig@abea47f85e598557f500fa1fd2ab7464fcb39406 # v2.2.1 if: ${{ contains(matrix.settings.target, 'musl') }} with: version: 0.12.0 @@ -57,21 +60,36 @@ jobs: - name: Add build architecture run: rustup target add ${{ matrix.settings.target }} + # Build Rust for musl - name: Build Rust for - ${{ matrix.settings.target }} if: ${{ contains(matrix.settings.target, 'musl') }} env: RUSTFLAGS: "-D warnings" run: cargo zigbuild -p bitwarden-c --target ${{ matrix.settings.target }} --release + # Build Rust for windows-gnu - name: Build Rust for - ${{ matrix.settings.target }} - if: ${{ !contains(matrix.settings.target, 'musl') }} + if: ${{ matrix.settings.target == 'x86_64-pc-windows-gnu' }} env: RUSTFLAGS: "-D warnings" + run: cargo build -p bitwarden-c --target ${{ matrix.settings.target }} --profile=release-windows + + # Build Rust for !musl && !windows-gnu + - name: Build Rust for - ${{ matrix.settings.target }} + if: ${{ !contains(matrix.settings.target, 'musl') && matrix.settings.target != 'x86_64-pc-windows-gnu' }} + env: + RUSTFLAGS: "-D warnings" + MACOSX_DEPLOYMENT_TARGET: "10.14" # allows using new macos runner versions while still supporting older systems run: cargo build -p bitwarden-c --target ${{ matrix.settings.target }} --release - name: Upload Artifact - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 + with: + name: libbitwarden_c_files-${{ matrix.settings.target }} + path: target/${{ matrix.settings.target }}/release/*bitwarden_c* + + - name: Upload Artifact + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: libbitwarden_c_files-${{ matrix.settings.target }} - path: | - target/${{ matrix.settings.target }}/release/*bitwarden_c* + path: target/${{ matrix.settings.target }}/release-windows/*bitwarden_c* diff --git a/.github/workflows/build-swift.yml b/.github/workflows/build-swift.yml index b37c62811..372241348 100644 --- a/.github/workflows/build-swift.yml +++ b/.github/workflows/build-swift.yml @@ -7,6 +7,7 @@ on: - "rc" - "hotfix-rc" - "main" + workflow_dispatch: jobs: version: @@ -16,7 +17,7 @@ jobs: package_version: ${{ steps.retrieve-version.outputs.package_version }} steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Get Package Version id: retrieve-version @@ -32,7 +33,7 @@ jobs: _VERSION: ${{ needs.version.outputs.package_version }} steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Install rust uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable @@ -60,11 +61,23 @@ jobs: # SHA Short echo "short-sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + - name: Zip BitwardenFFI.xcframework + run: | + mkdir artifacts + cp -rf languages/swift/BitwardenFFI.xcframework artifacts + - name: Upload BitwardenFFI.xcframework artifact uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: BitwardenFFI-${{ env._VERSION }}-${{ steps.build.outputs.short-sha }}.xcframework - path: languages/swift/BitwardenFFI.xcframework + path: artifacts + if-no-files-found: error + + - name: Upload BitwardenSdk sources + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 + with: + name: BitwardenSdk-${{ env._VERSION }}-${{ steps.build.outputs.short-sha }}-sources + path: languages/swift/Sources/BitwardenSdk if-no-files-found: error trigger-swift-release: diff --git a/.github/workflows/build-wasm-internal.yml b/.github/workflows/build-wasm-internal.yml new file mode 100644 index 000000000..99fe06c44 --- /dev/null +++ b/.github/workflows/build-wasm-internal.yml @@ -0,0 +1,59 @@ +--- +name: Build @bitwarden/sdk-internal + +on: + pull_request: + push: + branches: + - "main" + - "rc" + - "hotfix-rc" + workflow_dispatch: + +defaults: + run: + shell: bash + working-directory: crates/bitwarden-wasm-internal + +jobs: + build: + name: Building @bitwarden/sdk-wasm-internal + runs-on: ubuntu-22.04 + + steps: + - name: Checkout repo + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Setup Node + uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4 + with: + node-version: 20 + registry-url: "https://npm.pkg.github.com" + cache: "npm" + + - name: Install dependencies + run: npm i -g binaryen + + - name: Install rust + uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable + with: + toolchain: stable + targets: wasm32-unknown-unknown + + - name: Cache cargo registry + uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + with: + key: wasm-cargo-cache + + - name: Install wasm-bindgen-cli + run: cargo install wasm-bindgen-cli + + - name: Build + run: ./build.sh -r + + - name: Upload artifact + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 + with: + name: sdk-internal + path: ${{ github.workspace }}/languages/js/sdk-internal/* + if-no-files-found: error diff --git a/.github/workflows/build-wasm.yml b/.github/workflows/build-wasm.yml index 62be51d79..35c0ca6b6 100644 --- a/.github/workflows/build-wasm.yml +++ b/.github/workflows/build-wasm.yml @@ -22,10 +22,10 @@ jobs: steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Setup Node - uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3 + uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4 with: node-version: 18 registry-url: "https://npm.pkg.github.com" @@ -52,7 +52,7 @@ jobs: run: ./build.sh -r - name: Upload artifact - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: sdk-bitwarden-wasm path: ${{ github.workspace }}/languages/js/wasm/* diff --git a/.github/workflows/cloc.yml b/.github/workflows/cloc.yml index 120aeb511..644dc0bfd 100644 --- a/.github/workflows/cloc.yml +++ b/.github/workflows/cloc.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Set up cloc run: | diff --git a/.github/workflows/direct-minimal-versions.yml b/.github/workflows/direct-minimal-versions.yml index 3cfec8a48..22feb04cf 100644 --- a/.github/workflows/direct-minimal-versions.yml +++ b/.github/workflows/direct-minimal-versions.yml @@ -36,7 +36,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Install rust uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable diff --git a/.github/workflows/generate_schemas.yml b/.github/workflows/generate_schemas.yml index 87f4dd988..434174c7b 100644 --- a/.github/workflows/generate_schemas.yml +++ b/.github/workflows/generate_schemas.yml @@ -19,7 +19,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Install rust uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable @@ -27,7 +27,7 @@ jobs: toolchain: stable - name: Set up Node - uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3 + uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4 with: cache: "npm" cache-dependency-path: "package-lock.json" @@ -43,55 +43,55 @@ jobs: run: npm run schemas - name: Upload ts schemas artifact - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: schemas.ts path: ${{ github.workspace }}/languages/js/sdk-client/src/schemas.ts if-no-files-found: error - name: Upload c# schemas artifact - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: schemas.cs path: ${{ github.workspace }}/languages/csharp/Bitwarden.Sdk/schemas.cs if-no-files-found: error - name: Upload python schemas artifact - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: schemas.py path: ${{ github.workspace }}/languages/python/bitwarden_sdk/schemas.py if-no-files-found: error - name: Upload ruby schemas artifact - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: schemas.rb path: ${{ github.workspace }}/languages/ruby/bitwarden_sdk_secrets/lib/schemas.rb if-no-files-found: error - name: Upload json schemas artifact - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: sdk-schemas-json path: ${{ github.workspace }}/support/schemas/* if-no-files-found: error - name: Upload Go schemas artifact - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: schemas.go path: ${{ github.workspace }}/languages/go/schema.go - name: Upload java schemas artifact - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: sdk-schemas-java path: ${{ github.workspace }}/languages/java/src/main/java/com/bitwarden/sdk/schema/* if-no-files-found: error - name: Upload cpp schemas artifact - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: name: sdk-schemas-cpp path: ${{ github.workspace }}/languages/cpp/include/schemas.hpp diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 761c564cd..a12e263c4 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -17,7 +17,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Install rust uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable @@ -45,12 +45,12 @@ jobs: RUSTFLAGS: "-D warnings" - name: Upload Clippy results to GitHub - uses: github/codeql-action/upload-sarif@2c779ab0d087cd7fe7b826087247c2c81f27bfa6 # v3.26.5 + uses: github/codeql-action/upload-sarif@461ef6c76dfe95d5c364de2f431ddbd31a417628 # v3.26.9 with: sarif_file: clippy_result.sarif - name: Set up Node - uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3 + uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4 with: cache: "npm" cache-dependency-path: "package-lock.json" diff --git a/.github/workflows/memory-testing.yml b/.github/workflows/memory-testing.yml index a9635bc68..41b158536 100644 --- a/.github/workflows/memory-testing.yml +++ b/.github/workflows/memory-testing.yml @@ -22,7 +22,7 @@ jobs: steps: - name: Check out repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Set up gdb run: | diff --git a/.github/workflows/minimum-rust-version.yml b/.github/workflows/minimum-rust-version.yml index 19b81de63..fa95eb0bb 100644 --- a/.github/workflows/minimum-rust-version.yml +++ b/.github/workflows/minimum-rust-version.yml @@ -27,7 +27,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Install rust uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable diff --git a/.github/workflows/release-cli.yml b/.github/workflows/publish-bws.yml similarity index 58% rename from .github/workflows/release-cli.yml rename to .github/workflows/publish-bws.yml index 009dc9359..dc939a5d6 100644 --- a/.github/workflows/release-cli.yml +++ b/.github/workflows/publish-bws.yml @@ -1,6 +1,6 @@ --- -name: Release CLI -run-name: Release CLI ${{ inputs.release_type }} +name: Publish bws CLI +run-name: Publish bws CLI ${{ inputs.release_type }} on: workflow_dispatch: @@ -13,10 +13,11 @@ on: options: - Release - Dry Run - -defaults: - run: - shell: bash + version: + description: "Version to publish (default: latest bws cli release)" + required: true + type: string + default: latest env: _AZ_REGISTRY: bitwardenprod.azurecr.io @@ -26,113 +27,66 @@ jobs: name: Setup runs-on: ubuntu-22.04 outputs: - release-version: ${{ steps.version.outputs.version }} + release-version: ${{ steps.version-output.outputs.version }} + release-tag: ${{ steps.version-output.outputs.tag_name }} + deployment-id: ${{ steps.deployment.outputs.deployment_id }} steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Branch check - if: ${{ github.event.inputs.release_type != 'Dry Run' }} + if: ${{ inputs.release_type != 'Dry Run' }} run: | - if [[ "$GITHUB_REF" != "refs/heads/rc" ]] && [[ "$GITHUB_REF" != "refs/heads/hotfix-rc-cli" ]]; then + if [[ "$GITHUB_REF" != "refs/heads/main" ]]; then echo "===================================" - echo "[!] Can only release from the 'rc' or 'hotfix-rc-cli' branches" + echo "[!] Can only release from the 'main' branch" echo "===================================" exit 1 fi - - name: Check Release Version - id: version + - name: Version output + id: version-output run: | - VERSION=$(grep -o '^version = ".*"' crates/bws/Cargo.toml | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+") - echo "version=$VERSION" >> $GITHUB_OUTPUT + if [[ "${{ inputs.version }}" == "latest" || "${{ inputs.version }}" == "" ]]; then + TAG_NAME=$(curl "https://api.github.com/repos/bitwarden/sdk/releases" | jq -c '.[] | select(.tag_name | contains("bws")) | .tag_name' | head -1) + VERSION=$(echo $TAG_NAME | grep -ohE '20[0-9]{2}\.([1-9]|1[0-2])\.[0-9]+') + echo "Latest Released Version: $VERSION" + echo "version=$VERSION" >> $GITHUB_OUTPUT + + echo "Latest Released Tag name: $TAG_NAME" + echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT + else + echo "Release Version: ${{ inputs.version }}" + echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT + fi - name: Create GitHub deployment - if: ${{ github.event.inputs.release_type != 'Dry Run' }} + if: ${{ inputs.release_type != 'Dry Run' }} uses: chrnorm/deployment-action@55729fcebec3d284f60f5bcabbd8376437d696b1 # v2.0.7 id: deployment with: token: "${{ secrets.GITHUB_TOKEN }}" initial-status: "in_progress" - environment: "CLI - Production" - description: "Deployment ${{ steps.version.outputs.version }} from branch ${{ github.ref_name }}" + environment: "bws CLI - Production" + description: "Deployment ${{ steps.version-output.outputs.version }} from branch ${{ github.ref_name }}" task: release - - name: Download all Release artifacts - if: ${{ github.event.inputs.release_type != 'Dry Run' }} - uses: bitwarden/gh-actions/download-artifacts@main - with: - workflow: build-cli.yml - path: packages - workflow_conclusion: success - branch: ${{ github.ref_name }} - - - name: Dry Run - Download all artifacts - if: ${{ github.event.inputs.release_type == 'Dry Run' }} - uses: bitwarden/gh-actions/download-artifacts@main - with: - workflow: build-cli.yml - path: packages - workflow_conclusion: success - branch: main - - - name: Get checksum files - uses: bitwarden/gh-actions/get-checksum@main - with: - packages_dir: "packages" - file_path: "packages/bws-sha256-checksums-${{ steps.version.outputs.version }}.txt" - - - name: Create release - if: ${{ github.event.inputs.release_type != 'Dry Run' }} - uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # v1.14.0 - env: - PKG_VERSION: ${{ steps.version.outputs.version }} - with: - artifacts: "packages/bws-x86_64-apple-darwin-${{ env.PKG_VERSION }}.zip, - packages/bws-aarch64-apple-darwin-${{ env.PKG_VERSION }}.zip, - packages/bws-macos-universal-${{ env.PKG_VERSION }}.zip, - packages/bws-x86_64-pc-windows-msvc-${{ env.PKG_VERSION }}.zip, - packages/bws-aarch64-pc-windows-msvc-${{ env.PKG_VERSION }}.zip, - packages/bws-x86_64-unknown-linux-gnu-${{ env.PKG_VERSION }}.zip, - packages/bws-aarch64-unknown-linux-gnu-${{ env.PKG_VERSION }}.zip, - packages/THIRDPARTY.html, - packages/bws-sha256-checksums-${{ env.PKG_VERSION }}.txt" - commit: ${{ github.sha }} - tag: bws-v${{ env.PKG_VERSION }} - name: bws CLI v${{ env.PKG_VERSION }} - body: "" - token: ${{ secrets.GITHUB_TOKEN }} - draft: true - - - name: Update deployment status to Success - if: ${{ github.event.inputs.release_type != 'Dry Run' && success() }} - uses: chrnorm/deployment-status@9a72af4586197112e0491ea843682b5dc280d806 # v2.0.3 - with: - token: "${{ secrets.GITHUB_TOKEN }}" - state: "success" - deployment-id: ${{ steps.deployment.outputs.deployment_id }} - - - name: Update deployment status to Failure - if: ${{ github.event.inputs.release_type != 'Dry Run' && failure() }} - uses: chrnorm/deployment-status@9a72af4586197112e0491ea843682b5dc280d806 # v2.0.3 - with: - token: "${{ secrets.GITHUB_TOKEN }}" - state: "failure" - deployment-id: ${{ steps.deployment.outputs.deployment_id }} - publish: name: Publish bws to crates.io runs-on: ubuntu-22.04 - needs: - - setup + needs: setup + env: + _VERSION: ${{ needs.setup.outputs.release-version }} + _TAG_NAME: ${{ needs.setup.outputs.release-tag }} steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Login to Azure uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0 with: creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} + ref: ${{ env._TAG_NAME }} - name: Retrieve secrets id: retrieve-secrets @@ -153,7 +107,7 @@ jobs: run: cargo install cargo-release - name: Cargo release - if: ${{ github.event.inputs.release_type != 'Dry Run' }} + if: ${{ inputs.release_type != 'Dry Run' }} env: PUBLISH_GRACE_SLEEP: 10 CARGO_REGISTRY_TOKEN: ${{ steps.retrieve-secrets.outputs.cratesio-api-token }} @@ -165,7 +119,9 @@ jobs: needs: setup steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 + with: + ref: ${{ env._TAG_NAME }} - name: Generate tag list id: tag-list @@ -216,7 +172,7 @@ jobs: azure-keyvault-name: "bitwarden-ci" - name: Build and push Docker image - uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v6.7.0 + uses: docker/build-push-action@32945a339266b759abcbdc89316275140b0fc960 # v6.8.0 with: context: . file: crates/bws/Dockerfile @@ -229,7 +185,31 @@ jobs: "GH_PAT=${{ steps.retrieve-secret-pat.outputs.github-pat-bitwarden-devops-bot-repo-scope }}" - name: Log out of Docker and disable Docker Notary - if: ${{ github.event.inputs.release_type != 'Dry Run' }} + if: ${{ inputs.release_type != 'Dry Run' }} run: | docker logout echo "DOCKER_CONTENT_TRUST=0" >> $GITHUB_ENV + + update_release_status: + name: Update GitHub deployment status + runs-on: ubuntu-22.04 + needs: setup + if: ${{ inputs.release_type != 'Dry Run' }} + env: + _DEPLOYMENT_ID: ${{ needs.setup.outputs.deployment-id }} + steps: + - name: Update deployment status to Success + if: ${{ inputs.release_type != 'Dry Run' && success() }} + uses: chrnorm/deployment-status@9a72af4586197112e0491ea843682b5dc280d806 # v2.0.3 + with: + token: "${{ secrets.GITHUB_TOKEN }}" + state: "success" + deployment-id: ${{ env._DEPLOYMENT_ID }} + + - name: Update deployment status to Failure + if: ${{ inputs.release_type != 'Dry Run' && failure() }} + uses: chrnorm/deployment-status@9a72af4586197112e0491ea843682b5dc280d806 # v2.0.3 + with: + token: "${{ secrets.GITHUB_TOKEN }}" + state: "failure" + deployment-id: ${{ env._DEPLOYMENT_ID }} diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 1c4cf5840..1e2fc06f4 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -12,6 +12,10 @@ on: options: - Release - Dry Run + version: + description: "Release Version" + required: false + default: "latest" env: _KEY_VAULT: "bitwarden-ci" @@ -21,43 +25,58 @@ jobs: name: Setup runs-on: ubuntu-22.04 outputs: - version: ${{ steps.version.outputs.version }} + version: ${{ steps.version-output.outputs.version }} steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - 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 - - name: Install xmllint - run: sudo apt-get install -y libxml2-utils - - - name: Get version - id: version + - name: Version output + id: version-output run: | - VERSION=$(xmllint --xpath 'string(/Project/PropertyGroup/Version)' languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj) - echo "version=$VERSION" >> $GITHUB_OUTPUT + if [[ "${{ inputs.version }}" == "latest" || "${{ inputs.version }}" == "" ]]; then + TAG_NAME=$(curl "https://api.github.com/repos/bitwarden/sdk/releases" | jq -c '.[] | select(.tag_name | contains("dotnet")) | .tag_name' | head -1) + VERSION=$(echo $TAG_NAME | grep -ohE '20[0-9]{2}\.([1-9]|1[0-2])\.[0-9]+') + echo "Latest Released Version: $VERSION" + echo "version=$VERSION" >> $GITHUB_OUTPUT + + echo "Latest Released Tag name: $TAG_NAME" + echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT + else + echo "Release Version: ${{ inputs.version }}" + echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT + fi deploy: name: Deploy runs-on: ubuntu-22.04 needs: validate steps: - - name: Download NuGet package - uses: bitwarden/gh-actions/download-artifacts@main + - name: Create GitHub deployment + if: ${{ inputs.release_type != 'Dry Run' }} + uses: chrnorm/deployment-action@55729fcebec3d284f60f5bcabbd8376437d696b1 # v2.0.7 + id: deployment with: - workflow: build-dotnet.yml - workflow_conclusion: success - branch: ${{ inputs.release_type == 'Dry Run' && 'main' || github.ref_name }} - artifacts: Bitwarden.Sdk.${{ needs.validate.outputs.version }}.nupkg - path: ./nuget-output + token: "${{ secrets.GITHUB_TOKEN }}" + initial-status: "in_progress" + environment: "dotnet - Production" + description: "Deployment ${{ needs.validate.outputs.version }} from branch ${{ github.ref_name }}" + task: release + + - name: Download artifact + run: | + mkdir -p nuget-output + cd nuget-output + wget https://github.com/bitwarden/sdk/releases/download/dotnet-v${{ needs.validate.outputs.version }}/Bitwarden.Sdk.${{ needs.validate.outputs.version }}.nupkg - name: Login to Azure - Prod Subscription uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0 @@ -76,3 +95,19 @@ jobs: env: NUGET_API_KEY: ${{ steps.retrieve-secrets.outputs.nuget-api-key }} run: dotnet nuget push ./nuget-output/*.nupkg -k ${{ env.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json + + - name: Update deployment status to Success + if: ${{ inputs.release_type != 'Dry Run' && success() }} + uses: chrnorm/deployment-status@9a72af4586197112e0491ea843682b5dc280d806 # v2.0.3 + with: + token: "${{ secrets.GITHUB_TOKEN }}" + state: "success" + deployment-id: ${{ steps.deployment.outputs.deployment_id }} + + - name: Update deployment status to Failure + if: ${{ inputs.release_type != 'Dry Run' && failure() }} + uses: chrnorm/deployment-status@9a72af4586197112e0491ea843682b5dc280d806 # v2.0.3 + with: + token: "${{ secrets.GITHUB_TOKEN }}" + state: "failure" + deployment-id: ${{ steps.deployment.outputs.deployment_id }} diff --git a/.github/workflows/publish-internal.yml b/.github/workflows/publish-internal.yml new file mode 100644 index 000000000..13f3a9d97 --- /dev/null +++ b/.github/workflows/publish-internal.yml @@ -0,0 +1,94 @@ +--- +name: Publish @bitwarden/sdk-internal +run-name: Publish @bitwarden/sdk-internal ${{ inputs.release_type }} + +on: + workflow_dispatch: + inputs: + release_type: + description: "Release Options" + required: true + default: "Release" + type: choice + options: + - Release + - Dry Run + version: + description: "Release Version" + required: true + +defaults: + run: + working-directory: languages/js/sdk-internal + +jobs: + setup: + name: Setup + runs-on: ubuntu-22.04 + steps: + - name: Checkout repo + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Branch check + if: ${{ inputs.release_type != 'Dry Run' }} + run: | + if [[ "$GITHUB_REF" != "refs/heads/main" ]]; then + echo "===================================" + echo "[!] Can only release from the 'main' branch" + echo "===================================" + exit 1 + fi + + npm: + name: Publish NPM + runs-on: ubuntu-22.04 + needs: setup + steps: + - name: Checkout repo + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Setup Node + uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3 + with: + node-version: 20 + + - name: Login to Azure + uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0 + with: + creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} + + - name: Retrieve secrets + id: retrieve-secrets + uses: bitwarden/gh-actions/get-keyvault-secrets@main + with: + keyvault: "bitwarden-ci" + secrets: "npm-api-key" + + - name: Download artifact + uses: bitwarden/gh-actions/download-artifacts@main + with: + workflow: build-wasm-internal.yml + workflow_conclusion: success + branch: ${{ inputs.release_type == 'Dry Run' && 'main' || github.ref_name }} + artifacts: sdk-internal + path: languages/js/sdk-internal + + - name: Set version + run: | + npm version --no-git-tag-version ${{ inputs.version }} + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup NPM + run: | + echo 'registry="https://registry.npmjs.org/"' > ./.npmrc + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ./.npmrc + + echo 'registry="https://registry.npmjs.org/"' > ~/.npmrc + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc + env: + NPM_TOKEN: ${{ steps.retrieve-secrets.outputs.npm-api-key }} + + - name: Publish NPM + if: ${{ inputs.release_type != 'Dry Run' }} + run: npm publish --access public --registry=https://registry.npmjs.org/ --userconfig=./.npmrc diff --git a/.github/workflows/publish-java.yml b/.github/workflows/publish-java.yml index c50080728..002a61ee4 100644 --- a/.github/workflows/publish-java.yml +++ b/.github/workflows/publish-java.yml @@ -1,3 +1,4 @@ +--- name: Publish Java SDK run-name: Publish Java SDK ${{ inputs.release_type }} @@ -12,6 +13,15 @@ on: options: - Release - Dry Run + version: + description: "Release Version" + required: false + default: "latest" + +defaults: + run: + shell: bash + working-directory: languages/java env: _KEY_VAULT: "bitwarden-ci" @@ -21,26 +31,37 @@ jobs: name: Setup runs-on: ubuntu-22.04 outputs: - version: ${{ steps.version.outputs.version }} + version: ${{ steps.version-output.outputs.version }} + tag_name: ${{ steps.version-output.outputs.tag_name }} steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - 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 - - name: Get version - id: version + - name: Version output + id: version-output run: | - VERSION=$(cat languages/java/build.gradle | grep -Eo 'version = "[0-9]+\.[0-9]+\.[0-9]+"' | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') - echo "version=$VERSION" >> $GITHUB_OUTPUT + if [[ "${{ inputs.version }}" == "latest" || "${{ inputs.version }}" == "" ]]; then + TAG_NAME=$(curl "https://api.github.com/repos/bitwarden/sdk/releases" | jq -c '.[] | select(.tag_name | contains("java")) | .tag_name' | head -1) + VERSION=$(echo $TAG_NAME | grep -ohE '20[0-9]{2}\.([1-9]|1[0-2])\.[0-9]+') + echo "Latest Released Version: $VERSION" + echo "version=$VERSION" >> $GITHUB_OUTPUT + + echo "Latest Released Tag name: $TAG_NAME" + echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT + else + echo "Release Version: ${{ inputs.version }}" + echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT + fi publish: name: Publish @@ -48,7 +69,9 @@ jobs: needs: validate steps: - name: Checkout Repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 + with: + ref: ${{ needs.validate.outputs.tag_name }} - name: Azure login uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0 @@ -64,13 +87,37 @@ jobs: maven-sonartype-ossrh-password" - name: Setup java - uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4.2.2 + uses: actions/setup-java@b36c23c0d998641eff861008f374ee103c25ac73 # v4.4.0 with: distribution: temurin java-version: 17 - name: Setup Gradle - uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 + uses: gradle/actions/setup-gradle@d156388eb19639ec20ade50009f3d199ce1e2808 # v4.1.0 + + - name: Download Java SDK Build + uses: bitwarden/gh-actions/download-artifacts@main + with: + workflow: build-java.yml + workflow_conclusion: success + artifacts: build + path: languages/java/build + + - name: Download Java Resources + uses: bitwarden/gh-actions/download-artifacts@main + with: + workflow: build-java.yml + workflow_conclusion: success + artifacts: resources + path: languages/java/src/main/resources + + - name: Download Java Resources + uses: bitwarden/gh-actions/download-artifacts@main + with: + workflow: build-java.yml + workflow_conclusion: success + artifacts: schemas + path: languages/java/src/main/java/bit/sdk/schema - name: Publish package to GitHub Packages if: ${{ inputs.release_type != 'Dry Run' }} diff --git a/.github/workflows/publish-napi.yml b/.github/workflows/publish-napi.yml new file mode 100644 index 000000000..6a284d4a4 --- /dev/null +++ b/.github/workflows/publish-napi.yml @@ -0,0 +1,155 @@ +--- +name: Publish @bitwarden/sdk-napi +run-name: Publish @bitwarden/sdk-napi ${{ inputs.release_type }} + +on: + workflow_dispatch: + inputs: + release_type: + description: "Release Options" + required: true + default: "Release" + type: choice + options: + - Release + - Dry Run + version: + description: "Release Version" + required: false + default: "latest" + +defaults: + run: + working-directory: crates/bitwarden-napi + +jobs: + setup: + name: Setup + runs-on: ubuntu-22.04 + outputs: + release-version: ${{ steps.version-output.outputs.version }} + tag-name: ${{ steps.version-output.outputs.tag_name }} + steps: + - name: Checkout repo + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Branch check + if: ${{ inputs.release_type != 'Dry Run' }} + run: | + if [[ "$GITHUB_REF" != "refs/heads/main" ]]; then + echo "===================================" + echo "[!] Can only release from the 'main' branch" + echo "===================================" + exit 1 + fi + + - name: Version output + id: version-output + run: | + if [[ "${{ inputs.version }}" == "latest" || "${{ inputs.version }}" == "" ]]; then + TAG_NAME=$(curl "https://api.github.com/repos/bitwarden/sdk/releases" | jq -c '.[] | select(.tag_name | contains("napi")) | .tag_name' | head -1) + VERSION=$(echo $TAG_NAME | grep -ohE '20[0-9]{2}\.([1-9]|1[0-2])\.[0-9]+') + echo "Latest Released Version: $VERSION" + echo "version=$VERSION" >> $GITHUB_OUTPUT + + echo "Latest Released Tag name: $TAG_NAME" + echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT + else + echo "Release Version: ${{ inputs.version }}" + echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT + fi + + npm: + name: Publish NPM + runs-on: ubuntu-22.04 + needs: setup + env: + _PKG_VERSION: ${{ needs.setup.outputs.release-version }} + _TAG_NAME: ${{ needs.setup.outputs.tag-name }} + steps: + - name: Checkout repo + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + with: + ref: ${{ env._TAG_NAME }} + + - name: Create GitHub deployment + if: ${{ inputs.release_type != 'Dry Run' }} + uses: chrnorm/deployment-action@55729fcebec3d284f60f5bcabbd8376437d696b1 # v2.0.7 + id: deployment + with: + token: "${{ secrets.GITHUB_TOKEN }}" + initial-status: "in_progress" + environment: "Bitwarden SDK NAPI - Production" + description: "Deployment ${{ env._PKG_VERSION }} from branch ${{ github.ref_name }}" + task: release + + - name: Setup Node + uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3 + with: + node-version: 18 + cache: "npm" + cache-dependency-path: crates/bitwarden-napi/package-lock.json + + - name: Download schemas.ts artifact + run: | + wget https://github.com/bitwarden/sdk/releases/download/napi-v${{ env._PKG_VERSION }}/schemas.ts + mv schemas.ts ${{ github.workspace }}/crates/bitwarden-napi/src-ts/bitwarden_client/schemas.ts + + - name: Install dependencies + run: npm ci + + - name: Run tsc + run: npm run tsc + + - name: Login to Azure + uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0 + with: + creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} + + - name: Retrieve secrets + id: retrieve-secrets + uses: bitwarden/gh-actions/get-keyvault-secrets@main + with: + keyvault: "bitwarden-ci" + secrets: "npm-api-key" + + - name: Download sdk-napi artifacts + run: | + wget https://github.com/bitwarden/sdk/releases/download/napi-v${{ env._PKG_VERSION }}/sdk-napi.darwin-arm64.node + wget https://github.com/bitwarden/sdk/releases/download/napi-v${{ env._PKG_VERSION }}/sdk-napi.darwin-x64.node + wget https://github.com/bitwarden/sdk/releases/download/napi-v${{ env._PKG_VERSION }}/sdk-napi.win32-x64-msvc.node + wget https://github.com/bitwarden/sdk/releases/download/napi-v${{ env._PKG_VERSION }}/sdk-napi.linux-x64-gnu.node + mv sdk-napi.*.node ${{ github.workspace }}/crates/bitwarden-napi/artifacts + + - name: Move artifacts + run: npm run artifacts + + - name: Setup NPM + run: | + echo 'registry="https://registry.npmjs.org/"' > ./.npmrc + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ./.npmrc + + echo 'registry="https://registry.npmjs.org/"' > ~/.npmrc + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc + env: + NPM_TOKEN: ${{ steps.retrieve-secrets.outputs.npm-api-key }} + + - name: Publish NPM + if: ${{ inputs.release_type != 'Dry Run' }} + run: npm publish --access public --registry=https://registry.npmjs.org/ --userconfig=./.npmrc + + - name: Update deployment status to Success + if: ${{ inputs.release_type != 'Dry Run' && success() }} + uses: chrnorm/deployment-status@9a72af4586197112e0491ea843682b5dc280d806 # v2.0.3 + with: + token: "${{ secrets.GITHUB_TOKEN }}" + state: "success" + deployment-id: ${{ steps.deployment.outputs.deployment_id }} + + - name: Update deployment status to Failure + if: ${{ inputs.release_type != 'Dry Run' && failure() }} + uses: chrnorm/deployment-status@9a72af4586197112e0491ea843682b5dc280d806 # v2.0.3 + with: + token: "${{ secrets.GITHUB_TOKEN }}" + state: "failure" + deployment-id: ${{ steps.deployment.outputs.deployment_id }} diff --git a/.github/workflows/publish-php.yml b/.github/workflows/publish-php.yml index 0cf7c59b0..986923ab5 100644 --- a/.github/workflows/publish-php.yml +++ b/.github/workflows/publish-php.yml @@ -1,3 +1,4 @@ +--- name: Publish PHP SDK run-name: Publish PHP SDK ${{ inputs.release_type }} @@ -24,14 +25,14 @@ jobs: version: ${{ steps.version.outputs.version }} steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - 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 @@ -47,7 +48,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout Repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Setup PHP with PECL extension uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231 # 2.31.1 @@ -75,7 +76,7 @@ jobs: _PKG_VERSION: ${{ needs.validate.outputs.version }} steps: - name: Checkout SDK repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: path: sdk @@ -92,7 +93,7 @@ jobs: secrets: "github-pat-bitwarden-devops-bot-repo-scope" - name: Checkout SDK-PHP repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: repository: bitwarden/sm-sdk-php path: sm-sdk-php @@ -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 "===================================" @@ -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: | @@ -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 @@ -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 @@ -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 @@ -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 @@ -254,7 +255,7 @@ jobs: packagist-key" - name: Checkout SDK-PHP repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: repository: bitwarden/sm-sdk-php path: sm-sdk-php diff --git a/.github/workflows/publish-python.yml b/.github/workflows/publish-python.yml index 343fadd8a..7e3395093 100644 --- a/.github/workflows/publish-python.yml +++ b/.github/workflows/publish-python.yml @@ -13,6 +13,10 @@ on: options: - Release - Dry Run + version: + description: "Release Version" + required: false + default: "latest" defaults: run: @@ -22,42 +26,71 @@ jobs: setup: name: Setup runs-on: ubuntu-22.04 + outputs: + version: ${{ steps.version-output.outputs.version }} + tag_name: ${{ steps.version-output.outputs.tag_name }} steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Branch check - if: ${{ github.event.inputs.release_type != 'Dry Run' }} + 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 + - name: Version output + id: version-output + run: | + if [[ "${{ inputs.version }}" == "latest" || "${{ inputs.version }}" == "" ]]; then + TAG_NAME=$(curl "https://api.github.com/repos/bitwarden/sdk/releases" | jq -c '.[] | select(.tag_name | contains("python")) | .tag_name' | head -1) + VERSION=$(echo $TAG_NAME | grep -ohE '20[0-9]{2}\.([1-9]|1[0-2])\.[0-9]+') + echo "Latest Released Version: $VERSION" + echo "version=$VERSION" >> $GITHUB_OUTPUT + + echo "Latest Released Tag name: $TAG_NAME" + echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT + else + echo "Release Version: ${{ inputs.version }}" + echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT + fi + publish: name: Publish runs-on: ubuntu-22.04 needs: setup steps: + - name: Checkout repo + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + with: + ref: ${{ needs.setup.outputs.tag_name }} + - name: Install Python - uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1 + uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0 with: python-version: "3.9" - name: Install twine run: pip install twine - - name: Download artifacts - uses: bitwarden/gh-actions/download-artifacts@main - with: - workflow: build-python-wheels.yml - path: ${{ github.workspace }}/target/wheels/dist - workflow_conclusion: success - branch: ${{ github.event.inputs.release_type == 'Dry Run' && 'main' || github.ref_name }} - name: bitwarden_sdk(.*) - name_is_regexp: true + - name: Get release assets + working-directory: ${{ github.workspace }}/target/wheels/dist + run: | + ARTIFACT_URLS=$(curl -sSL https://api.github.com/repos/bitwarden/sdk/releases/tags/${{ needs.setup.outputs.tag_name }} | jq -r '.assets[].browser_download_url') + for url in $ARTIFACT_URLS; do + wget $url + done + + - name: Unpack release assets + working-directory: ${{ github.workspace }}/target/wheels/dist + run: | + for file in *.zip; do + unzip $file + done - name: Move files working-directory: ${{ github.workspace }}/target/wheels/dist @@ -83,7 +116,7 @@ jobs: run: twine check dist/* - name: Publish - if: ${{ github.event.inputs.release_type != 'Dry Run' }} + if: ${{ inputs.release_type != 'Dry Run' }} working-directory: ${{ github.workspace }}/target/wheels env: TWINE_USERNAME: __token__ @@ -91,7 +124,7 @@ jobs: run: twine upload --repository pypi dist/* - name: Dry Run - Publish - if: ${{ github.event.inputs.release_type == 'Dry Run' }} + if: ${{ inputs.release_type == 'Dry Run' }} working-directory: ${{ github.workspace }}/target/wheels env: TWINE_USERNAME: __token__ diff --git a/.github/workflows/publish-ruby.yml b/.github/workflows/publish-ruby.yml index 6dd3e4064..875def064 100644 --- a/.github/workflows/publish-ruby.yml +++ b/.github/workflows/publish-ruby.yml @@ -12,6 +12,10 @@ on: options: - Release - Dry Run + version: + description: "Release Version" + required: false + default: "latest" permissions: contents: read @@ -21,91 +25,62 @@ jobs: setup: name: Setup runs-on: ubuntu-22.04 + outputs: + release-version: ${{ steps.version-output.outputs.version }} + tag-name: ${{ steps.version-output.outputs.tag_name }} steps: - - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - name: Checkout Repository + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Branch check - if: ${{ github.event.inputs.release_type != 'Dry Run' }} + 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 - publish_ruby: - name: Publish Ruby + - name: Version output + id: version-output + run: | + if [[ "${{ inputs.version }}" == "latest" || "${{ inputs.version }}" == "" ]]; then + TAG_NAME=$(curl "https://api.github.com/repos/bitwarden/sdk/releases" | jq -c '.[] | select(.tag_name | contains("ruby")) | .tag_name' | head -1) + VERSION=$(echo $TAG_NAME | grep -ohE '20[0-9]{2}\.([1-9]|1[0-2])\.[0-9]+') + echo "Latest Released Version: $VERSION" + echo "version=$VERSION" >> $GITHUB_OUTPUT + + echo "Latest Released Tag name: $TAG_NAME" + echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT + else + echo "Release Version: ${{ inputs.version }}" + echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT + fi + + publish: + name: Publish runs-on: ubuntu-22.04 needs: setup + env: + _VERSION: ${{ needs.setup.outputs.release-version }} + _TAG_NAME: ${{ needs.setup.outputs.tag-name }} steps: - name: Checkout Repository uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - - - name: Set up Ruby - uses: ruby/setup-ruby@a6e6f86333f0a2523ece813039b8b4be04560854 # v1.190.0 with: - ruby-version: 3.2 + ref: ${{ env._TAG_NAME }} - - name: Download artifacts - uses: bitwarden/gh-actions/download-artifacts@main + - name: Create GitHub deployment + if: ${{ inputs.release_type != 'Dry Run' }} + uses: chrnorm/deployment-action@55729fcebec3d284f60f5bcabbd8376437d696b1 # v2.0.7 + id: deployment with: - workflow: generate_schemas.yml - path: languages/ruby/bitwarden_sdk_secrets/lib - workflow_conclusion: success - branch: ${{ github.event.inputs.release_type == 'Dry Run' && 'main' || github.ref_name }} - artifacts: schemas.rb - - - name: Download x86_64-apple-darwin artifact - uses: bitwarden/gh-actions/download-artifacts@main - with: - workflow: build-rust-cross-platform.yml - path: temp/macos-x64 - workflow_conclusion: success - branch: ${{ github.event.inputs.release_type == 'Dry Run' && 'main' || github.ref_name }} - artifacts: libbitwarden_c_files-x86_64-apple-darwin - - - name: Download aarch64-apple-darwin artifact - uses: bitwarden/gh-actions/download-artifacts@main - with: - workflow: build-rust-cross-platform.yml - workflow_conclusion: success - branch: ${{ github.event.inputs.release_type == 'Dry Run' && 'main' || github.ref_name }} - artifacts: libbitwarden_c_files-aarch64-apple-darwin - path: temp/macos-arm64 - - - name: Download x86_64-unknown-linux-gnu artifact - uses: bitwarden/gh-actions/download-artifacts@main - with: - workflow: build-rust-cross-platform.yml - workflow_conclusion: success - branch: ${{ github.event.inputs.release_type == 'Dry Run' && 'main' || github.ref_name }} - artifacts: libbitwarden_c_files-x86_64-unknown-linux-gnu - path: temp/linux-x64 - - - name: Download x86_64-pc-windows-msvc artifact - uses: bitwarden/gh-actions/download-artifacts@main - with: - workflow: build-rust-cross-platform.yml - workflow_conclusion: success - branch: ${{ github.event.inputs.release_type == 'Dry Run' && 'main' || github.ref_name }} - artifacts: libbitwarden_c_files-x86_64-pc-windows-msvc - path: temp/windows-x64 - - - name: Copy lib files - run: | - mkdir -p languages/ruby/bitwarden_sdk_secrets/lib/macos-arm64 - mkdir -p languages/ruby/bitwarden_sdk_secrets/lib/linux-x64 - mkdir -p languages/ruby/bitwarden_sdk_secrets/lib/macos-x64 - mkdir -p languages/ruby/bitwarden_sdk_secrets/lib/windows-x64 - - platforms=("macos-arm64" "linux-x64" "macos-x64" "windows-x64") - files=("libbitwarden_c.dylib" "libbitwarden_c.so" "libbitwarden_c.dylib" "bitwarden_c.dll") - - for ((i=0; i<${#platforms[@]}; i++)); do - cp "temp/${platforms[$i]}/${files[$i]}" "languages/ruby/bitwarden_sdk_secrets/lib/${platforms[$i]}/${files[$i]}" - done + token: "${{ secrets.GITHUB_TOKEN }}" + initial-status: "in_progress" + environment: "Bitwarden Ruby SDK - Production" + description: "Deployment ${{ env._VERSION }} from branch ${{ github.ref_name }}" + task: release - name: Login to Azure uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0 @@ -119,15 +94,11 @@ jobs: keyvault: "bitwarden-ci" secrets: "rubygem-api-key" - - name: bundle install - run: bundle install - working-directory: languages/ruby/bitwarden_sdk_secrets - - - name: Build gem - run: gem build bitwarden-sdk-secrets.gemspec - working-directory: languages/ruby/bitwarden_sdk_secrets + - name: Download ruby artifact + run: wget https://github.com/bitwarden/sdk/releases/download/ruby-v${{ env._VERSION }}/bitwarden-sdk-secrets-${{ env._VERSION }}.gem - name: Push gem to Rubygems + if: ${{ inputs.release_type != 'Dry Run' }} run: | mkdir -p $HOME/.gem touch $HOME/.gem/credentials @@ -137,3 +108,19 @@ jobs: env: GEM_HOST_API_KEY: ${{ steps.retrieve-secrets.outputs.rubygem-api-key }} working-directory: languages/ruby/bitwarden_sdk_secrets + + - name: Update deployment status to Success + if: ${{ inputs.release_type != 'Dry Run' && success() }} + uses: chrnorm/deployment-status@9a72af4586197112e0491ea843682b5dc280d806 # v2.0.3 + with: + token: "${{ secrets.GITHUB_TOKEN }}" + state: "success" + deployment-id: ${{ steps.deployment.outputs.deployment_id }} + + - name: Update deployment status to Failure + if: ${{ inputs.release_type != 'Dry Run' && failure() }} + uses: chrnorm/deployment-status@9a72af4586197112e0491ea843682b5dc280d806 # v2.0.3 + with: + token: "${{ secrets.GITHUB_TOKEN }}" + state: "failure" + deployment-id: ${{ steps.deployment.outputs.deployment_id }} diff --git a/.github/workflows/publish-rust-crates.yml b/.github/workflows/publish-rust-crates.yml index 3931e9e2a..bb79aad24 100644 --- a/.github/workflows/publish-rust-crates.yml +++ b/.github/workflows/publish-rust-crates.yml @@ -14,37 +14,58 @@ on: - Initial Release - Redeploy - Dry Run - -defaults: - run: - shell: bash + version: + description: "Version to publish (default: latest rust crates release)" + required: true + type: string + default: latest jobs: setup: - name: Setup + name: setup runs-on: ubuntu-22.04 + outputs: + release-version: ${{ steps.version-output.outputs.version }} + release-tag: ${{ steps.version-output.outputs.tag_name }} steps: - - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - name: Checkout + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Branch check - if: ${{ github.event.inputs.release_type != 'Dry Run' }} + 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 + - name: Version output + id: version-output + run: | + if [[ "${{ inputs.version }}" == "latest" || "${{ inputs.version }}" == "" ]]; then + TAG_NAME=$(curl "https://api.github.com/repos/bitwarden/sdk/releases" | jq -c '.[] | select(.tag_name | contains("rust")) | .tag_name' | head -1) + VERSION=$(echo $TAG_NAME | grep -ohE '20[0-9]{2}\.([1-9]|1[0-2])\.[0-9]+') + echo "Latest Released Version: $VERSION" + echo "version=$VERSION" >> $GITHUB_OUTPUT + + echo "Latest Released Tag name: $TAG_NAME" + echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT + else + echo "Release Version: ${{ inputs.version }}" + echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT + fi + publish: name: Publish - runs-on: ubuntu-latest - needs: - - setup + runs-on: ubuntu-22.04 + needs: setup steps: - name: Checkout uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + with: + ref: ${{ needs.setup.outputs.release-tag }} - name: Login to Azure uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0 @@ -70,7 +91,7 @@ jobs: run: cargo install cargo-release - name: Create GitHub deployment - if: ${{ github.event.inputs.release_type != 'Dry Run' }} + if: ${{ inputs.release_type != 'Dry Run' }} uses: chrnorm/deployment-action@55729fcebec3d284f60f5bcabbd8376437d696b1 # v2.0.7 id: deployment with: @@ -81,14 +102,14 @@ jobs: task: release - name: Cargo release - if: ${{ github.event.inputs.release_type != 'Dry Run' }} + if: ${{ inputs.release_type != 'Dry Run' }} env: PUBLISH_GRACE_SLEEP: 10 CARGO_REGISTRY_TOKEN: ${{ steps.retrieve-secrets.outputs.cratesio-api-token }} run: cargo-release release publish --exclude bw --exclude bws --execute --no-confirm - name: Update deployment status to Success - if: ${{ github.event.inputs.release_type != 'Dry Run' && success() }} + if: ${{ inputs.release_type != 'Dry Run' && success() }} uses: chrnorm/deployment-status@9a72af4586197112e0491ea843682b5dc280d806 # v2.0.3 with: token: "${{ secrets.GITHUB_TOKEN }}" @@ -96,7 +117,7 @@ jobs: deployment-id: ${{ steps.deployment.outputs.deployment_id }} - name: Update deployment status to Failure - if: ${{ github.event.inputs.release_type != 'Dry Run' && failure() }} + if: ${{ inputs.release_type != 'Dry Run' && failure() }} uses: chrnorm/deployment-status@9a72af4586197112e0491ea843682b5dc280d806 # v2.0.3 with: token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/publish-wasm.yml b/.github/workflows/publish-wasm.yml new file mode 100644 index 000000000..95a86a0c4 --- /dev/null +++ b/.github/workflows/publish-wasm.yml @@ -0,0 +1,138 @@ +--- +name: Publish @bitwarden/sdk-wasm +run-name: Publish @bitwarden/sdk-wasm ${{ inputs.release_type }} + +on: + workflow_dispatch: + inputs: + release_type: + description: "Release Options" + required: true + default: "Release" + type: choice + options: + - Release + - Dry Run + version: + description: "Release Version" + required: false + default: "latest" + +defaults: + run: + working-directory: languages/js/wasm + +jobs: + setup: + name: Setup + runs-on: ubuntu-22.04 + outputs: + release-version: ${{ steps.version-output.outputs.version }} + tag_name: ${{ steps.version-output.outputs.tag_name }} + steps: + - name: Checkout repo + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Branch check + if: ${{ inputs.release_type != 'Dry Run' }} + run: | + if [[ "$GITHUB_REF" != "refs/heads/main" ]]; then + echo "===================================" + echo "[!] Can only release from the 'main' branch" + echo "===================================" + exit 1 + fi + + - name: Version output + id: version-output + run: | + if [[ "${{ inputs.version }}" == "latest" || "${{ inputs.version }}" == "" ]]; then + TAG_NAME=$(curl "https://api.github.com/repos/bitwarden/sdk/releases" | jq -c '.[] | select(.tag_name | contains("napi")) | .tag_name' | head -1) + VERSION=$(echo $TAG_NAME | grep -ohE '20[0-9]{2}\.([1-9]|1[0-2])\.[0-9]+') + echo "Latest Released Version: $VERSION" + echo "version=$VERSION" >> $GITHUB_OUTPUT + + echo "Latest Released Tag name: $TAG_NAME" + echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT + else + echo "Release Version: ${{ inputs.version }}" + echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT + fi + + npm: + name: Publish NPM + runs-on: ubuntu-22.04 + needs: setup + env: + _VERSION: ${{ needs.setup.outputs.release-version }} + steps: + - name: Checkout repo + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + with: + ref: ${{ needs.setup.outputs.tag_name }} + + - name: Setup Node + uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3 + with: + node-version: 18 + cache: "npm" + + - name: Login to Azure + uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0 + with: + creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} + + - name: Retrieve secrets + id: retrieve-secrets + uses: bitwarden/gh-actions/get-keyvault-secrets@main + with: + keyvault: "bitwarden-ci" + secrets: "npm-api-key" + + - name: Download artifact + run: | + cd ${{ github.workspace }}/languages/js/wasm + wget https://github.com/bitwarden/sdk/releases/download/wasm-v${{ env._VERSION }}/sdk-bitwarden-wasm.zip + unzip sdk-bitwarden-wasm.zip + rm sdk-bitwarden-wasm.zip + + - name: Create GitHub deployment + if: ${{ inputs.release_type != 'Dry Run' }} + uses: chrnorm/deployment-action@55729fcebec3d284f60f5bcabbd8376437d696b1 # v2.0.7 + id: deployment + with: + token: "${{ secrets.GITHUB_TOKEN }}" + initial-status: "in_progress" + environment: "Bitwarden SDK WASM - Production" + description: "Deployment ${{ env._VERSION }} from branch ${{ github.ref_name }}" + task: release + + - name: Setup NPM + run: | + echo 'registry="https://registry.npmjs.org/"' > ./.npmrc + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ./.npmrc + + echo 'registry="https://registry.npmjs.org/"' > ~/.npmrc + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc + env: + NPM_TOKEN: ${{ steps.retrieve-secrets.outputs.npm-api-key }} + + - name: Publish NPM + if: ${{ inputs.release_type != 'Dry Run' }} + run: npm publish --access public --registry=https://registry.npmjs.org/ --userconfig=./.npmrc + + - name: Update deployment status to Success + if: ${{ inputs.release_type != 'Dry Run' && success() }} + uses: chrnorm/deployment-status@9a72af4586197112e0491ea843682b5dc280d806 # v2.0.3 + with: + token: "${{ secrets.GITHUB_TOKEN }}" + state: "success" + deployment-id: ${{ steps.deployment.outputs.deployment_id }} + + - name: Update deployment status to Failure + if: ${{ inputs.release_type != 'Dry Run' && failure() }} + uses: chrnorm/deployment-status@9a72af4586197112e0491ea843682b5dc280d806 # v2.0.3 + with: + token: "${{ secrets.GITHUB_TOKEN }}" + state: "failure" + deployment-id: ${{ steps.deployment.outputs.deployment_id }} diff --git a/.github/workflows/release-bws.yml b/.github/workflows/release-bws.yml new file mode 100644 index 000000000..92a8544b8 --- /dev/null +++ b/.github/workflows/release-bws.yml @@ -0,0 +1,77 @@ +--- +name: Release bws CLI +run-name: Release bws CLI ${{ inputs.release_type }} + +on: + workflow_dispatch: + inputs: + release_type: + description: "Release Options" + required: true + default: "Release" + type: choice + options: + - Release + - Dry Run + +jobs: + setup: + name: Setup + runs-on: ubuntu-22.04 + outputs: + release-version: ${{ steps.version.outputs.version }} + steps: + - name: Checkout repo + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Branch check + if: ${{ inputs.release_type != 'Dry Run' }} + run: | + if [[ "$GITHUB_REF" != "refs/heads/main" ]]; then + echo "===================================" + echo "[!] Can only release from the 'main' branch" + echo "===================================" + exit 1 + fi + + - name: Check Release Version + id: version + run: | + VERSION=$(grep -o '^version = ".*"' crates/bws/Cargo.toml | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+") + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Download all Release artifacts + uses: bitwarden/gh-actions/download-artifacts@main + with: + workflow: build-cli.yml + path: packages + workflow_conclusion: success + branch: ${{ github.ref_name }} + + - name: Get checksum files + uses: bitwarden/gh-actions/get-checksum@main + with: + packages_dir: "packages" + file_path: "packages/bws-sha256-checksums-${{ steps.version.outputs.version }}.txt" + + - name: Create release + if: ${{ inputs.release_type != 'Dry Run' }} + uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # v1.14.0 + env: + PKG_VERSION: ${{ steps.version.outputs.version }} + with: + artifacts: "packages/bws-x86_64-apple-darwin-${{ env.PKG_VERSION }}.zip, + packages/bws-aarch64-apple-darwin-${{ env.PKG_VERSION }}.zip, + packages/bws-macos-universal-${{ env.PKG_VERSION }}.zip, + packages/bws-x86_64-pc-windows-msvc-${{ env.PKG_VERSION }}.zip, + packages/bws-aarch64-pc-windows-msvc-${{ env.PKG_VERSION }}.zip, + packages/bws-x86_64-unknown-linux-gnu-${{ env.PKG_VERSION }}.zip, + packages/bws-aarch64-unknown-linux-gnu-${{ env.PKG_VERSION }}.zip, + packages/THIRDPARTY.html, + packages/bws-sha256-checksums-${{ env.PKG_VERSION }}.txt" + commit: ${{ github.sha }} + tag: bws-v${{ env.PKG_VERSION }} + name: bws CLI v${{ env.PKG_VERSION }} + body: "" + token: ${{ secrets.GITHUB_TOKEN }} + draft: true diff --git a/.github/workflows/release-cpp.yml b/.github/workflows/release-cpp.yml index c96b8e088..47199a99f 100644 --- a/.github/workflows/release-cpp.yml +++ b/.github/workflows/release-cpp.yml @@ -24,14 +24,14 @@ jobs: version: ${{ steps.version.outputs.version }} steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - 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' branches" echo "===================================" exit 1 fi @@ -45,9 +45,7 @@ jobs: github-release: name: GitHub Release runs-on: ubuntu-22.04 - needs: - - repo-sync - - validate + needs: validate env: _PKG_VERSION: ${{ needs.validate.outputs.version }} steps: diff --git a/.github/workflows/release-dotnet.yml b/.github/workflows/release-dotnet.yml new file mode 100644 index 000000000..dc8539271 --- /dev/null +++ b/.github/workflows/release-dotnet.yml @@ -0,0 +1,75 @@ +name: Release .NET NuGet +run-name: Release .NET NuGet Package ${{ inputs.release_type }} + +on: + workflow_dispatch: + inputs: + release_type: + description: "Release Options" + required: true + default: "Release" + type: choice + options: + - Release + - Dry Run + +jobs: + setup: + name: Setup + runs-on: ubuntu-22.04 + outputs: + version: ${{ steps.version.outputs.version }} + steps: + - name: Checkout repo + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Branch check + if: ${{ inputs.release_type != 'Dry Run' }} + run: | + if [[ "$GITHUB_REF" != "refs/heads/main" ]]; then + echo "===================================" + echo "[!] Can only release from the 'main' branch" + echo "===================================" + exit 1 + fi + + - name: Install xmllint + run: sudo apt-get install -y libxml2-utils + + - name: Get version + id: version + run: | + VERSION=$(xmllint --xpath 'string(/Project/PropertyGroup/Version)' languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj) + echo "version=$VERSION" >> $GITHUB_OUTPUT + + release: + name: Create GitHub release + runs-on: ubuntu-22.04 + needs: setup + steps: + - name: Checkout Repository + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Download NuGet package + uses: bitwarden/gh-actions/download-artifacts@main + with: + workflow: build-dotnet.yml + workflow_conclusion: success + branch: main + artifacts: Bitwarden.Sdk.${{ needs.setup.outputs.version }}.nupkg + path: ./nuget-output + + - name: Create release + if: ${{ inputs.release_type != 'Dry Run' }} + uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # v1.14.0 + env: + PKG_VERSION: ${{ needs.setup.outputs.version }} + with: + commit: ${{ github.sha }} + tag: dotnet-v${{ env.PKG_VERSION }} + name: .NET NuGet v${{ env.PKG_VERSION }} + body: "" + token: ${{ secrets.GITHUB_TOKEN }} + draft: true + artifacts: | + ./nuget-output/Bitwarden.Sdk.${{ needs.setup.outputs.version }}.nupkg diff --git a/.github/workflows/release-go.yml b/.github/workflows/release-go.yml index 2c2aea4e4..f88e52af5 100644 --- a/.github/workflows/release-go.yml +++ b/.github/workflows/release-go.yml @@ -26,7 +26,7 @@ jobs: version: ${{ steps.version.outputs.version }} steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Branch check if: ${{ inputs.release_type != 'Dry Run' }} @@ -55,7 +55,7 @@ jobs: steps: - name: Checkout SDK repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: path: sdk @@ -72,7 +72,7 @@ jobs: secrets: "github-pat-bitwarden-devops-bot-repo-scope" - name: Checkout SDK-Go repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: repository: bitwarden/sdk-go path: sdk-go diff --git a/.github/workflows/release-java.yml b/.github/workflows/release-java.yml new file mode 100644 index 000000000..6898932d5 --- /dev/null +++ b/.github/workflows/release-java.yml @@ -0,0 +1,61 @@ +name: Release Java SDK +run-name: Release Java SDK ${{ inputs.release_type }} + +on: + workflow_dispatch: + inputs: + release_type: + description: "Release Options" + required: true + default: "Release" + type: choice + options: + - Release + - Dry Run + +jobs: + setup: + name: Setup + runs-on: ubuntu-22.04 + outputs: + version: ${{ steps.version.outputs.version }} + steps: + - name: Checkout repo + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Branch check + if: ${{ inputs.release_type != 'Dry Run' }} + run: | + if [[ "$GITHUB_REF" != "refs/heads/main" ]]; then + echo "===================================" + echo "[!] Can only release from the 'main' branch" + echo "===================================" + exit 1 + fi + + - name: Get version + id: version + run: | + VERSION=$(cat languages/java/build.gradle | grep -Eo 'version = "[0-9]+\.[0-9]+\.[0-9]+"' | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') + echo "version=$VERSION" >> $GITHUB_OUTPUT + + release: + name: Release + runs-on: ubuntu-22.04 + needs: setup + steps: + - name: Checkout Repository + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Create release + if: ${{ inputs.release_type != 'Dry Run' }} + uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # v1.14.0 + env: + PKG_VERSION: ${{ needs.setup.outputs.version }} + with: + commit: ${{ github.sha }} + tag: java-v${{ env.PKG_VERSION }} + name: Java SDK v${{ env.PKG_VERSION }} + body: "" + token: ${{ secrets.GITHUB_TOKEN }} + draft: true diff --git a/.github/workflows/release-napi.yml b/.github/workflows/release-napi.yml index bdb579ec2..761515c73 100644 --- a/.github/workflows/release-napi.yml +++ b/.github/workflows/release-napi.yml @@ -14,11 +14,6 @@ on: - Initial Release - Redeploy - Dry Run - npm_publish: - description: "Publish to NPM registry" - required: true - default: true - type: boolean defaults: run: @@ -30,17 +25,17 @@ jobs: name: Setup runs-on: ubuntu-22.04 outputs: - release-version: ${{ steps.version.outputs.version }} + version: ${{ steps.version.outputs.version }} steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Branch check - if: ${{ github.event.inputs.release_type != 'Dry Run' }} + 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 @@ -49,125 +44,53 @@ jobs: id: version uses: bitwarden/gh-actions/release-version-check@main with: - release-type: ${{ github.event.inputs.release_type }} + release-type: ${{ inputs.release_type }} project-type: ts file: crates/bitwarden-napi/package.json monorepo: false - - name: Create GitHub deployment - if: ${{ github.event.inputs.release_type != 'Dry Run' }} - uses: chrnorm/deployment-action@55729fcebec3d284f60f5bcabbd8376437d696b1 # v2.0.7 - id: deployment - with: - token: "${{ secrets.GITHUB_TOKEN }}" - initial-status: "in_progress" - environment: "Bitwarden SDK NAPI - Production" - description: "Deployment ${{ steps.version.outputs.version }} from branch ${{ github.ref_name }}" - task: release - - - name: Update deployment status to Success - if: ${{ github.event.inputs.release_type != 'Dry Run' && success() }} - uses: chrnorm/deployment-status@9a72af4586197112e0491ea843682b5dc280d806 # v2.0.3 - with: - token: "${{ secrets.GITHUB_TOKEN }}" - state: "success" - deployment-id: ${{ steps.deployment.outputs.deployment_id }} - - - name: Update deployment status to Failure - if: ${{ github.event.inputs.release_type != 'Dry Run' && failure() }} - uses: chrnorm/deployment-status@9a72af4586197112e0491ea843682b5dc280d806 # v2.0.3 - with: - token: "${{ secrets.GITHUB_TOKEN }}" - state: "failure" - deployment-id: ${{ steps.deployment.outputs.deployment_id }} - - npm: - name: Publish NPM + release: + name: Create GitHub release runs-on: ubuntu-22.04 needs: setup - if: inputs.npm_publish - env: - _PKG_VERSION: ${{ needs.setup.outputs.release-version }} steps: - - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - - - name: Setup Node - uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3 - with: - node-version: 18 - cache: "npm" - cache-dependency-path: crates/bitwarden-napi/package-lock.json - - - name: Download schemas - if: ${{ github.event.inputs.release_type != 'Dry Run' }} - uses: bitwarden/gh-actions/download-artifacts@main - with: - workflow: build-napi.yml - artifacts: schemas.ts - path: ${{ github.workspace }}/crates/bitwarden-napi/src-ts/bitwarden_client/ - workflow_conclusion: success - branch: ${{ github.ref_name }} - - - name: Dry Run - Download schemas - if: ${{ github.event.inputs.release_type == 'Dry Run' }} - uses: bitwarden/gh-actions/download-artifacts@main - with: - workflow: build-napi.yml - artifacts: schemas.ts - path: ${{ github.workspace }}/crates/bitwarden-napi/src-ts/bitwarden_client/ - workflow_conclusion: success - branch: main - - - name: Install dependencies - run: npm ci - - - name: Run tsc - run: npm run tsc - - - name: Login to Azure - uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0 - with: - creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} - - - name: Retrieve secrets - id: retrieve-secrets - uses: bitwarden/gh-actions/get-keyvault-secrets@main - with: - keyvault: "bitwarden-ci" - secrets: "npm-api-key" + - name: Checkout Repository + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Download artifacts - if: ${{ github.event.inputs.release_type != 'Dry Run' }} - uses: bitwarden/gh-actions/download-artifacts@main + uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v6 with: workflow: build-napi.yml - path: ${{ github.workspace }}/crates/bitwarden-napi/artifacts - workflow_conclusion: success - branch: ${{ github.ref_name }} - - - name: Dry Run - Download artifacts - if: ${{ github.event.inputs.release_type == 'Dry Run' }} - uses: bitwarden/gh-actions/download-artifacts@main - with: - workflow: build-napi.yml - path: ${{ github.workspace }}/crates/bitwarden-napi/artifacts workflow_conclusion: success branch: main + name: sdk-bitwarden-napi-(.*)|schemas.ts + name_is_regexp: true + path: dist - - name: Move artifacts - run: npm run artifacts - - - name: Setup NPM + - name: Move artifact files to single directory run: | - echo 'registry="https://registry.npmjs.org/"' > ./.npmrc - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ./.npmrc - - echo 'registry="https://registry.npmjs.org/"' > ~/.npmrc - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc + ls -alhR + shopt -s globstar + mv **/*.node . + mv schemas.ts/ schemas/ + mv schemas/schemas.ts . + working-directory: dist + + - name: Create release + if: ${{ inputs.release_type != 'Dry Run' }} + uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # v1.14.0 env: - NPM_TOKEN: ${{ steps.retrieve-secrets.outputs.npm-api-key }} - - - name: Publish NPM - if: ${{ github.event.inputs.release_type != 'Dry Run' }} - run: npm publish --access public --registry=https://registry.npmjs.org/ --userconfig=./.npmrc + _VERSION: ${{ needs.setup.outputs.version }} + with: + commit: ${{ github.sha }} + tag: napi-v${{ env._VERSION }} + name: napi v${{ env._VERSION }} + body: "" + token: ${{ secrets.GITHUB_TOKEN }} + draft: true + artifacts: | + dist/sdk-napi.darwin-arm64.node + dist/sdk-napi.darwin-x64.node + dist/sdk-napi.win32-x64-msvc.node + dist/sdk-napi.linux-x64-gnu.node + dist/schemas.ts diff --git a/.github/workflows/release-python.yml b/.github/workflows/release-python.yml new file mode 100644 index 000000000..5be1a12fc --- /dev/null +++ b/.github/workflows/release-python.yml @@ -0,0 +1,80 @@ +--- +name: Release Python SDK +run-name: Release Python SDK ${{ inputs.release_type }} + +on: + workflow_dispatch: + inputs: + release_type: + description: "Release Options" + required: true + default: "Release" + type: choice + options: + - Release + - Dry Run + +jobs: + setup: + name: Setup + runs-on: ubuntu-22.04 + outputs: + version: ${{ steps.version.outputs.version }} + steps: + - name: Checkout repo + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Branch check + if: ${{ inputs.release_type != 'Dry Run' }} + run: | + if [[ "$GITHUB_REF" != "refs/heads/main" ]]; then + echo "===================================" + echo "[!] Can only release from the 'main' branch" + echo "===================================" + exit 1 + fi + + - name: Get version + id: version + run: | + VERSION=$(cat languages/python/pyproject.toml | grep -Eo 'version = "[0-9]+\.[0-9]+\.[0-9]+"' | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') + echo "version=$VERSION" >> $GITHUB_OUTPUT + + release: + name: Release + runs-on: ubuntu-22.04 + needs: setup + steps: + - name: Checkout repo + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Download artifacts + uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v6 + with: + workflow: build-python-wheels.yml + path: ${{ github.workspace }}/target/wheels/dist + workflow_conclusion: success + branch: main + name: bitwarden_sdk(.*) + name_is_regexp: true + + - name: Move all whl files to single directory + run: | + shopt -s globstar + mv **/*.whl . + working-directory: ${{ github.workspace }}/target/wheels/dist + + - name: Create GitHub release + if: ${{ inputs.release_type != 'Dry Run' }} + uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # v1.14.0 + env: + PKG_VERSION: ${{ needs.setup.outputs.version }} + with: + commit: ${{ github.sha }} + tag: python-v${{ env.PKG_VERSION }} + name: Python v${{ env.PKG_VERSION }} + body: "" + token: ${{ secrets.GITHUB_TOKEN }} + draft: true + artifacts: | + ${{ github.workspace }}/target/wheels/dist/bitwarden_sdk-*.whl diff --git a/.github/workflows/release-ruby.yml b/.github/workflows/release-ruby.yml new file mode 100644 index 000000000..9c3e82b77 --- /dev/null +++ b/.github/workflows/release-ruby.yml @@ -0,0 +1,71 @@ +name: Release Ruby SDK +run-name: Release Ruby SDK ${{ inputs.release_type }} + +on: + workflow_dispatch: + inputs: + release_type: + description: "Release Options" + required: true + default: "Release" + type: choice + options: + - Release + - Dry Run + +jobs: + setup: + name: Setup + runs-on: ubuntu-22.04 + outputs: + version: ${{ steps.version.outputs.version }} + steps: + - name: Checkout repo + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Branch check + if: ${{ inputs.release_type != 'Dry Run' }} + run: | + if [[ "$GITHUB_REF" != "refs/heads/main" ]]; then + echo "===================================" + echo "[!] Can only release from the 'main' branch" + echo "===================================" + exit 1 + fi + + - name: Get version + id: version + run: | + VERSION=$(cat languages/ruby/lib/version.rb | grep -Eo 'VERSION = "[0-9]+\.[0-9]+\.[0-9]+"' | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') + echo "version=$VERSION" >> $GITHUB_OUTPUT + + release: + name: Create GitHub release + runs-on: ubuntu-22.04 + needs: setup + steps: + - name: Checkout Repository + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Download ruby artifact + uses: bitwarden/gh-actions/download-artifacts@main + with: + workflow: build-ruby.yml + workflow_conclusion: success + branch: main + artifacts: bitwarden-sdk-secrets + + - name: Create release + if: ${{ inputs.release_type != 'Dry Run' }} + uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # v1.14.0 + env: + PKG_VERSION: ${{ needs.setup.outputs.version }} + with: + commit: ${{ github.sha }} + tag: ruby-v${{ env.PKG_VERSION }} + name: Ruby v${{ env.PKG_VERSION }} + body: "" + token: ${{ secrets.GITHUB_TOKEN }} + draft: true + artifacts: | + bitwarden-sdk-secrets-${{ env.PKG_VERSION }}.gem diff --git a/.github/workflows/release-rust-crates.yml b/.github/workflows/release-rust-crates.yml new file mode 100644 index 000000000..54845e148 --- /dev/null +++ b/.github/workflows/release-rust-crates.yml @@ -0,0 +1,53 @@ +name: Release Rust crates +run-name: Release Rust crates ${{ inputs.release_type }} + +on: + workflow_dispatch: + inputs: + release_type: + description: "Release Options" + required: true + default: "Release" + type: choice + options: + - Release + - Dry Run + +jobs: + setup: + name: Setup + runs-on: ubuntu-22.04 + outputs: + release-version: ${{ steps.version.outputs.version }} + steps: + - name: Checkout repo + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Branch check + if: ${{ inputs.release_type != 'Dry Run' }} + run: | + if [[ "$GITHUB_REF" != "refs/heads/main" ]]; then + echo "===================================" + echo "[!] Can only release from the 'main' branch" + echo "===================================" + exit 1 + fi + + - name: Get version + id: version + run: | + VERSION=$(grep -o '^version = ".*"' Cargo.toml | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+") + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Create release + if: ${{ inputs.release_type != 'Dry Run' }} + uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # v1.14.0 + env: + PKG_VERSION: ${{ steps.version.outputs.version }} + with: + commit: ${{ github.sha }} + tag: rust-v${{ env.PKG_VERSION }} + name: Rust crates v${{ env.PKG_VERSION }} + body: "" + token: ${{ secrets.GITHUB_TOKEN }} + draft: true diff --git a/.github/workflows/release-swift.yml b/.github/workflows/release-swift.yml index dcae5b5d2..351581a7a 100644 --- a/.github/workflows/release-swift.yml +++ b/.github/workflows/release-swift.yml @@ -42,7 +42,7 @@ jobs: swift_checksum: ${{ steps.calculate-swift-checksum.outputs.checksum }} steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Get version id: version @@ -63,7 +63,7 @@ jobs: -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ /repos/$OWNER/$REPO/actions/workflows/build-swift.yml/runs \ - | jq -r ".workflow_runs[] | select(.head_branch == \"$BRANCH\") | .id") + | jq -r "[.workflow_runs[] | select(.head_branch == \"$BRANCH\").id ] | first") else RUN_ID=${{ inputs.build-run-id }} fi @@ -82,7 +82,7 @@ jobs: - name: Set SHA id: set-sha run: | - echo "sha=$(${{ steps.download-artifact.outputs.artifact-build-commit }})" >> $GITHUB_OUTPUT + echo "sha=${{ steps.download-artifact.outputs.artifact-build-commit }}" >> $GITHUB_OUTPUT echo "short_sha=$(echo ${{ steps.download-artifact.outputs.artifact-build-commit }} | cut -c1-7)" >> $GITHUB_OUTPUT - name: Set release name @@ -111,9 +111,10 @@ jobs: _PRE_RELEASE: ${{ inputs.pre-release }} _RELEASE_NAME: ${{ needs.validate.outputs.release_name }} _SWIFT_CHECKSUM: ${{ needs.validate.outputs.swift_checksum }} + _BUILD_RUN_ID: ${{ needs.validate.outputs.run_id }} steps: - name: Checkout SDK repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: path: sdk @@ -141,7 +142,7 @@ jobs: github-pat-bitwarden-devops-bot-repo-scope" - name: Checkout SDK-Swift repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: repository: bitwarden/sdk-swift path: sdk-swift @@ -163,6 +164,16 @@ jobs: git config --local user.email "${{ env._BOT_EMAIL }}" git config --local user.name "${{ env._BOT_NAME }}" + - name: Download BitwardenSdk sources artifact + uses: bitwarden/gh-actions/download-artifacts@main + id: download-artifact + with: + workflow: build-swift.yml + workflow_conclusion: success + artifacts: "BitwardenSdk-${{ env._PKG_VERSION }}-${{ needs.validate.outputs.short_sha }}-sources" + run_id: ${{ env._BUILD_RUN_ID }} + path: sdk/languages/swift/Sources/BitwardenSdk + - name: Install Swift formatter run: | git clone https://github.com/nicklockwood/SwiftFormat @@ -181,11 +192,16 @@ jobs: # Run swiftformat swiftformat sdk/languages/swift/Package.swift + find sdk/languages/swift/Sources/ -name ".gitignore" -exec rm -f {} \; + + rm -rf sdk-swift/Sources + rm -rf sdk-swift/Tests + # Copy files to local sdk-swift repo path cp --verbose -rf sdk/languages/swift/README.md sdk-swift/README.md cp --verbose -rf sdk/languages/swift/Package.swift sdk-swift/Package.swift - cp --verbose -rf sdk/languages/swift/Sources sdk-swift/Sources - cp --verbose -rf sdk/languages/swift/Tests sdk-swift/Tests + cp --verbose -rf sdk/languages/swift/Sources sdk-swift + cp --verbose -rf sdk/languages/swift/Tests sdk-swift - name: Push changes working-directory: sdk-swift @@ -243,5 +259,5 @@ jobs: draft: false repo: sdk-swift owner: bitwarden - artifacts: "BitwardenFFI-${{ env._PKG_VERSION }}-${{ needs.validate.outputs.short_sha }}.xcframework" + artifacts: "BitwardenFFI-${{ env._PKG_VERSION }}-${{ needs.validate.outputs.short_sha }}.xcframework.zip" prerelease: ${{ inputs.pre-release }} diff --git a/.github/workflows/release-wasm.yml b/.github/workflows/release-wasm.yml index 268dd1ce2..97b2c34dd 100644 --- a/.github/workflows/release-wasm.yml +++ b/.github/workflows/release-wasm.yml @@ -13,15 +13,9 @@ on: options: - Release - Dry Run - npm_publish: - description: "Publish to NPM registry" - required: true - default: true - type: boolean defaults: run: - shell: bash working-directory: languages/js/wasm jobs: @@ -32,14 +26,14 @@ jobs: release-version: ${{ steps.version.outputs.version }} steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Branch check - if: ${{ github.event.inputs.release_type != 'Dry Run' }} + 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 @@ -48,85 +42,37 @@ jobs: id: version uses: bitwarden/gh-actions/release-version-check@main with: - release-type: ${{ github.event.inputs.release_type }} + release-type: ${{ inputs.release_type }} project-type: ts file: languages/js/wasm/package.json monorepo: false - - name: Create GitHub deployment - if: ${{ github.event.inputs.release_type != 'Dry Run' }} - uses: chrnorm/deployment-action@55729fcebec3d284f60f5bcabbd8376437d696b1 # v2.0.7 - id: deployment - with: - token: "${{ secrets.GITHUB_TOKEN }}" - initial-status: "in_progress" - environment: "Bitwarden SDK WASM - Production" - description: "Deployment ${{ steps.version.outputs.version }} from branch ${{ github.ref_name }}" - task: release - - - name: Update deployment status to Success - if: ${{ github.event.inputs.release_type != 'Dry Run' && success() }} - uses: chrnorm/deployment-status@9a72af4586197112e0491ea843682b5dc280d806 # v2.0.3 - with: - token: "${{ secrets.GITHUB_TOKEN }}" - state: "success" - deployment-id: ${{ steps.deployment.outputs.deployment_id }} - - - name: Update deployment status to Failure - if: ${{ github.event.inputs.release_type != 'Dry Run' && failure() }} - uses: chrnorm/deployment-status@9a72af4586197112e0491ea843682b5dc280d806 # v2.0.3 - with: - token: "${{ secrets.GITHUB_TOKEN }}" - state: "failure" - deployment-id: ${{ steps.deployment.outputs.deployment_id }} - - npm: - name: Publish NPM + release: + name: Release runs-on: ubuntu-22.04 needs: setup - if: inputs.npm_publish - env: - _PKG_VERSION: ${{ needs.setup.outputs.release-version }} steps: - name: Checkout repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - - - name: Setup Node - uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3 - with: - node-version: 18 - cache: "npm" - - - name: Login to Azure - uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0 - with: - creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} - - - name: Retrieve secrets - id: retrieve-secrets - uses: bitwarden/gh-actions/get-keyvault-secrets@main - with: - keyvault: "bitwarden-ci" - secrets: "npm-api-key" + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Download artifacts - uses: bitwarden/gh-actions/download-artifacts@main + uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v6 with: workflow: build-wasm.yml - path: ${{ github.workspace }}/languages/js/wasm + skip_unpack: true workflow_conclusion: success - branch: ${{ github.event.inputs.release_type == 'Dry Run' && 'main' || github.ref_name }} + branch: main - - name: Setup NPM - run: | - echo 'registry="https://registry.npmjs.org/"' > ./.npmrc - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ./.npmrc - - echo 'registry="https://registry.npmjs.org/"' > ~/.npmrc - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc + - name: Create GitHub release + if: ${{ inputs.release_type != 'Dry Run' }} + uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # v1.14.0 env: - NPM_TOKEN: ${{ steps.retrieve-secrets.outputs.npm-api-key }} - - - name: Publish NPM - if: ${{ github.event.inputs.release_type != 'Dry Run' }} - run: npm publish --access public --registry=https://registry.npmjs.org/ --userconfig=./.npmrc + PKG_VERSION: ${{ needs.setup.outputs.release-version }} + with: + commit: ${{ github.sha }} + tag: wasm-v${{ env.PKG_VERSION }} + name: WASM v${{ env.PKG_VERSION }} + body: "" + token: ${{ secrets.GITHUB_TOKEN }} + draft: true + artifacts: sdk-bitwarden-wasm.zip diff --git a/.github/workflows/rust-test.yml b/.github/workflows/rust-test.yml index 514e2a310..5e7703e84 100644 --- a/.github/workflows/rust-test.yml +++ b/.github/workflows/rust-test.yml @@ -5,8 +5,6 @@ on: push: branches: - "main" - - "rc" - - "hotfix-rc" pull_request: env: @@ -23,7 +21,7 @@ jobs: - run: exit 0 test: - name: ${{ matrix.os }} / ${{matrix.target || 'default' }} + name: ${{ matrix.os }} / default runs-on: ${{ matrix.os || 'ubuntu-22.04' }} @@ -36,7 +34,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Install rust uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable @@ -47,7 +45,8 @@ jobs: uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - name: Test - run: cargo test --all-features + # Termporarily exclude NAPI due to a test error on windows + run: cargo test --workspace --exclude bitwarden-napi --all-features coverage: name: Coverage @@ -55,7 +54,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Install rust uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable @@ -84,7 +83,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Install rust uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable diff --git a/.github/workflows/rustdoc.yml b/.github/workflows/rustdoc.yml index a2a07490c..45ab6d07d 100644 --- a/.github/workflows/rustdoc.yml +++ b/.github/workflows/rustdoc.yml @@ -20,7 +20,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Install rust uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable diff --git a/.github/workflows/scan.yml b/.github/workflows/scan.yml index 2df3b61b7..193c9fcf6 100644 --- a/.github/workflows/scan.yml +++ b/.github/workflows/scan.yml @@ -26,12 +26,12 @@ jobs: steps: - name: Check out repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: ref: ${{ github.event.pull_request.head.sha }} - name: Scan with Checkmarx - uses: checkmarx/ast-github-action@1fe318de2993222574e6249750ba9000a4e2a6cd # 2.0.33 + uses: checkmarx/ast-github-action@9fda5a4a2c297608117a5a56af424502a9192e57 # 2.0.34 env: INCREMENTAL: "${{ contains(github.event_name, 'pull_request') && '--sast-incremental' || '' }}" with: @@ -46,7 +46,7 @@ jobs: --output-path . ${{ env.INCREMENTAL }} - name: Upload Checkmarx results to GitHub - uses: github/codeql-action/upload-sarif@2c779ab0d087cd7fe7b826087247c2c81f27bfa6 # v3.26.5 + uses: github/codeql-action/upload-sarif@461ef6c76dfe95d5c364de2f431ddbd31a417628 # v3.26.9 with: sarif_file: cx_result.sarif @@ -60,13 +60,13 @@ jobs: steps: - name: Check out repo - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: fetch-depth: 0 ref: ${{ github.event.pull_request.head.sha }} - name: Scan with SonarCloud - uses: sonarsource/sonarcloud-github-action@e44258b109568baa0df60ed515909fc6c72cba92 # v2.3.0 + uses: sonarsource/sonarcloud-github-action@eb211723266fe8e83102bac7361f0a05c3ac1d1b # v3.0.0 env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 3536c96ce..7053181eb 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -1,6 +1,6 @@ --- name: Version Bump -run-name: Version Bump - v${{ inputs.version_number }} +run-name: Version Bump - ${{ inputs.project }} - v${{ inputs.version_number }} on: workflow_dispatch: @@ -25,7 +25,7 @@ on: required: true cut_rc_branch: description: "Cut RC branch?" - default: true + default: false type: boolean jobs: @@ -59,7 +59,7 @@ jobs: github-pat-bitwarden-devops-bot-repo-scope" - name: Checkout Branch - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: ref: main repository: bitwarden/sdk @@ -198,7 +198,7 @@ jobs: env: GH_TOKEN: ${{ steps.retrieve-secrets.outputs.github-pat-bitwarden-devops-bot-repo-scope }} PR_BRANCH: ${{ steps.create-branch.outputs.name }} - TITLE: "Bump version to ${{ inputs.version_number }}" + TITLE: "Bump ${{ inputs.project }} version to ${{ inputs.version_number }}" run: | PR_URL=$(gh pr create --title "$TITLE" \ --base "main" \ @@ -236,7 +236,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout Branch - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: ref: main diff --git a/.gitignore b/.gitignore index b13651d19..4a1d79fca 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/.prettierignore b/.prettierignore index 36c418776..16243942f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,5 +1,9 @@ target languages/* +!languages/js +languages/js/* +!languages/js/sdk-internal +languages/js/sdk-internal/bitwarden_wasm_internal_bg.wasm.js schemas /crates/bitwarden-napi/src-ts/bitwarden_client/schemas.ts about.hbs diff --git a/Cargo.lock b/Cargo.lock index 5818f6cfc..0f98a3684 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -142,9 +142,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.86" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" [[package]] name = "arc-swap" @@ -188,7 +188,7 @@ dependencies = [ "proc-macro2", "quote", "serde", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -231,13 +231,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.81" +version = "0.1.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -248,9 +248,9 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "backtrace" @@ -273,12 +273,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" -[[package]] -name = "base64" -version = "0.21.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" - [[package]] name = "base64" version = "0.22.1" @@ -366,7 +360,7 @@ checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "bitwarden" -version = "0.5.0" +version = "1.0.0" dependencies = [ "bitwarden-api-api", "bitwarden-api-identity", @@ -384,7 +378,7 @@ dependencies = [ [[package]] name = "bitwarden-api-api" -version = "0.5.0" +version = "1.0.0" dependencies = [ "reqwest", "serde", @@ -397,7 +391,7 @@ dependencies = [ [[package]] name = "bitwarden-api-identity" -version = "0.5.0" +version = "1.0.0" dependencies = [ "reqwest", "serde", @@ -419,7 +413,7 @@ dependencies = [ [[package]] name = "bitwarden-cli" -version = "0.5.0" +version = "1.0.0" dependencies = [ "clap", "color-eyre", @@ -429,9 +423,9 @@ dependencies = [ [[package]] name = "bitwarden-core" -version = "0.5.0" +version = "1.0.0" dependencies = [ - "base64 0.22.1", + "base64", "bitwarden-api-api", "bitwarden-api-identity", "bitwarden-crypto", @@ -452,9 +446,11 @@ dependencies = [ "sha2", "thiserror", "tokio", + "tsify-next", "uniffi", "uuid", "validator", + "wasm-bindgen", "wiremock", "zeroize", "zxcvbn", @@ -462,11 +458,11 @@ dependencies = [ [[package]] name = "bitwarden-crypto" -version = "0.5.0" +version = "1.0.0" dependencies = [ "aes", "argon2", - "base64 0.22.1", + "base64", "cbc", "criterion", "generic-array", @@ -493,9 +489,9 @@ dependencies = [ [[package]] name = "bitwarden-exporters" -version = "0.5.0" +version = "1.0.0" dependencies = [ - "base64 0.22.1", + "base64", "bitwarden-core", "bitwarden-crypto", "bitwarden-vault", @@ -511,10 +507,10 @@ dependencies = [ [[package]] name = "bitwarden-fido" -version = "0.5.0" +version = "1.0.0" dependencies = [ "async-trait", - "base64 0.22.1", + "base64", "bitwarden-core", "bitwarden-crypto", "bitwarden-vault", @@ -524,6 +520,7 @@ dependencies = [ "log", "p256", "passkey", + "passkey-client", "reqwest", "schemars", "serde", @@ -535,7 +532,7 @@ dependencies = [ [[package]] name = "bitwarden-generators" -version = "0.5.0" +version = "1.0.0" dependencies = [ "bitwarden-core", "bitwarden-crypto", @@ -565,7 +562,7 @@ dependencies = [ [[package]] name = "bitwarden-napi" -version = "0.3.1" +version = "1.0.0" dependencies = [ "bitwarden-json", "env_logger", @@ -588,9 +585,9 @@ dependencies = [ [[package]] name = "bitwarden-send" -version = "0.5.0" +version = "1.0.0" dependencies = [ - "base64 0.22.1", + "base64", "bitwarden-api-api", "bitwarden-core", "bitwarden-crypto", @@ -606,7 +603,7 @@ dependencies = [ [[package]] name = "bitwarden-sm" -version = "0.5.0" +version = "1.0.0" dependencies = [ "bitwarden-api-api", "bitwarden-core", @@ -650,9 +647,9 @@ dependencies = [ [[package]] name = "bitwarden-vault" -version = "0.5.0" +version = "1.0.0" dependencies = [ - "base64 0.22.1", + "base64", "bitwarden-api-api", "bitwarden-core", "bitwarden-crypto", @@ -689,6 +686,20 @@ dependencies = [ "wasm-bindgen-test", ] +[[package]] +name = "bitwarden-wasm-internal" +version = "0.1.0" +dependencies = [ + "bitwarden", + "console_error_panic_hook", + "console_log", + "js-sys", + "log", + "serde_json", + "wasm-bindgen", + "wasm-bindgen-futures", +] + [[package]] name = "blake2" version = "0.10.6" @@ -750,7 +761,7 @@ dependencies = [ [[package]] name = "bws" -version = "0.5.0" +version = "1.0.0" dependencies = [ "bat", "bitwarden", @@ -780,9 +791,9 @@ dependencies = [ [[package]] name = "bytemuck" -version = "1.17.1" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773d90827bc3feecfb67fab12e24de0749aad83c74b9504ecde46237b5cd24e2" +checksum = "94bbb0ad554ad961ddc5da507a12a29b14e4ae5bda06b19f575a3e6079d2e2ae" [[package]] name = "byteorder" @@ -792,9 +803,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "bytesize" @@ -851,9 +862,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.15" +version = "1.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" dependencies = [ "shlex", ] @@ -925,9 +936,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.16" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019" +checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" dependencies = [ "clap_builder", "clap_derive", @@ -935,9 +946,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.15" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6" +checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" dependencies = [ "anstream", "anstyle", @@ -947,23 +958,23 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.5.24" +version = "4.5.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d7db6eca8c205649e8d3ccd05aa5042b1800a784e56bc7c43524fde8abbfa9b" +checksum = "9646e2e245bf62f45d39a0f3f36f1171ad1ea0d6967fd114bca72cb02a8fcdfb" dependencies = [ "clap", ] [[package]] name = "clap_derive" -version = "4.5.13" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -974,9 +985,9 @@ checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "clap_mangen" -version = "0.2.23" +version = "0.2.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f17415fd4dfbea46e3274fcd8d368284519b358654772afb700dc2e8d2b24eeb" +checksum = "fbae9cbfdc5d4fa8711c09bd7b83f644cb48281ac35bf97af3e47b0675864bdf" dependencies = [ "clap", "roff", @@ -1135,9 +1146,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" dependencies = [ "libc", ] @@ -1306,7 +1317,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edb49164822f3ee45b17acd4a208cfc1251410cf0cad9a833234c9890774dd9f" dependencies = [ "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1330,7 +1341,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1341,7 +1352,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1404,33 +1415,33 @@ dependencies = [ [[package]] name = "derive_builder" -version = "0.20.1" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd33f37ee6a119146a1781d3356a7c26028f83d779b2e04ecd45fdc75c76877b" +checksum = "507dfb09ea8b7fa618fcf76e953f4f5e192547945816d5358edffe39f6f94947" dependencies = [ "derive_builder_macro", ] [[package]] name = "derive_builder_core" -version = "0.20.1" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7431fa049613920234f22c47fdc33e6cf3ee83067091ea4277a3f8c4587aae38" +checksum = "2d5bcf7b024d6835cfb3d473887cd966994907effbe9227e8c8219824d06c4e8" dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "derive_builder_macro" -version = "0.20.1" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4abae7035bf79b9877b779505d8cf3749285b80c43941eda66604841889451dc" +checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c" dependencies = [ "derive_builder_core", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1608,9 +1619,9 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.33" +version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253" +checksum = "a1b589b4dc103969ad3cf85c950899926ec64300a1a46d76c03a6072957036f0" dependencies = [ "crc32fast", "miniz_oxide 0.8.0", @@ -1642,9 +1653,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" dependencies = [ "futures-channel", "futures-core", @@ -1657,9 +1668,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", "futures-sink", @@ -1667,15 +1678,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-executor" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" dependencies = [ "futures-core", "futures-task", @@ -1684,38 +1695,38 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-macro" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "futures-sink" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] name = "futures-task" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-util" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-channel", "futures-core", @@ -1785,9 +1796,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "globset" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" +checksum = "15f1ce686646e7f1e19bf7d5533fe443a45dbfb990e00629110797578b42fb19" dependencies = [ "aho-corasick", "bstr", @@ -1830,7 +1841,7 @@ dependencies = [ "futures-core", "futures-sink", "http", - "indexmap 2.5.0", + "indexmap 2.6.0", "slab", "tokio", "tokio-util", @@ -1859,6 +1870,12 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" + [[package]] name = "heck" version = "0.4.1" @@ -1952,9 +1969,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.9.4" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] name = "httpdate" @@ -1991,16 +2008,15 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.27.2" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ "futures-util", "http", "hyper", "hyper-util", "rustls", - "rustls-native-certs", "rustls-pki-types", "tokio", "tokio-rustls", @@ -2009,9 +2025,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.7" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde7055719c54e36e95e8719f95883f22072a48ede39db7fc17a4e1d5281e9b9" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ "bytes", "futures-channel", @@ -2022,16 +2038,15 @@ dependencies = [ "pin-project-lite", "socket2", "tokio", - "tower", "tower-service", "tracing", ] [[package]] name = "iana-time-zone" -version = "0.1.60" +version = "0.1.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -2085,12 +2100,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.14.5", + "hashbrown 0.15.0", "serde", ] @@ -2129,9 +2144,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.9.0" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" [[package]] name = "is-terminal" @@ -2202,9 +2217,9 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" [[package]] name = "js-sys" -version = "0.3.70" +version = "0.3.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +checksum = "0cb94a0ffd3f3ee755c20f7d8752f45cac88605a4dcf808abcff72873296ec7b" dependencies = [ "wasm-bindgen", ] @@ -2220,9 +2235,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libloading" @@ -2375,9 +2390,9 @@ dependencies = [ [[package]] name = "napi" -version = "2.16.9" +version = "2.16.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1277600d452e570cc83cf5f4e8efb389cc21e5cbefadcfba7239f4551e2e3e99" +checksum = "53575dfa17f208dd1ce3a2da2da4659aae393b256a472f2738a8586a6c4107fd" dependencies = [ "bitflags 2.6.0", "ctor", @@ -2395,23 +2410,23 @@ checksum = "e1c0f5d67ee408a4685b61f5ab7e58605c8ae3f2b4189f0127d804ff13d5560a" [[package]] name = "napi-derive" -version = "2.16.11" +version = "2.16.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "150d87c4440b9f4815cb454918db498b5aae9a57aa743d20783fe75381181d01" +checksum = "17435f7a00bfdab20b0c27d9c56f58f6499e418252253081bfff448099da31d1" dependencies = [ "cfg-if", "convert_case", "napi-derive-backend", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "napi-derive-backend" -version = "1.0.73" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cd81b794fc1d6051acf8c4f3cb4f82833b0621272a232b4ff0cf3df1dbddb61" +checksum = "967c485e00f0bf3b1bdbe510a38a4606919cf1d34d9a37ad41f25a81aa077abe" dependencies = [ "convert_case", "once_cell", @@ -2419,7 +2434,7 @@ dependencies = [ "quote", "regex", "semver", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2543,9 +2558,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "onig" @@ -2641,8 +2656,8 @@ dependencies = [ [[package]] name = "passkey" -version = "0.3.1" -source = "git+https://github.com/bitwarden/passkey-rs?rev=ae08e2cb7dd3d44d915caed395c0cdc56b50fa27#ae08e2cb7dd3d44d915caed395c0cdc56b50fa27" +version = "0.2.0" +source = "git+https://github.com/bitwarden/passkey-rs?rev=ff757604cd7b4e8f321ed1616fef7e40e21ac5df#ff757604cd7b4e8f321ed1616fef7e40e21ac5df" dependencies = [ "passkey-authenticator", "passkey-client", @@ -2652,8 +2667,8 @@ dependencies = [ [[package]] name = "passkey-authenticator" -version = "0.3.0" -source = "git+https://github.com/bitwarden/passkey-rs?rev=ae08e2cb7dd3d44d915caed395c0cdc56b50fa27#ae08e2cb7dd3d44d915caed395c0cdc56b50fa27" +version = "0.2.0" +source = "git+https://github.com/bitwarden/passkey-rs?rev=ff757604cd7b4e8f321ed1616fef7e40e21ac5df#ff757604cd7b4e8f321ed1616fef7e40e21ac5df" dependencies = [ "async-trait", "coset", @@ -2665,12 +2680,13 @@ dependencies = [ [[package]] name = "passkey-client" -version = "0.3.1" -source = "git+https://github.com/bitwarden/passkey-rs?rev=ae08e2cb7dd3d44d915caed395c0cdc56b50fa27#ae08e2cb7dd3d44d915caed395c0cdc56b50fa27" +version = "0.2.0" +source = "git+https://github.com/bitwarden/passkey-rs?rev=ff757604cd7b4e8f321ed1616fef7e40e21ac5df#ff757604cd7b4e8f321ed1616fef7e40e21ac5df" dependencies = [ "ciborium", "coset", "idna", + "nom", "passkey-authenticator", "passkey-types", "public-suffix", @@ -2682,19 +2698,19 @@ dependencies = [ [[package]] name = "passkey-transports" version = "0.1.0" -source = "git+https://github.com/bitwarden/passkey-rs?rev=ae08e2cb7dd3d44d915caed395c0cdc56b50fa27#ae08e2cb7dd3d44d915caed395c0cdc56b50fa27" +source = "git+https://github.com/bitwarden/passkey-rs?rev=ff757604cd7b4e8f321ed1616fef7e40e21ac5df#ff757604cd7b4e8f321ed1616fef7e40e21ac5df" [[package]] name = "passkey-types" version = "0.2.1" -source = "git+https://github.com/bitwarden/passkey-rs?rev=ae08e2cb7dd3d44d915caed395c0cdc56b50fa27#ae08e2cb7dd3d44d915caed395c0cdc56b50fa27" +source = "git+https://github.com/bitwarden/passkey-rs?rev=ff757604cd7b4e8f321ed1616fef7e40e21ac5df#ff757604cd7b4e8f321ed1616fef7e40e21ac5df" dependencies = [ "bitflags 2.6.0", "ciborium", "coset", "data-encoding", "getrandom", - "indexmap 2.5.0", + "indexmap 2.6.0", "rand", "serde", "serde_json", @@ -2752,26 +2768,6 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" -[[package]] -name = "pin-project" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.77", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -2807,9 +2803,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "plain" @@ -2823,8 +2819,8 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42cf17e9a1800f5f396bc67d193dc9411b59012a5876445ef450d449881e1016" dependencies = [ - "base64 0.22.1", - "indexmap 2.5.0", + "base64", + "indexmap 2.6.0", "quick-xml", "serde", "time", @@ -2832,9 +2828,9 @@ dependencies = [ [[package]] name = "plotters" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a15b6eccb8484002195a3e44fe65a4ce8e93a625797a063735536fd59cb01cf3" +checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" dependencies = [ "num-traits", "plotters-backend", @@ -2845,24 +2841,24 @@ dependencies = [ [[package]] name = "plotters-backend" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "414cec62c6634ae900ea1c56128dfe87cf63e7caece0852ec76aba307cebadb7" +checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" [[package]] name = "plotters-svg" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81b30686a7d9c3e010b84284bdd26a29f2138574f52f5eb6f794fc0ad924e705" +checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" dependencies = [ "plotters-backend", ] [[package]] name = "portable-atomic" -version = "1.7.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" [[package]] name = "powerfmt" @@ -2914,9 +2910,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" dependencies = [ "unicode-ident", ] @@ -2924,13 +2920,13 @@ dependencies = [ [[package]] name = "public-suffix" version = "0.1.1" -source = "git+https://github.com/bitwarden/passkey-rs?rev=ae08e2cb7dd3d44d915caed395c0cdc56b50fa27#ae08e2cb7dd3d44d915caed395c0cdc56b50fa27" +source = "git+https://github.com/bitwarden/passkey-rs?rev=ff757604cd7b4e8f321ed1616fef7e40e21ac5df#ff757604cd7b4e8f321ed1616fef7e40e21ac5df" [[package]] name = "pyo3" -version = "0.22.2" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "831e8e819a138c36e212f3af3fd9eeffed6bf1510a805af35b0edee5ffa59433" +checksum = "15ee168e30649f7f234c3d49ef5a7a6cbf5134289bc46c29ff3155fa3221c225" dependencies = [ "cfg-if", "indoc", @@ -2946,9 +2942,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.22.2" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e8730e591b14492a8945cdff32f089250b05f5accecf74aeddf9e8272ce1fa8" +checksum = "e61cef80755fe9e46bb8a0b8f20752ca7676dcc07a5277d8b7768c6172e529b3" dependencies = [ "once_cell", "target-lexicon", @@ -2956,9 +2952,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.22.2" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e97e919d2df92eb88ca80a037969f44e5e70356559654962cbb3316d00300c6" +checksum = "67ce096073ec5405f5ee2b8b31f03a68e02aa10d5d4f565eca04acc41931fa1c" dependencies = [ "libc", "pyo3-build-config", @@ -2977,27 +2973,27 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.22.2" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb57983022ad41f9e683a599f2fd13c3664d7063a3ac5714cae4b7bee7d3f206" +checksum = "2440c6d12bc8f3ae39f1e775266fa5122fd0c8891ce7520fa6048e683ad3de28" dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "pyo3-macros-backend" -version = "0.22.2" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec480c0c51ddec81019531705acac51bcdbeae563557c982aa8263bb96880372" +checksum = "1be962f0e06da8f8465729ea2cb71a416d2257dff56cbe40a70d3e62a93ae5d1" dependencies = [ "heck 0.5.0", "proc-macro2", "pyo3-build-config", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -3011,9 +3007,9 @@ dependencies = [ [[package]] name = "quinn" -version = "0.11.3" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b22d8e7369034b9a7132bc2008cac12f2013c8132b45e0554e6e20e2617f2156" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" dependencies = [ "bytes", "pin-project-lite", @@ -3029,9 +3025,9 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.11.6" +version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba92fb39ec7ad06ca2582c0ca834dfeadcaf06ddfc8e635c80aa7e1c05315fdd" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" dependencies = [ "bytes", "rand", @@ -3046,15 +3042,15 @@ dependencies = [ [[package]] name = "quinn-udp" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +checksum = "4fe68c2e9e1a1234e218683dbdf9f9dfcb094113c5ac2b938dfcb9bab4c4140b" dependencies = [ "libc", "once_cell", "socket2", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -3118,9 +3114,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.3" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ "bitflags 2.6.0", ] @@ -3138,9 +3134,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.6" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" dependencies = [ "aho-corasick", "memchr", @@ -3150,9 +3146,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", @@ -3161,17 +3157,17 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "reqwest" -version = "0.12.7" +version = "0.12.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ - "base64 0.22.1", + "base64", "bytes", "futures-core", "futures-util", @@ -3192,7 +3188,6 @@ dependencies = [ "pin-project-lite", "quinn", "rustls", - "rustls-native-certs", "rustls-pemfile", "rustls-pki-types", "serde", @@ -3283,9 +3278,9 @@ checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustix" -version = "0.38.35" +version = "0.38.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" dependencies = [ "bitflags 2.6.0", "errno", @@ -3296,9 +3291,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.12" +version = "0.23.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", "ring", @@ -3323,19 +3318,18 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "2.1.3" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" dependencies = [ - "base64 0.22.1", "rustls-pki-types", ] [[package]] name = "rustls-pki-types" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" [[package]] name = "rustls-platform-verifier" @@ -3366,9 +3360,9 @@ checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" [[package]] name = "rustls-webpki" -version = "0.102.7" +version = "0.102.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84678086bd54edf2b415183ed7a94d0efb049f1b646a33e22a36f3794be6ae56" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ "ring", "rustls-pki-types", @@ -3398,11 +3392,11 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.23" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -3429,7 +3423,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -3461,7 +3455,7 @@ checksum = "7f81c2fde025af7e69b1d1420531c8a8811ca898919db177141a85313b1cb932" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -3508,9 +3502,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.11.1" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" dependencies = [ "core-foundation-sys", "libc", @@ -3527,22 +3521,33 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.209" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] +[[package]] +name = "serde-wasm-bindgen" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8302e169f0eddcc139c70f139d19d6467353af16f9fce27e8c30158036a1e16b" +dependencies = [ + "js-sys", + "serde", + "wasm-bindgen", +] + [[package]] name = "serde_derive" -version = "1.0.209" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -3553,16 +3558,16 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "serde_json" -version = "1.0.127" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ - "indexmap 2.5.0", + "indexmap 2.6.0", "itoa", "memchr", "ryu", @@ -3588,14 +3593,14 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "serde_spanned" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" dependencies = [ "serde", ] @@ -3614,15 +3619,15 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.9.0" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cecfa94848272156ea67b2b1a53f20fc7bc638c4a46d2f8abde08f05f4b857" +checksum = "8e28bdad6db2b8340e449f7108f020b3b092e8583a9e3fb82713e1d4e71fe817" dependencies = [ - "base64 0.22.1", + "base64", "chrono", "hex", "indexmap 1.9.3", - "indexmap 2.5.0", + "indexmap 2.6.0", "serde", "serde_derive", "serde_json", @@ -3632,14 +3637,14 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "3.9.0" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8fee4991ef4f274617a51ad4af30519438dacb2f56ac773b08a1922ff743350" +checksum = "9d846214a9854ef724f3da161b426242d8de7c1fc7de2f89bb1efcb154dca79d" dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -3648,7 +3653,7 @@ version = "0.9.34+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" dependencies = [ - "indexmap 2.5.0", + "indexmap 2.6.0", "itoa", "ryu", "serde", @@ -3838,7 +3843,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -3851,7 +3856,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -3862,9 +3867,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "supports-color" -version = "3.0.0" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9829b314621dfc575df4e409e79f9d6a66a3bd707ab73f23cb4aa3a854ac854f" +checksum = "8775305acf21c96926c900ad056abeef436701108518cf890020387236ac5a77" dependencies = [ "is_ci", ] @@ -3881,9 +3886,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.77" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -3927,9 +3932,9 @@ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "tempfile" -version = "3.12.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" dependencies = [ "cfg-if", "fastrand", @@ -3949,22 +3954,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4057,7 +4062,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4073,9 +4078,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.11" +version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" dependencies = [ "bytes", "futures-core", @@ -4116,38 +4121,17 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.20" +version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ - "indexmap 2.5.0", + "indexmap 2.6.0", "serde", "serde_spanned", "toml_datetime", "winnow", ] -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite", - "tokio", - "tower-layer", - "tower-service", -] - -[[package]] -name = "tower-layer" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" - [[package]] name = "tower-service" version = "0.3.3" @@ -4201,6 +4185,30 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "tsify-next" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4a645dca4ee0800f5ab60ce166deba2db6a0315de795a2691e138a3d55d756" +dependencies = [ + "serde", + "serde-wasm-bindgen", + "tsify-next-macros", + "wasm-bindgen", +] + +[[package]] +name = "tsify-next-macros" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d5c06f8a51d759bb58129e30b2631739e7e1e4579fad1f30ac09a6c88e488a6" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 2.0.79", +] + [[package]] name = "typenum" version = "1.17.0" @@ -4218,36 +4226,36 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-normalization" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" dependencies = [ "tinyvec", ] [[package]] name = "unicode-segmentation" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" [[package]] name = "unicode-width" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] name = "uniffi" @@ -4308,12 +4316,12 @@ dependencies = [ [[package]] name = "uniffi_checksum_derive" -version = "0.28.1" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a22dbe67c1c957ac6e7611bdf605a6218aa86b0eebeb8be58b70ae85ad7d73dc" +checksum = "d2c801f0f05b06df456a2da4c41b9c2c4fdccc6b9916643c6c67275c4c9e4d07" dependencies = [ "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4345,7 +4353,7 @@ dependencies = [ "proc-macro2", "quote", "serde", - "syn 2.0.77", + "syn 2.0.79", "toml 0.5.11", "uniffi_meta", ] @@ -4460,7 +4468,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4502,9 +4510,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +checksum = "ef073ced962d62984fb38a36e5fdc1a2b23c9e0e1fa0689bb97afa4202ef6887" dependencies = [ "cfg-if", "once_cell", @@ -4515,24 +4523,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +checksum = "c4bfab14ef75323f4eb75fa52ee0a3fb59611977fd3240da19b2cf36ff85030e" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.43" +version = "0.4.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +checksum = "65471f79c1022ffa5291d33520cbbb53b7687b01c2f8e83b57d102eed7ed479d" dependencies = [ "cfg-if", "js-sys", @@ -4542,9 +4550,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +checksum = "a7bec9830f60924d9ceb3ef99d55c155be8afa76954edffbb5936ff4509474e7" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -4552,28 +4560,28 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +checksum = "4c74f6e152a76a2ad448e223b0fc0b6b5747649c3d769cc6bf45737bf97d0ed6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" +checksum = "a42f6c679374623f295a8623adfe63d9284091245c3504bde47c17a3ce2777d9" [[package]] name = "wasm-bindgen-test" -version = "0.3.43" +version = "0.3.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68497a05fb21143a08a7d24fc81763384a3072ee43c44e86aad1744d6adef9d9" +checksum = "a93d2a9ae98f1af8953f6415397299d808cce0a24f6d7c613d27bd83edf98da8" dependencies = [ "console_error_panic_hook", "js-sys", @@ -4586,20 +4594,20 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.43" +version = "0.3.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8220be1fa9e4c889b30fd207d4906657e7e90b12e0e6b0c8b8d8709f5de021" +checksum = "fb8b294691f640bad8f2bb35a11bb28272701b1d687bd5fd661a27684e894d4d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "web-sys" -version = "0.3.70" +version = "0.3.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +checksum = "44188d185b5bdcae1052d08bcbcf9091a5524038d4572cc4f4f2bb9d5554ddd9" dependencies = [ "js-sys", "wasm-bindgen", @@ -4607,9 +4615,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.26.5" +version = "0.26.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bd24728e5af82c6c4ec1b66ac4844bdf8156257fccda846ec58b42cd0cdbe6a" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" dependencies = [ "rustls-pki-types", ] @@ -4855,9 +4863,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.18" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" dependencies = [ "memchr", ] @@ -4870,13 +4878,13 @@ checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" [[package]] name = "wiremock" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a59f8ae78a4737fb724f20106fb35ccb7cfe61ff335665d3042b3aa98e34717" +checksum = "7fff469918e7ca034884c7fd8f93fe27bacb7fcb599fd879df6c7b429a29b646" dependencies = [ "assert-json-diff", "async-trait", - "base64 0.21.7", + "base64", "deadpool", "futures", "http", @@ -4910,7 +4918,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4931,7 +4939,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index d64aa04fc..ce01a7b7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ members = ["crates/*"] # Global settings for all crates should be defined here [workspace.package] # Update using `cargo set-version -p bitwarden ` -version = "0.5.0" +version = "1.0.0" authors = ["Bitwarden Inc"] edition = "2021" # Note: Changing rust-version should be considered a breaking change @@ -17,18 +17,46 @@ keywords = ["bitwarden"] # Define dependencies that are expected to be consistent across all crates [workspace.dependencies] -bitwarden = { path = "crates/bitwarden", version = "=0.5.0" } -bitwarden-api-api = { path = "crates/bitwarden-api-api", version = "=0.5.0" } -bitwarden-api-identity = { path = "crates/bitwarden-api-identity", version = "=0.5.0" } -bitwarden-cli = { path = "crates/bitwarden-cli", version = "=0.5.0" } -bitwarden-core = { path = "crates/bitwarden-core", version = "=0.5.0" } -bitwarden-crypto = { path = "crates/bitwarden-crypto", version = "=0.5.0" } -bitwarden-exporters = { path = "crates/bitwarden-exporters", version = "=0.5.0" } -bitwarden-fido = { path = "crates/bitwarden-fido", version = "=0.5.0" } -bitwarden-generators = { path = "crates/bitwarden-generators", version = "=0.5.0" } -bitwarden-send = { path = "crates/bitwarden-send", version = "=0.5.0" } -bitwarden-sm = { path = "crates/bitwarden-sm", version = "=0.5.0" } -bitwarden-vault = { path = "crates/bitwarden-vault", version = "=0.5.0" } +bitwarden = { path = "crates/bitwarden", version = "=1.0.0" } +bitwarden-api-api = { path = "crates/bitwarden-api-api", version = "=1.0.0" } +bitwarden-api-identity = { path = "crates/bitwarden-api-identity", version = "=1.0.0" } +bitwarden-cli = { path = "crates/bitwarden-cli", version = "=1.0.0" } +bitwarden-core = { path = "crates/bitwarden-core", version = "=1.0.0" } +bitwarden-crypto = { path = "crates/bitwarden-crypto", version = "=1.0.0" } +bitwarden-exporters = { path = "crates/bitwarden-exporters", version = "=1.0.0" } +bitwarden-fido = { path = "crates/bitwarden-fido", version = "=1.0.0" } +bitwarden-generators = { path = "crates/bitwarden-generators", version = "=1.0.0" } +bitwarden-send = { path = "crates/bitwarden-send", version = "=1.0.0" } +bitwarden-sm = { path = "crates/bitwarden-sm", version = "=1.0.0" } +bitwarden-vault = { path = "crates/bitwarden-vault", version = "=1.0.0" } + +# External crates that are expected to maintain a consistent version across all crates +chrono = { version = ">=0.4.26, <0.5", features = [ + "clock", + "serde", + "std", +], default-features = false } +log = "0.4.20" +reqwest = { version = ">=0.12.5, <0.13", features = [ + "json", + "multipart", + "http2", +], default-features = false } +schemars = { version = ">=0.8.9, <0.9", features = ["uuid1", "chrono"] } +serde = { version = ">=1.0, <2.0", features = ["derive"] } +serde_json = ">=1.0.96, <2.0" +serde_qs = ">=0.12.0, <0.14" +serde_repr = ">=0.1.12, <0.2" +thiserror = ">=1.0.40, <2.0" +tokio = { version = "1.36.0", features = ["macros"] } +tsify-next = { version = ">=0.5.4, <0.6", features = [ + "js", +], default-features = false } +uniffi = "=0.28.1" +uuid = { version = ">=1.3.3, <2.0", features = ["serde", "v4"] } +validator = { version = "0.18.1", features = ["derive"] } +wasm-bindgen = { version = ">=0.2.91, <0.3", features = ["serde-serialize"] } +wasm-bindgen-futures = "0.4.41" [workspace.lints.clippy] unused_async = "deny" @@ -49,6 +77,13 @@ opt-level = 1 [profile.release] lto = "thin" codegen-units = 1 + +# Turn off LTO on release mode for windows +# This is a workaround until this is fixed: https://github.com/rustls/rustls-platform-verifier/issues/141 +[profile.release-windows] +inherits = "release" +lto = "off" + # Stripping the binary reduces the size by ~30%, but the stacktraces won't be usable anymore. # This is fine as long as we don't have any unhandled panics, but let's keep it disabled for now # strip = true diff --git a/README.md b/README.md index 497af6547..14ca1f667 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,19 @@ To build, you will need the following in your PATH: - We recommend installing this via the [Visual Studio Build Tools](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022) +## Documentation + +Please refer to our [Contributing Docs](https://contributing.bitwarden.com/) for +[getting started](https://contributing.bitwarden.com/getting-started/sdk/) instructions and +[architectural documentation](https://contributing.bitwarden.com/architecture/sdk/). + +You can also browse the latest published documentation: + +- [docs.rs](https://docs.rs/bitwarden/latest/bitwarden/) for the public SDK. +- Or for developers of the SDK, view the internal + [API documentation](https://sdk-api-docs.bitwarden.com/bitwarden/index.html) which includes + private items. + ## Crates The project is structured as a monorepo using cargo workspaces. Some of the more noteworthy crates diff --git a/crates/bitwarden-api-api/Cargo.toml b/crates/bitwarden-api-api/Cargo.toml index bd4ec05c0..43ec79ff0 100644 --- a/crates/bitwarden-api-api/Cargo.toml +++ b/crates/bitwarden-api-api/Cargo.toml @@ -13,10 +13,14 @@ license-file.workspace = true keywords.workspace = true [dependencies] -serde = { version = ">=1.0.163, <2", features = ["derive"] } -serde_with = { version = ">=3.8, <4", default-features = false, features = ["base64", "std", "macros"] } -serde_json = ">=1.0.96, <2" -serde_repr = ">=0.1.12, <0.2" +serde = { workspace = true } +serde_with = { version = ">=3.8, <4", default-features = false, features = [ + "base64", + "std", + "macros", +] } +serde_json = { workspace = true } +serde_repr = { workspace = true } url = ">=2.5, <3" -uuid = { version = ">=1.3.3, <2", features = ["serde", "v4"] } -reqwest = { version = ">=0.12.5, <0.13", features = ["json", "multipart", "http2"], default-features = false } +uuid = { workspace = true } +reqwest = { workspace = true } diff --git a/crates/bitwarden-api-identity/Cargo.toml b/crates/bitwarden-api-identity/Cargo.toml index d101e9a9e..9d4d81a0d 100644 --- a/crates/bitwarden-api-identity/Cargo.toml +++ b/crates/bitwarden-api-identity/Cargo.toml @@ -13,10 +13,14 @@ license-file.workspace = true keywords.workspace = true [dependencies] -serde = { version = ">=1.0.163, <2", features = ["derive"] } -serde_with = { version = ">=3.8, <4", default-features = false, features = ["base64", "std", "macros"] } -serde_json = ">=1.0.96, <2" -serde_repr = ">=0.1.12, <0.2" +serde = { workspace = true } +serde_with = { version = ">=3.8, <4", default-features = false, features = [ + "base64", + "std", + "macros", +] } +serde_json = { workspace = true } +serde_repr = { workspace = true } url = ">=2.5, <3" -uuid = { version = ">=1.3.3, <2", features = ["serde", "v4"] } -reqwest = { version = ">=0.12.5, <0.13", features = ["json", "multipart", "http2"], default-features = false } +uuid = { workspace = true } +reqwest = { workspace = true } diff --git a/crates/bitwarden-core/Cargo.toml b/crates/bitwarden-core/Cargo.toml index bb7a9b15e..d212afb7a 100644 --- a/crates/bitwarden-core/Cargo.toml +++ b/crates/bitwarden-core/Cargo.toml @@ -20,58 +20,46 @@ no-memory-hardening = [ ] # Disable memory hardening features uniffi = ["bitwarden-crypto/uniffi", "dep:uniffi"] # Uniffi bindings secrets = [] # Secrets manager API +wasm = ["dep:wasm-bindgen", "dep:tsify-next"] # WASM support [dependencies] base64 = ">=0.22.1, <0.23" bitwarden-api-api = { workspace = true } bitwarden-api-identity = { workspace = true } bitwarden-crypto = { workspace = true } -chrono = { version = ">=0.4.26, <0.5", features = [ - "clock", - "serde", - "std", -], default-features = false } +chrono = { workspace = true, features = ["std"] } # We don't use this directly (it's used by rand), but we need it here to enable WASM support getrandom = { version = ">=0.2.9, <0.3", features = ["js"] } hmac = ">=0.12.1, <0.13" log = ">=0.4.18, <0.5" rand = ">=0.8.5, <0.9" -reqwest = { version = ">=0.12.5, <0.13", features = [ - "http2", - "json", -], default-features = false } -schemars = { version = ">=0.8.9, <0.9", features = ["uuid1", "chrono"] } -serde = { version = ">=1.0, <2.0", features = ["derive"] } -serde_json = ">=1.0.96, <2.0" -serde_qs = ">=0.12.0, <0.14" -serde_repr = ">=0.1.12, <0.2" +reqwest = { workspace = true } +schemars = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +serde_qs = { workspace = true } +serde_repr = { workspace = true } sha1 = ">=0.10.5, <0.11" sha2 = ">=0.10.6, <0.11" -thiserror = ">=1.0.40, <2.0" -uniffi = { version = "=0.28.1", optional = true, features = ["tokio"] } -uuid = { version = ">=1.3.3, <2.0", features = ["serde"] } -validator = { version = "0.18.1", features = ["derive"] } +thiserror = { workspace = true } +uniffi = { workspace = true, optional = true, features = ["tokio"] } +uuid = { workspace = true } +validator = { workspace = true } +wasm-bindgen = { workspace = true, optional = true } zeroize = { version = ">=1.7.0, <2.0", features = ["derive", "aarch64"] } zxcvbn = { version = ">=3.0.1, <4.0", optional = true } +tsify-next = { workspace = true, optional = true } -[target.'cfg(all(not(target_arch="wasm32"), not(windows)))'.dependencies] +[target.'cfg(not(target_arch="wasm32"))'.dependencies] # By default, we use rustls as the TLS stack and rust-platform-verifier to support user-installed root certificates # The only exception is WASM, as it just uses the browsers/node fetch -reqwest = { version = ">=0.12.5, <0.13", features = [ - "rustls-tls-manual-roots", -], default-features = false } -rustls-platform-verifier = "0.3.3" - -[target.'cfg(windows)'.dependencies] -# We are having issues with rustls-platform-verifier on Windows GitHub runners -reqwest = { version = ">=0.12.5, <0.13", features = [ - "rustls-tls-native-roots", -], default-features = false } +reqwest = { workspace = true, features = ["rustls-tls-manual-roots"] } +rustls-platform-verifier = "0.3.4" [dev-dependencies] bitwarden-crypto = { workspace = true } rand_chacha = "0.3.1" -tokio = { version = "1.36.0", features = ["rt", "macros"] } +tokio = { workspace = true, features = ["rt"] } wiremock = "0.6.0" zeroize = { version = ">=1.7.0, <2.0", features = ["derive", "aarch64"] } diff --git a/crates/bitwarden-core/src/auth/auth_request.rs b/crates/bitwarden-core/src/auth/auth_request.rs index dc9be1b90..1d6ce1802 100644 --- a/crates/bitwarden-core/src/auth/auth_request.rs +++ b/crates/bitwarden-core/src/auth/auth_request.rs @@ -6,6 +6,8 @@ use bitwarden_crypto::{ #[cfg(feature = "internal")] use bitwarden_crypto::{EncString, KeyDecryptable, SymmetricCryptoKey}; +#[cfg(feature = "internal")] +use crate::client::encryption_settings::EncryptionSettingsError; use crate::{error::Error, Client}; #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] @@ -49,7 +51,7 @@ pub(crate) fn new_auth_request(email: &str) -> Result Result { +) -> Result { let key = AsymmetricCryptoKey::from_der(&STANDARD.decode(private_key)?)?; let mut key: Vec = user_key.decrypt_with_key(&key)?; @@ -62,7 +64,7 @@ pub(crate) fn auth_request_decrypt_master_key( private_key: String, master_key: AsymmetricEncString, user_key: EncString, -) -> Result { +) -> Result { use bitwarden_crypto::MasterKey; let key = AsymmetricCryptoKey::from_der(&STANDARD.decode(private_key)?)?; diff --git a/crates/bitwarden-core/src/client/client.rs b/crates/bitwarden-core/src/client/client.rs index 5f73fcd8a..b9bf4c516 100644 --- a/crates/bitwarden-core/src/client/client.rs +++ b/crates/bitwarden-core/src/client/client.rs @@ -25,7 +25,7 @@ impl Client { #[allow(unused_mut)] let mut client_builder = reqwest::Client::builder(); - #[cfg(all(not(target_arch = "wasm32"), not(windows)))] + #[cfg(not(target_arch = "wasm32"))] { client_builder = client_builder.use_preconfigured_tls(rustls_platform_verifier::tls_config()); @@ -86,7 +86,7 @@ impl Client { #[cfg(test)] mod tests { - #[cfg(all(not(target_arch = "wasm32"), not(windows)))] + #[cfg(not(target_arch = "wasm32"))] #[test] fn test_reqwest_rustls_platform_verifier_are_compatible() { // rustls-platform-verifier is generating a rustls::ClientConfig, diff --git a/crates/bitwarden-core/src/client/client_settings.rs b/crates/bitwarden-core/src/client/client_settings.rs index bd678d131..70e2e6839 100644 --- a/crates/bitwarden-core/src/client/client_settings.rs +++ b/crates/bitwarden-core/src/client/client_settings.rs @@ -19,6 +19,11 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, JsonSchema)] #[serde(default, rename_all = "camelCase", deny_unknown_fields)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] +#[cfg_attr( + feature = "wasm", + derive(tsify_next::Tsify), + tsify(into_wasm_abi, from_wasm_abi) +)] pub struct ClientSettings { /// The identity url of the targeted Bitwarden instance. Defaults to `https://identity.bitwarden.com` pub identity_url: String, @@ -44,6 +49,11 @@ impl Default for ClientSettings { #[allow(non_camel_case_types)] #[derive(Serialize, Deserialize, Copy, Clone, Debug, JsonSchema)] #[cfg_attr(feature = "uniffi", derive(uniffi::Enum))] +#[cfg_attr( + feature = "wasm", + derive(tsify_next::Tsify), + tsify(into_wasm_abi, from_wasm_abi) +)] pub enum DeviceType { Android = 0, iOS = 1, @@ -66,6 +76,9 @@ pub enum DeviceType { VivaldiBrowser = 18, VivaldiExtension = 19, SafariExtension = 20, - SDK = 21, + Server = 22, + WindowsCLI = 23, + MacOsCLI = 24, + LinuxCLI = 25, } diff --git a/crates/bitwarden-core/src/client/encryption_settings.rs b/crates/bitwarden-core/src/client/encryption_settings.rs index 828a97139..9d9549021 100644 --- a/crates/bitwarden-core/src/client/encryption_settings.rs +++ b/crates/bitwarden-core/src/client/encryption_settings.rs @@ -3,10 +3,30 @@ use std::collections::HashMap; use bitwarden_crypto::{AsymmetricCryptoKey, CryptoError, KeyContainer, SymmetricCryptoKey}; #[cfg(feature = "internal")] use bitwarden_crypto::{AsymmetricEncString, EncString, MasterKey}; +use thiserror::Error; use uuid::Uuid; #[cfg(feature = "internal")] use crate::error::Result; +use crate::VaultLocked; + +#[derive(Debug, Error)] +pub enum EncryptionSettingsError { + #[error("Cryptography error, {0}")] + Crypto(#[from] bitwarden_crypto::CryptoError), + + #[error(transparent)] + InvalidBase64(#[from] base64::DecodeError), + + #[error(transparent)] + VaultLocked(#[from] VaultLocked), + + #[error("Invalid private key")] + InvalidPrivateKey, + + #[error("Missing private key")] + MissingPrivateKey, +} #[derive(Clone)] pub struct EncryptionSettings { @@ -28,7 +48,7 @@ impl EncryptionSettings { master_key: MasterKey, user_key: EncString, private_key: EncString, - ) -> Result { + ) -> Result { // Decrypt the user key let user_key = master_key.decrypt_user_key(user_key)?; Self::new_decrypted_key(user_key, private_key) @@ -42,12 +62,25 @@ impl EncryptionSettings { pub(crate) fn new_decrypted_key( user_key: SymmetricCryptoKey, private_key: EncString, - ) -> Result { + ) -> Result { use bitwarden_crypto::KeyDecryptable; + use log::warn; let private_key = { let dec: Vec = private_key.decrypt_with_key(&user_key)?; - Some(AsymmetricCryptoKey::from_der(&dec)?) + + // FIXME: [PM-11690] - Temporarily ignore invalid private keys until we have a recovery + // process in place. + AsymmetricCryptoKey::from_der(&dec) + .map_err(|_| { + warn!("Invalid private key"); + }) + .ok() + + // Some( + // AsymmetricCryptoKey::from_der(&dec) + // .map_err(|_| EncryptionSettingsError::InvalidPrivateKey)?, + // ) }; Ok(EncryptionSettings { @@ -72,17 +105,23 @@ impl EncryptionSettings { pub(crate) fn set_org_keys( &mut self, org_enc_keys: Vec<(Uuid, AsymmetricEncString)>, - ) -> Result<&Self> { + ) -> Result<&Self, EncryptionSettingsError> { use bitwarden_crypto::KeyDecryptable; - use crate::VaultLocked; - - let private_key = self.private_key.as_ref().ok_or(VaultLocked)?; - // Make sure we only keep the keys given in the arguments and not any of the previous // ones, which might be from organizations that the user is no longer a part of anymore self.org_keys.clear(); + // FIXME: [PM-11690] - Early abort to handle private key being corrupt + if org_enc_keys.is_empty() { + return Ok(self); + } + + let private_key = self + .private_key + .as_ref() + .ok_or(EncryptionSettingsError::MissingPrivateKey)?; + // Decrypt the org keys with the private key for (org_id, org_enc_key) in org_enc_keys { let mut dec: Vec = org_enc_key.decrypt_with_key(private_key)?; diff --git a/crates/bitwarden-core/src/client/internal.rs b/crates/bitwarden-core/src/client/internal.rs index 199e35459..d64ac75be 100644 --- a/crates/bitwarden-core/src/client/internal.rs +++ b/crates/bitwarden-core/src/client/internal.rs @@ -9,16 +9,18 @@ use uuid::Uuid; #[cfg(feature = "secrets")] use super::login_method::ServiceAccountLoginMethod; -use super::{encryption_settings::EncryptionSettings, login_method::LoginMethod}; -#[cfg(feature = "internal")] -use super::{flags::Flags, login_method::UserLoginMethod}; -#[cfg(feature = "internal")] -use crate::error::Error; use crate::{ auth::renew::renew_token, + client::{encryption_settings::EncryptionSettings, login_method::LoginMethod}, error::{Result, VaultLocked}, DeviceType, }; +#[cfg(feature = "internal")] +use crate::{ + client::encryption_settings::EncryptionSettingsError, + client::{flags::Flags, login_method::UserLoginMethod}, + error::Error, +}; #[derive(Debug, Clone)] pub struct ApiConfigurations { @@ -179,7 +181,7 @@ impl InternalClient { master_key: MasterKey, user_key: EncString, private_key: EncString, - ) -> Result<()> { + ) -> Result<(), EncryptionSettingsError> { *self .encryption_settings .write() @@ -197,7 +199,7 @@ impl InternalClient { &self, user_key: SymmetricCryptoKey, private_key: EncString, - ) -> Result<()> { + ) -> Result<(), EncryptionSettingsError> { *self .encryption_settings .write() @@ -214,7 +216,7 @@ impl InternalClient { pin_key: PinKey, pin_protected_user_key: EncString, private_key: EncString, - ) -> Result<()> { + ) -> Result<(), EncryptionSettingsError> { let decrypted_user_key = pin_key.decrypt_user_key(pin_protected_user_key)?; self.initialize_user_crypto_decrypted_key(decrypted_user_key, private_key) } @@ -232,7 +234,7 @@ impl InternalClient { pub fn initialize_org_crypto( &self, org_keys: Vec<(Uuid, AsymmetricEncString)>, - ) -> Result> { + ) -> Result, EncryptionSettingsError> { let mut guard = self .encryption_settings .write() diff --git a/crates/bitwarden-core/src/error.rs b/crates/bitwarden-core/src/error.rs index 300aba452..697ca6c99 100644 --- a/crates/bitwarden-core/src/error.rs +++ b/crates/bitwarden-core/src/error.rs @@ -9,6 +9,9 @@ use reqwest::StatusCode; use thiserror::Error; use validator::ValidationErrors; +#[cfg(feature = "internal")] +use crate::client::encryption_settings::EncryptionSettingsError; + #[derive(Debug, Error)] pub enum Error { #[error(transparent)] @@ -56,6 +59,10 @@ pub enum Error { #[error("Internal error: {0}")] Internal(Cow<'static, str>), + + #[cfg(feature = "internal")] + #[error(transparent)] + EncryptionSettings(#[from] EncryptionSettingsError), } impl From for Error { diff --git a/crates/bitwarden-core/src/mobile/client_crypto.rs b/crates/bitwarden-core/src/mobile/client_crypto.rs index 293b8f9b3..0175f2712 100644 --- a/crates/bitwarden-core/src/mobile/client_crypto.rs +++ b/crates/bitwarden-core/src/mobile/client_crypto.rs @@ -2,7 +2,7 @@ use bitwarden_crypto::{AsymmetricEncString, EncString}; use super::crypto::{derive_key_connector, DeriveKeyConnectorRequest}; -use crate::Client; +use crate::{client::encryption_settings::EncryptionSettingsError, Client}; #[cfg(feature = "internal")] use crate::{ error::Result, @@ -18,11 +18,17 @@ pub struct ClientCrypto<'a> { } impl<'a> ClientCrypto<'a> { - pub async fn initialize_user_crypto(&self, req: InitUserCryptoRequest) -> Result<()> { + pub async fn initialize_user_crypto( + &self, + req: InitUserCryptoRequest, + ) -> Result<(), EncryptionSettingsError> { initialize_user_crypto(self.client, req).await } - pub async fn initialize_org_crypto(&self, req: InitOrgCryptoRequest) -> Result<()> { + pub async fn initialize_org_crypto( + &self, + req: InitOrgCryptoRequest, + ) -> Result<(), EncryptionSettingsError> { initialize_org_crypto(self.client, req).await } diff --git a/crates/bitwarden-core/src/mobile/crypto.rs b/crates/bitwarden-core/src/mobile/crypto.rs index 15ddeb9b7..2aae903c5 100644 --- a/crates/bitwarden-core/src/mobile/crypto.rs +++ b/crates/bitwarden-core/src/mobile/crypto.rs @@ -8,7 +8,7 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use crate::{ - client::{LoginMethod, UserLoginMethod}, + client::{encryption_settings::EncryptionSettingsError, LoginMethod, UserLoginMethod}, error::{Error, Result}, Client, }; @@ -86,7 +86,10 @@ pub enum AuthRequestMethod { }, } -pub async fn initialize_user_crypto(client: &Client, req: InitUserCryptoRequest) -> Result<()> { +pub async fn initialize_user_crypto( + client: &Client, + req: InitUserCryptoRequest, +) -> Result<(), EncryptionSettingsError> { use bitwarden_crypto::{DeviceKey, PinKey}; use crate::auth::{auth_request_decrypt_master_key, auth_request_decrypt_user_key}; @@ -187,7 +190,10 @@ pub struct InitOrgCryptoRequest { pub organization_keys: HashMap, } -pub async fn initialize_org_crypto(client: &Client, req: InitOrgCryptoRequest) -> Result<()> { +pub async fn initialize_org_crypto( + client: &Client, + req: InitOrgCryptoRequest, +) -> Result<(), EncryptionSettingsError> { let organization_keys = req.organization_keys.into_iter().collect(); client.internal.initialize_org_crypto(organization_keys)?; Ok(()) diff --git a/crates/bitwarden-crypto/Cargo.toml b/crates/bitwarden-crypto/Cargo.toml index b071b4ee9..3254640fe 100644 --- a/crates/bitwarden-crypto/Cargo.toml +++ b/crates/bitwarden-crypto/Cargo.toml @@ -36,20 +36,20 @@ pbkdf2 = { version = ">=0.12.1, <0.13", default-features = false } rand = ">=0.8.5, <0.9" rayon = ">=1.8.1, <2.0" rsa = ">=0.9.2, <0.10" -schemars = { version = ">=0.8, <0.9", features = ["uuid1"] } -serde = { version = ">=1.0, <2.0", features = ["derive"] } +schemars = { workspace = true } +serde = { workspace = true } sha1 = ">=0.10.5, <0.11" sha2 = ">=0.10.6, <0.11" subtle = ">=2.5.0, <3.0" -thiserror = ">=1.0.40, <2.0" -uniffi = { version = "=0.28.1", optional = true } -uuid = { version = ">=1.3.3, <2.0", features = ["serde"] } +thiserror = { workspace = true } +uniffi = { workspace = true, optional = true } +uuid = { workspace = true } zeroize = { version = ">=1.7.0, <2.0", features = ["derive", "aarch64"] } [dev-dependencies] criterion = "0.5.1" rand_chacha = "0.3.1" -serde_json = ">=1.0.96, <2.0" +serde_json = { workspace = true } [[bench]] name = "default_allocator" diff --git a/crates/bitwarden-crypto/src/enc_string/symmetric.rs b/crates/bitwarden-crypto/src/enc_string/symmetric.rs index eb1220e29..1fc9b3a9d 100644 --- a/crates/bitwarden-crypto/src/enc_string/symmetric.rs +++ b/crates/bitwarden-crypto/src/enc_string/symmetric.rs @@ -237,6 +237,10 @@ impl KeyDecryptable> for EncString { fn decrypt_with_key(&self, key: &SymmetricCryptoKey) -> Result> { match self { EncString::AesCbc256_B64 { iv, data } => { + if key.mac_key.is_some() { + return Err(CryptoError::MacNotProvided); + } + let dec = crate::aes::decrypt_aes256(iv, data.clone(), &key.key)?; Ok(dec) } @@ -296,7 +300,9 @@ mod tests { use schemars::schema_for; use super::EncString; - use crate::{derive_symmetric_key, KeyDecryptable, KeyEncryptable, SymmetricCryptoKey}; + use crate::{ + derive_symmetric_key, CryptoError, KeyDecryptable, KeyEncryptable, SymmetricCryptoKey, + }; #[test] fn test_enc_string_roundtrip() { @@ -418,6 +424,24 @@ mod tests { assert_eq!(dec_str, "EncryptMe!"); } + #[test] + fn test_decrypt_downgrade_encstring_prevention() { + // Simulate a potential downgrade attack by removing the mac portion of the `EncString` and + // attempt to decrypt it using a `SymmetricCryptoKey` with a mac key. + let key = "hvBMMb1t79YssFZkpetYsM3deyVuQv4r88Uj9gvYe0+G8EwxvW3v1iywVmSl61iwzd17JW5C/ivzxSP2C9h7Tw==".to_string(); + let key = SymmetricCryptoKey::try_from(key).unwrap(); + + // A "downgraded" `EncString` from `EncString::AesCbc256_HmacSha256_B64` (2) to + // `EncString::AesCbc256_B64` (0), with the mac portion removed. + // + let enc_str = "0.NQfjHLr6za7VQVAbrpL81w==|wfrjmyJ0bfwkQlySrhw8dA=="; + let enc_string: EncString = enc_str.parse().unwrap(); + assert_eq!(enc_string.enc_type(), 0); + + let result: Result = enc_string.decrypt_with_key(&key); + assert!(matches!(result, Err(CryptoError::MacNotProvided))); + } + #[test] fn test_decrypt_cbc128_hmac() { let key = "Gt1aZ8kTTgkF80bLtb7LiMZBcxEA2FA5mbvV4x7K208=".to_string(); diff --git a/crates/bitwarden-crypto/src/error.rs b/crates/bitwarden-crypto/src/error.rs index 2fc4d2591..2f9a58b8b 100644 --- a/crates/bitwarden-crypto/src/error.rs +++ b/crates/bitwarden-crypto/src/error.rs @@ -11,6 +11,8 @@ pub enum CryptoError { InvalidKey, #[error("The cipher's MAC doesn't match the expected value")] InvalidMac, + #[error("The key provided expects mac protected encstrings, but the mac is missing")] + MacNotProvided, #[error("Error while decrypting EncString")] KeyDecrypt, #[error("The cipher key has an invalid length")] @@ -22,6 +24,9 @@ pub enum CryptoError { #[error("The item was missing a required field: {0}")] MissingField(&'static str), + #[error("Insufficient KDF parameters")] + InsufficientKdfParameters, + #[error("EncString error, {0}")] EncString(#[from] EncStringParseError), diff --git a/crates/bitwarden-crypto/src/keys/shareable_key.rs b/crates/bitwarden-crypto/src/keys/shareable_key.rs index 556432aea..c6a44405c 100644 --- a/crates/bitwarden-crypto/src/keys/shareable_key.rs +++ b/crates/bitwarden-crypto/src/keys/shareable_key.rs @@ -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, @@ -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>> = 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") } diff --git a/crates/bitwarden-crypto/src/keys/utils.rs b/crates/bitwarden-crypto/src/keys/utils.rs index 8564a7c9f..4b2c4c8cd 100644 --- a/crates/bitwarden-crypto/src/keys/utils.rs +++ b/crates/bitwarden-crypto/src/keys/utils.rs @@ -3,30 +3,45 @@ use std::pin::Pin; use generic_array::{typenum::U32, GenericArray}; use sha2::Digest; -use crate::{util::hkdf_expand, Kdf, Result, SymmetricCryptoKey}; +use crate::{util::hkdf_expand, CryptoError, Kdf, Result, SymmetricCryptoKey}; + +const PBKDF2_MIN_ITERATIONS: u32 = 5000; + +const ARGON2ID_MIN_MEMORY: u32 = 16 * 1024; +const ARGON2ID_MIN_ITERATIONS: u32 = 2; +const ARGON2ID_MIN_PARALLELISM: u32 = 1; /// Derive a generic key from a secret and salt using the provided KDF. pub(super) fn derive_kdf_key(secret: &[u8], salt: &[u8], kdf: &Kdf) -> Result { let mut hash = match kdf { - Kdf::PBKDF2 { iterations } => crate::util::pbkdf2(secret, salt, iterations.get()), + Kdf::PBKDF2 { iterations } => { + let iterations = iterations.get(); + if iterations < PBKDF2_MIN_ITERATIONS { + return Err(CryptoError::InsufficientKdfParameters); + } + crate::util::pbkdf2(secret, salt, iterations) + } Kdf::Argon2id { iterations, memory, parallelism, } => { + let memory = memory.get() * 1024; // Convert MiB to KiB; + let iterations = iterations.get(); + let parallelism = parallelism.get(); + + if memory < ARGON2ID_MIN_MEMORY + || iterations < ARGON2ID_MIN_ITERATIONS + || parallelism < ARGON2ID_MIN_PARALLELISM + { + return Err(CryptoError::InsufficientKdfParameters); + } + use argon2::*; - let argon = Argon2::new( - Algorithm::Argon2id, - Version::V0x13, - Params::new( - memory.get() * 1024, // Convert MiB to KiB - iterations.get(), - parallelism.get(), - Some(32), - )?, - ); + let params = Params::new(memory, iterations, parallelism, Some(32))?; + let argon = Argon2::new(Algorithm::Argon2id, Version::V0x13, params); let salt_sha = sha2::Sha256::new().chain_update(salt).finalize(); @@ -57,6 +72,8 @@ pub(super) fn stretch_kdf_key(k: &SymmetricCryptoKey) -> Result NonZero { + NonZero::new(n).unwrap() + } + + let secret = [0u8; 32]; + let salt = [0u8; 32]; + + for kdf in [ + Kdf::PBKDF2 { + iterations: nz(4999), + }, + Kdf::Argon2id { + iterations: nz(1), + memory: nz(16), + parallelism: nz(1), + }, + Kdf::Argon2id { + iterations: nz(2), + memory: nz(15), + parallelism: nz(1), + }, + Kdf::Argon2id { + iterations: nz(1), + memory: nz(15), + parallelism: nz(1), + }, + ] { + assert_eq!( + derive_kdf_key(&secret, &salt, &kdf) + .unwrap_err() + .to_string(), + "Insufficient KDF parameters" + ); + } + } } diff --git a/crates/bitwarden-exporters/Cargo.toml b/crates/bitwarden-exporters/Cargo.toml index 858e9f522..38cf49953 100644 --- a/crates/bitwarden-exporters/Cargo.toml +++ b/crates/bitwarden-exporters/Cargo.toml @@ -22,18 +22,14 @@ base64 = ">=0.22.1, <0.23" bitwarden-core = { workspace = true } bitwarden-crypto = { workspace = true } bitwarden-vault = { workspace = true } -chrono = { version = ">=0.4.26, <0.5", features = [ - "clock", - "serde", - "std", -], default-features = false } +chrono = { workspace = true, features = ["std"] } csv = "1.3.0" -schemars = { version = ">=0.8.9, <0.9", features = ["uuid1", "chrono"] } -serde = { version = ">=1.0, <2.0", features = ["derive"] } -serde_json = ">=1.0.96, <2.0" -thiserror = ">=1.0.40, <2.0" -uniffi = { version = "=0.28.1", optional = true } -uuid = { version = ">=1.3.3, <2.0", features = ["serde", "v4"] } +schemars = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +thiserror = { workspace = true } +uniffi = { workspace = true, optional = true } +uuid = { workspace = true } [lints] workspace = true diff --git a/crates/bitwarden-fido/Cargo.toml b/crates/bitwarden-fido/Cargo.toml index e85e56a19..20f5cdaf6 100644 --- a/crates/bitwarden-fido/Cargo.toml +++ b/crates/bitwarden-fido/Cargo.toml @@ -22,22 +22,22 @@ base64 = ">=0.22.1, <0.23" bitwarden-core = { workspace = true } bitwarden-crypto = { workspace = true } bitwarden-vault = { workspace = true } -chrono = { version = ">=0.4.26, <0.5", features = [ - "clock", - "serde", -], default-features = false } +chrono = { workspace = true } coset = { version = "0.3.7" } itertools = "0.13.0" log = ">=0.4.18, <0.5" p256 = { version = ">=0.13.2, <0.14" } -passkey = { git = "https://github.com/bitwarden/passkey-rs", rev = "ae08e2cb7dd3d44d915caed395c0cdc56b50fa27" } -reqwest = { version = ">=0.12.5, <0.13", default-features = false } -schemars = { version = "0.8.21", features = ["uuid1", "chrono"] } -serde = { version = ">=1.0, <2.0", features = ["derive"] } -serde_json = ">=1.0.96, <2.0" -thiserror = ">=1.0.40, <2.0" -uniffi = { version = "=0.28.1", optional = true } -uuid = { version = ">=1.3.3, <2.0", features = ["serde"] } +passkey = { git = "https://github.com/bitwarden/passkey-rs", rev = "ff757604cd7b4e8f321ed1616fef7e40e21ac5df" } +passkey-client = { git = "https://github.com/bitwarden/passkey-rs", rev = "ff757604cd7b4e8f321ed1616fef7e40e21ac5df", features = [ + "android-asset-validation", +] } +reqwest = { workspace = true } +schemars = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +thiserror = { workspace = true } +uniffi = { workspace = true, optional = true } +uuid = { workspace = true } [lints] workspace = true diff --git a/crates/bitwarden-fido/src/client.rs b/crates/bitwarden-fido/src/client.rs index a72dae6f5..ac4330be7 100644 --- a/crates/bitwarden-fido/src/client.rs +++ b/crates/bitwarden-fido/src/client.rs @@ -1,5 +1,4 @@ use passkey::client::WebauthnError; -use reqwest::Url; use thiserror::Error; use super::{ @@ -7,15 +6,12 @@ use super::{ get_string_name_from_enum, types::{ AuthenticatorAssertionResponse, AuthenticatorAttestationResponse, ClientData, - ClientExtensionResults, CredPropsResult, + ClientExtensionResults, CredPropsResult, Origin, }, Fido2Authenticator, PublicKeyCredentialAuthenticatorAssertionResponse, PublicKeyCredentialAuthenticatorAttestationResponse, }; - -#[derive(Debug, Error)] -#[error("Invalid origin: {0}")] -pub struct InvalidOriginError(String); +use crate::types::InvalidOriginError; #[derive(Debug, Error)] pub enum Fido2ClientError { @@ -43,12 +39,11 @@ pub struct Fido2Client<'a> { impl<'a> Fido2Client<'a> { pub async fn register( &mut self, - origin: String, + origin: Origin, request: String, client_data: ClientData, ) -> Result { - let origin = Url::parse(&origin).map_err(|e| InvalidOriginError(format!("{}", e)))?; - + let origin: passkey::client::Origin = origin.try_into()?; let request: passkey::types::webauthn::CredentialCreationOptions = serde_json::from_str(&request)?; @@ -67,7 +62,7 @@ impl<'a> Fido2Client<'a> { let rp_id = request.public_key.rp.id.clone(); let mut client = passkey::client::Client::new(self.authenticator.get_authenticator(true)); - let result = client.register(&origin, request, client_data).await?; + let result = client.register(origin, request, client_data).await?; Ok(PublicKeyCredentialAuthenticatorAttestationResponse { id: result.id, @@ -98,12 +93,11 @@ impl<'a> Fido2Client<'a> { pub async fn authenticate( &mut self, - origin: String, + origin: Origin, request: String, client_data: ClientData, ) -> Result { - let origin = Url::parse(&origin).map_err(|e| InvalidOriginError(format!("{}", e)))?; - + let origin: passkey::client::Origin = origin.try_into()?; let request: passkey::types::webauthn::CredentialRequestOptions = serde_json::from_str(&request)?; @@ -116,7 +110,7 @@ impl<'a> Fido2Client<'a> { .replace(uv); let mut client = passkey::client::Client::new(self.authenticator.get_authenticator(false)); - let result = client.authenticate(&origin, request, client_data).await?; + let result = client.authenticate(origin, request, client_data).await?; Ok(PublicKeyCredentialAuthenticatorAssertionResponse { id: result.id, diff --git a/crates/bitwarden-fido/src/lib.rs b/crates/bitwarden-fido/src/lib.rs index 991828eb3..be1dfdb53 100644 --- a/crates/bitwarden-fido/src/lib.rs +++ b/crates/bitwarden-fido/src/lib.rs @@ -32,10 +32,10 @@ pub use traits::{ pub use types::{ AuthenticatorAssertionResponse, AuthenticatorAttestationResponse, ClientData, Fido2CredentialAutofillView, Fido2CredentialAutofillViewError, GetAssertionRequest, - GetAssertionResult, MakeCredentialRequest, MakeCredentialResult, Options, + GetAssertionResult, MakeCredentialRequest, MakeCredentialResult, Options, Origin, PublicKeyCredentialAuthenticatorAssertionResponse, PublicKeyCredentialAuthenticatorAttestationResponse, PublicKeyCredentialRpEntity, - PublicKeyCredentialUserEntity, + PublicKeyCredentialUserEntity, UnverifiedAssetLink, }; use self::crypto::{cose_key_to_pkcs8, pkcs8_to_cose_key}; diff --git a/crates/bitwarden-fido/src/types.rs b/crates/bitwarden-fido/src/types.rs index 8bc8ae42c..409db7a98 100644 --- a/crates/bitwarden-fido/src/types.rs +++ b/crates/bitwarden-fido/src/types.rs @@ -1,7 +1,10 @@ +use std::borrow::Cow; + use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine}; use bitwarden_crypto::KeyContainer; use bitwarden_vault::{CipherError, CipherView}; use passkey::types::webauthn::UserVerificationRequirement; +use reqwest::Url; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -359,6 +362,67 @@ pub struct AuthenticatorAssertionResponse { pub user_handle: Vec, } +#[derive(Debug, Error)] +#[error("Invalid origin: {0}")] +pub struct InvalidOriginError(String); + +#[cfg_attr(feature = "uniffi", derive(uniffi::Record))] +/// An Unverified asset link. +pub struct UnverifiedAssetLink { + /// Application package name. + package_name: String, + /// Fingerprint to compare. + sha256_cert_fingerprint: String, + /// Host to lookup the well known asset link. + host: String, + /// When sourced from the application statement list or parsed from host for passkeys. + /// Will be generated from `host` if not provided. + asset_link_url: Option, +} + +#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))] +/// The origin of a WebAuthn request. +pub enum Origin { + /// A Url, meant for a request in the web browser. + Web(String), + /// An android digital asset fingerprint. + /// Meant for a request coming from an android application. + Android(UnverifiedAssetLink), +} + +impl<'a> TryFrom for passkey::client::Origin<'a> { + type Error = InvalidOriginError; + + fn try_from(value: Origin) -> Result { + Ok(match value { + Origin::Web(url) => { + let url = Url::parse(&url).map_err(|e| InvalidOriginError(format!("{}", e)))?; + passkey::client::Origin::Web(Cow::Owned(url)) + } + Origin::Android(link) => passkey::client::Origin::Android(link.try_into()?), + }) + } +} + +impl<'a> TryFrom for passkey::client::UnverifiedAssetLink<'a> { + type Error = InvalidOriginError; + + fn try_from(value: UnverifiedAssetLink) -> Result { + let asset_link_url = match value.asset_link_url { + Some(url) => Some(Url::parse(&url).map_err(|e| InvalidOriginError(format!("{}", e)))?), + None => None, + }; + + passkey::client::UnverifiedAssetLink::new( + Cow::from(value.package_name), + value.sha256_cert_fingerprint.as_str(), + Cow::from(value.host), + asset_link_url, + ) + .map_err(|e| InvalidOriginError(format!("{:?}", e))) + } +} + #[cfg(test)] mod tests { use serde::{Deserialize, Serialize}; diff --git a/crates/bitwarden-generators/Cargo.toml b/crates/bitwarden-generators/Cargo.toml index 442e00c08..24e5d5ebc 100644 --- a/crates/bitwarden-generators/Cargo.toml +++ b/crates/bitwarden-generators/Cargo.toml @@ -20,19 +20,16 @@ uniffi = ["dep:uniffi"] # Uniffi bindings bitwarden-core = { workspace = true, features = ["internal"] } bitwarden-crypto = { workspace = true } rand = ">=0.8.5, <0.9" -reqwest = { version = ">=0.12.5, <0.13", features = [ - "http2", - "json", -], default-features = false } -schemars = { version = ">=0.8.9, <0.9", features = ["uuid1", "chrono"] } -serde = { version = ">=1.0, <2.0", features = ["derive"] } -serde_json = ">=1.0.96, <2.0" -thiserror = ">=1.0.40, <2.0" -uniffi = { version = "=0.28.1", optional = true } +reqwest = { workspace = true } +schemars = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +thiserror = { workspace = true } +uniffi = { workspace = true, optional = true } [dev-dependencies] rand_chacha = "0.3.1" -tokio = { version = "1.36.0", features = ["rt", "macros"] } +tokio = { workspace = true, features = ["rt"] } wiremock = "0.6.0" [lints] diff --git a/crates/bitwarden-generators/src/client_generator.rs b/crates/bitwarden-generators/src/client_generator.rs index e5bad6f29..d2e2b7483 100644 --- a/crates/bitwarden-generators/src/client_generator.rs +++ b/crates/bitwarden-generators/src/client_generator.rs @@ -1,8 +1,9 @@ use bitwarden_core::Client; use crate::{ - passphrase, password, username, PassphraseError, PassphraseGeneratorRequest, PasswordError, - PasswordGeneratorRequest, UsernameError, UsernameGeneratorRequest, + passphrase::passphrase, password::password, username::username, PassphraseError, + PassphraseGeneratorRequest, PasswordError, PasswordGeneratorRequest, UsernameError, + UsernameGeneratorRequest, }; pub struct ClientGenerator<'a> { diff --git a/crates/bitwarden-generators/src/lib.rs b/crates/bitwarden-generators/src/lib.rs index 0ebd20295..6455a759a 100644 --- a/crates/bitwarden-generators/src/lib.rs +++ b/crates/bitwarden-generators/src/lib.rs @@ -1,13 +1,13 @@ -mod passphrase; -pub use passphrase::{passphrase, PassphraseError, PassphraseGeneratorRequest}; -mod password; -mod util; -pub use password::{password, PasswordError, PasswordGeneratorRequest}; -mod username; -pub use username::{username, ForwarderServiceType, UsernameError, UsernameGeneratorRequest}; mod client_generator; -pub use client_generator::{ClientGenerator, ClientGeneratorExt}; mod username_forwarders; +pub use client_generator::{ClientGenerator, ClientGeneratorExt}; +pub(crate) mod passphrase; +pub use passphrase::{PassphraseError, PassphraseGeneratorRequest}; +pub(crate) mod password; +pub use password::{PasswordError, PasswordGeneratorRequest}; +pub(crate) mod username; +pub use username::{ForwarderServiceType, UsernameError, UsernameGeneratorRequest}; +mod util; #[cfg(feature = "uniffi")] uniffi::setup_scaffolding!(); diff --git a/crates/bitwarden-generators/src/passphrase.rs b/crates/bitwarden-generators/src/passphrase.rs index 94b2c0acd..1fb83422e 100644 --- a/crates/bitwarden-generators/src/passphrase.rs +++ b/crates/bitwarden-generators/src/passphrase.rs @@ -77,7 +77,7 @@ impl PassphraseGeneratorRequest { } /// Implementation of the random passphrase generator. -pub fn passphrase(request: PassphraseGeneratorRequest) -> Result { +pub(crate) fn passphrase(request: PassphraseGeneratorRequest) -> Result { let options = request.validate_options()?; Ok(passphrase_with_rng(rand::thread_rng(), options)) } diff --git a/crates/bitwarden-generators/src/password.rs b/crates/bitwarden-generators/src/password.rs index 6121c7597..9821f8bbe 100644 --- a/crates/bitwarden-generators/src/password.rs +++ b/crates/bitwarden-generators/src/password.rs @@ -219,7 +219,7 @@ impl PasswordGeneratorRequest { } /// Implementation of the random password generator. -pub fn password(input: PasswordGeneratorRequest) -> Result { +pub(crate) fn password(input: PasswordGeneratorRequest) -> Result { let options = input.validate_options()?; Ok(password_with_rng(rand::thread_rng(), options)) } diff --git a/crates/bitwarden-generators/src/username.rs b/crates/bitwarden-generators/src/username.rs index 830cb5b04..0140f77fb 100644 --- a/crates/bitwarden-generators/src/username.rs +++ b/crates/bitwarden-generators/src/username.rs @@ -131,7 +131,7 @@ impl ForwarderServiceType { /// /// Note: The HTTP client is passed in as a required parameter for convenience, /// as some username generators require making API calls. -pub async fn username( +pub(crate) async fn username( input: UsernameGeneratorRequest, http: &reqwest::Client, ) -> Result { diff --git a/crates/bitwarden-json/Cargo.toml b/crates/bitwarden-json/Cargo.toml index 095c02402..dd703b9d7 100644 --- a/crates/bitwarden-json/Cargo.toml +++ b/crates/bitwarden-json/Cargo.toml @@ -22,9 +22,9 @@ secrets = ["bitwarden/secrets"] # Secrets manager API [dependencies] bitwarden = { workspace = true } log = ">=0.4.18, <0.5" -schemars = ">=0.8.12, <0.9" -serde = { version = ">=1.0, <2.0", features = ["derive"] } -serde_json = ">=1.0.96, <2.0" +schemars = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } [target.'cfg(debug_assertions)'.dependencies] tokio = { version = "1.36.0", features = ["time"] } diff --git a/crates/bitwarden-json/src/client.rs b/crates/bitwarden-json/src/client.rs index 71f57cc3d..55c08c2e5 100644 --- a/crates/bitwarden-json/src/client.rs +++ b/crates/bitwarden-json/src/client.rs @@ -1,10 +1,11 @@ -#[cfg(feature = "secrets")] -use bitwarden::secrets_manager::{ - generators::ClientGeneratorExt, ClientProjectsExt, ClientSecretsExt, -}; #[cfg(feature = "internal")] use bitwarden::vault::ClientVaultExt; use bitwarden::ClientSettings; +#[cfg(feature = "secrets")] +use bitwarden::{ + generators::ClientGeneratorExt, + secrets_manager::{ClientProjectsExt, ClientSecretsExt}, +}; #[cfg(feature = "secrets")] use crate::command::{GeneratorsCommand, ProjectsCommand, SecretsCommand}; diff --git a/crates/bitwarden-json/src/command.rs b/crates/bitwarden-json/src/command.rs index 26a3471bd..132925b0c 100644 --- a/crates/bitwarden-json/src/command.rs +++ b/crates/bitwarden-json/src/command.rs @@ -1,8 +1,8 @@ #[cfg(feature = "secrets")] use bitwarden::{ auth::login::AccessTokenLoginRequest, + generators::PasswordGeneratorRequest, secrets_manager::{ - generators::PasswordGeneratorRequest, projects::{ ProjectCreateRequest, ProjectGetRequest, ProjectPutRequest, ProjectsDeleteRequest, ProjectsListRequest, diff --git a/crates/bitwarden-napi/Cargo.toml b/crates/bitwarden-napi/Cargo.toml index 7bcd54aad..7a9deeb8f 100644 --- a/crates/bitwarden-napi/Cargo.toml +++ b/crates/bitwarden-napi/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bitwarden-napi" -version = "0.3.1" +version = "1.0.0" description = """ N-API bindings for the Bitwarden Secrets Manager SDK """ @@ -22,7 +22,7 @@ bitwarden-json = { path = "../bitwarden-json", version = "0.3.0", features = [ "secrets", ] } env_logger = "0.11.1" -log = "0.4.20" +log = { workspace = true } napi = { version = "2", features = ["async"] } napi-derive = "2" diff --git a/crates/bitwarden-napi/README.md b/crates/bitwarden-napi/README.md index e9c3d0a71..6fce8d069 100644 --- a/crates/bitwarden-napi/README.md +++ b/crates/bitwarden-napi/README.md @@ -17,11 +17,12 @@ const settings: ClientSettings = { }; const accessToken = "-- REDACTED --"; +const stateFile = "some/path/to/state/file"; const client = new BitwardenClient(settings, LogLevel.Info); // Authenticating using a machine account access token -await client.accessTokenLogin(accessToken); +await client.auth().loginAccessToken(accessToken, stateFile); // List secrets const secrets = await client.secrets().list(); diff --git a/crates/bitwarden-napi/npm/darwin-arm64/package.json b/crates/bitwarden-napi/npm/darwin-arm64/package.json index 52d785d87..88e3122c5 100644 --- a/crates/bitwarden-napi/npm/darwin-arm64/package.json +++ b/crates/bitwarden-napi/npm/darwin-arm64/package.json @@ -1,6 +1,6 @@ { "name": "@bitwarden/sdk-napi-darwin-arm64", - "version": "0.3.1", + "version": "1.0.0", "homepage": "https://github.com/bitwarden/sdk#readme", "bugs": { "url": "https://github.com/bitwarden/sdk/issues" diff --git a/crates/bitwarden-napi/npm/darwin-x64/package.json b/crates/bitwarden-napi/npm/darwin-x64/package.json index 0a1b06423..4650654ce 100644 --- a/crates/bitwarden-napi/npm/darwin-x64/package.json +++ b/crates/bitwarden-napi/npm/darwin-x64/package.json @@ -1,6 +1,6 @@ { "name": "@bitwarden/sdk-napi-darwin-x64", - "version": "0.3.1", + "version": "1.0.0", "homepage": "https://github.com/bitwarden/sdk#readme", "bugs": { "url": "https://github.com/bitwarden/sdk/issues" diff --git a/crates/bitwarden-napi/npm/linux-x64-gnu/package.json b/crates/bitwarden-napi/npm/linux-x64-gnu/package.json index 2284d8415..ed3b62f80 100644 --- a/crates/bitwarden-napi/npm/linux-x64-gnu/package.json +++ b/crates/bitwarden-napi/npm/linux-x64-gnu/package.json @@ -1,6 +1,6 @@ { "name": "@bitwarden/sdk-napi-linux-x64-gnu", - "version": "0.3.1", + "version": "1.0.0", "homepage": "https://github.com/bitwarden/sdk#readme", "bugs": { "url": "https://github.com/bitwarden/sdk/issues" diff --git a/crates/bitwarden-napi/npm/win32-x64-msvc/package.json b/crates/bitwarden-napi/npm/win32-x64-msvc/package.json index 261554e93..5b2a93121 100644 --- a/crates/bitwarden-napi/npm/win32-x64-msvc/package.json +++ b/crates/bitwarden-napi/npm/win32-x64-msvc/package.json @@ -1,6 +1,6 @@ { "name": "@bitwarden/sdk-napi-win32-x64-msvc", - "version": "0.3.1", + "version": "1.0.0", "homepage": "https://github.com/bitwarden/sdk#readme", "bugs": { "url": "https://github.com/bitwarden/sdk/issues" diff --git a/crates/bitwarden-napi/package-lock.json b/crates/bitwarden-napi/package-lock.json index 8082a7a80..eaa8d3473 100644 --- a/crates/bitwarden-napi/package-lock.json +++ b/crates/bitwarden-napi/package-lock.json @@ -1,12 +1,12 @@ { "name": "@bitwarden/sdk-napi", - "version": "0.3.1", + "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@bitwarden/sdk-napi", - "version": "0.3.1", + "version": "1.0.0", "license": "SEE LICENSE IN LICENSE", "devDependencies": { "@napi-rs/cli": "2.18.4", diff --git a/crates/bitwarden-napi/package.json b/crates/bitwarden-napi/package.json index 9f1048d18..31cee632b 100644 --- a/crates/bitwarden-napi/package.json +++ b/crates/bitwarden-napi/package.json @@ -1,6 +1,6 @@ { "name": "@bitwarden/sdk-napi", - "version": "0.3.1", + "version": "1.0.0", "homepage": "https://github.com/bitwarden/sdk#readme", "bugs": { "url": "https://github.com/bitwarden/sdk/issues" diff --git a/crates/bitwarden-napi/src-ts/bitwarden_client/index.ts b/crates/bitwarden-napi/src-ts/bitwarden_client/index.ts index 52a53ef4f..3a3765a12 100644 --- a/crates/bitwarden-napi/src-ts/bitwarden_client/index.ts +++ b/crates/bitwarden-napi/src-ts/bitwarden_client/index.ts @@ -37,19 +37,6 @@ export class BitwardenClient { this.client = new rust.BitwardenClient(settingsJson, loggingLevel ?? LogLevel.Info); } - async accessTokenLogin(accessToken: string, stateFile?: string): Promise { - const response = await this.client.runCommand( - Convert.commandToJson({ - accessTokenLogin: { - accessToken, - stateFile, - }, - }), - ); - - handleResponse(Convert.toResponseForAccessTokenLoginResponse(response)); - } - secrets(): SecretsClient { return new SecretsClient(this.client); } @@ -57,6 +44,10 @@ export class BitwardenClient { projects(): ProjectsClient { return new ProjectsClient(this.client); } + + auth(): AuthClient { + return new AuthClient(this.client); + } } export class SecretsClient { @@ -91,11 +82,11 @@ export class SecretsClient { } async create( + organizationId: string, key: string, value: string, note: string, projectIds: string[], - organizationId: string, ): Promise { const response = await this.client.runCommand( Convert.commandToJson({ @@ -121,12 +112,12 @@ export class SecretsClient { } async update( + organizationId: string, id: string, key: string, value: string, note: string, projectIds: string[], - organizationId: string, ): Promise { const response = await this.client.runCommand( Convert.commandToJson({ @@ -183,7 +174,7 @@ export class ProjectsClient { return handleResponse(Convert.toResponseForProjectResponse(response)); } - async create(name: string, organizationId: string): Promise { + async create(organizationId: string, name: string): Promise { const response = await this.client.runCommand( Convert.commandToJson({ projects: { @@ -207,7 +198,7 @@ export class ProjectsClient { return handleResponse(Convert.toResponseForProjectsResponse(response)); } - async update(id: string, name: string, organizationId: string): Promise { + async update(organizationId: string, id: string, name: string): Promise { const response = await this.client.runCommand( Convert.commandToJson({ projects: { @@ -231,3 +222,24 @@ export class ProjectsClient { return handleResponse(Convert.toResponseForProjectsDeleteResponse(response)); } } + +export class AuthClient { + client: rust.BitwardenClient; + + constructor(client: rust.BitwardenClient) { + this.client = client; + } + + async loginAccessToken(accessToken: string, stateFile?: string): Promise { + const response = await this.client.runCommand( + Convert.commandToJson({ + loginAccessToken: { + accessToken, + stateFile, + }, + }), + ); + + handleResponse(Convert.toResponseForAccessTokenLoginResponse(response)); + } +} diff --git a/crates/bitwarden-py/Cargo.toml b/crates/bitwarden-py/Cargo.toml index c66a35889..b637d5faa 100644 --- a/crates/bitwarden-py/Cargo.toml +++ b/crates/bitwarden-py/Cargo.toml @@ -24,7 +24,7 @@ pyo3-log = "0.11.0" pyo3-build-config = { version = "0.22.1" } [target.'cfg(not(target_arch="wasm32"))'.dependencies] -tokio = { version = "1.36.0", features = ["rt-multi-thread", "macros"] } +tokio = { workspace = true, features = ["rt-multi-thread"] } [lints] workspace = true diff --git a/crates/bitwarden-send/Cargo.toml b/crates/bitwarden-send/Cargo.toml index 417cac89e..33c0b76c6 100644 --- a/crates/bitwarden-send/Cargo.toml +++ b/crates/bitwarden-send/Cargo.toml @@ -25,16 +25,13 @@ base64 = ">=0.22.1, <0.23" bitwarden-api-api = { workspace = true } bitwarden-core = { workspace = true } bitwarden-crypto = { workspace = true } -chrono = { version = ">=0.4.26, <0.5", features = [ - "clock", - "serde", -], default-features = false } -schemars = { version = ">=0.8.9, <0.9", features = ["uuid1", "chrono"] } -serde = { version = ">=1.0, <2.0", features = ["derive"] } -serde_repr = ">=0.1.12, <0.2" -thiserror = ">=1.0.40, <2.0" -uniffi = { version = "=0.28.1", optional = true } -uuid = { version = ">=1.3.3, <2.0", features = ["serde"] } +chrono = { workspace = true } +schemars = { workspace = true } +serde = { workspace = true } +serde_repr = { workspace = true } +thiserror = { workspace = true } +uniffi = { workspace = true, optional = true } +uuid = { workspace = true } zeroize = { version = ">=1.7.0, <2.0" } [lints] diff --git a/crates/bitwarden-sm/Cargo.toml b/crates/bitwarden-sm/Cargo.toml index 882780001..77fa9d7c1 100644 --- a/crates/bitwarden-sm/Cargo.toml +++ b/crates/bitwarden-sm/Cargo.toml @@ -17,19 +17,16 @@ keywords.workspace = true bitwarden-api-api = { workspace = true } bitwarden-core = { workspace = true } bitwarden-crypto = { workspace = true } -chrono = { version = ">=0.4.26, <0.5", features = [ - "clock", - "serde", -], default-features = false } -schemars = { version = ">=0.8.9, <0.9", features = ["uuid1", "chrono"] } -serde = { version = ">=1.0, <2.0", features = ["derive"] } -serde_json = ">=1.0.96, <2.0" -thiserror = ">=1.0.40, <2.0" -uuid = { version = ">=1.3.3, <2.0", features = ["serde"] } -validator = { version = "0.18.1", features = ["derive"] } +chrono = { workspace = true } +schemars = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +thiserror = { workspace = true } +uuid = { workspace = true } +validator = { workspace = true } [dev-dependencies] -tokio = { version = "1.36.0", features = ["rt", "macros"] } +tokio = { workspace = true, features = ["rt"] } [lints] workspace = true diff --git a/crates/bitwarden-uniffi/Cargo.toml b/crates/bitwarden-uniffi/Cargo.toml index 414948d4d..822ed0d38 100644 --- a/crates/bitwarden-uniffi/Cargo.toml +++ b/crates/bitwarden-uniffi/Cargo.toml @@ -27,16 +27,13 @@ bitwarden-fido = { workspace = true, features = ["uniffi"] } bitwarden-generators = { workspace = true, features = ["uniffi"] } bitwarden-send = { workspace = true, features = ["uniffi"] } bitwarden-vault = { workspace = true, features = ["uniffi"] } -chrono = { version = ">=0.4.26, <0.5", features = [ - "serde", - "std", -], default-features = false } -log = "0.4.20" +chrono = { workspace = true, features = ["std"] } +log = { workspace = true } env_logger = "0.11.1" -schemars = { version = ">=0.8, <0.9", optional = true } -thiserror = ">=1.0.40, <2.0" -uniffi = "=0.28.1" -uuid = ">=1.3.3, <2" +schemars = { workspace = true, optional = true } +thiserror = { workspace = true } +uniffi = { workspace = true } +uuid = { workspace = true } [target.'cfg(target_os = "android")'.dependencies] android_logger = "0.14" @@ -44,13 +41,13 @@ android_logger = "0.14" # The use of rustls-platform-verifier requires some extra support to communicate with the Android platform jni = ">=0.19, <0.20" libloading = ">=0.8.1, <0.9" -rustls-platform-verifier = "0.3.3" +rustls-platform-verifier = "0.3.4" [target.'cfg(target_os = "ios")'.dependencies] oslog = "0.2.0" [build-dependencies] -uniffi = { version = "=0.28.1", features = ["build"] } +uniffi = { workspace = true, features = ["build"] } [lints] workspace = true diff --git a/crates/bitwarden-uniffi/README.md b/crates/bitwarden-uniffi/README.md index 4b2e61714..c2e4d6c45 100644 --- a/crates/bitwarden-uniffi/README.md +++ b/crates/bitwarden-uniffi/README.md @@ -1,13 +1 @@ # Bitwarden-uniffi - -## Generating documentation - -If desired we have some scripts that generates markdown documentation from the rustdoc output. - -```bash -cargo +nightly rustdoc -p bitwarden -- -Zunstable-options --output-format json -cargo +nightly rustdoc -p bitwarden-uniffi -- -Zunstable-options --output-format json -npm run schemas - -npx ts-node ./support/docs/docs.ts > doc.md -``` diff --git a/crates/bitwarden-uniffi/src/crypto.rs b/crates/bitwarden-uniffi/src/crypto.rs index 8a089404a..608698fc6 100644 --- a/crates/bitwarden-uniffi/src/crypto.rs +++ b/crates/bitwarden-uniffi/src/crypto.rs @@ -1,8 +1,11 @@ use std::sync::Arc; -use bitwarden::mobile::crypto::{ - DeriveKeyConnectorRequest, DerivePinKeyResponse, InitOrgCryptoRequest, InitUserCryptoRequest, - UpdatePasswordResponse, +use bitwarden::{ + mobile::crypto::{ + DeriveKeyConnectorRequest, DerivePinKeyResponse, InitOrgCryptoRequest, + InitUserCryptoRequest, UpdatePasswordResponse, + }, + Error, }; use bitwarden_crypto::{AsymmetricEncString, EncString}; @@ -16,13 +19,25 @@ impl ClientCrypto { /// Initialization method for the user crypto. Needs to be called before any other crypto /// operations. pub async fn initialize_user_crypto(&self, req: InitUserCryptoRequest) -> Result<()> { - Ok(self.0 .0.crypto().initialize_user_crypto(req).await?) + Ok(self + .0 + .0 + .crypto() + .initialize_user_crypto(req) + .await + .map_err(Error::EncryptionSettings)?) } /// Initialization method for the organization crypto. Needs to be called after /// `initialize_user_crypto` but before any other crypto operations. pub async fn initialize_org_crypto(&self, req: InitOrgCryptoRequest) -> Result<()> { - Ok(self.0 .0.crypto().initialize_org_crypto(req).await?) + Ok(self + .0 + .0 + .crypto() + .initialize_org_crypto(req) + .await + .map_err(Error::EncryptionSettings)?) } /// Get the uses's decrypted encryption key. Note: It's very important diff --git a/crates/bitwarden-uniffi/src/docs.rs b/crates/bitwarden-uniffi/src/docs.rs deleted file mode 100644 index 5edbc7144..000000000 --- a/crates/bitwarden-uniffi/src/docs.rs +++ /dev/null @@ -1,49 +0,0 @@ -use bitwarden::{ - auth::password::MasterPasswordPolicyOptions, - exporters::ExportFormat, - generators::{PassphraseGeneratorRequest, PasswordGeneratorRequest}, - mobile::crypto::{InitOrgCryptoRequest, InitUserCryptoRequest}, - platform::FingerprintRequest, - send::{Send, SendListView, SendView}, - vault::{Cipher, CipherView, Collection, Folder, FolderView, TotpResponse}, -}; -use bitwarden_crypto::{HashPurpose, Kdf}; -use schemars::JsonSchema; - -#[derive(JsonSchema)] -#[allow(clippy::large_enum_variant)] -pub enum DocRef { - // Vault - Cipher(Cipher), - CipherView(CipherView), - Collection(Collection), - Folder(Folder), - FolderView(FolderView), - Send(Send), - SendView(SendView), - SendListView(SendListView), - - // Crypto - InitUserCryptoRequest(InitUserCryptoRequest), - InitOrgCryptoRequest(InitOrgCryptoRequest), - HashPurpose(HashPurpose), - - // Generators - PasswordGeneratorRequest(PasswordGeneratorRequest), - PassphraseGeneratorRequest(PassphraseGeneratorRequest), - - // Exporters - ExportFormat(ExportFormat), - - // Platform - FingerprintRequest(FingerprintRequest), - - // Auth - MasterPasswordPolicyOptions(MasterPasswordPolicyOptions), - - // Kdf - Kdf(Kdf), - - /// TOTP - TotpResponse(TotpResponse), -} diff --git a/crates/bitwarden-uniffi/src/lib.rs b/crates/bitwarden-uniffi/src/lib.rs index d0209de01..a9eb6a3e0 100644 --- a/crates/bitwarden-uniffi/src/lib.rs +++ b/crates/bitwarden-uniffi/src/lib.rs @@ -13,9 +13,6 @@ pub mod tool; mod uniffi_support; pub mod vault; -#[cfg(feature = "docs")] -pub mod docs; - #[cfg(target_os = "android")] mod android_support; @@ -28,7 +25,7 @@ use vault::ClientVault; #[derive(uniffi::Object)] pub struct Client(bitwarden::Client); -#[uniffi::export] +#[uniffi::export(async_runtime = "tokio")] impl Client { /// Initialize a new instance of the SDK client #[uniffi::constructor] @@ -79,6 +76,18 @@ impl Client { pub fn echo(&self, msg: String) -> String { msg } + + /// Test method, calls http endpoint + pub async fn http_get(&self, url: String) -> Result { + let client = self.0.internal.get_http_client(); + let res = client + .get(&url) + .send() + .await + .map_err(bitwarden::Error::Reqwest)?; + + Ok(res.text().await.map_err(bitwarden::Error::Reqwest)?) + } } fn init_logger() { diff --git a/crates/bitwarden-uniffi/src/platform/fido2.rs b/crates/bitwarden-uniffi/src/platform/fido2.rs index 3018d7beb..f483ff346 100644 --- a/crates/bitwarden-uniffi/src/platform/fido2.rs +++ b/crates/bitwarden-uniffi/src/platform/fido2.rs @@ -11,7 +11,7 @@ use bitwarden::{ }, vault::{Cipher, CipherView, Fido2CredentialNewView}, }; -use bitwarden_fido::Fido2CredentialAutofillView; +use bitwarden_fido::{Fido2CredentialAutofillView, Origin}; use crate::{error::Result, Client}; @@ -135,7 +135,7 @@ pub struct ClientFido2Client(pub(crate) ClientFido2Authenticator); impl ClientFido2Client { pub async fn register( &self, - origin: String, + origin: Origin, request: String, client_data: ClientData, ) -> Result { @@ -153,7 +153,7 @@ impl ClientFido2Client { pub async fn authenticate( &self, - origin: String, + origin: Origin, request: String, client_data: ClientData, ) -> Result { diff --git a/crates/bitwarden-vault/Cargo.toml b/crates/bitwarden-vault/Cargo.toml index 04a64078f..4c41e139c 100644 --- a/crates/bitwarden-vault/Cargo.toml +++ b/crates/bitwarden-vault/Cargo.toml @@ -25,25 +25,22 @@ base64 = ">=0.22.1, <0.23" bitwarden-api-api = { workspace = true } bitwarden-core = { workspace = true, features = ["internal"] } bitwarden-crypto = { workspace = true } -chrono = { version = ">=0.4.26, <0.5", features = [ - "clock", - "serde", -], default-features = false } +chrono = { workspace = true } rand = ">=0.8.5, <0.9" hmac = ">=0.12.1, <0.13" -reqwest = { version = ">=0.12.5, <0.13", default-features = false } -schemars = { version = ">=0.8.9, <0.9", features = ["uuid1", "chrono"] } -serde = { version = ">=1.0, <2.0", features = ["derive"] } -serde_json = ">=1.0.96, <2.0" -serde_repr = ">=0.1.12, <0.2" +reqwest = { workspace = true } +schemars = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +serde_repr = { workspace = true } sha1 = ">=0.10.5, <0.11" sha2 = ">=0.10.6, <0.11" -thiserror = ">=1.0.40, <2.0" +thiserror = { workspace = true } uniffi = { version = "=0.28.1", optional = true } -uuid = { version = ">=1.3.3, <2.0", features = ["serde"] } +uuid = { workspace = true } [dev-dependencies] -tokio = { version = "1.36.0", features = ["rt", "macros"] } +tokio = { workspace = true, features = ["rt"] } [lints] workspace = true diff --git a/crates/bitwarden-vault/src/sync.rs b/crates/bitwarden-vault/src/sync.rs index 6b4845d35..be4c3b169 100644 --- a/crates/bitwarden-vault/src/sync.rs +++ b/crates/bitwarden-vault/src/sync.rs @@ -44,7 +44,10 @@ pub(crate) async fn sync(client: &Client, input: &SyncRequest) -> Result Level { + match level { + LogLevel::Trace => Level::Trace, + LogLevel::Debug => Level::Debug, + LogLevel::Info => Level::Info, + LogLevel::Warn => Level::Warn, + LogLevel::Error => Level::Error, + } +} + +// Rc<...> is to avoid needing to take ownership of the Client during our async run_command +// function https://github.com/rustwasm/wasm-bindgen/issues/2195#issuecomment-799588401 +#[wasm_bindgen] +pub struct BitwardenClient(Rc); + +#[wasm_bindgen] +impl BitwardenClient { + #[wasm_bindgen(constructor)] + pub fn new(settings: Option, log_level: Option) -> Self { + console_error_panic_hook::set_once(); + let log_level = convert_level(log_level.unwrap_or(LogLevel::Info)); + if let Err(_e) = console_log::init_with_level(log_level) { + set_max_level(log_level.to_level_filter()) + } + + Self(Rc::new(Client::new(settings))) + } + + /// Test method, echoes back the input + pub fn echo(&self, msg: String) -> String { + msg + } + + /// Test method, calls http endpoint + pub async fn http_get(&self, url: String) -> Result { + let client = self.0.internal.get_http_client(); + let res = client.get(&url).send().await.map_err(|e| e.to_string())?; + + res.text().await.map_err(|e| e.to_string()) + } +} diff --git a/crates/bitwarden-wasm-internal/src/lib.rs b/crates/bitwarden-wasm-internal/src/lib.rs new file mode 100644 index 000000000..b79c47fca --- /dev/null +++ b/crates/bitwarden-wasm-internal/src/lib.rs @@ -0,0 +1 @@ +mod client; diff --git a/crates/bitwarden-wasm/src/client.rs b/crates/bitwarden-wasm/src/client.rs index bca8c2383..e130705c1 100644 --- a/crates/bitwarden-wasm/src/client.rs +++ b/crates/bitwarden-wasm/src/client.rs @@ -4,7 +4,7 @@ use std::rc::Rc; use argon2::{Algorithm, Argon2, Params, Version}; use bitwarden_json::client::Client as JsonClient; use js_sys::Promise; -use log::Level; +use log::{set_max_level, Level}; use wasm_bindgen::prelude::*; use wasm_bindgen_futures::future_to_promise; @@ -37,10 +37,9 @@ impl BitwardenClient { #[wasm_bindgen(constructor)] pub fn new(settings_input: Option, log_level: Option) -> Self { console_error_panic_hook::set_once(); - if let Err(e) = - console_log::init_with_level(convert_level(log_level.unwrap_or(LogLevel::Info))) - { - panic!("failed to initialize logger: {:?}", e); + let log_level = convert_level(log_level.unwrap_or(LogLevel::Info)); + if let Err(_e) = console_log::init_with_level(log_level) { + set_max_level(log_level.to_level_filter()) } Self(Rc::new(bitwarden_json::client::Client::new(settings_input))) diff --git a/crates/bitwarden/CHANGELOG.md b/crates/bitwarden/CHANGELOG.md index 689b58e72..5d3eefa95 100644 --- a/crates/bitwarden/CHANGELOG.md +++ b/crates/bitwarden/CHANGELOG.md @@ -10,6 +10,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Added - Support for secrets sync (#678) +- Password generator (#986) ### Changed diff --git a/crates/bitwarden/Cargo.toml b/crates/bitwarden/Cargo.toml index f927564cf..1d09377cf 100644 --- a/crates/bitwarden/Cargo.toml +++ b/crates/bitwarden/Cargo.toml @@ -35,7 +35,12 @@ uniffi = [ "bitwarden-send/uniffi", "bitwarden-vault/uniffi", ] # Uniffi bindings -secrets = ["bitwarden-core/secrets", "dep:bitwarden-sm", "dep:bitwarden-generators"] # Secrets manager API +secrets = [ + "bitwarden-core/secrets", + "dep:bitwarden-sm", + "dep:bitwarden-generators", +] # Secrets manager API +wasm = ["bitwarden-core/wasm"] # WASM support [dependencies] bitwarden-api-api = { workspace = true } @@ -48,10 +53,10 @@ bitwarden-generators = { workspace = true, optional = true } bitwarden-send = { workspace = true, optional = true } bitwarden-sm = { workspace = true, optional = true } bitwarden-vault = { workspace = true, optional = true } -thiserror = ">=1.0.40, <2.0" +thiserror = { workspace = true } [dev-dependencies] -uuid = { version = ">=1.3.3, <2.0" } +uuid = { workspace = true } [lints] workspace = true diff --git a/crates/bitwarden/src/lib.rs b/crates/bitwarden/src/lib.rs index b8d8a0bda..c87693ce7 100644 --- a/crates/bitwarden/src/lib.rs +++ b/crates/bitwarden/src/lib.rs @@ -87,13 +87,13 @@ pub mod internal { #[cfg(feature = "internal")] pub use internal::*; +// Re-export generators used for secrets-manager, internal flag already exports all generators +#[cfg(all(feature = "secrets", not(feature = "internal")))] +pub mod generators { + pub use bitwarden_generators::{ClientGeneratorExt, PasswordError, PasswordGeneratorRequest}; +} + #[cfg(feature = "secrets")] pub mod secrets_manager { pub use bitwarden_sm::*; - - pub mod generators { - pub use bitwarden_generators::{ - password, ClientGeneratorExt, PasswordError, PasswordGeneratorRequest, - }; - } } diff --git a/crates/bw/Cargo.toml b/crates/bw/Cargo.toml index 7361f15b6..cb8e02ba1 100644 --- a/crates/bw/Cargo.toml +++ b/crates/bw/Cargo.toml @@ -22,7 +22,7 @@ color-eyre = "0.6.3" env_logger = "0.11.1" inquire = "0.7.0" log = "0.4.20" -tokio = { version = "1.36.0", features = ["rt-multi-thread", "macros"] } +tokio = { workspace = true, features = ["rt-multi-thread"] } [dev-dependencies] tempfile = "3.10.0" diff --git a/crates/bws/Cargo.toml b/crates/bws/Cargo.toml index 1b13c68a1..08e3941f2 100644 --- a/crates/bws/Cargo.toml +++ b/crates/bws/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bws" -version = "0.5.0" +version = "1.0.0" description = """ Bitwarden Secrets Manager CLI """ @@ -41,7 +41,7 @@ serde_json = "1.0.113" serde_yaml = "0.9" supports-color = "3.0.0" thiserror = "1.0.57" -tokio = { version = "1.36.0", features = ["rt-multi-thread", "macros"] } +tokio = { workspace = true, features = ["rt-multi-thread"] } toml = "0.8.10" uuid = { version = "1.7.0", features = ["serde"] } which = "6.0.1" diff --git a/crates/bws/Dockerfile b/crates/bws/Dockerfile index 1f3542e52..07f9f3a79 100644 --- a/crates/bws/Dockerfile +++ b/crates/bws/Dockerfile @@ -1,7 +1,7 @@ ############################################### # Build stage # ############################################### -FROM --platform=$BUILDPLATFORM rust:1.76 AS build +FROM --platform=$BUILDPLATFORM rust:1.81 AS build # Docker buildx supplies the value for this arg ARG TARGETPLATFORM diff --git a/crates/bws/scripts/install.ps1 b/crates/bws/scripts/install.ps1 index f39846c20..daa5cf9d1 100755 --- a/crates/bws/scripts/install.ps1 +++ b/crates/bws/scripts/install.ps1 @@ -4,7 +4,7 @@ param ( $ErrorActionPreference = "Stop" -$defaultBwsVersion = "0.5.0" +$defaultBwsVersion = "1.0.0" $bwsVersion = if ($env:bwsVersion) { $env:bwsVersion } else { $defaultBwsVersion } $installDir = [Environment]::GetFolderPath([Environment+SpecialFolder]::LocalApplicationData) | Join-Path -ChildPath "Programs" | Join-Path -ChildPath "Bitwarden" diff --git a/crates/bws/scripts/install.sh b/crates/bws/scripts/install.sh index 126ae9e22..6cd7fe01f 100755 --- a/crates/bws/scripts/install.sh +++ b/crates/bws/scripts/install.sh @@ -4,7 +4,7 @@ # An installer for the bws command line utility. # ################################################## -DEFAULT_BWS_VERSION="0.5.0" +DEFAULT_BWS_VERSION="1.0.0" BWS_VERSION="${BWS_VERSION:-$DEFAULT_BWS_VERSION}" main() { diff --git a/crates/memory-testing/Dockerfile b/crates/memory-testing/Dockerfile index 3804f59e0..3df22466d 100644 --- a/crates/memory-testing/Dockerfile +++ b/crates/memory-testing/Dockerfile @@ -1,7 +1,7 @@ ############################################### # Build stage # ############################################### -FROM rust:1.76 AS build +FROM rust:1.81 AS build WORKDIR /app diff --git a/crates/memory-testing/cases.json b/crates/memory-testing/cases.json index 4205e3dce..5223d3671 100644 --- a/crates/memory-testing/cases.json +++ b/crates/memory-testing/cases.json @@ -72,7 +72,7 @@ "kdf": { "argon2id": { "iterations": 3, - "memory": 4, + "memory": 16, "parallelism": 1 } } @@ -80,15 +80,15 @@ "memory_lookups": [ { "name": "Key", - "hex": "3bc0520a0abff0097d521ce0ee5e5b1cee301939a84742623c0c1697d7a4bd46" + "hex": "59079cd7134409c6882c2701de8357a3d8aabb2dad2da19eea5f1b8081dfb51c" }, { "name": "Hash B64", - "string": "lHkprdORlICVJ4Umwi94Uz/nATK6Y7If7e+iFoabzh0=" + "string": "P1ZT6T80zOfEqXj/kPbtON3yszf7xLNGCxWjdO2xfjU=" }, { "name": "Hash bytes", - "hex": "947929add391948095278526c22f78533fe70132ba63b21fedefa216869bce1d" + "hex": "3f5653e93f34cce7c4a978ff90f6ed38ddf2b337fbc4b3460b15a374edb17e35" } ] }, diff --git a/crates/memory-testing/src/bin/capture-dumps.rs b/crates/memory-testing/src/bin/capture-dumps.rs index 1fe4eead1..5dddd7622 100644 --- a/crates/memory-testing/src/bin/capture-dumps.rs +++ b/crates/memory-testing/src/bin/capture-dumps.rs @@ -37,6 +37,11 @@ fn wait_dump_and_continue( loop { let mut buf = [0u8; 1024]; let read = stdout.read(&mut buf).unwrap(); + + if read == 0 { + panic!("Process exited unexpectedly"); + } + let buf_str = std::str::from_utf8(&buf[..read]).unwrap(); if buf_str.contains("Waiting for dump...") { break; diff --git a/crates/sdk-schemas/Cargo.toml b/crates/sdk-schemas/Cargo.toml index 9982e47fe..b4dd496a4 100644 --- a/crates/sdk-schemas/Cargo.toml +++ b/crates/sdk-schemas/Cargo.toml @@ -12,11 +12,7 @@ license-file.workspace = true keywords.workspace = true [features] -internal = [ - "bitwarden/internal", - "bitwarden-json/internal", - "bitwarden-uniffi/docs", -] +internal = ["bitwarden/internal", "bitwarden-json/internal"] [dependencies] anyhow = "1.0.82" @@ -24,5 +20,5 @@ bitwarden = { workspace = true } bitwarden-json = { path = "../bitwarden-json" } bitwarden-uniffi = { path = "../bitwarden-uniffi", optional = true } itertools = "0.13.0" -schemars = { version = "0.8.16", features = ["preserve_order"] } +schemars = { workspace = true, features = ["preserve_order"] } serde_json = "1.0.113" diff --git a/crates/sdk-schemas/src/main.rs b/crates/sdk-schemas/src/main.rs index 94959fa69..66683256b 100644 --- a/crates/sdk-schemas/src/main.rs +++ b/crates/sdk-schemas/src/main.rs @@ -121,8 +121,5 @@ struct SchemaTypes { fn main() -> Result<()> { write_schema_for!("schema_types", SchemaTypes); - #[cfg(feature = "internal")] - write_schema_for!(bitwarden_uniffi::docs::DocRef); - Ok(()) } diff --git a/crates/uniffi-bindgen/Cargo.toml b/crates/uniffi-bindgen/Cargo.toml index 042ea8b65..b5401afb9 100644 --- a/crates/uniffi-bindgen/Cargo.toml +++ b/crates/uniffi-bindgen/Cargo.toml @@ -17,4 +17,4 @@ name = "uniffi-bindgen" path = "uniffi-bindgen.rs" [dependencies] -uniffi = { version = "=0.28.1", features = ["cli"] } +uniffi = { workspace = true, features = ["cli"] } diff --git a/languages/cpp/CMakeBuild.md b/languages/cpp/CMakeBuild.md index cb148069e..b75da5c17 100644 --- a/languages/cpp/CMakeBuild.md +++ b/languages/cpp/CMakeBuild.md @@ -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` @@ -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 @@ -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 diff --git a/languages/cpp/CMakeLists.txt b/languages/cpp/CMakeLists.txt index e513a32ed..e6ad7f4f3 100644 --- a/languages/cpp/CMakeLists.txt +++ b/languages/cpp/CMakeLists.txt @@ -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}) diff --git a/languages/cpp/README.md b/languages/cpp/README.md index 23b59ac76..fb714a20e 100644 --- a/languages/cpp/README.md +++ b/languages/cpp/README.md @@ -22,9 +22,10 @@ bitwardenSettings.set_identity_url(""); ```c++ std::string accessToken = ""; +std::string stateFile = ""; // Optional - argument in BitwardenClient BitwardenClient bitwardenClient = BitwardenClient(bitwardenSettings); -bitwardenClient.accessTokenLogin(accessToken); +bitwardenClient.loginAccessToken(accessToken, stateFile); ``` ### Create new project @@ -32,6 +33,7 @@ bitwardenClient.accessTokenLogin(accessToken); ```c++ boost::uuids::uuid organizationUuid = boost::uuids::string_generator()(""); ProjectResponse projectResponseCreate = bitwardenClient.createProject(organizationUuid, "TestProject"); +boost::uuids::uuid projectId = boost::uuids::string_generator()(projectResponseCreate.get_id()); ``` ### List all projects @@ -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 @@ -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 @@ -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 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 diff --git a/languages/cpp/examples/Wrapper.cpp b/languages/cpp/examples/Wrapper.cpp index bb53bf0c4..7790adfb0 100644 --- a/languages/cpp/examples/Wrapper.cpp +++ b/languages/cpp/examples/Wrapper.cpp @@ -1,14 +1,18 @@ #include "BitwardenClient.h" #include #include +#include int main() { // Retrieve access token and organization ID from environment variables - const char* accessTokenEnv = std::getenv("ACCESS_TOKEN"); - const char* organizationIdEnv = std::getenv("ORGANIZATION_ID"); + const char *accessTokenEnv = std::getenv("ACCESS_TOKEN"); + const char *organizationIdEnv = std::getenv("ORGANIZATION_ID"); - const char* apiUrl = std::getenv("API_URL"); - const char* identityUrl = std::getenv("IDENTITY_URL"); + // Use optional state file for authentication + const char *stateFile = std::getenv("STATE_FILE"); + + const char *apiUrl = std::getenv("API_URL"); + const char *identityUrl = std::getenv("IDENTITY_URL"); if (!accessTokenEnv || !organizationIdEnv) { std::cerr << "Error: Environment variables ACCESS_TOKEN or ORGANIZATION_ID not set." << std::endl; @@ -18,57 +22,110 @@ int main() { std::string accessToken = accessTokenEnv; std::string organizationId = organizationIdEnv; - // Configuring the URLS is optional, remove them to use the default values + // Configuring the URLS is optional; if unset, use bitwarden.com BitwardenSettings bitwardenSettings; - bitwardenSettings.set_api_url(apiUrl); - bitwardenSettings.set_identity_url(identityUrl); + if (apiUrl != nullptr && identityUrl != nullptr) { + bitwardenSettings.set_api_url(apiUrl); + bitwardenSettings.set_identity_url(identityUrl); + } else { + std::cerr << "Info: API_URL and IDENTITY_URL are not set, using default values..." << std::endl; + } // Create a Bitwarden client instance - BitwardenClient bitwardenClient = BitwardenClient(bitwardenSettings); - // // Access token login - bitwardenClient.loginAccessToken(accessToken); - // Organization ID - boost::uuids::uuid organizationUuid = boost::uuids::string_generator()(organizationId); - - // // Create a new project + BitwardenClient bitwardenClient(bitwardenSettings); + + // Access token login + if (stateFile != nullptr) { + bitwardenClient.loginAccessToken(accessToken, stateFile); + } else { + bitwardenClient.loginAccessToken(accessToken); + } + + // Convert organization ID to UUID + boost::uuids::uuid organizationUuid = boost::uuids::string_generator()(organizationId); + + // Create a new project + std::cout << "Projects:\n"; ProjectResponse projectResponseCreate = bitwardenClient.createProject(organizationUuid, "NewTestProject"); boost::uuids::uuid projectId = boost::uuids::string_generator()(projectResponseCreate.get_id()); - + + std::cout << "\tcreateProject: '" << projectResponseCreate.get_name() << "'\n\n"; + // List projects ProjectsResponse projectResponseList = bitwardenClient.listProjects(organizationUuid); + std::cout << "\tlistProjects:\n"; + for (const ProjectResponse& project : projectResponseList.get_data()) { + std::cout << "\t\tID: '" << project.get_id() << "', Name: '" << project.get_name() << "'\n"; + } + std::cout << '\n'; // Get project details ProjectResponse projectResponseGet = bitwardenClient.getProject(projectId); + std::cout << "\tgetProject:\n\t\tID: '" << projectResponseGet.get_id() << "', Name: '" << projectResponseGet.get_name() << "'\n\n"; // Update project - ProjectResponse ProjectResponseUpdate = bitwardenClient.updateProject(projectId, organizationUuid, "NewTestProject2"); + ProjectResponse projectResponseUpdate = bitwardenClient.updateProject(organizationUuid, projectId, "NewTestProject2"); + std::cout << "\tupdateProject: '" << projectResponseUpdate.get_name() << "'\n\n"; // Secrets std::string key = "key"; std::string value = "value"; std::string note = "note"; + // Sync secrets + std::cout << "Secrets:\n"; + std::cout << "\tSyncing secrets...\n"; + SecretsSyncResponse secretsSyncResponse = bitwardenClient.sync(organizationUuid, {}); + std::chrono::system_clock::time_point lastSyncedDate = std::chrono::system_clock::now(); + std::cout << "\t\tSync has changes: '" << (secretsSyncResponse.get_has_changes() ? "true" : "false") << "'\n\n"; + + std::cout << "\tSyncing again to ensure no changes since last sync...\n"; + secretsSyncResponse = bitwardenClient.sync(organizationUuid, lastSyncedDate); + std::cout << "\t\tSync has changes: '" << (secretsSyncResponse.get_has_changes() ? "true" : "false") << "'\n\n"; + // Create a new secret - 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()); + std::cout << "\tcreateSecret: '" << secretResponseCreate.get_key() << "'\n\n"; + // List secrets SecretIdentifiersResponse secretIdentifiersResponse = bitwardenClient.listSecrets(organizationUuid); + std::cout << "\tlistSecrets:\n"; + for (const SecretIdentifierResponse& secretIdentifier : secretIdentifiersResponse.get_data()) { + std::cout << "\t\tID: '" << secretIdentifier.get_id() << "'\n"; + } + std::cout << '\n'; // Get secret details SecretResponse secretResponseGet = bitwardenClient.getSecret(secretId); + std::cout << "\tgetSecret: '" << secretResponseGet.get_key() << "'\n\n"; + + // Get secrets by IDs + std::cout << "\tgetSecretsByIds:\n"; + SecretsResponse secretsResponseGetByIds = bitwardenClient.getSecretsByIds({secretId}); + for (const SecretResponse& secret : secretsResponseGetByIds.get_data()) { + std::cout << "\t\tID: '" << secret.get_id() << "', Key: '" << secret.get_key() << "'\n"; + } + std::cout << '\n'; // Update secret - key = "key2"; - value = "value2"; - note = "note2"; - SecretResponse responseForSecretResponseUpdate = bitwardenClient.updateSecret(secretId, key, value, note, organizationUuid, {projectId}); + key = "updated-key"; + value = "updated-value"; + note = "updated-note"; + SecretResponse responseForSecretResponseUpdate = bitwardenClient.updateSecret( + organizationUuid, secretId, key, value, note, {projectId}); + + std::cout << "\tupdateSecret: '" << responseForSecretResponseUpdate.get_key() << "'\n\n"; // Delete secrets + std::cout << "Deleting projects and secrets...\n"; SecretsDeleteResponse secretsDeleteResponse = bitwardenClient.deleteSecrets({secretId}); + std::cout << "\tdeleteSecrets: '" << secretsDeleteResponse.get_data()[0].get_id() << "'\n\n"; // Delete projects ProjectsDeleteResponse projectsDeleteResponse = bitwardenClient.deleteProjects({projectId}); + std::cout << "\tdeleteProjects: '" << projectsDeleteResponse.get_data()[0].get_id() << "'\n\n"; return 0; } diff --git a/languages/cpp/include/BitwardenClient.h b/languages/cpp/include/BitwardenClient.h index a5cf72475..2910c49b7 100644 --- a/languages/cpp/include/BitwardenClient.h +++ b/languages/cpp/include/BitwardenClient.h @@ -9,20 +9,22 @@ class BitwardenClient { public: - BitwardenClient(const BitwardenSettings& bitwardenSettings = BitwardenSettings()); + explicit BitwardenClient(const BitwardenSettings& bitwardenSettings = BitwardenSettings()); ~BitwardenClient(); - - void accessTokenLogin(const std::string& accessToken); + + void loginAccessToken(const std::string& accessToken, const std::string& stateFile = ""); ProjectResponse getProject(const boost::uuids::uuid& id); ProjectResponse createProject(const boost::uuids::uuid& organizationId, const std::string& name); - ProjectResponse updateProject(const boost::uuids::uuid& id, const boost::uuids::uuid& organizationId, const std::string& name); + ProjectResponse updateProject(const boost::uuids::uuid& organizationId, const boost::uuids::uuid& id, const std::string& name); ProjectsDeleteResponse deleteProjects(const std::vector& ids); ProjectsResponse listProjects(const boost::uuids::uuid &organizationId); SecretResponse getSecret(const boost::uuids::uuid& id); - SecretResponse createSecret(const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector& projectIds); - SecretResponse updateSecret(const boost::uuids::uuid& id, const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector& projectIds); + SecretsResponse getSecretsByIds(const std::vector& ids); + SecretResponse createSecret(const boost::uuids::uuid& organizationId, const std::string& key, const std::string& value, const std::string& note, const std::vector& projectIds); + SecretResponse updateSecret(const boost::uuids::uuid& organizationId, const boost::uuids::uuid& id, const std::string& key, const std::string& value, const std::string& note, const std::vector& projectIds); SecretsDeleteResponse deleteSecrets(const std::vector& ids); SecretIdentifiersResponse listSecrets(const boost::uuids::uuid& organizationId); + SecretsSyncResponse sync(const boost::uuids::uuid &organizationId, const std::chrono::system_clock::time_point &lastSyncedDate); private: BitwardenLibrary* library; diff --git a/languages/cpp/include/Projects.h b/languages/cpp/include/Projects.h index 9bef19b9c..27511c327 100644 --- a/languages/cpp/include/Projects.h +++ b/languages/cpp/include/Projects.h @@ -10,7 +10,7 @@ class Projects { ProjectResponse get(const boost::uuids::uuid& id); ProjectResponse create(const boost::uuids::uuid& organizationId, const std::string& name); - ProjectResponse update(const boost::uuids::uuid& id, const boost::uuids::uuid& organizationId, const std::string& name); + ProjectResponse update(const boost::uuids::uuid& organizationId, const boost::uuids::uuid& id, const std::string& name); ProjectsDeleteResponse deleteProjects(const std::vector& ids); ProjectsResponse list(const boost::uuids::uuid& organizationId); diff --git a/languages/cpp/include/Secrets.h b/languages/cpp/include/Secrets.h index 024ec3692..5c5a3275c 100644 --- a/languages/cpp/include/Secrets.h +++ b/languages/cpp/include/Secrets.h @@ -1,6 +1,8 @@ #pragma once #include +#include +#include #include #include "CommandRunner.h" @@ -9,10 +11,12 @@ class Secrets { Secrets(CommandRunner* commandRunner); SecretResponse get(const boost::uuids::uuid& id); - SecretResponse create(const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector& projectIds); - SecretResponse update(const boost::uuids::uuid& id, const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector& projectIds); + SecretsResponse getByIds(const std::vector &ids); + SecretResponse create(const boost::uuids::uuid& organizationId, const std::string& key, const std::string& value, const std::string& note, const std::vector& projectIds); + SecretResponse update(const boost::uuids::uuid& organizationId, const boost::uuids::uuid& id, const std::string& key, const std::string& value, const std::string& note, const std::vector& projectIds); SecretsDeleteResponse deleteSecrets(const std::vector& ids); SecretIdentifiersResponse list(const boost::uuids::uuid& organizationId); + SecretsSyncResponse sync(const boost::uuids::uuid& organizationId, const boost::optional& lastSyncedDate); private: CommandRunner* commandRunner; diff --git a/languages/cpp/src/BitwardenClient.cpp b/languages/cpp/src/BitwardenClient.cpp index ce161a2bf..2d11977d4 100644 --- a/languages/cpp/src/BitwardenClient.cpp +++ b/languages/cpp/src/BitwardenClient.cpp @@ -50,10 +50,11 @@ BitwardenClient::~BitwardenClient() { } } -void BitwardenClient::loginAccessToken(const std::string& accessToken) { +void BitwardenClient::loginAccessToken(const std::string& accessToken, const std::string& stateFile) { Command command; AccessTokenLoginRequest accessTokenLoginRequest; accessTokenLoginRequest.set_access_token(accessToken); + accessTokenLoginRequest.set_state_file(stateFile); command.set_login_access_token(accessTokenLoginRequest); auto deserializer = [](const char* response) -> ResponseForApiKeyLoginResponse { @@ -84,11 +85,11 @@ ProjectResponse BitwardenClient::createProject(const boost::uuids::uuid& organiz return projects.create(organizationId, name); } -ProjectResponse BitwardenClient::updateProject(const boost::uuids::uuid& id, const boost::uuids::uuid& organizationId, const std::string& name){ +ProjectResponse BitwardenClient::updateProject(const boost::uuids::uuid& organizationId, const boost::uuids::uuid& id, const std::string& name){ if (!isClientOpen) { throw std::runtime_error("Client is not open."); } - return projects.update(id, organizationId, name); + return projects.update(organizationId, id, name); } ProjectsDeleteResponse BitwardenClient::deleteProjects(const std::vector& ids) { @@ -114,18 +115,25 @@ SecretResponse BitwardenClient::getSecret(const boost::uuids::uuid& id){ return secrets.get(id); } -SecretResponse BitwardenClient::createSecret(const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector& projectIds){ +SecretsResponse BitwardenClient::getSecretsByIds(const std::vector& ids){ if (!isClientOpen) { throw std::runtime_error("Client is not open."); } - return secrets.create(key, value, note, organizationId, projectIds); + return secrets.getByIds(ids); } -SecretResponse BitwardenClient::updateSecret(const boost::uuids::uuid& id, const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector& projectIds){ +SecretResponse BitwardenClient::createSecret(const boost::uuids::uuid& organizationId, const std::string& key, const std::string& value, const std::string& note, const std::vector& projectIds){ if (!isClientOpen) { throw std::runtime_error("Client is not open."); } - return secrets.update(id, key, value, note, organizationId, projectIds); + return secrets.create(organizationId, key, value, note, projectIds); +} + +SecretResponse BitwardenClient::updateSecret(const boost::uuids::uuid& organizationId, const boost::uuids::uuid& id, const std::string& key, const std::string& value, const std::string& note, const std::vector& projectIds){ + if (!isClientOpen) { + throw std::runtime_error("Client is not open."); + } + return secrets.update(organizationId, id, key, value, note, projectIds); } SecretsDeleteResponse BitwardenClient::deleteSecrets(const std::vector& ids) { @@ -143,3 +151,10 @@ SecretIdentifiersResponse BitwardenClient::listSecrets(const boost::uuids::uuid return secrets.list(organizationId); } + +SecretsSyncResponse BitwardenClient::sync(const boost::uuids::uuid &organizationId, const std::chrono::system_clock::time_point &lastSyncedDate) { + if (!isClientOpen) { + throw std::runtime_error("Client is not open."); + } + return secrets.sync(organizationId, lastSyncedDate); +} diff --git a/languages/cpp/src/Projects.cpp b/languages/cpp/src/Projects.cpp index d0aa6ed49..b2fa1c688 100644 --- a/languages/cpp/src/Projects.cpp +++ b/languages/cpp/src/Projects.cpp @@ -67,7 +67,7 @@ ProjectResponse Projects::create(const boost::uuids::uuid& organizationId, const } } -ProjectResponse Projects::update(const boost::uuids::uuid& id, const boost::uuids::uuid& organizationId, const std::string& name) { +ProjectResponse Projects::update(const boost::uuids::uuid& organizationId, const boost::uuids::uuid& id, const std::string& name) { Command command; ProjectsCommand projectsCommand; ProjectPutRequest projectPutRequest; diff --git a/languages/cpp/src/Secrets.cpp b/languages/cpp/src/Secrets.cpp index e153ea7f1..1fff9441f 100644 --- a/languages/cpp/src/Secrets.cpp +++ b/languages/cpp/src/Secrets.cpp @@ -1,8 +1,8 @@ #include "Secrets.h" #include #include -#include -#include +#include +#include Secrets::Secrets(CommandRunner* commandRunner) : commandRunner(commandRunner) {} @@ -13,6 +13,13 @@ auto secretsDeserializer = [](const std::string& response) -> ResponseForSecretR return secretResponse; }; +auto secretsByIdsDeserializer = [](const std::string& response) -> ResponseForSecretsResponse { + nlohmann::json jsonResponse = nlohmann::json::parse(response); + ResponseForSecretsResponse secretsResponse; + Bitwarden::Sdk::from_json(jsonResponse, secretsResponse); + return secretsResponse; +}; + auto deleteSecretsDeserializer = [](const std::string& response) -> ResponseForSecretsDeleteResponse { nlohmann::json jsonResponse = nlohmann::json::parse(response); ResponseForSecretsDeleteResponse deleteSecretsResponse; @@ -27,6 +34,13 @@ auto secretListDeserializer = [](const std::string& response) -> ResponseForSecr return listResponse; }; +auto secretsSyncDeserializer = [](const std::string& response) -> ResponseForSecretsSyncResponse { + nlohmann::json jsonResponse = nlohmann::json::parse(response); + ResponseForSecretsSyncResponse syncResponse; + Bitwarden::Sdk::from_json(jsonResponse, syncResponse); + return syncResponse; +}; + SecretResponse Secrets::get(const boost::uuids::uuid& id) { Command command; SecretsCommand secretsCommand; @@ -46,7 +60,29 @@ SecretResponse Secrets::get(const boost::uuids::uuid& id) { } } -SecretResponse Secrets::create(const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector& projectIds) { +SecretsResponse Secrets::getByIds(const std::vector& ids) { + Command command; + SecretsCommand secretsCommand; + SecretsGetRequest secretsGetRequest; + + std::vector idsStr; + for (const auto& id : ids) { + idsStr.push_back(boost::uuids::to_string(id)); + } + secretsGetRequest.set_ids(idsStr); + + secretsCommand.set_get_by_ids(secretsGetRequest); + command.set_secrets(secretsCommand); + + try { + return commandRunner->runCommand(command, secretsByIdsDeserializer); + } catch (const std::exception& ex) { + std::cerr << "Error in getSecretsByIds: " << ex.what() << std::endl; + throw ex; + } +} + +SecretResponse Secrets::create(const boost::uuids::uuid& organizationId, const std::string& key, const std::string& value, const std::string& note, const std::vector& projectIds) { Command command; SecretsCommand secretsCommand; SecretCreateRequest secretCreateRequest; @@ -75,7 +111,7 @@ SecretResponse Secrets::create(const std::string& key, const std::string& value, } } -SecretResponse Secrets::update(const boost::uuids::uuid& id, const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector& projectIds) { +SecretResponse Secrets::update(const boost::uuids::uuid& organizationId, const boost::uuids::uuid& id, const std::string& key, const std::string& value, const std::string& note, const std::vector& projectIds) { Command command; SecretsCommand secretsCommand; SecretPutRequest secretPutRequest; @@ -147,3 +183,48 @@ SecretIdentifiersResponse Secrets::list(const boost::uuids::uuid& organizationId throw ex; } } + +SecretsSyncResponse Secrets::sync(const boost::uuids::uuid& organizationId, const boost::optional& lastSyncedDate) { + Command command; + SecretsCommand secretsCommand; + SecretsSyncRequest secretsSyncRequest; + + std::string orgIdStr = boost::uuids::to_string(organizationId); + secretsSyncRequest.set_organization_id(orgIdStr); + + if (lastSyncedDate.has_value()) { + auto timePoint = lastSyncedDate.value(); + + // Get time as time_t and milliseconds + auto timeT = std::chrono::system_clock::to_time_t(timePoint); + auto milliseconds = std::chrono::duration_cast(timePoint.time_since_epoch()) % 1000; + + // Convert to a tm struct + std::tm tm = *std::gmtime(&timeT); + + // Create a string stream to format the date and time + std::stringstream dateStream; + dateStream << std::put_time(&tm, "%Y-%m-%dT%H:%M:%S"); + + // Add milliseconds + dateStream << '.' << std::setw(3) << std::setfill('0') << milliseconds.count() << 'Z'; + + // Convert to string + std::string dateStr = dateStream.str(); + + // Set the last synced date + secretsSyncRequest.set_last_synced_date(dateStr); + } else { + secretsSyncRequest.set_last_synced_date(boost::none); + } + + secretsCommand.set_sync(secretsSyncRequest); + command.set_secrets(secretsCommand); + + try { + return commandRunner->runCommand(command, secretsSyncDeserializer); + } catch (const std::exception& ex) { + std::cerr << "Error in syncSecrets: " << ex.what() << std::endl; + throw ex; + } +} diff --git a/languages/cpp/vcpkg.json b/languages/cpp/vcpkg.json index 06a7b968c..8e5b968b9 100644 --- a/languages/cpp/vcpkg.json +++ b/languages/cpp/vcpkg.json @@ -1,10 +1,11 @@ { - "name": "bitwarden-sdk-secrets", - "version": "0.1.0", - "homepage": "https://github.com/bitwarden/sdk/tree/languages/cpp", - "description": "Bitwarden Secrets Manager SDK for C++", - "dependencies": [ - "boost", - "nlohmann-json" - ] + "name": "bitwarden-sdk-secrets", + "version": "0.1.0", + "homepage": "https://github.com/bitwarden/sdk/tree/languages/cpp", + "description": "Bitwarden Secrets Manager SDK for C++", + "dependencies": [ + "boost-uuid", + "boost-optional", + "nlohmann-json" + ] } diff --git a/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj b/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj index 4a0934ab9..2dd16dd82 100644 --- a/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj +++ b/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj @@ -27,7 +27,7 @@ - + diff --git a/languages/go/.version b/languages/go/.version index 6da28dde7..e6d5cb833 100644 --- a/languages/go/.version +++ b/languages/go/.version @@ -1 +1 @@ -0.1.1 \ No newline at end of file +1.0.2 \ No newline at end of file diff --git a/languages/go/internal/cinterface/bitwarden_library.go b/languages/go/internal/cinterface/bitwarden_library.go index 3a63be61b..69d752716 100644 --- a/languages/go/internal/cinterface/bitwarden_library.go +++ b/languages/go/internal/cinterface/bitwarden_library.go @@ -11,7 +11,7 @@ import ( #cgo linux,arm64 LDFLAGS: -L ./lib/linux-arm64 #cgo darwin,amd64 LDFLAGS: -L ./lib/darwin-x64 -framework Security -framework SystemConfiguration #cgo darwin,arm64 LDFLAGS: -L ./lib/darwin-arm64 -framework Security -framework SystemConfiguration -#cgo windows,amd64 LDFLAGS: -L ./lib/windows-x64 -lbitwarden_c -ladvapi32 -lbcrypt -lcrypt32 -lcryptnet -lkernel32 -lncrypt -lntdll -luserenv -lws2_32 -lmsvcrt +#cgo windows,amd64 LDFLAGS: -L ./lib/windows-x64 -lbitwarden_c -ladvapi32 -lbcrypt -lcrypt32 -lcryptnet -lkernel32 -lncrypt -lntdll -luserenv -lws2_32 -lmsvcrt -loleaut32 -lruntimeobject #include typedef void* ClientPtr; extern char* run_command(const char *command, ClientPtr client); diff --git a/languages/java/README.md b/languages/java/README.md index 02cbc4aaf..b4db4475e 100644 --- a/languages/java/README.md +++ b/languages/java/README.md @@ -13,12 +13,19 @@ Review the help documentation on [Access Tokens] ```java import com.bitwarden.sdk.*; +import com.bitwarden.sdk.schema.*; + +import java.lang.System; +import java.util.UUID; +import java.time.OffsetDateTime; + +String stateFile = System.getenv("STATE_FILE"); BitwardenSettings bitwardenSettings = new BitwardenSettings(); bitwardenSettings.setApiUrl("https://api.bitwarden.com"); bitwardenSettings.setIdentityUrl("https://identity.bitwarden.com"); BitwardenClient bitwardenClient = new BitwardenClient(bitwardenSettings); -bitwardenClient.accessTokenLogin(""); +bitwardenClient.auth().loginAccessToken("", stateFile); ``` ### Create new project @@ -44,7 +51,7 @@ var projectsResponse = bitwardenClient.projects().list(organizationId); ### Update project ```java -var projectResponse = bitwardenClient.projects().update(projectId, organizationId, "TestProjectUpdated"); +var projectResponse = bitwardenClient.projects().update(organizationId, projectId, "TestProjectUpdated"); ``` ### Add new secret @@ -53,7 +60,7 @@ var projectResponse = bitwardenClient.projects().update(projectId, organizationI String key = "key"; String value = "value"; String note = "note"; -var secretResponse = bitwardenClient.secrets().create(key, value, note, organizationId, new UUID[]{projectId}); +var secretResponse = bitwardenClient.secrets().create(organizationId, key, value, note, new UUID[]{projectId}); UUID secretId = secretResponse.getID(); ``` @@ -63,10 +70,19 @@ UUID secretId = secretResponse.getID(); var secretResponse = bitwardenClient.secrets().get(secretId); ``` +### Get secrets by ids + +```java +SecretsResponse secretsByIds = bitwardenClient.secrets().getByIds(new UUID[]{secretId}); +for (SecretResponse sr : secretsByIds.getData()) { + System.out.println(sr.getKey()); +} +``` + ### Update secret ```java -var secretResponse = bitwardenClient.secrets().update(secretId, key2, value2, note2, organizationId, new UUID[]{projectId}); +var secretResponse = bitwardenClient.secrets().update(organizationId, secretId, key2, value2, note2, new UUID[]{projectId}); ``` ### List secrets @@ -75,6 +91,12 @@ var secretResponse = bitwardenClient.secrets().update(secretId, key2, value2, no var secretIdentifiersResponse = bitwardenClient.secrets().list(organizationId); ``` +### Secrets sync +```java +SecretsSyncResponse syncResponse = bitwardenClient.secrets().sync(organizationId, OffsetDateTime.now()); +System.out.println("Has changes: " + syncResponse.getHasChanges()); +``` + ### Delete secret or project ```java diff --git a/languages/java/build.gradle b/languages/java/build.gradle index 2363d3a32..52337a447 100644 --- a/languages/java/build.gradle +++ b/languages/java/build.gradle @@ -36,7 +36,7 @@ repositories { def branchName = "git branch --show-current".execute().text.trim() if (branchName == "main" || branchName == "rc" || branchName == "hotfix-rc") { - version = "0.1.0" + version = "1.0.0" } else { // branchName-SNAPSHOT version = "${branchName.replaceAll('/', '-')}-SNAPSHOT" @@ -74,6 +74,7 @@ tasks.withType(JavaCompile) { tasks.withType(Javadoc) { options.encoding = 'UTF-8' + failOnError = false } java { diff --git a/languages/java/example/Example.java b/languages/java/example/Example.java index 2460d76b5..cc34c2a29 100644 --- a/languages/java/example/Example.java +++ b/languages/java/example/Example.java @@ -1,5 +1,6 @@ import java.lang.System; import java.util.UUID; +import java.time.OffsetDateTime; import com.bitwarden.sdk.*; import com.bitwarden.sdk.schema.*; @@ -13,8 +14,10 @@ public static void main(String[] args) { String accessToken = System.getenv("ACCESS_TOKEN"); UUID organizationId = UUID.fromString(System.getenv("ORGANIZATION_ID")); + String apiUrl = System.getenv("API_URL"); String identityUrl = System.getenv("IDENTITY_URL"); + String stateFile = System.getenv("STATE_FILE"); // Configuring the URLS is optional, remove them to use the default values BitwardenSettings bitwardenSettings = new BitwardenSettings(); @@ -22,31 +25,49 @@ public static void main(String[] args) { bitwardenSettings.setIdentityUrl(identityUrl); try (BitwardenClient client = new BitwardenClient(bitwardenSettings)) { - client.accessTokenLogin(accessToken); + client.auth().loginAccessToken(accessToken, stateFile); - ProjectResponse project = client.projects().create(organizationId, "Test Project"); - System.out.println("Project id: " + project.getID()); + ProjectResponse project = client.projects().create(organizationId, "Test Project from Java SDK"); + System.out.println("Project CREATE, id: " + project.getID()); project = client.projects().get(project.getID()); + System.out.println("Project GET, id: " + project.getID()); ProjectsResponse projects = client.projects().list(organizationId); - System.out.println("Projects count: " + projects.getData().length); + System.out.println("Projects LIST, count: " + projects.getData().length); - client.projects().update(project.getID(), organizationId, "Updated Test Project"); + client.projects().update(organizationId, project.getID(), "Updated Test Project"); + project = client.projects().get(project.getID()); + System.out.println("Project UPDATE, new name: " + project.getName()); - SecretResponse secret = client.secrets().create("Secret Key", "Secret Value", "Secret Note", - organizationId, new UUID[]{project.getID()}); - System.out.println("Secret id: " + secret.getID()); + SecretResponse secret = client.secrets().create(organizationId, "Secret Key", "Secret Value", "Secret Note", new UUID[]{project.getID()}); + System.out.println("Secret CREATE, id: " + secret.getID()); secret = client.secrets().get(secret.getID()); + System.out.println("Secret GET, id: " + secret.getID()); SecretIdentifiersResponse secrets = client.secrets().list(organizationId); - System.out.println("Secrets count: " + secrets.getData().length); + System.out.println("Secrets LIST, count: " + secrets.getData().length); + + client.secrets().update(organizationId, secret.getID(), "Updated Key", "Updated Value", "Updated Note", new UUID[]{project.getID()}); + secret = client.secrets().get(secret.getID()); + System.out.println("Secret UPDATE, new key: " + secret.getKey()); + + SecretsResponse secretsByIds = client.secrets().getByIds(new UUID[]{secret.getID()}); + System.out.println("Getting secrets by ids, here are the keys of the retrieved secrets..."); + for (SecretResponse sr : secretsByIds.getData()) { + System.out.println(" " + sr.getKey()); + } - client.secrets().update(secret.getID(), "Updated Key", "Updated Value", "Updated Noye", organizationId, new UUID[]{project.getID()}); + SecretsSyncResponse syncResponse = client.secrets().sync(organizationId, OffsetDateTime.now()); + System.out.println("Running a secrets sync request based on the current time..."); + System.out.println("Has changes: " + syncResponse.getHasChanges()); + System.out.println("Deleting the created secret and project..."); client.secrets().delete(new UUID[]{secret.getID()}); client.projects().delete(new UUID[]{project.getID()}); + + System.out.println("Execution complete."); } } } diff --git a/languages/java/src/main/java/com/bitwarden/sdk/AuthClient.java b/languages/java/src/main/java/com/bitwarden/sdk/AuthClient.java new file mode 100644 index 000000000..b4c26eb75 --- /dev/null +++ b/languages/java/src/main/java/com/bitwarden/sdk/AuthClient.java @@ -0,0 +1,32 @@ +package com.bitwarden.sdk; + +import com.bitwarden.sdk.schema.*; + +import java.util.function.Function; + +public class AuthClient { + + private final CommandRunner commandRunner; + + AuthClient(CommandRunner commandRunner) { + this.commandRunner = commandRunner; + } + + public APIKeyLoginResponse loginAccessToken(String accessToken, String stateFile) { + Command command = new Command(); + AccessTokenLoginRequest accessTokenLoginRequest = new AccessTokenLoginRequest(); + accessTokenLoginRequest.setAccessToken(accessToken); + accessTokenLoginRequest.setStateFile(stateFile); + + command.setLoginAccessToken(accessTokenLoginRequest); + + ResponseForAPIKeyLoginResponse response = commandRunner.runCommand(command, + BitwardenClient.throwingFunctionWrapper(Converter::ResponseForAPIKeyLoginResponseFromJsonString)); + + if (response == null || !response.getSuccess()) { + throw new BitwardenClientException(response != null ? response.getErrorMessage() : "Login failed"); + } + + return response.getData(); + } +} diff --git a/languages/java/src/main/java/com/bitwarden/sdk/BitwardenClient.java b/languages/java/src/main/java/com/bitwarden/sdk/BitwardenClient.java index 9e1948184..bed29982d 100644 --- a/languages/java/src/main/java/com/bitwarden/sdk/BitwardenClient.java +++ b/languages/java/src/main/java/com/bitwarden/sdk/BitwardenClient.java @@ -21,6 +21,8 @@ public class BitwardenClient implements AutoCloseable { private final SecretsClient secrets; + private final AuthClient auth; + public BitwardenClient(BitwardenSettings bitwardenSettings) { ClientSettings clientSettings = new ClientSettings(); clientSettings.setAPIURL(bitwardenSettings.getApiUrl()); @@ -39,36 +41,20 @@ public BitwardenClient(BitwardenSettings bitwardenSettings) { commandRunner = new CommandRunner(library, client); projects = new ProjectsClient(commandRunner); secrets = new SecretsClient(commandRunner); + auth = new AuthClient(commandRunner); isClientOpen = true; } static Function throwingFunctionWrapper(ThrowingFunction throwingFunction) { - return i -> { try { return throwingFunction.accept(i); } catch (Exception ex) { - throw new BitwardenClientException("Response deserialization failed"); + throw new BitwardenClientException("Response failed", ex); } }; } - public APIKeyLoginResponse accessTokenLogin(String accessToken) { - Command command = new Command(); - AccessTokenLoginRequest accessTokenLoginRequest = new AccessTokenLoginRequest(); - accessTokenLoginRequest.setAccessToken(accessToken); - command.setAccessTokenLogin(accessTokenLoginRequest); - - ResponseForAPIKeyLoginResponse response = commandRunner.runCommand(command, - throwingFunctionWrapper(Converter::ResponseForAPIKeyLoginResponseFromJsonString)); - - if (response == null || !response.getSuccess()) { - throw new BitwardenClientException(response != null ? response.getErrorMessage() : "Login failed"); - } - - return response.getData(); - } - public ProjectsClient projects() { return projects; } @@ -77,6 +63,10 @@ public SecretsClient secrets() { return secrets; } + public AuthClient auth() { + return auth; + } + @Override public void close() { if (isClientOpen) { diff --git a/languages/java/src/main/java/com/bitwarden/sdk/BitwardenClientException.java b/languages/java/src/main/java/com/bitwarden/sdk/BitwardenClientException.java index 7b6025be8..e1bc9d477 100644 --- a/languages/java/src/main/java/com/bitwarden/sdk/BitwardenClientException.java +++ b/languages/java/src/main/java/com/bitwarden/sdk/BitwardenClientException.java @@ -5,4 +5,8 @@ public class BitwardenClientException extends RuntimeException { public BitwardenClientException(String message) { super(message); } + + public BitwardenClientException(String message, Exception ex) { + super(message, ex); + } } diff --git a/languages/java/src/main/java/com/bitwarden/sdk/ProjectsClient.java b/languages/java/src/main/java/com/bitwarden/sdk/ProjectsClient.java index 73b87440c..eb96b8286 100644 --- a/languages/java/src/main/java/com/bitwarden/sdk/ProjectsClient.java +++ b/languages/java/src/main/java/com/bitwarden/sdk/ProjectsClient.java @@ -49,7 +49,7 @@ public ProjectResponse create(UUID organizationId, String name) { return response.getData(); } - public ProjectResponse update(UUID id, UUID organizationId, String name) { + public ProjectResponse update(UUID organizationId, UUID id, String name) { Command command = new Command(); ProjectsCommand projectsCommand = new ProjectsCommand(); ProjectPutRequest projectPutRequest = new ProjectPutRequest(); diff --git a/languages/java/src/main/java/com/bitwarden/sdk/SecretsClient.java b/languages/java/src/main/java/com/bitwarden/sdk/SecretsClient.java index f1a97fdc7..63324449f 100644 --- a/languages/java/src/main/java/com/bitwarden/sdk/SecretsClient.java +++ b/languages/java/src/main/java/com/bitwarden/sdk/SecretsClient.java @@ -3,6 +3,7 @@ import com.bitwarden.sdk.schema.*; import java.util.UUID; +import java.time.OffsetDateTime; public class SecretsClient { @@ -30,7 +31,7 @@ public SecretResponse get(UUID id) { return response.getData(); } - public SecretResponse create(String key, String value, String note, UUID organizationId, UUID[] projectIds) { + public SecretResponse create(UUID organizationId, String key, String value, String note, UUID[] projectIds) { Command command = new Command(); SecretsCommand secretsCommand = new SecretsCommand(); SecretCreateRequest secretCreateRequest = new SecretCreateRequest(); @@ -52,8 +53,7 @@ public SecretResponse create(String key, String value, String note, UUID organiz return response.getData(); } - public SecretResponse update(UUID id, String key, String value, String note, UUID organizationId, - UUID[] projectIds) { + public SecretResponse update(UUID organizationId, UUID id, String key, String value, String note, UUID[] projectIds) { Command command = new Command(); SecretsCommand secretsCommand = new SecretsCommand(); SecretPutRequest secretPutRequest = new SecretPutRequest(); @@ -112,4 +112,41 @@ public SecretIdentifiersResponse list(UUID organizationId) { return response.getData(); } + + public SecretsResponse getByIds(UUID[] ids) { + Command command = new Command(); + SecretsCommand secretsCommand = new SecretsCommand(); + SecretsGetRequest secretsGetRequest = new SecretsGetRequest(); + secretsGetRequest.setIDS(ids); + secretsCommand.setGetByIDS(secretsGetRequest); + command.setSecrets(secretsCommand); + + ResponseForSecretsResponse response = commandRunner.runCommand(command, + BitwardenClient.throwingFunctionWrapper(Converter::ResponseForSecretsResponseFromJsonString)); + + if (response == null || !response.getSuccess()) { + throw new BitwardenClientException(response != null ? response.getErrorMessage() : "Secret(s) not found"); + } + + return response.getData(); + } + + public SecretsSyncResponse sync(UUID organizationId, OffsetDateTime lastSyncedDate) { + Command command = new Command(); + SecretsCommand secretsCommand = new SecretsCommand(); + SecretsSyncRequest secretsSyncRequest = new SecretsSyncRequest(); + secretsSyncRequest.setOrganizationID(organizationId); + secretsSyncRequest.setLastSyncedDate(lastSyncedDate); + secretsCommand.setSync(secretsSyncRequest); + command.setSecrets(secretsCommand); + + ResponseForSecretsSyncResponse response = commandRunner.runCommand(command, + BitwardenClient.throwingFunctionWrapper(Converter::ResponseForSecretsSyncResponseFromJsonString)); + + if (response == null || !response.getSuccess()) { + throw new BitwardenClientException(response != null ? response.getErrorMessage() : "Secrets sync failed"); + } + + return response.getData(); + } } diff --git a/languages/js/sdk-client/package-lock.json b/languages/js/sdk-client/package-lock.json index eb2b74671..5911a3331 100644 --- a/languages/js/sdk-client/package-lock.json +++ b/languages/js/sdk-client/package-lock.json @@ -29,21 +29,10 @@ "node": ">=12" } }, - "node_modules/@pkgjs/parseargs": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", - "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", - "dev": true, - "license": "MIT", - "optional": true, - "engines": { - "node": ">=14" - } - }, "node_modules/@types/node": { - "version": "20.16.3", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.16.3.tgz", - "integrity": "sha512-/wdGiWRkMOm53gAsSyFMXFZHbVg7C6CbkrzHNpaHoYfsUWPg7m6ZRKtvQjgvQ9i8WT540a3ydRlRQbxjY30XxQ==", + "version": "20.16.11", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.16.11.tgz", + "integrity": "sha512-y+cTCACu92FyA5fgQSAI8A1H429g7aSK2HsO7K4XYUWc4dY5IUz55JSDIYT6/VsOLfGy8vmvQYC2hfb0iF16Uw==", "dev": true, "license": "MIT", "dependencies": { @@ -51,9 +40,9 @@ } }, "node_modules/ansi-regex": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", - "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz", + "integrity": "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==", "dev": true, "license": "MIT", "engines": { @@ -201,9 +190,9 @@ "license": "ISC" }, "node_modules/jackspeak": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-4.0.1.tgz", - "integrity": "sha512-cub8rahkh0Q/bw1+GxP7aeSe29hHHn2V4m29nnDlvCdlgU+3UGxkZp7Z53jLUdpX3jdTO0nJZUDl3xvbWc2Xog==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-4.0.2.tgz", + "integrity": "sha512-bZsjR/iRjl1Nk1UkjGpAzLNfQtzuijhn2g+pbZb98HQ1Gk8vM9hfbxeMBP+M2/UUdwj0RqGG3mlvk2MsAqwvEw==", "dev": true, "license": "BlueOak-1.0.0", "dependencies": { @@ -214,15 +203,12 @@ }, "funding": { "url": "https://github.com/sponsors/isaacs" - }, - "optionalDependencies": { - "@pkgjs/parseargs": "^0.11.0" } }, "node_modules/lru-cache": { - "version": "11.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.0.0.tgz", - "integrity": "sha512-Qv32eSV1RSCfhY3fpPE2GNZ8jgM9X7rdAfemLWqTUxwiyIC4jJ6Sy0fZ8H+oLWevO6i4/bizg7c8d8i6bxrzbA==", + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.0.1.tgz", + "integrity": "sha512-CgeuL5uom6j/ZVrg7G/+1IXqRY8JXX4Hghfy5YE0EhoYQWvndP1kufu58cmZLNIDKnRhZrXfdS9urVWx98AipQ==", "dev": true, "license": "ISC", "engines": { @@ -256,9 +242,9 @@ } }, "node_modules/package-json-from-dist": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.0.tgz", - "integrity": "sha512-dATvCeZN/8wQsGywez1mzHtTlP22H8OEfPrVMLNr4/eGa+ijtLn/6M5f0dY8UKNrC2O9UCU6SSoG3qRKnt7STw==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz", + "integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==", "dev": true, "license": "BlueOak-1.0.0" }, @@ -450,9 +436,9 @@ } }, "node_modules/typescript": { - "version": "5.5.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", - "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "version": "5.6.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz", + "integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==", "dev": true, "license": "Apache-2.0", "bin": { diff --git a/languages/js/sdk-internal/.gitignore b/languages/js/sdk-internal/.gitignore new file mode 100644 index 000000000..ef69b9de9 --- /dev/null +++ b/languages/js/sdk-internal/.gitignore @@ -0,0 +1,6 @@ +bitwarden_wasm_internal_bg.js +bitwarden_wasm_internal_bg.wasm +bitwarden_wasm_internal_bg.wasm.d.ts +bitwarden_wasm_internal_bg.wasm.js +bitwarden_wasm_internal.d.ts +bitwarden_wasm_internal.js diff --git a/languages/js/sdk-internal/LICENSE b/languages/js/sdk-internal/LICENSE new file mode 100644 index 000000000..e9d496ff7 --- /dev/null +++ b/languages/js/sdk-internal/LICENSE @@ -0,0 +1,295 @@ +BITWARDEN SOFTWARE DEVELOPMENT KIT LICENSE AGREEMENT +Version 1, 17 March 2023 + +1. Introduction + +1.1 The Bitwarden Software Development Kit (referred to in the License Agreement +as the "SDK" and available for download at the following URL +https://github.com/bitwarden/sdk) is licensed to you subject to the terms of +this License Agreement. The License Agreement forms a legally binding contract +between you and the Company in relation to your use of the SDK. + +1.2 "Bitwarden" means the Bitwarden software made available by the Company, +available for download at the following URL, as updated from time to time. + +1.3 A "Compatible Application" means any software program or service that (i) +connects to and interoperates with a current version of the Bitwarden server +products distributed by the Company; and (ii) complies with the Company’s +acceptable use policy available at the following URL: +https://bitwarden.com/terms/#acceptable_use. + +1.4 "Company" means Bitwarden Inc., organized under the laws of the State of +Delaware. + +2. Accepting this License Agreement + +2.1 In order to access or use the SDK, you must first agree to the License +Agreement. You may not access or use the SDK if you do not accept the License +Agreement. + +2.2 By clicking to accept and/or accessing or using the SDK, you hereby agree to +the terms of the License Agreement. + +2.3 You may not access or use the SDK and may not accept the License Agreement +if you are a person barred from receiving the SDK under the laws of the United +States or other countries, including the country in which you are resident or +from which you access or use the SDK. + +2.4 If you are agreeing to be bound by the License Agreement on behalf of your +employer or any other entity, you represent and warrant that you have full legal +authority to bind your employer or such other entity to the License Agreement. +If you do not have the requisite authority, you may not accept the License +Agreement or you may not access or use the SDK on behalf of your employer or +other entity. + +3. SDK License from Bitwarden + +3.1 Subject to the terms of this License Agreement, Bitwarden grants you a +limited, worldwide, royalty-free, non-assignable, non-exclusive, and +non-sublicensable license to use the SDK solely (a) to develop, test, and +demonstrate a Compatible Application; (b) to develop, test, and run a Compatible +Application for personal use by your family; or (c) to to develop, test, and run +a Compatible Application for the internal business operations of your +organization in connection with a paid license for a Bitwarden server product, +provided that in no case above may the Compatible Application be offered, +licensed, or sold to a third party. + +3.2 You agree that Bitwarden or third parties own all legal right, title and +interest in and to the SDK, including any Intellectual Property Rights that +subsist in the SDK. "Intellectual Property Rights" means any and all rights +under patent law, copyright law, trade secret law, trademark law, and any and +all other proprietary rights. Bitwarden reserves all rights not expressly +granted to you. + +3.3 You may not use this SDK to develop applications for use with software other +than Bitwarden (including non-compatible implementations of Bitwarden) or to +develop another SDK. + +3.4 You may not use the SDK for any purpose not expressly permitted by the +License Agreement. Except for contributions to Bitwarden pursuant to the +Contribution License Agreement available at this URL: +https://cla-assistant.io/bitwarden/clients, or to the extent required by +applicable third party licenses, you may not copy modify, adapt, redistribute, +decompile, reverse engineer, disassemble, or create derivative works of the SDK +or any part of the SDK. + +3.5 Use, reproduction, and distribution of a component of the SDK licensed under +an open source software license are governed solely by the terms of that open +source software license and not the License Agreement. + +3.6 You agree that the form and nature of the SDK that the Company provides may +change without prior notice to you and that future versions of the SDK may be +incompatible with applications developed on previous versions of the SDK. You +agree that the Company may stop (permanently or temporarily) providing the SDK +or any features within the SDK to you or to users generally at the Company’s +sole discretion, without prior notice to you. + +3.7 Nothing in the License Agreement gives you a right to use any of the +Company’s trade names, trademarks, service marks, logos, domain names, or other +distinctive brand features. + +3.8 You agree that you will not remove, obscure, or alter any proprietary rights +notices (including copyright and trademark notices) that may be affixed to or +contained within the SDK. + +4. Use of the SDK by You + +4.1 The Company agrees that it obtains no right, title, or interest from you (or +your licensors) under the License Agreement in or to any software applications +that you develop using the SDK, including any Intellectual Property Rights that +subsist in those applications. + +4.2 You agree to use the SDK and write applications only for purposes that are +permitted by (a) the License Agreement and (b) any applicable law, regulation or +generally accepted practices or guidelines in the relevant jurisdictions +(including any laws regarding the export of data or software to and from the +United States or other relevant countries). + +4.3 You agree that if you use the SDK to develop applications for other users, +you will protect the privacy and legal rights of those users. If the users +provide you with user names, passwords, or other login information or personal +information, you must make the users aware that the information will be +available to your application, and you must provide legally adequate privacy +notice and protection for those users. If your application stores personal or +sensitive information provided by users, it must do so securely. If the user +provides your application with Bitwarden Account information, your application +may only use that information to access the user's Bitwarden Account when, and +for the limited purposes for which, the user has given you permission to do so. + +4.4 You agree that you will not engage in any activity with the SDK, including +the development or distribution of an application, that interferes with, +disrupts, damages, or accesses in an unauthorized manner the servers, networks, +or other properties or services of any third party including, but not limited +to, the Company, or any mobile communications carrier or public cloud service. + +4.5 If you use the SDK to retrieve a user's data from Bitwarden, you acknowledge +and agree that you shall retrieve data only with the user's explicit consent and +only when, and for the limited purposes for which, the user has given you +permission to do so. + +4.6 You agree that you are solely responsible for, and that the Company has no +responsibility to you or to any third party for, any data, content, or resources +that you create, transmit or display through Bitwarden and/or applications for +Bitwarden, and for the consequences of your actions (including any loss or +damage which Bitwarden may suffer) by doing so. + +4.7 You agree that you are solely responsible for, and that the Company has no +responsibility to you or to any third party for, any breach of your obligations +under the License Agreement, any applicable third party contract or Terms of +Service, or any applicable law or regulation, and for the consequences +(including any loss or damage which the Company or any third party may suffer) +of any such breach. + +5. Third Party Applications + +5.1 If you use the SDK to integrate or run applications developed by a third +party or that access data, content or resources provided by a third party, you +agree that the Company is not responsible for those applications, data, content, +or resources. You understand that all data, content or resources which you may +access through such third party applications are the sole responsibility of the +person from which they originated and that the Company is not liable for any +loss or damage that you may experience as a result of the use or access of any +of those third party applications, data, content, or resources. + +5.2 You should be aware that the data, content, and resources presented to you +through such a third party application may be protected by intellectual property +rights which are owned by the providers (or by other persons or companies on +their behalf). You acknowledge that your use of such third party applications, +data, content, or resources may be subject to separate terms between you and the +relevant third party. In that case, the License Agreement does not affect your +legal relationship with these third parties. + +6. Use of Bitwarden Server + +You acknowledge and agree that the Bitwarden server products to which any +Compatible Application must connect is protected by intellectual property rights +which are owned by the Company and your use of the Bitwarden server products is +subject to additional terms not set forth in this License Agreement. + +7. Terminating this License Agreement + +7.1 The License Agreement will continue to apply until terminated by either you +or the Company as set out below. + +7.2 If you want to terminate the License Agreement, you may do so by ceasing +your use of the SDK and any relevant developer credentials. + +7.3 The Company may at any time, terminate the License Agreement with you if: + +(a) you have breached any provision of the License Agreement; or + +(b) the Company is required to do so by law; or + +(c) a third party with whom the Company offered certain parts of the SDK to you +has terminated its relationship with the Company or ceased to offer certain +parts of the SDK to either the Company or to you; or + +(d) the Company decides to no longer provide the SDK or certain parts of the SDK +to users in the country in which you are resident or from which you use the +service, or the provision of the SDK or certain SDK services to you by the +Company is, in the Company’'s sole discretion, no longer commercially viable or +technically practicable. + +7.4 When the License Agreement comes to an end, all of the legal rights, +obligations and liabilities that you and the Company have benefited from, been +subject to (or which have accrued over time whilst the License Agreement has +been in force) or which are expressed to continue indefinitely, shall be +unaffected by this cessation, and the provisions of paragraph 12.8 shall +continue to apply to such rights, obligations and liabilities indefinitely. + +8. NO SUPPORT + +The Company is not obligated under this License Agreement to provide you any +support services for the SDK. Any support provided is at the Company’s sole +discretion and provided on an "as is" basis and without warranty of any kind. + +9. DISCLAIMER OF WARRANTIES + +9.1 YOU EXPRESSLY UNDERSTAND AND AGREE THAT YOUR USE OF THE SDK IS AT YOUR SOLE +RISK AND THAT THE SDK IS PROVIDED "AS IS" AND "AS AVAILABLE" WITHOUT WARRANTY OF +ANY KIND FROM Bitwarden. + +9.2 YOUR USE OF THE SDK AND ANY MATERIAL DOWNLOADED OR OTHERWISE OBTAINED +THROUGH THE USE OF THE SDK IS AT YOUR OWN DISCRETION AND RISK AND YOU ARE SOLELY +RESPONSIBLE FOR ANY DAMAGE TO YOUR COMPUTER SYSTEM OR OTHER DEVICE OR LOSS OF +DATA THAT RESULTS FROM SUCH USE. + +9.3 THE COMPANY FURTHER EXPRESSLY DISCLAIMS ALL WARRANTIES AND CONDITIONS OF ANY +KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE IMPLIED +WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE +AND NON-INFRINGEMENT. + +10. LIMITATION OF LIABILITY + +YOU EXPRESSLY UNDERSTAND AND AGREE THAT THE COMPANY, ITS SUBSIDIARIES AND +AFFILIATES, AND ITS LICENSORS SHALL NOT BE LIABLE TO YOU UNDER ANY THEORY OF +LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL, +STATUTORY, OR EXEMPLARY DAMAGES THAT MAY BE INCURRED BY YOU, INCLUDING ANY LOSS +OF DATA, WHETHER OR NOT THE COMPANY OR ITS REPRESENTATIVES HAVE BEEN ADVISED OF +OR SHOULD HAVE BEEN AWARE OF THE POSSIBILITY OF ANY SUCH LOSSES ARISING. + +11. Indemnification + +To the maximum extent permitted by law, you agree to defend, indemnify and hold +harmless the Company, its affiliates and their respective directors, officers, +employees and agents from and against any and all claims, actions, suits or +proceedings, as well as any and all losses, liabilities, damages, costs and +expenses (including reasonable attorneys fees) arising out of or accruing from +(a) your use of the SDK, (b) any application you develop on the SDK that +infringes any copyright, trademark, trade secret, trade dress, patent or other +intellectual property right of any person or defames any person or violates +their rights of publicity or privacy, and (c) any non-compliance by you with the +License Agreement. + +12. General Legal Terms + +12.1 The Company may make changes to the License Agreement as it distributes new +versions of the SDK. When these changes are made, the Company will make a new +version of the License Agreement available on the website where the SDK is made +available. + +12.2 The License Agreement constitutes the whole legal agreement between you and +the Company and governs your use of the SDK (excluding any services or software +which the Company may provide to you under a separate written agreement), and +completely replaces any prior agreements between you and the Company in relation +to the SDK. + +12.3 You agree that if the Company does not exercise or enforce any legal right +or remedy which is contained in the License Agreement (or which the Company has +the benefit of under any applicable law), this will not be taken to be a formal +waiver of the Company's rights and that those rights or remedies will still be +available to the Company. + +12.4 If any court of law, having the jurisdiction to decide on this matter, +rules that any provision of the License Agreement is invalid, then that +provision will be removed from the License Agreement without affecting the rest +of the License Agreement. The remaining provisions of the License Agreement will +continue to be valid and enforceable. + +12.5 You acknowledge and agree that each member of the group of companies of +which the Company is the parent shall be third party beneficiaries to the +License Agreement and that such other companies shall be entitled to directly +enforce, and rely upon, any provision of the License Agreement that confers a +benefit on them or rights in favor of them. Other than this, no other person or +company shall be third party beneficiaries to the License Agreement. + +12.6 EXPORT RESTRICTIONS. THE SDK IS SUBJECT TO UNITED STATES EXPORT LAWS AND +REGULATIONS. YOU MUST COMPLY WITH ALL DOMESTIC AND INTERNATIONAL EXPORT LAWS AND +REGULATIONS THAT APPLY TO THE SDK. THESE LAWS INCLUDE RESTRICTIONS ON +DESTINATIONS, END USERS, AND END USE. + +12.7 The rights granted in the License Agreement may not be assigned or +transferred by either you or the Company without the prior written approval of +the other party, provided that the Company may assign this License Agreement +upon notice to you in connection with an acquisition, merger, sale of assets, or +similar corporate change in control for the Company or the Intellectual Property +Rights in the SDK. + +12.8 The License Agreement, and any dispute relating to or arising out of this +License Agreement, shall be governed by the laws of the State of California +without regard to its conflict of laws provisions. You and the Company agree to +submit to the exclusive jurisdiction of the courts located within the county of +Los Angeles, California to resolve any dispute or legal matter arising from the +License Agreement. Notwithstanding this, you agree that the Company shall be +allowed to apply for injunctive remedies, or any equivalent type of urgent legal +relief, in any forum or jurisdiction. diff --git a/languages/js/sdk-internal/README.md b/languages/js/sdk-internal/README.md new file mode 100644 index 000000000..9391aa071 --- /dev/null +++ b/languages/js/sdk-internal/README.md @@ -0,0 +1,3 @@ +# @bitwarden/sdk-internal + +**Note:** This is only for internal use. Bitwarden will not provide any support for this package. diff --git a/languages/js/sdk-internal/index.js b/languages/js/sdk-internal/index.js new file mode 100644 index 000000000..0525f7aa4 --- /dev/null +++ b/languages/js/sdk-internal/index.js @@ -0,0 +1,8 @@ +import { __wbg_set_wasm } from "./bitwarden_wasm_internal_bg.js"; + +// In order to support a fallback strategy for web we need to conditionally load the wasm file +export function init(wasm) { + __wbg_set_wasm(wasm); +} + +export * from "./bitwarden_wasm_internal_bg.js"; diff --git a/languages/js/sdk-internal/package.json b/languages/js/sdk-internal/package.json new file mode 100644 index 000000000..29e5c5a54 --- /dev/null +++ b/languages/js/sdk-internal/package.json @@ -0,0 +1,25 @@ +{ + "name": "@bitwarden/sdk-internal", + "version": "0.1.0", + "license": "SEE LICENSE IN LICENSE", + "files": [ + "bitwarden_wasm_internal_bg.js", + "bitwarden_wasm_internal_bg.wasm", + "bitwarden_wasm_internal_bg.wasm.d.ts", + "bitwarden_wasm_internal_bg.wasm.js", + "bitwarden_wasm_internal.d.ts", + "bitwarden_wasm_internal.js", + "index.js", + "node/bitwarden_wasm_internal_bg.wasm", + "node/bitwarden_wasm_internal_bg.wasm.d.ts", + "node/bitwarden_wasm_internal.d.ts", + "node/bitwarden_wasm_internal.js" + ], + "main": "node/bitwarden_wasm_internal.js", + "module": "index.js", + "types": "bitwarden_wasm_internal.d.ts", + "scripts": {}, + "sideEffects": [ + "./bitwarden_wasm_internal.js" + ] +} diff --git a/languages/kotlin/publish-local.sh b/languages/kotlin/publish-local.sh new file mode 100755 index 000000000..68e67455f --- /dev/null +++ b/languages/kotlin/publish-local.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -e + +cd "$(dirname "$0")" + +mkdir -p ./sdk/src/main/jniLibs/{arm64-v8a,armeabi-v7a,x86_64,x86} + +# Build arm64 for emulator +cross build -p bitwarden-uniffi --release --target=aarch64-linux-android +mv ../../target/aarch64-linux-android/release/libbitwarden_uniffi.so ./sdk/src/main/jniLibs/arm64-v8a/libbitwarden_uniffi.so + +# Generate latest bindings +./build-schemas.sh + +# Publish to local maven +./gradlew sdk:publishToMavenLocal -Pversion=LOCAL diff --git a/languages/kotlin/sdk/build.gradle b/languages/kotlin/sdk/build.gradle index c41bccac1..2006e4673 100644 --- a/languages/kotlin/sdk/build.gradle +++ b/languages/kotlin/sdk/build.gradle @@ -12,8 +12,8 @@ android { minSdk 28 targetSdk 34 - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles "consumer-rules.pro" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' + consumerProguardFiles 'consumer-rules.pro' } buildTypes { @@ -31,7 +31,7 @@ android { } lint { - baseline = file("lint-baseline.xml") + baseline = file('lint-baseline.xml') } publishing { @@ -47,23 +47,25 @@ publishing { groupId = 'com.bitwarden' artifactId = 'sdk-android' - // Determine the version from the git history. - // - // PRs: use the branch name. - // Main: Grab it from `crates/bitwarden/Cargo.toml` + if (findProperty('version') == 'unspecified') { + // Determine the version from the git history. + // + // PRs: use the branch name. + // Main: Grab it from `crates/bitwarden/Cargo.toml` - def branchName = "git branch --show-current".execute().text.trim() + def branchName = 'git branch --show-current'.execute().text.trim() - if (branchName == "main") { - def content = ['grep', '-o', '^version = ".*"', '../../Cargo.toml'].execute().text.trim() - def match = ~/version = "(.*)"/ - def matcher = match.matcher(content) - matcher.find() + if (branchName == 'main') { + def content = ['grep', '-o', '^version = ".*"', '../../Cargo.toml'].execute().text.trim() + def match = ~/version = "(.*)"/ + def matcher = match.matcher(content) + matcher.find() - version = "${matcher.group(1)}-SNAPSHOT" - } else { - // branchName-SNAPSHOT - version = "${branchName.replaceAll('/', '-')}-SNAPSHOT" + version = "${matcher.group(1)}-SNAPSHOT" + } else { + // branchName-SNAPSHOT + version = "${branchName.replaceAll('/', '-')}-SNAPSHOT" + } } afterEvaluate { @@ -73,19 +75,38 @@ publishing { } repositories { maven { - name = "GitHubPackages" - url = "https://maven.pkg.github.com/bitwarden/sdk" + name = 'GitHubPackages' + url = 'https://maven.pkg.github.com/bitwarden/sdk' credentials { - username = System.getenv("GITHUB_ACTOR") - password = System.getenv("GITHUB_TOKEN") + username = System.getenv('GITHUB_ACTOR') + password = System.getenv('GITHUB_TOKEN') } } } } +// Find and include the classes.jar from platform-verifier. +// +// Based on the instructions from the readme in https://github.com/rustls/rustls-platform-verifier +// and issue details from https://github.com/rustls/rustls-platform-verifier/issues/115. +File findRustlsPlatformVerifierClassesJar() { + def dependencyText = providers.exec { + it.workingDir = new File('../../') + commandLine('cargo', 'metadata', '--format-version', '1', '--manifest-path', 'crates/bitwarden-uniffi/Cargo.toml') + }.standardOutput.asText.get() + + def dependencyJson = new groovy.json.JsonSlurper().parseText(dependencyText) + def manifestPath = file(dependencyJson.packages.find { it.name == "rustls-platform-verifier-android" }.manifest_path) + + def aar = fileTree(manifestPath.parentFile).matching { + include "maven/rustls/rustls-platform-verifier/*/rustls-platform-verifier-*.aar" + }.getSingleFile() + return zipTree(aar).matching { include 'classes.jar'}.getSingleFile() +} + dependencies { implementation 'net.java.dev.jna:jna:5.14.0@aar' - implementation 'rustls:rustls-platform-verifier:latest.release' + implementation files(findRustlsPlatformVerifierClassesJar()) implementation 'androidx.core:core-ktx:1.13.0' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3' diff --git a/languages/kotlin/settings.gradle b/languages/kotlin/settings.gradle index e82ac3727..fac8f3fae 100644 --- a/languages/kotlin/settings.gradle +++ b/languages/kotlin/settings.gradle @@ -10,25 +10,9 @@ dependencyResolutionManagement { repositories { google() mavenCentral() - - maven { - url = findRustlsPlatformVerifierProject() - metadataSources.artifact() - } } } -String findRustlsPlatformVerifierProject() { - def dependencyText = providers.exec { - it.workingDir = new File("../../") - commandLine("cargo", "metadata", "--format-version", "1", "--manifest-path", "crates/bitwarden-uniffi/Cargo.toml") - }.standardOutput.asText.get() - - def dependencyJson = new groovy.json.JsonSlurper().parseText(dependencyText) - def manifestPath = file(dependencyJson.packages.find { it.name == "rustls-platform-verifier-android" }.manifest_path) - return new File(manifestPath.parentFile, "maven").path -} - -rootProject.name = "My Application" +rootProject.name = 'My Application' include ':app' include ':sdk' diff --git a/languages/php/.gitignore b/languages/php/.gitignore index b2a69e9a0..5d6ed424e 100644 --- a/languages/php/.gitignore +++ b/languages/php/.gitignore @@ -1,2 +1,4 @@ .DS_Store vendor +src/lib/ +src/Schemas/ diff --git a/languages/php/INSTALL.md b/languages/php/INSTALL.md new file mode 100644 index 000000000..299053389 --- /dev/null +++ b/languages/php/INSTALL.md @@ -0,0 +1,56 @@ +# PHP Installation + +## Introduction + +Composer is used to build the PHP Bitwarden client library. + +## Prerequisites + +- PHP >= 8.0 +- FFI extension enabled in PHP configuration +- Composer +- Bitwarden SDK native library. + - Expected in one of below locations, depending on the OS and architecture. + The `src` is relative path to the [src](./src) directory. + - Windows x86_64: `src\lib\windows-x64\bitwarden_c.dll` + - Linux x86_64: `src/lib/linux-x64/libbitwarden_c.so` + - macOS x86_64: `src/lib/macos-x64/libbitwarden_c.dylib` + - macOS aarch64: `src/lib/macos-arm64/libbitwarden_c.dylib` + - If you prefer to build the SDK yourself, see the [SDK README.md](../../README.md) for instructions. + +## Build Commands + +```shell +composer install +``` + +## Example + +### macOS + +#### Install Prerequisites + +Use brew Composer and PHP + +```shell +brew install php +brew install composer +``` + +#### Build Commands + +```shell +composer install +``` + +## Example SDK Usage Project + +```shell +export ACCESS_TOKEN="" +export STATE_FILE="" +export ORGANIZATION_ID="" +export API_URL="https://api.bitwarden.com" +export IDENTITY_URL="https://identity.bitwarden.com" + +php example.php +``` diff --git a/languages/php/README.md b/languages/php/README.md index 9e4a9385d..61991bd0e 100644 --- a/languages/php/README.md +++ b/languages/php/README.md @@ -1,100 +1,121 @@ # Bitwarden Secrets Manager SDK wrapper for PHP PHP bindings for interacting with the [Bitwarden Secrets Manager]. This is a beta release and might be missing some functionality. -Supported are CRUD operations on project and secret entities. ## Installation -Requirements: -- PHP >= 8.0 -- Composer -- Bitwarden C libraries which you can generate using BitwardenSDK and following instructions in its readme (requires Rust). https://github.com/bitwarden/sdk -If you are not using the standalone version of this library, file will be placed in `target/debug` folder if you are using from BitwardenSDK repository. -- Access token for the Bitwarden account - +See the [installation instructions](./INSTALL.md) ## Usage -To interact with the client first you need to obtain the access token from Bitwarden. -You can then initialize BitwardenSettings passing $api_url and $identity_url if needed. These parameteres are -optional and if they are not defined, BitwardenSettings instance will try to get these values from ENV, and -if they are not defined there as well, it will use defaults: `https://api.bitwarden.com` as api_url and -`https://identity.bitwarden.com` as identity_url. You can also pass device type as argument but that is entirely -optional. +### Create access token -Passing BitwardenSettings instance to BitwardenClient will initialize it. Before using the client you must -be authorized by calling the access_token_login method passing your Bitwarden access token to it. +To interact with the client first you need to obtain the access token from Bitwarden. +Review the help documentation on [Access Tokens]. +### Create new Bitwarden client ```php -$access_token = ''; -$api_url = ""; -$identity_url = ""; +require_once 'vendor/autoload.php'; + +$access_token = ""; +$state_file = ""; +$organization_id = ""; +$api_url = "https://api.bitwarden.com"; +$identity_url = "https://identity.bitwarden.com"; + $bitwarden_settings = new \Bitwarden\Sdk\BitwardenSettings($api_url, $identity_url); $bitwarden_client = new \Bitwarden\Sdk\BitwardenClient($bitwarden_settings); -$bitwarden_client->access_token_login($access_token); +$bitwarden_client->auth->login_access_token($access_token, $state_file); ``` -After successful authorization you can interact with client to manage your projects and secrets. -```php -$organization_id = ""; +Initialize `BitwardenSettings` by passing `$api_url` and `$identity_url` or set to null to use the defaults. +The default for `api_url` is `https://api.bitwarden.com` and for `identity_url` is `https://identity.bitwarden.com`. -$bitwarden_client = new \Bitwarden\Sdk\BitwardenClient($bitwarden_settings); -$res = $bitwarden_client->access_token_login($access_token); +### Create new project -// create project -$name = "PHP project" -$res = $bitwarden_client->projects->create($name, $organization_id); +```php +$name = "PHP project"; +$res = $bitwarden_client->projects->create($organization_id, $name); $project_id = $res->id; +``` -// get project +### Get project + +```php $res = $bitwarden_client->projects->get($project_id); +``` + +### List all projects -// list projects +```php $res = $bitwarden_client->projects->list($organization_id); +``` -// update project -$name = "Updated PHP project" -$res = $bitwarden_client->projects->put($project_id, $name, $organization_id); +### Update project -// get secret -$res = $bitwarden_client->secrets->get($secret_id); +```php +$name = "Updated PHP project"; +$res = $bitwarden_client->projects->update($organization_id, $project_id, $name); +``` -// list secrets -$res = $bitwarden_client->secrets->list($organization_id); +### Delete project -// delete project +```php $res = $bitwarden_client->projects->delete([$project_id]); +``` +### Create new secret + +```php +$key = "Secret key"; +$note = "Secret note"; +$value = "Secret value"; +$res = $bitwarden_client->secrets->create($organization_id, $key, $value, $note, [$project_id]); +$secret_id = $res->id; ``` -Similarly, you interact with secrets: +### Get secret + ```php -$organization_id = ""; +$res = $bitwarden_client->secrets->get($secret_id); +``` -// create secret -$key = "AWS secret key"; -$note = "Private account"; -$secret = "76asaj,Is_)" -$res = $bitwarden_client->secrets->create($key, $note, $organization_id, [$project_id], $secret); -$secret_id = $res->id; +### Get multiple secrets -// get secret -$res = $bitwarden_sdk->secrets->get($secret_id); +```php +$res = $bitwarden_client->secrets->get_by_ids([$secret_id]); +``` -// list secrets +### List all secrets + +```php $res = $bitwarden_client->secrets->list($organization_id); +``` + +### Update secret + +```php +$key = "Updated key"; +$note = "Updated note"; +$value = "Updated value"; +$res = $bitwarden_client->secrets->update($organization_id, $secret_id, $key, $value, $note, [$project_id]); +``` -// update secret -$note = "Updated account"; -$key = "AWS private updated" -$secret = "7uYTE,:Aer" -$res = $bitwarden_client->secrets->update($secret_id, $key, $note, $organization_id, [$project_id], $secret); +### Sync secrets -// delete secret -$res = $bitwarden_sdk->secrets->delete([$secret_id]); +```php +$last_synced_date = "2024-09-01T00:00:00Z"; +$res = $bitwarden_client->secrets->sync($organization_id, $last_synced_date); +``` + +### Delete secret + +```php +$res = $bitwarden_client->secrets->delete([$secret_id]); ``` +[Access Tokens]: https://bitwarden.com/help/access-tokens/ [Bitwarden Secrets Manager]: https://bitwarden.com/products/secrets-manager/ diff --git a/languages/php/composer.json b/languages/php/composer.json index 85447e72a..6df44ed0b 100644 --- a/languages/php/composer.json +++ b/languages/php/composer.json @@ -4,16 +4,16 @@ "type": "library", "keywords": ["bitwarden","sdk","password-manager"], "homepage": "https://github.com/bitwarden/sdk", - "version": "0.1.0", + "version": "1.0.0", "require": { "php": "^8.0", - "swaggest/json-schema": "^0.12.42", "ext-ffi": "*" }, "autoload": { "psr-4": { "Bitwarden\\Sdk\\": "src/" - } + }, + "files": ["src/Schemas/Schemas.php"] }, "authors": [ { diff --git a/languages/php/composer.lock b/languages/php/composer.lock index fc6b42c4f..187511304 100644 --- a/languages/php/composer.lock +++ b/languages/php/composer.lock @@ -4,234 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7081b1bfe099982a63ad06d5ab9fa66d", - "packages": [ - { - "name": "phplang/scope-exit", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/phplang/scope-exit.git", - "reference": "239b73abe89f9414aa85a7ca075ec9445629192b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phplang/scope-exit/zipball/239b73abe89f9414aa85a7ca075ec9445629192b", - "reference": "239b73abe89f9414aa85a7ca075ec9445629192b", - "shasum": "" - }, - "require-dev": { - "phpunit/phpunit": "*" - }, - "type": "library", - "autoload": { - "psr-4": { - "PhpLang\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD" - ], - "authors": [ - { - "name": "Sara Golemon", - "email": "pollita@php.net", - "homepage": "https://twitter.com/SaraMG", - "role": "Developer" - } - ], - "description": "Emulation of SCOPE_EXIT construct from C++", - "homepage": "https://github.com/phplang/scope-exit", - "keywords": [ - "cleanup", - "exit", - "scope" - ], - "support": { - "issues": "https://github.com/phplang/scope-exit/issues", - "source": "https://github.com/phplang/scope-exit/tree/master" - }, - "time": "2016-09-17T00:15:18+00:00" - }, - { - "name": "swaggest/json-diff", - "version": "v3.10.4", - "source": { - "type": "git", - "url": "https://github.com/swaggest/json-diff.git", - "reference": "f4e511708060ff7511a3743fab4aa484a062bcfb" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/swaggest/json-diff/zipball/f4e511708060ff7511a3743fab4aa484a062bcfb", - "reference": "f4e511708060ff7511a3743fab4aa484a062bcfb", - "shasum": "" - }, - "require": { - "ext-json": "*" - }, - "require-dev": { - "phperf/phpunit": "4.8.37" - }, - "type": "library", - "autoload": { - "psr-4": { - "Swaggest\\JsonDiff\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Viacheslav Poturaev", - "email": "vearutop@gmail.com" - } - ], - "description": "JSON diff/rearrange/patch/pointer library for PHP", - "support": { - "issues": "https://github.com/swaggest/json-diff/issues", - "source": "https://github.com/swaggest/json-diff/tree/v3.10.4" - }, - "time": "2022-11-09T13:21:05+00:00" - }, - { - "name": "swaggest/json-schema", - "version": "v0.12.42", - "source": { - "type": "git", - "url": "https://github.com/swaggest/php-json-schema.git", - "reference": "d23adb53808b8e2da36f75bc0188546e4cbe3b45" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/swaggest/php-json-schema/zipball/d23adb53808b8e2da36f75bc0188546e4cbe3b45", - "reference": "d23adb53808b8e2da36f75bc0188546e4cbe3b45", - "shasum": "" - }, - "require": { - "ext-json": "*", - "php": ">=5.4", - "phplang/scope-exit": "^1.0", - "swaggest/json-diff": "^3.8.2", - "symfony/polyfill-mbstring": "^1.19" - }, - "require-dev": { - "phperf/phpunit": "4.8.37" - }, - "suggest": { - "ext-mbstring": "For better performance" - }, - "type": "library", - "autoload": { - "psr-4": { - "Swaggest\\JsonSchema\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Viacheslav Poturaev", - "email": "vearutop@gmail.com" - } - ], - "description": "High definition PHP structures with JSON-schema based validation", - "support": { - "email": "vearutop@gmail.com", - "issues": "https://github.com/swaggest/php-json-schema/issues", - "source": "https://github.com/swaggest/php-json-schema/tree/v0.12.42" - }, - "time": "2023-09-12T14:43:42+00:00" - }, - { - "name": "symfony/polyfill-mbstring", - "version": "v1.28.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "42292d99c55abe617799667f454222c54c60e229" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/42292d99c55abe617799667f454222c54c60e229", - "reference": "42292d99c55abe617799667f454222c54c60e229", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "provide": { - "ext-mbstring": "*" - }, - "suggest": { - "ext-mbstring": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Mbstring\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for the Mbstring extension", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "mbstring", - "polyfill", - "portable", - "shim" - ], - "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.28.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2023-07-28T09:04:16+00:00" - } - ], + "content-hash": "1769eb8cdcb42d17f993aa0ef123895b", + "packages": [], "packages-dev": [], "aliases": [], "minimum-stability": "stable", diff --git a/languages/php/example.php b/languages/php/example.php index 7eafcb96a..864a4ca23 100644 --- a/languages/php/example.php +++ b/languages/php/example.php @@ -3,45 +3,101 @@ require_once 'vendor/autoload.php'; $access_token = getenv('ACCESS_TOKEN'); +$state_file = getenv('STATE_FILE'); $organization_id = getenv('ORGANIZATION_ID'); // Configuring the URLS is optional, set them to null to use the default values $api_url = getenv('API_URL'); $identity_url = getenv('IDENTITY_URL'); -$client_settings = new \Bitwarden\Sdk\BitwardenSettings($api_url, $identity_url); +try { + $client_settings = new \Bitwarden\Sdk\BitwardenSettings($api_url, $identity_url); -$bitwarden_client = new \Bitwarden\Sdk\BitwardenClient($client_settings); -$bitwarden_client->access_token_login($access_token); + $bitwarden_client = new \Bitwarden\Sdk\BitwardenClient($client_settings); -// create project -$res = $bitwarden_client->projects->create('php project', $organization_id); -$project_id = $res->id; + $bitwarden_client->auth->login_access_token($access_token, $state_file); -// get project -$res = $bitwarden_client->projects->get($project_id); + // create project + print("Projects:\n"); + $res = $bitwarden_client->projects->create($organization_id, 'php project'); + $project_id = $res->id; + print("\tcreate: '" . $project_id . "'\n\n"); -// list projects -$res = $bitwarden_client->projects->list($organization_id); + // get project + $res = $bitwarden_client->projects->get($project_id); + print("\tget: '" . $res->name . "'\n\n"); -// update project -$res = $bitwarden_client->projects->put($project_id, 'php test awesome', $organization_id); + // list projects + $res = $bitwarden_client->projects->list($organization_id); + print("\tlist:\n"); + foreach ($res->data as $project) { + print("\t\tID: '" . $project->id . "', Name: '" . $project->name . "'\n"); + } + print("\n"); -// create secret -$res = $bitwarden_client->secrets->create("New Key", "hello world", $organization_id, [$project_id], "123"); -$secret_id = $res->id; + // update project + $res = $bitwarden_client->projects->update($organization_id, $project_id, 'php test project'); + print("\tupdate: '" . $res->name . "'\n\n"); -// get secret -$res = $bitwarden_client->secrets->get($secret_id); + // sync secrets + print("Secrets:\n"); + print("\tSyncing secrets...\n"); + $res = $bitwarden_client->secrets->sync($organization_id, null); + $now = new DateTime(); + $now_string = $now->format('Y-m-d\TH:i:s.u\Z'); + print("\t\tSync has changes: " . ($res->hasChanges ? 'true' : 'false') . "\n\n"); -// list secrets -$res = $bitwarden_client->secrets->list($organization_id); + print("\tSyncing again to ensure no changes since last sync...\n"); + $res = $bitwarden_client->secrets->sync($organization_id, $now_string); + print("\t\tSync has changes: " . ($res->hasChanges ? 'true' : 'false') . "\n\n"); -// update secret -$res = $bitwarden_client->secrets->update($secret_id, "hello world 2", "hello", $organization_id, [$project_id], "123"); + // create secret + $res = $bitwarden_client->secrets->create($organization_id, "New Key", "New value", "New note", [$project_id]); + $secret_id = $res->id; + print("\tcreate: '" . $secret_id . "'\n\n"); -// delete secret -$res = $bitwarden_client->secrets->delete([$secret_id]); + // get secret + $res = $bitwarden_client->secrets->get($secret_id); + print("\tget: '" . $res->key . "'\n\n"); -// delete project -$res = $bitwarden_client->projects->delete([$project_id]); + // get multiple secrets by ids + $res = $bitwarden_client->secrets->get_by_ids([$secret_id]); + print("\tget_by_ids:\n"); + foreach ($res->data as $secret) { + print("\t\tID: '" . $secret->id . "', Key: '" . $secret->key . "'\n"); + } + print("\n"); + + // list secrets + $res = $bitwarden_client->secrets->list($organization_id); + print("\tlist:\n"); + foreach ($res->data as $secret) { + print("\t\tID: '" . $secret->id . "', Key: '" . $secret->key . "'\n"); + } + print("\n"); + + // update secret + $res = $bitwarden_client->secrets->update($organization_id, $secret_id, "Updated key", "Updated value", "Updated note", [$project_id]); + print("\tupdate: '" . $res->key . "'\n\n"); + + // delete secret + print("Cleaning up secrets and projects:\n"); + $res = $bitwarden_client->secrets->delete([$secret_id]); + print("\tdelete:\n"); + foreach ($res->data as $secret) { + print("\t\tdeleted secret: '" . $secret->id . "'\n"); + } + print("\n"); + + // delete project + $res = $bitwarden_client->projects->delete([$project_id]); + print("\tdelete:\n"); + foreach ($res->data as $project) { + print("\t\tdeleted project: '" . $project->id . "'\n"); + } + print("\n"); + +} catch (Exception $e) { + print("Error: " . $e->getMessage() . "\n"); + exit(1); +} diff --git a/languages/php/src/AuthClient.php b/languages/php/src/AuthClient.php new file mode 100644 index 000000000..449c76905 --- /dev/null +++ b/languages/php/src/AuthClient.php @@ -0,0 +1,35 @@ +commandRunner = $commandRunner; + } + + /** + * @throws Exception + */ + public function login_access_token(string $access_token, ?string $state_file): void + { + $access_token_request = new AccessTokenLoginRequest($access_token, $state_file); + $command = new Command(passwordLogin: null, apiKeyLogin: null, loginAccessToken: $access_token_request, + getUserApiKey: null, fingerprint: null, sync: null, secrets: null, projects: null, generators: null); + try { + $result = $this->commandRunner->run($command); + if (!isset($result->authenticated) || !$result->authenticated) { + throw new Exception("Unauthorized"); + } + } catch (Exception $exception) { + throw new Exception("Authorization error: " . $exception->getMessage()); + } + } +} diff --git a/languages/php/src/BitwardenClient.php b/languages/php/src/BitwardenClient.php index 79fccdf9c..c125b6aa7 100644 --- a/languages/php/src/BitwardenClient.php +++ b/languages/php/src/BitwardenClient.php @@ -2,59 +2,40 @@ namespace Bitwarden\Sdk; -use Bitwarden\Sdk\Schemas\AccessTokenLoginRequest; -use Bitwarden\Sdk\schemas\ClientSettings; -use Bitwarden\Sdk\Schemas\Command; -use FFI; -use Swaggest\JsonDiff\Exception; - +use Bitwarden\Sdk\Schemas\ClientSettings; +use Bitwarden\Sdk\Schemas\DeviceType; +use JsonException; class BitwardenClient { - private BitwardenLib $bitwarden_lib; - - private ClientSettings $clientSettings; - public ProjectsClient $projects; public SecretsClient $secrets; - private CommandRunner $commandRunner; + public AuthClient $auth; - private FFI\CData $handle; + private BitwardenLib $bitwarden_lib; + private ClientSettings $clientSettings; + + private CommandRunner $commandRunner; + + /** + * @throws JsonException + */ public function __construct(BitwardenSettings $bitwardenSettings) { - $this->clientSettings = new ClientSettings(); - $this->clientSettings->apiUrl = $bitwardenSettings->get_api_url(); - $this->clientSettings->identityUrl = $bitwardenSettings->get_identity_url(); - $this->clientSettings->userAgent = "Bitwarden PHP-SDK"; + $this->clientSettings = new ClientSettings(apiUrl: $bitwardenSettings->get_api_url(), + deviceType: DeviceType::$SDK, identityUrl: $bitwardenSettings->get_identity_url(), + userAgent: "Bitwarden PHP-SDK"); $this->bitwarden_lib = new BitwardenLib(); - $this->handle = $this->bitwarden_lib->init($this->clientSettings); + $this->bitwarden_lib->init($this->clientSettings); - $this->commandRunner = new CommandRunner($this->bitwarden_lib, $this->handle); + $this->commandRunner = new CommandRunner($this->bitwarden_lib); $this->projects = new ProjectsClient($this->commandRunner); $this->secrets = new SecretsClient($this->commandRunner); - } - - /** - * @throws \Exception - */ - public function access_token_login(string $access_token) - { - $access_token_request = new AccessTokenLoginRequest(); - $access_token_request->accessToken = $access_token; - $command = new Command(); - $command->accessTokenLogin = $access_token_request->jsonSerialize(); - $result = $this->commandRunner->run($command); - if (!isset($result->authenticated)) { - throw new \Exception("Authorization error"); - } - - if ($result->authenticated == False) { - throw new \Exception("Unauthorized"); - } + $this->auth = new AuthClient($this->commandRunner); } public function __destruct() diff --git a/languages/php/src/BitwardenLib.php b/languages/php/src/BitwardenLib.php index 351728986..53be3299b 100644 --- a/languages/php/src/BitwardenLib.php +++ b/languages/php/src/BitwardenLib.php @@ -4,10 +4,11 @@ use Bitwarden\Sdk\Schemas\ClientSettings; use Bitwarden\Sdk\Schemas\Command; +use Exception; use FFI; -use Swaggest\JsonDiff\Exception; -use Swaggest\JsonSchema\JsonSchema; - +use JsonException; +use RuntimeException; +use stdClass; class BitwardenLib { @@ -15,36 +16,36 @@ class BitwardenLib public FFI\CData $handle; /** - * @throws \Exception + * @throws Exception */ public function __construct() { $lib_file = null; if (PHP_OS === 'WINNT') { - $lib_file = '/lib/windows-x64/bitwarden_c.dll'; - if (file_exists($lib_file) == false) { - $lib_file = __DIR__.'/../../../target/debug/bitwarden_c.dll'; + $lib_file = __DIR__ . '/lib/windows-x64/bitwarden_c.dll'; + if (!file_exists($lib_file)) { + $lib_file = __DIR__ . '/../../../target/debug/bitwarden_c.dll'; } } elseif (PHP_OS === 'Linux') { - $lib_file = '/lib/linux-x64/libbitwarden_c.so'; - if (file_exists($lib_file) == false) { - $lib_file = __DIR__.'/../../../target/debug/libbitwarden_c.so'; + $lib_file = __DIR__ . '/lib/linux-x64/libbitwarden_c.so'; + if (!file_exists($lib_file)) { + $lib_file = __DIR__ . '/../../../target/debug/libbitwarden_c.so'; } } elseif (PHP_OS === 'Darwin') { $architecture = trim(exec('uname -m')); if ($architecture === 'x86_64' || $architecture === 'amd64') { - $lib_file = __DIR__.'/lib/macos-x64/libbitwarden_c.dylib'; + $lib_file = __DIR__ . '/lib/macos-x64/libbitwarden_c.dylib'; } elseif ($architecture === 'arm64') { - $lib_file = __DIR__.'/lib/macos-arm64/libbitwarden_c.dylib'; + $lib_file = __DIR__ . '/lib/macos-arm64/libbitwarden_c.dylib'; } - if (file_exists($lib_file) == false) { - $lib_file = __DIR__.'/../../../target/debug/libbitwarden_c.dylib'; + if (!file_exists($lib_file)) { + $lib_file = __DIR__ . '/../../../target/debug/libbitwarden_c.dylib'; } } - if ($lib_file == null || is_file($lib_file) == false) { - throw new \Exception("Lib file not found"); + if ($lib_file == null || !is_file($lib_file)) { + throw new Exception("Lib file not found"); } $this->ffi = FFI::cdef(' @@ -55,20 +56,29 @@ public function __construct() ); } + /** + * @throws JsonException + * @throws Exception + */ public function init(ClientSettings $client_settings): FFI\CData { - $this->handle = $this->ffi->init(json_encode($client_settings->jsonSerialize())); + $encoded_json = $this::json_encode_sdk_format($client_settings->to()); + $this->handle = $this->ffi->init($encoded_json); return $this->handle; } - public function run_command(Command $command): \stdClass + /** + * @throws JsonException + * @throws Exception + */ + public function run_command(Command $command): stdClass { - $encoded_json = json_encode($command->jsonSerialize()); + $encoded_json = $this::json_encode_sdk_format($command->to()); try { $result = $this->ffi->run_command($encoded_json, $this->handle); return json_decode(FFI::string($result)); - } catch (\FFI\Exception $e) { - throw new \RuntimeException('Error occurred during FFI operation: ' . $e->getMessage()); + } catch (FFI\Exception $e) { + throw new RuntimeException('Error occurred during FFI operation: ' . $e->getMessage()); } } @@ -76,4 +86,27 @@ public function free_mem(): void { $this->ffi->free_mem($this->handle); } + + /** + * @throws JsonException + */ + private static function json_encode_sdk_format($object): string + { + $withoutNull = function ($a) use (&$withoutNull) { + if (is_object($a)) { + $a = array_filter((array)$a); + foreach ($a as $k => $v) { + $a[$k] = $withoutNull($v); + } + + return (object)$a; + } + + return $a; + }; + + $object_no_nulls = $withoutNull($object); + + return json_encode($object_no_nulls, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES); + } } diff --git a/languages/php/src/CommandRunner.php b/languages/php/src/CommandRunner.php index 9eec68b2d..532b9625e 100644 --- a/languages/php/src/CommandRunner.php +++ b/languages/php/src/CommandRunner.php @@ -2,36 +2,32 @@ namespace Bitwarden\Sdk; - use Bitwarden\Sdk\Schemas\Command; -use FFI; +use Exception; +use stdClass; class CommandRunner { - private FFI\CData $handle; - private BitwardenLib $bitwardenLib; - public function __construct(BitwardenLib $bitwardenLib, $handle) + public function __construct(BitwardenLib $bitwardenLib) { $this->bitwardenLib = $bitwardenLib; - $this->handle = $handle; } /** - * @throws \Exception + * @throws Exception */ - public function run(Command $command): \stdClass + public function run(Command $command): stdClass { $result = $this->bitwardenLib->run_command($command); - if ($result->success == true) { + if ($result->success) { return $result->data; } - if (isset($result->errorMessage)) - { - throw new \Exception($result->errorMessage); + if (isset($result->errorMessage)) { + throw new Exception($result->errorMessage); } - throw new \Exception("Unknown error occurred"); + throw new Exception("Unknown error occurred"); } } diff --git a/languages/php/src/ProjectsClient.php b/languages/php/src/ProjectsClient.php index 6b6f9fb6a..cca44f1e6 100644 --- a/languages/php/src/ProjectsClient.php +++ b/languages/php/src/ProjectsClient.php @@ -9,6 +9,8 @@ use Bitwarden\Sdk\Schemas\ProjectsCommand; use Bitwarden\Sdk\Schemas\ProjectsDeleteRequest; use Bitwarden\Sdk\Schemas\ProjectsListRequest; +use Exception; +use stdClass; class ProjectsClient { @@ -19,63 +21,74 @@ public function __construct(CommandRunner $commandRunner) $this->commandRunner = $commandRunner; } - public function get(string $project_id): \stdClass + /** + * @throws Exception + */ + public function get(string $project_id): stdClass { - $project_get_request = new ProjectGetRequest(); - $project_get_request->id = $project_id; + $project_get_request = new ProjectGetRequest($project_id); $project_get_request->validate(); - $project_command = new ProjectsCommand(); - $project_command->get = $project_get_request->jsonSerialize(); + $project_command = new ProjectsCommand(get: $project_get_request, create: null, list: null, update: null, + delete: null); return $this->run_project_command($project_command); } - public function list(string $organization_id): \stdClass + /** + * @throws Exception + */ + public function list(string $organization_id): stdClass { - $project_list_request = new ProjectsListRequest(); - $project_list_request->organizationId = $organization_id; + $project_list_request = new ProjectsListRequest($organization_id); $project_list_request->validate(); - $project_command = new ProjectsCommand(); - $project_command->list = $project_list_request->jsonSerialize(); + $project_command = new ProjectsCommand(get: null, create: null, list: $project_list_request, update: null, + delete: null); return $this->run_project_command($project_command); } - public function create(string $project_name, string $organization_id): \stdClass + /** + * @throws Exception + */ + public function create(string $organization_id, string $project_name): stdClass { - $project_create_request = new ProjectCreateRequest(); - $project_create_request->name = $project_name; - $project_create_request->organizationId = $organization_id; + $project_create_request = new ProjectCreateRequest(name: $project_name, organizationId: $organization_id); $project_create_request->validate(); - $project_command = new ProjectsCommand(); - $project_command->create = $project_create_request->jsonSerialize(); + $project_command = new ProjectsCommand(get: null, create: $project_create_request, list: null, update: null, + delete: null); return $this->run_project_command($project_command); } - public function put(string $project_id, string $project_name, string $organization_id): \stdClass + /** + * @throws Exception + */ + public function update(string $organization_id, string $project_id, string $project_name): stdClass { - $project_put_request = new ProjectPutRequest(); - $project_put_request->organizationId = $organization_id; - $project_put_request->name = $project_name; - $project_put_request->id = $project_id; + $project_put_request = new ProjectPutRequest(id: $project_id, name: $project_name, + organizationId: $organization_id); $project_put_request->validate(); - $project_command = new ProjectsCommand(); - $project_command->update = $project_put_request->jsonSerialize(); + $project_command = new ProjectsCommand(get: null, create: null, list: null, update: $project_put_request, + delete: null); return $this->run_project_command($project_command); } - public function delete(array $ids): \stdClass + /** + * @throws Exception + */ + public function delete(array $ids): stdClass { - $projects_delete_request = new ProjectsDeleteRequest(); - $projects_delete_request->ids = $ids; + $projects_delete_request = new ProjectsDeleteRequest($ids); $projects_delete_request->validate(); - $project_command = new ProjectsCommand(); - $project_command->delete = $projects_delete_request->jsonSerialize(); + $project_command = new ProjectsCommand(get: null, create: null, list: null, update: null, + delete: $projects_delete_request); return $this->run_project_command($project_command); } - public function run_project_command($projectCommand): \stdClass + /** + * @throws Exception + */ + public function run_project_command($projectCommand): stdClass { - $command = new Command(); - $command->projects = $projectCommand; + $command = new Command(passwordLogin: null, apiKeyLogin: null, loginAccessToken: null, getUserApiKey: null, + fingerprint: null, sync: null, secrets: null, projects: $projectCommand, generators: null); return $this->commandRunner->run($command); } } diff --git a/languages/php/src/SecretsClient.php b/languages/php/src/SecretsClient.php index d5c0b0cef..85bc334d5 100644 --- a/languages/php/src/SecretsClient.php +++ b/languages/php/src/SecretsClient.php @@ -10,6 +10,9 @@ use Bitwarden\Sdk\Schemas\SecretsCommand; use Bitwarden\Sdk\Schemas\SecretsDeleteRequest; use Bitwarden\Sdk\Schemas\SecretsGetRequest; +use Bitwarden\Sdk\Schemas\SecretsSyncRequest; +use Exception; +use stdClass; class SecretsClient { @@ -20,79 +23,103 @@ public function __construct(CommandRunner $commandRunner) $this->commandRunner = $commandRunner; } - public function get(string $secret_id): \stdClass + /** + * @throws Exception + */ + public function get(string $secret_id): stdClass { - $secret_get_request = new SecretGetRequest(); - $secret_get_request->id = $secret_id; + $secret_get_request = new SecretGetRequest($secret_id); $secret_get_request->validate(); - $secret_command = new SecretsCommand(); - $secret_command->get = $secret_get_request->jsonSerialize(); - return $this->run_secret_command($secret_command); + $secrets_command = new SecretsCommand(get: $secret_get_request, getByIds: null, create: null, list: null, + update: null, delete: null, sync: null); + return $this->run_secret_command($secrets_command); } - public function get_by_ids(array $secret_ids): \stdClass + /** + * @throws Exception + */ + public function get_by_ids(array $secret_ids): stdClass { - $project_get_by_ids_request = new SecretsGetRequest(); - $project_get_by_ids_request->ids = $secret_ids; + $project_get_by_ids_request = new SecretsGetRequest($secret_ids); $project_get_by_ids_request->validate(); - $secrets_command = new SecretsCommand(); - $secrets_command->get_by_ids = $project_get_by_ids_request->jsonSerialize(); + $secrets_command = new SecretsCommand(get: null, getByIds: $project_get_by_ids_request, create: null, list: null, + update: null, delete: null, sync: null); return $this->run_secret_command($secrets_command); } - public function list(string $organization_id): \stdClass + /** + * @throws Exception + */ + public function list(string $organization_id): stdClass { - $secrets_list_request = new SecretIdentifiersRequest(); - $secrets_list_request->organizationId = $organization_id; + $secrets_list_request = new SecretIdentifiersRequest($organization_id); $secrets_list_request->validate(); - $secrets_command = new SecretsCommand(); - $secrets_command->list = $secrets_list_request->jsonSerialize(); + $secrets_command = new SecretsCommand(get: null, getByIds: null, create: null, list: $secrets_list_request, + update: null, delete: null, sync: null); return $this->run_secret_command($secrets_command); } - public function create(string $key, string $note, string $organization_id, array $project_ids, string $value): \stdClass + /** + * @throws Exception + */ + public function create(string $organization_id, string $key, string $value, string $note, array $project_ids): stdClass { - $secrets_create_request = new SecretCreateRequest(); - $secrets_create_request->organizationId = $organization_id; - $secrets_create_request->projectIds = $project_ids; - $secrets_create_request->key = $key; - $secrets_create_request->note = $note; - $secrets_create_request->value = $value; + $secrets_create_request = new SecretCreateRequest(key: $key, note: $note, organizationId: $organization_id, + projectIds: $project_ids, value: $value); $secrets_create_request->validate(); - $secrets_command = new SecretsCommand(); - $secrets_command->create = $secrets_create_request->jsonSerialize(); + $secrets_command = new SecretsCommand(get: null, getByIds: null, create: $secrets_create_request, list: null, + update: null, delete: null, sync: null); return $this->run_secret_command($secrets_command); } - public function update(string $id, string $key, string $note, string $organization_id, array $project_ids, string $value): \stdClass + /** + * @throws Exception + */ + public function update(string $organization_id, string $id, string $key, string $value, string $note, array $project_ids): stdClass { - $secrets_put_request = new SecretPutRequest(); - $secrets_put_request->id = $id; - $secrets_put_request->organizationId = $organization_id; - $secrets_put_request->projectIds = $project_ids; - $secrets_put_request->key = $key; - $secrets_put_request->note = $note; - $secrets_put_request->value = $value; + $secrets_put_request = new SecretPutRequest(id: $id, key: $key, note: $note, organizationId: $organization_id, + projectIds: $project_ids, value: $value); $secrets_put_request->validate(); - $secrets_command = new SecretsCommand(); - $secrets_command->update = $secrets_put_request->jsonSerialize(); + $secrets_command = new SecretsCommand(get: null, getByIds: null, create: null, list: null, + update: $secrets_put_request, delete: null, sync: null); return $this->run_secret_command($secrets_command); } - public function delete(array $secrets_ids): \stdClass + /** + * @throws Exception + */ + public function delete(array $secrets_ids): stdClass { - $secrets_delete_request = new SecretsDeleteRequest(); - $secrets_delete_request->ids = $secrets_ids; + $secrets_delete_request = new SecretsDeleteRequest($secrets_ids); $secrets_delete_request->validate(); - $secrets_command = new SecretsCommand(); - $secrets_command->delete = $secrets_delete_request->jsonSerialize(); + $secrets_command = new SecretsCommand(get: null, getByIds: null, create: null, list: null, + update: null, delete: $secrets_delete_request, sync: null); + return $this->run_secret_command($secrets_command); + } + + /** + * @throws Exception + */ + public function sync(string $organization_id, ?string $last_synced_date): stdClass + { + if (empty($last_synced_date)) { + $last_synced_date = "1970-01-01T00:00:00.000Z"; + } + + $secrets_sync_request = new SecretsSyncRequest(lastSyncedDate: $last_synced_date, organizationId: $organization_id); + $secrets_sync_request->validate(); + $secrets_command = new SecretsCommand(get: null, getByIds: null, create: null, list: null, + update: null, delete: null, sync: $secrets_sync_request); return $this->run_secret_command($secrets_command); } - public function run_secret_command($secretsCommand): \stdClass + /** + * @throws Exception + */ + public function run_secret_command($secretsCommand): stdClass { - $command = new Command(); - $command->secrets = $secretsCommand; + $command = new Command(passwordLogin: null, apiKeyLogin: null, loginAccessToken: null, getUserApiKey: null, + fingerprint: null, sync: null, secrets: $secretsCommand, projects: null, generators: null); return $this->commandRunner->run($command); } } diff --git a/languages/php/src/schemas/AccessTokenLoginRequest.php b/languages/php/src/schemas/AccessTokenLoginRequest.php deleted file mode 100644 index a08805f92..000000000 --- a/languages/php/src/schemas/AccessTokenLoginRequest.php +++ /dev/null @@ -1,39 +0,0 @@ -accessToken = Schema::string(); - $properties->accessToken->description = "Bitwarden service API access token"; - $ownerSchema->type = Schema::OBJECT; - $ownerSchema->additionalProperties = false; - $ownerSchema->description = "Login to Bitwarden with access token"; - $ownerSchema->required = array( - self::names()->accessToken, - ); - $ownerSchema->setFromRef('#/definitions/AccessTokenLoginRequest'); - } -} diff --git a/languages/php/src/schemas/BitwardenClassStructure.php b/languages/php/src/schemas/BitwardenClassStructure.php deleted file mode 100644 index fd50354d4..000000000 --- a/languages/php/src/schemas/BitwardenClassStructure.php +++ /dev/null @@ -1,11 +0,0 @@ -properties = $properties; - $schema->objectItemClass = $className; - $schemaWrapper = new Wrapper($schema); - static::setUpProperties($properties, $schema); - if (null === $schema->getFromRefs()) { - $schema->setFromRef('#/definitions/' . $className); - } - if ($properties->isEmpty()) { - $schema->properties = null; - } - $properties->lock(); - } - - return $schemaWrapper; - } - - /** - * @return Properties|static|null - */ - public static function properties() - { - return static::schema()->getProperties(); - } - - /** - * @param mixed $data - * @param Context $options - * @return static|mixed - * @throws \Swaggest\JsonSchema\Exception - * @throws \Swaggest\JsonSchema\InvalidValue - */ - public static function import($data, Context $options = null) - { - return static::schema()->in($data, $options); - } - - /** - * @param mixed $data - * @param Context $options - * @return mixed - * @throws \Swaggest\JsonSchema\InvalidValue - * @throws \Exception - */ - public static function export($data, Context $options = null) - { - return static::schema()->out($data, $options); - } - - /** - * @param ObjectItemContract $objectItem - * @return static - */ - public static function pick(ObjectItemContract $objectItem) - { - $className = get_called_class(); - return $objectItem->getNestedObject($className); - } - - /** - * @return static - */ - public static function create() - { - return new static; - } - - protected $__validateOnSet = true; // todo skip validation during import - - /** - * @return \stdClass - */ - #[\ReturnTypeWillChange] - public function jsonSerialize() - { - $result = new \stdClass(); - $schema = static::schema(); - $properties = $schema->getProperties(); - $processed = array(); - if (null !== $properties) { - foreach ($properties->getDataKeyMap() as $propertyName => $dataName) { - $value = $this->$propertyName ?? null; - - // Value is exported if exists. - if (null !== $value || array_key_exists($propertyName, $this->__arrayOfData)) { - $result->$dataName = $value; - $processed[$propertyName] = true; - continue; - } - - // Non-existent value is only exported if belongs to nullable property (having 'null' in type array). - $property = $schema->getProperty($propertyName); - if ($property instanceof Schema) { - $types = $property->type; - if ($types === Schema::NULL || (is_array($types) && in_array(Schema::NULL, $types))) { - $result->$dataName = $value; - } - } - } - } - foreach ($schema->getNestedPropertyNames() as $name) { - /** @var ObjectItem $nested */ - $nested = $this->$name; - if (null !== $nested) { - foreach ((array)$nested->jsonSerialize() as $key => $value) { - $result->$key = $value; - } - } - } - - if (!empty($this->__arrayOfData)) { - foreach ($this->__arrayOfData as $name => $value) { - if (!isset($processed[$name])) { - $result->$name = $this->{$name}; - } - } - } - - return $result; - } - - /** - * @return static|NameMirror - */ - public static function names(Properties $properties = null, $mapping = Schema::DEFAULT_MAPPING) - { - if ($properties !== null) { - return new NameMirror($properties->getDataKeyMap($mapping)); - } - - static $nameflector = null; - if (null === $nameflector) { - $nameflector = new NameMirror(); - } - return $nameflector; - } - - public function __set($name, $column) // todo nested schemas - { - if ($this->__validateOnSet) { - if ($property = static::schema()->getProperty($name)) { - $property->out($column); - } - } - $this->__arrayOfData[$name] = $column; - return $this; - } - - public static function className() - { - return get_called_class(); - } - - /** - * @throws \Exception - * @throws \Swaggest\JsonSchema\InvalidValue - */ - public function validate() - { - static::schema()->out($this); - } -} - diff --git a/languages/php/src/schemas/ClientSettings.php b/languages/php/src/schemas/ClientSettings.php deleted file mode 100644 index c27cc3322..000000000 --- a/languages/php/src/schemas/ClientSettings.php +++ /dev/null @@ -1,133 +0,0 @@ -identityUrl = Schema::string(); - $properties->identityUrl->description = "The identity url of the targeted Bitwarden instance. Defaults to `https://identity.bitwarden.com`"; - $properties->identityUrl->default = "https://identity.bitwarden.com"; - $properties->apiUrl = Schema::string(); - $properties->apiUrl->description = "The api url of the targeted Bitwarden instance. Defaults to `https://api.bitwarden.com`"; - $properties->apiUrl->default = "https://api.bitwarden.com"; - $properties->userAgent = Schema::string(); - $properties->userAgent->description = "The user_agent to sent to Bitwarden. Defaults to `Bitwarden Rust-SDK`"; - $properties->userAgent->default = "Bitwarden Rust-SDK"; - $properties->deviceType = new Schema(); - $propertiesDeviceTypeAllOf0 = Schema::string(); - $propertiesDeviceTypeAllOf0->enum = array( - self::ANDROID, - self::I_OS, - self::CHROME_EXTENSION, - self::FIREFOX_EXTENSION, - self::OPERA_EXTENSION, - self::EDGE_EXTENSION, - self::WINDOWS_DESKTOP, - self::MAC_OS_DESKTOP, - self::LINUX_DESKTOP, - self::CHROME_BROWSER, - self::FIREFOX_BROWSER, - self::OPERA_BROWSER, - self::EDGE_BROWSER, - self::IE_BROWSER, - self::UNKNOWN_BROWSER, - self::ANDROID_AMAZON, - self::UWP, - self::SAFARI_BROWSER, - self::VIVALDI_BROWSER, - self::VIVALDI_EXTENSION, - self::SAFARI_EXTENSION, - self::SDK, - ); - $propertiesDeviceTypeAllOf0->setFromRef('#/definitions/DeviceType'); - $properties->deviceType->allOf[0] = $propertiesDeviceTypeAllOf0; - $properties->deviceType->description = "Device type to send to Bitwarden. Defaults to SDK"; - $properties->deviceType->default = "SDK"; - $ownerSchema->type = Schema::OBJECT; - $ownerSchema->additionalProperties = false; - $ownerSchema->schema = "http://json-schema.org/draft-07/schema#"; - $ownerSchema->title = "ClientSettings"; - $ownerSchema->description = "Basic client behavior settings. These settings specify the various targets and behavior of the Bitwarden Client. They are optional and uneditable once the client is initialized.\n\nDefaults to\n\n``` # use bitwarden::client::client_settings::{ClientSettings, DeviceType}; # use assert_matches::assert_matches; let settings = ClientSettings { identity_url: \"https://identity.bitwarden.com\".to_string(), api_url: \"https://api.bitwarden.com\".to_string(), user_agent: \"Bitwarden Rust-SDK\".to_string(), device_type: DeviceType::SDK, }; let default = ClientSettings::default(); assert_matches!(settings, default); ```\n\nTargets `localhost:8080` for debug builds."; - } -} diff --git a/languages/php/src/schemas/Command.php b/languages/php/src/schemas/Command.php deleted file mode 100644 index cbd649c2f..000000000 --- a/languages/php/src/schemas/Command.php +++ /dev/null @@ -1,44 +0,0 @@ -projects = ProjectsCommand::schema(); - $properties->secrets = SecretsCommand::schema(); - $properties->accessTokenLogin = AccessTokenLoginRequest::schema(); - - $ownerSchema->type = Schema::OBJECT; - $ownerSchema->additionalProperties = false; - - $ownerSchema->oneOf = array( - self::names()->projects, - self::names()->secrets, - self::names()->accessTokenLogin, - ); - } -} diff --git a/languages/php/src/schemas/ProjectCreateRequest.php b/languages/php/src/schemas/ProjectCreateRequest.php deleted file mode 100644 index 6a4e0f082..000000000 --- a/languages/php/src/schemas/ProjectCreateRequest.php +++ /dev/null @@ -1,43 +0,0 @@ -organizationId = Schema::string(); - $properties->organizationId->description = "Organization where the project will be created"; - $properties->organizationId->format = "uuid"; - $properties->name = Schema::string(); - $ownerSchema->type = Schema::OBJECT; - $ownerSchema->additionalProperties = false; - $ownerSchema->required = array( - self::names()->name, - self::names()->organizationId, - ); - $ownerSchema->setFromRef('#/definitions/ProjectCreateRequest'); - } -} diff --git a/languages/php/src/schemas/ProjectGetRequest.php b/languages/php/src/schemas/ProjectGetRequest.php deleted file mode 100644 index 972bf18ec..000000000 --- a/languages/php/src/schemas/ProjectGetRequest.php +++ /dev/null @@ -1,37 +0,0 @@ -id = Schema::string(); - $properties->id->description = "ID of the project to retrieve"; - $properties->id->format = "uuid"; - $ownerSchema->type = Schema::OBJECT; - $ownerSchema->additionalProperties = false; - $ownerSchema->required = array( - self::names()->id, - ); - $ownerSchema->setFromRef('#/definitions/ProjectGetRequest'); - } -} diff --git a/languages/php/src/schemas/ProjectPutRequest.php b/languages/php/src/schemas/ProjectPutRequest.php deleted file mode 100644 index 96b9705e7..000000000 --- a/languages/php/src/schemas/ProjectPutRequest.php +++ /dev/null @@ -1,50 +0,0 @@ -id = Schema::string(); - $properties->id->description = "ID of the project to modify"; - $properties->id->format = "uuid"; - $properties->organizationId = Schema::string(); - $properties->organizationId->description = "Organization ID of the project to modify"; - $properties->organizationId->format = "uuid"; - $properties->name = Schema::string(); - $ownerSchema->type = Schema::OBJECT; - $ownerSchema->additionalProperties = false; - $ownerSchema->required = array( - self::names()->id, - self::names()->name, - self::names()->organizationId, - ); - $ownerSchema->setFromRef('#/definitions/ProjectPutRequest'); - } -} diff --git a/languages/php/src/schemas/ProjectsCommand.php b/languages/php/src/schemas/ProjectsCommand.php deleted file mode 100644 index 22645db3c..000000000 --- a/languages/php/src/schemas/ProjectsCommand.php +++ /dev/null @@ -1,55 +0,0 @@ - Requires Authentication > Requires using an Access Token for login or calling Sync at least once Deletes all the projects whose IDs match the provided ones - * - * Returns: [ProjectsDeleteResponse](bitwarden::secrets_manager::projects::ProjectsDeleteResponse) - */ -class ProjectsCommand extends BitwardenClassStructure -{ - public ?\stdClass $delete; - - public ?\stdClass $get; - - public ?\stdClass $list; - - public ?\stdClass $create; - - public ?\stdClass $update; - - - /** - * @param Properties|static $properties - * @param Schema $ownerSchema - */ - public static function setUpProperties($properties, Schema $ownerSchema) - { - $properties->delete = ProjectsDeleteRequest::schema() ? ProjectsDeleteRequest::schema() : null; - $properties->get = ProjectGetRequest::schema() ? ProjectGetRequest::schema() : null; - $properties->list = ProjectsListRequest::schema() ? ProjectsListRequest::schema() : null; - $properties->update = ProjectPutRequest::schema() ? ProjectPutRequest::schema() : null; - $properties->create = ProjectCreateRequest::schema() ? ProjectCreateRequest::schema() : null; - $ownerSchema->type = Schema::OBJECT; - $ownerSchema->additionalProperties = false; - $ownerSchema->description = "> Requires Authentication > Requires using an Access Token for login or calling Sync at least once Deletes all the projects whose IDs match the provided ones\n\nReturns: [ProjectsDeleteResponse](bitwarden::secrets_manager::projects::ProjectsDeleteResponse)"; - - $ownerSchema->oneOf = array( - self::names()->create, - self::names()->delete, - self::names()->get, - self::names()->list, - self::names()->update, - ); - } -} diff --git a/languages/php/src/schemas/ProjectsDeleteRequest.php b/languages/php/src/schemas/ProjectsDeleteRequest.php deleted file mode 100644 index 87a7cfad7..000000000 --- a/languages/php/src/schemas/ProjectsDeleteRequest.php +++ /dev/null @@ -1,39 +0,0 @@ -ids = Schema::arr(); - $properties->ids->items = Schema::string(); - $properties->ids->items->format = "uuid"; - $properties->ids->description = "IDs of the projects to delete"; - $ownerSchema->type = Schema::OBJECT; - $ownerSchema->additionalProperties = false; - $ownerSchema->required = array( - self::names()->ids, - ); - $ownerSchema->setFromRef('#/definitions/ProjectsDeleteRequest'); - } -} diff --git a/languages/php/src/schemas/ProjectsListRequest.php b/languages/php/src/schemas/ProjectsListRequest.php deleted file mode 100644 index cc1a9474f..000000000 --- a/languages/php/src/schemas/ProjectsListRequest.php +++ /dev/null @@ -1,38 +0,0 @@ -organizationId = Schema::string(); - $properties->organizationId->description = "Organization to retrieve all the projects from"; - $properties->organizationId->format = "uuid"; - $ownerSchema->type = Schema::OBJECT; - $ownerSchema->additionalProperties = false; - $ownerSchema->required = array( - self::names()->organizationId, - ); - $ownerSchema->setFromRef('#/definitions/ProjectsListRequest'); - } -} diff --git a/languages/php/src/schemas/SecretCreateRequest.php b/languages/php/src/schemas/SecretCreateRequest.php deleted file mode 100644 index d34b36e98..000000000 --- a/languages/php/src/schemas/SecretCreateRequest.php +++ /dev/null @@ -1,58 +0,0 @@ -organizationId = Schema::string(); - $properties->organizationId->description = "Organization where the secret will be created"; - $properties->organizationId->format = "uuid"; - $properties->key = Schema::string(); - $properties->value = Schema::string(); - $properties->note = Schema::string(); - $properties->projectIds = (new Schema())->setType([Schema::_ARRAY, Schema::NULL]); - $properties->projectIds->items = Schema::string(); - $properties->projectIds->items->format = "uuid"; - $properties->projectIds->description = "IDs of the projects that this secret will belong to"; - $ownerSchema->type = Schema::OBJECT; - $ownerSchema->additionalProperties = false; - $ownerSchema->required = array( - self::names()->key, - self::names()->note, - self::names()->organizationId, - self::names()->value, - ); - $ownerSchema->setFromRef('#/definitions/SecretCreateRequest'); - } -} diff --git a/languages/php/src/schemas/SecretGetRequest.php b/languages/php/src/schemas/SecretGetRequest.php deleted file mode 100644 index f31f7cad3..000000000 --- a/languages/php/src/schemas/SecretGetRequest.php +++ /dev/null @@ -1,38 +0,0 @@ -id = Schema::string(); - $properties->id->description = "ID of the secret to retrieve"; - $properties->id->format = "uuid"; - $ownerSchema->type = Schema::OBJECT; - $ownerSchema->additionalProperties = false; - $ownerSchema->required = array( - self::names()->id, - ); - $ownerSchema->setFromRef('#/definitions/SecretGetRequest'); - } -} diff --git a/languages/php/src/schemas/SecretIdentifiersRequest.php b/languages/php/src/schemas/SecretIdentifiersRequest.php deleted file mode 100644 index b4e75b801..000000000 --- a/languages/php/src/schemas/SecretIdentifiersRequest.php +++ /dev/null @@ -1,38 +0,0 @@ -organizationId = Schema::string(); - $properties->organizationId->description = "Organization to retrieve all the secrets from"; - $properties->organizationId->format = "uuid"; - $ownerSchema->type = Schema::OBJECT; - $ownerSchema->additionalProperties = false; - $ownerSchema->required = array( - self::names()->organizationId, - ); - $ownerSchema->setFromRef('#/definitions/SecretIdentifiersRequest'); - } -} diff --git a/languages/php/src/schemas/SecretPutRequest.php b/languages/php/src/schemas/SecretPutRequest.php deleted file mode 100644 index d890a909d..000000000 --- a/languages/php/src/schemas/SecretPutRequest.php +++ /dev/null @@ -1,64 +0,0 @@ -id = Schema::string(); - $properties->id->description = "ID of the secret to modify"; - $properties->id->format = "uuid"; - $properties->organizationId = Schema::string(); - $properties->organizationId->description = "Organization ID of the secret to modify"; - $properties->organizationId->format = "uuid"; - $properties->key = Schema::string(); - $properties->value = Schema::string(); - $properties->note = Schema::string(); - $properties->projectIds = (new Schema())->setType([Schema::_ARRAY, Schema::NULL]); - $properties->projectIds->items = Schema::string(); - $properties->projectIds->items->format = "uuid"; - $ownerSchema->type = Schema::OBJECT; - $ownerSchema->additionalProperties = false; - $ownerSchema->required = array( - self::names()->id, - self::names()->key, - self::names()->note, - self::names()->organizationId, - self::names()->value, - ); - $ownerSchema->setFromRef('#/definitions/SecretPutRequest'); - } -} diff --git a/languages/php/src/schemas/SecretVerificationRequest.php b/languages/php/src/schemas/SecretVerificationRequest.php deleted file mode 100644 index 95cfd1e15..000000000 --- a/languages/php/src/schemas/SecretVerificationRequest.php +++ /dev/null @@ -1,35 +0,0 @@ -masterPassword = (new Schema())->setType([Schema::STRING, Schema::NULL]); - $properties->masterPassword->description = "The user's master password to use for user verification. If supplied, this will be used for verification purposes."; - $properties->otp = (new Schema())->setType([Schema::STRING, Schema::NULL]); - $properties->otp->description = "Alternate user verification method through OTP. This is provided for users who have no master password due to use of Customer Managed Encryption. Must be present and valid if master_password is absent."; - $ownerSchema->type = Schema::OBJECT; - $ownerSchema->additionalProperties = false; - $ownerSchema->setFromRef('#/definitions/SecretVerificationRequest'); - } -} diff --git a/languages/php/src/schemas/SecretsCommand.php b/languages/php/src/schemas/SecretsCommand.php deleted file mode 100644 index 1ed8c97c5..000000000 --- a/languages/php/src/schemas/SecretsCommand.php +++ /dev/null @@ -1,56 +0,0 @@ - Requires Authentication > Requires using an Access Token for login or calling Sync at least once Deletes all the secrets whose IDs match the provided ones - * - * Returns: [SecretsDeleteResponse](bitwarden::secrets_manager::secrets::SecretsDeleteResponse) - */ -class SecretsCommand extends BitwardenClassStructure -{ - public ?\stdClass $delete; - - public ?\stdClass $get; - - public ?\stdClass $getByIds; - - public ?\stdClass $list; - - public ?\stdClass $create; - - public ?\stdClass $put; - - /** - * @param Properties|static $properties - * @param Schema $ownerSchema - */ - public static function setUpProperties($properties, Schema $ownerSchema) - { - $properties->delete = SecretsDeleteRequest::schema() ? SecretsDeleteRequest::schema() : null; - $properties->getByIds = SecretsGetRequest::schema() ? SecretGetRequest::schema() : null; - $properties->create = SecretCreateRequest::schema() ? SecretCreateRequest::schema() : null; - $properties->put = SecretPutRequest::schema() ? SecretPutRequest::schema() : null; - $properties->list = SecretIdentifiersRequest::schema() ? SecretIdentifiersRequest::schema() : null; - $properties->get = SecretsGetRequest::schema() ? SecretGetRequest::schema() : null; - $ownerSchema->type = Schema::OBJECT; - $ownerSchema->additionalProperties = false; - $ownerSchema->description = "> Requires Authentication > Requires using an Access Token for login or calling Sync at least once Deletes all the secrets whose IDs match the provided ones\n\nReturns: [SecretsDeleteResponse](bitwarden::secrets_manager::secrets::SecretsDeleteResponse)"; - $ownerSchema->oneOf = array( - self::names()->create, - self::names()->put, - self::names()->list, - self::names()->getByIds, - self::names()->delete, - ); - } -} diff --git a/languages/php/src/schemas/SecretsDeleteRequest.php b/languages/php/src/schemas/SecretsDeleteRequest.php deleted file mode 100644 index 35138fcb1..000000000 --- a/languages/php/src/schemas/SecretsDeleteRequest.php +++ /dev/null @@ -1,39 +0,0 @@ -ids = Schema::arr(); - $properties->ids->items = Schema::string(); - $properties->ids->items->format = "uuid"; - $properties->ids->description = "IDs of the secrets to delete"; - $ownerSchema->type = Schema::OBJECT; - $ownerSchema->additionalProperties = false; - $ownerSchema->required = array( - self::names()->ids, - ); - $ownerSchema->setFromRef('#/definitions/SecretsDeleteRequest'); - } -} diff --git a/languages/php/src/schemas/SecretsGetRequest.php b/languages/php/src/schemas/SecretsGetRequest.php deleted file mode 100644 index 4758dabf4..000000000 --- a/languages/php/src/schemas/SecretsGetRequest.php +++ /dev/null @@ -1,39 +0,0 @@ -ids = Schema::arr(); - $properties->ids->items = Schema::string(); - $properties->ids->items->format = "uuid"; - $properties->ids->description = "IDs of the secrets to retrieve"; - $ownerSchema->type = Schema::OBJECT; - $ownerSchema->additionalProperties = false; - $ownerSchema->required = array( - self::names()->ids, - ); - $ownerSchema->setFromRef('#/definitions/SecretsGetRequest'); - } -} diff --git a/languages/python/bitwarden_sdk/__init__.py b/languages/python/bitwarden_sdk/__init__.py index 067ed3aa5..f1712c77b 100644 --- a/languages/python/bitwarden_sdk/__init__.py +++ b/languages/python/bitwarden_sdk/__init__.py @@ -1,6 +1,6 @@ """The official Bitwarden client library for Python.""" -__version__ = "0.1.1" +__version__ = "1.0.0" from .bitwarden_client import * from .schemas import * diff --git a/languages/python/pyproject.toml b/languages/python/pyproject.toml index 0ce9a96b2..a4ab1f693 100644 --- a/languages/python/pyproject.toml +++ b/languages/python/pyproject.toml @@ -17,7 +17,7 @@ description = "A Bitwarden Client for python" name = "bitwarden_sdk" readme = "README.md" requires-python = ">=3.0" -version = "0.1.1" +version = "1.0.0" [tool.maturin] bindings = "pyo3" diff --git a/languages/ruby/README.md b/languages/ruby/README.md index a02b1b53e..790008b38 100644 --- a/languages/ruby/README.md +++ b/languages/ruby/README.md @@ -9,7 +9,7 @@ Requirements: Ruby >= 3.0 Install gem: `gem install bitwarden-sdk-secrets` -Import it: require 'bitwarden-sdk-secrets' +Import it: `require 'bitwarden-sdk-secrets'` ## Usage @@ -28,7 +28,7 @@ bitwarden_settings = BitwardenSDK::BitwardenSettings.new( # By passing these setting you can initialize BitwardenClient bw_client = BitwardenSDK::BitwardenClient.new(bitwarden_settings) -response = bw_client.access_token_login(token) +response = bw_client.auth.login_access_token(token, state_file) puts response ``` @@ -38,25 +38,25 @@ After successful authorization you can interact with client to manage your proje # CREATE project project_name = 'Test project 1' -response = bw_client.project_client.create_project(project_name, organization_id) +response = bw_client.projects.create(organization_id, project_name) puts response project_id = response['id'] # GET project -response = bw_client.project_client.get(project_id) +response = bw_client.projects.get(project_id) puts response # LIST projects -response = bw_client.project_client.list_projects(organization_id) +response = bw_client.projects.list(organization_id) puts response # UPDATE projects name = 'Updated test project 1' -response = bw_client.project_client.update_project(project_id, name, organization_id) +response = bw_client.projects.update(organization_id, project_id, name) puts response # DELETE project -response = bw_client.project_client.delete_projects([project_id]) +response = bw_client.projects.delete_projects([project_id]) puts response ``` @@ -67,30 +67,38 @@ Similarly, you interact with secrets: key = 'AWS-SES' note = 'Private account' value = '8t27.dfj;' -response = bw_client.secrets_client.create(key, note, organization_id, [project_id], value) +response = bw_client.secrets.create(organization_id, key, value, note, [project_id]) puts response secret_id = response['id'] # GET secret -response = bw_client.secrets_client.get(secret_id) +response = bw_client.secrets.get(secret_id) puts response # GET secret by ids -response = bw_client.secrets_client.get_by_ids([secret_id]) +response = bw_client.secrets.get_by_ids([secret_id]) puts response # LIST secrets -response = bw_client.secrets_client.list(organization_id) +response = bw_client.secrets.list(organization_id) +puts response + +# SYNC secrets +response = bw_client.secrets.sync(organization_id, nil) +last_synced_date = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%6NZ') +puts response + +response = bw_client.secrets.sync(organization_id, last_synced_date) puts response # UPDATE secret note = 'updated password' value = '7I.ert10AjK' -response = bw_client.secrets_client.update(secret_id, key, note,organization_id, [project_id], value) +response = bw_client.secrets.update(organization_id, secret_id, key, value, note, [project_id]) puts response # DELETE secret -response = bw_client.secrets_client.delete_secret([secret_id]) +response = bw_client.secrets.delete([secret_id]) puts response ``` diff --git a/languages/ruby/bitwarden_sdk_secrets/lib/auth.rb b/languages/ruby/bitwarden_sdk_secrets/lib/auth.rb new file mode 100644 index 000000000..481f30257 --- /dev/null +++ b/languages/ruby/bitwarden_sdk_secrets/lib/auth.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true +require_relative 'bitwarden_error' + +module BitwardenSDKSecrets + class AuthClient + def initialize(command_runner) + @command_runner = command_runner + end + + def login_access_token(access_token, state_file = nil) + access_token_request = AccessTokenLoginRequest.new(access_token: access_token, state_file: state_file) + @command_runner.run(SelectiveCommand.new(login_access_token: access_token_request)) + nil + end + end +end diff --git a/languages/ruby/bitwarden_sdk_secrets/lib/bitwarden-sdk-secrets.rb b/languages/ruby/bitwarden_sdk_secrets/lib/bitwarden-sdk-secrets.rb index 15cd115d1..4cd1c2597 100644 --- a/languages/ruby/bitwarden_sdk_secrets/lib/bitwarden-sdk-secrets.rb +++ b/languages/ruby/bitwarden_sdk_secrets/lib/bitwarden-sdk-secrets.rb @@ -10,6 +10,7 @@ require_relative 'bitwarden_error' require_relative 'projects' require_relative 'secrets' +require_relative 'auth' module BitwardenSDKSecrets class BitwardenSettings @@ -26,7 +27,7 @@ def initialize(api_url, identity_url) end class BitwardenClient - attr_reader :bitwarden, :project_client, :secrets_client + attr_reader :bitwarden, :projects, :secrets, :auth def initialize(bitwarden_settings) client_settings = ClientSettings.new( @@ -39,14 +40,9 @@ def initialize(bitwarden_settings) @bitwarden = BitwardenLib @handle = @bitwarden.init(client_settings.to_dynamic.compact.to_json) @command_runner = CommandRunner.new(@bitwarden, @handle) - @project_client = ProjectsClient.new(@command_runner) - @secrets_client = SecretsClient.new(@command_runner) - end - - def access_token_login(access_token, state_file = nil) - access_token_request = AccessTokenLoginRequest.new(access_token: access_token, state_file: state_file) - @command_runner.run(SelectiveCommand.new(access_token_login: access_token_request)) - nil + @projects = ProjectsClient.new(@command_runner) + @secrets = SecretsClient.new(@command_runner) + @auth = AuthClient.new(@command_runner) end def free_mem diff --git a/languages/ruby/bitwarden_sdk_secrets/lib/extended_schemas/schemas.rb b/languages/ruby/bitwarden_sdk_secrets/lib/extended_schemas/schemas.rb index e2352237f..bcdfa5e5f 100644 --- a/languages/ruby/bitwarden_sdk_secrets/lib/extended_schemas/schemas.rb +++ b/languages/ruby/bitwarden_sdk_secrets/lib/extended_schemas/schemas.rb @@ -3,23 +3,25 @@ module BitwardenSDKSecrets class SelectiveCommand < Command attribute :password_login, PasswordLoginRequest.optional.default(nil) attribute :api_key_login, APIKeyLoginRequest.optional.default(nil) - attribute :access_token_login, AccessTokenLoginRequest.optional.default(nil) + attribute :login_access_token, AccessTokenLoginRequest.optional.default(nil) attribute :get_user_api_key, SecretVerificationRequest.optional.default(nil) attribute :fingerprint, FingerprintRequest.optional.default(nil) attribute :sync, SyncRequest.optional.default(nil) attribute :secrets, SecretsCommand.optional.default(nil) attribute :projects, ProjectsCommand.optional.default(nil) + attribute :generators, GeneratorsCommand.optional.default(nil) def to_dynamic { "passwordLogin" => password_login&.to_dynamic, "apiKeyLogin" => api_key_login&.to_dynamic, - "accessTokenLogin" => access_token_login&.to_dynamic, + "loginAccessToken" => login_access_token&.to_dynamic, "getUserApiKey" => get_user_api_key&.to_dynamic, "fingerprint" => fingerprint&.to_dynamic, "sync" => sync&.to_dynamic, "secrets" => secrets&.to_dynamic, "projects" => projects&.to_dynamic, + "generators" => generators&.to_dynamic, }.compact end end @@ -49,6 +51,7 @@ class SelectiveSecretsCommand < SecretsCommand attribute :list, SecretIdentifiersRequest.optional.default(nil) attribute :update, SecretPutRequest.optional.default(nil) attribute :delete, SecretsDeleteRequest.optional.default(nil) + attribute :sync, SecretsSyncRequest.optional.default(nil) def to_dynamic { @@ -58,7 +61,18 @@ def to_dynamic "list" => list&.to_dynamic, "update" => update&.to_dynamic, "delete" => delete&.to_dynamic, + "sync" => sync&.to_dynamic, }.compact end end + + class SelectiveGeneratorsCommand < GeneratorsCommand + attribute :generate_password, PasswordGeneratorRequest.optional.default(nil) + + def to_dynamic + { + "generate_password" => generate_password&.to_dynamic, + }.compact + end + end end diff --git a/languages/ruby/bitwarden_sdk_secrets/lib/projects.rb b/languages/ruby/bitwarden_sdk_secrets/lib/projects.rb index 957a7d31d..bf4e903ca 100644 --- a/languages/ruby/bitwarden_sdk_secrets/lib/projects.rb +++ b/languages/ruby/bitwarden_sdk_secrets/lib/projects.rb @@ -8,7 +8,7 @@ def initialize(command_runner) @command_runner = command_runner end - def create_project(project_name, organization_id) + def create(organization_id, project_name) project_create_request = ProjectCreateRequest.new( project_create_request_name: project_name, organization_id: organization_id @@ -43,7 +43,7 @@ def get(project_id) error_response(projects_response) end - def list_projects(organization_id) + def list(organization_id) project_list_request = ProjectsListRequest.new(organization_id: organization_id) command = create_command(list: project_list_request) response = parse_response(command) @@ -58,7 +58,7 @@ def list_projects(organization_id) error_response(projects_response) end - def update_project(id, project_put_request_name, organization_id) + def update(organization_id, id, project_put_request_name) project_put_request = ProjectPutRequest.new( id: id, project_put_request_name: project_put_request_name, @@ -79,7 +79,7 @@ def update_project(id, project_put_request_name, organization_id) error_response(projects_response) end - def delete_projects(ids) + def delete(ids) project_delete_request = ProjectsDeleteRequest.new(ids: ids) command = create_command(delete: project_delete_request) response = parse_response(command) diff --git a/languages/ruby/bitwarden_sdk_secrets/lib/secrets.rb b/languages/ruby/bitwarden_sdk_secrets/lib/secrets.rb index 709d8f8b1..5dda98830 100644 --- a/languages/ruby/bitwarden_sdk_secrets/lib/secrets.rb +++ b/languages/ruby/bitwarden_sdk_secrets/lib/secrets.rb @@ -36,7 +36,23 @@ def get_by_ids(ids) error_response(secrets_response) end - def create(key, note, organization_id, project_ids, value) + def sync(organization_id, last_synced_date) + command = create_command( + sync: SecretsSyncRequest.new(organization_id: organization_id, last_synced_date: last_synced_date) + ) + response = run_command(command) + + secrets_response = ResponseForSecretsSyncResponse.from_json!(response).to_dynamic + + if secrets_response.key?('success') && secrets_response['success'] == true && + secrets_response.key?('data') + return secrets_response['data'] + end + + error_response(secrets_response) + end + + def create(organization_id, key, value, note, project_ids) command = create_command( create: SecretCreateRequest.new( key: key, note: note, organization_id: organization_id, project_ids: project_ids, value: value @@ -68,7 +84,7 @@ def list(organization_id) error_response(secrets_response) end - def update(id, key, note, organization_id, project_ids, value) + def update(organization_id, id, key, value, note, project_ids) command = create_command( update: SecretPutRequest.new( id: id, key: key, note: note, organization_id: organization_id, project_ids: project_ids, value: value @@ -86,7 +102,7 @@ def update(id, key, note, organization_id, project_ids, value) error_response(secrets_response) end - def delete_secret(ids) + def delete(ids) command = create_command(delete: SecretsDeleteRequest.new(ids: ids)) response = run_command(command) diff --git a/languages/ruby/bitwarden_sdk_secrets/lib/version.rb b/languages/ruby/bitwarden_sdk_secrets/lib/version.rb index 3103642a1..39b47b47b 100644 --- a/languages/ruby/bitwarden_sdk_secrets/lib/version.rb +++ b/languages/ruby/bitwarden_sdk_secrets/lib/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module BitwardenSDKSecrets - VERSION = '0.2.0' + VERSION = '1.0.0' end diff --git a/languages/ruby/bitwarden_sdk_secrets/sig/auth.rbs b/languages/ruby/bitwarden_sdk_secrets/sig/auth.rbs new file mode 100644 index 000000000..4e75cf4c4 --- /dev/null +++ b/languages/ruby/bitwarden_sdk_secrets/sig/auth.rbs @@ -0,0 +1,9 @@ +module BitwardenSDKSecrets + class AuthClient + @command_runner: untyped + + def initialize: (untyped command_runner) -> void + + def login_access_token: (untyped access_token, ?untyped? state_file) -> nil + end +end diff --git a/languages/ruby/bitwarden_sdk_secrets/sig/bitwarden-sdk-secrets.rbs b/languages/ruby/bitwarden_sdk_secrets/sig/bitwarden-sdk-secrets.rbs new file mode 100644 index 000000000..ffca59e61 --- /dev/null +++ b/languages/ruby/bitwarden_sdk_secrets/sig/bitwarden-sdk-secrets.rbs @@ -0,0 +1,39 @@ +module BitwardenSDKSecrets + class BitwardenSettings + @api_url: untyped + + @identity_url: untyped + + attr_accessor api_url: untyped + + attr_accessor identity_url: untyped + + def initialize: (untyped api_url, untyped identity_url) -> void + end + + class BitwardenClient + @bitwarden: untyped + + @handle: untyped + + @command_runner: untyped + + @projects: untyped + + @secrets: untyped + + @auth: untyped + + attr_reader bitwarden: untyped + + attr_reader projects: untyped + + attr_reader secrets: untyped + + attr_reader auth: untyped + + def initialize: (untyped bitwarden_settings) -> void + + def free_mem: () -> untyped + end +end diff --git a/languages/ruby/bitwarden_sdk_secrets/sig/bitwarden-sdk.rbs b/languages/ruby/bitwarden_sdk_secrets/sig/bitwarden-sdk.rbs deleted file mode 100644 index 3f6a73f6a..000000000 --- a/languages/ruby/bitwarden_sdk_secrets/sig/bitwarden-sdk.rbs +++ /dev/null @@ -1,13 +0,0 @@ -require_relative '../lib/schemas' - -class BitwardenClient - @command_runner: CommandRunner - - attr_reader bitwarden: Module - attr_reader project_client: ProjectsClient - attr_reader secrets_client: SecretsClient - - def initialize: (BitwardenSettings) -> void - def access_token_login: (String) -> JSON - def free_mem: () -> nil -end diff --git a/languages/ruby/bitwarden_sdk_secrets/sig/bitwarden_error.rbs b/languages/ruby/bitwarden_sdk_secrets/sig/bitwarden_error.rbs new file mode 100644 index 000000000..99c60f48d --- /dev/null +++ b/languages/ruby/bitwarden_sdk_secrets/sig/bitwarden_error.rbs @@ -0,0 +1,5 @@ +module BitwardenSDKSecrets + class BitwardenError < StandardError + def initialize: (?::String message) -> void + end +end diff --git a/languages/ruby/bitwarden_sdk_secrets/sig/bitwarden_lib.rbs b/languages/ruby/bitwarden_sdk_secrets/sig/bitwarden_lib.rbs new file mode 100644 index 000000000..6038fbf03 --- /dev/null +++ b/languages/ruby/bitwarden_sdk_secrets/sig/bitwarden_lib.rbs @@ -0,0 +1,7 @@ +module BitwardenSDKSecrets + module BitwardenLib + extend FFI::Library + + def self.mac_with_intel?: () -> untyped + end +end diff --git a/languages/ruby/bitwarden_sdk_secrets/sig/bitwarden_settings.rbs b/languages/ruby/bitwarden_sdk_secrets/sig/bitwarden_settings.rbs deleted file mode 100644 index 154ee16e5..000000000 --- a/languages/ruby/bitwarden_sdk_secrets/sig/bitwarden_settings.rbs +++ /dev/null @@ -1,8 +0,0 @@ -require_relative '../lib/schemas' - -class BitwardenSettings - attr_accessor api_url: String - attr_accessor identity_url: String - - def initialize: (String, String) -> void -end diff --git a/languages/ruby/bitwarden_sdk_secrets/sig/command_runner.rbs b/languages/ruby/bitwarden_sdk_secrets/sig/command_runner.rbs index 7a7a17dd9..483679076 100644 --- a/languages/ruby/bitwarden_sdk_secrets/sig/command_runner.rbs +++ b/languages/ruby/bitwarden_sdk_secrets/sig/command_runner.rbs @@ -1,4 +1,12 @@ -class CommandRunner - @bitwarden_sdk: Module - def run: -> String +module BitwardenSDKSecrets + class CommandRunner + @bitwarden_sdk: untyped + + @handle: untyped + + def initialize: (untyped bitwarden_sdk, untyped handle) -> void + + # @param [Dry-Struct] cmd + def run: (untyped cmd) -> untyped + end end diff --git a/languages/ruby/bitwarden_sdk_secrets/sig/projects.rbs b/languages/ruby/bitwarden_sdk_secrets/sig/projects.rbs new file mode 100644 index 000000000..e68df3d59 --- /dev/null +++ b/languages/ruby/bitwarden_sdk_secrets/sig/projects.rbs @@ -0,0 +1,25 @@ +module BitwardenSDKSecrets + class ProjectsClient + @command_runner: untyped + + def initialize: (untyped command_runner) -> void + + def create: (untyped organization_id, untyped project_name) -> untyped + + def get: (untyped project_id) -> untyped + + def list: (untyped organization_id) -> untyped + + def update: (untyped organization_id, untyped id, untyped project_put_request_name) -> untyped + + def delete: (untyped ids) -> untyped + + private + + def error_response: (untyped response) -> untyped + + def create_command: (untyped commands) -> untyped + + def parse_response: (untyped command) -> untyped + end +end diff --git a/languages/ruby/bitwarden_sdk_secrets/sig/projects_client.rbs b/languages/ruby/bitwarden_sdk_secrets/sig/projects_client.rbs deleted file mode 100644 index 00c9e578d..000000000 --- a/languages/ruby/bitwarden_sdk_secrets/sig/projects_client.rbs +++ /dev/null @@ -1,17 +0,0 @@ -require_once '../lib/extended_schemas/schemas.rbs' -require_once '../schemas.rbs' - -class ProjectsClient - @command_runner: CommandRunner - def initialize: (command_runner: CommandRunner) -> void - def create_project: (project_name: String, organization_id: String) -> ProjectsResponse - def get: (project_id: String) -> ProjectsResponse - def list_projects: (organization_id: String) -> Array(DatumElement) - def update_project: (id: String, project_put_request_name: String, organization_id: String) -> ProjectsResponse - def delete_projects: (ids: Array[String]) -> Array(ProjectDeleteResponse) - - private - - def create_command: (SelectiveProjectsCommand) -> SelectiveCommand - def parse_response: (ResponseForProjectResponse) -> ResponseForProjectResponse -end diff --git a/languages/ruby/bitwarden_sdk_secrets/sig/sdk.rbs b/languages/ruby/bitwarden_sdk_secrets/sig/sdk.rbs deleted file mode 100644 index 260fa1420..000000000 --- a/languages/ruby/bitwarden_sdk_secrets/sig/sdk.rbs +++ /dev/null @@ -1,3 +0,0 @@ -module BitwardenSDK - VERSION: String -end diff --git a/languages/ruby/bitwarden_sdk_secrets/sig/secrets.rbs b/languages/ruby/bitwarden_sdk_secrets/sig/secrets.rbs new file mode 100644 index 000000000..8590fd82b --- /dev/null +++ b/languages/ruby/bitwarden_sdk_secrets/sig/secrets.rbs @@ -0,0 +1,29 @@ +module BitwardenSDKSecrets + class SecretsClient + @command_runner: untyped + + def initialize: (untyped command_runner) -> void + + def get: (untyped id) -> untyped + + def get_by_ids: (untyped ids) -> untyped + + def sync: (untyped organization_id, untyped last_synced_date) -> untyped + + def create: (untyped organization_id, untyped key, untyped value, untyped note, untyped project_ids) -> untyped + + def list: (untyped organization_id) -> untyped + + def update: (untyped organization_id, untyped id, untyped key, untyped value, untyped note, untyped project_ids) -> untyped + + def delete: (untyped ids) -> untyped + + private + + def error_response: (untyped response) -> (untyped | nil | untyped) + + def create_command: (untyped commands) -> untyped + + def run_command: (untyped command) -> untyped + end +end diff --git a/languages/ruby/bitwarden_sdk_secrets/sig/secrets_client.rbs b/languages/ruby/bitwarden_sdk_secrets/sig/secrets_client.rbs deleted file mode 100644 index ccebcecd8..000000000 --- a/languages/ruby/bitwarden_sdk_secrets/sig/secrets_client.rbs +++ /dev/null @@ -1,18 +0,0 @@ -require_once '../lib/extended_schemas/schemas.rbs' -require_once '../schemas.rbs' - -class SecretsClient - # @command_runner: CommandRunner - def initialize: (command_runner: CommandRunner) -> void - def get: (id: String) -> SecretResponse - def get_by_ids: (ids: Array[String]) -> Array(SecretIdentifierResponse) - def create: (key: String, note: String, organization_id: String, project_ids: Array[String], value: String) -> SecretResponse - def list: (organization_id: String) -> Array(SecretIdentifierResponse) - def update: (id: String, key: String, note: String, organization_id: String, project_ids: Array[String], value: String) -> SecretResponse - def delete_secret: (ids: Array[String]) -> Array(SecretDeleteResponse) - - private - - def create_command: (SelectiveSecretsCommand) -> SelectiveCommand - def parse_response: (SelectiveSecretCommand) -> ResponseForSecretResponse -end diff --git a/languages/ruby/bitwarden_sdk_secrets/sig/version.rbs b/languages/ruby/bitwarden_sdk_secrets/sig/version.rbs new file mode 100644 index 000000000..869b679db --- /dev/null +++ b/languages/ruby/bitwarden_sdk_secrets/sig/version.rbs @@ -0,0 +1,3 @@ +module BitwardenSDKSecrets + VERSION: "0.2.0" +end diff --git a/languages/ruby/examples/example.rb b/languages/ruby/examples/example.rb index 475e52089..29a686708 100644 --- a/languages/ruby/examples/example.rb +++ b/languages/ruby/examples/example.rb @@ -12,58 +12,66 @@ bitwarden_settings = BitwardenSDKSecrets::BitwardenSettings.new(api_url, identity_url) bw_client = BitwardenSDKSecrets::BitwardenClient.new(bitwarden_settings) -response = bw_client.access_token_login(token, state_file) +response = bw_client.auth.login_access_token(token, state_file) puts response # CREATE project project_name = 'Test project 1' -response = bw_client.project_client.create_project(project_name, organization_id) +response = bw_client.projects.create(organization_id, project_name) puts response project_id = response['id'] # GET project -response = bw_client.project_client.get(project_id) +response = bw_client.projects.get(project_id) puts response # LIST projects -response = bw_client.project_client.list_projects(organization_id) +response = bw_client.projects.list(organization_id) puts response # UPDATE projects name = 'Updated test project 1' -response = bw_client.project_client.update_project(project_id, name, organization_id) +response = bw_client.projects.update(organization_id, project_id, name) puts response # CREATE secret key = 'AWS-SES' note = 'Private account' value = '8t27.dfj;' -response = bw_client.secrets_client.create(key, note, organization_id, [project_id], value) +response = bw_client.secrets.create(organization_id, key, value, note, [project_id]) puts response secret_id = response['id'] # GET secret -response = bw_client.secrets_client.get(secret_id) +response = bw_client.secrets.get(secret_id) puts response # GET secret by ids -response = bw_client.secrets_client.get_by_ids([secret_id]) +response = bw_client.secrets.get_by_ids([secret_id]) puts response # LIST secrets -response = bw_client.secrets_client.list(organization_id) +response = bw_client.secrets.list(organization_id) +puts response + +# SYNC secrets +response = bw_client.secrets.sync(organization_id, nil) +last_synced_date = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%6NZ') +puts response + +response = bw_client.secrets.sync(organization_id, last_synced_date) puts response # UPDATE secret note = 'updated password' value = '7I.ert10AjK' -response = bw_client.secrets_client.update(secret_id, key, note,organization_id, [project_id], value) +response = bw_client.secrets.update(organization_id, secret_id, key, value, note, [project_id]) puts response # DELETE secret -response = bw_client.secrets_client.delete_secret([secret_id]) +response = bw_client.secrets.delete([secret_id]) puts response # DELETE project -response = bw_client.project_client.delete_projects([project_id]) +response = bw_client.projects.delete([project_id]) puts response diff --git a/languages/ruby/gen_ruby_typedefs.sh b/languages/ruby/gen_ruby_typedefs.sh new file mode 100755 index 000000000..acd2bcc3c --- /dev/null +++ b/languages/ruby/gen_ruby_typedefs.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# shellcheck disable=SC3044,SC3020 + +# bail if rbs is not installed +if ! command -v rbs &>/dev/null; then + echo "rbs could not be found" + exit +fi + +# use consistent repository root to avoid relative paths +REPO_ROOT="$(git rev-parse --show-toplevel)" +pushd "$REPO_ROOT"/languages/ruby || exit + +# delete existing typedefs +rm -rf bitwarden_sdk_secrets/sig/* +mkdir -p bitwarden_sdk_secrets/sig + +# generate typedefs +RUBY_LIB_FILES="$(find bitwarden_sdk_secrets/lib -name "*.rb")" + +for file in $RUBY_LIB_FILES; do + rbs prototype rb "$file" >bitwarden_sdk_secrets/sig/"$(basename "$file" .rb).rbs" + rm -f bitwarden_sdk_secrets/sig/schemas.rbs +done + +popd || exit diff --git a/package-lock.json b/package-lock.json index bb89e32d2..894ec74eb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,6 @@ "license": "SEE LICENSE IN LICENSE", "devDependencies": { "@openapitools/openapi-generator-cli": "2.13.4", - "handlebars": "^4.7.8", "prettier": "3.3.3", "quicktype-core": "23.0.170", "rimraf": "6.0.1", @@ -19,9 +18,9 @@ } }, "node_modules/@babel/runtime": { - "version": "7.25.6", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.25.6.tgz", - "integrity": "sha512-VBj9MYyDb9tuLq7yzqjgzt6Q+IBQLrGZfdjOekyEirZPHxXWoTSGUTMrpsfi58Up73d13NfYLv8HT9vmznjzhQ==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.25.7.tgz", + "integrity": "sha512-FjoyLe754PMiYsFaN5C94ttGiOmBNYTf6pLr4xXHAT5uctHb092PBszndLDR5XA/jghQvn4n7JMHl7dmTgbm9w==", "dev": true, "license": "MIT", "dependencies": { @@ -70,9 +69,9 @@ } }, "node_modules/@isaacs/cliui/node_modules/ansi-regex": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", - "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz", + "integrity": "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==", "dev": true, "license": "MIT", "engines": { @@ -330,17 +329,6 @@ "url": "https://opencollective.com/openapi_generator" } }, - "node_modules/@pkgjs/parseargs": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", - "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", - "dev": true, - "license": "MIT", - "optional": true, - "engines": { - "node": ">=14" - } - }, "node_modules/@tsconfig/node10": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz", @@ -370,9 +358,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "22.5.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.2.tgz", - "integrity": "sha512-acJsPTEqYqulZS/Yp/S3GgeE6GZ0qYODUR8aVr/DkhHQ8l9nd4j5x1/ZJy9/gHrRlFMqkO6i0I3E27Alu4jjPg==", + "version": "22.7.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.5.tgz", + "integrity": "sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ==", "dev": true, "license": "MIT", "peer": true, @@ -407,9 +395,9 @@ } }, "node_modules/acorn-walk": { - "version": "8.3.3", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.3.tgz", - "integrity": "sha512-MxXdReSRhGO7VlFe1bRG/oI7/mdLV9B9JJT0N8vZOhF7gFRR5l3M8W9G8JxmKV+JC5mGqJ0QvqfSOLsCPa4nUw==", + "version": "8.3.4", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.4.tgz", + "integrity": "sha512-ueEepnujpqee2o5aIYnvHU6C0A42MNdsIDeqy5BydrkuC5R1ZuUFnm27EeFJGoEHJQgn3uleRvmTXaJgfXbt4g==", "dev": true, "license": "MIT", "dependencies": { @@ -876,13 +864,13 @@ } }, "node_modules/debug": { - "version": "4.3.6", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz", - "integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==", + "version": "4.3.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", + "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", "dev": true, "license": "MIT", "dependencies": { - "ms": "2.1.2" + "ms": "^2.1.3" }, "engines": { "node": ">=6.0" @@ -1029,9 +1017,9 @@ } }, "node_modules/follow-redirects": { - "version": "1.15.6", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", - "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", "dev": true, "funding": [ { @@ -1080,9 +1068,9 @@ } }, "node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", + "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", "dev": true, "license": "MIT", "dependencies": { @@ -1155,28 +1143,6 @@ "dev": true, "license": "ISC" }, - "node_modules/handlebars": { - "version": "4.7.8", - "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.8.tgz", - "integrity": "sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "minimist": "^1.2.5", - "neo-async": "^2.6.2", - "source-map": "^0.6.1", - "wordwrap": "^1.0.0" - }, - "bin": { - "handlebars": "bin/handlebars" - }, - "engines": { - "node": ">=0.4.7" - }, - "optionalDependencies": { - "uglify-js": "^3.1.4" - } - }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -1339,9 +1305,9 @@ } }, "node_modules/jackspeak": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-4.0.1.tgz", - "integrity": "sha512-cub8rahkh0Q/bw1+GxP7aeSe29hHHn2V4m29nnDlvCdlgU+3UGxkZp7Z53jLUdpX3jdTO0nJZUDl3xvbWc2Xog==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-4.0.2.tgz", + "integrity": "sha512-bZsjR/iRjl1Nk1UkjGpAzLNfQtzuijhn2g+pbZb98HQ1Gk8vM9hfbxeMBP+M2/UUdwj0RqGG3mlvk2MsAqwvEw==", "dev": true, "license": "BlueOak-1.0.0", "dependencies": { @@ -1352,9 +1318,6 @@ }, "funding": { "url": "https://github.com/sponsors/isaacs" - }, - "optionalDependencies": { - "@pkgjs/parseargs": "^0.11.0" } }, "node_modules/js-base64": { @@ -1402,9 +1365,9 @@ } }, "node_modules/lru-cache": { - "version": "11.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.0.0.tgz", - "integrity": "sha512-Qv32eSV1RSCfhY3fpPE2GNZ8jgM9X7rdAfemLWqTUxwiyIC4jJ6Sy0fZ8H+oLWevO6i4/bizg7c8d8i6bxrzbA==", + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.0.1.tgz", + "integrity": "sha512-CgeuL5uom6j/ZVrg7G/+1IXqRY8JXX4Hghfy5YE0EhoYQWvndP1kufu58cmZLNIDKnRhZrXfdS9urVWx98AipQ==", "dev": true, "license": "ISC", "engines": { @@ -1464,16 +1427,6 @@ "node": "*" } }, - "node_modules/minimist": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", - "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", - "dev": true, - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/minipass": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", @@ -1485,9 +1438,9 @@ } }, "node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "dev": true, "license": "MIT" }, @@ -1498,13 +1451,6 @@ "dev": true, "license": "ISC" }, - "node_modules/neo-async": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", - "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", - "dev": true, - "license": "MIT" - }, "node_modules/node-fetch": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", @@ -1587,9 +1533,9 @@ } }, "node_modules/package-json-from-dist": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.0.tgz", - "integrity": "sha512-dATvCeZN/8wQsGywez1mzHtTlP22H8OEfPrVMLNr4/eGa+ijtLn/6M5f0dY8UKNrC2O9UCU6SSoG3qRKnt7STw==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz", + "integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==", "dev": true, "license": "BlueOak-1.0.0" }, @@ -1953,16 +1899,6 @@ "dev": true, "license": "ISC" }, - "node_modules/source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true, - "license": "BSD-3-Clause", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/spawn-command": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/spawn-command/-/spawn-command-0.0.2.tgz", @@ -2172,20 +2108,6 @@ "node": ">=14.17" } }, - "node_modules/uglify-js": { - "version": "3.19.3", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.19.3.tgz", - "integrity": "sha512-v3Xu+yuwBXisp6QYTcH4UbH+xYJXqnq2m/LtQVWKWzYc1iehYnLixoQDN9FH6/j9/oybfd6W9Ghwkl8+UMKTKQ==", - "dev": true, - "license": "BSD-2-Clause", - "optional": true, - "bin": { - "uglifyjs": "bin/uglifyjs" - }, - "engines": { - "node": ">=0.8.0" - } - }, "node_modules/uid": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/uid/-/uid-2.0.2.tgz", @@ -2370,9 +2292,9 @@ } }, "node_modules/yaml": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.5.0.tgz", - "integrity": "sha512-2wWLbGbYDiSqqIKoPjar3MPgB94ErzCtrNE1FdqGuaO0pi2JGjmE8aW8TDZwzU7vuxcGRdL/4gPQwQ7hD5AMSw==", + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.5.1.tgz", + "integrity": "sha512-bLQOjaX/ADgQ20isPJRvF0iRUHIxVhYvr53Of7wGcWlO2jvtUlH5m87DsmulFVxRpNLOnI4tB6p/oh8D7kpn9Q==", "dev": true, "license": "ISC", "bin": { diff --git a/package.json b/package.json index 8f40e36ab..e7e419467 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ }, "devDependencies": { "@openapitools/openapi-generator-cli": "2.13.4", - "handlebars": "^4.7.8", "prettier": "3.3.3", "quicktype-core": "23.0.170", "rimraf": "6.0.1", diff --git a/support/docs/docs.ts b/support/docs/docs.ts deleted file mode 100644 index 067ff0827..000000000 --- a/support/docs/docs.ts +++ /dev/null @@ -1,139 +0,0 @@ -// Quick script that parses the rustdoc json output and generates a basic markdown documentation. -// -// Do note that this script follows no best practices and will not handle anything many edge cases. - -import fs from "fs"; -import path from "path"; -import Handlebars from "handlebars"; - -import { Input, InputType } from "./rustdoc"; - -const doc = JSON.parse(fs.readFileSync("./target/doc/bitwarden_uniffi.json", "utf8")); -const command = JSON.parse( - fs.readFileSync("./support/schemas/bitwarden_uniffi/DocRef.json", "utf8"), -); - -const template = Handlebars.compile( - fs.readFileSync(path.resolve(__dirname, "template.hbs"), "utf8"), -); - -// Modify this to include more root elements -const rootElements = [ - "Client", - "ClientAuth", - "ClientAttachments", - "ClientCiphers", - "ClientCollections", - "ClientCrypto", - "ClientExporters", - "ClientFolders", - "ClientGenerators", - "ClientPasswordHistory", - "ClientPlatform", - "ClientSends", - "ClientVault", -]; - -const localIndexArray = Object.values(doc.index).filter((entry: any) => entry.crate_id == 0); -const localIndex = localIndexArray.reduce((map: any, obj: any) => { - map[obj.id] = obj; - return map; -}, {}) as Record; - -let usedDefinitions: any[] = []; - -const out = rootElements.map((rootElement) => { - const root: any = localIndexArray.find((entry: any) => entry.name == rootElement); - const impls = root.inner.struct.impls; - - const elements = impls - .flatMap((e: any) => localIndex[e]) - .flatMap((e: any) => e.inner.impl.items) - .map((e: any) => localIndex[e]) - .filter((e: any) => e?.docs != null); - - return { - name: rootElement, - elements: elements.map((e: any) => { - return { - name: e.name, - docs: e.docs, - args: e.inner.function.decl.inputs.map((e: any) => map_input(e)), - output: map_type(e.inner.function.decl.output), - }; - }), - }; -}); - -function stripDef(str: string) { - return str.replace(/#\/definitions\//g, ""); -} - -Handlebars.registerHelper("stripDef", (str: string) => { - return stripDef(str); -}); - -// Add references -for (let i = 0; i < usedDefinitions.length; i++) { - const key = usedDefinitions[i]; - const cmd = command.definitions[key]; - if (cmd == null) { - continue; - } - - Object.entries(cmd.properties ?? {}).forEach((prop: any) => { - prop[1].allOf?.forEach((e: any) => { - usedDefinitions.push(stripDef(e["$ref"] as string)); - }); - }); -} - -const filteredDefinitions = [...new Set(usedDefinitions)] - .sort() - .map((key) => [key, command.definitions[key]]) - .filter((e) => e[1] != null) - .reduce((obj, cur) => ({ ...obj, [cur[0]]: cur[1] }), {}); - -console.log(template({ sections: out, commands: filteredDefinitions })); - -/// -/// Implementation details below. -/// - -// Format -function map_input(input: Input) { - return { - name: input[0], - type: map_type(input[1]), - }; -} - -function map_type(t: InputType) { - const args = t.resolved_path?.args; - const name = t.resolved_path?.name; - - let out = ""; - - if (name) { - usedDefinitions.push(name); - - if (command.definitions[name] != null) { - out += `[${name}](#${name.toLowerCase()})`; - } else { - out += name; - } - } - - if (args != null && args.angle_bracketed.args.length > 0) { - out += "<"; - out += args.angle_bracketed.args.map((t: any) => { - if (t.type.generic) { - return t.type.generic; - } else if (t.type.resolved_path) { - return t.type.resolved_path.name; - } - }); - out += ">"; - } - return out; -} diff --git a/support/docs/rustdoc.ts b/support/docs/rustdoc.ts deleted file mode 100644 index 2622b711e..000000000 --- a/support/docs/rustdoc.ts +++ /dev/null @@ -1,12 +0,0 @@ -export type Input = [string, InputType]; - -export type InputType = { - resolved_path?: { - name: string; - args: { - angle_bracketed: { - args: any[]; - }; - }; - }; -}; diff --git a/support/docs/template.hbs b/support/docs/template.hbs deleted file mode 100644 index bd78d138a..000000000 --- a/support/docs/template.hbs +++ /dev/null @@ -1,91 +0,0 @@ -# Bitwarden Mobile SDK - -Auto generated documentation for the Bitwarden Mobile SDK. For more information please refer to -the rust crates `bitwarden` and `bitwarden-uniffi`. For code samples check the -`languages/kotlin/app` and `languages/swift/app` directories. - -{{#each sections}} - -## {{name}} - -{{#each elements}} -### `{{name}}` -{{docs}} - -**Arguments**: -{{#each args}} -- {{name}}: {{{type}}} -{{/each}} - -**Output**: {{{output}}} - -{{/each}} -{{/each}} - -# References - -References are generated from the JSON schemas and should mostly match the kotlin and swift -implementations. - -{{#each commands}} - -## `{{@key}}` - -{{#if oneOf}} - - - - - - -{{#each oneOf}} -{{#each properties}} - - - - - -{{#if properties}} - - - -{{/if}} -{{/each}} -{{/each}} -
KeyTypeDescription
{{@key}}{{type}}
- - - - - - - {{#each properties}} - - - - - - {{/each}} -
KeyTypeDescription
{{@key}}{{type}}{{{description}}}
-
- -{{/if}} - -{{#unless oneOf}} - - - - - - -{{#each properties}} - - - - - -{{/each}} -
KeyTypeDescription
{{@key}}{{type}}{{description}}
-{{/unless}} - -{{/each}} diff --git a/support/scripts/schemas.ts b/support/scripts/schemas.ts index 5ea71408c..3eaad1903 100644 --- a/support/scripts/schemas.ts +++ b/support/scripts/schemas.ts @@ -117,9 +117,30 @@ async function main() { java.forEach((file, path) => { writeToFile(javaDir + path, file.lines); }); + + const php = await quicktype({ + inputData, + lang: "php", + inferUuids: false, + inferDateTimes: false, + rendererOptions: { + "acronym-style": "camel", + "with-get": false, + }, + }); + + const phpDir = "./languages/php/src/Schemas/"; + if (!fs.existsSync(phpDir)) { + fs.mkdirSync(phpDir); + } + + php.lines.splice(1, 0, "namespace Bitwarden\\Sdk\\Schemas;", "use stdClass;", "use Exception;"); + + writeToFile("./languages/php/src/Schemas/Schemas.php", php.lines); } main(); + function writeToFile(filename: string, lines: string[]) { const output = fs.createWriteStream(filename); lines.forEach((line) => {