def generate_issuer_file(config): if config.public_key_created: issued_on = config.public_key_created else: print(helpers.create_iso8601_tz()) issued_on = helpers.create_iso8601_tz() output_handle = open(config.output_file, 'w') if config.output_file else sys.stdout context = [OPEN_BADGES_V2_CONTEXT_JSON, BLOCKCERTS_V2_CONTEXT_JSON] issuer_json = { '@context': context, 'id': config.issuer_id, 'url': config.issuer_url, 'name': config.issuer_name, 'email': config.issuer_email, 'image': helpers.encode_image(os.path.join(config.abs_data_dir, config.issuer_logo_file)), 'publicKey': [{'id': config.issuer_public_key, "created": issued_on}], 'revocationList': config.revocation_list_uri, 'type': ISSUER_TYPE } if config.intro_url: issuer_json['introductionUrl'] = config.intro_url output_handle.write(json.dumps(issuer_json, indent=2)) if output_handle is not sys.stdout: output_handle.close()
def generate_issuer_file(config): if config.public_key_created: issued_on = config.public_key_created else: issued_on = helpers.create_iso8601_tz() output_handle = open(config.output_file, 'w') if config.output_file else sys.stdout context = [OPEN_BADGES_V2_CONTEXT_JSON, BLOCKCERTS_V2_CONTEXT_JSON] issuer_json = { '@context': context, 'id': config.issuer_id, 'url': config.issuer_url, 'name': config.issuer_name, 'email': config.issuer_email, 'image': helpers.encode_image(os.path.join(config.abs_data_dir, config.issuer_logo_file)), 'publicKey': [{'id': config.issuer_public_key, "created": issued_on}], 'revocationList': config.revocation_list_uri, 'type': ISSUER_TYPE } if config.intro_url: issuer_json['introductionUrl'] = config.intro_url output_handle.write(json.dumps(issuer_json, indent=2)) if output_handle is not sys.stdout: output_handle.close()
def generate_issuer_file(config): if config.public_key_created: issued_on = config.public_key_created else: issued_on = helpers.create_iso8601_tz() context = [OPEN_BADGES_V2_CONTEXT_JSON, BLOCKCERTS_V2_CONTEXT_JSON] issuer_json = { '@context': context, 'id': config.domain_name_prefix + config.issuer_id_path, 'url': config.issuer_url, 'name': config.issuer_name, 'email': config.issuer_email, 'publicKey': [{ 'id': PUBKEY_PREFIX + config.public_key, "created": issued_on }], 'revocationList': config.domain_name_prefix + config.revocation_list_path, 'type': ISSUER_TYPE } return issuer_json
def create_unsigned_certificates_from_roster(config): roster = os.path.join(config.abs_data_dir, config.roster) template = os.path.join(config.abs_data_dir, config.template_dir, config.template_file_name) issued_on = helpers.create_iso8601_tz() output_dir = os.path.join(config.abs_data_dir, config.unsigned_certificates_dir) print('Writing certificates to ' + output_dir) recipients = [] with open(roster, 'r') as theFile: reader = csv.DictReader(theFile) for line in reader: r = Recipient(line) recipients.append(r) with open(template) as template: cert_str = template.read() template = json.loads(cert_str) for recipient in recipients: uid = str(uuid.uuid4()) cert = copy.deepcopy(template) instantiate_assertion(config, cert, uid, issued_on) instantiate_recipient(config, cert, recipient) # validate certificate before writing schema_validator.validate_v2(cert) with open(os.path.join(output_dir, uid + '.json'), 'w') as unsigned_cert: json.dump(cert, unsigned_cert)
def post(self): json_data = request.get_json(force=True) # get recipient from the json_data fields = {} fields["identity"] = json_data['email'] fields["name"] = json_data['name'] recipient = Recipient(fields) # get the template from db template_col = DAO().get_collection('certificate_template') template = template_col.find_one({}, {"_id": 0}) # get deep copy of the template as cert cert = deepcopy(template) # get the config config = Config().get() # call instantiate_assertion and instantiate_recipient uid = str(uuid.uuid4()) issued_on = helpers.create_iso8601_tz() instantiate_assertion(cert, uid, issued_on) instantiate_recipient(cert, recipient, config.additional_per_recipient_fields, config.hash_emails) # get the config config = Config().get() # post it to blockchain # first instantiate handlers chain = config.chain if chain == Chain.ethereum_mainnet or chain == Chain.ethereum_ropsten: from cert_issuer.blockchain_handlers import ethereum certificate_batch_handler, transaction_handler, connector = ethereum.instantiate_blockchain_handlers( config, False) else: from cert_issuer.blockchain_handlers import bitcoin certificate_batch_handler, transaction_handler, connector = bitcoin.instantiate_blockchain_handlers( config, False) certificate_batch_handler.certificates_to_issue = [cert] issuer = Issuer(certificate_batch_handler=certificate_batch_handler, transaction_handler=transaction_handler, max_retry=config.max_retry) tx_id = issuer.issue(config.chain) issued_cert = certificate_batch_handler.certificates_to_issue[0] issued_cert_to_insert = deepcopy(issued_cert) cert_col = DAO().get_collection("certificates") cert_col.insert_one(issued_cert_to_insert) return issued_cert
def create_unsigned_certificates_from_roster(config): csv.field_size_limit(sys.maxsize) roster = os.path.join(config.abs_data_dir, config.roster) template = os.path.join(config.abs_data_dir, config.template_dir, config.template_file_name) issued_on = helpers.create_iso8601_tz() output_dir = os.path.join(config.abs_data_dir, config.unsigned_certificates_dir) print('Writing certificates to ' + output_dir) recipients = [] with open(roster, 'r') as theFile: reader = csv.DictReader(theFile, quoting=csv.QUOTE_MINIMAL) for line in reader: r = Recipient(line) recipients.append(r) with tqdm.tqdm(total=len(recipients)) as bar: with open(template) as template: cert_str = template.read() template = json.loads(cert_str) for recipient in recipients: if config.filename_format == "certname_identity": uid = template['badge']['name'] + recipient.identity uid = "".join(c for c in uid if c.isalnum()) else: uid = str(uuid.uuid4()) cert_file = os.path.join(output_dir, uid + '.json') if os.path.isfile(cert_file) and config.no_clobber: continue cert = copy.deepcopy(template) instantiate_assertion(config, cert, uid, issued_on) instantiate_recipient(config, cert, recipient) # validate certificate before writing # schema_validator.validate_v2(cert) with open(cert_file, 'w') as unsigned_cert: json.dump(cert, unsigned_cert) bar.update(1)
def create_unsigned_certificates_from_roster(template, recipients, use_identities, additionalFields, hash_emails): issued_on = helpers.create_iso8601_tz() certs = {} for recipient in recipients: if use_identities: uid = template['badge']['name'] + recipient.identity uid = "".join(c for c in uid if c.isalnum()) else: uid = str(uuid.uuid4()) cert = copy.deepcopy(template) instantiate_assertion(cert, uid, issued_on) instantiate_recipient(cert, recipient, additionalFields, hash_emails) # validate certificate before writing schema_validator.validate_v2(cert) certs[uid] = cert return certs
def create_unsigned_certificates_from_roster(config): roster = os.path.join(config.abs_data_dir, config.roster) template = os.path.join(config.abs_data_dir, config.template_dir, config.template_file_name) issued_on = helpers.create_iso8601_tz() output_dir = os.path.join(config.abs_data_dir, config.unsigned_certificates_dir) print('Writing certificates to ' + output_dir) recipients = [] with open(roster, 'r') as theFile: reader = csv.DictReader(theFile) for line in reader: r = Recipient(line) recipients.append(r) with open(template) as template: cert_str = template.read() template = json.loads(cert_str) for recipient in recipients: if config.filename_format == "certname_identity": uid = template['badge']['name'] + recipient.identity uid = "".join(c for c in uid if c.isalnum()) else: uid = str(uuid.uuid4()) cert_file = os.path.join(output_dir, uid + '.json') if os.path.isfile(cert_file) and config.no_clobber: continue cert = copy.deepcopy(template) instantiate_assertion(config, cert, uid, issued_on) instantiate_recipient(config, cert, recipient) # validate certificate before writing schema_validator.validate_v2(cert) with open(cert_file, 'w') as unsigned_cert: json.dump(cert, unsigned_cert)
def create_unsigned_certificates_from_roster(template, recipients, use_identities, additionalFields, hash_emails): issued_on = helpers.create_iso8601_tz() certs = {} for recipient in recipients: if use_identities: uid = template['badge']['name'] + recipient.identity uid = "".join(c for c in uid if c.isalnum()) else: uid = str(uuid.uuid4()) cert = copy.deepcopy(template) instantiate_assertion(cert, uid, issued_on) instantiate_recipient(cert, recipient, additionalFields, hash_emails) # validate certificate before writing schema_validator.validate_v2(cert) certs[uid] = cert return certs
def create_unsigned_certificates_from_roster(template, publicKey, use_identities, cridArray, cridType, metadataJson): issued_on = helpers.create_iso8601_tz() certs = {} for crid in cridArray: if use_identities: uid = publicKey uid = "".join(c for c in uid if c.isalnum()) else: uid = str(uuid.uuid4()) cert = copy.deepcopy(template) instantiate_assertion(cert, uid, issued_on, crid, cridType) instantiate_recipient(cert, publicKey, metadataJson) # validate unsigned certificate before writing schema_validator.validate_v3_alpha(cert, True) certs[uid] = cert return certs
def generate_issuer(config): if hasattr(config, 'public_key_created') and config.public_key_created: issued_on = config.public_key_created else: issued_on = helpers.create_iso8601_tz() context = [OPEN_BADGES_V2_CONTEXT_JSON, BLOCKCERTS_V2_CONTEXT_JSON] issuer = { '@context': context, 'id': config.issuer_id, 'url': config.issuer_url, 'name': config.issuer_name, 'email': config.issuer_email, 'image': helpers.get_b64encoded_image(config, 'issuer_logo_file'), 'publicKey': [{ 'id': config.issuer_public_key, "created": issued_on }], 'revocationList': config.revocation_list_uri, 'type': ISSUER_TYPE } if config.intro_url: issuer['introductionUrl'] = config.intro_url return issuer
def create_unsigned_certificates_from_roster(template, recipient_name, publicKey, use_identities, additionalFields, SHA256Hash, email): issued_on = helpers.create_iso8601_tz() certs = {} for shahash in SHA256Hash: if use_identities: uid = publicKey uid = "".join(c for c in uid if c.isalnum()) else: uid = str(uuid.uuid4()) cert = copy.deepcopy(template) instantiate_assertion(cert, uid, issued_on, shahash) instantiate_recipient(cert, recipient_name, additionalFields, email) # validate unsigned certificate before writing schema_validator.validate_v3_alpha(cert, True) certs[uid] = cert return certs
def create_unsigned_certificates_from_roster(config): roster = os.path.join(config.abs_data_dir, config.roster) template = os.path.join(config.abs_data_dir, config.template_dir, config.template_file_name) issued_on = helpers.create_iso8601_tz() output_dir = os.path.join(config.abs_data_dir, config.unsigned_certificates_dir) print('Writing certificates to ' + output_dir) recipients = [] ### User defined changes. Defined a mapping list for keeping user mapping. ### mapping = [] ### END ### with open(roster, 'r') as theFile: reader = csv.DictReader(theFile) for line in reader: r = Recipient(line) recipients.append(r) with open(template) as template: cert_str = template.read() template = json.loads(cert_str) for recipient in recipients: if config.filename_format == "certname_identity": uid = template['badge']['name'] + recipient.identity uid = "".join(c for c in uid if c.isalnum()) else: uid = str(uuid.uuid4()) ### User-defined changes. Added a field to change the certificate Image for a given recipient ### template['badge']['image'] = helpers.encode_image( os.path.join(config.abs_data_dir, 'images/' + recipient.imagefile)) ### END ### cert_file = os.path.join(output_dir, uid + '.json') if os.path.isfile(cert_file) and config.no_clobber: continue cert = copy.deepcopy(template) instantiate_assertion(config, cert, uid, issued_on) instantiate_recipient(config, cert, recipient) # validate certificate before writing schema_validator.validate_v2(cert) with open(cert_file, 'w') as unsigned_cert: json.dump(cert, unsigned_cert) ###UserDefined changes. Creating a mapping for recepient email and filename mapping.append([recipient.identity, uid + '.json']) ### END ### ### User Defined changes. Writes to the mapping csv file ### with open(os.path.join(config.abs_data_dir, 'mapping.csv'), 'w') as mappingFile: writer = csv.writer(mappingFile) writer.writerows(mapping)