def get_certification_document(current_block, self_cert_document, from_pubkey, salt, password): """ Create and return a Certification document :param dict current_block: Current block data :param Identity self_cert_document: Identity document :param str from_pubkey: Pubkey of the certifier :param str salt: Secret salt (DO NOT SHOW IT ANYWHERE, IT IS SECRET !!!) :param str password: Secret password (DO NOT SHOW IT ANYWHERE, IT IS SECRET !!!) :rtype: Certification """ # construct Certification Document certification = Certification(version=10, currency=current_block['currency'], pubkey_from=from_pubkey, pubkey_to=self_cert_document.pubkey, timestamp=BlockUID(current_block['number'], current_block['hash']), signature="") # sign document key = SigningKey(salt, password, ScryptParams(4096, 16, 1)) certification.sign(self_cert_document, [key]) return certification
async def certify(self, connection, secret_key, password, identity): """ Certify an other identity :param sakia.data.entities.Connection connection: the connection published :param str secret_key: the private key salt :param str password: the private key password :param sakia.data.entities.Identity identity: the identity certified """ self._logger.debug("Certdata") blockUID = self._blockchain_processor.current_buid(connection.currency) if not identity.signature: lookup_data = await self._bma_connector.get( connection.currency, bma.wot.lookup, req_args={'search': identity.pubkey}) for uid_data in next(data["uids"] for data in lookup_data["results"] if data["pubkey"] == identity.pubkey): if uid_data["uid"] == identity.uid and block_uid( uid_data["meta"]["timestamp"]) == identity.blockstamp: identity.signature = uid_data["self"] break else: return False, "Could not find certified identity signature" certification = Certification(10, connection.currency, connection.pubkey, identity.pubkey, blockUID, None) key = SigningKey(secret_key, password, connection.scrypt_params) certification.sign(identity.document(), [key]) signed_cert = certification.signed_raw(identity.document()) self._logger.debug("Certification : {0}".format(signed_cert)) timestamp = self._blockchain_processor.time(connection.currency) responses = await self._bma_connector.broadcast( connection.currency, bma.wot.certify, req_args={'cert': signed_cert}) result = await parse_bma_responses(responses) if result[0]: self._identities_processor.insert_or_update_identity(identity) self._certifications_processor.create_or_update_certification( connection.currency, certification, timestamp, BlockUID.empty()) return result
async def certify(self, request): data = await request.post() if self.reject_next_post: self.reject_next_post = False return {'ucode': errors.UNHANDLED, 'message': "Rejected"}, 400 certification = Certification.from_signed_raw(data["cert"]) self.forge.pool.append(certification) return {}, 200
async def certify(self, password, community, pubkey): """ Certify an other identity :param str password: The account SigningKey password :param sakia.core.community.Community community: The community target of the certification :param str pubkey: The certified identity pubkey """ logging.debug("Certdata") blockUID = community.network.current_blockUID identity = await self._identities_registry.future_find(pubkey, community) selfcert = await identity.selfcert(community) if selfcert: certification = Certification(PROTOCOL_VERSION, community.currency, self.pubkey, pubkey, blockUID, None) key = SigningKey(self.salt, password) certification.sign(selfcert, [key]) signed_cert = certification.signed_raw(selfcert) logging.debug("Certification : {0}".format(signed_cert)) data = {'cert': certification.signed_raw(selfcert)} logging.debug("Posted data : {0}".format(data)) responses = await community.bma_access.broadcast(bma.wot.Certify, {}, data) result = (False, "") for r in responses: if r.status == 200: result = (True, (await r.json())) # signal certification to all listeners self.certification_accepted.emit() elif not result[0]: result = (False, (await r.text())) else: await r.release() return result else: return False, self.tr("Could not find user self certification.")
async def certify(self, connection, secret_key, password, identity): """ Certify an other identity :param sakia.data.entities.Connection connection: the connection published :param str secret_key: the private key salt :param str password: the private key password :param sakia.data.entities.Identity identity: the identity certified """ self._logger.debug("Certdata") blockUID = self._blockchain_processor.current_buid(connection.currency) if not identity.signature: lookup_data = await self._bma_connector.get(connection.currency, bma.wot.lookup, req_args={'search': identity.pubkey}) for uid_data in next(data["uids"] for data in lookup_data["results"] if data["pubkey"] == identity.pubkey): if uid_data["uid"] == identity.uid and block_uid(uid_data["meta"]["timestamp"]) == identity.blockstamp: identity.signature = uid_data["self"] break else: return False, "Could not find certified identity signature" certification = Certification(10, connection.currency, connection.pubkey, identity.pubkey, blockUID, None) key = SigningKey(secret_key, password, connection.scrypt_params) certification.sign(identity.document(), [key]) signed_cert = certification.signed_raw(identity.document()) self._logger.debug("Certification : {0}".format(signed_cert)) timestamp = self._blockchain_processor.time(connection.currency) responses = await self._bma_connector.broadcast(connection.currency, bma.wot.certify, req_args={'cert': signed_cert}) result = await parse_bma_responses(responses) if result[0]: self._identities_processor.insert_or_update_identity(identity) self._certifications_processor.create_or_update_certification(connection.currency, certification, timestamp, None) return result
def get_certification_document(current_block: dict, self_cert_document: Identity, from_pubkey: str) -> Certification: """ Create and return a Certification document :param current_block: Current block data :param self_cert_document: Identity document :param from_pubkey: Pubkey of the certifier :rtype: Certification """ # construct Certification Document return Certification(version=10, currency=current_block['currency'], pubkey_from=from_pubkey, identity=self_cert_document, timestamp=BlockUID(current_block['number'], current_block['hash']), signature="")
async def certify(self, password, community, pubkey): """ Certify an other identity :param str password: The account SigningKey password :param sakia.core.community.Community community: The community target of the certification :param str pubkey: The certified identity pubkey """ logging.debug("Certdata") blockUID = community.network.current_blockUID try: identity = await self._identities_registry.future_find(pubkey, community) selfcert = await identity.selfcert(community) except LookupFailureError as e: return False, str(e) if selfcert: certification = Certification(PROTOCOL_VERSION, community.currency, self.pubkey, pubkey, blockUID, None) key = SigningKey(self.salt, password) certification.sign(selfcert, [key]) signed_cert = certification.signed_raw(selfcert) logging.debug("Certification : {0}".format(signed_cert)) data = {'cert': certification.signed_raw(selfcert)} logging.debug("Posted data : {0}".format(data)) responses = await community.bma_access.broadcast(bma.wot.Certify, {}, data) result = (False, "") for r in responses: if r.status == 200: result = (True, (await r.json())) # signal certification to all listeners self.certification_accepted.emit() elif not result[0]: result = (False, (await r.text())) else: await r.release() return result else: return False, self.tr("Could not find user self certification.")
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 certify(self, other, blockstamp): cert = Certification(10, self.currency, self.key.pubkey, other.key.pubkey, blockstamp, []) cert.sign(self.identity(), [self.key]) return cert