Last active
September 27, 2023 16:19
-
-
Save geeknik/5a75459c89d0184dcc406dfe2768093b to your computer and use it in GitHub Desktop.
lightning network anti-spam poc for sending/receiving email
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ecdsa import SigningKey, VerifyingKey | |
import smtplib | |
from email.mime.text import MIMEText | |
import lnd_grpc | |
import imaplib | |
import email | |
# Initialize Lightning Network client (Assumes LND is running) | |
lnd_client = lnd_grpc.Client() | |
# Generate ECDSA keys for sender and receiver | |
sk = SigningKey.generate() # Sender's private key | |
vk = sk.get_verifying_key() # Sender's public key | |
# Step 1: Initiate Lightning Network Payment | |
payment_request = lnd_client.add_invoice(value=10) | |
pending_payment = lnd_client.send_payment(payment_request) | |
# Step 2: Generate Cryptographic Signature | |
email_content = "Hello, this is a test email." | |
signature = sk.sign(email_content.encode()) | |
# Step 3: Send Email with Signature | |
server = smtplib.SMTP('smtp.example.com', 587) | |
server.starttls() | |
server.login("[email protected]", "password") | |
msg = MIMEText(email_content) | |
msg['Subject'] = 'Test Email' | |
msg['From'] = '[email protected]' | |
msg['To'] = '[email protected]' | |
msg['X-Crypto-Signature'] = signature.hex() | |
server.send_message(msg) | |
server.quit() | |
# Receiver's Email Verification | |
mail = imaplib.IMAP4_SSL('imap.example.com') | |
mail.login('[email protected]', 'password') | |
mail.select('inbox') | |
status, messages = mail.search(None, 'ALL') | |
email_ids = messages[0].split() | |
latest_email_id = email_ids[-1] | |
status, msg_data = mail.fetch(latest_email_id, '(RFC822)') | |
raw_email = msg_data[0][1] | |
received_email = email.message_from_bytes(raw_email) | |
received_signature = received_email['X-Crypto-Signature'] | |
received_content = received_email.get_payload() | |
# Verify the signature | |
if vk.verify(bytes.fromhex(received_signature), received_content.encode()): | |
print("Email is verified.") | |
lnd_client.settle_payment(pending_payment) | |
else: | |
print("Email verification failed.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment