From e0b5913d9666cfc3578ba09c30cc7ef3ac0b5167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt?= Date: Tue, 7 Jan 2020 17:27:52 +0100 Subject: [PATCH] (#258) Fix generation of certif -> chg Time.time() to self.uid.int --- proxy/core/threadless.py | 8 ++++---- proxy/http/handler.py | 8 ++++---- proxy/http/proxy/plugin.py | 4 ++-- proxy/http/proxy/server.py | 4 ++-- proxy/http/server/plugin.py | 4 ++-- proxy/plugin/cache/store/base.py | 4 ++-- proxy/plugin/cache/store/disk.py | 5 +++-- 7 files changed, 19 insertions(+), 18 deletions(-) diff --git a/proxy/core/threadless.py b/proxy/core/threadless.py index d13f973aa8..87be7e5b86 100644 --- a/proxy/core/threadless.py +++ b/proxy/core/threadless.py @@ -9,7 +9,6 @@ :license: BSD, see LICENSE for more details. """ import os -import uuid import socket import logging import asyncio @@ -21,6 +20,7 @@ from abc import ABC, abstractmethod from typing import Dict, Optional, Tuple, List, Union, Generator, Any, Type +from uuid import uuid4, UUID from .connection import TcpClientConnection from .event import EventQueue, eventNames @@ -41,11 +41,11 @@ def __init__( client: TcpClientConnection, flags: Optional[Flags], event_queue: Optional[EventQueue] = None, - uid: Optional[str] = None) -> None: + uid: Optional[UUID] = None) -> None: self.client = client self.flags = flags if flags else Flags() self.event_queue = event_queue - self.uid: str = uid if uid is not None else uuid.uuid4().hex + self.uid: UUID = uid if uid is not None else uuid4() @abstractmethod def initialize(self) -> None: @@ -80,7 +80,7 @@ def publish_event( return assert self.event_queue self.event_queue.publish( - self.uid, + self.uid.hex, event_name, event_payload, publisher_id diff --git a/proxy/http/handler.py b/proxy/http/handler.py index a19a2b65d2..4570d296c3 100644 --- a/proxy/http/handler.py +++ b/proxy/http/handler.py @@ -17,7 +17,7 @@ import logging from abc import ABC, abstractmethod from typing import Tuple, List, Union, Optional, Generator, Dict - +from uuid import UUID from .parser import HttpParser, httpParserStates, httpParserTypes from .exception import HttpProtocolException @@ -54,12 +54,12 @@ class HttpProtocolHandlerPlugin(ABC): def __init__( self, - uid: str, + uid: UUID, flags: Flags, client: TcpClientConnection, request: HttpParser, event_queue: EventQueue): - self.uid: str = uid + self.uid: UUID = uid self.flags: Flags = flags self.client: TcpClientConnection = client self.request: HttpParser = request @@ -116,7 +116,7 @@ class HttpProtocolHandler(ThreadlessWork): def __init__(self, client: TcpClientConnection, flags: Optional[Flags] = None, event_queue: Optional[EventQueue] = None, - uid: Optional[str] = None): + uid: Optional[UUID] = None): super().__init__(client, flags, event_queue, uid) self.start_time: float = time.time() diff --git a/proxy/http/proxy/plugin.py b/proxy/http/proxy/plugin.py index 63fda08f8d..44129ed863 100644 --- a/proxy/http/proxy/plugin.py +++ b/proxy/http/proxy/plugin.py @@ -10,7 +10,7 @@ """ from abc import ABC, abstractmethod from typing import Optional - +from uuid import UUID from ..parser import HttpParser from ...common.flags import Flags @@ -26,7 +26,7 @@ class HttpProxyBasePlugin(ABC): def __init__( self, - uid: str, + uid: UUID, flags: Flags, client: TcpClientConnection, event_queue: EventQueue) -> None: diff --git a/proxy/http/proxy/server.py b/proxy/http/proxy/server.py index 229187cd0c..500aec471d 100644 --- a/proxy/http/proxy/server.py +++ b/proxy/http/proxy/server.py @@ -369,7 +369,7 @@ def generate_upstream_certificate( stderr=subprocess.PIPE) sign_cert = subprocess.Popen( ['openssl', 'x509', '-req', '-days', '365', '-CA', self.flags.ca_cert_file, '-CAkey', - self.flags.ca_key_file, '-set_serial', str(int(time.time())), '-out', cert_file_path], + self.flags.ca_key_file, '-set_serial', str(self.uid.int), '-out', cert_file_path], stdin=gen_cert.stdout, stderr=subprocess.PIPE) # TODO: Ensure sign_cert success. @@ -437,7 +437,7 @@ def emit_request_complete(self) -> None: assert self.request.path assert self.request.port self.event_queue.publish( - request_id=self.uid, + request_id=self.uid.hex, event_name=eventNames.REQUEST_COMPLETE, event_payload={ 'url': text_(self.request.path) diff --git a/proxy/http/server/plugin.py b/proxy/http/server/plugin.py index 64491a34ec..a1e17c1e6d 100644 --- a/proxy/http/server/plugin.py +++ b/proxy/http/server/plugin.py @@ -10,7 +10,7 @@ """ from abc import ABC, abstractmethod from typing import List, Tuple - +from uuid import UUID from ..websocket import WebsocketFrame from ..parser import HttpParser @@ -24,7 +24,7 @@ class HttpWebServerBasePlugin(ABC): def __init__( self, - uid: str, + uid: UUID, flags: Flags, client: TcpClientConnection, event_queue: EventQueue): diff --git a/proxy/plugin/cache/store/base.py b/proxy/plugin/cache/store/base.py index d15c5a6da3..eafeaa3c4a 100644 --- a/proxy/plugin/cache/store/base.py +++ b/proxy/plugin/cache/store/base.py @@ -10,13 +10,13 @@ """ from abc import ABC, abstractmethod from typing import Optional - +from uuid import UUID from ....http.parser import HttpParser class CacheStore(ABC): - def __init__(self, uid: str) -> None: + def __init__(self, uid: UUID) -> None: self.uid = uid @abstractmethod diff --git a/proxy/plugin/cache/store/disk.py b/proxy/plugin/cache/store/disk.py index cf108c61e0..91eb4f295b 100644 --- a/proxy/plugin/cache/store/disk.py +++ b/proxy/plugin/cache/store/disk.py @@ -11,6 +11,7 @@ import logging import os from typing import Optional, BinaryIO +from uuid import UUID from ....common.utils import text_ from ....http.parser import HttpParser @@ -22,7 +23,7 @@ class OnDiskCacheStore(CacheStore): - def __init__(self, uid: str, cache_dir: str) -> None: + def __init__(self, uid: UUID, cache_dir: str) -> None: super().__init__(uid) self.cache_dir = cache_dir self.cache_file_path: Optional[str] = None @@ -31,7 +32,7 @@ def __init__(self, uid: str, cache_dir: str) -> None: def open(self, request: HttpParser) -> None: self.cache_file_path = os.path.join( self.cache_dir, - '%s-%s.txt' % (text_(request.host), self.uid)) + '%s-%s.txt' % (text_(request.host), self.uid.hex)) self.cache_file = open(self.cache_file_path, "wb") def cache_request(self, request: HttpParser) -> Optional[HttpParser]: