Skip to content

Commit

Permalink
update run_method() (shadowsocks#1161)
Browse files Browse the repository at this point in the history
  • Loading branch information
mengskysama authored Feb 18, 2018
1 parent 2ab8c6b commit 8b30264
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
9 changes: 3 additions & 6 deletions shadowsocks/crypto/mbedtls.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,22 +408,20 @@ def __init__(self, cipher_name, key, iv, op, crypto_path=None):


def run_method(method):
from shadowsocks.crypto import openssl

print(method, ': [stream]', 32)
cipher = MbedTLSStreamCrypto(method, b'k' * 32, b'i' * 16, 1)
decipher = openssl.OpenSSLStreamCrypto(method, b'k' * 32, b'i' * 16, 0)
decipher = MbedTLSStreamCrypto(method, b'k' * 32, b'i' * 16, 0)

util.run_cipher(cipher, decipher)


def run_aead_method(method, key_len=16):
from shadowsocks.crypto import openssl

print(method, ': [payload][tag]', key_len)
key_len = int(key_len)
cipher = MbedTLSAeadCrypto(method, b'k' * key_len, b'i' * key_len, 1)
decipher = openssl.OpenSSLAeadCrypto(
decipher = MbedTLSAeadCrypto(
method,
b'k' * key_len, b'i' * key_len, 0
)
Expand All @@ -432,12 +430,11 @@ def run_aead_method(method, key_len=16):


def run_aead_method_chunk(method, key_len=16):
from shadowsocks.crypto import openssl

print(method, ': chunk([size][tag][payload][tag]', key_len)
key_len = int(key_len)
cipher = MbedTLSAeadCrypto(method, b'k' * key_len, b'i' * key_len, 1)
decipher = openssl.OpenSSLAeadCrypto(
decipher = MbedTLSAeadCrypto(
method,
b'k' * key_len, b'i' * key_len, 0
)
Expand Down
4 changes: 4 additions & 0 deletions shadowsocks/crypto/openssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ def run_method(method):

def run_aead_method(method, key_len=16):

if not loaded:
load_openssl(None)
print(method, ': [payload][tag]', key_len)
cipher = libcrypto.EVP_get_cipherbyname(common.to_bytes(method))
if not cipher:
Expand All @@ -362,6 +364,8 @@ def run_aead_method(method, key_len=16):

def run_aead_method_chunk(method, key_len=16):

if not loaded:
load_openssl(None)
print(method, ': chunk([size][tag][payload][tag]', key_len)
cipher = libcrypto.EVP_get_cipherbyname(common.to_bytes(method))
if not cipher:
Expand Down
7 changes: 7 additions & 0 deletions tests/libopenssl/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ pushd openssl-$OPENSSL_VER
# sudo ldconfig # test multiple libcrypto
popd
rm -rf openssl-$OPENSSL_VER || exit 1

rm /usr/bin/openssl || exit 1
rm -r /usr/include/openssl || exit 1
ln -s /usr/local/bin/openssl /usr/bin/openssl || exit 1
ln -s /usr/local/include/openssl /usr/include/openssl || exit 1
echo /usr/local/lib >> /etc/ld.so.conf || exit 1
ldconfig -v || exit 1

0 comments on commit 8b30264

Please sign in to comment.