Skip to content

Commit

Permalink
Mozilla ca (Chia-Network#1155)
Browse files Browse the repository at this point in the history
* include moz

* add mozzila submodule

* install script

* use file path

* update commit

* typo
  • Loading branch information
Yostra authored Mar 4, 2021
1 parent 85b0f7f commit da9b9cc
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
path = chia-blockchain-gui
url = https://github.com/Chia-Network/chia-blockchain-gui.git
branch = main
[submodule "mozilla-ca"]
path = mozilla-ca
url = https://github.com/Chia-Network/mozilla-ca.git
2 changes: 1 addition & 1 deletion build_scripts/daemon.spec
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ full_node = Analysis([f"{root}/src/server/start_full_node.py"],
wallet = Analysis([f"{root}/src/server/start_wallet.py"],
pathex=[f"{root}/venv/lib/python3.7/site-packages/aiter/", f"{root}"],
binaries = [],
datas=[(f"../src/ssl/dst_root_ca.pem", f"./src/ssl/"), (f"../src/ssl/chia_ca.key", f"./src/ssl/"), (f"../src/ssl/chia_ca.crt", f"./src/ssl/"), (f"../src/util/english.txt", f"./src/util/"), version_data ] + hex_puzzles,
datas=[(f"../mozilla-ca/cacert.pem", f"./mozilla-ca/"), (f"../src/ssl/dst_root_ca.pem", f"./src/ssl/"), (f"../src/ssl/chia_ca.key", f"./src/ssl/"), (f"../src/ssl/chia_ca.crt", f"./src/ssl/"), (f"../src/util/english.txt", f"./src/util/"), version_data ] + hex_puzzles,
hiddenimports=subcommand_modules,
hookspath=[],
runtime_hooks=[],
Expand Down
2 changes: 1 addition & 1 deletion build_scripts/daemon_windows.spec
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ full_node = Analysis([f"../src/server/start_full_node.py"],
wallet = Analysis([f"../src/server/start_wallet.py"],
pathex=[f"../venv/lib/python3.7/site-packages/aiter/", f"../"],
binaries = [],
datas=[(f"../src/ssl/dst_root_ca.pem", f"./src/ssl/"), (f"../src/ssl/chia_ca.key", f"./src/ssl/"), (f"../src/ssl/chia_ca.crt", f"./src/ssl/"), (f"../src/util/english.txt", f"./src/util/"), version_data ] + hex_puzzles,
datas=[(f"../mozilla-ca/cacert.pem", f"./mozilla-ca/"), (f"../src/ssl/dst_root_ca.pem", f"./src/ssl/"), (f"../src/ssl/chia_ca.key", f"./src/ssl/"), (f"../src/ssl/chia_ca.crt", f"./src/ssl/"), (f"../src/util/english.txt", f"./src/util/"), version_data ] + hex_puzzles,
hiddenimports=subcommand_modules,
hookspath=[],
runtime_hooks=[],
Expand Down
2 changes: 2 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ if [ "$(uname -m)" = "armv7l" ]; then
echo "Exiting."
exit 1
fi
# get submodules
git submodule update --init --recursive

UBUNTU_PRE_2004=false
if $UBUNTU; then
Expand Down
1 change: 1 addition & 0 deletions mozilla-ca
Submodule mozilla-ca added at 666cf7
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"src.wallet.util",
"src.wallet.trading",
"src.ssl",
"mozilla-ca",
],
entry_points={
"console_scripts": [
Expand All @@ -94,6 +95,7 @@
package_data={
"src.util": ["initial-*.yaml", "english.txt"],
"src.ssl": ["chia_ca.crt", "chia_ca.key", "dst_root_ca.pem"],
"mozilla-ca": ["cacert.pem"],
},
use_scm_version={"fallback_version": "unknown-no-.git-directory"},
long_description=open("README.md").read(),
Expand Down
6 changes: 3 additions & 3 deletions src/daemon/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from src.cmds.init import chia_init
from src.daemon.windows_signal import kill
from src.server.server import ssl_context_for_server, ssl_context_for_root
from src.ssl.create_ssl import get_dst_ca_crt
from src.ssl.create_ssl import get_mozzila_ca_crt
from src.util.setproctitle import setproctitle
from src.util.validate_alert import validate_alert
from src.util.ws_message import format_response, create_payload
Expand Down Expand Up @@ -49,8 +49,8 @@
async def fetch(url: str):
session = ClientSession()
try:
dst_root = get_dst_ca_crt()
ssl_context = ssl_context_for_root(dst_root.decode())
mozzila_root = get_mozzila_ca_crt()
ssl_context = ssl_context_for_root(mozzila_root)
response = await session.get(url, ssl=ssl_context)
await session.close()
return await response.text()
Expand Down
5 changes: 2 additions & 3 deletions src/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pathlib import Path
from secrets import token_bytes
from typing import Any, List, Dict, Callable, Optional, Set, Tuple

from aiohttp.web_app import Application
from aiohttp.web_runner import TCPSite
from aiohttp import web, ClientTimeout, client_exceptions, ClientSession, WSCloseCode
Expand Down Expand Up @@ -38,9 +37,9 @@ def ssl_context_for_server(


def ssl_context_for_root(
ca_cert: str,
ca_cert_file: str,
) -> Optional[ssl.SSLContext]:
ssl_context = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH, cadata=ca_cert)
ssl_context = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH, cafile=ca_cert_file)
return ssl_context


Expand Down
4 changes: 2 additions & 2 deletions src/ssl/create_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def get_chia_ca_crt_key() -> Tuple[Any, Any]:
return crt, key


def get_dst_ca_crt() -> bytes:
crt = pkg_resources.resource_string(__name__, "dst_root_ca.pem")
def get_mozzila_ca_crt() -> str:
crt = pkg_resources.resource_filename("mozilla-ca", "cacert.pem")
return crt


Expand Down
6 changes: 3 additions & 3 deletions src/wallet/util/backup_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from cryptography.fernet import Fernet

from src.server.server import ssl_context_for_root
from src.ssl.create_ssl import get_dst_ca_crt
from src.ssl.create_ssl import get_mozzila_ca_crt
from src.util.byte_types import hexstr_to_bytes
from src.util.hash import std_hash
from src.wallet.derive_keys import master_sk_to_backup_sk
Expand Down Expand Up @@ -72,8 +72,8 @@ def get_backup_info(file_path, private_key):


async def post(session: aiohttp.ClientSession, url: str, data: Any):
dst_root = get_dst_ca_crt()
ssl_context = ssl_context_for_root(dst_root.decode())
mozzila_root = get_mozzila_ca_crt()
ssl_context = ssl_context_for_root(mozzila_root)
response = await session.post(url, json=data, ssl=ssl_context)
return await response.json()

Expand Down

0 comments on commit da9b9cc

Please sign in to comment.