Example #1
0
 def test_rsa_keys(self):
   for key, cert in KEY_FILE_PAIRS:
     rsa_dict = self.dicts[key]
     rsa_t = rsa_pem.dict_to_tuple(rsa_dict)
     rsa_key = RSA.construct(rsa_t)
     self.assertTrue(rsa_key)
     self.assertEqual(rsa_key.e, 65537)
Example #2
0
 def test_rsa_keys(self):
   for key, cert in KEY_FILE_PAIRS:
     rsa_dict = self.dicts[key]
     rsa_t = rsa_pem.dict_to_tuple(rsa_dict)
     rsa_key = RSA.construct(rsa_t)
     self.assertTrue(rsa_key)
     self.assertEqual(rsa_key.e, 65537)
Example #3
0
  def setUp(self):
    self.keys = {}

    for key, cert in KEY_FILE_PAIRS:
      with open(key, "r") as f:
        data = f.read()
        dict = rsa_pem.parse(data)
        t = rsa_pem.dict_to_tuple(dict)
        self.keys[key] = RSA.construct(t)
      with open(cert, "r") as f:
        data = f.read()
        dict = x509_pem.parse(data)
        t = x509_pem.dict_to_tuple(dict)
        self.keys[cert] = RSA.construct(t)
Example #4
0
  def setUp(self):
    self.keys = {}

    for key, cert in KEY_FILE_PAIRS:
      with open(key, "r") as f:
        data = f.read()
        dict = rsa_pem.parse(data)
        t = rsa_pem.dict_to_tuple(dict)
        self.keys[key] = RSA.construct(t)
      with open(cert, "r") as f:
        data = f.read()
        dict = x509_pem.parse(data)
        t = x509_pem.dict_to_tuple(dict)
        self.keys[cert] = RSA.construct(t)
Example #5
0
def get_key(parse_dict):
  """Return RSA object from parsed PEM key file dictionary.

  Args:
    parse_dict: {str:str} as returned by `parse`
  Returns:
    `RSAKey` RSA key object as specified by `parse_dict`
  """
  if parse_dict['type'] == "RSA PRIVATE":
    key_tuple = rsa_pem.dict_to_tuple(parse_dict)
  elif parse_dict['type'] == "X509 CERTIFICATE":
    key_tuple = x509_pem.dict_to_tuple(parse_dict)
  else:
    raise Exception("parse_dict type '%s' not supported." % parse_dict['type'])
  key = RSA.construct(key_tuple)
  return key
Example #6
0
def get_key(parse_dict):
    """Return RSA object from parsed PEM key file dictionary.

  Args:
    parse_dict: {str:str} as returned by `parse`
  Returns:
    `RSAKey` RSA key object as specified by `parse_dict`
  """
    if parse_dict['type'] == "RSA PRIVATE":
        key_tuple = rsa_pem.dict_to_tuple(parse_dict)
    elif parse_dict['type'] == "X509 CERTIFICATE":
        key_tuple = x509_pem.dict_to_tuple(parse_dict)
    else:
        raise Exception("parse_dict type '%s' not supported." %
                        parse_dict['type'])
    key = RSA.construct(key_tuple)
    return key
Example #7
0
 def test_rsa_tuple_generation(self):
   for key, cert in KEY_FILE_PAIRS:
     rsa_dict = self.dicts[key]
     t = rsa_pem.dict_to_tuple(rsa_dict)
     self.assertTrue(t)
     self.assertEqual(len(t), 6)
Example #8
0
 def test_rsa_tuple_generation(self):
   for key, cert in KEY_FILE_PAIRS:
     rsa_dict = self.dicts[key]
     t = rsa_pem.dict_to_tuple(rsa_dict)
     self.assertTrue(t)
     self.assertEqual(len(t), 6)