#NEWLINE# def get_hash( name , password = None ) : #NEWLINE# #INDENT# "\n    Returns the hash of a certificate in the keychain.\n\n    name\n        The name of the certificate (which you can get from keychain.get_friendly_name) or the\n        location of a p12 file.\n\n    password\n        The password that is used in the certificate. Only required if your passing a p12 file.\n        Note: This will be outputted to logs\n\n    CLI Example:\n\n    .. code-block:: bash\n\n        salt '*' keychain.get_hash /tmp/test.p12 test123\n    " #NEWLINE# if ( '.p12' in name [ ( - 4 ) : ] ) : #NEWLINE# #INDENT# cmd = 'openssl pkcs12 -in {0} -passin pass:{1} -passout pass:{1}' . format ( name , password ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cmd = 'security find-certificate -c "{0}" -m -p' . format ( name ) #NEWLINE# #UNINDENT# out = __salt__ [ 'cmd.run' ] ( cmd ) #NEWLINE# matches = re . search ( '-----BEGIN CERTIFICATE-----(.*)-----END CERTIFICATE-----' , matches , ( re . DOTALL | re . MULTILINE ) ) #NEWLINE# if matches : #NEWLINE# #INDENT# return matches . group ( 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return False