1313from common .allocation import Allocation
1414from common .block import Block
1515from common .encryption_key import EncryptionKey
16- from common .exceptions import EncryptorNotRegisteredForClientError
16+ from common .exceptions import (
17+ EncryptorNotRegisteredForClientError ,
18+ WrongMasterSAEIDError ,
19+ )
1720from common .logging import LOGGER
1821from common .pool import Pool
1922from common .share import Share
@@ -144,6 +147,8 @@ async def get_share_requested_by_client(
144147 self ,
145148 client_name : str ,
146149 key_id_str : str ,
150+ master_sae_id : str ,
151+ slave_sae_id : str ,
147152 raw_request : fastapi .Request ,
148153 headers_temp_response : fastapi .Response ,
149154 ) -> APIGetShareResponse :
@@ -168,6 +173,22 @@ async def get_share_requested_by_client(
168173 except KeyError as exc :
169174 LOGGER .warning (f"No share for key ID { key_id_str } " )
170175 raise exceptions .UnknownKeyIDError (key_id ) from exc
176+ # Check that master and slave SAE IDs in the Get key with key IDs request match those in the
177+ # original Get key request.
178+ if master_sae_id != share .master_sae_id :
179+ LOGGER .warning (
180+ f"Requested master SAE ID { master_sae_id } does not match stored master SAE ID "
181+ f"{ share .master_sae_id } for key ID { key_id_str } "
182+ )
183+ raise exceptions .WrongMasterSAEIDError (
184+ client_name , master_sae_id , key_id_str
185+ )
186+ if slave_sae_id != share .slave_sae_id :
187+ LOGGER .warning (
188+ f"Requested slave SAE ID { slave_sae_id } does not match stored slave SAE ID "
189+ f"{ share .slave_sae_id } for key ID { key_id_str } "
190+ )
191+ raise WrongMasterSAEIDError (client_name , slave_sae_id , key_id_str )
171192 # Encrypt the share value
172193 encryption_key = EncryptionKey .from_pool (peer_client .local_pool , share .size )
173194 encrypted_share_value = encryption_key .encrypt (share .value )
0 commit comments