ua_securechannel.c 2.2 KB

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