Пример #1
0
    def _LoadKey(self, keystr):
        """Load a key and return a key object.

    Args:
      keystr: str, key in PEM format
    Returns:
      tlslite.utils.RSAKey instance
    Raises:
      ValueError: keystr is improperly formed
    """
        try:
            key = tlslite_bridge.parsePEMKey(keystr)
        except (SyntaxError, AttributeError), e:
            raise ValueError('invalid PEM key format: %s' % str(e))
Пример #2
0
  def _LoadKey(self, keystr):
    """Load a key and return a key object.

    Args:
      keystr: str, key in PEM format
    Returns:
      tlslite.utils.RSAKey instance
    Raises:
      ValueError: keystr is improperly formed
    """
    try:
      key = tlslite_bridge.parsePEMKey(keystr)
    except (SyntaxError, AttributeError), e:
      raise ValueError('invalid PEM key format: %s' % str(e))
Пример #3
0
def LoadRSAPrivateKeyFromPEM(s):
  """Load a RSA Private key from PEM format.

  Args:
    s: str, key in PEM format, including newlines
  Returns:
    X509Certificate object
  Raises:
    PEMFormatError: general format error.
    HeaderMissingPEMFormatError: header is missing.
    FooterMissingPEMFormatError: footer is missing.
    RSAPrivateKeyPEMFormatError: the RSA priv key cannot be loaded.
  """
  lines = LoadPemGeneric(s, 'BEGIN RSA PRIVATE KEY', 'END RSA PRIVATE KEY')
  # tlslite expects to see the header too.
  pem_rsa_key = '\n'.join(lines)
  try:
    return tlslite_bridge.parsePEMKey(pem_rsa_key)
  except SyntaxError, e:
    raise RSAPrivateKeyPEMFormatError(str(e))
Пример #4
0
def LoadRSAPrivateKeyFromPEM(s):
  """Load a RSA Private key from PEM format.

  Args:
    s: str, key in PEM format, including newlines
  Returns:
    X509Certificate object
  Raises:
    PEMFormatError: general format error.
    HeaderMissingPEMFormatError: header is missing.
    FooterMissingPEMFormatError: footer is missing.
    RSAPrivateKeyPEMFormatError: the RSA priv key cannot be loaded.
  """
  lines = LoadPemGeneric(s, 'BEGIN RSA PRIVATE KEY', 'END RSA PRIVATE KEY')
  # tlslite expects to see the header too.
  pem_rsa_key = '\n'.join(lines)
  try:
    return tlslite_bridge.parsePEMKey(pem_rsa_key)
  except SyntaxError, e:
    raise RSAPrivateKeyPEMFormatError(str(e))