Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions payjoin-ffi/python/src/payjoin/http.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import ssl
from urllib.parse import urljoin

import httpx

from .payjoin import OhttpKeys


async def fetch_ohttp_keys(
ohttp_relay_url: str,
directory_url: str,
certificate: bytes,
) -> OhttpKeys:
keys_url = urljoin(directory_url, "/.well-known/ohttp-gateway")
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ssl_context.check_hostname = True
ssl_context.verify_mode = ssl.CERT_REQUIRED
pem_certificate = ssl.DER_cert_to_PEM_cert(certificate)
ssl_context.load_verify_locations(cadata=pem_certificate)
async with httpx.AsyncClient(
proxy=ohttp_relay_url, verify=ssl_context, timeout=30.0
) as client:
response = await client.get(
keys_url,
headers={"Accept": "application/ohttp-keys"},
)
response.raise_for_status()
return OhttpKeys.decode(response.content)
6 changes: 4 additions & 2 deletions payjoin-ffi/python/test/test_payjoin_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json

from payjoin import *
from payjoin.http import fetch_ohttp_keys
from typing import Optional
import unittest

Expand Down Expand Up @@ -98,7 +99,8 @@ async def test_ffi_validation(self):
services = TestServices.initialize()
services.wait_for_services_ready()
directory = services.directory_url()
ohttp_keys = services.fetch_ohttp_keys()
ohttp_relay = services.ohttp_relay_url()
ohttp_keys = await fetch_ohttp_keys(ohttp_relay, directory, services.cert())
recv_persister = InMemoryReceiverSessionEventLog(999)
pj_uri = self.create_receiver_context(
receiver_address, directory, ohttp_keys, recv_persister
Expand Down Expand Up @@ -261,8 +263,8 @@ async def test_integration_v2_to_v2(self):

services.wait_for_services_ready()
directory = services.directory_url()
ohttp_keys = services.fetch_ohttp_keys()
ohttp_relay = services.ohttp_relay_url()
ohttp_keys = await fetch_ohttp_keys(ohttp_relay, directory, services.cert())
agent = httpx.AsyncClient()

# **********************
Expand Down
Loading