-
Notifications
You must be signed in to change notification settings - Fork 34
Added option --tls-certKey to supply cert private key #20
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
Open
jobarasoined
wants to merge
1
commit into
NeffIsBack:master
Choose a base branch
from
jobarasoined:tlsCertKey-option
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,11 +140,37 @@ def run(self): | |
| if not os.path.isfile(self.args.tlsCert): | ||
| self.logger.error(f"TLS certificate file '{self.args.tlsCert}' not found! Exiting...") | ||
| exit(1) | ||
|
|
||
| if self.args.tlsCertKey: | ||
| if not os.path.isfile(self.args.tlsCertKey): | ||
| self.logger.error(f"TLS certificate Key file '{self.args.tlsCertKey}' not found! Exiting...") | ||
| exit(1) | ||
|
|
||
| self.logger.info(f"Using TLS certificate '{self.args.tlsCert}' for HTTPS WSUS Server") | ||
| # checking if the cert has the private key baked within the cert | ||
| # https://docs.python.org/3/library/ssl.html#combined-key-and-certificate | ||
|
|
||
| if not self.args.tlsCertKey: | ||
| with open(self.args.tlsCert, 'r') as h: | ||
| data = h.read() | ||
| has_private_key = "-----BEGIN PRIVATE KEY-----" in data or "-----BEGIN RSA PRIVATE KEY-----" in data | ||
| has_cert = "-----BEGIN CERTIFICATE-----" in data | ||
| if has_cert and has_private_key: | ||
| self.logger.warning("Private key BEGIN in the certfile is not secure separate the two and keep the private key safe") | ||
| else: | ||
| self.logger.error("No private key found. Supply it using --tls-certKey") | ||
| # To perform TLS server authentication (decrypt/session key ops, prove ownership) the server needs the corresponding private key. The cert alone cannot do that. | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is why i exit after no private key is found immediately |
||
| exit(1) | ||
|
|
||
| self.logger.info(f"Using TLS certificate private key '{self.args.tlsCertKey}' for HTTPS WSUS Server") | ||
| try: | ||
| context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) | ||
| context.load_cert_chain(certfile=self.args.tlsCert) | ||
| context.load_cert_chain(certfile=self.args.tlsCert, keyfile=self.args.tlsCertKey) | ||
| context.check_hostname = False | ||
| http_server.socket = context.wrap_socket(http_server.socket, server_side=True) | ||
| except ssl.SSLError: | ||
| self.logger.error("Make sure The cert in a PEM format not a DER") | ||
| exit(1) | ||
|
|
||
| try: | ||
| self.logger.info(f"Starting WSUS Server on {self.hostIp}:{self.wsusPort}...") | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to break kebab-case for camel case, I felt --tls-cert-key already have too many dashs