Skip to content

[webview_flutter_wkwebview] Fixes loadFlutterAsset exception and updates native wrapper for SecTrust and SecCertificate #9016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Apr 14, 2025

Conversation

bparrishMines
Copy link
Contributor

@bparrishMines bparrishMines commented Apr 6, 2025

Adds support to the native wrapper to handle SecTrust and SecCertificate.

This is a part of landing #7893 by splitting of the native wrapper implementation.

Also fixes flutter/flutter#162938 and adds an integration test for loadFlutterAsset.

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

@bparrishMines bparrishMines changed the title Sec methods [webview_flutter_wkwebview] Fixes loadFlutterAsset exception and updates native wrapper for SecTrust and SecCertificate Apr 6, 2025
Copy link
Contributor Author

@bparrishMines bparrishMines Apr 6, 2025

Choose a reason for hiding this comment

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

For future reference, I ran this in a terminal to generate this file

# Generate a private key
openssl genpkey -algorithm RSA -out test_key.pem -pkeyopt rsa_keygen_bits:2048

# Generate a Certificate Signing Request (CSR) - fill in dummy info
openssl req -new -key test_key.pem -out test_csr.pem

# Generate a self-signed certificate (e.g., valid for 5000 days) and export to DER format
openssl x509 -req -days 5000 -in test_csr.pem -signkey test_key.pem -out test_cert.der -outform DER

@bparrishMines bparrishMines marked this pull request as ready for review April 6, 2025 20:24
@bparrishMines bparrishMines requested a review from cbracken as a code owner April 6, 2025 20:24
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM with small comments.


var url: URL? = bundle.url(
forResource: (assetFilePath! as NSString).deletingPathExtension,
withExtension: (assetFilePath! as NSString).pathExtension)
Copy link
Contributor

Choose a reason for hiding this comment

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

If you use guard for the nil check on line 27, can't you avoid the force unwrap here and below?

Copy link
Contributor Author

@bparrishMines bparrishMines Apr 13, 2025

Choose a reason for hiding this comment

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

I tried changing line 27 to:

guard assetFilePath != nil else {
  return nil
}

and I still needed the force unwrap here. Is this what you were thinking?

Copy link

Choose a reason for hiding this comment

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

I'm not @stuartmorgan-g, but you could write it as

guard let assetFilePath else {
    return nil
}

and then you can use the variable assetFilePath without force unwrapping it.

Copy link
Contributor

Choose a reason for hiding this comment

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

For the versions of Swift we support it's still guard let assetFilePath = assetFilePath else.

@bparrishMines bparrishMines added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 14, 2025
@auto-submit auto-submit bot merged commit 7bdffbe into flutter:main Apr 14, 2025
82 checks passed
@bparrishMines bparrishMines deleted the sec_methods branch April 14, 2025 17:59
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 15, 2025
…ion and updates native wrapper for `SecTrust` and `SecCertificate` (flutter/packages#9016)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: webview_flutter platform-ios platform-macos
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[webview_flutter] loadFlutterAsset throws PlatformException on macOS
3 participants