Commit 3d7929b0 authored by guillecxb's avatar guillecxb
Browse files

negotiate suppFeat

parent a6dac599
Loading
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -12,7 +12,18 @@ from .redis_internal_event import RedisInternalEvent
from .resources import Resource
from .responses import internal_server_error, not_found_error, forbidden_error, make_response, bad_request_error
from ..core.sign_certificate import sign_certificate
from ..util import dict_to_camel_case, clean_empty, serialize_clean_camel_case, negotiate_supported_features
from ..util import dict_to_camel_case, clean_empty, serialize_clean_camel_case


TOTAL_FEATURES = 2
SUPPORTED_FEATURES_HEX = "1"

def negotiate_supported_features(supp_feat):
    final_supp_feat = bin(int(supp_feat, 16) & int(SUPPORTED_FEATURES_HEX, 16))[2:].zfill(TOTAL_FEATURES)[::-1]
    return {
        "PatchUpdate": True if final_supp_feat[0] == "1" else False,
        "RNAA": True if final_supp_feat[1] == "1" else False,
    }


class ProviderManagementOperations(Resource):
@@ -50,6 +61,12 @@ class ProviderManagementOperations(Resource):
            api_provider_enrolment_details.api_prov_dom_id = secrets.token_hex(
                15)
            
            # Suppoerted Features Negotiation
            client_feat = api_provider_enrolment_details.supp_feat
            negotiated = negotiate_supported_features(client_feat)
            api_provider_enrolment_details.supp_feat = negotiated
            current_app.logger.debug(f"Negotiated supported features: {negotiated}")

            current_app.logger.debug("Generating certs to api prov funcs")

            for api_provider_func in api_provider_enrolment_details.api_prov_funcs:
+0 −14
Original line number Diff line number Diff line
@@ -192,17 +192,3 @@ def _deserialize_dict(data, boxed_type):
    """
    return {k: _deserialize(v, boxed_type)
            for k, v in data.items() }

TOTAL_FEATURES = 18
SUPPORTED_FEATURES_HEX = "201"

def negotiate_supported_features(client_hex: str) -> str:
    client_bin = bin(int(client_hex or "0", 16))[2:].zfill(TOTAL_FEATURES)[::-1]
    server_bin = bin(int(SUPPORTED_FEATURES_HEX, 16))[2:].zfill(TOTAL_FEATURES)[::-1]

    negotiated_bin = ''.join([
        '1' if client_bin[i] == '1' and server_bin[i] == '1' else '0'
        for i in range(TOTAL_FEATURES)
    ])[::-1]

    return hex(int(negotiated_bin, 2))[2:] or "0"
 No newline at end of file