File: //usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/cryptutil.pyo
�
d�bc @ s� d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z m Z d d l m
Z
d d l j j
Z
d d l j j j Z d Z d e f d � � YZ d S( i����N( t ustrt
bytebuffer( t
CryptErrors6 {0} cms -decrypt -inform DER -inkey {1} -in /dev/stdint CryptUtilc B sk e Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z
d � Z d
� Z RS( c C s
| | _ d S( N( t openssl_cmd( t selfR ( ( sJ /usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/cryptutil.pyt __init__% s c C s� | j d d d d d d d d d d
| d | g } y t j | � WnA t j k
r� } d j | | | j | j � } t j | � n Xd
S( sV
Create ssl certificate for https communication with endpoint server.
t reqs -x509s -nodess -subjs /CN=LinuxTransports -dayst 730s -newkeys rsa:2048s -keyouts -outsF Failed to create {0} and {1} certificates.
[stdout]
{2}
[stderr]
{3}
N( R t shellutilt run_commandt CommandErrort formatt stdoutt stderrt loggert error( R t prv_filet crt_filet cmdt cmd_errt msg( ( sJ /usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/cryptutil.pyt gen_transport_cert( s c C s_ t j j | � s* t t j d | � � n1 | j d d | d g } t j | d t �} | Sd S( Ns File not foundt rsas -ins -puboutt log_error(
t ost patht existst IOErrort errnot ENOENTR R R
t True( R t file_nameR t pub( ( sJ /usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/cryptutil.pyt get_pubkey_from_prv5 s
c C sb t j j | � s* t t j d | � � n4 | j d d | d d g } t j | d t �} | Sd S( Ns File not foundt x509s -ins -pubkeys -nooutR (
R R R R R R R R R
R ( R R R R! ( ( sJ /usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/cryptutil.pyt get_pubkey_from_crt= s
c C s� t j j | � s* t t j d | � � nY | j d d | d d g } t j | � } | j � j
d � d j d d � j � } | Sd S(
Ns File not foundR# s -ins -fingerprints -nooutt =i t :t (
R R R R R R R R R
t rstript splitt replacet upper( R R R t
thumbprint( ( sJ /usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/cryptutil.pyt get_thumbprint_from_crtE s +c
C s� t j j | � s* t t j d | � � n� t j j | � sT t t j d | � � n� yM t j | j d d d | d | d | g | j d d d d
d | g g � Wn8 t j k
r� } t
j d | | j | j
| j � n Xd S(
Ns File not foundt cmss -decrypts -ins -inkeys -recipt pkcs12s -nodess -passwords pass:s -outsB Failed to decrypt {0} (return code: {1})
[stdout]
{2}
[stderr]
{3}( R R R R R R R t run_pipeR R R R t
returncodeR
R ( R t p7m_filet trans_prv_filet trans_cert_filet pem_filet
command_error( ( sJ /usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/cryptutil.pyt decrypt_p7mN s !& c
C sh t | d � �S } d d d d d | g } y t j | d | d t �Wn t j k
r] n XWd QXd S( Nt abs
ssh-keygens -is -mt PKCS8s -fR
R ( t openR R
R R ( R t
input_filet output_filet file_outR ( ( sJ /usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/cryptutil.pyt
crt_to_ssh\ s c C s� | j d � } g | D] } | j d � s | ^ q } d j | � } yYd d l m } t j | � } | j | � d d } | j | j | � � d } | d } | d } t � }
|
j
t j d t
d � � � |
j
d � |
j
t j d t
| j | � � � � |
j
| j | � � |
j
t j d t
| j | � � d � � |
j
d
� |
j
| j | � � t j t |
� � } t d | d d d
�SWn t k
r�} t d � � n Xd S( Ns
s ----R'