Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

treewide: bump py-cose version, update accordingly #25

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ __pycache__
dist/
docs/build/
build/
.tox/*
8 changes: 5 additions & 3 deletions edhoc/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import cbor2
from cose.algorithms import AESCCM1664128, Sha256, EdDSA, AESCCM16128128, Es256, A128GCM, A256GCM, Sha384, Es384
from cose.curves import X25519, Ed25519, P256, P384
from cose.keys.curves import X25519, Ed25519, P256, P384

from edhoc.exceptions import EdhocException

Expand Down Expand Up @@ -180,6 +180,7 @@ class CipherSuite3(CipherSuite):
app_aead = AESCCM1664128
app_hash = Sha256


@CipherSuite.register_ciphersuite()
class CipherSuite4(CipherSuite):
identifier = 4
Expand All @@ -192,7 +193,8 @@ class CipherSuite4(CipherSuite):
sign_curve = P256
app_aead = A128GCM
app_hash = Sha256
assert CipherSuite4.check_identifiers() == (1, -16, 4, -7, 1, 1, -16)
assert CipherSuite4.check_identifiers() == (1, -16, 4, -7, 1, 1, -16) # noqa: E305


@CipherSuite.register_ciphersuite()
class CipherSuite5(CipherSuite):
Expand All @@ -206,7 +208,7 @@ class CipherSuite5(CipherSuite):
sign_curve = P384
app_aead = A256GCM
app_hash = Sha384
assert CipherSuite5.check_identifiers() == (3, -43, 2, -35, 2, 3, -43)
assert CipherSuite5.check_identifiers() == (3, -43, 2, -35, 2, 3, -43) # noqa: E305


class EdhocKDFInfo(NamedTuple):
Expand Down
7 changes: 3 additions & 4 deletions edhoc/roles/edhoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import cbor2
from cose import headers
from cose.curves import X25519, X448, P256
from cose.exceptions import CoseIllegalCurve
from cose.keys.curves import X25519, X448, P256
from cose.exceptions import CoseUnsupportedCurve
from cose.headers import CoseHeaderAttribute
from cose.keys import OKPKey, EC2Key, SymmetricKey
from cose.keys.keyops import EncryptOp
Expand All @@ -29,7 +29,6 @@
from edhoc.definitions import CS
from cose.keys.keyops import KEYOPS
from cose.keys.cosekey import CK
from cose.headers import CoseHeaderAttribute

RPK = Union[EC2Key, OKPKey]
CBOR = bytes
Expand Down Expand Up @@ -142,7 +141,7 @@ def shared_secret(private_key: 'CK', public_key: 'CK') -> bytes:
x = x.public_key()
secret = d.exchange(ec.ECDH(), x)
else:
raise CoseIllegalCurve(f"{public_key.crv} is unsupported")
raise CoseUnsupportedCurve(f"{public_key.crv} is unsupported")

return secret

Expand Down
8 changes: 5 additions & 3 deletions edhoc/roles/initiator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import cbor2
from asn1crypto.x509 import Certificate
from cose import headers
from cose.curves import X448, X25519
from cose.keys.curves import X448, X25519
from cose.headers import KID
from cose.keys import OKPKey, EC2Key
from cose.keys.keyops import EncryptOp
Expand Down Expand Up @@ -201,7 +201,8 @@ def create_message_three(self, message_two: bytes):
return self.msg_3.encode(self.corr)

def _verify_signature_or_mac2(self, signature_or_mac2: bytes) -> bool:
mac_2 = self._mac(self.cred_idr, self.remote_cred, self._hkdf2, 'K_2m', 16, 'IV_2m', 13, self._th2_input, self._prk3e2m, self.aad2_cb)
mac_2 = self._mac(self.cred_idr, self.remote_cred, self._hkdf2, 'K_2m', 16,
'IV_2m', 13, self._th2_input, self._prk3e2m, self.aad2_cb)

if not self.is_static_dh(self.remote_role):
external_aad = self._external_aad(self.remote_cred, self._th2_input, self.aad2_cb)
Expand Down Expand Up @@ -277,7 +278,8 @@ def _prk4x3m_static_dh(self, prk: bytes):
@property
def _p_3ae(self):
# TODO: resolve magic key and IV lengths
mac_3 = self._mac(self.cred_idi, self.cred, self._hkdf3, 'K_3m', 16, 'IV_3m', 13, self._th3_input, self._prk4x3m, self.aad3_cb)
mac_3 = self._mac(self.cred_idi, self.cred, self._hkdf3, 'K_3m', 16,
'IV_3m', 13, self._th3_input, self._prk4x3m, self.aad3_cb)

signature = self.signature_or_mac3(mac_3)

Expand Down
8 changes: 5 additions & 3 deletions edhoc/roles/responder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import cbor2
from asn1crypto.x509 import Certificate
from cose import headers
from cose.curves import X25519, X448
from cose.keys.curves import X25519, X448
from cose.headers import KID
from cose.keys import OKPKey, EC2Key
from cose.keys.keyops import DecryptOp
Expand Down Expand Up @@ -237,7 +237,8 @@ def finalize(self, message_three: bytes) -> Union[Tuple[bytes, bytes, int, int],
return self.msg_1.conn_idi, self._conn_id, app_aead.identifier, app_hash.identifier

def _verify_signature_or_mac3(self, signature_or_mac3: bytes) -> bool:
mac_3 = self._mac(self.cred_idi, self.remote_cred, self._hkdf3, 'K_3m', 16, 'IV_3m', 13, self._th3_input, self._prk4x3m, self.aad3_cb)
mac_3 = self._mac(self.cred_idi, self.remote_cred, self._hkdf3, 'K_3m', 16,
'IV_3m', 13, self._th3_input, self._prk4x3m, self.aad3_cb)

if not self.is_static_dh(self.remote_role):
external_aad = self._external_aad(self.remote_cred, self._th3_input, self.aad3_cb)
Expand Down Expand Up @@ -265,7 +266,8 @@ def _hkdf3(self) -> Callable:
def _p_2e(self):
# compute MAC_2
# TODO: resolve magic key and IV lengths
mac_2 = self._mac(self.cred_idr, self.cred, self._hkdf2, 'K_2m', 16, 'IV_2m', 13, self._th2_input, self._prk3e2m, self.aad2_cb)
mac_2 = self._mac(self.cred_idr, self.cred, self._hkdf2, 'K_2m', 16,
'IV_2m', 13, self._th2_input, self._prk3e2m, self.aad2_cb)

# compute the signature_or_mac2
signature = self.signature_or_mac2(mac_2)
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
cbor2>=5.2.0
cryptography>=3.2.1
cose>=0.9dev5
cose>=0.9dev7
aiocoap
asn1crypto


2 changes: 1 addition & 1 deletion scripts/edhoc_initiator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from aiocoap.numbers.codes import Code
from cose import headers
from cose.algorithms import Sha256Trunc64
from cose.curves import X25519, Ed25519
from cose.keys.curves import X25519, Ed25519
from cose.extensions.x509 import X5T
from cose.keys import OKPKey
from cryptography import x509
Expand Down
2 changes: 1 addition & 1 deletion scripts/edhoc_responder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import aiocoap.resource as resource
from cose import headers
from cose.algorithms import Sha256Trunc64
from cose.curves import Ed25519, X25519
from cose.keys.curves import Ed25519, X25519
from cose.extensions.x509 import X5T
from cose.keys import OKPKey
from cryptography import x509
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import cbor2
from cose.algorithms import Es256
from cose.curves import Ed448, Ed25519, X25519, X448, P256
from cose.keys.curves import Ed448, Ed25519, X25519, X448, P256
from cose.keys import EC2Key, OKPKey, CoseKey
from cose.keys.keyparam import KpAlg
from pytest import fixture
Expand Down