@@ -118,7 +118,7 @@ class Session:
118118 """A connect to a domain"""
119119
120120 key : bytes
121- counter : int = 0
121+ counter : int
122122 epoch : bytes
123123 delta : int
124124 hmac : bytes
@@ -127,24 +127,26 @@ class Session:
127127
128128 def __init__ (self ):
129129 self .lock = Lock ()
130+ self .counter = 0
130131
131132 def update (self , sessionInfo : SessionInfo , privateKey : ec .EllipticCurvePrivateKey ):
132133 """Update the session with new information"""
133134 self .counter = sessionInfo .counter
134135 self .epoch = sessionInfo .epoch
135136 self .delta = int (time .time ()) - sessionInfo .clock_time
136- self .publicKey = sessionInfo .publicKey
137- self .key = hashlib .sha1 (
138- privateKey .exchange (
139- ec .ECDH (),
140- ec .EllipticCurvePublicKey .from_encoded_point (
141- ec .SECP256R1 (), self .publicKey
137+ if (self .publicKey != sessionInfo .publicKey ):
138+ self .publicKey = sessionInfo .publicKey
139+ self .key = hashlib .sha1 (
140+ privateKey .exchange (
141+ ec .ECDH (),
142+ ec .EllipticCurvePublicKey .from_encoded_point (
143+ ec .SECP256R1 (), self .publicKey
144+ ),
142145 ),
143- )
144- ).digest ()[:16 ]
145- self .hmac = hmac .new (
146- self .key , "authenticated command" .encode (), hashlib .sha256
147- ).digest ()
146+ ).digest ()[:16 ]
147+ self .hmac = hmac .new (
148+ self .key , "authenticated command" .encode (), hashlib .sha256
149+ ).digest ()
148150
149151 def get (self ) -> HMAC_Personalized_Signature_Data :
150152 """Sign a command and return session metadata"""
0 commit comments