def signed(s, arg=None, hide=False): """Sign a string, optionally with a time limit in minutes. The signed result contains the original string.""" if not arg: n = 60 else: try: n = int(arg) except: n = 60 return signatures.sign(s, minutes=n, hide=hide)
def compute_signature(self, key): alg = self.get_algorithm() print("Computing signature using alg {}".format(alg)) if alg is None: print("Signature algorithm not set") return False if str.capitalize(alg) == "NONE": return self.build_token_without_signature() # TODO reuse build_section content_to_sign = utils.base64url_encode( utils.force_bytes(json.dumps(self.header, separators=( ",", ":")))) + utils.force_bytes(".") + utils.base64url_encode( utils.force_bytes( json.dumps(self.payload, separators=(",", ":")))) return signatures.sign(alg, content_to_sign, key=key)
def __init__(self, certificates, prefix): self.prefix = prefix for c in certificates: c.id = self.prefix + str(c.id) self.certificates = {str(c.id) : c for c in certificates} self.private_key, self.public_key = generate_keys() self.base_url = 'http://janky.satyarth.me:5000/' certificates_strings = [str(c) for c in certificates] self.mht = MerkTree(certificates_strings) self.mht.create_tree() self.mht_root = self.mht.Get_Root_leaf() self.signature = sign(self.mht_root, self.private_key) self.transaction = None
def save_auth_cookie(request, args, m, remember): if m: flags = ("admin" if m.admin else "") timestamp = datetime.datetime.utcnow().strftime("%a, %d-%b-%Y %H:%M:%S GMT") zid = m.id.replace("\r","").replace("\n","") authcookie = stringstack.push(None, zid, m.name, m.display_name(), flags, timestamp) ## BOGUS REMOVE IN JULY (left here for possible testing) ##authcookie = stringstack.push(None, m.id, m.name, m.display_name(), flags, timestamp) authcookie = signatures.sign(authcookie) else: authcookie = None if remember: expiration = None # Permanent cookie else: expiration = 0 # Session cookie request.set_cookie(kiwioptions.AUTH_COOKIE_NAME, authcookie, expires=expiration, domain=kiwioptions.AUTH_COOKIE_DOMAIN) return authcookie
def build_token(self, key=None): content_to_sign = self.build_token_without_signature() return content_to_sign + utils.force_bytes('.') + signatures.sign( self.get_algorithm(), content_to_sign, key=key)
def test_none_signature(self): content_to_sign = self.tjwt.build_token_without_signature() self.assertEqual(b'', signatures.sign('none', content_to_sign)) self.assertEqual(b'', signatures.sign('None', content_to_sign)) self.assertEqual(b'', signatures.sign('NONE', content_to_sign))
def sign(self, private_key): message = self.__gather() new_sig = signatures.sign(message, private_key) self.sigs.append(new_sig)
def sign(self, private): """Signs the transactions with the private key""" message = self.__gather() newsigs = sign(message, private) self.sigs.append(newsigs)
def sign2(self, key): self.sig2 = sign(self.hash, key)
def sign1(self, key): self.sig1 = sign(self.hash, key)
def create_and_send_tx(client_socket: socket.socket, user): sender = utils.get_public_key(user) command = gui_metadata(TX_COMMAND) client_socket.send(command) inputs = [] N_inputs = int.from_bytes(client_socket.recv(4), 'little') for _ in range(N_inputs): input_data = client_socket.recv(159) inputs.append(utils.decode_input(input_data)) input_choices = [ { 'name': f'txID: {input.where_created} value: {input.value}', } for index, input in enumerate(inputs) ] recipient_choices = [ { 'name': 'Alice', }, { 'name': 'Bob', }, { 'name': 'Charlie', }, { 'name': 'No more pays', }, ] actions = [{ 'type': 'checkbox', 'name': INPUT_INDEX, 'message': 'Selecciona los inputs a ingresar en la transacción', 'choices': input_choices, }] recipient_actions = [{ 'type': 'list', 'name': 'recipient', 'message': 'Selecciona a la persona que le pagarás', 'choices': recipient_choices, }] value_actions = [{ 'type': 'input', 'name': 'value', 'message': '¿Cuánto le vas a pagar?', }] answers = prompt(actions) inputs_selected = answers.get(INPUT_INDEX) inputs_to_pay = [] for inputs_selected in inputs_selected: index = input_choices.index({'name': inputs_selected}) inputs_to_pay.append(inputs[index]) outputs = [] while True: answers = prompt(recipient_actions) answer = answers['recipient'] if answer == 'No more pays': break recipient = utils.get_public_key(answer) answers = prompt(value_actions) value = int(answers['value']) output = Output(value, recipient) outputs.append(output) unsigned = UnsignedTransaction(PAYCOINS_TYPE, inputs_to_pay, outputs) to_sign = unsigned.DataForSigs() signs = {} signs[sender.export_key(format='DER')] = sign(to_sign, utils.get_private_key(user)) transaction = Transaction(unsigned, signs) client_socket.send(transaction.serialize())
def confirm_tx(tx, root, key): return sign(u.sha3(tx.hash + root), key)