Skip to content

Commit

Permalink
Fix several bugs in the service data routines for verification
Browse files Browse the repository at this point in the history
Signed-off-by: Mic Bowman <[email protected]>
  • Loading branch information
cmickeyb authored and bvavala committed Mar 26, 2024
1 parent da18b88 commit b3bbd5f
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions python/pdo/service_client/service_data/service_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.

import atexit
import datetime
from functools import lru_cache
import json
import lmdb
Expand All @@ -27,6 +28,7 @@
from pdo.service_client.provisioning import ProvisioningServiceClient
from pdo.service_client.storage import StorageServiceClient
from pdo.common.utility import classproperty
from pdo.submitter.create import create_submitter

from urllib.parse import urlparse

Expand Down Expand Up @@ -64,14 +66,14 @@ def force_to_string(s) :
@classmethod
def unpack(cls, url, json_encoded_info) :
service_info = json.loads(json_encoded_info)
return cls(url, service_info['service_identity'], **service_info)
return cls(**service_info)

def __init__(self, service_type, url, identity, service_names=[]) :
def __init__(self, service_type, service_url, service_identity, service_names=[], last_verified_time=0) :
self.service_type = BaseInfo.force_to_string(service_type)
self.service_url = BaseInfo.force_to_string(url)
self.service_identity = BaseInfo.force_to_string(identity)
self.service_url = BaseInfo.force_to_string(service_url)
self.service_identity = BaseInfo.force_to_string(service_identity)
self.service_names = set(map(lambda n : BaseInfo.force_to_string(n), service_names))
self.last_verified_time = 0
self.last_verified_time = last_verified_time

def pack(self) :
return BaseInfo.force_to_bytes(json.dumps(self.serialize()))
Expand All @@ -98,7 +100,7 @@ def remove_service_name(self, service_name) :
self.service_names.discard(BaseInfo.force_to_string(service_name))

def clone(self) :
return type(self).unpack(self.serialize())
return type(self).unpack(self.service_url, self.pack())

# -----------------------------------------------------------------
# -----------------------------------------------------------------
Expand All @@ -125,8 +127,10 @@ def fetch_service_info(cls, url, service_names=[], service_identity=None) :

return new_info

def __init__(self, url, identity, **kwargs) :
super().__init__('eservice', url, identity, kwargs.get('service_names'))
def __init__(self, service_url, service_identity, **kwargs) :
service_names = kwargs.get('service_names', [])
last_verified_time = kwargs.get('last_verified_time', 0)
super().__init__('eservice', service_url, service_identity, service_names, last_verified_time)

self.verifying_key = BaseInfo.force_to_string(kwargs.get('verifying_key', ''))
self.encryption_key = BaseInfo.force_to_string(kwargs.get('encryption_key', ''))
Expand Down Expand Up @@ -176,7 +180,7 @@ def verify(self, ledger_config = None) :
if enclave_state['encryption_key'] != self.encryption_key :
return False

self.last_verified_time = int(round(datetime.datetime.new().timestamp()))
self.last_verified_time = int(round(datetime.datetime.now().timestamp()))
return True

# -----------------------------------------------------------------
Expand All @@ -196,8 +200,11 @@ def fetch_service_info(cls, url, service_names=[], service_identity=None) :

return new_info

def __init__(self, url, identity, **kwargs) :
super().__init__('pservice', url, identity, kwargs.get('service_names'))
def __init__(self, service_url, service_identity, **kwargs) :
service_names = kwargs.get('service_names', [])
last_verified_time = kwargs.get('last_verified_time', 0)
super().__init__('pservice', service_url, service_identity, service_names, last_verified_time)

self.verifying_key = BaseInfo.force_to_string(kwargs.get('verifying_key', ''))

def serialize(self) :
Expand All @@ -222,7 +229,7 @@ def verify(self, ledger_config = None) :
if client.verifying_key != self.verifying_key :
return False

self.last_verified_time = int(round(datetime.datetime.new().timestamp()))
self.last_verified_time = int(round(datetime.datetime.now().timestamp()))
return True

# -----------------------------------------------------------------
Expand All @@ -242,8 +249,11 @@ def fetch_service_info(cls, url, service_names=[], service_identity=None) :

return new_info

def __init__(self, url, identity, **kwargs) :
super().__init__('sservice', url, identity, kwargs.get('service_names'))
def __init__(self, service_url, service_identity, **kwargs) :
service_names = kwargs.get('service_names', [])
last_verified_time = kwargs.get('last_verified_time', 0)
super().__init__('sservice', service_url, service_identity, service_names, last_verified_time)

self.verifying_key = BaseInfo.force_to_string(kwargs.get('verifying_key', ''))
# will add information about duration etal when it is exported

Expand All @@ -269,7 +279,7 @@ def verify(self, ledger_config = None) :
if client.verifying_key != self.verifying_key :
return False

self.last_verified_time = int(round(datetime.datetime.new().timestamp()))
self.last_verified_time = int(round(datetime.datetime.now().timestamp()))
return True

## =================================================================
Expand Down Expand Up @@ -351,7 +361,9 @@ def update(self, old_service_info, new_service_info) :
transaction... so it either works completely or not at all
"""

service_db = self.service_db(service_info.service_type)
assert old_service_info.service_type == new_service_info.service_type

service_db = self.service_db(old_service_info.service_type)
identity_db = self.service_db_env.open_db(b'identity_index')
name_db = self.service_db_env.open_db(b'name_index')

Expand Down

0 comments on commit b3bbd5f

Please sign in to comment.