我正在构建一个运行在几十个嵌入式设备上的ServiceStack服务。我想确保与设备的所有通信都通过加密通道进行。我已经研究了各种SSL / TLS选项,但管理几十种不同的证书,或者将一个证书发布到几十台设备上,似乎需要很多开销。
我一直在关注Encrypted Messaging功能,但似乎只提供透明覆盖,这样就可以发送普通DTO或加密的DTO。
有没有办法限制我的端点只接受EncryptedMessage
DTO,同时保留内部处理它们的能力?可以告诉原始DTO的某种过滤器最初可能来自EncryptedMessage
吗?
我考虑过Service Gateway,但似乎我必须有两个独立的AppHosts - 一个用于接收加密数据,另一个用于内部(仅限内部)用于处理&响应。似乎应该有更好的方法。
答案 0 :(得分: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");