首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Microsoft安全支持提供者接口(SSPI)加密和签名消息

使用Microsoft安全支持提供者接口(SSPI)加密和签名消息
EN

Stack Overflow用户
提问于 2017-03-08 16:22:17
回答 2查看 1.2K关注 0票数 2

我希望在Windows域环境(与Kerberos一起)中使用Microsoft的安全支持提供者接口(SSPI)在两个实体之间(在C++中)发送加密和签名的消息。

基于MSDN中的文档,有两个函数MakeSignature()和EncryptMessage() 1,但是文档和示例代码2没有明确说明如何发送加密和签名的数据(根据encrypt)。

有人能确认我必须按顺序手动调用EncryptMessage()和MakeSignature()来获得所需的结果吗?还是我错过了一些东西,EncryptMessage()有一种方法可以直接创建加密数据的签名?

1 EncryptMessage()和MakeSignature() https://msdn.microsoft.com/en-us/library/windows/desktop/aa378736(v=vs.85).aspx的MSDN文档

https://msdn.microsoft.com/en-us/library/windows/desktop/aa375378(v=vs.85).aspx

2 MSDN示例代码https://msdn.microsoft.com/en-us/library/windows/desktop/aa380531(v=vs.85).aspx

谢谢@ Rusanu的回答,我还没有考虑GSSAPI互操作性文档。

这里指出,"GSS_Wrap和GSS_Unwrap用于完整性和隐私,隐私的使用受"conf_flag“参数的值控制。”而且,“与GSS_Wrap等价的SSPI是EncryptMessage (Kerberos),既具有完整性,又具有隐私性”。

你说"EncryptMessage .如果谈判的上下文需要的话,也会进行签名。“这意味着,至少需要为InitializeSecurityContext()设置以下InitializeSecurityContext标志:

  • ISC_REQ_CONFIDENTIALITY
  • ISC_REQ_INTEGRITY

你(或其他人)能证实这一点吗?

--更新2017-03-16

经过进一步的研究,我得出了以下的见解:

  1. Kerberos特定的EncryptMessage()函数不提供消息完整性,不管Securitycontext是如何初始化的。
代码语言:javascript
复制
- The [general EncryptMessage()](https://msdn.microsoft.com/en-us/library/windows/desktop/aa375378(v=vs.85%29.aspx) and [general DecryptMessage](https://msdn.microsoft.com/en-us/library/windows/desktop/aa375211(v=vs.85%29.aspx) functions support the feature of creating and verifying the message's integrity because there exists some supporting Security Support Providers (SSPs) - but Kerberos does not.
- If DecryptMessage would check the message's integrity, there must be a respective error return code in case of a modified message. The general DecryptMessage interface lists the error code "SEC\_E\_MESSAGE\_ALTERED" which is described as "The message has been altered. Used with the Digest and Schannel SSPs.".
- The specific DecryptMessage interface for the SSPs Digest and Schannel lists the SEC\_E\_MESSAGE\_ALTERED - but the [Kerberos DecryptMessage](https://msdn.microsoft.com/en-us/library/windows/desktop/aa375215(v=vs.85%29.aspx) **does not**.
- Within the parameter description of the general EncryptMessage's documentation, the term 'signature' is used only regarding the Digest SSP: "When using the Digest SSP, there must be a second buffer of type SECBUFFER\_PADDING or SEC\_BUFFER\_DATA to hold signature information".

  1. MakeSignature不会根据维基百科的定义 (真实性+不可否认性+完整性)创建数字签名.MakeSignature创建加密散列以提供消息完整性。
代码语言:javascript
复制
- The name of the MakeSignature() function leads to the idea that SSPI creates a digital signature (authenticity + non-repudiation + integrity) but the [MakeSignature documentation](https://msdn.microsoft.com/en-us/library/windows/desktop/aa378736(v=vs.85%29.aspx) explains that only a cryptographic checksum is created (providing integrity): "The MakeSignature function generates a cryptographic checksum of the message, and also includes sequencing information to prevent message loss or insertion."
- The [VerifySignature documentation](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380540(v=vs.85%29.aspx) helps as well to clarify SSPI's terminology: "Verifies that a message signed by using the MakeSignature function was received in the correct sequence and has not been modified."

  1. 从(1)和(2)可以看出,为了实现机密性和完整性,需要调用EncryptData(),然后调用MakeSignature() (用于密文)。

希望我的自我回答能在某一时刻帮助某人;)

如果有人在我的答复中添加或更正了什么,请回复并帮助改进这里收集的信息!

EN

回答 2

Stack Overflow用户

发布于 2017-03-08 17:22:14

如果我没记错的话,您只调用EncryptMessage/DecryptMessage,如果协商好的上下文需要它,它也会进行签名。例如,如果您查看SSPI/Kerberos与GSSAPI的互操作性,它声明EncryptMessage对与GSS_UnwrapDecryptMessage对与GSS_Wrap,而不涉及MakeSignature。链接中的示例还显示,必须向3 SecBuffer结构(SECBUFFER_TOKENSECBUFFER_DATASECBUFFER_PADDING,我认为最后一个是可选的)提供给EncryptMessage,并为DecryptMessage提供2。在Windows套接字服务器中使用SSPI在Windows套接字客户端中使用SSPI中的两个互补示例提供了完全的功能消息交换,您还可以看到,MakeSignature/VerifySignature从未被调用,签名由加密/解密处理,并被放置在“安全令牌”报头或预告片中(在其中,SSPI/SPNego/Kerberos没有指定连接,这不是TLS/Schannel.)。

票数 0
EN

Stack Overflow用户

发布于 2021-03-25 21:01:22

如果您希望创建一个仅带有签名(未加密)的GSS令牌,请将KERB_WRAP_NO_ENCRYPT作为EncryptMessage值传递给EncryptMessage。签名包装令牌包括有效负载和签名。

MakeSignature创建一个GSS令牌--它只是签名,不包括有效负载。您可以将其用于需要分离签名的应用程序协议。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42676575

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档