gpt4 book ai didi

cloud-foundry - Spring Cloud Config Server 加密问题

转载 作者:行者123 更新时间:2023-12-04 09:57:51 26 4
gpt4 key购买 nike

我们有一个 Pivotal Cloud Foundry 服务器,它配置了一个带有加密 key 的 Spring 配置服务器。在相应的属性文件(通过 github)中,我们为一些简单的属性添加了 {cipher} 前缀,我们能够在应用程序中很好地获取这些值。但是我们最近注意到的挑战是,当我们有一个 base64 数据需要加密时,spring 加密会截断 base64 数据末尾的尾随等号。当我们的应用程序读取这些数据时,它解析它失败,因为它不是有效的 base64,因为它在末尾缺少填充字符(等号)。我们尝试用反斜杠转义等号,但仍然没有运气。我们只看到两个反斜杠,所以想知道是否有任何建议可以解决这个问题。谢谢!

最佳答案

据我所知,这里的问题似乎与 curl 的用法有关。 .我可以通过运行来复制您看到的问题:

spring decrypt --key @${HOME}/server_rsa_no_eol.key "$(curl -H "Authorization: $(cf oauth-token)" https://config-server.example.com/encrypt -s -d 'VGVzdC0=')"

这使用 curl命中加密端点并获取结果并立即使用 spring decrypt 解密它.正如您所指出的,这将返回 VGVzdC0 .

这似乎是一个 curl 问题,因为我可以将相同的帖子发送到 https://httpbin.org/post我得到了相同的结果, VGVzdC0没有 = .
$ curl https://httpbin.org/post --data 'VGVzdC0='
{
...
"form": {
"VGVzdC0": ""
},
...

有效的是,如果我对 = 进行 url 编码特点。
$ curl https://httpbin.org/post --data 'VGVzdC0%3D'
{
...
"form": {
"VGVzdC0=": ""
},
...

您也可以制作 curl使用 --data-urlencode 进行 url 编码但有一个问题。您必须使用 = 作为该值的前缀.所以这也有效
$ curl https://httpbin.org/post --data-urlencode '=VGVzdC0='
{
"args": {},
"data": "",
"files": {},
"form": {
"VGVzdC0=": ""
},
...

从 curl 手册页:
  --data-urlencode <data>
(HTTP) This posts data, similar to the other -d, --data options with the exception that this performs URL-encoding.

To be CGI-compliant, the <data> part should begin with a name followed by a separator and a content specification. The <data> part can be passed to curl using one of the following
syntaxes:

content
This will make curl URL-encode the content and pass that on. Just be careful so that the content doesn't contain any = or @ symbols, as that will then make the syntax match
one of the other cases below!

=content
This will make curl URL-encode the content and pass that on. The preceding = symbol is not included in the data.

关键是最后一部分 =content .这将使 curl url 编码内容和前缀 =不包括在内。

如果我重复上面的测试,我会得到预期的结果 VGVzdC0= .
spring decrypt --key @${HOME}/server_rsa_no_eol.key "$(curl -H "Authorization: $(cf oauth-token)" https://config-server.example.com/encrypt -s --data-urlencode '=VGVzdC0=')"

顺便说一句,您还可以采用简单的选项并安装 Spring Boot CLI + Spring Cloud Extension。然后你就可以 spring encrypt --key @${HOME}/server_rsa_no_eol.key 'VGVzdC0='你会得到正确的值。这确实意味着您需要本地计算机上的 key 副本,您可能有也可能没有。
brew install springboot
spring install org.springframework.cloud:spring-cloud-cli:2.2.1.RELEASE
  • https://docs.spring.io/spring-boot/docs/2.2.7.RELEASE/reference/html/spring-boot-cli.html#cli-installation
  • https://cloud.spring.io/spring-cloud-static/spring-cloud-cli/2.2.1.RELEASE/reference/html/#_installation
  • 关于cloud-foundry - Spring Cloud Config Server 加密问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61883560/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com