ua_securitypolicy_none.c 6.2 KB

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