加密 SSO 的密碼
欲使用 KeyStore,KeyStore 提供者使用以檔案形式加密儲存的安全權杖。寫入至金鑰庫的所有資料都會使用密碼安全儲存。提供者初次啟動時,如果不存在隨機密碼值與 KeyStore 檔案,它就會產生隨機密碼值與 KeyStore 檔案。
* 
金鑰庫密碼與金鑰庫檔案應限制為僅供應用程式使用者使用。應用程式使用者必須擁有檔案的讀取/寫入權限。
* 
下列範例以 Windows 為基礎。如果您要使用 Linux 作業系統,請視需要變更指令。
欲提前建立 KeyStore 檔案並在其中儲存初始資料,您必須使用 安全性管理工具
1. PTC 支援網站取得「安全性管理工具」ZIP 檔。如果您已安裝此工具,請跳到步驟 3。
2. 將壓縮檔的內容解壓縮至某一目錄。
3. 使用下列參數建立組態檔案並將其放置在解壓縮檔案的 bin 資料夾中。
* 
在此範例中,檔案名為 keystore.conf,工具版本為 1.0.0.36,其位於 C://security-common-cli-1.0.0.36/bin
* 
default-encryption-key-length 必須符合應用程式組態。在 ThingWorx 中,就是位於 platform-settings.jsonInternalAesCryptographicKeyLength 參數。預設為 128,但是如果您使用 Java 1.8.0_162 或更高版本,則可以使用 256 位元加密。如有必要,您也可以更新金鑰大小限制的 java 政策來與較舊的 Java 版本搭配使用。
{
security {
secret-provider = "com.thingworx.security.provider.keystore.KeyStoreProvider"
default-encryption-key-length = 128
keystore {
password-file-path = "/ThingworxPlatform/ssoSecurityConfig"
password-file-name = "keystore-password"
path = "/ThingworxPlatform/ssoSecurityConfig"
name = "_sso_keystore"
}
}
}
4. 停止 ThingWorx 伺服器。
5. 以管理員身分啟動指令提示,並導向至 security-common-cli-1.0.0.36\bin 的位置。
6. 執行下列指令以切換至工具的 shell 提示:
C:\security-common-cli-1.0.0.36\bin> security-common-cli.bat <path to keystore>\keystore.conf
7. 執行下列指令集以插入密碼:
資料庫密碼:

> set encrypt.accesstoken.password <add-password-here>
KeyStore 儲存密碼 (sso-keystore.jks 的密碼):
> set encrypt.keystorestore.password <add-keystorestore-password-here>
KeyStore 金鑰密碼 (sso-keystore.jks 中金鑰的密碼):
> set encrypt.keystorekey.password <add-keystorekey-password-here>
服務提供者用戶端密碼:針對每個 AuthorizationServersSettings.<AuthorizationServerId> (在 /ThingworxPlatform/ssoSecurityConfig/sso-settings.json 檔案中提及)。

> set <AuthorizationServerId>.encrypt.SP.clientSecret <add-SP-clientSecret-here>
例如,針對下面的 sso-settings.json 組態檔案,請執行它後面的指令:
"AuthorizationServersSettings": {
"PingFed1": {
"clientId": "twx-sp-client-1",
"clientSecret": "twx-sp-client_1234",
"authorizeUri": "https://pingfed1.com:9031/as/authorization.oauth2",
"tokenUri": "https://pingfed1.com:9031/as/token.oauth2",
"clientAuthScheme": "form"
},
"PingFed2": {
"clientId": "twx-sp-client-2",
"clientSecret": "twx-sp-client_123456",
"authorizeUri": "https://pingfed2.com:9031/as/authorization.oauth2",
"tokenUri": "https://pingfed2.com:9031/as/token.oauth2",
"clientAuthScheme": "form"
}
}

Run:
> set PingFed1.encrypt.SP.clientSecret twx-sp-client_1234
> set PingFed2.encrypt.SP.clientSecret twx-sp-client_123456
資源提供者用戶端密碼 (只有在將 ThingWorx 配置為資源提供者的情況下):
> set encrypt.RP.clientSecret <add-clientSecret-here>
8. 鍵入 exit,以結束 shell 模式:
> exit
9. 開啟 /ThingworxPlatform/ssoSecurityConfig/sso-settings.json 並進行下列更新:
資料庫密碼:在 AccessTokenPersistenceSettings 下,將 password 值變更為:
"encrypt.accesstoken.password"
KeyStore 儲存密碼:在 KeyManagerSettings 下,將 keyStoreStorePass 值變更為:
"encrypt.keystorestore.password"
KeyStore 金鑰密碼:在 KeyManagerSettings 下,將 keyStoreKeyPassvalue 變更為:
"encrypt.keystorekey.password"
服務提供者用戶端密碼:針對每個 AuthorizationServersSettings.<AuthorizationServerId>.clientSecret,將 clientSecret 值變更為:
"encrypt.SP.clientSecret"
10. 如果將 ThingWorx 配置為資源提供者,請開啟 /ThingworxPlatform/ssoSecurityConfig/resourceServerSettings.json 檔案並進行下列更新:
資源提供者用戶端密碼:在 ResourceServerSettings.accessTokenServicesSettings 下,將 clientSecret 值變更為:
"encrypt.RP.clientSecret"
11. 啟動 ThingWorx 伺服器。