使用 xmlsec1 對 InCommon SAML 元資料進行簽章驗證失敗

使用 xmlsec1 對 InCommon SAML 元資料進行簽章驗證失敗

共同聯邦提供 IdP 和 SP 元資料。他們的刷新政策建議經常檢查元資料聚合使用最新版本。他們強烈推薦 InCommon SP刷新並驗證元數據至少每天。

以下提供的說明元數據消耗頁面上,我下載了一個聚合並獲得了元資料簽名證書的真實副本。

然後,我要「驗證下載的元資料上的 XML 簽章」。這就是我遇到問題的地方。我能夠驗證下載的元數據帶有嵌入的 x509 證書,但無法使用單獨下載的元資料簽署憑證進行驗證。

我從 InCommon 下載了兩個檔案:

  • xml:InCommon-metadata-idp-only.xml
  • 私人簽署金鑰:inc-md-cert.pem

我想我應該能夠運行命令:

# xmlsec1 --verify \
     --id-attr:ID urn:oasis:names:tc:SAML:2.0:metadata:EntitiesDescriptor \
     --privkey-pem ./inc-md-cert.pem \
     ./InCommon-metadata-idp-only.xml

失敗說「無法從./inc-md-cert.pem載入私鑰」。我可以使用 驗證它包含有效的金鑰openssl x509 -text -in ./inc-md-cert.pem。 (它是可讀的,這是正確的路徑。)如果我用--privkey-pemor引用它,也會以同樣的方式失敗--pubkey-pem

現在,如果我改用--pubkey-cert-pem ./inc-md-cert.pem它,它運行時不會出現錯誤,指示OK SignedInfo References (ok/all): 1/1.

但不,它顯然忽略了我的私人簽署金鑰,只是根據嵌入在metadata.xml 檔案中的金鑰進行驗證。 (我可以--pubkey-cert-pem完全刪除該參數,並且使用嵌入式 x509 憑證進行驗證仍然有效。

更新

鑑於提供的簽名文件是自簽署的(由組織),我嘗試將其自身添加為受信任的證書。例如,如果您嘗試使用 openssl 進行基本驗證,請比較:

# openssl verify ./inc-md-cert.pem
error 18 at 9 depth lookup:self signed certificate
# openssl verify -CAfile ./inc-md-cert.pem ./inc-md-cert.pem
./inc-md-cert.pem: OK

那麼如果這就是問題所在呢?所以我嘗試添加--trusted-pem選項

# xmlsec1 --verify \
     --id-attr:ID urn:oasis:names:tc:SAML:2.0:metadata:EntitiesDescriptor \
     --privkey-pem ./inc-md-cert.pem \
     --trusted-pem ./inc-md-cert.pem \
     ./InCommon-metadata-idp-only.xml
func=xmlSecOpenSSLAppKeyLoadBIO:file=app.c:line=263:
   obj=unknown:subj=PEM_read_bio_PrivateKey and PEM_read_bio_PUBKEY:
   error=4:crypto library function failed: 
func=xmlSecOpenSSLAppKeyLoad:file=app.c:line=153:
   obj=unknown:subj=xmlSecOpenSSLAppKeyLoadBIO:
   error=1:xmlsec library function failed:
   filename=/tmp/inc-md-cert.pem;errno=2
func=xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad:file=crypto.c:line=118:
   obj=unknown:subj=xmlSecCryptoAppKeyLoad:
   error=1:xmlsec library function failed:uri=./inc-md-cert.pem
Error: failed to load public key from "./inc-md-cert.pem".
Error: keys manager creation failed

我認為這是我的根本錯誤,因為這不會那麼困難:如何使用外部金鑰(由 InCommon 提供)來驗證元資料檔案(由 InCommon 提供)的簽章?

答案1

一種解決方案,雖然感覺有點不太令人滿意:

a) 驗證 InCommon 元資料文件使用嵌入的證書

# xmlsec1  --verify --id-attr:ID \ 
        urn:oasis:names:tc:SAML:2.0:metadata:EntitiesDescriptor  \
       ./InCommon-metadata-idp-only.xml
OK
SignedInfo References (ok/all): 1/1
Manifests References (ok/all): 0/0

b) 然後,只需將嵌入的憑證與單獨下載的憑證進行比較—它們應該匹配,以空格為模。請注意,一個或其他證書可能會被鏈接,出於比較目的,您應該忽略它。

答案2

經過一番努力,我發現您可以嘗試添加--enabled-key-data到命令列中,例如:

--enabled-key-data rsa 或者 --enabled-key-data x509

要么這些都應該有效。你也可以嘗試

xmlsec1 --list-key-data查看您可以選擇的內容。

在你的情況下似乎

xmlsec1 --verify \
  --enabled-key-data rsa \
  --id-attr:ID urn:oasis:names:tc:SAML:2.0:metadata:EntitiesDescriptor \
  --pubkey-cert-pem ./inc-md-cert.pem \
  ./InCommon-metadata-idp-only.xml

應該做你想做的事。

相關內容