(self, myAddress)
| 307 | # If this isn't a chan address, this function assembles the pubkey data, |
| 308 | # does the necessary POW and sends it out. |
| 309 | def sendOutOrStoreMyV4Pubkey(self, myAddress): |
| 310 | if not BMConfigParser().has_section(myAddress): |
| 311 | #The address has been deleted. |
| 312 | return |
| 313 | if shared.BMConfigParser().safeGetBoolean(myAddress, 'chan'): |
| 314 | logger.info('This is a chan address. Not sending pubkey.') |
| 315 | return |
| 316 | status, addressVersionNumber, streamNumber, hash = decodeAddress( |
| 317 | myAddress) |
| 318 | |
| 319 | TTL = int(28 * 24 * 60 * 60 + random.randrange(-300, 300))# 28 days from now plus or minus five minutes |
| 320 | embeddedTime = int(time.time() + TTL) |
| 321 | payload = pack('>Q', (embeddedTime)) |
| 322 | payload += '\x00\x00\x00\x01' # object type: pubkey |
| 323 | payload += encodeVarint(addressVersionNumber) # Address version number |
| 324 | payload += encodeVarint(streamNumber) |
| 325 | dataToEncrypt = protocol.getBitfield(myAddress) |
| 326 | |
| 327 | try: |
| 328 | privSigningKeyBase58 = BMConfigParser().get( |
| 329 | myAddress, 'privsigningkey') |
| 330 | privEncryptionKeyBase58 = BMConfigParser().get( |
| 331 | myAddress, 'privencryptionkey') |
| 332 | except Exception as err: |
| 333 | logger.error('Error within sendOutOrStoreMyV4Pubkey. Could not read the keys from the keys.dat file for a requested address. %s\n' % err) |
| 334 | return |
| 335 | |
| 336 | privSigningKeyHex = hexlify(shared.decodeWalletImportFormat( |
| 337 | privSigningKeyBase58)) |
| 338 | privEncryptionKeyHex = hexlify(shared.decodeWalletImportFormat( |
| 339 | privEncryptionKeyBase58)) |
| 340 | pubSigningKey = unhexlify(highlevelcrypto.privToPub( |
| 341 | privSigningKeyHex)) |
| 342 | pubEncryptionKey = unhexlify(highlevelcrypto.privToPub( |
| 343 | privEncryptionKeyHex)) |
| 344 | dataToEncrypt += pubSigningKey[1:] |
| 345 | dataToEncrypt += pubEncryptionKey[1:] |
| 346 | |
| 347 | dataToEncrypt += encodeVarint(BMConfigParser().getint( |
| 348 | myAddress, 'noncetrialsperbyte')) |
| 349 | dataToEncrypt += encodeVarint(BMConfigParser().getint( |
| 350 | myAddress, 'payloadlengthextrabytes')) |
| 351 | |
| 352 | # When we encrypt, we'll use a hash of the data |
| 353 | # contained in an address as a decryption key. This way in order to |
| 354 | # read the public keys in a pubkey message, a node must know the address |
| 355 | # first. We'll also tag, unencrypted, the pubkey with part of the hash |
| 356 | # so that nodes know which pubkey object to try to decrypt when they |
| 357 | # want to send a message. |
| 358 | doubleHashOfAddressData = hashlib.sha512(hashlib.sha512(encodeVarint( |
| 359 | addressVersionNumber) + encodeVarint(streamNumber) + hash).digest()).digest() |
| 360 | payload += doubleHashOfAddressData[32:] # the tag |
| 361 | signature = highlevelcrypto.sign(payload + dataToEncrypt, privSigningKeyHex) |
| 362 | dataToEncrypt += encodeVarint(len(signature)) |
| 363 | dataToEncrypt += signature |
| 364 | |
| 365 | privEncryptionKey = doubleHashOfAddressData[:32] |
| 366 | pubEncryptionKey = highlevelcrypto.pointMult(privEncryptionKey) |
no test coverage detected