ua_securitypolicy_none.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
  3. #include "ua_securitypolicy_none.h"
  4. #include "ua_types_generated_handling.h"
  5. static UA_StatusCode
  6. verify_none(const UA_SecurityPolicy *securityPolicy,
  7. const void *channelContext,
  8. const UA_ByteString *message,
  9. const UA_ByteString *signature) {
  10. return UA_STATUSCODE_GOOD;
  11. }
  12. static UA_StatusCode
  13. sign_none(const UA_SecurityPolicy *securityPolicy,
  14. const void *channelContext,
  15. const UA_ByteString *message,
  16. UA_ByteString *signature) {
  17. return UA_STATUSCODE_GOOD;
  18. }
  19. static size_t
  20. length_none(const UA_SecurityPolicy *securityPolicy,
  21. const void *channelContext) {
  22. return 0;
  23. }
  24. static UA_StatusCode
  25. encrypt_none(const UA_SecurityPolicy *securityPolicy,
  26. const void *channelContext,
  27. UA_ByteString *data) {
  28. return UA_STATUSCODE_GOOD;
  29. }
  30. static UA_StatusCode
  31. decrypt_none(const UA_SecurityPolicy *securityPolicy,
  32. const void *channelContext,
  33. UA_ByteString *data) {
  34. return UA_STATUSCODE_GOOD;
  35. }
  36. static UA_StatusCode
  37. makeThumbprint_none(const UA_SecurityPolicy *securityPolicy,
  38. const UA_ByteString *certificate,
  39. UA_ByteString *thumbprint) {
  40. return UA_STATUSCODE_GOOD;
  41. }
  42. static UA_StatusCode
  43. compareThumbprint_none(const UA_SecurityPolicy *securityPolicy,
  44. const UA_ByteString *certificateThumbprint) {
  45. return UA_STATUSCODE_GOOD;
  46. }
  47. static UA_StatusCode
  48. generateKey_none(const UA_SecurityPolicy *securityPolicy,
  49. const UA_ByteString *secret,
  50. const UA_ByteString *seed,
  51. UA_ByteString *out) {
  52. return UA_STATUSCODE_GOOD;
  53. }
  54. static UA_StatusCode
  55. generateNonce_none(const UA_SecurityPolicy *securityPolicy,
  56. UA_ByteString *out) {
  57. out->data = UA_Byte_new();
  58. if(!out->data)
  59. return UA_STATUSCODE_BADOUTOFMEMORY;
  60. out->length = 1;
  61. out->data[0] = 'a';
  62. return UA_STATUSCODE_GOOD;
  63. }
  64. static UA_StatusCode
  65. newContext_none(const UA_SecurityPolicy *securityPolicy,
  66. const UA_ByteString *remoteCertificate,
  67. void **channelContext) {
  68. return UA_STATUSCODE_GOOD;
  69. }
  70. static void
  71. deleteContext_none(void *const channelContext) {
  72. }
  73. static UA_StatusCode
  74. setContextValue_none(void *channelContext,
  75. const UA_ByteString *key) {
  76. return UA_STATUSCODE_GOOD;
  77. }
  78. static size_t
  79. getRemoteAsymPlainTextBlockSize_none(const void *const channelContext) {
  80. return 0;
  81. }
  82. static size_t
  83. getRemoteAsymEncryptionBufferLengthOverhead_none(const void *const channelContext,
  84. const size_t maxEncryptionLength) {
  85. return 0;
  86. }
  87. static UA_StatusCode
  88. compareCertificate_none(const void *channelContext,
  89. const UA_ByteString *certificate) {
  90. return UA_STATUSCODE_GOOD;
  91. }
  92. static void
  93. policy_deletemembers_none(UA_SecurityPolicy *policy) {
  94. UA_ByteString_deleteMembers(&policy->localCertificate);
  95. }
  96. UA_StatusCode
  97. UA_SecurityPolicy_None(UA_SecurityPolicy *policy, const UA_ByteString localCertificate,
  98. UA_Logger logger) {
  99. policy->policyContext = (void*)(uintptr_t)logger;
  100. policy->policyUri = UA_STRING("http://opcfoundation.org/UA/SecurityPolicy#None");
  101. policy->logger = logger;
  102. UA_ByteString_copy(&localCertificate, &policy->localCertificate);
  103. policy->asymmetricModule.makeCertificateThumbprint = makeThumbprint_none;
  104. policy->asymmetricModule.compareCertificateThumbprint = compareThumbprint_none;
  105. policy->asymmetricModule.cryptoModule.signatureAlgorithmUri = UA_STRING_NULL;
  106. policy->asymmetricModule.cryptoModule.verify = verify_none;
  107. policy->asymmetricModule.cryptoModule.sign = sign_none;
  108. policy->asymmetricModule.cryptoModule.getLocalSignatureSize = length_none;
  109. policy->asymmetricModule.cryptoModule.getRemoteSignatureSize = length_none;
  110. policy->asymmetricModule.cryptoModule.encrypt = encrypt_none;
  111. policy->asymmetricModule.cryptoModule.decrypt = decrypt_none;
  112. policy->asymmetricModule.cryptoModule.getLocalEncryptionKeyLength = length_none;
  113. policy->asymmetricModule.cryptoModule.getRemoteEncryptionKeyLength = length_none;
  114. policy->symmetricModule.generateKey = generateKey_none;
  115. policy->symmetricModule.generateNonce = generateNonce_none;
  116. policy->symmetricModule.cryptoModule.signatureAlgorithmUri = UA_STRING_NULL;
  117. policy->symmetricModule.cryptoModule.verify = verify_none;
  118. policy->symmetricModule.cryptoModule.sign = sign_none;
  119. policy->symmetricModule.cryptoModule.getLocalSignatureSize = length_none;
  120. policy->symmetricModule.cryptoModule.getRemoteSignatureSize = length_none;
  121. policy->symmetricModule.cryptoModule.encrypt = encrypt_none;
  122. policy->symmetricModule.cryptoModule.decrypt = decrypt_none;
  123. policy->symmetricModule.cryptoModule.getLocalEncryptionKeyLength = length_none;
  124. policy->symmetricModule.cryptoModule.getRemoteEncryptionKeyLength = length_none;
  125. policy->symmetricModule.encryptionBlockSize = 0;
  126. policy->symmetricModule.signingKeyLength = 0;
  127. policy->channelModule.newContext = newContext_none;
  128. policy->channelModule.deleteContext = deleteContext_none;
  129. policy->channelModule.setLocalSymEncryptingKey = setContextValue_none;
  130. policy->channelModule.setLocalSymSigningKey = setContextValue_none;
  131. policy->channelModule.setLocalSymIv = setContextValue_none;
  132. policy->channelModule.setRemoteSymEncryptingKey = setContextValue_none;
  133. policy->channelModule.setRemoteSymSigningKey = setContextValue_none;
  134. policy->channelModule.setRemoteSymIv = setContextValue_none;
  135. policy->channelModule.compareCertificate = compareCertificate_none;
  136. policy->channelModule.getRemoteAsymPlainTextBlockSize = getRemoteAsymPlainTextBlockSize_none;
  137. policy->channelModule.getRemoteAsymEncryptionBufferLengthOverhead =
  138. getRemoteAsymEncryptionBufferLengthOverhead_none;
  139. policy->deleteMembers = policy_deletemembers_none;
  140. return UA_STATUSCODE_GOOD;
  141. }