Repository navigation
fix(worker): verify local_cert/local_pk form a matching, parseable pair - #1193
Open
rootsiemen wants to merge 1 commit into
Open
rootsiemen wants to merge 1 commit into
rootsiemen wants to merge 1 commit into
Conversation
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.
Closes #1183
What changed
ServerWorker::createSslContext()now verifies thatlocal_certandlocal_pkform a matching, parseable pair before the worker starts: the certificate must parse as X.509 (openssl_x509_read), the key must parse as a private key (openssl_pkey_get_private), and the two must match (openssl_x509_check_private_key). Any failure throwsInvalidArgumentExceptionnaming the file path(s), matching the existing TLS config error style. The existing path/symlink/readability checks are unchanged.Why
A mismatched or unparseable pair previously passed config validation and failed later in Workerman
listen()with a low-levelRuntimeException, after the worker had already started booting.Tests
ServerWorkerTestcases (fixtures generated in-test with PHP openssl functions, following the existinggenerateSelfSignedCerthelper): valid pair (existingtestHttpsWorkerUsesSslTransportAndTlsContext), mismatched pair, garbage certificate, garbage key.vendor/bin/phpunit --no-coverage tests/ServerWorkerTest.php: 47/49 pass. The 2 failures (testUnreadableCertThrowsException,testUnreadableKeyThrowsException) are pre-existing in this environment: running as root,is_readable()is true even for chmod-0000 files, so the same 2 tests fail on pristine master too (verified viagit stash).composer lint: php-cs-fixer, PHPStan level 8, Rector, kb-lint, check-changelog, check-exception-usage all pass.shellcheckflags a pre-existing info note inbin/worktree-done.sh(untouched shared script) andhadolintis not installed in this environment, so the lint script reports those two steps as failed; neither is caused by this change.[Unreleased]→Fixed([Bug] ServerWorker does not verify local_cert/local_pk form a matching, parseable pair #1183).