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

vdirsyncer 0.19: auth_cert broken #1033

Closed
Pikrass opened this issue Jan 17, 2023 · 6 comments · Fixed by #1037
Closed

vdirsyncer 0.19: auth_cert broken #1033

Pikrass opened this issue Jan 17, 2023 · 6 comments · Fixed by #1037

Comments

@Pikrass
Copy link

Pikrass commented Jan 17, 2023

So I was investigating why my calendar wasn't syncing anymore, with 401 responses. After seeing my client certificate wasn't being received on the server, I realized this was coming from vdirsyncer. A bit of digging and I found these lines in http.py:

    # TODO: Support for client-side certifications.
    #...
    kwargs.pop("cert", None)  # TODO XXX FIXME!

So, yeah. A line in the changelog would have saved me a bit of time. 🥲
Since I need this I'll see what I can do.

@Pikrass
Copy link
Author

Pikrass commented Jan 17, 2023

Looks like something like this works fine.

diff --git i/vdirsyncer/http.py w/vdirsyncer/http.py
index b35035b..2791433 100644
--- i/vdirsyncer/http.py
+++ w/vdirsyncer/http.py
@@ -127,7 +127,11 @@ async def request(
 
     assert isinstance(kwargs.get("data", b""), bytes)
 
-    kwargs.pop("cert", None)  # TODO XXX FIXME!
+    cert = kwargs.pop("cert", None)
+    if cert is not None:
+        ssl_context = create_default_context()
+        ssl_context.load_cert_chain(cert)
+        kwargs['ssl'] = ssl_context
 
     response = await session.request(method, url, **kwargs)
 

Needs a bit more work obviously (supporting list arg for auth_cert, tests), but it's late where I am.

@WhyNotHugo
Copy link
Member

Whoops, sorry, that TODO should not have shipped in that state. 😢

@WhyNotHugo WhyNotHugo pinned this issue Jan 17, 2023
@WhyNotHugo
Copy link
Member

I don't have a server set up with client certificates.

Do you have your own server? Is setting up a test user feasible?

@WhyNotHugo
Copy link
Member

Can you confirm if #1037 is sufficient to address this? I believe the previous call to prepare_client_cert in vdirsyncer/storage/dav.py should cover everything else.

Right now I don't have a test setup where I can log in with client certificates. If you have a public server where you can provide a test account, that would be super useful. I'm currently looking for hosted Dav servers to improve testing.

@tom-kuca
Copy link

tom-kuca commented Feb 5, 2023

I found two errors in the patch:

It breaks server certificate verification

A new blank SSL context is created. There might already be one with CA certifificate setup.

-ssl_context = create_default_context()
+ssl_context = kwargs.pop("ssl", create_default_context())
It doesn't support private key in a separate file.

From the documentation

auth_cert – Optional. Either a path to a certificate with a client certificate and the key or a list of paths to the files with them.

The list is converted to a tuple, load_cert_chain expects private key as a separate argument.

-ssl_context.load_cert_chain(cert)
+ssl_context.load_cert_chain(*cert) 

It works for both cases.

The complete snippet that works for me:

    cert = kwargs.pop("cert", None)
    if cert is not None:
        ssl_context = kwargs.pop("ssl", create_default_context())
        ssl_context.load_cert_chain(*cert)
        kwargs['ssl'] = ssl_context

Tested on version 0.19.1.dev28+gdf14865

WhyNotHugo added a commit that referenced this issue Feb 16, 2023
WhyNotHugo added a commit that referenced this issue Feb 27, 2023
@WhyNotHugo
Copy link
Member

Thanks for digging into this and sharing all the details!

WhyNotHugo added a commit that referenced this issue Feb 27, 2023
WhyNotHugo added a commit that referenced this issue Feb 28, 2023
@WhyNotHugo WhyNotHugo unpinned this issue Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants