Skip to content

Commit

Permalink
Merge branch 'master' into feature/SK-558
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhellander committed Nov 21, 2023
2 parents 2bd9276 + 36cf7f7 commit ceeab9d
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Base image
ARG BASE_IMG=python:3.9-slim
ARG BASE_IMG=python:3.10-slim
FROM $BASE_IMG

# Requirements (use MNIST Keras as default)
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ services:
build:
context: .
args:
BASE_IMG: ${BASE_IMG:-python:3.9-slim}
BASE_IMG: ${BASE_IMG:-python:3.10-slim}
working_dir: /app
volumes:
- ${HOST_REPO_DIR:-.}/fedn:/app/fedn
Expand All @@ -89,7 +89,7 @@ services:
build:
context: .
args:
BASE_IMG: ${BASE_IMG:-python:3.9-slim}
BASE_IMG: ${BASE_IMG:-python:3.10-slim}
working_dir: /app
volumes:
- ${HOST_REPO_DIR:-.}/fedn:/app/fedn
Expand All @@ -110,7 +110,7 @@ services:
build:
context: .
args:
BASE_IMG: ${BASE_IMG:-python:3.9-slim}
BASE_IMG: ${BASE_IMG:-python:3.10-slim}
working_dir: /app
volumes:
- ${HOST_REPO_DIR:-.}/fedn:/app/fedn
Expand All @@ -127,7 +127,7 @@ services:
build:
context: .
args:
BASE_IMG: ${BASE_IMG:-python:3.9-slim}
BASE_IMG: ${BASE_IMG:-python:3.10-slim}
working_dir: /app
volumes:
- ${HOST_REPO_DIR:-.}/fedn:/app/fedn
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
author = 'Scaleout Systems AB'

# The full version, including alpha/beta/rc tags
release = '0.4.1'
release = '0.6.0'

# Add any Sphinx extension module names here, as strings
extensions = [
Expand Down
5 changes: 0 additions & 5 deletions fedn/fedn/network/api/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import uuid

import requests

__all__ = ['APIClient']
Expand Down Expand Up @@ -137,9 +135,6 @@ def start_session(self, session_id=None, round_timeout=180, rounds=5, round_buff
:return: A dict with success or failure message and session config.
:rtype: dict
"""
# If session id is None, generate a random session id.
if session_id is None:
session_id = str(uuid.uuid4())
response = requests.post(self._get_url('start_session'), json={
'session_id': session_id,
'round_timeout': round_timeout,
Expand Down
3 changes: 2 additions & 1 deletion fedn/fedn/network/api/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import copy
import os
import threading
import uuid
from io import BytesIO

from flask import jsonify, send_from_directory
Expand Down Expand Up @@ -863,7 +864,7 @@ def start_session(

# Setup session config
session_config = {
"session_id": session_id,
"session_id": session_id if session_id else str(uuid.uuid4()),
"round_timeout": round_timeout,
"buffer_size": round_buffer_size,
"model_id": model_id,
Expand Down
20 changes: 18 additions & 2 deletions fedn/fedn/network/clients/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import queue
import re
import ssl
import socket
import sys
import tempfile
import threading
Expand All @@ -15,7 +15,9 @@
from io import BytesIO

import grpc
from cryptography.hazmat.primitives.serialization import Encoding
from google.protobuf.json_format import MessageToJson
from OpenSSL import SSL

import fedn.common.net.grpc.fedn_pb2 as fedn
import fedn.common.net.grpc.fedn_pb2_grpc as rpc
Expand Down Expand Up @@ -149,6 +151,20 @@ def _add_grpc_metadata(self, key, value):
# Set metadata using tuple concatenation
self.metadata += ((key, value),)

def _get_ssl_certificate(self, domain, port=443):
context = SSL.Context(SSL.SSLv23_METHOD)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((domain, port))
ssl_sock = SSL.Connection(context, sock)
ssl_sock.set_tlsext_host_name(domain.encode())
ssl_sock.set_connect_state()
ssl_sock.do_handshake()
cert = ssl_sock.get_peer_certificate()
ssl_sock.close()
sock.close()
cert = cert.to_cryptography().public_bytes(Encoding.PEM).decode()
return cert

def _connect(self, client_config):
"""Connect to assigned combiner.
Expand Down Expand Up @@ -186,7 +202,7 @@ def _connect(self, client_config):
elif self.config['secure']:
secure = True
logger.info("Using CA certificate for GRPC channel.")
cert = ssl.get_server_certificate((host, port))
cert = self._get_ssl_certificate(host, port=port)

credentials = grpc.ssl_channel_credentials(cert.encode('utf-8'))
if self.config['token']:
Expand Down
2 changes: 1 addition & 1 deletion fedn/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='fedn',
version='0.5.0',
version='0.6.0',
description="""Scaleout Federated Learning""",
author='Scaleout Systems AB',
author_email='[email protected]',
Expand Down

0 comments on commit ceeab9d

Please sign in to comment.