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rdASr8KCl1mrLflHZKFkPQFquQaUCgYB2fc431vBL2mPk1KMw/wuT JYK+HqiP73piOZCqvPE1kZegKkT3ZY2dcH5HWA2gdQ6fPGyUffnja4vTe0lSzbsN la6IKeRMgObDQzPTKpWzDQZiHzGy/T5a7NXPeUvo5wnAU4c0zjHOp6nTXlB+s+6h lJjW+NFsouaq0UBDGqW3SQKBgEYRTWuHrvVYrGSGC5iHWQNsrOTHY//iS8HN+J5Z WHESnzoZW6xu7yn5AxjHTdaNCaC2xXkg4oKn9D2CvrPm4DPVzcjCKg2U3+TzZkUv Nrok6+jo74VshWEJUTvM/PVu52QMiwmGpcHEoM0jceQJmE5abdkqI2A+mdCL/a9o sw9dAoGAPxzIiKU606m7m8GKr3IuRjMPqwP7qC9HOdc+NXIyJqnK+nvwReCAIOEL pzqLRw7mjUfdCJ5Gdx0TPYl8ckRKQAwuSWm4a8XaUCP73NCIe6e3lVn/29wsVtTI 2XQsAKrvBHQ9834wJ6XEn4j6LnUxbLIiSdV8wJqOhjRxEZKwu4w= -----END RSA PRIVATE KEY----- """ key = Key(keyString) self.assertFalse(key.bogus())
def verify_valid_entitlement(self): """ Verify that a valid entitlement was processed. @return: True if valid, False otherwise. """ ent_cert = EntitlementCertificate(self.get_cert_content()) ent_key = Key(self.get_key_content()) if ent_cert.bogus() or ent_key.bogus(): return False return True
def _check_key(self, cert): """ If the new key file (SERIAL-key.pem) does not exist, check for the old style (key.pem), and if found write it out as the new style. Return false if neither is found, indicating we have no key for this certificate. See bz #711133. """ key_path = "%s/%s-key.pem" % (self.path, cert.serialNumber()) if not os.access(key_path, os.R_OK): # read key from old key path old_key_path = "%s/key.pem" % self.path # if we don't have a new style or old style key, consider the # cert invalid if not os.access(old_key_path, os.R_OK): return False # write the key/cert out again in new style format key = Key.read(old_key_path) cert_writer = Writer() cert_writer.write(key, cert) return True
def _check_key(self, cert): """ If the new key file (SERIAL-key.pem) does not exist, check for the old style (key.pem), and if found write it out as the new style. Return false if neither is found, indicating we have no key for this certificate. See bz #711133. """ key_path = cert.key_path() if not os.access(key_path, os.R_OK): # read key from old key path old_key_path = "%s/key.pem" % self.path # if we don't have a new style or old style key, consider the # cert invalid if not os.access(old_key_path, os.R_OK): return False # write the key/cert out again in new style format key = Key.read(old_key_path) cert_writer = Writer(self) cert_writer.write(key, cert) return True
def build(self, bundle): keypem = bundle['key'] crtpem = bundle['cert'] key = Key(keypem) cert = create_from_pem(crtpem) return (key, cert)
def verify_valid_entitlement(self): """ Verify that a valid entitlement was processed. @return: True if valid, False otherwise. """ try: cert = self.get_cert() # Don't want to check class explicitly, instead we'll look for # order info, which only an entitlement cert could have: if not hasattr(cert, 'order'): return False except CertificateException: return False ent_key = Key(self.get_key_content()) if ent_key.bogus(): return False return True
def build_cert(self, bundle): """Split a cert bundle into a EntitlementCertificate and a Key.""" keypem = bundle['key'] crtpem = bundle['cert'] key = Key(keypem) cert = create_from_pem(crtpem) return (key, cert)
def test_garbage_key(self): keyString = "Some Garbage Data" key = Key(keyString) self.assertTrue(key.bogus())
def test_empty_key(self): keyString = "" key = Key(keyString) self.assertTrue(key.bogus())