Пример #1
0
 def can_sign_unspent(self, unspent):
     script = bytes_to_hex(address_to_scriptpubkey(self.address))
     if self.segwit_address:
         segwit_script = bytes_to_hex(
             address_to_scriptpubkey(self.segwit_address))
         return unspent.script == script or unspent.script == segwit_script
     else:
         return unspent.script == script
Пример #2
0
    def handle_cert(self, pem):
        now = timezone.now()
        x509_cert = x509.load_pem_x509_certificate(pem.encode('utf-8'),
                                                   default_backend())

        issuer_cn = x509_cert.issuer
        try:
            issuer_serial = x509_cert.extensions.get_extension_for_oid(
                ExtensionOID.AUTHORITY_KEY_IDENTIFIER)
        except x509.ExtensionNotFound:
            log.error('Cannot get AuthorityKeyIdentifier extension.')
            return

        try:
            ca_serial = bytes_to_hex(issuer_serial.value.key_identifier)
            ca_name = issuer_cn.get_attributes_for_oid(
                NameOID.COMMON_NAME)[0].value
        except Exception as e:
            log.exception(e)

        self.ca = CertificateAuthority.objects.get_or_create(
            serial=ca_serial,
            defaults={
                'name': ca_name,
                'display_name': ca_name,
            })[0]

        try:
            cert, created = Certificate.objects.get_or_create(
                pem=pem,
                defaults={
                    'ca': self.ca,
                    'first_seen': now,
                    'last_seen': now,
                    'serial': int_to_hex(x509_cert.serial_number),
                    'valid_from': x509_cert.not_valid_before,
                    'valid_until': x509_cert.not_valid_after,
                })
        except Exception as e:
            log.exception(e)
            return

        if not created:  # update information
            cert.last_seen = now
            cert.save()
Пример #3
0
    def handle_cert(self, pem):
        now = timezone.now()
        x509_cert = x509.load_pem_x509_certificate(pem.encode('utf-8'), default_backend())

        issuer_cn = x509_cert.issuer
        try:
            issuer_serial = x509_cert.extensions.get_extension_for_oid(ExtensionOID.AUTHORITY_KEY_IDENTIFIER)
        except x509.ExtensionNotFound:
            log.error('Cannot get AuthorityKeyIdentifier extension.')
            return

        try:
            ca_serial = bytes_to_hex(issuer_serial.value.key_identifier)
            ca_name = issuer_cn.get_attributes_for_oid(NameOID.COMMON_NAME)[0].value
        except Exception as e:
            log.exception(e)

        self.ca = CertificateAuthority.objects.get_or_create(serial=ca_serial, defaults={
            'name': ca_name,
            'display_name': ca_name,
        })[0]

        try:
            cert, created = Certificate.objects.get_or_create(pem=pem, defaults={
                'ca': self.ca,
                'first_seen': now,
                'last_seen': now,
                'serial': int_to_hex(x509_cert.serial_number),
                'valid_from': x509_cert.not_valid_before,
                'valid_until': x509_cert.not_valid_after,
            })
        except Exception as e:
            log.exception(e)
            return

        if not created:  # update information
            cert.last_seen = now
            cert.save()
Пример #4
0
def calc_txid(tx_hex):
    tx_obj = deserialize(tx_hex)
    return bytes_to_hex(double_sha256(tx_obj.legacy_repr())[::-1])
Пример #5
0
 def to_hex(self):
     return bytes_to_hex(bytes(self))
Пример #6
0
 def pub_to_hex(self):
     """:rtype: ``str`` """
     return bytes_to_hex(self.public_key)