Ejemplo n.º 1
0
def msg_list(l,s,f):
    global login

    if login==None:
	return '-BAD_LOGIN'

    db=start_db()

    ret=''
    
    dumps=db.get('MSG_USR_' + login)
    if dumps:
        msgs=pickle.loads(dumps)
    else:
	msgs={}
    
    for x in msgs.keys():
	msg_from=db.get('MSG_FROM_' + str(x))
	ret+=msg_from + ' ' + str(x) + "\n"

    ret+='+0'
    return ret
Ejemplo n.º 2
0
def msg_read(l,s,f):
    global login
    
    if len(l)<1:
	return '-ISE:Too few params!'
    
    mid=l[0]
    
    if login==None:
	return '-NO_PERM'

    key=('MSG_' + str(mid))

    db=start_db()
    ret="+OK\n"
    if db.has_key(key):
	ret+=db.get('MSG_' + str(mid))
    ret+="\n"
    ret+='+0'
    
    return ret
Ejemplo n.º 3
0
def login(l,s,f):
    global login

    if len(l)<2:
	login=None
	return '-BAD_LOGIN'

    user=l[0]
    pswd=l[1]

    if (not re_str.search(user)) or (not re_str.search(pswd)):
	login=None
	return '-BAD_LOGIN'

    key='USR_' + user
    db=start_db()
    
    if db.get(key) == str(h(pswd)):
	login=user
	return '+OK'

    login=None
    return '-BAD_LOGIN'
Ejemplo n.º 4
0
def msg_send(l,s,f):
    if len(l)<1:
	return '-ISE:Too few params!'
	
    to=l[0]
	
    s.send("+GO_AHEAD\n")
    msg=''
    a=f.readline().strip("\r\n")
    while(a!="+0"):
	msg+=a+"\n"
	a=f.readline().strip("\r\n")
    
    db=start_db()
    
    mid=random.randint(0,2345543466359044543)
    while (db.has_key('MSG_' + str(mid))):
	mid=random.randint(0,2345543466359044543)

    db.put('MSG_' + str(mid),msg)
    msgs_dumps=db.get('MSG_USR_' + to)
    
    if msgs_dumps:
	db.delete('MSG_USR_' + to)
	msgs=pickle.loads(msgs_dumps)
    else:
	msgs={}

    msgs[mid]=1
    
    msgs_dumps=pickle.dumps(msgs)

    db.put('MSG_USR_' + to, msgs_dumps)
    db.put('MSG_FROM_' + str(mid),login)

    return '+OK'
    print("usage:", prog, "BITCOINCORE_WALLET_FILE", file=sys.stderr)
    sys.exit(2)

wallet_filename = os.path.abspath(sys.argv[1])

with open(wallet_filename, "rb") as wallet_file:
    wallet_file.seek(12)
    if wallet_file.read(8) != b"\x62\x31\x05\x00\x09\x00\x00\x00":  # BDB magic, Btree v9
        print(prog+": error: file is not a Bitcoin Core wallet", file=sys.stderr)
        sys.exit(1)

db_env = bsddb.db.DBEnv()
db_env.open(os.path.dirname(wallet_filename), bsddb.db.DB_CREATE | bsddb.db.DB_INIT_MPOOL)
db = bsddb.db.DB(db_env)
db.open(wallet_filename, b"main", bsddb.db.DB_BTREE, bsddb.db.DB_RDONLY)
mkey = db.get(b"\x04mkey\x01\x00\x00\x00")
db.close()
db_env.close()

if not mkey:
    raise ValueError("Encrypted master key #1 not found in the Bitcoin Core wallet file.\n"+
                     "(is this wallet encrypted? is this a standard Bitcoin Core wallet?)")

# This is a little fragile because it assumes the encrypted key and salt sizes are
# 48 and 8 bytes long respectively, which although currently true may not always be:
# (it will loudly fail if this isn't the case; if smarter it could gracefully succeed):
encrypted_master_key, salt, method, iter_count = struct.unpack_from("< 49p 9p I I", mkey)
if method != 0:
    print(prog+": warning: unexpected Bitcoin Core key derivation method", str(method), file=sys.stderr)

print("Partial Bitcoin Core encrypted master key, salt, iter_count, and crc in base64:", file=sys.stderr)
Ejemplo n.º 6
0
wallet_filename = os.path.abspath(sys.argv[1])

with open(wallet_filename, "rb") as wallet_file:
    wallet_file.seek(12)
    if wallet_file.read(
            8) != b"\x62\x31\x05\x00\x09\x00\x00\x00":  # BDB magic, Btree v9
        print(prog + ": error: file is not a Bitcoin Core wallet",
              file=sys.stderr)
        sys.exit(1)

db_env = bsddb.db.DBEnv()
db_env.open(os.path.dirname(wallet_filename),
            bsddb.db.DB_CREATE | bsddb.db.DB_INIT_MPOOL)
db = bsddb.db.DB(db_env)
db.open(wallet_filename, b"main", bsddb.db.DB_BTREE, bsddb.db.DB_RDONLY)
mkey = db.get(b"\x04mkey\x01\x00\x00\x00")
db.close()
db_env.close()

if not mkey:
    raise ValueError(
        "Encrypted master key #1 not found in the Bitcoin Core wallet file.\n"
        +
        "(is this wallet encrypted? is this a standard Bitcoin Core wallet?)")

# This is a little fragile because it assumes the encrypted key and salt sizes are
# 48 and 8 bytes long respectively, which although currently true may not always be:
# (it will loudly fail if this isn't the case; if smarter it could gracefully succeed):
encrypted_master_key, salt, method, iter_count = struct.unpack_from(
    "< 49p 9p I I", mkey)
if method != 0: