def gen(): """Generate students tasks""" common.check_env() common.create_module(__name__) # TODO Add certificate chain generation here students = common.load_students() if os.path.exists(_M(VARIANTS_DB)): passwords = [x for x in common.load_csv(_M(VARIANTS_DB))] else: passwords = [[x.name, ''] for x in students] cache = [] for i, student in enumerate(students): print('Gen {0}: {1} '.format(i + 1, student), end='') if len(student.keybase) == 0: print('has no keybase account') continue if len(passwords[i][1]) == 0: passwords[i][1] = common.gen_pass() print('generated') else: print('already generated') rsa_pub = common.extract_module(_get_rsa(student.fingerprint)) cache.append([rsa_pub, passwords[i][1]]) common.save_csv(_M(CACHE_DB), cache) common.save_csv(_M(VARIANTS_DB), passwords) print('Created students tasks')
def gen(): """Генерирует набор кошельков студентов""" common.check_env() common.create_module(__name__) native = _gen_native() students = common.load_students() wallets = collections.OrderedDict() block = ctypes.create_string_buffer(BLOCK_SIZE) for i, student in enumerate(students): print('Gen {0}: {1} ['.format(i + 1, student), end='') key_name = _M('student{}.key'.format(i + 1)) if not os.path.exists(key_name): print('k', end='') subprocess.check_call([ 'openssl', 'ecparam', '-genkey', '-name', 'secp256k1', '-noout', '-out', key_name ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) pub_name = _M('student{}.pub'.format(i + 1)) if not os.path.exists(pub_name): print('p', end='') subprocess.check_call([ 'openssl', 'ec', '-pubout', '-in', key_name, '-out', pub_name ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) enc_name = _M('student{}.enc'.format(i + 1)) if not os.path.exists(enc_name) and len(student.keybase) != 0: print('e', end='') subprocess.check_call([ 'gpg', '--trust-model', 'always', '--yes', '-r', student.fingerprint, '--output', enc_name, '--encrypt', key_name ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) native.write_target(block, pub_name.encode('utf8')) wallets[student.name] = ''.join('{:02x}'.format(x) for x in block[96:160]) print('] generated') with open(WALLETS_FILE, 'w', encoding='utf8') as wallets_file: json.dump(wallets, wallets_file, ensure_ascii=False) print('Created students tasks')
def gen(): """Generate students tasks""" common.check_env() common.create_module(__name__) students = common.load_students() if os.path.exists(_M(VARIANTS_DB)): passwords = [x for x in common.load_csv(_M(VARIANTS_DB))] else: passwords = [[x.name, ''] for x in students] for i, student in enumerate(students): print('Gen {0}: {1} '.format(i + 1, student), end='') if len(passwords[i][1]) > 0: print('skipped, already generated') continue passwords[i][1] = common.gen_pass() correct = random.choice(MASKS) for j, mask in enumerate(MASKS): filename = _M('file{0}_{1}.bin'.format(i + 1, j)) code_file = open('temp', 'w') print(mask.format(passwords[i][1]), file=code_file) code_file.close() subprocess.check_call([ 'gpg', '--batch', '--yes', '--output', filename, '--clear-sign', 'temp']) os.unlink('temp') if mask == correct: continue code_file = open(filename, 'r') content = code_file.read() code_file.close() content = content.replace(passwords[i][1], common.gen_pass()) code_file = open(filename, 'w') code_file.write(content) code_file.close() print('generated') common.save_csv(_M(VARIANTS_DB), passwords) print('Created students tasks')
def gen(): """Generate students tasks""" common.check_env() common.create_module(__name__) students = common.load_students() if os.path.exists(_M(VARIANTS_DB)): passwords = [x for x in common.load_csv(_M(VARIANTS_DB))] else: passwords = [[x.name, '', '', '', ''] for x in students] for i, student in enumerate(students): print('Gen {0}: {1} '.format(i + 1, student), end='') if len(passwords[i][1]) > 0: print('skipped, already generated') continue print('generating...') variant = Variant() target, native = _gen_native(variant, _M('ref_{}.so'.format(i + 1)), debug=True) code = native.check(0, 0) reference = code >> 32 code = code & 0xFFFFFFFF passwords[i][1] = '{:08x}'.format(code) passwords[i][2] = '{}'.format(variant.mask) passwords[i][3] = '{}'.format(variant.nonce) passwords[i][4] = '{:08x}'.format(reference) target_dir = _M('stud_{}'.format(i + 1)) target_so = os.path.join(target_dir, 'native.so') target_cli = os.path.join(target_dir, 'cli.py') os.makedirs(target_dir, exist_ok=True) target, native = _gen_native(variant, target_so, reference=reference) shutil.copyfile(_R('cli.py'), target_cli) print('generated') shutil.rmtree(_M('tmp')) common.save_csv(_M(VARIANTS_DB), passwords) print('Created students tasks')
def gen(): """Generate students tasks""" common.check_env() common.create_module(__name__) students = common.load_students() if os.path.exists(_M(VARIANTS_DB)): passwords = [x for x in common.load_csv(_M(VARIANTS_DB))] else: passwords = [[x.name, ''] for x in students] for i, student in enumerate(students): print('Gen {0}: {1} '.format(i + 1, student), end='') if len(student.keybase) == 0: print('skipped, keybase account is not configured') continue if len(passwords[i][1]) > 0: print('skipped, already generated') continue print('generating...') passwords[i][1] = common.gen_pass() source_filename = 'file{0}.bin'.format(i + 1) target_filename = source_filename + '.gpg' code_file = open(_M(source_filename), 'w') print(MASK.format(passwords[i][1]), file=code_file) code_file.close() subprocess.check_call(['gpg', '--trust-model', 'always', '--yes', '-r', student.fingerprint, '-z', '0', '-e', _M(source_filename)]) os.unlink(_M(source_filename)) _broke(_M(target_filename)) print('checking...') container = OpenPgpContainer(_M(target_filename)) print('generated') common.save_csv(_M(VARIANTS_DB), passwords) print('Created students tasks')
def gen(): """Generate test env""" common.check_env() common.create_module(__name__) print('Created env')