Repository navigation
Conversation
On iOS and tvOS HAVE_SECITEMIMPORT is 0, so import_pem() returns AVERROR_PATCHWELCOME and any tls_ca_file makes the TLS open fail, although the later verification through SecTrustSetAnchorCertificates() works on those platforms. When SecItemImport() is unavailable, parse the PEM CERTIFICATE blocks of the CA file directly: strip whitespace, decode them with av_base64_decode() and build the anchor array with SecCertificateCreateWithData(). Other PEM block types are skipped, a malformed block is AVERROR_INVALIDDATA, and so is a file without any certificate. Behaviour with SecItemImport() is unchanged. Separately, open the CA, certificate and key files with a protocol whitelist of exactly "file" instead of inheriting the stream's whitelist. FFmpeg's https protocol sets a default_whitelist of "http,https,tls,rtp,tcp,udp,crypto,httpproxy" (libavformat/http.c), which has no "file", so the inherited whitelist made loading the CA file, and so every https open with ca_file, fail with "Protocol 'file' not on whitelist". This is not specific to iOS/tvOS: it also fails on the macOS SecItemImport path, on pristine FFmpeg. This permits local-file reads of the configured CA/cert/key path even when the caller's whitelist excludes "file". It still honours the caller's blacklist. The GnuTLS and OpenSSL backends read these paths straight from disk and never hit the whitelist.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(build): add opt-in
enable-lgpl21(FFmpeg as LGPL-2.1+, Secure Transport TLS)Closes #87
What this adds
A new opt-in build argument,
enable-lgpl21, alongsideenable-gpl:With it, FFmpeg is built as "LGPL version 2.1 or later":
--enable-version3is removed (gmp is LGPLv3, which is what forced it).--enable-securetransportis added, so TLS comes from Apple's Secure Transport.enable-gpl(the option parser rejects the pair).Package.swiftis post-processed to match (below).Nothing changes unless
enable-lgpl21is passed. With the option off, the generatedPackage.swiftiscmp-identical to the one produced bymainbefore this PR.Why
The default build links gmp and gnutls, so FFmpeg ends up LGPLv3 (
--enable-version3). For an appshipped through the App Store, LGPL-2.1 is a materially easier obligation than LGPLv3. This option
gives people who need that a supported path without forking the build scripts.
Why Secure Transport and not OpenSSL
--enable-opensslwith OpenSSL 3.x does configure as LGPL 2.1 (configure only asks for--enable-version3for OpenSSL >= 3 together with--enable-gpl).LICENSE.mdsays Apache-2.0 libraries need--enable-version3to combine withLGPL-2.1, and OpenSSL 3 is Apache-2.0. The configure check and the documentation disagree.
enabled; gnutls and Secure Transport accept it.
Secure Transport is part of the OS, adds no library to ship, and has no license question.
The FFmpeg patch
Sources/BuildScripts/patch/FFmpeg/0001-tls_securetransport-load-ca_file-without-SecItemImport.patch(applies to FFmpeg n9.0.2, which this branch builds, and also applied to n8.1.2).
SecItemImportdoes not exist on iOS/tvOS. configure setsHAVE_SECITEMIMPORT 0there, soimport_pem()returnsAVERROR_PATCHWELCOMEand any https open with a CA file (mpv'stls-ca-file)fails. When
SecItemImportis unavailable the patch parses the PEMCERTIFICATEblocks itself:whitespace stripped,
av_base64_decode, thenSecCertificateCreateWithData. Other block types areskipped; a malformed block, or a file with no certificate, is
AVERROR_INVALIDDATA. Behaviour withSecItemImportis unchanged.FFmpeg's own https protocol sets a
default_whitelistofhttp,https,tls,rtp,tcp,udp,crypto,httpproxy(
libavformat/http.c), which has nofile, so loading the CA file failed withProtocol 'file' not on whitelistand so did every https open withca_file. A plainavio_open2of anhttps URL with
ca_filefails this way on pristine FFmpeg; mpv is not involved. It is not only aniOS/tvOS problem: on macOS (
HAVE_SECITEMIMPORT=1) any https open withca_filefails too, so theproblem is live there, not latent. The patch opens the CA, certificate and key files with a whitelist of
exactly
file. This permits local-file reads of the configured CA/cert/key path even when thecaller's whitelist excludes
file; it still honours the caller's blacklist. Those paths areconfiguration, not stream data. The gnutls and OpenSSL backends read them straight from disk and never
hit the whitelist.
Generated manifest
docs/Package.template.swiftis post-processed whenenable-lgpl21is set(
applyLGPL21Manifest, plus early returns ingeneratePackageManagerFile):_FFmpegdependencies, and.linkedFramework("Security")is added.MPVKit-GPLproduct and the_MPVKit-GPL/_FFmpeg-GPLtargets with their-GPLbinary targetsare removed (an LGPL-2.1 build cannot produce them).
nothing links them in this mode.
rather than quietly emitting a manifest that still needs the removed libraries.
How it was verified
On 1.0.0 (FFmpeg n8.1.2, mpv v0.41.0), in a fork, with this feature fully built:
LGPL version 2.1 or later.archives show no gnutls, nettle, gmp or OpenSSL code, and Secure Transport plus the patched
import_ca_pempresent.tls-verify=yesandtls-ca-fileagainst a local HTTPS server: a self-signed certificate added to the CA file plays; a private-CA leaf
added to the CA file plays; a certificate not in the CA file is rejected (
-9807,errSSLXCertChainInvalid).leaks: a Mozilla bundle parses 119/119, CRLFinput works, malformed input is rejected.
On this branch (FFmpeg n9.0.2) only; no full build and no runtime test of the network path:
git apply --checkof the patch on pristine n9.0.2 passes (the build script applies it withgit apply).enable-lgpl21configure of n9.0.2 for iOS arm64 (using this branch's build script) reportsCONFIG_SECURETRANSPORT 1,CONFIG_GNUTLS 0,CONFIG_VERSION3 0,CONFIG_GPL 0, and license"LGPL version 2.1 or later".
libavformat/tls_securetransport.ocompiles for arm64.HAVE_SECITEMIMPORTforced to 0, under ASan/UBSan, covering 15CA-file cases.
cmp-identical tomain's; option on parseswith
swift package dump-package, has the single productMPVKit, no GPL product or target, no gmp /nettle / hogweed / gnutls / Libssl / Libcrypto / Libsmbclient, links Security, and every target dependency
resolves. Mutating the template (renamed dependency, product, target, marker) makes it fail loudly.
swiftc -typecheckof the build script sources passes at each of the three commits.Known limits
OSes, but this option inherits that.
tls-ca-file, Secure Transport verifies against the system roots (still verified, hostnamechecked). The gnutls build behaves differently: with no
ca_fileit falls back tognutls_certificate_set_x509_system_trust, which is unimplemented on iOS/tvOS (it returned -1250 whenmeasured), and a
ca_filepath that does not exist is only logged, not an error.enable-lgpl21build still downloads OpenSSL and Smbclient during the build, but they are not linkedand not shipped in the generated manifest.
Libbluray,LibuchardetandLibluajitbinaryTargets are still emitted unchanged in this mode;they are not licence issues for this option.