【问题标题】:Only allow `EncryptedMessage` for ServiceStack host只允许 ServiceStack 主机使用 `EncryptedMessage`
【发布时间】:2017-08-24 15:04:57
【问题描述】:

我正在构建一个在几十个嵌入式设备上运行的ServiceStack 服务。我想确保与设备的所有通信都通过加密通道进行。我研究了各种 SSL/TLS 选项,但管理几十个不同的证书,或将一个证书发布到几十个设备,似乎开销很大。

我一直在研究 Encrypted Messaging 功能,但它似乎只提供了一个透明的覆盖,这将允许发送纯 DTO 或加密 DTO。

有没有办法限制我的端点只接受EncryptedMessage DTO,同时保留在内部处理它们的能力?某种可以判断原始 DTO 的过滤器最初可能来自 EncryptedMessage 吗?

我考虑过Service Gateway,但似乎我必须有两个单独的 AppHosts - 一个用于接收加密数据,一个(仅限内部)用于处理和响应。似乎应该有更好的方法。

【问题讨论】:

    标签: c# asp.net servicestack


    【解决方案1】:

    我刚刚在this commit 中将加密消息请求标记为安全,这将允许您使用Restricting Services Attribute 来确保仅通过以下方式发出安全请求:

    [Restrict(RequestAttributes.Secure)]
    public class SecureOnlyServices { }
    
    [Restrict(RequestAttributes.InSecure | RequestAttributes.InternalNetworkAccess,
              RequestAttributes.Secure   | RequestAttributes.External)]
    public class InternalHttpAndExternalSecure { }
    

    此更改从 v4.5.13 开始可用,现在是 available on MyGet

    ServiceStack 的早期版本可以检查IRequest.Items 字典以确定它是否是加密消息请求:

    var isEncryptedMessagingRequest = base.Request.Items.ContainsKey("_encryptCryptKey");
    if (!isEncryptedMessagingRequest)
        throw new HttpError.Forbidden("Only secure requests allowed");
    

    【讨论】:

    • 谢谢@mythz。看起来RestrictAttribute 是要走的路,但我不想自己动手!
    猜你喜欢
    • 2023-02-23
    • 1970-01-01
    • 2016-07-25
    • 2017-02-28
    • 2020-09-01
    • 2019-07-07
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    相关资源
    最近更新 更多