PageRenderTime 52ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/Kilimanjaro_Trunk/Security/Transport/Scripts/1 - Target endpoint setup.sql

#
SQL | 65 lines | 24 code | 13 blank | 28 comment | 0 complexity | 8ff8f75ef3aab0ba652051ac3c6c7eaf MD5 | raw file
  1. --------------------------------------------------------------------
  2. -- Script for transport security sample.
  3. --
  4. -- This file is part of the Microsoft SQL Server Code Samples.
  5. -- Copyright (C) Microsoft Corporation. All Rights reserved.
  6. -- This source code is intended only as a supplement to Microsoft
  7. -- Development Tools and/or on-line documentation. See these other
  8. -- materials for detailed information regarding Microsoft code samples.
  9. --
  10. -- THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF
  11. -- ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  12. -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  13. -- PARTICULAR PURPOSE.
  14. --------------------------------------------------------------------
  15. -- This script sets up a the target broker endpoint for transport
  16. -- certificate-based security.
  17. -- Modify the location of the certificate in script to suit configuration.
  18. USE master;
  19. GO
  20. -- A master key is required to use certificates.
  21. BEGIN TRANSACTION;
  22. IF NOT EXISTS (SELECT * FROM sys.symmetric_keys WHERE name = '##MS_DatabaseMasterKey##')
  23. CREATE MASTER KEY ENCRYPTION BY PASSWORD ='Password#123'
  24. COMMIT;
  25. GO
  26. -- Create a certificate to authenticate the endpoint.
  27. IF EXISTS (SELECT * FROM sys.certificates WHERE name = 'target_transport_cert')
  28. DROP CERTIFICATE target_transport_cert;
  29. GO
  30. CREATE CERTIFICATE target_transport_cert
  31. WITH SUBJECT = 'Service broker transport authentication for target';
  32. GO
  33. -- Backup to a file to allow the certificate to be given to the initiator.
  34. BACKUP CERTIFICATE target_transport_cert
  35. TO FILE = 'c:\target_transport.cert';
  36. GO
  37. -- Create the broker endpoint using the certificate for authentication.
  38. IF EXISTS (SELECT * FROM sys.endpoints WHERE name = 'service_broker_endpoint')
  39. DROP ENDPOINT service_broker_endpoint;
  40. GO
  41. CREATE ENDPOINT service_broker_endpoint
  42. STATE = STARTED
  43. AS TCP (LISTENER_PORT = 4022)
  44. FOR SERVICE_BROKER (AUTHENTICATION = CERTIFICATE target_transport_cert);
  45. GO
  46. ----------EXCHANGE CERTIFICATES BEFORE PROCEEDING---------------
  47. -- The initiator and target certificates must be exchanged in order for them to
  48. -- authenticate each other. In a production system, this "out of band" exchange
  49. -- should be done with a high level of trust, since a certificate bearer will be
  50. -- able to begin dialogs and send messages to service broker services in the
  51. -- authenticating server. However, assuming the sample is being used on a development
  52. -- system, the exchange may be simple remote copies.