mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-18 10:46:24 +00:00
Move get_keypair to a shared location
This commit is contained in:
parent
3423bfb351
commit
e236cc95a5
@ -1,15 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
Ported to Python 3.
|
Ported to Python 3.
|
||||||
"""
|
"""
|
||||||
from __future__ import division
|
from __future__ import annotations
|
||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from future.utils import PY2
|
|
||||||
if PY2:
|
|
||||||
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, max, min # noqa: F401
|
|
||||||
from past.builtins import unicode as str # prevent leaking newbytes/newstr into code that can't handle it
|
|
||||||
|
|
||||||
from six import ensure_str
|
from six import ensure_str
|
||||||
|
|
||||||
@ -21,6 +13,7 @@ except ImportError:
|
|||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
from base64 import urlsafe_b64decode
|
||||||
|
|
||||||
from hyperlink import (
|
from hyperlink import (
|
||||||
DecodedURL,
|
DecodedURL,
|
||||||
@ -94,7 +87,7 @@ from allmydata.util.encodingutil import (
|
|||||||
to_bytes,
|
to_bytes,
|
||||||
)
|
)
|
||||||
from allmydata.util import abbreviate
|
from allmydata.util import abbreviate
|
||||||
|
from allmydata.crypto.rsa import PrivateKey, PublicKey, create_signing_keypair_from_string
|
||||||
|
|
||||||
class WebError(Exception):
|
class WebError(Exception):
|
||||||
def __init__(self, text, code=http.BAD_REQUEST):
|
def __init__(self, text, code=http.BAD_REQUEST):
|
||||||
@ -833,3 +826,14 @@ def abbreviate_time(data):
|
|||||||
if s >= 0.001:
|
if s >= 0.001:
|
||||||
return u"%.1fms" % (1000*s)
|
return u"%.1fms" % (1000*s)
|
||||||
return u"%.0fus" % (1000000*s)
|
return u"%.0fus" % (1000000*s)
|
||||||
|
|
||||||
|
def get_keypair(request: IRequest) -> tuple[PublicKey, PrivateKey] | None:
|
||||||
|
"""
|
||||||
|
Load a keypair from a urlsafe-base64-encoded RSA private key in the
|
||||||
|
**private-key** argument of the given request, if there is one.
|
||||||
|
"""
|
||||||
|
privkey_der = get_arg(request, "private-key", None)
|
||||||
|
if privkey_der is None:
|
||||||
|
return None
|
||||||
|
privkey, pubkey = create_signing_keypair_from_string(urlsafe_b64decode(privkey_der))
|
||||||
|
return pubkey, privkey
|
||||||
|
@ -3,8 +3,6 @@ Ported to Python 3.
|
|||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from base64 import urlsafe_b64decode
|
|
||||||
|
|
||||||
from twisted.web import http, static
|
from twisted.web import http, static
|
||||||
from twisted.web.iweb import IRequest
|
from twisted.web.iweb import IRequest
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
@ -26,6 +24,7 @@ from allmydata.blacklist import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from allmydata.web.common import (
|
from allmydata.web.common import (
|
||||||
|
get_keypair,
|
||||||
boolean_of_arg,
|
boolean_of_arg,
|
||||||
exception_to_child,
|
exception_to_child,
|
||||||
get_arg,
|
get_arg,
|
||||||
@ -47,20 +46,6 @@ from allmydata.web.check_results import (
|
|||||||
)
|
)
|
||||||
from allmydata.web.info import MoreInfo
|
from allmydata.web.info import MoreInfo
|
||||||
from allmydata.util import jsonbytes as json
|
from allmydata.util import jsonbytes as json
|
||||||
from allmydata.crypto.rsa import PrivateKey, PublicKey, create_signing_keypair_from_string
|
|
||||||
|
|
||||||
|
|
||||||
def get_keypair(request: IRequest) -> tuple[PublicKey, PrivateKey] | None:
|
|
||||||
"""
|
|
||||||
Load a keypair from a urlsafe-base64-encoded RSA private key in the
|
|
||||||
**private-key** argument of the given request, if there is one.
|
|
||||||
"""
|
|
||||||
privkey_der = get_arg(request, "private-key", None)
|
|
||||||
if privkey_der is None:
|
|
||||||
return None
|
|
||||||
privkey, pubkey = create_signing_keypair_from_string(urlsafe_b64decode(privkey_der))
|
|
||||||
return pubkey, privkey
|
|
||||||
|
|
||||||
|
|
||||||
class ReplaceMeMixin(object):
|
class ReplaceMeMixin(object):
|
||||||
def replace_me_with_a_child(self, req, client, replace):
|
def replace_me_with_a_child(self, req, client, replace):
|
||||||
|
Loading…
Reference in New Issue
Block a user