Bitcoin Forum
May 08, 2024, 10:56:50 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: wallet email backup script w/embedded encryption  (Read 1118 times)
kokjo (OP)
Legendary
*
Offline Offline

Activity: 1050
Merit: 1000

You are WRONG!


View Profile
April 23, 2012, 06:33:20 PM
Last edit: April 23, 2012, 06:43:54 PM by kokjo
 #1

Wrote this for a cronjob on my server, it might be useful for you.
Donations goes to 1JpsKmkim7REYq2EWE5aEXG8YN4zJTTX16
Code:
#!/usr/bin/python
import os
import sys
import smtplib
# For guessing MIME type based on file name extension
import mimetypes

from optparse import OptionParser
from email import encoders
from email.message import Message
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
import time
import Crypto.Cipher.AES as AES
import hashlib
import jsonrpc
import random

PASSWORD = "ENCRYPTION PASSWORD"
BITCOIN_USER = ""
BITCOIN_PASS = "BITCOIND PASSWORD"
TO_EMAIL = "someone@some.where"

DECRYPT_SCRIPT = """#!/usr/bin/python
import Crypto.Cipher.AES as AES
import hashlib
DATA = "%s"
CKSUM = "%s"
PASSWORD = raw_input("Password: ")
OUTPUTFILE = raw_input("Output file: ")
KEY = hashlib.sha256(PASSWORD).digest()
CRYPTER = AES.new(KEY, AES.MODE_CFB)

decrypted_data = CRYPTER.decrypt(DATA.decode("hex"))
if hashlib.sha256(decrypted_data).digest() == CKSUM.decode("hex"):
    open(OUTPUTFILE, "w").write(decrypted_data)
    print "wallet decrypted!"
else:
    print "Wrong password(cksum wrong)"
"""
BITCOIN_ACCESS = jsonrpc.ServiceProxy("http://%s:%s@127.0.0.1:8332"%(BITCOIN_USER, BITCOIN_PASS))
TEMPFILE = "/tmp/wallet.tmp.%d"%random.randint(0,2**23)

HOSTNAME = open("/etc/hostname").readline().strip("\n")
DATESTRING = time.ctime(time.time())
KEY = hashlib.sha256(PASSWORD).digest()
CRYPTER = AES.new(KEY, AES.MODE_CFB)

msg = MIMEMultipart()
msg['Subject'] = "Wallet Backup from %s on %s" %(HOSTNAME, DATESTRING)
msg['To'] = TO_EMAIL
msg['From'] = "walletbackup@%s" % HOSTNAME

BITCOIN_ACCESS.backupwallet(TEMPFILE)
walletdata = open(TEMPFILE, "r").read()

cksum = hashlib.sha256(walletdata).digest()
wallet = CRYPTER.encrypt(walletdata)

wallet_attachment = MIMEBase("application", "octet-stream")
wallet_attachment.set_payload(DECRYPT_SCRIPT % (wallet.encode("hex"), cksum.encode("hex")))
wallet_attachment.add_header('Content-Disposition', 'attachment', filename="decrypter.py")
encoders.encode_base64(wallet_attachment)

msg.attach(wallet_attachment)

#print msg.as_string()
s = smtplib.SMTP('localhost')
s.sendmail("walletbackup@%s" % HOSTNAME, TO_EMAIL, msg.as_string())
s.quit()

"The whole problem with the world is that fools and fanatics are always so certain of themselves and wiser people so full of doubts." -Bertrand Russell
1715209010
Hero Member
*
Offline Offline

Posts: 1715209010

View Profile Personal Message (Offline)

Ignore
1715209010
Reply with quote  #2

1715209010
Report to moderator
"Governments are good at cutting off the heads of a centrally controlled networks like Napster, but pure P2P networks like Gnutella and Tor seem to be holding their own." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715209010
Hero Member
*
Offline Offline

Posts: 1715209010

View Profile Personal Message (Offline)

Ignore
1715209010
Reply with quote  #2

1715209010
Report to moderator
kokjo (OP)
Legendary
*
Offline Offline

Activity: 1050
Merit: 1000

You are WRONG!


View Profile
May 04, 2012, 06:46:29 AM
 #2

BUMP! no one replyed?  Shocked I though i was writing good code, to help you people.

"The whole problem with the world is that fools and fanatics are always so certain of themselves and wiser people so full of doubts." -Bertrand Russell
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!