Authentication.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /*!
  15. * @file Authentication.h
  16. */
  17. #ifndef _FASTDDS_RTPS_SECURITY_AUTHENTICATION_AUTHENTICATION_H_
  18. #define _FASTDDS_RTPS_SECURITY_AUTHENTICATION_AUTHENTICATION_H_
  19. #include <fastdds/rtps/security/common/Handle.h>
  20. #include <fastdds/rtps/security/common/SharedSecretHandle.h>
  21. #include <fastdds/rtps/common/Guid.h>
  22. #include <fastdds/rtps/attributes/RTPSParticipantAttributes.h>
  23. #include <fastdds/rtps/security/exceptions/SecurityException.h>
  24. #include <fastdds/rtps/common/Token.h>
  25. #include <fastdds/rtps/common/CDRMessage_t.h>
  26. #include <fastdds/rtps/security/authentication/Handshake.h>
  27. #include <cstdint>
  28. namespace eprosima {
  29. namespace fastrtps {
  30. namespace rtps {
  31. namespace security {
  32. class Logging;
  33. enum ValidationResult_t : uint32_t
  34. {
  35. VALIDATION_OK = 0,
  36. VALIDATION_FAILED,
  37. VALIDATION_PENDING_RETRY,
  38. VALIDATION_PENDING_HANDSHAKE_REQUEST,
  39. VALIDATION_PENDING_HANDSHAKE_MESSAGE,
  40. VALIDATION_OK_WITH_FINAL_MESSAGE
  41. };
  42. class Authentication;
  43. class AuthenticationListener
  44. {
  45. virtual bool on_revoke_identity(Authentication& plugin,
  46. const IdentityHandle& handle,
  47. SecurityException& exception) = 0;
  48. };
  49. class Authentication
  50. {
  51. public:
  52. virtual ~Authentication() = default;
  53. /*!
  54. * @brief Validates the identity of the local RTPSParticipant.
  55. * @param local_identity_handle (out) A handle that can be used to locally refer to the Authenticated
  56. * Participant in subsequent interactions with the Authentication plugin.
  57. * @param adjusted_participant_key (out) The GUID_t that the implementation shall use to uniquely identify the
  58. * RTPSParticipant on the network.
  59. * @param domain_id The Domain Id of the RTPSParticipant.
  60. * @param participant_attr The RTPSParticipantAttributes of the RTPSParticipant.
  61. * @param candidate_participant_key The GUID_t that the DDS implementation would have used to uniquely identify
  62. * the RTPSParticipant if the Security plugins were not enabled.
  63. * @param exception (out) A SecurityException object.
  64. * @return Validation status.
  65. */
  66. virtual ValidationResult_t validate_local_identity(IdentityHandle** local_identity_handle,
  67. GUID_t& adjusted_participant_key,
  68. const uint32_t domain_id,
  69. const RTPSParticipantAttributes& participant_attr,
  70. const GUID_t& candidate_participant_key,
  71. SecurityException& exception) = 0;
  72. /*!
  73. * @brief Initiates the process of validating the identity of the discovered remote RTPSParticipant, represented
  74. * as an IdentityToken object.
  75. * @param remote_identity_handle (out) A handle that can be used to locally refer to the remote Authenticated
  76. * Participant in subsequent interactions with the AuthenticationPlugin.
  77. * @param local_identity_handle A handle to the local RTPSParticipant requesting the remote participant to be
  78. * validate.
  79. * @param remote_identity_token A token received as part of ParticipantProxyData, representing the
  80. * identity of the remote DomainParticipant.
  81. * @param remote_participant_key
  82. * @param exception (out) A SecurityException object.
  83. * @result Validation status.
  84. */
  85. virtual ValidationResult_t validate_remote_identity(IdentityHandle** remote_identity_handle,
  86. const IdentityHandle& local_identity_handle,
  87. const IdentityToken& remote_identity_token,
  88. const GUID_t& remote_participant_key,
  89. SecurityException& exception) = 0;
  90. /*!
  91. * @brief This operation is used to initiate a handshake.
  92. * @param handshake_handle (out) A handle returned by the Authentication plugin used to keep the state of the
  93. * handshake.
  94. * @param handshake_message (out) A HandshakeMessageToken to be sent using the BuiltinParticipantMessageWriter.
  95. * @param initiator_identity_handle Handle to the local participant that originated the handshake.
  96. * @param replier_identity_handle Handle to the remote participant whose identity is being validated.
  97. * @param cdr_participant_data Participant's data.
  98. * @param exception (out) A SecurityException object.
  99. * @result Validation status.
  100. */
  101. virtual ValidationResult_t begin_handshake_request(HandshakeHandle** handshake_handle,
  102. HandshakeMessageToken** handshake_message,
  103. const IdentityHandle& initiator_identity_handle,
  104. IdentityHandle& replier_identity_handle,
  105. const CDRMessage_t& cdr_participant_data,
  106. SecurityException& exception) = 0;
  107. /*!
  108. * @brief This operation shall be invoked by the implementation in reaction to the reception of the initial
  109. * handshake message that originated on a RTPSParticipant that called the begin_handshake_request operation.
  110. * @param handshake_handle (out) A handle returned by the Authentication Plugin used to keep the state of the
  111. * handshake.
  112. * @param handshake_message_out (out) A HandshakeMessageToken containing a message to be sent using the
  113. * BuiltinParticipantMessageWriter.
  114. * @param handshake_message_in A HandshakeMessageToken containing a message received from the
  115. * BuiltinParticipantMessageReader.
  116. * @param initiator_identity_handle Handle to the remote participant that originated the handshake.
  117. * @param replier_identity_handle Handle to the local participant that is initiaing the handshake.
  118. * @param cdr_participant_data Participant's CDRMessage.
  119. * @param exception A SecurityException object.
  120. * @result Validation status.
  121. */
  122. virtual ValidationResult_t begin_handshake_reply(
  123. HandshakeHandle** handshake_handle,
  124. HandshakeMessageToken** handshake_message_out,
  125. HandshakeMessageToken&& handshake_message_in,
  126. IdentityHandle& initiator_identity_handle,
  127. const IdentityHandle& replier_identity_handle,
  128. const CDRMessage_t& cdr_participant_data,
  129. SecurityException& exception) = 0;
  130. /*!
  131. * @brief This operation is used to continue a handshake.
  132. * @param handshake_message_out (out) A HandshakeMessageToken containing the message_data that should be
  133. * place in a ParticipantStatelessMessage to be sent using the BuiltinParticipantMessageWriter.
  134. * @param handshake_message_in The HandshakeMessageToken contained in the message_data attribute of the
  135. * ParticipantStatelessMessage received.
  136. * @param handshake_handle Handle returned by a correspoing previous call to begin_handshake_request or
  137. * begin_handshake_reply.
  138. * @param exception A SecurityException object.
  139. * @return Validation status.
  140. */
  141. virtual ValidationResult_t process_handshake(
  142. HandshakeMessageToken** handshake_message_out,
  143. HandshakeMessageToken&& handshake_message_in,
  144. HandshakeHandle& handshake_handle,
  145. SecurityException& exception) = 0;
  146. /*!
  147. * @brief Retrieve the SharedSecretHandle resulting with a successfully completed handshake.
  148. * @param handshake_handle Handle returned bu a corresponding previous call to begin_handshake_request or
  149. * begin_handshake_reply, which has successfully complete the handshake operations.
  150. * @param exception SecurityException object
  151. * @return SharedSecretHandle.
  152. */
  153. virtual SharedSecretHandle* get_shared_secret(
  154. const HandshakeHandle& handshake_handle,
  155. SecurityException& exception) = 0;
  156. /*!
  157. * @brief Sets the AuthenticationListener that the Authentication plugin will use to notify the infrastructure
  158. * of events relevant to the Authentication of RTPSParticipants.
  159. * @param listener An AuthenticationListener object to be attached to the Authentication object.
  160. * @param exception (out) A SecurityException object.
  161. */
  162. virtual bool set_listener(AuthenticationListener* listener,
  163. SecurityException& exception) = 0;
  164. virtual bool get_identity_token(IdentityToken** identity_token,
  165. const IdentityHandle& handle,
  166. SecurityException& exception) = 0;
  167. /*!
  168. * @brief Returns the IdentityToken object to the plugin so it can be disposed of.
  169. * @param token An IdentityToken issued by the plugin on a prior call to get_identity_token.
  170. * @param exception (out) A SecurityException object.
  171. */
  172. virtual bool return_identity_token(IdentityToken* token,
  173. SecurityException& exception) = 0;
  174. /*!
  175. * @brief Returns the Handshakehandle object to the plugin so it can be disposed of.
  176. * @param handshake_handle A HandshakeHandle issued by the plugin on a prior call to begin_handshake_request or
  177. * begin_handshake_reply.
  178. * @param exception (out) A SecurityException object.
  179. */
  180. virtual bool return_handshake_handle(HandshakeHandle* handshake_handle,
  181. SecurityException& exception) = 0;
  182. /*!
  183. * @brief Returns the IdentityHandle object to the plugin so it can be disposed of.
  184. * @param identity_handle An IdentityHandle issued by the plugin on a prior call to validate_local_identity or
  185. * validate_remote_identity.
  186. * @param exception (out) A SecurityException object.
  187. */
  188. virtual bool return_identity_handle(IdentityHandle* identity_handle,
  189. SecurityException& exception) = 0;
  190. /*!
  191. * @brief Returns the SharedSecretHandle object to the plugin so it can be disposed of.
  192. * @param sharedsecret_handle An SharedSecretHandle issued by the plugin on a prior call to get_shared_secret.
  193. * @param exception (out) A SecurityException object.
  194. */
  195. virtual bool return_sharedsecret_handle(SharedSecretHandle* sharedsecret_handle,
  196. SecurityException& exception) = 0;
  197. virtual bool set_permissions_credential_and_token(IdentityHandle& identity_handle,
  198. PermissionsCredentialToken& permissions_credential_token,
  199. SecurityException& ex) = 0;
  200. virtual bool get_authenticated_peer_credential_token(PermissionsCredentialToken **token,
  201. const IdentityHandle& identity_handle, SecurityException& exception) = 0;
  202. virtual bool return_authenticated_peer_credential_token(PermissionsCredentialToken* token,
  203. SecurityException& ex) = 0;
  204. bool set_logger(Logging* logger,
  205. SecurityException& /*exception*/)
  206. {
  207. logger_ = logger;
  208. return true;
  209. }
  210. protected:
  211. const Logging* get_logger() const
  212. {
  213. return logger_;
  214. }
  215. private:
  216. Logging* logger_ = nullptr;
  217. };
  218. } //namespace security
  219. } //namespace rtps
  220. } //namespace fastrtps
  221. } //namespace eprosima
  222. #endif // _FASTDDS_RTPS_SECURITY_AUTHENTICATION_AUTHENTICATION_H_