ua_securechannel.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <time.h>
  2. #include <stdlib.h>
  3. #include "ua_securechannel.h"
  4. #include "ua_util.h"
  5. void UA_SecureChannel_init(UA_SecureChannel *channel) {
  6. UA_AsymmetricAlgorithmSecurityHeader_init(&channel->clientAsymAlgSettings);
  7. UA_AsymmetricAlgorithmSecurityHeader_init(&channel->serverAsymAlgSettings);
  8. UA_ByteString_init(&channel->clientNonce);
  9. UA_ByteString_init(&channel->serverNonce);
  10. channel->connection = UA_NULL;
  11. channel->session = UA_NULL;
  12. }
  13. void UA_SecureChannel_deleteMembers(UA_SecureChannel *channel) {
  14. UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(&channel->serverAsymAlgSettings);
  15. UA_ByteString_deleteMembers(&channel->serverNonce);
  16. UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(&channel->clientAsymAlgSettings);
  17. UA_ByteString_deleteMembers(&channel->clientNonce);
  18. UA_ChannelSecurityToken_deleteMembers(&channel->securityToken);
  19. }
  20. void UA_SecureChannel_delete(UA_SecureChannel *channel) {
  21. UA_SecureChannel_deleteMembers(channel);
  22. UA_free(channel);
  23. }
  24. UA_Boolean UA_SecureChannel_compare(UA_SecureChannel *sc1, UA_SecureChannel *sc2) {
  25. return (sc1->securityToken.channelId == sc2->securityToken.channelId);
  26. }
  27. //TODO implement real nonce generator - DUMMY function
  28. UA_Int32 UA_SecureChannel_generateNonce(UA_ByteString *nonce) {
  29. //UA_ByteString_new(&nonce);
  30. UA_alloc((void ** )&nonce->data, 1);
  31. nonce->length = 1;
  32. nonce->data[0] = 'a';
  33. return UA_SUCCESS;
  34. }
  35. UA_Int32 UA_SecureChannel_updateRequestId(UA_SecureChannel *channel, UA_UInt32 requestId) {
  36. //TODO review checking of request id
  37. if(channel->requestId+1 == requestId) {
  38. channel->requestId++;
  39. return UA_SUCCESS;
  40. }
  41. return UA_ERROR;
  42. }
  43. UA_Int32 UA_SecureChannel_updateSequenceNumber(UA_SecureChannel *channel,
  44. UA_UInt32 sequenceNumber) {
  45. //TODO review checking of sequence
  46. if(channel->sequenceNumber+1 == sequenceNumber) {
  47. channel->sequenceNumber++;
  48. return UA_SUCCESS;
  49. }
  50. return UA_ERROR;
  51. }