Esempio n. 1
0
def test():
    """Test cases """
    print("Testing Message")
    Message.test()
    print("Testing PublicKey")
    PublicKey.test()
    print("Testing PrivateKey")
    PrivateKey.test()
    print("Testing PublicKeyMap")
    PublicKeyMap.test()
    print("Testing Wallet")
    Wallet.test()
    print("Testing SampleWallet")
    SampleWallet.test()
    print("Testing TxOutput")
    TxOutput.test()
    print("Testing TxOutputList")
    TxOutputList.test()
    print("Testing TxInputUnsigned")
    TxInputUnsigned.test()
    print("Testing TxInput")
    TxInput.test()
    print("Testing TxInputList")
    TxInputList.test()
    print("Testing AccountBalance")
    AccountBalance.test()
Esempio n. 2
0
    def load(self):
        curr_pub = None
        curr_index = -1

        ps = packet_stream(self._keyring)
        while 1:
            pkt = ps.read() 

            if pkt is None:
                break

            elif isinstance(pkt, public_key_packet):
                curr_index = curr_index + 1
                curr_pub = PublicKey(pkt)
                self._pubkey.append(curr_pub)
                #self._keyid[curr_pub.keyid()] = (curr_pub, curr_index)

            elif isinstance(pkt, userid_packet):
                if curr_pub is None:
                    self._spurious.append(pkt)
                else:
                    curr_pub.add_userid(pkt)
                    self._userid[pkt.userid()] = (curr_pub, curr_index)

            elif isinstance(pkt, signature_packet):
                if curr_pub is None:
                    self._spurious.append(pkt)
                else:
                    curr_pub.add_signature(pkt)

            else:
                self._spurious.append(pkt)

        ps.close()
Esempio n. 3
0
def account_create_operation(creator: str, fee: Amount, name: str, owner: str,
                             active: str, posting: str, memo, json_meta,
                             additional_owner_accounts,
                             additional_active_accounts,
                             additional_posting_accounts,
                             additional_owner_keys, additional_active_keys,
                             additional_posting_keys):
    creation_fee = str(fee)

    owner_pubkey = owner if type(owner) is PublicKey else PublicKey(owner)
    active_pubkey = active if type(active) is PublicKey else PublicKey(active)
    posting_pubkey = posting if type(posting) is PublicKey else PublicKey(
        posting)
    memo_pubkey = memo if type(memo) is PublicKey else PublicKey(memo)

    owner_key_authority = [[str(owner_pubkey), 1]]
    active_key_authority = [[str(active_pubkey), 1]]
    posting_key_authority = [[str(posting_pubkey), 1]]
    owner_accounts_authority = []
    active_accounts_authority = []
    posting_accounts_authority = []

    for k in additional_owner_keys:
        owner_key_authority.append([k, 1])
    for k in additional_active_keys:
        active_key_authority.append([k, 1])
    for k in additional_posting_keys:
        posting_key_authority.append([k, 1])

    for k in additional_owner_accounts:
        owner_accounts_authority.append([k, 1])
    for k in additional_active_accounts:
        active_accounts_authority.append([k, 1])
    for k in additional_posting_accounts:
        posting_accounts_authority.append([k, 1])
    return operations.AccountCreate(
        **{
            'fee': creation_fee,
            'creator': creator,
            'new_account_name': name,
            'owner': {
                'account_auths': owner_accounts_authority,
                'key_auths': owner_key_authority,
                'weight_threshold': 1
            },
            'active': {
                'account_auths': active_accounts_authority,
                'key_auths': active_key_authority,
                'weight_threshold': 1
            },
            'posting': {
                'account_auths': posting_accounts_authority,
                'key_auths': posting_key_authority,
                'weight_threshold': 1
            },
            'memo_key': str(memo_pubkey),
            'json_metadata': json_meta
        })
Esempio n. 4
0
    def __init__(self, cert):
        # c = OpenSSL.crypto
        # st_cert = open("Citi.cer", 'rt').read()
        # cert = c.load_certificate(c.FILETYPE_PEM, st_cert)

        self.logger = get_audit_logger()

        self.cert = cert
        self.config_obj = GetCertConfig()
        self.valid_obj = CertValidity(cert)
        self.revocation_obj = Revocation()
        self.trust_store_obj = TrustStore(cert)

        self.usage_obj = Usage()
        self.pubkey_obj = PublicKey(cert)
        self.ext_dict = get_extension(cert)
Esempio n. 5
0
def get_tests():
    tests = []
    import Cipher; tests += Cipher.get_tests()
    import Hash;   tests += Hash.get_tests()
    import PublicKey; tests += PublicKey.get_tests()
#    import Random; tests += Random.get_tests()
#    import Util;   tests += Util.get_tests()
    return tests
Esempio n. 6
0
def get_tests():
    tests = []
    import Cipher; tests += Cipher.get_tests()
    import Hash;   tests += Hash.get_tests()
    import PublicKey; tests += PublicKey.get_tests()
#    import Random; tests += Random.get_tests()
#    import Util;   tests += Util.get_tests()
    return tests
Esempio n. 7
0
def get_tests(config={}):
    tests = []
    import Cipher; tests += Cipher.get_tests(config=config)
    import Hash;   tests += Hash.get_tests(config=config)
    import Protocol; tests += Protocol.get_tests(config=config)
    import PublicKey; tests += PublicKey.get_tests(config=config)
    import Random; tests += Random.get_tests(config=config)
    import Util;   tests += Util.get_tests(config=config)
    return tests
Esempio n. 8
0
    def load(self):
        curr_pub = None
        curr_index = -1

        ps = packet_stream(self._keyring)
        while 1:
            pkt = ps.read()

            if pkt is None:
                break

            elif isinstance(pkt, public_key_packet):
                curr_index = curr_index + 1
                curr_pub = PublicKey(pkt)
                self._pubkey.append(curr_pub)
                #self._keyid[curr_pub.keyid()] = (curr_pub, curr_index)

            elif isinstance(pkt, userid_packet):
                if curr_pub is None:
                    self._spurious.append(pkt)
                else:
                    curr_pub.add_userid(pkt)
                    self._userid[pkt.userid()] = (curr_pub, curr_index)

            elif isinstance(pkt, signature_packet):
                if curr_pub is None:
                    self._spurious.append(pkt)
                else:
                    curr_pub.add_signature(pkt)

            else:
                self._spurious.append(pkt)

        ps.close()
Esempio n. 9
0
def get_tests(config={}):
    tests = []
    import Cipher
    tests += Cipher.get_tests(config=config)
    import Hash
    tests += Hash.get_tests(config=config)
    import Protocol
    tests += Protocol.get_tests(config=config)
    import PublicKey
    tests += PublicKey.get_tests(config=config)
    import Random
    tests += Random.get_tests(config=config)
    import Util
    tests += Util.get_tests(config=config)
    return tests
Esempio n. 10
0
class CertRules(object):
    def __init__(self, cert):
        # c = OpenSSL.crypto
        # st_cert = open("Citi.cer", 'rt').read()
        # cert = c.load_certificate(c.FILETYPE_PEM, st_cert)

        self.logger = get_audit_logger()

        self.cert = cert
        self.config_obj = GetCertConfig()
        self.valid_obj = CertValidity(cert)
        self.revocation_obj = Revocation()
        self.trust_store_obj = TrustStore(cert)

        self.usage_obj = Usage()
        self.pubkey_obj = PublicKey(cert)
        self.ext_dict = get_extension(cert)
        #self.config_obj.trust_store_path = "E:\\DEV_ENV\\Source\\Git\\git_implementation_repo\\common_criteria_cert_validation\\PyCertValidate\\truststore\\*.cer"

    def check_validity(self):

        validity_chk = self.valid_obj.check_validity()
        period_chk = self.valid_obj.check_period(self.config_obj.cert_age)

        if validity_chk == False or period_chk == False:
            return False

        return True

    def check_issuer(self):
        print self.config_obj.trust_store_path
        res = self.trust_store_obj.get_issuer(
            self.config_obj.trust_store_path +
            "\*.*")  #self.config_obj.trust_store_path)
        if res == False:
            return False
        return True
        #return True
        #return check_issuer(self.cert,self.config_obj.trust_store_path)

    def check_subject(self):
        return True

    def check_keysize(self):
        return self.pubkey_obj.check_keysize(self.config_obj.pub_key_list)

    def check_key_usage(self):
        req_usage_list = []
        key_list = self.config_obj.key_list
        for index in key_list:
            req_usage_list.append(index[0])

        return self.usage_obj.key_usage_chk(self.cert,
                                            self.ext_dict['keyUsage'],
                                            req_usage_list)

    def check_ext_key_usage(self):
        req_extusage_list = []
        extusage_list = self.config_obj.ext_key_list
        #print extusage_list

        for element in extusage_list:
            #print element[0]
            req_extusage_list.append(element[0])

        return self.usage_obj.extkey_usage_chk(
            self.cert, self.ext_dict[ExtensionOID.EXTENDED_KEY_USAGE._name],
            req_extusage_list)

    def check_revocation(self):
        mech = self.config_obj.preferred_mechanism

        if mech == "CRL":
            return self.check_crl()
        elif mech == "OCSP":
            return self.check_ocsp()

    def check_crl(self):
        print "CRL"
        t0 = time.clock()
        cert = self.cert
        res = True

        while res == True:

            trust_store_obj = TrustStore(cert)
            is_cert = trust_store_obj.get_issuer(
                self.config_obj.trust_store_path + "\*.*")

            if str(is_cert.get_issuer()) == str(is_cert.get_subject()):
                break
            else:
                res = self.revocation_obj.crl_check(cert, is_cert)

                if res == False:
                    return False
                else:
                    cert = is_cert

        print "Total CRL check time"
        print time.clock() - t0
        return True

    def check_ocsp(self):
        print "OCSP"
        cert = self.cert
        res = True

        while res == True:
            trust_store_obj = TrustStore(cert)
            is_cert = trust_store_obj.get_issuer(
                self.config_obj.trust_store_path +
                "\*.*")  #self.config_obj.trust_store_path

            if is_cert:
                if str(is_cert.get_issuer()) == str(is_cert.get_subject()):
                    break
                else:
                    cert_url = self.revocation_obj.get_ocsp_url(cert)

                    if is_cert == False:
                        return False
                    else:
                        is_cert_url = self.revocation_obj.get_ocsp_url(is_cert)

                        if is_cert_url == False:
                            return False
                        else:
                            res = self.revocation_obj.get_ocsp_status(
                                cert, is_cert, cert_url, is_cert_url)
                            if res == True:
                                cert = is_cert
                            else:
                                return False
            else:
                return False

        return True
Esempio n. 11
0
 print("p = ", p)
 print("q = ", q, "\n")
 n = p * q
 print("Por lo tanto el módulo será:\n")
 print("n = ", n, "\n")
 print("Ahora, se calcula el valor de la función phi(n):\n")
 phi_n = (p - 1) * (q - 1)
 print("Phi(n) = ", phi_n, "\n")
 print("Se escoje un exponente de cifrado:\n")
 e = RSAProcesses.encrypt_exponent(phi_n)
 print("e = ", e, "\n")
 print("A continuación se calcula el exponente de descifrado:\n")
 d = RSAProcesses.decrypt_exponent(e, phi_n)
 print("d = ", d, "\n")
 print("Finalmente se crean las claves pública y privada.\n")
 public_key = PublicKey.PublicKey(n, e)
 print("Clave pública: (", public_key.module, " ,", public_key.exponent,
       ")")
 private_key = PrivateKey.PrivateKey(n, d)
 print("Clave privada: (", private_key.module, " ,", private_key.exponent,
       ")")
 print("\n-------------------\n")
 print("Ahora se va a transmitir el mensaje. \n")
 string_array = list(
     input(
         "Escriba la cadena de caracteres que representa el mensaje a transmitir: "
     ))
 c = []
 string_array.reverse()
 for i in range(0, len(string_array)):
     c.append(
Esempio n. 12
0
from PrivateKey import *
from PublicKey import *

p = 47
q = 71
private_key = PrivateKey(p, q)
public, private = private_key.create()

public_key = PublicKey(public[0], public[1])
ciphered = public_key.encrypt("Hello, World!")
print(ciphered)
dechiphered = private_key.decrypt(ciphered)
print(dechiphered)
Esempio n. 13
0
 def __init__(self, keyfile, rel):
     self.pkey = PublicKey.PublicKey(self.read_keyfile(keyfile))
     self.rel = rel
     self.num = self.get_num()