ua_securitypolicy_none.c 6.4 KB

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