-
Notifications
You must be signed in to change notification settings - Fork 122
feat: POC of PQC negotiation with candlepin server #3713
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
Draft
jirihnidek
wants to merge
2
commits into
main
Choose a base branch
from
jhnidek/pqc_poc
base: main
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.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
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
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
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 |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import re | ||
| import subprocess | ||
|
|
||
| """ | ||
| This is POC of new functionality of subscription-manager. This module helps to negotiate | ||
| PQC with candlepin server. | ||
| """ | ||
|
|
||
|
|
||
| def run(cmd, shell=True, cwd=None): | ||
| """ | ||
| Run a command. | ||
| Return exitcode, stdout, stderr | ||
| """ | ||
|
|
||
| proc = subprocess.Popen( | ||
| cmd, | ||
| shell=shell, | ||
| cwd=cwd, | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE, | ||
| universal_newlines=True, | ||
| errors="surrogateescape", | ||
| ) | ||
|
|
||
| stdout, stderr = proc.communicate() | ||
| return proc.returncode, stdout, stderr | ||
|
|
||
|
|
||
| # FIXME: We should get the list of OIDs from openssl library in the certificate.c. Parsing | ||
| # output of "openssl list -public-key-algorithms" is something we should avoid. | ||
|
|
||
|
|
||
| def get_signature_algorithms(): | ||
| """ | ||
| Get signature algorithms supported by the system. | ||
| """ | ||
| cmd = "openssl list -signature-algorithms" | ||
| return_code, stdout, stderr = run(cmd) | ||
| if return_code != 0: | ||
| raise RuntimeError(f"Failed to get public key algorithms: {stderr}") | ||
| lines = stdout.strip().splitlines() | ||
| algorithms = [] | ||
| for i, line in enumerate(lines): | ||
| line = line.strip() | ||
| # Parse line like this: | ||
| # { 2.16.840.1.101.3.4.3.31, id-slh-dsa-shake-256f, SLH-DSA-SHAKE-256f } @ default | ||
| match = re.search(r"\{\s*([^,]+)", line) | ||
| if match: | ||
| algorithms.append(match.group(1).strip()) | ||
| return algorithms | ||
|
|
||
|
|
||
| def get_public_key_algorithms(): | ||
| """ | ||
| Get public key algorithms supported by the system. | ||
| """ | ||
| cmd = "openssl list -public-key-algorithms" | ||
| return_code, stdout, stderr = run(cmd) | ||
| if return_code != 0: | ||
| raise RuntimeError(f"Failed to get public key algorithms: {stderr}") | ||
| lines = stdout.strip().splitlines() | ||
| algorithms = [] | ||
| legacy = False | ||
| for i, line in enumerate(lines): | ||
| line = line.strip() | ||
| if line.startswith("Legacy:"): | ||
| legacy = True | ||
| continue | ||
| if line.startswith("Provided:"): | ||
| legacy = False | ||
| continue | ||
| # Parse line like this: | ||
| # IDs: { 2.16.840.1.101.3.4.3.21, id-slh-dsa-sha2-128f, SLH-DSA-SHA2-128f } @ default | ||
| if not legacy: | ||
| match = re.search(r"IDs: \{\s*([^,]+)", line) | ||
| if match: | ||
| algorithms.append(match.group(1).strip()) | ||
| return algorithms | ||
|
|
||
|
|
||
| def get_pub_key_and_sign_algorithms(): | ||
| """ | ||
| Returns a list containing supported public key and signature algorithms. | ||
| """ | ||
| pub_key_algorithms = get_public_key_algorithms() | ||
| sig_algorithms = get_signature_algorithms() | ||
| all_algorithms = set(pub_key_algorithms).union(set(sig_algorithms)) | ||
| return list(all_algorithms) | ||
|
|
||
|
|
||
| def __smoke_test__(): | ||
| """ | ||
| Smoke testing of get_public_key_algorithms() | ||
| """ | ||
| pub_key_algorithms = get_public_key_algorithms() | ||
| sig_algorithms = get_signature_algorithms() | ||
| print("Supported public key & signature algorithms:") | ||
| for algorithm in pub_key_algorithms: | ||
| if algorithm in sig_algorithms: | ||
| print(f"- {algorithm} (sig+pub)") | ||
| else: | ||
| print(f"- {algorithm} (pub only)") | ||
| for algorithm in sig_algorithms: | ||
| if algorithm not in pub_key_algorithms: | ||
| print(f"- {algorithm} (sig only)") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| __smoke_test__() | ||
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
Oops, something went wrong.
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.
security (python.lang.security.audit.dangerous-subprocess-use-audit): Detected subprocess function 'Popen' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'.
Source: opengrep