move utils to one utils.py file
This commit is contained in:
parent
084c8271c2
commit
53a9c296fb
6 changed files with 30 additions and 37 deletions
|
@ -7,7 +7,7 @@ import logging
|
||||||
import json
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from ed25519_utils import valid
|
from utils import valid
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
from settings import db
|
from settings import db
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
|
||||||
from __future__ import division
|
|
||||||
|
|
||||||
import ed25519
|
|
||||||
ENCODING='base64'
|
|
||||||
|
|
||||||
def valid(key, value, sig):
|
|
||||||
'''
|
|
||||||
validate that value was signed by key
|
|
||||||
'''
|
|
||||||
vk = ed25519.VerifyingKey(str(key), encoding=ENCODING)
|
|
||||||
try:
|
|
||||||
vk.verify(str(sig), str(value), encoding=ENCODING)
|
|
||||||
#except ed25519.BadSignatureError:
|
|
||||||
except:
|
|
||||||
return False
|
|
||||||
return True
|
|
|
@ -12,8 +12,7 @@ import thread
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from settings import preferences, server, USER_ID, sk
|
from settings import preferences, server, USER_ID, sk
|
||||||
from node.utils import get_public_ipv6
|
from utils import valid, get_public_ipv6
|
||||||
from ed25519_utils import valid
|
|
||||||
|
|
||||||
logger = logging.getLogger('oml.localnodes')
|
logger = logging.getLogger('oml.localnodes')
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,11 @@ from tornado.httpserver import HTTPServer
|
||||||
import settings
|
import settings
|
||||||
|
|
||||||
import directory
|
import directory
|
||||||
import utils
|
|
||||||
import state
|
import state
|
||||||
import user
|
import user
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from ed25519_utils import valid
|
from utils import valid, get_public_ipv6
|
||||||
import api
|
import api
|
||||||
import cert
|
import cert
|
||||||
|
|
||||||
|
@ -105,7 +104,7 @@ class ShareHandler(tornado.web.RequestHandler):
|
||||||
|
|
||||||
|
|
||||||
def publish_node():
|
def publish_node():
|
||||||
host = utils.get_public_ipv6()
|
host = get_public_ipv6()
|
||||||
state.online = directory.put(settings.sk, {
|
state.online = directory.put(settings.sk, {
|
||||||
'host': host,
|
'host': host,
|
||||||
'port': settings.server['node_port'],
|
'port': settings.server['node_port'],
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
|
||||||
|
|
||||||
import socket
|
|
||||||
|
|
||||||
def get_public_ipv6():
|
|
||||||
host = ('2a01:4f8:120:3201::3', 25519)
|
|
||||||
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
|
|
||||||
s.connect(host)
|
|
||||||
ip = s.getsockname()[0]
|
|
||||||
s.close()
|
|
||||||
return ip
|
|
||||||
|
|
26
oml/utils.py
26
oml/utils.py
|
@ -1,15 +1,21 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
import Image
|
import Image
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
import re
|
import re
|
||||||
import stdnum.isbn
|
import stdnum.isbn
|
||||||
|
import socket
|
||||||
|
|
||||||
import ox
|
import ox
|
||||||
|
import ed25519
|
||||||
|
|
||||||
from meta.utils import normalize_isbn, find_isbns
|
from meta.utils import normalize_isbn, find_isbns
|
||||||
|
|
||||||
|
|
||||||
|
ENCODING='base64'
|
||||||
|
|
||||||
def valid_olid(id):
|
def valid_olid(id):
|
||||||
return id.startswith('OL') and id.endswith('M')
|
return id.startswith('OL') and id.endswith('M')
|
||||||
|
|
||||||
|
@ -82,3 +88,23 @@ def get_position_by_id(list, key):
|
||||||
return i
|
return i
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
def valid(key, value, sig):
|
||||||
|
'''
|
||||||
|
validate that value was signed by key
|
||||||
|
'''
|
||||||
|
vk = ed25519.VerifyingKey(str(key), encoding=ENCODING)
|
||||||
|
try:
|
||||||
|
vk.verify(str(sig), str(value), encoding=ENCODING)
|
||||||
|
#except ed25519.BadSignatureError:
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def get_public_ipv6():
|
||||||
|
host = ('2a01:4f8:120:3201::3', 25519)
|
||||||
|
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
|
||||||
|
s.connect(host)
|
||||||
|
ip = s.getsockname()[0]
|
||||||
|
s.close()
|
||||||
|
return ip
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue