ó
Yé?_c           @   sZ   d  d l  m Z d  d l m Z d  d l m Z d  d l m Z d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t	   HSMSigner(   t   comma_separated_string(   t   logger(   t   hexdumpt   HSMOEMSignerc           B   s>   e  Z d  Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z RS(   s%   Class to enable signing via OEM's HSMc         C   s   t  S(   s0  Registers the class with the signer plugin manager. This allows
        the signer to be selected by the user from config/command line.

        Returns:
            is_plugin   (bool): True if the signer should be enabled,
                                False if the signer should be disabled.
        (   t   True(   t   cls(    (    sx   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/plugin/signer/hsm_oem.pyt	   is_plugin   s    	c         C   s   d S(   sÏ   Specifies the unique id of the signer. This is the id that the user
        will use to select the signer from config/command line.

        Returns:
            signer_id   (str): ID of the signer.
        t   hsm_oem(    (   R   (    (    sx   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/plugin/signer/hsm_oem.pyt	   signer_id   s    c   	      C   s“   t  j d t | j ƒ ƒ t  j d | j ƒ t  j d t | j d ƒ ƒ t  j d t | j ƒ ƒ d \ } } } } t
 d ƒ ‚ | | | | f S(	   s-  This API replaces sign_req and enables inspection of the data being signed.

        Args:
            signing_attrs              (object): An object containing the following signing attributes:
                                                 - key_size: Size of the key for attestation key
                                                 - exponent: Exponent for attestation key
            attest_cert_dict             (dict): Dictionary containing the parameters to be put in the attestation
                                                 certificate.
            image_hash                    (str): The image hash binary blob to be signed.
            data_to_hash        (StructDynamic): An object which encapsulates the format of the
                                                 authentication-relevant fields which were hashed to create
                                                 image_hash. The authentication-relevant fields available for
                                                 interrogation can be retrieved via the "fields" member.

        Returns:
            A tuple containing the root certificate, ca certificate, attestation
            certificate and the signature corresponding to the image hash.

            root_cert    (str): - Binary blob of the root certificate.
                                - None if root certificate is provided under:
                                    resources/data_prov_assets/Signing/Local
            ca_cert      (str): - Binary blob of the ca certificate.
                                - None if ca certificate is provided under:
                                    resources/data_prov_assets/Signing/Local
            attest_cert  (str): Binary blob of the attestation certificate.
            signature    (str): Binary blob of the signature.
        s   Data being signed:
s5   Format of authentication-relevant data being signed: s9   Authentication-relevant fields within data being signed: t   ands   SW ID of image being signed: s   OEM to implement hsm signerN(   NNNN(   R   t   infoR   t   binary_datat   formatR   t   fieldst   strt   sw_idt   Nonet   NotImplementedError(	   t   selft   signing_attrst   attest_cert_dictt
   image_hasht   data_to_hasht	   root_certt   ca_certt   attest_certt	   signature(    (    sx   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/plugin/signer/hsm_oem.pyt   sign_req_data'   s    	c         C   s.   d \ } } } } t d ƒ ‚ | | | | f S(   sL  Signs the image_hash, generates the attestation certificate using
        the attest_cert_dict and signing_attrs and optionally returns the
        root certificate and the ca certificate.

        Args:
            signing_attrs  (object): An object containing the following signing
                                     attributes:
                                         - key_size: Size of the key for
                                                     attestation key.
                                         - exponent: Exponent for attestation
                                                     key.
            attest_cert_dict (dict): Dictionary containing the parameters to be
                                     put in the attestation certificate.
            image_hash        (str): The image hash binary blob to be signed.

        Returns:
            A tuple containing the root certificate, ca certificate, attestation
            certificate and the signature corresponding to the image hash.

            root_cert    (str): - Binary blob of the root certificate.
                                - None if root certificate is provided under:
                                    resources/data_prov_assets/Signing/Local
            ca_cert      (str): - Binary blob of the ca certificate.
                                - None if ca certificate is provided under:
                                    resources/data_prov_assets/Signing/Local
            attest_cert  (str): Binary blob of the attestation certificate.
            signature    (str): Binary blob of the signature.
        s   OEM to implement hsm signerN(   NNNN(   R   R   (   R   R   R   R   R   R   R   R   (    (    sx   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/plugin/signer/hsm_oem.pyt   sign_reqS   s    (   t   __name__t
   __module__t   __doc__t   classmethodR   R	   R   R   (    (    (    sx   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/plugin/signer/hsm_oem.pyR      s
   
	,N(	   t   plugin.signerR    t   sectools.common.utils.c_dataR   t   sectools.common.utils.c_loggingR   t   sectools.common.utils.c_miscR   R   (    (    (    sx   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/plugin/signer/hsm_oem.pyt   <module>	   s   