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

Adds TLS to FRP tunnel #9218

Merged
merged 9 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
5 changes: 5 additions & 0 deletions .changeset/dirty-pugs-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": minor
---

feat:Adds TLS to FRP tunnel
9 changes: 7 additions & 2 deletions gradio/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
import os
import time
import warnings
from pathlib import Path

import httpx

from gradio.routes import App # HACK: to avoid circular import # noqa: F401
from gradio.tunneling import Tunnel
from gradio.tunneling import CERTIFICATE_PATH, Tunnel

GRADIO_API_SERVER = "https://api.gradio.app/v2/tunnel-request"
GRADIO_API_SERVER = "https://api.gradio.app/v3/tunnel-request"
GRADIO_SHARE_SERVER_ADDRESS = os.getenv("GRADIO_SHARE_SERVER_ADDRESS")


Expand All @@ -32,6 +33,10 @@ def setup_tunnel(
response = httpx.get(GRADIO_API_SERVER, timeout=30)
payload = response.json()[0]
remote_host, remote_port = payload["host"], int(payload["port"])
certificate = payload["root_ca"]
Path(CERTIFICATE_PATH).parent.mkdir(parents=True, exist_ok=True)
with open(CERTIFICATE_PATH, "w") as f:
f.write(certificate)
except Exception as e:
raise RuntimeError(
"Could not get share link from Gradio API Server."
Expand Down
31 changes: 24 additions & 7 deletions gradio/tunneling.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,37 @@

import httpx

VERSION = "0.2"
VERSION = "0.3"
CURRENT_TUNNELS: list["Tunnel"] = []

machine = platform.machine()
if machine == "x86_64":
machine = "amd64"
elif machine == "aarch64":
Copy link
Member Author

Choose a reason for hiding this comment

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

Unrelated fix that closes: #6053

machine = "arm64"

BINARY_REMOTE_NAME = f"frpc_{platform.system().lower()}_{machine.lower()}"
EXTENSION = ".exe" if os.name == "nt" else ""
BINARY_URL = f"https://cdn-media.huggingface.co/frpc-gradio-{VERSION}/{BINARY_REMOTE_NAME}{EXTENSION}"

CHECKSUMS = {
"https://cdn-media.huggingface.co/frpc-gradio-0.2/frpc_windows_amd64.exe": "cdd756e16622e0e60b697022d8da827a11fefe689325861c58c1003f2f8aa519",
"https://cdn-media.huggingface.co/frpc-gradio-0.2/frpc_linux_amd64": "fb74b665633589410540c49dfcef5b6f0fd4a9bd7c9558bcdee2f0e43da0774d",
"https://cdn-media.huggingface.co/frpc-gradio-0.2/frpc_linux_arm64": "af13b93897512079ead398224bd58bbaa136fcc5679af023780ee6c0538b3d82",
"https://cdn-media.huggingface.co/frpc-gradio-0.2/frpc_darwin_amd64": "6d3bd9f7e92e82fe557ba1d223bdd25317fbc296173a829601926526263c6092",
"https://cdn-media.huggingface.co/frpc-gradio-0.2/frpc_darwin_arm64": "0227ae6dafbe59d4e2c4a827d983ecc463eaa61f152216a3ec809c429c08eb31",
}
'https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_windows_amd64.exe': '14bc0ea470be5d67d79a07412bd21de8a0a179c6ac1116d7764f68e942dc9ceb',
Copy link
Member Author

Choose a reason for hiding this comment

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

I had missed some of the binary paths previously

'https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_amd64': 'c791d1f047b41ff5885772fc4bf20b797c6059bbd82abb9e31de15e55d6a57c4',
'https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_arm64': '823ced25104de6dc3c9f4798dbb43f20e681207279e6ab89c40e2176ccbf70cd',
'https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_darwin_amd64': '930f8face3365810ce16689da81b7d1941fda4466225a7bbcbced9a2916a6e15',
'https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_darwin_arm64': 'dfac50c690aca459ed5158fad8bfbe99f9282baf4166cf7c410a6673fbc1f327',
'https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_arm': '4b563beb2e36c448cc688174e20b53af38dc1ff2b5e362d4ddd1401f2affbfb7',
'https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_freebsd_386': 'cb0a56c764ecf96dd54ed601d240c564f060ee4e58202d65ffca17c1a51ce19c',
'https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_freebsd_amd64': '516d9e6903513869a011ddcd1ec206167ad1eb5dd6640d21057acc258edecbbb',
'https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_386': '4c2f2a48cd71571498c0ac8a4d42a055f22cb7f14b4b5a2b0d584220fd60a283',
'https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_mips': 'b309ecd594d4f0f7f33e556a80d4b67aef9319c00a8334648a618e56b23cb9e0',
'https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_mips64': '0372ef5505baa6f3b64c6295a86541b24b7b0dbe4ef28b344992e21f47624b7b',
'https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_riscv64': '1658eed7e8c14ea76e1d95749d58441ce24147c3d559381832c725c29cfc3df3',
'https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_mipsle': 'a2aaba16961d3372b79bd7a28976fcd0f0bbaebc2b50d5a7a71af2240747960f',
'https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_windows_386.exe': '721b90550195a83e15f2176d8f85a48d5a25822757cb872e9723d4bccc4e5bb6',
'https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_mips64le': '796481edd609f31962b45cc0ab4c9798d040205ae3bf354ed1b72fb432d796b8'
}

CHUNK_SIZE = 128

BINARY_FILENAME = f"{BINARY_REMOTE_NAME}_v{VERSION}"
Expand All @@ -42,6 +55,8 @@
"Please check the appended log from frpc for more information:"
)

CERTIFICATE_PATH = ".gradio/certificate.pem"


class Tunnel:
def __init__(self, remote_host, remote_port, local_host, local_port, share_token):
Expand Down Expand Up @@ -113,6 +128,8 @@ def _start_tunnel(self, binary: str) -> str:
"--server_addr",
f"{self.remote_host}:{self.remote_port}",
"--disable_log_color",
"--tls_enable" "--tls_trusted_ca_file",
CERTIFICATE_PATH,
]
self.proc = subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE
Expand Down
Loading