def get_identity_document(current_block, uid, salt, password): """ Get an Identity document :param dict current_block: Current block data :param str uid: Unique Identifier :param str salt: Passphrase of the account :param str password: Password of the account :rtype: Identity """ # get current block BlockStamp timestamp = BlockUID(current_block['number'], current_block['hash']) # create keys from credentials key = SigningKey(salt, password, ScryptParams(4096, 16, 1)) # create identity document identity = Identity(version=10, currency=current_block['currency'], pubkey=key.pubkey, uid=uid, ts=timestamp, signature=None) # sign document identity.sign([key]) return identity
def get_identity_document(current_block: dict, uid: str, salt: str, password: str) -> Identity: """ Get an Identity document :param current_block: Current block data :param uid: Unique Identifier :param salt: Passphrase of the account :param password: Password of the account :rtype: Identity """ # get current block BlockStamp timestamp = BlockUID(current_block['number'], current_block['hash']) # create keys from credentials key = SigningKey.from_credentials(salt, password) # create identity document identity = Identity( version=10, currency=current_block['currency'], pubkey=key.pubkey, uid=uid, ts=timestamp, signature=None ) # sign document identity.sign([key]) return identity
def get_identity_document( current_block: dict, uid: str, key: SigningKey, ) -> Identity: """ Get an Identity document :param current_block: Current block data :param uid: Unique IDentifier :param key: cryptographic key to sign documents :rtype: Identity """ # get current block BlockStamp timestamp = BlockUID(current_block["number"], current_block["hash"]) # create identity document identity = Identity( version=10, currency=current_block["currency"], pubkey=key.pubkey, uid=uid, ts=timestamp, signature=None, ) # sign document identity.sign([key]) return identity
def test_document_message(self): # prepare message document_message = DocumentMessage() # prepare document identity_document = Identity( 10, "beta_brousouf", "HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd", "lolcat", BlockUID(32, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD"), "J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBfCznzyci", ) # get json string message json_document_message = document_message.get_json( DocumentMessage.IDENTITY_TYPE_ID, identity_document.inline()) # convert to dict to verify dict_document_message = json.loads(json_document_message) # verify self.assertIn("body", dict_document_message) self.assertIn("name", dict_document_message["body"]) self.assertIn("identity", dict_document_message["body"]) self.assertEqual(4, dict_document_message["body"]["name"]) expected = """HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd\ :J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBfCznzyci:32\ -DB30D958EE5CB75186972286ED3F4686B8A1C2CD:lolcat""" self.assertEqual(expected, dict_document_message["body"]["identity"])
async def get_identity_document(connection, current_block, pubkey): """ Get the identity document of the pubkey :param bma.api.ConnectionHandler connection: Connection handler :param dict current_block: Current block data :param str pubkey: UID/Public key :rtype: Identity """ # Here we request for the path wot/lookup/pubkey lookup_data = await bma.wot.lookup(connection, pubkey) # init vars uid = None timestamp = BlockUID.empty() signature = None # parse results for result in lookup_data['results']: if result["pubkey"] == pubkey: uids = result['uids'] for uid_data in uids: # capture data timestamp = BlockUID.from_str(uid_data["meta"]["timestamp"]) uid = uid_data["uid"] signature = uid_data["self"] # return self-certification document return Identity(version=10, currency=current_block['currency'], pubkey=pubkey, uid=uid, ts=timestamp, signature=signature)
async def add(self, request): data = await request.post() if self.reject_next_post: self.reject_next_post = False return {'ucode': errors.UNHANDLED, 'message': "Rejected"}, 400 identity = Identity.from_signed_raw(data["identity"]) self.forge.pool.append(identity) return {}, 200
def import_identity_document(self): file_name = QFileDialog.getOpenFileName(self, self.tr("Open identity document"), "", self.tr("Duniter documents (*.txt)")) if file_name and file_name[0]: with open(file_name[0], 'r') as open_file: raw_text = open_file.read() try: identity_doc = Identity.from_signed_raw(raw_text) self.identity_document_imported.emit(identity_doc) except MalformedDocumentError as e: QMessageBox.warning(self, self.tr("Identity document"), self.tr("The imported file is not a correct identity document"), QMessageBox.Ok)
def import_identity_document(self): file_name = QFileDialog.getOpenFileName(self, self.tr("Open identity document"), "", self.tr("Duniter documents (*.txt)")) if file_name: with open(file_name[0], 'r') as open_file: raw_text = open_file.read() try: identity_doc = Identity.from_signed_raw(raw_text) self.identity_document_imported.emit(identity_doc) except MalformedDocumentError as e: QMessageBox.warning(self, self.tr("Identity document"), self.tr("The imported file is not a correct identity document"), QMessageBox.Ok)
async def broadcast_identity(self, connection, secret_key, password): """ Send our self certification to a target community :param sakia.data.entities.Connection connection: the connection published :param str secret_key: the private key secret key :param str password: the private key password """ block_uid = self._blockchain_processor.current_buid( connection.currency) timestamp = self._blockchain_processor.time(connection.currency) selfcert = IdentityDoc(10, connection.currency, connection.pubkey, connection.uid, block_uid, None) key = SigningKey(secret_key, password, connection.scrypt_params) selfcert.sign([key]) self._logger.debug("Key publish : {0}".format(selfcert.signed_raw())) responses = await self._bma_connector.broadcast( connection.currency, bma.wot.add, req_args={'identity': selfcert.signed_raw()}) result = await parse_bma_responses(responses) if result[0]: identity = self._identities_processor.get_identity( connection.currency, connection.pubkey, connection.uid) if not identity: identity = Identity(connection.currency, connection.pubkey, connection.uid) identity.blockstamp = block_uid identity.signature = selfcert.signatures[0] identity.timestamp = timestamp else: identity = None return result, identity
async def get_identity_document(client: Client, current_block: dict, pubkey: str) -> Optional[Identity]: """ Get the identity document of the pubkey :param client: Client to connect to the api :param current_block: Current block data :param pubkey: UID/Public key :rtype: Identity """ # Here we request for the path wot/lookup/pubkey lookup_data = await client(bma.wot.lookup, pubkey) identity = None # parse results for result in lookup_data["results"]: if result["pubkey"] == pubkey: uids = result["uids"] uid_data = uids[0] # capture data timestamp = BlockUID.from_str(uid_data["meta"]["timestamp"]) uid = uid_data["uid"] # type: str signature = uid_data["self"] # type: str # return self-certification document identity = Identity( version=10, currency=current_block["currency"], pubkey=pubkey, uid=uid, ts=timestamp, signature=signature, ) break return identity
async def get_identity_document(client: Client, currency: str, pubkey: str) -> Identity: """ Get the Identity document of the pubkey :param client: Client to connect to the api :param currency: Currency name :param pubkey: Public key :rtype: Identity """ # Here we request for the path wot/lookup/pubkey lookup_data = await client(bma.wot.lookup, pubkey) # init vars uid = None timestamp = BlockUID.empty() signature = None # parse results for result in lookup_data['results']: if result["pubkey"] == pubkey: uids = result['uids'] for uid_data in uids: # capture data timestamp = BlockUID.from_str(uid_data["meta"]["timestamp"]) uid = uid_data["uid"] signature = uid_data["self"] # return self-certification document return Identity(version=PROTOCOL_VERSION, currency=currency, pubkey=pubkey, uid=uid, ts=timestamp, signature=signature)
async def send_certification(uid_pubkey_to_certify): client = ClientInstance().client checked_pubkey = is_pubkey_and_check(uid_pubkey_to_certify) if checked_pubkey: uid_pubkey_to_certify = checked_pubkey idty_to_certify, pubkey_to_certify, send_certs = await wot.choose_identity( uid_pubkey_to_certify) # Authentication key = auth_method() # Check whether current user is member issuer_pubkey = key.pubkey issuer = await wot.is_member(issuer_pubkey) if not issuer: message_exit("Current identity is not member.") if issuer_pubkey == pubkey_to_certify: message_exit("You can’t certify yourself!") # Check if the certification can be renewed req = await client(bma.wot.requirements, pubkey_to_certify) req = req["identities"][0] for cert in req["certifications"]: if cert["from"] == issuer_pubkey: params = await BlockchainParams().params # Ğ1: 0<–>2y - 2y + 2m # ĞT: 0<–>4.8m - 4.8m + 12.5d renewable = cert["expiresIn"] - params["sigValidity"] + params[ "sigReplay"] if renewable > 0: renewable_date = convert_time(time() + renewable, "date") message_exit("Certification renewable the " + renewable_date) # Check if the certification is already in the pending certifications for pending_cert in req["pendingCerts"]: if pending_cert["from"] == issuer_pubkey: message_exit("Certification is currently been processed") # Display license and ask for confirmation head = await HeadBlock().head_block currency = head["currency"] license_approval(currency) # Certification confirmation await certification_confirmation(issuer, issuer_pubkey, pubkey_to_certify, idty_to_certify) identity = Identity( version=10, currency=currency, pubkey=pubkey_to_certify, uid=idty_to_certify["uid"], ts=block_uid(idty_to_certify["meta"]["timestamp"]), signature=idty_to_certify["self"], ) certification = Certification( version=10, currency=currency, pubkey_from=issuer_pubkey, identity=identity, timestamp=BlockUID(head["number"], head["hash"]), signature="", ) # Sign document certification.sign([key]) # Send certification document response = await client(bma.wot.certify, certification.signed_raw()) if response.status == 200: print("Certification successfully sent.") else: print("Error while publishing certification: {0}".format( await response.text())) await client.close()
def identity(self): identity = Identity(10, self.currency, self.key.pubkey, self.uid, self.blockstamp, []) identity.sign([self.key]) return identity