当前位置:   article > 正文

解决kkfileview 使用https预览问题记录

解决kkfileview 使用https预览问题记录

场景:项目使用了开源的kkfileview进行文件在线预览,部署方式使用的是docker,使用IP进行访问,但是http协议直接访问有漏洞告警,现在需要调整为https,且仍然需要使用IP访问。

kkfileview官网kkFileView - 在线文件预览
问题:使用自签证书将web中间件访问方式调整为https,代理kkfile容器8012端口,后预览图片正常,预览其他类型文件提示如下错误

错误信息: 

下载失败:org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://192.168.1.1:80/api/admin/image/local/c639a28c6e4b4278b8c93ff94352957a.txt": sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

解决方法:

1.重新自包含签证书SAN(Subject Alternative Name)的证书

  1. openssl genrsa -out server.key 2048
  2. cat >server.cnf<<EOF
  3. [req]
  4. default_bits = 2048
  5. prompt = no
  6. default_md = sha256
  7. distinguished_name = dn
  8. req_extensions = req_ext
  9. [dn]
  10. C = CN
  11. ST = Province
  12. L = City
  13. O = Organization
  14. OU = Organizational Unit
  15. CN = test
  16. [req_ext]
  17. subjectAltName = @alt_names
  18. [alt_names]
  19. # 如果需要,可以添加更多的DNS或IP地址
  20. #DNS.1 = baidu.com
  21. IP.1 = 192.168.1.1
  22. IP.2 = 192.168.1.2
  23. EOF
  24. openssl req -new -sha256 -key server.key -config server.cnf -out server.csr
  25. openssl x509 -req -days 3650 -in server.csr -signkey server.key -extfile server.cnf -extensions req_ext -out server.crt

2.修改Dockerfile把证书加入到kkfile的jdk环境

  1. cat >Dockerfile<<EOF
  2. FROM keking/kkfileview:v4.4.0
  3. MAINTAINER hello
  4. ADD server.crt /opt/
  5. RUN keytool -import -alias myServer -file /opt/server.crt -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -noprompt
  6. ENTRYPOINT ["java","-Dfile.encoding=UTF-8","-Dspring.config.location=/opt/kkFileView-4.4.0-beta/config/application.properties","-jar","/opt/kkFileView-4.4.0-beta/bin/kkFileView-4.4.0-beta.jar"]
  7. EOF
  8. docker build -t keking/kkfileview:v4.4.1 .

3.使用新镜像重新启动kkfileview

  1. docker stop kkfile && docker rm kkfile
  2. docker run -d -p 8012:8012 -e KK_BASE_URL="https://192.168.1.1" --name kkfile keking/kkfileview:v4.4.1

4.替换web中间件的自签证书,重新加载web服务,验证预览

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/正经夜光杯/article/detail/892260
推荐阅读
相关标签
  

闽ICP备14008679号