Exemple #1
0
 def verifySig(self):
     """
         Verify if a block's signature is signed by its claimed signer
     """
     if self.signer is None:
         return False
     if signing.ed_verify(data=self.signedData,
                          key=self.signer,
                          sig=self.signature,
                          encodedData=True):
         self.validSig = True
     else:
         self.validSig = False
     return self.validSig
Exemple #2
0
 def decrypt(self):
     plaintext = ""
     data = ""
     logger.info("Please enter your message (ctrl-d or -q to stop):",
                 terminal=True)
     keypair = getourkeypair.get_keypair()
     try:
         for line in sys.stdin:
             if line == '-q\n':
                 break
             data += line
     except KeyboardInterrupt:
         sys.exit(1)
     if len(data) <= 1:
         return
     encrypted = data.replace('ONIONR ENCRYPTED DATA ',
                              '').replace('END ENCRYPTED DATA', '')
     myPub = keypair[0]
     decrypted = encryption.pub_key_decrypt(encrypted,
                                            privkey=keypair[1],
                                            encodedData=True)
     if decrypted == False:
         logger.error("Decryption failed", terminal=True)
     else:
         data = json.loads(decrypted)
         logger.info('Decrypted Message: \n\n%s' % data['data'],
                     terminal=True)
         try:
             logger.info("Signing public key: %s" % (data['signer'], ),
                         terminal=True)
             if not signing.ed_verify(data['data'], data['signer'],
                                      data['sig']):
                 raise ValueError
         except (ValueError, KeyError) as e:
             logger.warn(
                 "WARNING: THIS MESSAGE HAS A MISSING OR INVALID SIGNATURE",
                 terminal=True)
         else:
             logger.info("Message has good signature.", terminal=True)
     return
Exemple #3
0
    def isSigner(self, signer, encodedData=True):
        """
            Checks if the block was signed by the signer inputted

            Inputs:
            - signer (str): the public key of the signer to check against
            - encodedData (bool): whether or not the `signer` argument is base64 encoded

            Outputs:
            - (bool): whether or not the signer of the block is the signer inputted
        """
        signer = unpaddedbase32.repad(bytesconverter.str_to_bytes(signer))
        try:
            if (not self.isSigned()) or (
                    not stringvalidators.validate_pub_key(signer)):
                return False

            return bool(
                signing.ed_verify(self.getSignedData(),
                                  signer,
                                  self.getSignature(),
                                  encodedData=encodedData))
        except:
            return False