Update to new Block API
parent
500658808f
commit
007d7ad9fb
|
@ -22,9 +22,10 @@ from flask import request, Response, abort
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
from gevent.wsgi import WSGIServer
|
from gevent.wsgi import WSGIServer
|
||||||
import sys, random, threading, hmac, hashlib, base64, time, math, os, logger, config
|
import sys, random, threading, hmac, hashlib, base64, time, math, os, logger, config
|
||||||
|
|
||||||
from core import Core
|
from core import Core
|
||||||
|
from onionrblockapi import Block
|
||||||
import onionrutils, onionrcrypto
|
import onionrutils, onionrcrypto
|
||||||
|
|
||||||
class API:
|
class API:
|
||||||
'''
|
'''
|
||||||
Main HTTP API (Flask)
|
Main HTTP API (Flask)
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
'''
|
'''
|
||||||
import sqlite3, requests, hmac, hashlib, time, sys, os, math, logger, urllib.parse, base64, binascii, random, json, threading
|
import sqlite3, requests, hmac, hashlib, time, sys, os, math, logger, urllib.parse, base64, binascii, random, json, threading
|
||||||
import core, onionrutils, onionrcrypto, netcontroller, onionrproofs, config, onionrplugins as plugins
|
import core, onionrutils, onionrcrypto, netcontroller, onionrproofs, config, onionrplugins as plugins
|
||||||
|
from onionrblockapi import Block
|
||||||
|
|
||||||
class OnionrCommunicate:
|
class OnionrCommunicate:
|
||||||
def __init__(self, debug, developmentMode):
|
def __init__(self, debug, developmentMode):
|
||||||
|
|
|
@ -18,8 +18,7 @@
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
'''
|
||||||
import sqlite3, os, sys, time, math, base64, tarfile, getpass, simplecrypt, hashlib, nacl, logger, json, netcontroller, math, config
|
import sqlite3, os, sys, time, math, base64, tarfile, getpass, simplecrypt, hashlib, nacl, logger, json, netcontroller, math, config
|
||||||
#from Crypto.Cipher import AES
|
from onionrblockapi import Block
|
||||||
#from Crypto import Random
|
|
||||||
|
|
||||||
import onionrutils, onionrcrypto, onionrproofs, onionrevents as events
|
import onionrutils, onionrcrypto, onionrproofs, onionrevents as events
|
||||||
|
|
||||||
|
@ -111,7 +110,7 @@ class Core:
|
||||||
'''
|
'''
|
||||||
Add an address to the address database (only tor currently)
|
Add an address to the address database (only tor currently)
|
||||||
'''
|
'''
|
||||||
if address == config.get('i2p')['ownAddr']:
|
if (not (config.is_set('i2p') and 'ownAddr' in config.get('i2p'))) or address == config.get('i2p')['ownAddr']:
|
||||||
return False
|
return False
|
||||||
if self._utils.validateID(address):
|
if self._utils.validateID(address):
|
||||||
conn = sqlite3.connect(self.addressDB)
|
conn = sqlite3.connect(self.addressDB)
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import subprocess, os, random, sys, logger, time, signal
|
import subprocess, os, random, sys, logger, time, signal
|
||||||
|
from onionrblockapi import Block
|
||||||
|
|
||||||
class NetController:
|
class NetController:
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
# Misc functions that do not fit in the main api, but are useful
|
# Misc functions that do not fit in the main api, but are useful
|
||||||
import getpass, sys, requests, os, socket, hashlib, logger, sqlite3, config, binascii, time, base64, json, glob, shutil, math
|
import getpass, sys, requests, os, socket, hashlib, logger, sqlite3, config, binascii, time, base64, json, glob, shutil, math
|
||||||
import nacl.signing, nacl.encoding
|
import nacl.signing, nacl.encoding
|
||||||
|
from onionrblockapi import Block
|
||||||
|
|
||||||
if sys.version_info < (3, 6):
|
if sys.version_info < (3, 6):
|
||||||
try:
|
try:
|
||||||
|
@ -347,47 +348,41 @@ class OnionrUtils:
|
||||||
'''
|
'''
|
||||||
Find, decrypt, and return array of PMs (array of dictionary, {from, text})
|
Find, decrypt, and return array of PMs (array of dictionary, {from, text})
|
||||||
'''
|
'''
|
||||||
#blocks = self._core.getBlockList()
|
blocks = Block.getBlocks(type = 'pm', core = self._core)
|
||||||
blocks = self._core.getBlocksByType('pm')
|
|
||||||
message = ''
|
message = ''
|
||||||
sender = ''
|
sender = ''
|
||||||
for i in blocks:
|
for i in blocks:
|
||||||
if len (i) == 0:
|
|
||||||
continue
|
|
||||||
try:
|
try:
|
||||||
with open('data/blocks/' + i + '.dat', 'r') as potentialMessage:
|
blockContent = i.getContent()
|
||||||
potentialMessage = potentialMessage.read()
|
|
||||||
blockMetadata = json.loads(potentialMessage[:potentialMessage.find('\n')])
|
try:
|
||||||
blockContent = potentialMessage[potentialMessage.find('\n') + 1:]
|
message = self._core._crypto.pubKeyDecrypt(blockContent, encodedData=True, anonymous=True)
|
||||||
|
except nacl.exceptions.CryptoError as e:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
message = message.decode()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
message = self._core._crypto.pubKeyDecrypt(blockContent, encodedData=True, anonymous=True)
|
message = json.loads(message)
|
||||||
except nacl.exceptions.CryptoError as e:
|
except json.decoder.JSONDecodeError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
try:
|
logger.debug('Decrypted %s:' % i.getHash())
|
||||||
message = message.decode()
|
logger.info(message["msg"])
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
signer = message["id"]
|
||||||
message = json.loads(message)
|
sig = message["sig"]
|
||||||
except json.decoder.JSONDecodeError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
logger.info('Decrypted %s:' % i)
|
|
||||||
logger.info(message["msg"])
|
|
||||||
|
|
||||||
signer = message["id"]
|
if self.validatePubKey(signer):
|
||||||
sig = message["sig"]
|
if self._core._crypto.edVerify(message["msg"], signer, sig, encodedData=True):
|
||||||
|
logger.info("Good signature by %s" % signer)
|
||||||
if self.validatePubKey(signer):
|
|
||||||
if self._core._crypto.edVerify(message["msg"], signer, sig, encodedData=True):
|
|
||||||
logger.info("Good signature by %s" % signer)
|
|
||||||
else:
|
|
||||||
logger.warn("Bad signature by %s" % signer)
|
|
||||||
else:
|
else:
|
||||||
logger.warn('Bad sender id: %s' % signer)
|
logger.warn("Bad signature by %s" % signer)
|
||||||
|
else:
|
||||||
|
logger.warn('Bad sender id: %s' % signer)
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
# Imports some useful libraries
|
# Imports some useful libraries
|
||||||
import logger, config
|
import logger, config
|
||||||
|
from onionrblockapi import Block
|
||||||
|
|
||||||
plugin_name = '$name'
|
plugin_name = '$name'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue