def main(): BASE_MODULE_ARGS = dict( certdir = dict(default="/etc/certs"), subj = dict(default="/DC=com/DC=example/CN=CA/"), state = dict(default="present", choices=["present", "absent"]), force = dict(default="false", choices=["true", "false"]) ) module = AnsibleModule( argument_spec= BASE_MODULE_ARGS, supports_check_mode=True ) ca = CA(module.params["certdir"], module.params["subj"], module.params["force"]) if not ca.force: if ca.check_if_ca_exists(): module.exit_json(dict(changed=false, skip_reason="Conditional check failed", skipped=true)); isValid = ca.validate_setup() if isValid["success"]: if module.params["state"] == "present": isValid = ca.setup() else: isValid = ca.removeCA() if not isValid["success"]: module.fail_json(msg=isValid["msg"]) else: module.exit_json(**isValid)
def main(): BASE_MODULE_ARGS = dict( certdir = dict(default="/etc/certs"), subj = dict(default="/DC=com/DC=example/CN=CA/"), state = dict(default="present", choices=["present", "absent"]) ) module = AnsibleModule( argument_spec= BASE_MODULE_ARGS, supports_check_mode=True ) ca = CA(module.params["certdir"], module.params["subj"]) isValid = ca.validate_setup() if isValid["success"]: if module.params["state"] == "present": isValid = ca.setup() else: isValid = ca.removeCA() if not isValid["success"]: module.fail_json(msg=isValid["msg"]) else: module.exit_json(**isValid)
def setUp(self): self.ca_A = CA('/CN=A') self.ca_B = CA('/CN=B') self.ca_A_tls = CA('/CN=A_tls', self.ca_A) self.ca_A_enc = CA('/CN=A_enc', self.ca_A) self.srvA = self.__makeServer('/CN=localhost', 'localhost') self.srvB = self.__makeServer('/CN=localhost:5701', 'localhost', 5701)
def __init__(self, sid="test.security.sender.alice", rid="test.security.rec.bob", dummy=True): self.sid = sid self.rid = rid # 1. generate private/public key pairs for the certificate authority. # 2. Initially generate some X509 certificates for random public keys, for random ids and store them in a suitable format (a file or a database) if dummy: CA.get_instance().generateDummyCertificates(n=20)
def __init__(self, grid_filename, interval=100): """ Construct the simulation. Params: - grid_filename: Filename of the initial grid - interval: Amount of miliseconds between frames of the animation """ self.ca = CA.from_gridfile(grid_filename) self.interval = interval
def __init__(self, id, elgamal=None, persist=False): self.id = id self.lastRecInfo = {} self.persist = persist self.ca = CA.get_instance() self.caKey = self._loadCAKey() if(elgamal): self.elgSig = elgamal elif(os.path.exists(ELG_PARAMS_PATH)): self.elgSig = ElgamalDigitalSignature.from_file(ELG_PARAMS_PATH) else: self.elgSig = ElgamalDigitalSignature() self.elgSig.saveConfig(ELG_PARAMS_PATH) x = rsa.getAsymKey() self.privateKey = x self.publicKey = x.public_key() self._authenticateWithCA()
def main(): wa.pygame.init() # CA density_map = read.read_asc("data/polds00g.asc") cell_auto = CA(density_map, a=2, b=2, cell_size=constants.CELL_SIZE) # screen size screen_width = density_map.shape[1] * constants.CELL_SIZE + 200 screen_height = density_map.shape[0] * constants.CELL_SIZE # buttons import_data_button = Button(screen_width - 175, 100, 150, 30, "Import data") start_simulation_button = Button(screen_width - 175, 200, 150, 30, "Start simulation") stop_simulation_button = Button(screen_width - 175, 300, 150, 30, "Stop simulation") randomize_data_button = Button(screen_width - 175, 400, 150, 30, "Randomize data") buttons = [ import_data_button, start_simulation_button, stop_simulation_button, randomize_data_button ] win = wa.pygame.display.set_mode((screen_width, screen_height)) wa.pygame.display.set_caption('Pandemic simulation') run = True run_simulation = True # main loop while run: for event in wa.pygame.event.get(): if event.type == wa.pygame.QUIT: run = False if event.type == wa.pygame.MOUSEBUTTONDOWN and event.button == 1: run_simulation, import_data, new_density_map = wa.check_button_click( buttons, event.pos) if import_data: cell_auto = CA(new_density_map, a=2, b=2, cell_size=constants.CELL_SIZE) if run_simulation: wa.redraw_window(win, cell_auto, buttons) cell_auto.run(1) wa.pygame.quit()
def __init__(self, id, elgamal=None, elgKeyPairs=None, persist=False): ''' :param elgamal: elgamal object of Elgamal class type, if None a new one will be created with default params or will be restored from the file :param elgKeyPairs: key pairs generated from same parameters of elgamal object. if None they will be generated from elgamal object ''' self.id = id self.lastSendInfo = {} self.persist = persist self.ca = CA.get_instance( ) # this should be called before loading cakey self.caKey = self._loadCAKey() if (elgamal): self.elgSig = elgamal elif (os.path.exists(ELG_PARAMS_PATH)): self.elgSig = ElgamalDigitalSignature.from_file(ELG_PARAMS_PATH) else: self.elgSig = ElgamalDigitalSignature() self.elgSig.saveConfig(ELG_PARAMS_PATH) x, y = elgKeyPairs or self.elgSig.generateUserKey() self.privateKey = x self.publicKey = y self._authenticateWithCA()
from ca import CA from certificate import Certificate from keytool import Keytool import os line = "----------------------------------------------" cadir = "./testca" ca = CA(cadir, "/CN=Test CA/") ca.validate_setup() r1 = ca.setup() print "CA present" print line print r1 def createCert(certname, subj, password, isServerCert): print line print "Creating certificate for: {}".format(certname) cert = Certificate(cadir, certname, subj, password, isServerCert) print cert.create_certificate() return cert createCert("test.openampere.com", "/CN=Test/", "abc123!@#$", True) c1 = createCert("client.openampere.com", "/CN=Client/", "asdfaer13", False) createCert("client2.openampere.com", "/DC=com/DC=openampere/DC=test/CN=Client2", "asdf", False)
from ca import CA from certificate import Certificate from keytool import Keytool import os line = "----------------------------------------------" cadir = "./testca" ca = CA(cadir, "/CN=Test CA/") ca.validate_setup() r1 = ca.setup() print "CA present" print line print r1 def createCert(certname, subj, password, isServerCert): print line print "Creating certificate for: {}".format(certname) cert = Certificate(cadir, certname, subj, password, isServerCert) print cert.create_certificate() return cert createCert("test.openampere.com", "/CN=Test/", "abc123!@#$", True) c1 = createCert("client.openampere.com", "/CN=Client/", "asdfaer13", False) createCert("client2.openampere.com",
from utils import generate_safe_prime, generate_hash from elgamal import ElGamalDS import random from ca import CA from datetime import datetime, timedelta from utils import verify_certificate # Global Constants NBYTES = SHA.digest_size + 1 BYTES_TO_BITS = 8 MAX_ID = 30 RSA_KEY_BITS = 512 ######################################################################################################################## # CA Creation ca = CA(NBYTES) # RSA Creation rsa = RSA(RSA_KEY_BITS) # Alice and Bob Parameters q = generate_safe_prime(NBYTES * BYTES_TO_BITS) a = random.randint(2, q - 1) ######################################################################################################################## # Alice Keys x_a = random.randint(2, q - 1) y_a = pow(a, x_a, q) id_a = random.randint(1, MAX_ID)