(self, pem)
Reads data from PEM encoded certificate.

    This method take a PEM-encoded certificate and parses it with openssl x509.
    It adds attributes to the object from the parsed output. We feed the PEM
    data though openssl x509 once, with a given order of requested attributes,
    and then parse the output to retrieve the attributes.

    For issuer and subject, the output is "<attribute>= <value>", and we set the
    attribute to <value>.
    For issuer_cn and subject_cn, we get "<attribute>= /X=ZZ/CN=VALUE" and
    set <attribute>_cn VALUE. If the CN is not where we expect, don't set the
    attribute.
    For fingerprint, the output is "SHA1 Fingerprint=fi:ng:er:pr:in:tt", and we
    set fingerprint to "fi:ng:er:pr:in:tt" and osx_fingerprint to
    "fingerprintt".
    For startdate and enddate, we get "notAfter=Apr 29 18:09:17 2036 GMT" and
    make a list. Index 0 has the full date string, index 1 is a datetime object
    parsed from the string. If the string is in an unknown format, index 1 will
    be None.
    For hash, no parsing is needed as the output is just the hash.
    For email, we join up all the remaining lines of output and add them.

    Args:
      pem: str, PEM-encoded data

    Raises:
      CertError: unable to get certificate data
Reads data from PEM encoded certificate.
Reads data from PEM encoded certificate .
def _ParsePEMCertificate(self, pem):
    """Reads data from PEM encoded certificate.

    This method take a PEM-encoded certificate and parses it with openssl x509.
    It adds attributes to the object from the parsed output. We feed the PEM
    data though openssl x509 once, with a given order of requested attributes,
    and then parse the output to retrieve the attributes.

    For issuer and subject, the output is "<attribute>= <value>", and we set the
    attribute to <value>.
    For issuer_cn and subject_cn, we get "<attribute>= /X=ZZ/CN=VALUE" and
    set <attribute>_cn VALUE. If the CN is not where we expect, don't set the
    attribute.
    For fingerprint, the output is "SHA1 Fingerprint=fi:ng:er:pr:in:tt", and we
    set fingerprint to "fi:ng:er:pr:in:tt" and osx_fingerprint to
    "fingerprintt".
    For startdate and enddate, we get "notAfter=Apr 29 18:09:17 2036 GMT" and
    make a list. Index 0 has the full date string, index 1 is a datetime object
    parsed from the string. If the string is in an unknown format, index 1 will
    be None.
    For hash, no parsing is needed as the output is just the hash.
    For email, we join up all the remaining lines of output and add them.

    Args:
      pem: str, PEM-encoded data

    Raises:
      CertError: unable to get certificate data
    """
    command = [CMD_OPENSSL, 'x509', '-sha1', '-nameopt', 'compat', '-noout']
    attrs = ['hash', 'subject', 'issuer', 'startdate', 'enddate', 'fingerprint',
             'serial', 'email']

    for attr in attrs:
      command.extend(['-%s' % attr])
    (stdout, stderr, returncode) = gmacpyutil.RunProcess(command, pem)
    if returncode:
      raise CertError('Unable to retrieve data for certificates: %s' % stderr)
    output = stdout.splitlines()
    for index, attr in enumerate(attrs):
      if attr in ('issuer', 'subject'):
        name = output[index].split(' ', 1)[1]
        self.__dict__[attr] = name
        try:
          self.__dict__[''.join([attr, '_cn'])] = (
              name.split('/')[-1].split('=')[1])
        except IndexError:
          pass
      elif attr == 'fingerprint':
        self.__dict__['fingerprint'] = output[index].split('=', 1)[1]
        self.__dict__['osx_fingerprint'] = (
            re.sub(':', '', output[index].split('=', 1)[1]))
      elif attr in ('enddate', 'startdate'):
        datestring = output[index].split('=')[1]
        try:
          dateobject = datetime.datetime.strptime(datestring,
                                                  OPENSSL_DATETIME_FORMAT)
        except ValueError:
          dateobject = None
        self.__dict__[attr] = [datestring, dateobject]
      elif attr == 'hash':
        self.__dict__['certhash'] = output[index]
      elif attr == 'serial':
        self.__dict__[attr] = output[index].split('=')[1]
      elif attr == 'email':
        self.__dict__[attr] = ''.join(output[index:])
def _ParsePEMCertificate ( self , pem ) : command = [ CMD_OPENSSL , 'x509' , '-sha1' , '-nameopt' , 'compat' , '-noout' ] attrs = [ 'hash' , 'subject' , 'issuer' , 'startdate' , 'enddate' , 'fingerprint' , 'serial' , 'email' ] for attr in attrs : command . extend ( [ '-%s' % attr ] ) ( stdout , stderr , returncode ) = gmacpyutil . RunProcess ( command , pem ) if returncode : raise CertError ( 'Unable to retrieve data for certificates: %s' % stderr ) output = stdout . splitlines ( ) for index , attr in enumerate ( attrs ) : if attr in ( 'issuer' , 'subject' ) : name = output [ index ] . split ( ' ' , 1 ) [ 1 ] self . __dict__ [ attr ] = name try : self . __dict__ [ '' . join ( [ attr , '_cn' ] ) ] = ( name . split ( '/' ) [ - 1 ] . split ( '=' ) [ 1 ] ) except IndexError : pass elif attr == 'fingerprint' : self . __dict__ [ 'fingerprint' ] = output [ index ] . split ( '=' , 1 ) [ 1 ] self . __dict__ [ 'osx_fingerprint' ] = ( re . sub ( ':' , '' , output [ index ] . split ( '=' , 1 ) [ 1 ] ) ) elif attr in ( 'enddate' , 'startdate' ) : datestring = output [ index ] . split ( '=' ) [ 1 ] try : dateobject = datetime . datetime . strptime ( datestring , OPENSSL_DATETIME_FORMAT ) except ValueError : dateobject = None self . __dict__ [ attr ] = [ datestring , dateobject ] elif attr == 'hash' : self . __dict__ [ 'certhash' ] = output [ index ] elif attr == 'serial' : self . __dict__ [ attr ] = output [ index ] . split ( '=' ) [ 1 ] elif attr == 'email' : self . __dict__ [ attr ] = '' . join ( output [ index : ] )