2018-06-21 14:28:34 +00:00
|
|
|
# This file is part of the Trezor project.
|
2018-03-11 21:51:14 +00:00
|
|
|
#
|
2018-06-21 14:28:34 +00:00
|
|
|
# Copyright (C) 2012-2018 SatoshiLabs and contributors
|
2018-03-11 21:51:14 +00:00
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
2018-06-21 14:28:34 +00:00
|
|
|
# it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
# as published by the Free Software Foundation.
|
2018-03-11 21:51:14 +00:00
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser General Public License for more details.
|
|
|
|
#
|
2018-06-21 14:28:34 +00:00
|
|
|
# You should have received a copy of the License along with this library.
|
|
|
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
|
|
|
|
2018-05-11 12:53:51 +00:00
|
|
|
from binascii import unhexlify
|
2018-03-11 21:51:14 +00:00
|
|
|
|
2018-05-11 12:53:51 +00:00
|
|
|
from .common import TrezorTest
|
2018-03-11 21:51:14 +00:00
|
|
|
from trezorlib import messages as proto
|
2018-08-10 12:04:58 +00:00
|
|
|
from trezorlib import misc
|
2018-03-11 21:51:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestMsgGetECDHSessionKey(TrezorTest):
|
|
|
|
|
|
|
|
def test_ecdh(self):
|
|
|
|
self.setup_mnemonic_nopin_nopassphrase()
|
|
|
|
|
|
|
|
# URI : gpg://Satoshi Nakamoto <satoshi@bitcoin.org>
|
|
|
|
identity = proto.IdentityType(proto='gpg', user='', host='Satoshi Nakamoto <satoshi@bitcoin.org>', port='', path='', index=0)
|
|
|
|
|
|
|
|
peer_public_key = unhexlify('0407f2c6e5becf3213c1d07df0cfbe8e39f70a8c643df7575e5c56859ec52c45ca950499c019719dae0fda04248d851e52cf9d66eeb211d89a77be40de22b6c89d')
|
2018-08-10 12:04:58 +00:00
|
|
|
result = misc.get_ecdh_session_key(self.client, identity=identity, peer_public_key=peer_public_key, ecdsa_curve_name='secp256k1')
|
2018-03-11 21:51:14 +00:00
|
|
|
assert result.session_key == unhexlify('0495e5d8c9e5cc09e7cf4908774f52decb381ce97f2fc9ba56e959c13f03f9f47a03dd151cbc908bc1db84d46e2c33e7bbb9daddc800f985244c924fd64adf6647')
|
|
|
|
|
|
|
|
peer_public_key = unhexlify('04811a6c2bd2a547d0dd84747297fec47719e7c3f9b0024f027c2b237be99aac39a9230acbd163d0cb1524a0f5ea4bfed6058cec6f18368f72a12aa0c4d083ff64')
|
2018-08-10 12:04:58 +00:00
|
|
|
result = misc.get_ecdh_session_key(self.client, identity=identity, peer_public_key=peer_public_key, ecdsa_curve_name='nist256p1')
|
2018-03-11 21:51:14 +00:00
|
|
|
assert result.session_key == unhexlify('046d1f5c48af2cf2c57076ac2c9d7808db2086f614cb7b8107119ff2c6270cd209749809efe0196f01a0cc633788cef1f4a2bd650c99570d06962f923fca6d8fdf')
|
|
|
|
|
|
|
|
peer_public_key = unhexlify('40a8cf4b6a64c4314e80f15a8ea55812bd735fbb365936a48b2d78807b575fa17a')
|
2018-08-10 12:04:58 +00:00
|
|
|
result = misc.get_ecdh_session_key(self.client, identity=identity, peer_public_key=peer_public_key, ecdsa_curve_name='curve25519')
|
2018-03-11 21:51:14 +00:00
|
|
|
assert result.session_key == unhexlify('04e24516669e0b7d3d72e5129fddd07b6644c30915f5c8b7f1f62324afb3624311')
|