MCPcopy Create free account
hub / github.com/FreeOpcUa/python-opcua / _check_sym_header

Method _check_sym_header

opcua/common/connection.py:246–268  ·  view source on GitHub ↗

Validates the symmetric header of the message chunk and revolves the security token if needed.

(self, securityHeader)

Source from the content-addressed store, hash-verified

244 return b"".join([chunk.to_binary() for chunk in chunks])
245
246 def _check_sym_header(self, securityHeader):
247 """
248 Validates the symmetric header of the message chunk and revolves the
249 security token if needed.
250 """
251 assert isinstance(securityHeader, ua.SymmetricAlgorithmHeader), "Expected SymAlgHeader, got: {0}".format(securityHeader)
252 if securityHeader.TokenId != self.security_token.TokenId:
253 if securityHeader.TokenId != self.next_security_token.TokenId:
254 if self._allow_prev_token and \
255 securityHeader.TokenId == self.prev_security_token.TokenId:
256 timeout = self.prev_security_token.CreatedAt + timedelta(milliseconds=self.prev_security_token.RevisedLifetime * 1.25)
257 if timeout < datetime.utcnow():
258 raise ua.UaError("Security token id {} has timed out ({} < {})".format(securityHeader.TokenId, timeout, datetime.utcnow()))
259 else:
260 return
261 raise ua.UaError("Invalid security token id {}, expected {} or {}".format(securityHeader.TokenId, self.security_token.TokenId, self.next_security_token.TokenId))
262 else:
263 self.revolve_tokens()
264 self.security_policy.make_remote_symmetric_key(self.local_nonce, self.remote_nonce)
265 self.prev_security_token = ua.ChannelSecurityToken()
266 if self.prev_security_token.TokenId != 0:
267 self.security_policy.make_remote_symmetric_key(self.local_nonce, self.remote_nonce)
268 self.prev_security_token = ua.ChannelSecurityToken()
269
270 def _check_incoming_chunk(self, chunk):
271 assert isinstance(chunk, MessageChunk), "Expected chunk, got: {0}".format(chunk)

Callers 1

Calls 2

revolve_tokensMethod · 0.95

Tested by

no test coverage detected