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

python(feature): Allow using openssl certs with REST #181

Merged
merged 1 commit into from
Feb 27, 2025

Conversation

marcsiftstack
Copy link
Contributor

@marcsiftstack marcsiftstack commented Feb 27, 2025

This implementation is based on https://stackoverflow.com/a/77577017

Tested this by spinning up a local HTTP server with custom certs. I found instructions to create a custom cert for localhost and add it to openssl's CA store. Then I created an HTTPServer using the same cert:

import http.server
import ssl

server_address = ('localhost', 4443)
httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler)

context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
context.load_cert_chain(certfile="cert.pem", keyfile="key.pem")

httpd.socket = context.wrap_socket(httpd.socket, server_side=True)

print("Serving on https://localhost:4443")
httpd.serve_forever()

Used the following config with the CsvUploadService example:

    rest_config: SiftRestConfig = {
        "uri": "https://localhost:4443",
        "apikey": "ASDF",
        "cert_via_openssl": True,
    }

With cert_via_openssl set to False I get the following error:

requests.exceptions.SSLError: HTTPSConnectionPool(host='localhost', port=4443): Max retries exceeded with url: /api/v1/data-imports:upload (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate (_ssl.c:1018)')))

When set to True I get:

Exception: Config file upload request failed with status code 501. <!DOCTYPE HTML>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Error response</title>
    </head>
    <body>
        <h1>Error response</h1>
        <p>Error code: 501</p>
        <p>Message: Unsupported method ('POST').</p>
        <p>Error code explanation: 501 - Server does not support this operation.</p>
    </body>
</html>

and the following output from the HTTP server

127.0.0.1 - - [26/Feb/2025 22:56:45] code 501, message Unsupported method ('POST')
127.0.0.1 - - [26/Feb/2025 22:56:45] "POST /api/v1/data-imports:upload HTTP/1.1" 501 -

Which means there was a successful connection.

@marcsiftstack marcsiftstack force-pushed the openss-with-rest branch 3 times, most recently from b179a4e to e7e92d6 Compare February 27, 2025 07:04
@marcsiftstack marcsiftstack marked this pull request as ready for review February 27, 2025 18:29
@marcsiftstack marcsiftstack merged commit 2a18380 into main Feb 27, 2025
7 checks passed
@marcsiftstack marcsiftstack deleted the openss-with-rest branch February 27, 2025 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants