Click here to change the language (ja-JP).
This tutorial shows how to perform the basic tasks in Trust Services. Trust Services is a collection of components and Azure Service that enables secure information sharing through the Cloud. It enables you to encrypt your data before uploading it to cloud storage, saving it on a disk or sending it to your partner. In this tutorial, you will learn how to subscribe to Trust Services, define policies that enforce protection of data, and use the policies to encrypt and decrypt sample data. The demo scenario involves four parties:
Note:
Recommended:
In the steps below, you will learn how to subscribe to Trust Services, define policies that enforce protection of data, and use the policies to encrypt and decrypt sample data.
X.509 certificates are used for authentication by Trust Service, and encryption and signing by Trust Services SDK and PowerShell Snap-In. Certificates for the following three personas will be needed:
makecert -r -pe -n "CN=Azure.Trust.Sample.PolicyAdmin" -sky exchange -ss my %HOMEPATH%\PolicyAdmin.cer makecert -r -pe -n "CN=Azure.Trust.Sample.DataPublisher" -sky exchange -ss my %HOMEPATH%\DataPublisher.cer makecert -r -pe -n "CN=Azure.Trust.Sample.DataConsumer" -sky exchange -ss my %HOMEPATH%\DataConsumer.cer
These steps are performed by the TSA role described in the Introduction.
Figure 1. Trust Server Portal shows the name of the Trust Server generated for you and certificate of TSPA associated with the Trust Server.
Note: Copy the Trust Server name. It will be needed in subsequent actions on the client machines.
Download “Trust Services” SDK here and install.
When installing the 64-bit version of the SDK, save the TrustServiceLab_amd64.msi file to local disk, before double-clicking on the file in Windows Explorer to start installation. This prevents an error message (about the Trust Services plugin not being found) from being displayed when the installer attempts to start the Trust Services Powershell window when installation completes. See the Troubleshooting page for more details.
These steps are performed by the TSPA role described in the Introduction.
# Example script for using Trust Services PowerShell Snap-In. # Policy Administrator defines encryption data policy and # authorizes Data Publisher and Data Consumer to the policy and data. $ErrorActionPreference = "Stop" # Thumbprints of certificates. # Public key of policy administrator must be uploaded as .cer file to # Trust Server using Trust Services Portal. $policyAdminThumbprint = "153deca0bdd9f93cab118a75bef5bc8b25e1a8b7" $publisherThumbprint = "ae331870917312e78d86c2e0f0b7e3dde5ab75ee" $consumerThumbprint = "2e61b5d64c97746e44a75cbecd811329ecdfb9b4" # Name of Trust Server created using Trust Services Portal. $trustServerName = "i4p091naue" # URL of Trust Service. Can be obtained from Trust Services Portal. $trustServiceUrl = "https://TrustServicesApi2.cloudapp.net/" # Find certificates to use by Trust Services snap-in. # These certificates must be already uploaded to Trust Server using Trust Services Portal. $paCert = dir cert:\currentUser\my | where-object { $_.thumbprint -eq $policyAdminThumbprint } if ($paCert -eq $null) { Throw "Policy Administrator certificate with thumbprint ""$policyAdminThumbprint"" " + "not found in Current User Windows certificate store." } $pubCert = dir cert:\currentUser\my | where-object { $_.thumbprint -eq $publisherThumbprint } if ($pubCert -eq $null) { Throw "Data Publisher certificate with thumbprint ""$publisherThumbprint"" " + "not found in Current User Windows certificate store." } $subCert = dir cert:\currentUser\my | where-object { $_.thumbprint -eq $consumerThumbprint } if ($subCert -eq $null) { Throw "Data Consumer certificate with thumbprint ""$consumerThumbprint"" " + "not found in Current User Windows certificate store." } # Create admin ECM to create policies using Trust Services cmdlets. if ( !(Test-Path "ecm:\polAdmin") ) { Write-Host "Creating admin Trust Services Edge Compliance Module" New-Ecm -Admin -ServerName $trustServerName -ServerUrl $trustServiceUrl ` -EcmOwner $paCert -FriendlyName "polAdmin" } Write-Host "Adding Data Publisher" Add-Principal -Principal $pubCert -FriendlyName "polAdmin" Write-Host "Adding Data Subscriber" Add-Principal -Principal $subCert -FriendlyName "polAdmin" # Create a policy that data for URI "example:exampleUri" must be encrypted. $policyUri = "example:exampleUri" Write-Host "Creating policy for URI ""$policyUri""" Add-DataPolicy -Encrypt -PolicyUri $policyUri -FriendlyName "polAdmin" # Authorize publisher and consumer to data with URI "example:exampleUri". Write-Host "Adding authorization for URI ""$policyUri"" to Data Publisher" Add-DataAuthorization -Principal $pubCert -PolicyUri $policyUri -FriendlyName "polAdmin" Write-Host "Adding authorization for URI ""$policyUri"" to Data Consumer" Add-DataAuthorization -Principal $subCert -PolicyUri $policyUri -FriendlyName "polAdmin"
dir cert:\currentUser\my | where {$_.Subject -eq "CN=Azure.Trust.Sample.PolicyAdmin" } dir cert:\currentUser\my | where {$_.Subject -eq "CN=Azure.Trust.Sample.DataPublisher" } dir cert:\currentUser\my | where {$_.Subject -eq "CN=Azure.Trust.Sample.DataConsumer" }
d:\TrustPolicyExample.ps1
File d:\TrustPolicyExample.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process
PS C:\Program Files\Microsoft\Trust Services Lab SDK and Shell (x64)\bin> d:\TrustPolicyExample.ps1 Creating admin Trust Services Edge Compliance ModuleAdding Data PublisherAdding Data SubscriberCreating policy for URI "example:exampleUri"Adding authorization for URI "example:exampleUri" to Data PublisherAdding authorization for URI "example:exampleUri" to Data ConsumerPS C:\Program Files\Microsoft\Trust Services Lab SDK and Shell (x64)\bin>
Note: You can also use C# SDK to generate data policies. Please refer to samples on Trust Services Samples page.
Perform the following steps after the policies are created in the previous section. The steps in this section are performed by Data Publisher and Data Consumer roles described in the Introduction.
# Example script for using Trust Services PowerShell Snap-In. # Data Publisher encrypts data that Data Consumer decrypts. # Policy Administrator must have already defined encryption data policy and # authorized Data Publisher and Data Consumer to the policy and data. $ErrorActionPreference = "Stop" # Thumbprints of certificates. # Public key of policy administrator must be uploaded as .cer file to # Trust Server using Trust Services Portal. # Public keys of Data Publisher and data user must have been added using # Add-Principal command. $policyAdminThumbprint = "153deca0bdd9f93cab118a75bef5bc8b25e1a8b7" $publisherThumbprint = "ae331870917312e78d86c2e0f0b7e3dde5ab75ee" $consumerThumbprint = "2e61b5d64c97746e44a75cbecd811329ecdfb9b4" # Name of Trust Server created using Trust Services Portal. $trustServerName = "i4p091naue" # URL of Trust Service. Can be obtained from Trust Services Portal. $trustServiceUrl = "https://TrustServicesApi2.cloudapp.net/" # Find certificates to use by Trust Services snap-in. # These certificates must be already uploaded to Trust Server using Trust Services Portal. $paCert = dir cert:\currentUser\my | where-object { $_.thumbprint -eq $policyAdminThumbprint } if ($paCert -eq $null) { Throw "Policy Administrator certificate with thumbprint ""$policyAdminThumbprint"" " + "not found in Current User Windows certificate store." } $pubCert = dir cert:\currentUser\my | where-object { $_.thumbprint -eq $publisherThumbprint } if ($pubCert -eq $null) { Throw "Data Publisher certificate with thumbprint ""$publisherThumbprint"" " + "not found in Current User Windows certificate store." } $subCert = dir cert:\currentUser\my | where-object { $_.thumbprint -eq $consumerThumbprint } if ($subCert -eq $null) { Throw "Data Consumer certificate with thumbprint ""$consumerThumbprint"" " + "not found in Current User Windows certificate store." } # Create publisher ECM to encrypt data if ( !(Test-Path "ecm:\pubUser") ) { Write-Host "Creating publisher Trust Services Edge Compliance Module" New-Ecm -User -ServerName $trustServerName -ServerUrl $trustServiceUrl ` -EcmOwner $pubCert -TrustedPrincipal $paCert -FriendlyName "pubUser" } # Create consumer ECM to decrypt data if ( !(Test-Path "ecm:\subUser") ) { Write-Host "Creating consumer Trust Services Edge Compliance Module" New-Ecm -User -ServerName $trustServerName -ServerUrl $trustServiceUrl ` -EcmOwner $subCert -TrustedPrincipal $paCert -FriendlyName "subUser" } # Policy must have been already created by the Policy Administrator. $policyUri = "example:exampleUri" # Data to be encrypted. [byte[]] $originalBytes = 1,2,3 $originalString = -join ($originalBytes | foreach {$_.ToString("X2") } ) Write-Host "Publisher encrypting data $originalString" # Encrypt data. $encryptedBytes = Add-Encryption -ClearBytes $originalBytes -PolicyUri $policyUri -FriendlyName "pubUser" $encryptedString = -join ($encryptedBytes | foreach {$_.ToString("X2") } ) Write-Host "Consumer decrypting data $encryptedString" # Decrypt data. $decryptedBytes = Remove-Encryption -CypherBytes $encryptedBytes -PolicyUri $policyUri -FriendlyName "subUser" $decryptedString = -join ($decryptedBytes | foreach {$_.ToString("X2") } ) Write-Host "Consumer decrypted data $decryptedString"
d:\TrustEncryptExample.ps1
File d:\TrustEncryptExample.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.
PS C:\Program Files\Microsoft\Trust Services Lab SDK and Shell (x64)\bin> d:\TrustEncryptExample.ps1Creating publisher Trust Services Edge Compliance ModuleCreating consumer Trust Services Edge Compliance ModulePublisher encrypting data 010203Consumer decrypting data D83D01005ED3660A9D7EF1C78104340E26DCDD81149BF20545160B07B264DBE52ECF8CEA5F80CC91E641289829D670931CBBB0DA0040010000000000010000000100000030BCA3FB8194999E5F354114231B7F0E7FE3BB68033C8DDF0F70E80A9CE6844B0200000002000000F6CFBC8EFAA8348D1690B411EAE1A7F3F5CBBF7286AA7EF2BD26B636869FF42FConsumer decrypted data 010203PS C:\Program Files\Microsoft\Trust Services Lab SDK and Shell (x64)\bin>
Note: You can also use C# SDK to create an application that performs data encryption and decryption operations. Please refer to samples on Samples
Learn More
Download "Trust Services" SDK
Access "Trust Services" Portal
Samples
Troubleshooting
SQL Azure Labs Forums
Glossary
Horizon_Net edited Revision 89. Comment: added language tags
Dmitry Denisov MSFT edited Revision 25. Comment: Minor formatting
Dmitry Denisov MSFT edited Revision 24. Comment: Certificates instructions added
Dmitry Denisov MSFT edited Revision 22. Comment: Reverting to smaller font
Dmitry Denisov MSFT edited Revision 21. Comment: Larger font for output box