def test_add_user_data(ident_service): # No transactions in the chain yet assert ident_service.last_transaction_hash == b'Base' # Create the data and signature data = json.dumps({'first_name': 'Bob', 'last_name': 'Smith'}).encode() signature = sign(user_1_private_key, data) user_data = UserData(data, signature) # Add the data to the service tx_hash = ident_service.add_user_data(user_data, user_1_cert_string) # Ensure the head of the chain is the new transaction assert tx_hash == ident_service.last_transaction_hash # Get the transaction and encryption key tx = ident_service.get_transaction(tx_hash) key = ident_service.get_key(tx_hash) # Ensure the transaction points to the old head of the chain assert tx.hash_pointer == b'Base' # Get the message and signature from the transaction decrypted = decrypt(key, tx.action.get_data()) message, signature = split_data(decrypted) # Ensure the data has not been tampered with verify(user_1_cert, message, signature) # Ensure the data matches what the user uploaded assert message == data
def login(): try: if ('username' in session) and ('password' in session): #already logged in alert = "You are already logged in!" flash(alert, 'error') return redirect( redirect_url() ) elif request.method == 'GET': return render_template('login.html') else: #login username = request.form.get('username') password = request.form.get('password') alertList = ["Successfully logged in!", \ "Username cannot be left blank!", \ "Passwords cannot be left blank!", \ "Username does not exist! Please retry or make a new account.", \ "Password for %s is incorrect. Please retry or make a new account" % username] verifInt = util.verify(username, password) if verifInt == 0: #success session['username'] = request.form['username'] session['password'] = request.form['password'] flash( alertList[0], 'success' ) return redirect( url_for('index') ) else: flash( alertList[verifInt], 'error' ) return render_template("login.html") except Exception, e: return str(e)
def test_sign(): key = base64.b64encode('abc') string_to_sign = '/account/GET200601021504' signature = util.sign(string_to_sign, key) assert util.verify( string_to_sign, key, signature) is True
def verify(): global image_data1 global image_data2 result = util.verify(image_data1, image_data2) image_data1 = None image_data2 = None return render_template('app.html', result=result)
def verify_signature(): signature = request.args.get('signature') sender_pubkey = request.args.get('publickey') timestamp = request.args.get('timestamp') result = verify(sender_pubkey, timestamp, signature) if result: return jsonify("Verified"), 200 else: return jsonify("Not Verified"), 200
def analyze_fun_def(self, Γ, f, args, return_type, body): arg_types = [] nested_Γ = Γ.copy() for arg in args: a, t = T.from_ast(arg) nested_Γ.annotate(a, t, fixed=True) arg_types.append(t) r = T.from_ast(return_type) arg_types = T.Tuple(arg_types) if len(arg_types) != 1 else arg_types[0] fun_type = T.Fun(arg_types, r) nested_Γ.annotate(f, fun_type, fixed=True) polymorphic_fun_type = fun_type.fresh(Γ.fixed) #print('fun_type =', fun_type) #print('polymorphic_fun_type =', polymorphic_fun_type) Γ1, _ < -analyze_body(self.returning(r), nested_Γ, body) U.verify(Γ1) return [(Γ.annotate(f, polymorphic_fun_type), None)]
def check(self, ast): try: pairs = self.analyze([C.Context()], ast) state = C.State([s for s, _ in pairs]) return U.verify(state) except (ValueError, CheckError, T.UnificationError) as e: if not self.careful and 'Unsatisfiable constraint' in str(e): self.carefully().check(ast) else: raise
def test_share_data(ident_service): # Create the user data data = json.dumps({'first_name': 'Bob', 'last_name': 'Smith'}).encode() signature = sign(user_1_private_key, data) user_data = UserData(data, signature) # Add the user's data to the service tx_hash = ident_service.add_user_data(user_data, user_1_cert_string) # Create data to share with the service provider shared_data = json.dumps({'first_name': 'Bob'}).encode() signature = sign(user_1_private_key, shared_data) shared_user_data = UserData(shared_data, signature) # Add the shared data to the identity service shared_tx_hash = ident_service.share_data(shared_user_data, user_1_cert_string, sp_1_cert) # Ensure the head of the chain is the new transaction assert ident_service.last_transaction_hash == shared_tx_hash # Get the share transaction share_tx = ident_service.get_transaction(shared_tx_hash) # Ensure the share transaction points to the previous head of the chain assert tx_hash == share_tx.hash_pointer # As the service provider, get the encryption key and decrypt the data encrypted_encryption_key, encrypted_data = split_data( share_tx.action.get_data()) decrypted_encryption_key = decrypt_private(sp_1_private_key, encrypted_encryption_key) share_decrypted = decrypt(decrypted_encryption_key, encrypted_data) share_message, share_signature = split_data(share_decrypted) # Verify the data is signed by the user and hasn't been tampered with verify(user_1_cert, share_message, share_signature) # Ensure the data matches what the user uploaded to the service assert share_message == shared_data
def colorGradual(self, to, number): verify(to) colors = [] sgl = 1 / number from_color = self.hex2rgb() to_color = self.hex2rgb(to) diffs = [x > 0 for x in listDec(from_color, to_color)] diffc = [abs(x) for x in listDec(from_color, to_color)] props = [round(sgl * x) for x in diffc] for i in range(number): cs = [] for cp in range(len(diffs)): c = from_color[cp] + props[cp] * i if diffs[ cp] else from_color[cp] - props[cp] * i cs.append(c) colors.append(cs) cs = [] colors.append(to_color) self.printColors(colors)
def index(): try: #loggedIn = False if ('username' in session) and ('password' in session): username = session['username'] password = session['password'] verifInt = util.verify(username, password) if verifInt == 0: #successful login body_title = "Welcome back to SolRoute, %s!" % username else: alert = "We have detected that you have an invalid session ID. Please login again." flash(alert, 'error') return render_template("index.html") else: body_title = "Welcome to SolRoute!" return render_template('index.html', body_title=body_title) except Exception, e: return str(e)
def run_problem(primal_xele, primal_yele, primal_zele): """ Workhouse for running mesh refinement studies Args: [primal_xele, yele, zele] -- Numbers of elements. Primal_zele == nan in 2D """ global true_err, computed_QoI import data import primal_newton as primal import util import BC_factory primal_mesh, adjoint_mesh = setup_meshes(primal_xele, primal_yele, primal_zele, data.mult) W_primal, W_adjoint = setup_spaces(primal_mesh, adjoint_mesh, data.lo_u, data.lo_p, data.lo_B, data.ho_u, data.ho_p, data.ho_B) # True solution ut = util.HartmannVelocity(degree=6) # For splitting, uDirichlet if data.use_lifting: ud = BC_factory.get_ud(W_primal, primal_mesh, ut) else: ud = None # True soltution Bt = util.HartmannBField(degree=6) if data.experiment_name == "TaylorGreen": RHS = util.TaylorGreenRHS(degree=7) else: RHS = util.HartmannRHS(degree=6) (u0, p0, B0) = primal.solve_exact_penalty(W_primal, RHS, ut, ud, Bt, primal_xele, primal_yele) psi_u = get_qoi_psi(primal_mesh, "u") psi_B = get_qoi_psi(primal_mesh, "B") computed_QoI, true_err = util.verify(u0, ud, p0, B0, psi_u, psi_B, primal_mesh, rank) if data.do_adjoint_analysis: if data.use_lifting: solve_adjoint_problem(W_adjoint, adjoint_mesh, u0 + ud, p0, B0, psi_u, psi_B, RHS) else: solve_adjoint_problem(W_adjoint, adjoint_mesh, u0, p0, B0, psi_u, psi_B, RHS)
def post_result(service, category, username): with get_db() as conn: c = conn.cursor() # Check for service and category c.execute("SELECT 1 FROM service WHERE id = ?", (service, )) if not c.fetchone(): raise APIError("Service not found") # get the JSON try: key = get_secret(service) data = request.get_json(force=True) if not verify(data, key): raise Exception except: raise APIError("Bad JSON") score = (service, category, username, data["date"], data["result"], data["detail"]) c.execute("""INSERT INTO score VALUES (?,?,?,?,?,?)""", score) return 'Successful'
def main(): if request.method == "POST": file1 = request.files["file1"].read() file2 = request.files["file2"].read() try: npimg1 = numpy.fromstring(file1, numpy.uint8) npimg2 = numpy.fromstring(file2, numpy.uint8) img1 = cv2.imdecode(npimg1, cv2.IMREAD_UNCHANGED) img2 = cv2.imdecode(npimg2, cv2.IMREAD_UNCHANGED) result = util.verify(img1, img2) if result[19] == 's': return render_template("index.html", result1=result) else: return render_template("index.html", result2=result) except: return render_template("index.html", message='Upload only images') return render_template("index.html")
def test_add_share_edit(ident_service): # Create the initial user data data = json.dumps({'first_name': 'Bob', 'last_name': 'Smith'}).encode() signature = sign(user_1_private_key, data) user_data = UserData(data, signature) # Add the user data to the service initial_tx_hash = ident_service.add_user_data(user_data, user_1_cert_string) # Create data to share with the service provider shared_data = json.dumps({'first_name': 'Bob'}).encode() signature = sign(user_1_private_key, shared_data) shared_user_data = UserData(shared_data, signature) # Add the shared data to the identity service shared_tx_hash = ident_service.share_data(shared_user_data, user_1_cert_string, sp_1_cert) # Ensure the head of the chain has been updated assert ident_service.last_transaction_hash == shared_tx_hash # Create updated user data data_2 = json.dumps({ 'first_name': 'Robert', 'last_name': 'Smith', 'age': 35 }).encode() signature_2 = sign(user_1_private_key, data_2) updated_user_data = UserData(data_2, signature_2) # Update the user's data on the identity service updated_tx_hash = ident_service.add_user_data(updated_user_data, user_1_cert_string) # Ensure the head of the chain has been updated assert updated_tx_hash == ident_service.latest_tx_list[user_1_cert_string] # Ensure the user's latest hash has been updated assert updated_tx_hash == ident_service.last_transaction_hash # Get the updated data transaction updated_tx = ident_service.get_transaction(updated_tx_hash) # Ensure the transaction points to the previous head of the chain assert updated_tx.hash_pointer == shared_tx_hash # Get the share transaction share_tx = ident_service.get_transaction(shared_tx_hash) # Ensure the share transaction points to the initial user data transaction assert initial_tx_hash == share_tx.hash_pointer # As the service provider, get the message and signature from the transaction encrypted_encryption_key, encrypted_data = split_data( share_tx.action.get_data()) decrypted_encryption_key = decrypt_private(sp_1_private_key, encrypted_encryption_key) share_decrypted = decrypt(decrypted_encryption_key, encrypted_data) share_message, share_signature = split_data(share_decrypted) # Ensure the data is valid verify(user_1_cert, share_message, share_signature) # Ensure the data matches what the user uploaded at the time of # creating the share transaction and not the new user data. assert share_message == shared_data
def analyze_body(self, Γ, body, k=no_op): for a in __, Γ < -body: Γ, _ < -self.analyze([Γ], a) if self.careful: U.verify(Γ) return k(Γ, None)
def __init__(self, color): verify(color) self.colorStr = color
def test_signature_neg(self): util.get_keys("") res = util.make_post_signature(dict(test="1234")) self.assertFalse(util.verify(bytes(res["signature"][:-1]), res["data"], res["pub"].decode()))
def test_multiple_users(ident_service): assert ident_service.last_transaction_hash == b'Base' # Create the first user's data data_1 = json.dumps({'first_name': 'Bob', 'last_name': 'Smith'}).encode() signature_1 = sign(user_1_private_key, data_1) user_data = UserData(data_1, signature_1) # Add the first user's data to the identity service user_1_tx_hash = ident_service.add_user_data(user_data, user_1_cert_string) # Ensure the head of the chain has been updated assert user_1_tx_hash == ident_service.last_transaction_hash # Create the second user's data data_2 = json.dumps({'first_name': 'Sally', 'last_name': 'Jones'}).encode() signature_2 = sign(user_2_private_key, data_2) user_data_2 = UserData(data_2, signature_2) # Add the second user's data to the identity service user_2_tx_hash = ident_service.add_user_data(user_data_2, user_2_cert_string) # Ensure the head of the chain has been updated assert user_2_tx_hash == ident_service.last_transaction_hash # Get the first user's transaction user_1_tx = ident_service.get_transaction(user_1_tx_hash) key_1 = ident_service.get_key(user_1_tx_hash) # Ensure the first user's transaction points to the base hash pointer assert user_1_tx.hash_pointer == b'Base' # Decrypt the first user's data decrypted_1 = decrypt(key_1, user_1_tx.action.get_data()) message_1, signature_1 = split_data(decrypted_1) # Validate the first user's data verify(user_1_cert, message_1, signature_1) # Ensure the data from the transaction matches the data the first # user uploaded assert message_1 == data_1 # Get the second user's transaction user_2_tx = ident_service.get_transaction(user_2_tx_hash) key_2 = ident_service.get_key(user_2_tx_hash) # Ensure the second user's transaction points to the first user's # transaction assert user_2_tx.hash_pointer == user_1_tx_hash # Decrypt the second user's transaction decrypted_2 = decrypt(key_2, user_2_tx.action.get_data()) message_2, signature_2 = split_data(decrypted_2) # Validate the second user's data verify(user_2_cert, message_2, signature_2) # Ensure the data from the transaction matches the data that the # second user uploaded to the identity service assert message_2 == data_2 # Ensure the latest transaction hash for the first and second # user match what we expect. assert ident_service.latest_tx_list[user_1_cert_string] == user_1_tx_hash assert ident_service.latest_tx_list[user_2_cert_string] == user_2_tx_hash
if len(window) < window_size: continue decide() # drain the window while window: decide() return _unkeyify(result) DROPSORTS = ( dropsort, dropsort_between, _curry(dropsort_consecutive, 10), # TODO pick ideal n _curry(dropsort_between_consecutive, 10), # TODO pick ideal n dropsort_minmax, _curry(dropsort_window, 10), # TODO pick ideal n ) PARAMETERIZED_DROPSORTS = ( dropsort_consecutive, dropsort_between_consecutive, dropsort_window ) # basic verify if __name__ == '__main__': for f in (dropsort, drop_merge_sort, dropsort_between, dropsort_consecutive, dropsort_between_consecutive, dropsort_minmax, dropsort_window): util.verify(f)