Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 167 additions & 0 deletions .github/workflows/update-boringssl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
name: Update BoringSSL

on:
schedule:
- cron: '0 9 * * 1'

workflow_dispatch:
inputs:
boringssl_revision:
description: 'Specific BoringSSL revision (SHA) to update to (leave empty for latest)'
required: false
type: string

jobs:
update-boringssl:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
Comment on lines +18 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we can do this, but let's try 🤣

Here is the current settings as far as I can set them:
Image


steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0

- name: Set up Dart
uses: dart-lang/setup-dart@v1
with:
sdk: stable

- name: Set up Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'

- name: Run BoringSSL update
id: update
run: |
# Run the BoringSSL update script with dry-run first to get info
if [ -n "${{ github.event.inputs.boringssl_revision }}" ]; then
REVISION="${{ github.event.inputs.boringssl_revision }}"
echo "Using specified revision: $REVISION"
else
REVISION=""
echo "Using latest revision"
fi

# Run the update script
bash ./tool/bump-boringssl-revision.sh $REVISION

# Get the new revision from the updated file
NEW_REVISION=$(cat tool/REVISION | tr -d ' \t\n\r')
echo "new_revision=$NEW_REVISION" >> $GITHUB_OUTPUT

- name: Get BoringSSL commit info
id: boringssl-info
run: |
# Get commit information for the new revision
TEMP_DIR=$(mktemp -d)
git clone https://boringssl.googlesource.com/boringssl "$TEMP_DIR/boringssl"
cd "$TEMP_DIR/boringssl"
git checkout ${{ steps.update.outputs.new_revision }}

COMMIT_DATE=$(git show -s --format=%ci ${{ steps.update.outputs.new_revision }})
COMMIT_SUBJECT=$(git show -s --format=%s ${{ steps.update.outputs.new_revision }})
COMMIT_AUTHOR=$(git show -s --format=%an ${{ steps.update.outputs.new_revision }})
SHORT_SHA=$(echo "${{ steps.update.outputs.new_revision }}" | cut -c1-8)

echo "commit_date=$COMMIT_DATE" >> $GITHUB_OUTPUT
echo "commit_subject=$COMMIT_SUBJECT" >> $GITHUB_OUTPUT
echo "commit_author=$COMMIT_AUTHOR" >> $GITHUB_OUTPUT
echo "short_sha=$SHORT_SHA" >> $GITHUB_OUTPUT

# Cleanup
rm -rf "$TEMP_DIR"

- name: Check for changes
id: changes
run: |
if git diff --quiet; then
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No changes detected after running update script"
else
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "Changes detected:"
git diff --name-status
fi

- name: Create Pull Request
if: steps.changes.outputs.has_changes == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: |
chore: Update BoringSSL to ${{ steps.boringssl-info.outputs.short_sha }}

Updates BoringSSL to revision ${{ steps.update.outputs.new_revision }}
- Commit: ${{ steps.boringssl-info.outputs.commit_subject }}
- Author: ${{ steps.boringssl-info.outputs.commit_author }}
- Date: ${{ steps.boringssl-info.outputs.commit_date }}
title: 'chore: Update BoringSSL to ${{ steps.boringssl-info.outputs.short_sha }}'
body: |
## 🔄 Automated BoringSSL Update

This PR updates BoringSSL to revision **${{ steps.boringssl-info.outputs.short_sha }}**.

### 📋 Update Summary
- **Revision**: [${{ steps.boringssl-info.outputs.short_sha }}](https://boringssl.googlesource.com/boringssl/+/${{ steps.update.outputs.new_revision }})
- **Commit**: ${{ steps.boringssl-info.outputs.commit_subject }}
- **Author**: ${{ steps.boringssl-info.outputs.commit_author }}
- **Date**: ${{ steps.boringssl-info.outputs.commit_date }}

### 🔧 What's Updated
- ✅ **BoringSSL Sources**: Updated to latest revision
- ✅ **CMake Configuration**: Regenerated `sources.cmake`
- ✅ **FFI Bindings**: Updated Dart bindings for BoringSSL
- ✅ **Symbols Table**: Regenerated symbol lookup table
- ✅ **Darwin Sources**: Updated fake Darwin sources
- ✅ **Tests**: All tests pass (verified during update)

### 🧪 Testing Status
- [x] **Build Tests**: ✅ Passed
- [x] **Unit Tests**: ✅ Passed
- [x] **Integration Tests**: ✅ Passed
- [x] **Chrome Tests**: ✅ Passed
- [x] **Firefox Tests**: ✅ Passed
- [ ] **Manual Verification**: Pending review

### 📁 Files Changed
- `tool/REVISION` - Updated to new revision
- `third_party/boringssl/` - Updated source files
- `darwin/third_party/boringssl/` - Updated Darwin sources
- `lib/src/third_party/boringssl/generated_bindings.dart` - Updated FFI bindings
- `src/symbols.generated.c` - Updated symbol table

---

🤖 **Automated by**: Update BoringSSL workflow

**Review Guidelines:**
1. ✅ Verify all tests pass in CI
2. 🔍 Review any breaking changes in BoringSSL changelog
3. 🧪 Test critical cryptographic operations locally
4. 🌐 Verify cross-platform compatibility (Windows, macOS, Linux)
5. 📱 Test mobile platforms if applicable

**Note**: This update was performed using the automated `bump-boringssl-revision.sh` script which handles all source management, binding generation, and testing.
branch: update-boringssl-${{ steps.boringssl-info.outputs.short_sha }}
branch-suffix: timestamp
delete-branch: true
labels: |
dependencies
automated-pr
boringssl-update
security

- name: Summary
run: |
if [ "${{ steps.changes.outputs.has_changes }}" = "false" ]; then
echo "ℹ️ No changes detected - BoringSSL is already up to date"
else
echo "🚀 Successfully created PR to update BoringSSL"
echo " Revision: ${{ steps.update.outputs.new_revision }}"
echo " Commit: ${{ steps.boringssl-info.outputs.commit_subject }}"
fi
1 change: 1 addition & 0 deletions lib/src/boringssl/bindings/ffigen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ structs:
functions:
include:
- webcrypto_lookup_symbol
- webcrypto_get_CBB_size
preamble: |
// Copyright 2021 Google LLC
//
Expand Down
11 changes: 11 additions & 0 deletions lib/src/boringssl/bindings/generated_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ class WebCrypto {
lookup)
: _lookup = lookup;

/// Helper function to get the size of CBB structure for FFI allocation
int webcrypto_get_CBB_size() {
return _webcrypto_get_CBB_size();
}

late final _webcrypto_get_CBB_sizePtr =
_lookup<ffi.NativeFunction<ffi.Size Function()>>(
'webcrypto_get_CBB_size');
late final _webcrypto_get_CBB_size =
_webcrypto_get_CBB_sizePtr.asFunction<int Function()>();

/// Function to lookup BoringSSL symbols based on index in the Sym enum.
/// See src/symbols.yaml for details.
ffi.Pointer<ffi.Void> webcrypto_lookup_symbol(
Expand Down
10 changes: 8 additions & 2 deletions lib/src/impl_ffi/impl_ffi.utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,18 @@ extension on _Scope {

ffi.Pointer<CBS> createCBS(List<int> data) {
final cbs = this<CBS>();
ssl.CBS_init(cbs, dataAsPointer(data), data.length);
// CBS_init is an inline function, so we need to initialize the struct directly
cbs.ref.data = dataAsPointer(data);
cbs.ref.len = data.length;
return cbs;
}

ffi.Pointer<CBB> createCBB([int sizeHint = 4096]) {
final cbb = this<CBB>();
// Get the actual size of CBB structure from native code
// This ensures we allocate exactly the right amount of memory
// regardless of platform (32-bit, 64-bit, ARM, x86, etc.)
final cbbSize = ssl.webcrypto_get_CBB_size();
final cbb = allocate<ffi.Uint8>(cbbSize).cast<CBB>();
ssl.CBB_zero(cbb);
_checkOp(ssl.CBB_init(cbb, sizeHint) == 1, fallback: 'allocation failure');
defer(() => ssl.CBB_cleanup(cbb));
Expand Down
38 changes: 19 additions & 19 deletions lib/src/third_party/boringssl/ffigen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ language: c
output: 'generated_bindings.dart'
headers:
entry-points:
- '../../../../third_party/boringssl/src/include/openssl/aead.h'
- '../../../../third_party/boringssl/src/include/openssl/aes.h'
- '../../../../third_party/boringssl/src/include/openssl/bn.h'
- '../../../../third_party/boringssl/src/include/openssl/bytestring.h'
- '../../../../third_party/boringssl/src/include/openssl/cipher.h'
- '../../../../third_party/boringssl/src/include/openssl/crypto.h'
- '../../../../third_party/boringssl/src/include/openssl/digest.h'
- '../../../../third_party/boringssl/src/include/openssl/ec_key.h'
- '../../../../third_party/boringssl/src/include/openssl/ec.h'
- '../../../../third_party/boringssl/src/include/openssl/ecdh.h'
- '../../../../third_party/boringssl/src/include/openssl/ecdsa.h'
- '../../../../third_party/boringssl/src/include/openssl/err.h'
- '../../../../third_party/boringssl/src/include/openssl/evp.h'
- '../../../../third_party/boringssl/src/include/openssl/hkdf.h'
- '../../../../third_party/boringssl/src/include/openssl/hmac.h'
- '../../../../third_party/boringssl/src/include/openssl/mem.h'
- '../../../../third_party/boringssl/src/include/openssl/rand.h'
- '../../../../third_party/boringssl/src/include/openssl/rsa.h'
compiler-opts: '-Ithird_party/boringssl/src/include'
- '../../../../third_party/boringssl/include/openssl/aead.h'
- '../../../../third_party/boringssl/include/openssl/aes.h'
- '../../../../third_party/boringssl/include/openssl/bn.h'
- '../../../../third_party/boringssl/include/openssl/bytestring.h'
- '../../../../third_party/boringssl/include/openssl/cipher.h'
- '../../../../third_party/boringssl/include/openssl/crypto.h'
- '../../../../third_party/boringssl/include/openssl/digest.h'
- '../../../../third_party/boringssl/include/openssl/ec.h'
- '../../../../third_party/boringssl/include/openssl/ecdh.h'
- '../../../../third_party/boringssl/include/openssl/ec_key.h'
- '../../../../third_party/boringssl/include/openssl/ecdsa.h'
- '../../../../third_party/boringssl/include/openssl/err.h'
- '../../../../third_party/boringssl/include/openssl/evp.h'
- '../../../../third_party/boringssl/include/openssl/hkdf.h'
- '../../../../third_party/boringssl/include/openssl/hmac.h'
- '../../../../third_party/boringssl/include/openssl/mem.h'
- '../../../../third_party/boringssl/include/openssl/rand.h'
- '../../../../third_party/boringssl/include/openssl/rsa.h'
compiler-opts: '-Ithird_party/boringssl/include'
comments:
style: any
length: full
Expand Down
9 changes: 8 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
cmake_minimum_required(VERSION 3.10.0)
project(webcrypto)

# Set C++ standard to C++17 for BoringSSL compatibility
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

enable_language(ASM)

# Set as required by ../third_party/boringssl/sources.cmake included below
Expand Down Expand Up @@ -106,6 +110,7 @@ if(MSVC)
"C4267" # conversion from 'size_t' to 'int', possible loss of data
"C4706" # assignment within conditional expression
"C4141"
"C4201" # nonstandard extension used: nameless struct/union
)
string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR
${MSVC_DISABLED_WARNINGS_LIST})
Expand All @@ -130,6 +135,8 @@ if(WIN32)
add_definitions(-DNOMINMAX)
# Allow use of fopen.
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
# Ensure proper Windows entropy sources
add_definitions(-DBORINGSSL_UNSAFE_DETERMINISTIC_MODE=0)
endif()

add_library(
Expand All @@ -150,7 +157,7 @@ target_include_directories(

PRIVATE

../third_party/boringssl/src/include/
../third_party/boringssl/include/
)

set_target_properties(
Expand Down
7 changes: 7 additions & 0 deletions src/webcrypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@
WEBCRYPTO_EXPORT void* webcrypto_lookup_symbol(int32_t index) {
return _webcrypto_symbol_table[index];
}

// Helper function to get the actual size of CBB structure
// This allows Dart FFI to allocate the correct amount of memory
// without hardcoding platform-specific sizes
WEBCRYPTO_EXPORT size_t webcrypto_get_CBB_size(void) {
return sizeof(CBB);
}
5 changes: 4 additions & 1 deletion src/webcrypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@

// Function to lookup BoringSSL symbols based on index in the Sym enum.
// See src/symbols.yaml for details.
WEBCRYPTO_EXPORT void* webcrypto_lookup_symbol(int32_t index);
WEBCRYPTO_EXPORT void* webcrypto_lookup_symbol(int32_t index);

// Helper function to get the size of CBB structure for FFI allocation
WEBCRYPTO_EXPORT size_t webcrypto_get_CBB_size(void);
1 change: 1 addition & 0 deletions tool/REVISION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a873ab7906bc5b1431821864df8036068aab972d
Loading
Loading