@@ -366,34 +366,6 @@ def serialize_exception_to_s3(
366366 )
367367
368368
369- def _upload_payload_and_metadata_to_s3 (
370- bytes_to_upload : Union [bytes , io .BytesIO ],
371- hmac_key : str ,
372- s3_uri : str ,
373- sagemaker_session : Session ,
374- s3_kms_key ,
375- ):
376- """Uploads serialized payload and metadata to s3.
377-
378- Args:
379- bytes_to_upload (bytes): Serialized bytes to upload.
380- hmac_key (str): Key used to calculate hmac-sha256 hash of the serialized obj.
381- s3_uri (str): S3 root uri to which resulting serialized artifacts will be uploaded.
382- sagemaker_session (sagemaker.core.helper.session.Session):
383- The underlying Boto3 session which AWS service calls are delegated to.
384- s3_kms_key (str): KMS key used to encrypt artifacts uploaded to S3.
385- """
386- _upload_bytes_to_s3 (bytes_to_upload , f"{ s3_uri } /payload.pkl" , s3_kms_key , sagemaker_session )
387-
388- sha256_hash = _compute_hash (bytes_to_upload , secret_key = hmac_key )
389-
390- _upload_bytes_to_s3 (
391- _MetaData (sha256_hash ).to_json (),
392- f"{ s3_uri } /metadata.json" ,
393- s3_kms_key ,
394- sagemaker_session ,
395- )
396-
397369def _upload_payload_and_metadata_to_s3_signed (
398370 bytes_to_upload : Union [bytes , io .BytesIO ],
399371 private_key : ec .EllipticCurvePrivateKey ,
@@ -561,22 +533,3 @@ def _verify_sha256_hash(expected_hash: str, buffer: bytes):
561533 "Integrity check for the serialized function or data failed. "
562534 "Please restrict access to your S3 bucket"
563535 )
564-
565-
566- def _compute_hash (buffer : bytes , secret_key : str ) -> str :
567- """Compute the hmac-sha256 hash"""
568- return hmac .new (secret_key .encode (), msg = buffer , digestmod = hashlib .sha256 ).hexdigest ()
569-
570-
571- def _perform_integrity_check (expected_hash_value : str , secret_key : str , buffer : bytes ):
572- """Performs integrity checks for serialized code/arguments uploaded to s3.
573-
574- Verifies whether the hash read from s3 matches the hash calculated
575- during remote function execution.
576- """
577- actual_hash_value = _compute_hash (buffer = buffer , secret_key = secret_key )
578- if not hmac .compare_digest (expected_hash_value , actual_hash_value ):
579- raise DeserializationError (
580- "Integrity check for the serialized function or data failed. "
581- "Please restrict access to your S3 bucket"
582- )
0 commit comments