PyBitmessage

repository·v0.6·Indexed 25 days ago

https://github.com/bitmessage/pybitmessage

A Python implementation of the Bitmessage P2P protocol for decentralized, encrypted, and anonymous communication. The project includes PyElliptic, a Python 3 wrapper for OpenSSL providing ECC and symmetric cryptography. Documentation covers ECIES encryption schemes, Proof of Work (POW) generation and verification, Bitmessage address formats (v1-v4), and installation guides for Windows, OSX, Arch Linux, and FreeBSD.

Tokens
11.9K
Snippets
25
Records
97
Agent score
84%

What's inside pybitmessage

  1. Overview of PyBitmessage

    v0.6

    PyBitmessage implements the Bitmessage P2P communication protocol. It is a decentralized and trustless system designed for sending encrypted messages to individuals or multiple subscribers. Key features include:

    • Strong Authentication: Prevents message spoofing.
    • Metadata Protection: Aims to hide sender and receiver identities from passive eavesdroppers.
    • Anonymity: Designed to keep participants anonymous within the network.
  2. Understand Bitmessage Address Formats

    v0.6

    Bitmessage addresses are Base58 encoded public key hashes. They typically follow the format BM-BcbRqcFFSQUUmXFKsPJgVQPSiFA3Xash.

    Key characteristics:

    • Prefix: All addresses start with BM-, though PyBitmessage is designed to accept addresses without this prefix to facilitate easier copy-pasting.
    • Length: Without the BM- prefix, addresses are typically 32-34 characters long.
    • Verification: Addresses are used to verify senders. A message's authenticity is confirmed by attempting to decrypt a specific field in the data packet using the public key associated with the address. Successful decryption proves the message originated from that address.
    • Base58 Encoding: Bitmessage uses the Bitcoin-style Base58 alphabet: 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz. Note that some standard Base58 libraries may use different character orderings.
  3. Understand Bitmessage Encryption Scheme

    v0.6

    Bitmessage uses the Elliptic Curve Integrated Encryption Scheme (ECIES) to encrypt the payloads of Message and Broadcast objects.

    Key cryptographic components include:

    • Key Exchange: Elliptic Curve Diffie-Hellman (ECDH) to generate a shared secret.
    • Encryption: AES-256-CBC with a 256-bit key.
    • Padding: PKCS7 (padding to a 16-byte boundary).
    • Key Derivation: SHA512 is used to derive AES key material from the shared secret.
    • Authentication: HMACSHA256 is used for the Message Authentication Code (MAC).
  4. Add comments to a Bitmessage User Agent

    v0.6

    You can include an optional comments field immediately following the version number. Comments must be delimited by parentheses (...). While the content is implementation-defined, it is recommended to use semi-colons (;) to separate different pieces of information within the comment.

    Example: /cBitmessage:0.2(iPad; U; CPU OS 3_2_1)/AndroidBuild:0.8/

    /cBitmessage:0.2(iPad; U; CPU OS 3_2_1)/AndroidBuild:0.8/
  5. Compare Random vs Deterministic Address Types

    v0.6

    PyBitmessage supports two methods of address generation. While the resulting addresses are functionally identical, the generation process and use cases differ:

    Random Address

    Generated from a randomly chosen number.

    • Security: The address cannot be regenerated without the original random number and the keys.dat file. Always back up keys.dat.
    • Performance: Generation takes slightly longer because it requires Proof of Work (POW) for the public key broadcast.
    • Best Use Cases:
      • Generating unique, long-term addresses.
      • Generating one-time use addresses.

    Deterministic Address

    Generated using a passphrase to seed a random generator.

    • Security: Use caution. Using common words or numbers as passphrases allows others to generate the same address and intercept your messages.
    • Performance: Does not publish the public key immediately; the key is only sent upon request, which saves POW time when generating multiple addresses.
    • Best Use Cases:
      • Recreating the same address on multiple systems without transferring keys.dat or Address Blocks.
      • Creating Channels.
      • Restoring addresses in the event of database corruption or deletion.
  6. Install and use PyElliptic

    v0.6

    PyElliptic is a high-level Python 3 wrapper for OpenSSL. It provides asymmetric cryptography (ECC), symmetric cryptography (AES, Blowfish, RC4), and other primitives like CSPRNG, HMAC, and PBKDF2.

    Requirements:

    • Python 3
    • OpenSSL installed on the system
    • Compatible with GNU/Linux and Windows.
  7. Format Bitmessage User Agent strings

    v0.6

    Bitmessage user agents use a structured stack format to identify software. The stack is arranged from the most underlying software to the most specific, with each component enclosed in forward slashes (/).

    Basic Format: /Name:Version/Name:Version/.../

    Reserved Symbols: Do not use the following characters within names or versions as they are reserved for syntax:

    • / (separates the code-stack)
    • : (separates implementation name from version)
    • ( and ) (delimits comments)

    Version Recommendations:

    • Use Major.Minor.Revision (e.g., 2.6.41).
    • For repository builds, use a date in YYYYMMDD format (e.g., 20110128).
    • You may append -r1, -r2, etc., to version numbers.
    /PyBitmessage:0.2.2/Corporate Mail System:0.8/
    /Surdo:5.64/surdo-qt:0.4/
  8. Build PyBitmessage AppImage using Docker

    v0.6

    If you want to build an AppImage from your local code, you must have docker installed. The resulting AppImage will be placed in the dist directory.

    $ docker build -t bm-appimage -f .buildbot/appimage/Dockerfile .
    $ docker run -t --rm -v "$(pwd)"/dist:/out bm-appimage
  9. Verify dependencies for source installation

    v0.6

    Before building from source, run the checkdeps.py script in the PyBitmessage source directory to identify missing dependencies. You must repeat the script until no mandatory dependencies are reported as missing.

    python checkdeps.py