Numéro d'article: 915852 - Dernière mise à jour: jeudi 31 mai 2007 - Version: 1.3

Comment utiliser des certificats pour SQL Server 2005 Service Broker la sécurité à distance sur plusieurs instances de SQL Server 2005

A noterCet article s'applique à un système d'exploitation différent de celui que vous utilisez. Le contenu de l'article qui ne vous concerne peut-être pas est désactivé.

Sommaire

Agrandir tout | Réduire tout

INTRODUCTION

Cet article explique comment utiliser les certificats de sécurité à distance de SQL Server 2005 Service Broker sur plusieurs instances de SQL Server 2005. En utilisant des certificats dans ce cas, vous pouvez fournir des connexions sécurisées.

Plus d'informations

SQL Server 2005 Service Broker la sécurité à distance inclut des opérations qui impliquent plusieurs instances de SQL Server lorsque les opérations utilisent soit sécurité de la boîte de dialogue ou sécurité de transport. L'exemple suivant montre comment utiliser les certificats de sécurité à distance de SQL Server 2005 Service Broker sur deux instances de SQL Server 2005. Il présuppose que les conditions suivantes sont remplies :
  • Vous avez créé quatre certificats et les quatre fichiers de clé privées à l'aide de l'outil de création de certificat (makecert.exe). Cet exemple suppose que ces fichiers ont été copiés dans le dossier C:\Certificates sur les deux serveurs et que les fichiers sont nommés suivantes :
    • SourceServer.cer
    • SourceServer.pvk
    • TargetServer.cer
    • TargetServer.pvk
    • DlgSourceServer.cer
    • DlgSourceServer.pvk
    • DlgTargetServer.cer
    • DlgTargetServer.pvk
    Pour plus d'informations créer des certificats pour le test, reportez-vous au site de Web MSDN (Microsoft Developer Network) suivant :
    http://msdn2.microsoft.com/en-us/library/bfsktky3(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/bfsktky3(vs.71).aspx)
  • Vous avez installé deux instances de SQL Server 2005 sur différents serveurs dans le même réseau. Cet exemple suppose que le premier serveur est intitulée ServerSrc et que le second serveur est intitulé ServerTag.
  • Vous vous connectez aux deux instances via des connexions qui sont membres du sysadmin SQL Server fixe rôle de serveur.
  • Vous avez apporté des assurer que le port TCP 4022 est disponible. Dans cet exemple, le port va être utilisé par les deux instances pour vous connecter à l'autre.
Lorsque toutes les conditions précédentes sont remplies, utiliser les procédures suivantes.

Configurer SQL Server 2005 Service Broker pour l'instance de SQL Server sur le serveur ServerSrc

  1. Se connecter à l'instance sur le serveur ServerSrc au moyen de SQL Server Management Studio.
  2. Exécutez les instructions Transact-SQL suivantes dans l'éditeur de requête :
    --Configure the transport security.
    USE MASTER
    go
    
    --Create a master key in the master database.
    CREATE MASTER KEY ENCRYPTION BY password = 'MasterKeyPassword'
    Go
    
    --Create a certificate for transport security.
    CREATE CERTIFICATE ctfSourceServerMaster
    FROM FILE = 'C:\Certificates\SourceServer.cer'
    WITH PRIVATE KEY ( FILE = 'C:\Certificates\SourceServer.pvk' , DECRYPTION BY PASSWORD = 'PrivateKeyPassword' )
    ACTIVE FOR BEGIN_DIALOG = ON
    GO
    
    --Create the login and the user to own a certificate.
    CREATE LOGIN remcert WITH PASSWORD = 'LoginPassword'
    GO
    CREATE USER remcert FOR LOGIN remcert
    GO
    CREATE CERTIFICATE ctftTargetServerMaster
    AUTHORIZATION remcert
    FROM FILE = 'C:\Certificates\TargetServer.cer'
    ACTIVE FOR BEGIN_DIALOG = ON
    GO
    
    --Create a new endpoint for SQL Server 2005 Service Broker, and set the AUTHENTICATION option to use the ctfSourceServerMaster certificate.
    CREATE ENDPOINT BrokerEndpoint
    	STATE = STARTED
    	AS TCP
    	(
    		LISTENER_PORT = 4022
    	)
    	FOR SERVICE_BROKER (AUTHENTICATION = CERTIFICATE ctfSourceServerMaster)
    GO
    
    --Grant the required permissions to the remcert login.
    GRANT CONNECT TO remcert
    GRANT CONNECT ON ENDPOINT::BrokerEndpoint to remcert
    GO
    
    --Create a new database for testing.
    CREATE DATABASE SourceDB
    GO
    USE SourceDB
    GO
    
    --Configure the dialog security.
    
    --Create a master key in the SourceDB database.
    CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'MasterKeyPassword'
    
    --Create a certificate for the SourceDB database.
    CREATE CERTIFICATE ctfDlgSourceServer
    FROM FILE = 'C:\certificates\DlgSourceServer.cer'
    WITH PRIVATE KEY 
    (FILE='C:\certificates\DlgSourceServer.pvk',decryption by password='PrivateKeyPassword')
    ACTIVE FOR BEGIN_DIALOG = ON
    GO
    
    --Create a user for the remcert login that owns a certificate for the dialog security.
    CREATE USER remcert for LOGIN remcert
    GO
    CREATE CERTIFICATE ctfDlgTargetServer
    AUTHORIZATION remcert
    FROM FILE = 'C:\certificates\DlgTargetServer.cer'
    ACTIVE FOR BEGIN_DIALOG = ON
    
    --Create a message type, a contract, a queue, and a service.
    
    CREATE MESSAGE TYPE [mymsg] VALIDATION = NONE 
    CREATE CONTRACT [mycon] ([mymsg] SENT BY ANY)
    CREATE QUEUE [myQueue]
    CREATE SERVICE [SourceService] ON QUEUE [myQueue]([mycon])
    GO
    
    --Grant the send permission to the user.
    GRANT SEND ON SERVICE::[SourceService] TO remcert
    
    --Create a remote service binding for the target service. 
    CREATE REMOTE SERVICE BINDING [Certificate_Binding_on_server]
       TO SERVICE 'TargetService'
       WITH  USER = remcert,
       ANONYMOUS=Off  
    
    --Create a route for the target service.
    CREATE ROUTE [myRoute]
        WITH 
        SERVICE_NAME = 'TargetService',
        address = 'TCP://ServerTag:4022';
    
    
    CREATE gamme [myRoute] avec SERVICE_NAME = 'TargetService, « adresse = « TCP: / / ServerTag:4022 '; Remarque MasterKeyPassword est un espace réservé pour le mot de passe de la clé principale que vous devez spécifier pour la base de données. PrivateKeyPassword est un espace réservé pour le mot de passe de la clé privée que vous avez spécifié pour le fichier de clé privée .pvk en utilisant l'outil Création de certificat. LoginPassword est un espace réservé pour le mot de passe de l'ouverture de session nouvellement créée.

Configurer SQL Server 2005 Service Broker pour l'instance de SQL Server sur le serveur ServerTag

  1. Se connecter à l'instance sur le serveur ServerTag au moyen de SQL Server Management Studio.
  2. Exécutez les instructions Transact-SQL suivantes dans l'éditeur de requête :
    --Configure the transport security.
    USE MASTER
    go
    
    --Create a master key in the master database.
    CREATE MASTER KEY ENCRYPTION BY password = 'MasterKeyPassword'
    Go
    
    --Create a certificate for transport security.
    CREATE CERTIFICATE ctfTargetServerMaster
    FROM FILE = 'c:\certificates\TargetServer.cer'
    WITH PRIVATE KEY (FILE='c:\certificates\TargetServer.pvk',decryption by password='PrivateKeyPassword')
    ACTIVE FOR BEGIN_DIALOG = ON
    GO
    
    --Create the login and the user to own a certificate.
    CREATE LOGIN remcert WITH PASSWORD = 'LoginPassword'
    GO
    CREATE USER remcert FOR LOGIN remcert
    GO
    CREATE CERTIFICATE ctfSourceServerMaster
    AUTHORIZATION remcert
    FROM FILE = 'c:\certificates\SourceServer.cer'
    ACTIVE FOR BEGIN_DIALOG = ON
    GO
    
    --Create a new endpoint for SQL Server 2005 Service Broker, and set the AUTHENTICATION option to use the ctfSourceServerMaster certificate.
    CREATE ENDPOINT BrokerEndpoint
    	STATE = STARTED
    	AS TCP
    	(
    		LISTENER_PORT = 4022
    	)
    	FOR SERVICE_BROKER (AUTHENTICATION = CERTIFICATE ctfTargetServerMaster)
    GO
    
    --Grant the required permissions to the remcert login.
    GRANT CONNECT TO remcert
    GRANT CONNECT ON ENDPOINT::BrokerEndpoint to remcert
    GO
    
    --Create a new database for testing.
    CREATE DATABASE TargetDB
    GO
    USE TargetDB
    GO
    
    --Configure the dialog security.
    
    --Create a master key in the TargetDB database.
    CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'MasterKeyPassword'
    
    --Create a certificate for the TargetDB database.
    CREATE CERTIFICATE ctfDlgTargetServer
    FROM FILE = 'c:\certificates\DlgTargetServer.cer'
    WITH PRIVATE KEY 
    (FILE='c:\certificates\DlgTargetServer.pvk',decryption by password='PrivateKeyPassword')
    ACTIVE FOR BEGIN_DIALOG = ON
    GO
    
    --Create a user for the remcert login that owns a certificate for the dialog security.
    CREATE USER remcert for LOGIN remcert
    GO
    CREATE CERTIFICATE ctfDlgSourceServer
    AUTHORIZATION remcert
    FROM FILE = 'C:\certificates\DlgSourceServer.cer'
    ACTIVE FOR BEGIN_DIALOG = ON
    
    --Create a message type, a contract, a queue, and a service.
    CREATE MESSAGE TYPE [mymsg] VALIDATION = NONE 
    CREATE CONTRACT [mycon] ([mymsg] SENT BY ANY)
    CREATE QUEUE [myQueue]
    CREATE SERVICE [TargetService] ON QUEUE [myQueue]([mycon])
    GO
    
    --Grant the send permission to the user.
    GRANT SEND ON SERVICE::[TargetService] TO remcert
    GO
    
    --Create a remote service binding for the target service. 
    CREATE REMOTE SERVICE BINDING [Certificate_Binding_on_server]
       TO SERVICE 'SourceService'
       WITH  USER = remcert,
       ANONYMOUS=Off  
    --Create a route for the target service.
    CREATE ROUTE [myRoute]
        WITH 
        SERVICE_NAME = 'SourceService',
        address = 'TCP://ServerSrc:4022';
    CREATE gamme [myRoute] avec SERVICE_NAME = 'SourceService, « adresse = « TCP: / / ServerSrc:4022 ' ;

Test de la sécurité à distance de SQL Server 2005 Service Broker

Après avoir configuré les deux instances, se connecter à l'instance sur le serveur ServerSrc et exécutez les instructions suivantes pour tester le service SQL Server 2005 Service Broker :
USE SourceDB
SET NOCOUNT ON
DECLARE @conversationHandle uniqueidentifier
BEGIN TRANSACTION
	-- Start dialog.
	BEGIN DIALOG  @conversationHandle
	FROM SERVICE    [SourceService]
	TO SERVICE      'TargetService'
	ON CONTRACT     [mycon]
	WITH ENCRYPTION = ON, LIFETIME = 600;

	-- Send message.
	SEND ON CONVERSATION @conversationHandle 
	MESSAGE TYPE [mymsg] (N'Hi, from '+@@ServerName)
COMMIT
CONVERSATION sur SEND @conversationHandle MESSAGE TYPE [mymsg] (N'Hi, à partir de ' + @@ServerName) COMMIT après vous exécutez ces instructions, vous connecter à l'instance sur le serveur ServerTag, puis exécutez l'instruction suivante :
SELECT CONVERT(NVARCHAR(MAX),message_body) FROM myQueue
GO
vous recevrez le résultat suivant :
Hi, from ServerSrc

Références

Pour plus d'informations sur SQL Server 2005 Service Broker, consultez les rubriques suivantes dans la en ligne de SQL Server 2005 :
  • Gestion de la sécurité (Service Broker)
  • Sécurité réseau et à distance
  • Service Broker boîte de dialogue sécurité
  • Déterminer le type de sécurité de boîte de dialogue
  • Liaisons service distant

Les informations contenues dans cet article s'appliquent au(x) produit(s) suivant(s):
  • Microsoft SQL Server 2005 Standard Edition
  • Microsoft SQL Server 2005 Developer Edition
  • Microsoft SQL Server 2005 Enterprise Edition
  • Microsoft SQL Server 2005 Workgroup Edition
Mots-clés : 
kbmt kbexpertiseadvanced kbsql2005servicebroker kbinfo KB915852 KbMtfr
Traduction automatiqueTraduction automatique
IMPORTANT : Cet article est issu du système de traduction automatique mis au point par Microsoft (http://support.microsoft.com/gp/mtdetails). Un certain nombre d?articles obtenus par traduction automatique sont en effet mis à votre disposition en complément des articles traduits en langue française par des traducteurs professionnels. Cela vous permet d?avoir accès, dans votre propre langue, à l?ensemble des articles de la base de connaissances rédigés originellement en langue anglaise. Les articles traduits automatiquement ne sont pas toujours parfaits et peuvent comporter des erreurs de vocabulaire, de syntaxe ou de grammaire (probablement semblables aux erreurs que ferait une personne étrangère s?exprimant dans votre langue !). Néanmoins, mis à part ces imperfections, ces articles devraient suffire à vous orienter et à vous aider à résoudre votre problème. Microsoft s?efforce aussi continuellement de faire évoluer son système de traduction automatique.
La version anglaise de cet article est la suivante: 915852  (http://support.microsoft.com/kb/915852/en-us/ )
L'INFORMATION CONTENUE DANS CE DOCUMENT EST FOURNIE PAR MICROSOFT SANS GARANTIE D'AUCUNE SORTE, EXPLICITE OU IMPLICITE. L'UTILISATEUR ASSUME LE RISQUE DE L'UTILISATION DU CONTENU DE CE DOCUMENT. CE DOCUMENT NE PEUT ETRE REVENDU OU CEDE EN ECHANGE D'UN QUELCONQUE PROFIT.