コード例 #1
0
def main(app_config):
    # find certificates to process
    certificates = find_unsigned_certificates(app_config)
    if not certificates:
        logging.info('No certificates to process')
        exit(0)

    logging.info('Processing %d certificates', len(certificates))

    # validate schema
    for uid, certificate in certificates.items():
        with open(certificate.unsigned_certificate_file_name) as cert:
            cert_json = json.load(cert)
            schema_validator.validate_unsigned_v1_2_0(cert_json)

    # ensure they are not already signed. We want the user to know about this in case there
    # is a failure from a previous run
    for uid, certificate in certificates.items():
        with open(certificate.unsigned_certificate_file_name) as cert:
            cert_json = json.load(cert)
            if 'signature' in cert_json and cert_json['signature']:
                logging.warning(
                    'Certificate with uid=%s has already been signed.', uid)
                exit(0)

    start_time = str(time.time())

    logging.info('Signing certificates and writing to folder %s',
                 app_config.signed_certs_file_pattern)
    sign_certs(certificates)

    logging.info('Archiving unsigned files')
    helpers.archive_files(app_config.unsigned_certs_file_pattern,
                          app_config.archived_unsigned_certs_file_pattern,
                          start_time)
コード例 #2
0
def main(app_config):
    # find certificates to process
    certificates = find_unsigned_certificates(app_config)
    if not certificates:
        logging.info('No certificates to process')
        exit(0)

    batch_id = helpers.get_batch_id(list(certificates.keys()))
    logging.info('Processing %d certificates with batch id=%s', len(certificates), batch_id)

    # validate schema
    for uid, certificate in certificates.items():
        with open(certificate.unsigned_certificate_file_name) as cert:
            cert_json = json.load(cert)
            schema_validator.validate_unsigned_v1_2(cert_json)

    # ensure they are not already signed. We want the user to know about this in case there
    # is a failure from a previous run
    for uid, certificate in certificates.items():
        with open(certificate.unsigned_certificate_file_name) as cert:
            cert_json = json.load(cert)
            if 'signature' in cert_json and cert_json['signature']:
                logging.warning('Certificate with uid=%s has already been signed.', uid)
                exit(0)

    logging.info('Signing certificates and writing to folder %s', app_config.signed_certs_file_pattern)
    sign_certs(certificates)

    logging.info('Archiving unsigned files to archive folder %s', batch_id)
    helpers.archive_files(app_config.unsigned_certs_file_pattern,
                          app_config.archive_path,
                          app_config.unsigned_certs_file_part,
                          batch_id)
コード例 #3
0
def main(app_config):
    # find certificates to process
    certificates_metadata = find_unsigned_certificates(app_config)
    if not certificates_metadata:
        logging.info('No certificates to process')
        exit(0)

    logging.info('Processing %d certificates', len(certificates_metadata))

    if app_config.wallet_connector_type == 'bitcoind' and not app_config.disable_regtest_mode:
        bitcoin.SelectParams('regtest')
        allowable_wif_prefixes = [b'\x80', b'\xef']
    else:
        allowable_wif_prefixes = None
    # configure bitcoin wallet and broadcast connectors
    wallet = Wallet(connectors.create_wallet_connector(app_config))
    broadcast_function = connectors.create_broadcast_function(app_config)

    # get issuing and revocation addresses from config
    issuing_address = app_config.issuing_address
    revocation_address = app_config.revocation_address

    start_time = str(time.time())

    if not app_config.skip_sign:
        logging.info('Deleting previous generated files')
        helpers.clear_intermediate_folders(app_config)

        logging.info('Signing certificates')
        sign_certs(certificates_metadata)

        logging.info('Hashing signed certificates.')
        hash_certs(certificates_metadata)

        logging.info('Archiving signed certificates.')
        helpers.archive_files(app_config.signed_certs_file_pattern,
                              app_config.archived_certs_file_pattern,
                              start_time)

    # calculate transaction costs
    transaction_costs = wallet_helper.get_cost_for_certificate_batch(
        app_config.dust_threshold,
        app_config.tx_fees, app_config.satoshi_per_byte,
        len(certificates_metadata), app_config.transfer_from_storage_address)
    logging.info('Total cost will be %d satoshis', transaction_costs.total)

    # ensure there is enough in our wallet at the storage/issuing address, transferring from the storage address
    # if configured (advanced option)
    if app_config.transfer_from_storage_address:
        storage_address = app_config.storage_address
        wallet.transfer_balance(storage_address, issuing_address,
                                transaction_costs)

    logging.info('Checking there is enough balance in the wallet.')
    wallet.check_balance(issuing_address, transaction_costs)

    # issue the certificates on the blockchain
    logging.info('Issuing the certificates on the blockchain')
    issue_on_blockchain(wallet, broadcast_function, issuing_address,
                        revocation_address, certificates_metadata,
                        transaction_costs, issue_on_blockchain,
                        allowable_wif_prefixes)

    # archive
    logging.info('Archived sent transactions folder for safe keeping.')
    helpers.archive_files(app_config.sent_txs_file_pattern,
                          app_config.archived_txs_file_pattern, start_time)

    logging.info('Done!')
コード例 #4
0
def main(app_config):
    # find certificates to process
    certificates = find_signed_certificates(app_config)
    if not certificates:
        logging.info('No certificates to process')
        exit(0)

    batch_id = helpers.get_batch_id(list(certificates.keys()))
    logging.info('Processing %d certificates with batch id=%s', len(certificates), batch_id)

    helpers.clear_intermediate_folders(app_config)

    # get issuing and revocation addresses from config
    issuing_address = app_config.issuing_address
    revocation_address = app_config.revocation_address

    issuer = BatchIssuer(config=app_config, certificates_to_issue=certificates)

    issuer.validate_schema()

    # verify signed certs are signed with issuing key
    [verify_signature(uid, cert.signed_certificate_file_name, issuing_address) for uid, cert in
     certificates.items()]

    wallet = Wallet()

    logging.info('Hashing signed certificates.')
    issuer.hash_certificates()

    # calculate transaction costs
    all_costs = issuer.get_cost_for_certificate_batch(app_config.transfer_from_storage_address)

    logging.info('Total cost will be %d satoshis', all_costs.total)

    if app_config.transfer_from_storage_address:
        # ensure there is enough in our wallet at the storage/issuing address, transferring from the storage address
        # if configured
        logging.info('Checking there is enough balance in the issuing address')
        funds_needed = wallet.check_balance_no_throw(issuing_address, all_costs)
        if funds_needed > 0:
            wallet.check_balance(app_config.storage_address, all_costs)
            wallet.send_payment(
                app_config.storage_address,
                issuing_address,
                all_costs.min_per_output,
                all_costs.fee)

    # ensure the issuing address now has sufficient balance
    wallet.check_balance(issuing_address, all_costs)

    # issue the certificates on the blockchain
    logging.info('Issuing the certificates on the blockchain')
    issuer.issue_on_blockchain(revocation_address=revocation_address,
                               issuing_transaction_cost=all_costs)

    # archive
    logging.info('Archiving signed certificates.')
    helpers.archive_files(app_config.signed_certs_file_pattern,
                          app_config.archive_path,
                          app_config.signed_certs_file_part,
                          batch_id)

    logging.info('Archiving sent transactions.')
    helpers.archive_files(app_config.sent_txs_file_pattern,
                          app_config.archive_path,
                          app_config.txs_file_part,
                          batch_id)

    logging.info('Archiving receipts.')
    helpers.archive_files(app_config.receipts_file_pattern,
                          app_config.archive_path,
                          app_config.receipts_file_part,
                          batch_id)

    logging.info('Archiving blockchain certificates.')
    helpers.archive_files(app_config.blockchain_certificates_file_pattern,
                          app_config.archive_path,
                          app_config.blockchain_certificates_file_part,
                          batch_id)

    archive_folder = os.path.join(app_config.archive_path, batch_id)
    logging.info('Your Blockchain Certificates are in %s', archive_folder)
コード例 #5
0
def main(app_config):

    # find certificates to process
    certificates = find_signed_certificates(app_config)
    if not certificates:
        logging.info('No certificates to process')
        exit(0)

    batch_id = helpers.get_batch_id(list(certificates.keys()))
    logging.info('Processing %d certificates with batch id=%s',
                 len(certificates), batch_id)

    helpers.clear_intermediate_folders(app_config)

    # get issuing and revocation addresses from config
    issuing_address = app_config.issuing_address
    revocation_address = app_config.revocation_address

    issuer = V1_2_Issuer(config=app_config, certificates_to_issue=certificates)

    issuer.validate_schema()

    # verify signed certs are signed with issuing key
    [
        cert_utils.verify_signature(uid, cert.signed_certificate_file_name,
                                    issuing_address)
        for uid, cert in certificates.items()
    ]

    allowable_wif_prefixes = app_config.allowable_wif_prefixes

    # configure bitcoin wallet and broadcast connectors
    wallet = Wallet(connectors.create_wallet_connector(app_config))
    broadcast_function = connectors.create_broadcast_function(app_config)

    logging.info('Hashing signed certificates.')
    issuer.hash_certificates()

    # calculate transaction costs
    all_costs = issuer.get_cost_for_certificate_batch(
        app_config.dust_threshold, app_config.tx_fee,
        app_config.satoshi_per_byte, app_config.transfer_from_storage_address)

    logging.info('Total cost will be %d satoshis', all_costs.total)

    split_input_trxs = False
    if app_config.transfer_from_storage_address:
        # ensure there is enough in our wallet at the storage/issuing address, transferring from the storage address
        # if configured
        logging.info('Checking there is enough balance in the issuing address')
        funds_needed = wallet.calculate_funds_needed(issuing_address,
                                                     all_costs)
        if funds_needed > 0:
            wallet.check_balance(app_config.storage_address, all_costs)
            wallet.transfer_balance(app_config.storage_address,
                                    issuing_address, all_costs)
            split_input_trxs = True

    # ensure the issuing address now has sufficient balance
    wallet.check_balance(issuing_address, all_costs.issuing_transaction_cost)

    # issue the certificates on the blockchain
    logging.info('Issuing the certificates on the blockchain')
    issuer.issue_on_blockchain(
        wallet=wallet,
        revocation_address=revocation_address,
        split_input_trxs=split_input_trxs,
        allowable_wif_prefixes=allowable_wif_prefixes,
        broadcast_function=broadcast_function,
        issuing_transaction_cost=all_costs.issuing_transaction_cost)

    # archive
    logging.info('Archiving signed certificates.')
    helpers.archive_files(app_config.signed_certs_file_pattern,
                          app_config.archive_path,
                          app_config.signed_certs_file_part, batch_id)

    logging.info('Archiving sent transactions.')
    helpers.archive_files(app_config.sent_txs_file_pattern,
                          app_config.archive_path, app_config.txs_file_part,
                          batch_id)

    logging.info('Archiving receipts.')
    helpers.archive_files(app_config.receipts_file_pattern,
                          app_config.archive_path,
                          app_config.receipts_file_part, batch_id)

    logging.info('Archiving blockchain certificates.')
    helpers.archive_files(app_config.blockchain_certificates_file_pattern,
                          app_config.archive_path,
                          app_config.blockchain_certificates_file_part,
                          batch_id)

    archive_folder = os.path.join(app_config.archive_path, batch_id)
    logging.info('Your Blockchain Certificates are in %s', archive_folder)
コード例 #6
0
def main(app_config):
    # find certificates to process
    certificates_metadata = find_unsigned_certificates(app_config)
    if not certificates_metadata:
        logging.info('No certificates to process')
        exit(0)

    logging.info('Processing %d certificates', len(certificates_metadata))

    if app_config.wallet_connector_type == 'bitcoind' and not app_config.disable_regtest_mode:
        bitcoin.SelectParams('regtest')
        allowable_wif_prefixes = [b'\x80', b'\xef']
    else:
        allowable_wif_prefixes = None
    # configure bitcoin wallet and broadcast connectors
    wallet = Wallet(connectors.create_wallet_connector(app_config))
    broadcast_function = connectors.create_broadcast_function(app_config)

    # get issuing and revocation addresses from config
    issuing_address = app_config.issuing_address
    revocation_address = app_config.revocation_address

    start_time = str(time.time())

    if not app_config.skip_sign:
        logging.info('Deleting previous generated files')
        helpers.clear_intermediate_folders(app_config)

        logging.info('Signing certificates')
        sign_certs(certificates_metadata)

        logging.info('Hashing signed certificates.')
        hash_certs(certificates_metadata)

        logging.info('Archiving signed certificates.')
        helpers.archive_files(app_config.signed_certs_file_pattern,
                              app_config.archived_certs_file_pattern, start_time)

    # calculate transaction costs
    transaction_costs = wallet_helper.get_cost_for_certificate_batch(app_config.dust_threshold, app_config.tx_fees,
                                                                     app_config.satoshi_per_byte,
                                                                     len(certificates_metadata),
                                                                     app_config.transfer_from_storage_address)
    logging.info('Total cost will be %d satoshis', transaction_costs.total)

    # ensure there is enough in our wallet at the storage/issuing address, transferring from the storage address
    # if configured (advanced option)
    if app_config.transfer_from_storage_address:
        storage_address = app_config.storage_address
        wallet.transfer_balance(
            storage_address, issuing_address, transaction_costs)

    logging.info('Checking there is enough balance in the wallet.')
    wallet.check_balance(issuing_address, transaction_costs)

    # issue the certificates on the blockchain
    logging.info('Issuing the certificates on the blockchain')
    issue_on_blockchain(wallet, broadcast_function, issuing_address,
                        revocation_address, certificates_metadata,
                        transaction_costs, issue_on_blockchain, allowable_wif_prefixes)

    # archive
    logging.info('Archived sent transactions folder for safe keeping.')
    helpers.archive_files(app_config.sent_txs_file_pattern,
                          app_config.archived_txs_file_pattern, start_time)

    logging.info('Done!')