Skip to content
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

gh-118658: Modify cert generation script to extract cert3.pem #124598

Merged
merged 2 commits into from
Oct 4, 2024

Conversation

felixfontein
Copy link
Contributor

@felixfontein felixfontein commented Sep 26, 2024

This updates #118669 to extract the added file cert3.pem from keycert3.pem.

I'm not sure whether using the same issue number in the title is ok...

@felixfontein
Copy link
Contributor Author

felixfontein commented Sep 26, 2024

CC @kanavin

I cannot really test this since the script doesn't work for me at all (it produces an invalid OpenSSL command line before reaching the part I modified), but I ran the code I added/modified manually and it seems to work.

@kanavin
Copy link
Contributor

kanavin commented Sep 26, 2024

I have cherry-picked this. Sadly there are failures:

======================================================================
ERROR: test_certificate_chain (test.test_ssl.TestPostHandshakeAuth.test_certificate_chain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/srv/work/alex/cpython/Lib/test/test_ssl.py", line 4708, in test_certificate_chain
    expected_ee_cert = ssl.PEM_cert_to_DER_cert(f.read())
  File "/srv/work/alex/cpython/Lib/ssl.py", line 1498, in PEM_cert_to_DER_cert
    raise ValueError("Invalid PEM encoding; must start with %s"
                     % PEM_HEADER)
ValueError: Invalid PEM encoding; must start with -----BEGIN CERTIFICATE-----

======================================================================
FAIL: test_https_client_non_tls_response_ignored (test.test_ssl.TestPreHandshakeClose.test_https_client_non_tls_response_ignored)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/srv/work/alex/cpython/Lib/test/test_ssl.py", line 5150, in test_https_client_non_tls_response_ignored
    with warnings_helper.check_no_resource_warning(self), \
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/srv/work/alex/cpython/Lib/contextlib.py", line 148, in __exit__
    next(self.gen)
    ~~~~^^^^^^^^^^
  File "/srv/work/alex/cpython/Lib/test/support/warnings_helper.py", line 148, in check_no_resource_warning
    with check_no_warnings(testcase, category=ResourceWarning, force_gc=True):
         ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/work/alex/cpython/Lib/contextlib.py", line 148, in __exit__
    next(self.gen)
    ~~~~^^^^^^^^^^
  File "/srv/work/alex/cpython/Lib/test/support/warnings_helper.py", line 131, in check_no_warnings
    testcase.assertEqual(warns, [])
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
AssertionError: Lists differ: [<warnings.WarningMessage object at 0x7fe633996510>] != []

First list contains 1 additional elements.
First extra element 0:
<warnings.WarningMessage object at 0x7fe633996510>

- [<warnings.WarningMessage object at 0x7fe633996510>]
+ []

----------------------------------------------------------------------
Ran 2 tests in 0.081s

The generated cert3.pem looks like this:

-----BEGIN PRIVATE KEY-----
MIIG/gIBADANBgkqhkiG9w0BAQEFAASCBugwggbkAgEAAoIBgQDlMLf3ifFQ+30m
PFr/C+j+snJyAtnylop6CBLODCRxdcFKH40r7ugai8yDi+5uLWzw4n9I1Yim16sx
VBGDSl4hawzhSyMmg6TfzXMISFuQVCxib6vPH7Lp0PPAxHs2yTz/B+CmfLJKJX6T
xlGSN/4Ko6fcvkncovYDAi3N199T1dfIKh3PCcXQHvF5kR0aV6cieV7Ga4MIiZrR
j2v7lujEEVrOfOqdI7BR1LRN4wM8sDIkfUoJHjkrQd6PiasdiTNmhyAz6pQw4nKq
x1hSkLEB9lGY7MkqFJa58YHmDLEawlHIsTqrW0R5Zq8PPHeWyJ54/FPectRRWUDx
7gnRjTMKAePeK3LDXAq4ofpJvZvbOywWEDHh4k3d0IMGZWIZb+f8wzCe/twWfS0a
ifuIWlNOG0JDRQfrAOOQ8P646qY6O708qXyhGpN/W1QbsSaSzrzvPDtvPgZrHqAq
VrcP+ftIFzMC5T2ZUmsKsEVTi3cKbw4hNLMYGlem3erKP7qazhsCAwEAAQKCAYAg
FZJjamGoYxRxgliAxNOQuD1yPXjy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AQUF
BzABhilodHRwOi8vdGVzdGNhLnB5dGhvbnRlc3QubmV0L3Rlc3RjYS9vY3NwLzBD
BgNVHR8EPDA6MDigNqA0hjJodHRwOi8vdGVzdGNhLnB5dGhvbnRlc3QubmV0L3Rl
c3RjYS9yZXZvY2F0aW9uLmNybDANBgkqhkiG9w0BAQsFAAOCAYEAJTTD+6HAN2lq
N1t4GCNkGJZT02eOpIu/z943zUzZTevlZ4XAEaSsWLzgnj6E+6EZqh0pTVIi5DQv
2Wj10zlJsE/Pq1geJoFGQizxgngK5ExxKLuQs0/fbyOr092LYV98CeokqNzoKErY
2hSbTfZZid9eD9GMzdRyw3i8RIgsqZlh5bHv3fOm3zJfJuhmHGHyckY92uxVUulW
t0MqBOlAI4kfzysD4GCLDbqp7/oyPeBHpEJOOLXHEWRbZTX1RhL2F+I7ueFS4aCj
cnKIdwv9i6R3b0rMEoCBEwhIZUbcFKXtwSLebmwKStuECxLkzUiCJ1VNI9RCHubc
7RQKDt+PENJ/GdOgprLfGGhvyn6W78qogS/cQU9SW004upBZEYyLAy+szXm4LaEw
qh89p63QPpyRwCE1L9Ae+Bxv0aMg11fnMEs1vcA/7xls9GyDKV8fQq/cwrn+O/2/
t9wEerwHtYzuF+9tSnuy1hwSyAdmivXC/TrISwQbtSkqDZG1eWoo
-----END CERTIFICATE-----

@kanavin
Copy link
Contributor

kanavin commented Sep 26, 2024

CC @kanavin

I cannot really test this since the script doesn't work for me at all (it produces an invalid OpenSSL command line before reaching the part I modified), but I ran the code I added/modified manually and it seems to work.

I confirmed via #107594 that this fixes the problem. But you do need the above mentioned change, and the NEWS.d entry.

@encukou
Copy link
Member

encukou commented Sep 26, 2024

@gpshead Do you still have the context for this in your head? :)

@felixfontein
Copy link
Contributor Author

Since the skip news label has been added, do I still have to add a NEWS.d entry?

@kanavin
Copy link
Contributor

kanavin commented Sep 26, 2024

Since the skip news label has been added, do I still have to add a NEWS.d entry?

I don't think so, the CI check for that now passes. But this does need to be backported to 3.13.

@encukou
Copy link
Member

encukou commented Sep 26, 2024

It's a a test-only change, so no NEWS entry is needed , and a backport can go in 3.13.1.

@encukou encukou added the needs backport to 3.13 bugs and security fixes label Sep 26, 2024
@@ -266,6 +283,10 @@ def write_cert_reference(path):
f.write(key)
f.write(cert)

cert = extract_cert(cert, 0)
Copy link
Member

Choose a reason for hiding this comment

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

Instead of text manipulation, could we ask openssl to extract it?
As far as I can see, the incantation is:

openssl x509 -outform pem -in keycert3.pem -out cert3.pem

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea! Implemented in 021af09.

@encukou encukou merged commit 480354d into python:main Oct 4, 2024
34 checks passed
@miss-islington-app
Copy link

Thanks @felixfontein for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @felixfontein and @encukou, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 480354dc236af9ae9d47b2520aa85fb7293c7b68 3.13

@felixfontein felixfontein deleted the cert3 branch October 4, 2024 12:24
felixfontein added a commit to felixfontein/cpython that referenced this pull request Oct 4, 2024
…3.pem (pythonGH-124598)

(cherry picked from commit 480354d)

Co-authored-by: Felix Fontein <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Oct 4, 2024

GH-124972 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Oct 4, 2024
encukou pushed a commit that referenced this pull request Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants