MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / sendOutOrStoreMyV3Pubkey

Method sendOutOrStoreMyV3Pubkey

src/class_singleWorker.py:221–305  ·  view source on GitHub ↗
(self, hash)

Source from the content-addressed store, hash-verified

219 # assembles the pubkey and stores is in the pubkey table so that we can
220 # send messages to "ourselves".
221 def sendOutOrStoreMyV3Pubkey(self, hash):
222 try:
223 myAddress = shared.myAddressesByHash[hash]
224 except:
225 #The address has been deleted.
226 return
227 if BMConfigParser().safeGetBoolean(myAddress, 'chan'):
228 logger.info('This is a chan address. Not sending pubkey.')
229 return
230 status, addressVersionNumber, streamNumber, hash = decodeAddress(
231 myAddress)
232
233 TTL = int(28 * 24 * 60 * 60 + random.randrange(-300, 300))# 28 days from now plus or minus five minutes
234 embeddedTime = int(time.time() + TTL)
235 signedTimeForProtocolV2 = embeddedTime - TTL
236 """
237 According to the protocol specification, the expiresTime along with the pubkey information is
238 signed. But to be backwards compatible during the upgrade period, we shall sign not the
239 expiresTime but rather the current time. There must be precisely a 28 day difference
240 between the two. After the upgrade period we'll switch to signing the whole payload with the
241 expiresTime time.
242 """
243 payload = pack('>Q', (embeddedTime))
244 payload += '\x00\x00\x00\x01' # object type: pubkey
245 payload += encodeVarint(addressVersionNumber) # Address version number
246 payload += encodeVarint(streamNumber)
247 payload += protocol.getBitfield(myAddress) # bitfield of features supported by me (see the wiki).
248
249 try:
250 privSigningKeyBase58 = BMConfigParser().get(
251 myAddress, 'privsigningkey')
252 privEncryptionKeyBase58 = BMConfigParser().get(
253 myAddress, 'privencryptionkey')
254 except Exception as err:
255 logger.error('Error within sendOutOrStoreMyV3Pubkey. Could not read the keys from the keys.dat file for a requested address. %s\n' % err)
256
257 return
258
259 privSigningKeyHex = hexlify(shared.decodeWalletImportFormat(
260 privSigningKeyBase58))
261 privEncryptionKeyHex = hexlify(shared.decodeWalletImportFormat(
262 privEncryptionKeyBase58))
263 pubSigningKey = unhexlify(highlevelcrypto.privToPub(
264 privSigningKeyHex))
265 pubEncryptionKey = unhexlify(highlevelcrypto.privToPub(
266 privEncryptionKeyHex))
267
268 payload += pubSigningKey[1:]
269 payload += pubEncryptionKey[1:]
270
271 payload += encodeVarint(BMConfigParser().getint(
272 myAddress, 'noncetrialsperbyte'))
273 payload += encodeVarint(BMConfigParser().getint(
274 myAddress, 'payloadlengthextrabytes'))
275
276 signature = highlevelcrypto.sign(payload, privSigningKeyHex)
277 payload += encodeVarint(len(signature))
278 payload += signature

Callers 1

runMethod · 0.95

Calls 14

BMConfigParserClass · 0.90
InventoryClass · 0.90
PendingUploadClass · 0.90
decodeAddressFunction · 0.85
encodeVarintFunction · 0.85
calculateInventoryHashFunction · 0.85
safeGetBooleanMethod · 0.80
signMethod · 0.80
addMethod · 0.80
putMethod · 0.80
setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected