def validate_certificate(self, certificate_metadata): with open(certificate_metadata.unsigned_cert_file_name) as cert: certificate_json = json.load(cert) # Both tests raise exception on failure # 1. json schema validation validate_v2(certificate_json) # 2. detect if there are any unmapped fields normalize_jsonld(certificate_json, detect_unmapped_fields=True)
def do_execute(self): try: normalized = normalize_jsonld(self.content_to_verify, detect_unmapped_fields=self.detect_unmapped_fields) local_hash = hash_normalized(normalized) cert_hashes_match = hashes_match(local_hash, self.expected_hash) return cert_hashes_match except BlockcertValidationError: logging.error('Certificate has been modified', exc_info=True) return False
def test_v2_preloaded_loader(self): with open('../examples/2.0-alpha/sample_valid.json') as data_f: certificate = json.load(data_f) normalize_jsonld(certificate, detect_unmapped_fields=True)
def get_byte_array_to_issue(self, certificate_json): normalized = normalize_jsonld(certificate_json, detect_unmapped_fields=False) return normalized.encode('utf-8')
def test_v2_unmapped_fields(self): with self.assertRaises(BlockcertValidationError): with open('../examples/2.0-alpha/tampered_unmapped_fields.json') as data_f: certificate = json.load(data_f) normalize_jsonld(certificate, detect_unmapped_fields=True)
def test_v2_1_unmapped_fields_with_vocab(self): with open('../examples/2.1/tampered_unmapped_fields_vocab.json') as data_f: certificate = json.load(data_f) normalize_jsonld(certificate, detect_unmapped_fields=True)
def get_byte_array_to_issue(self, certificate_json): normalized = normalize_jsonld(certificate_json, detect_unmapped_fields=False) return normalized.encode('utf-8')
def get_byte_array_to_issue(self, certificate_metadata): certificate_json = certificate_metadata.unsigned_cert normalized = normalize_jsonld(certificate_json, detect_unmapped_fields=False) return normalized.encode('utf-8')
def test_v3_alpha_preloaded_loader(self): with open( '../examples/3.0-alpha/bbba8553-8ec1-445f-82c9-a57251dd731c.json' ) as data_f: certificate = json.load(data_f) normalize_jsonld(certificate, detect_unmapped_fields=True)
def _create_cert_generator(self) -> Generator: """Return a generator of jsonld-normalized unsigned certs.""" for uid, cert in self.unsigned_certs.items(): normalized = normalize_jsonld(cert, detect_unmapped_fields=False) yield normalized.encode('utf-8')