Loading [MathJax]/jax/output/CommonHTML/config.js
社区首页 >问答首页 >如何在中使用GoDaddy SSL证书?

如何在中使用GoDaddy SSL证书?
EN

Stack Overflow用户
提问于 2022-11-04 05:14:58
回答 1查看 43关注 0票数 0

我正在一个我继承的网站上工作。该网站是在Spring与嵌入式Tomcat服务器。它正在为HTTPS使用一个.jks文件。SSL证书已经过期,我正在尝试从Godaddy收到的文件中创建一个ne .jks文件。有一份文件说明了如何去做,但是缺少了一些东西。

代码语言:javascript
代码运行次数:0
复制
These are the steps in document to create .jks file:

Security Settings
C:\trash\keyproc>openssl req -new -newkey rsa:2048 -nodes -keyout website_name_here.key -out website_name_here.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:XX
State or Province Name (full name) [Some-State]:XXXXX
Locality Name (eg, city) []:XXXX
Organization Name (eg, company) [Internet Widgits Pty Ltd]:XXXXX
Organizational Unit Name (eg, section) []:Software Development
Common Name (e.g. server FQDN or YOUR name) []:website_name_here.co
Email Address []:xxxxx@gmail.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:pwd_here
An optional company name []:xxxxx
Two files are generated website_name_here.key & website_name_here.csr
Use website_name_here.csr generated to get certificate from Godaddy.
Get SSL cetrificate from Godaddy and extract to this folder.

####################  Java Version 17 was active from hereon #################################################################

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.


C:\trash\keyproc>keytool -importkeystore -deststorepass pwd_here -destkeystore website_name_here.jks -srckeystore website_name_here.p12 -srcstoretype PKCS12
Importing keystore website_name_here.p12 to website_name_here.jks...
Enter source keystore password:
Entry for alias website_name_here.co successfully imported.
Import command completed:  1 entries successfully imported, 0 entries failed or cancelled

Warning:
The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using "keytool -importkeystore -srckeystore website_name_here.jks -destkeystore website_name_here.jks -deststoretype pkcs12".

C:\trash\keyproc>

After this just import  main CRT file not bundle file using keytool.

在上述步骤中没有提到website_name_here.p12文件来自何处。可能是什么?

使用.jks文件的代码如下所示:

代码语言:javascript
代码运行次数:0
复制
import lombok.SneakyThrows;
import org.apache.catalina.connector.Connector;
import org.apache.coyote.http11.Http11NioProtocol;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.stereotype.Component;

import java.net.InetAddress;
import java.util.Optional;
//@Profile("dev")
@Component
public class TomcatEmbedServerCustomConfiguration implements WebServerFactoryCustomizer<TomcatServletWebServerFactory>
{
    private static final Logger logger = LoggerFactory.getLogger(TomcatEmbedServerCustomConfiguration.class);

    IWebApplicationServerSettingsRepository appSettinsRepository;

    ApplicationHttpsSettingsEntityRepository applicationHttpsSettingsEntityRepository;

    public TomcatEmbedServerCustomConfiguration(IWebApplicationServerSettingsRepository appSettinsRepository, ApplicationHttpsSettingsEntityRepository applicationHttpsSettingsEntityRepository)
    {
        this.appSettinsRepository = appSettinsRepository;
        this.applicationHttpsSettingsEntityRepository = applicationHttpsSettingsEntityRepository;
    }

    @SneakyThrows
    @Override
    public void customize(TomcatServletWebServerFactory factory)
    {
        logger.info("Setting the Tomcat specific configurations. started");
        try
        {

            Optional<WebApplicationServerSettingEntity> serverSettingEntity = appSettinsRepository.findById(1);

            if (serverSettingEntity.isPresent())
            {
                factory.setPort(serverSettingEntity.get().getPort().getPORT());
                factory.setAddress(InetAddress.getByName(serverSettingEntity.get().getHost()));
            }
            factory.setServerHeader("Server header of tomcat");

// HTTPS Settings - Begin

            Optional<ApplicationHttpsSettingsEntity> applicationHttpsSettingsEntity = applicationHttpsSettingsEntityRepository.findById(1);

            if(applicationHttpsSettingsEntity.isPresent())
            {
                logger.info("Setting HTTPS settings....");
                if(applicationHttpsSettingsEntity.get().getUseHttps() !=0)
                {
                    factory.addAdditionalTomcatConnectors(createSslConnector());
                    factory.addContextCustomizers(context ->
                                                  {
                                                      logger.info("Setting HTTPS settings....setting...");
                                                      SecurityConstraint securityConstraint = new SecurityConstraint();
                                                      securityConstraint.setUserConstraint("CONFIDENTIAL");
                                                      SecurityCollection collection = new SecurityCollection();
                                                      collection.addPattern("/*");
                                                      securityConstraint.addCollection(collection);
                                                      context.addConstraint(securityConstraint);
                                                      logger.info("Setting HTTPS settings....setting...Done");
                                                  });
                }
                logger.info("Setting HTTPS settings....End");
            }
// HTTPS Settings - end
            logger.info("Tomcat Server Configuration Host=[" + factory.getAddress() + "] Port=[" + factory.getPort() + "]");
            logger.info("Setting the Tomcat specific configurations. ended");
        }
        catch (Exception e)
        {
            logger.error(e.getMessage());
            throw e;
        }
    }

// HTTPS Settings - Begin
    private Connector createSslConnector() {


        Optional<ApplicationHttpsSettingsEntity> applicationHttpsSettingsEntity = applicationHttpsSettingsEntityRepository.findById(1);

        if(applicationHttpsSettingsEntity.isPresent())
        {
            logger.info("Creating SSL Connector...");

            Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
            Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
            //            File keystore = new ClassPathResource("website_name.jks").getFile();
//            File truststore = new ClassPathResource("keystore").getFile();
            connector.setScheme("https");
            connector.setSecure(applicationHttpsSettingsEntity.get().getUseHttps() != 0);
            connector.setPort(applicationHttpsSettingsEntity.get().getBroadcaster().getPORT());
            protocol.setSSLEnabled(applicationHttpsSettingsEntity.get().getUseHttps() != 0);
//            protocol.setKeystoreFile("file:///c://trash//website_name_here.jks");
            protocol.setKeystoreFile(applicationHttpsSettingsEntity.get().getKeyStore());
//            protocol.setKeystorePass("pwd_here");
            protocol.setKeystorePass(applicationHttpsSettingsEntity.get().getKeyStorePassword());
//            protocol.setTruststoreFile(truststore.getAbsolutePath());
//            protocol.setTruststorePass("changeit");
            protocol.setKeyAlias(applicationHttpsSettingsEntity.get().getKeyAlias());
            logger.info("Creating SSL Connector...Done");
            return connector;
        }

        return null;
    }
// HTTPS Settings - End
}

代码语言:javascript
代码运行次数:0
复制
@Configuration
//@Profile("production")
public class SecurityConfig
{
// HTTPS Settings - Begin
    @Bean
    public TomcatServletWebServerFactory httpsRedirectConfig()
    {
        return new TomcatServletWebServerFactory()
        {
            @Override
            protected void postProcessContext(Context context)
            {
                SecurityConstraint securityConstraint = new SecurityConstraint();
                securityConstraint.setUserConstraint("CONFIDENTIAL");
                SecurityCollection collection = new SecurityCollection();
                collection.addPattern("/*");
                securityConstraint.addCollection(collection);
                context.addConstraint(securityConstraint);
            }
        };
    }
// HTTPS Settings - End
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-04 09:41:43

设置像Tomcat这样的Java /TLS(包括HTTPS)服务器的正确过程之一是:

  1. openssl req -new -newkey ...来创建密钥和CSR,都是在PEM

  1. 将CSR发送给证书颁发机构--即CA (此处为GoDaddy),并提供您拥有或控制指定域的证明,以及(取决于CA)付款,并获得服务器(叶)证书和一个或多个链证书(通常标记为中间证书),可能/可能是根证书,所有这些都在GoDaddy中;如果没有,则必须在继续

之前转换成。

  1. (您缺少的步骤) openssl pkcs12 -export -in cert1PEM -inkey keyPEM [-certfile cert2PEM] [-friendlyname somename] -out p12file

cert1PEM必须至少包含服务器证书,并且可以包含另一个证书(链/中间和(可选的根)证书);如果它不包含服务器证书,那么这些证书必须在-certfile cert2PEM中。-friendlyname somename是可选的,但是您显示的来自keytool的输出意味着它被使用了(,包括keytool显示它为别名)。

  1. keytool -importkeystore -srckeystore p12file -destkeystore jksfile ...

但是我不相信你说‘Java17是活动的’,除非.jks文件已经存在,而它不应该存在。Java9up(包括17 )默认以PKCS12 (而不是JKS )的形式创建新的密钥存储库文件,不会产生警告。Java 8的最新更新将。(也就是说,j8的所有默认输出都会被更新到JKS,最近的更新会在这样做时发出警告。)

在任何情况下,步骤4都是过时和不必要的。从2015年的8u 60开始,所有版本的Java默认都可以读取PKCS12 (由步骤3生成),根本不需要JKS文件。即使是较早的版本(大约在2000年左右)也可以阅读PKCS12,只需稍微修改配置,我就会推荐这一点,因为JKS是“专有的”(正如现在的警告所述),而且还很弱(警告没有这样说)。

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

https://stackoverflow.com/questions/74317632

复制
相关文章
Vue 中,如何将函数作为 props 传递给组件
作者:Michael Thiessen 译者:前端小智 来源:medium 点赞再看,养成习惯本文 GitHub https://github.com/qq44924588... 上已经收录,更多往
前端小智@大迁世界
2020/05/18
8.2K0
React技巧之将函数作为props传递
原文链接:https://bobbyhadz.com/blog/react-typescript-pass-function-as-prop[1]
chuckQu
2022/08/19
9620
React技巧之将函数作为props传递
HTML中传递和引用JavaScript变量
http://ivantian2008.blog.51cto.com/622133/1127456
明哥的运维笔记
2019/01/30
5.6K0
Python 函数作为参数传递
#map()的功能是将函数对象依次作用于表的每一个元素,每次作用的结果储存于返回的表re中。 #map通过读入的函数(这里是lambda函数)来操作数据 def test_func_map():     re = map((lambda x: x+3), [1, 2, 3, 4])     print re def testA(a, b, **kargs):     print a+b     print "testA: %s" % kargs #函数作为参数传递 def test_func(func, a, b, **kargs):     func(a, b)     print "test_func: %s" % kargs #函数作为参数传递 def test_func_lambda(func, **kargs):     func()     print "test_func_lambda: %s" % kargs def test_func_getattr():     func = getattr(obj, "testA")     func(1, 2) class TestGetattr():     aa = "2a"     def get_attr(self):         print "test getattr()"     def print_text(self):         print "print text"     def print_string(self):         print "print string" #getattr(obj, "a")的作用和obj.a是一致的,但该方法还有其他的用处,最方便的就是用来实现工厂方法 #根据传入参数不同,调用不同的函数实现几种格式的输出 def output(print_type="text"):     tg = TestGetattr()     output_func = getattr(tg, "print_%s" % print_type)     output_func() if __name__ == "__main__":     #test_func(testA, 1, 2, aa="aa")     #test_func_lambda((lambda: testA(1, 2, bb="bb")), cc="cc")     #test_func_map()     #test_func_getattr()     #getattr方法,传入参数是对象和该对象的函数或者属性的名字,返回对象的函数或者属性实例     obj = TestGetattr()     func = getattr(obj, "get_attr") #getattr()获得对象的属性和方法     func()     print getattr(obj, "aa") #完成对象的反射     print obj.aa     #callable方法,如果传入的参数是可以调用的函数,则返回true,否则返回false。     print callable(getattr(obj, "aa"))     output("string")
py3study
2020/01/09
3K0
【Python】函数进阶 ③ ( 函数作为参数传递 )
之前介绍的函数 , 都是 接收具体的 变量 或 字面量 数据 作为参数 , 如 : 数字 / 布尔值 / 字典 / 列表 / 元组 等 ;
韩曙亮
2023/10/11
4550
【Python】函数进阶 ③ ( 函数作为参数传递 )
Go-函数作为参数传递
编码过程中业务需要将一个函数,作为参数传递到函数内部。Go 语言的匿名函数是一个闭包(Closure)
王小明_HIT
2023/03/01
1.7K0
Go-函数作为参数传递
React技巧之将CSS作为props传递
原文链接:https://bobbyhadz.com/blog/react-pass-style-as-props-typescript[1]
chuckQu
2022/08/19
2.5K0
React技巧之将CSS作为props传递
thymeleaf 传递数据到js变量
thymeleaf 传递数据到js变量 如何把控制器传来的model中的值传递给js变量呢? 需要以下两个: <script th:inline="javascript"> var message =
Dream城堡
2018/09/10
5.1K0
python中函数嵌套、函数作为变量以及闭包的原理
python允许创建嵌套函数。也就是说我们可以在函数里面定义函数,而且现有的作用域和变量生存周期依旧不变。
狼啸风云
2021/03/04
5.3K0
python中函数嵌套、函数作为变量以及闭包的原理
JS处理函数将对象作为参数传递
做项目的时候遇到一个不是很常见的问题,就是js函数传递参数的时候,我们一般是传递一个数字或者是一个字符串,但是当你的需求满足不了的时候,就需要将对象或者数组作为一个参数传递过去,这个时候怎么做呢,今天简单的说有一下:
何处锦绣不灰堆
2020/05/29
7.1K0
C++返回vector/将vector作为参数传递
在C++里很多时候我们会遇到函数想返回两个以上结果的情况,这时候可以用数组(vector)、类来作为容器返回,也可以声明一个全局变量的数组,将数值存放在数组里解决。
vincentbbli
2021/08/18
5.5K0
详解JavaScript中的变量提升/函数提升
先有鸡还是先有蛋:直觉上会认为 JavaScript 代码在执行时是由上到下一行一行执行的。但实际上这并不完全正确,有一种特殊情况会导致这个假设是错误的。
用户10106350
2022/10/28
1.5K0
答网友问:golang中的slice作为函数参数时是值传递还是引用传递?
今天有网友问通道和切片在赋值给另一个变量或作为函数参数传递的时候是不是引用传递?因为老师在讲解的时候说是指针传递?
Go学堂
2023/08/29
7160
答网友问:golang中的slice作为函数参数时是值传递还是引用传递?
C语言指针变量作为函数参数
自学气象人
2023/06/20
1160
C语言指针变量作为函数参数
WordPress 技巧:千万不要在全局中把 $blog_id 作为变量名
所以在 WordPress MU 环境中,在进行一些操作的时候,比如需要切换博客进行设置数据,千万不要把 $blog_id 作为变量名。
Denis
2023/04/15
2540
javascript——函数、变量和方法
当代码出现有规律的重复之后,可以利用函数,定义变量,调用方法,不用去重复的改动代码,只需要进行函数的修改。基本上所有的高级语言都支持函数,javascript也不例外,它可以像变量一样被使用,方便且强大,因此本文对js函数进行系统的学习,并在学习过程中做了详细的笔记以及样例。
子舒
2022/06/09
1.2K0
javascript——函数、变量和方法
Swift 5.2 将实例作为函数调用
Swift 5.2中的一个新功能是可以将类型实例作为函数调用(callAsFunction)。或者,如Swift Evolution 提案所述,“用户定义的标称类型的可调用值”。此函数的简短描述是,它允许您调用实现了callAsFunction方法的任何类型的实例,就好像它是一个函数一样。
韦弦zhy
2020/03/19
2.4K0
golang-101-hacks(12)——切片作为函数参数传递
注:本文是对golang-101-hacks中文翻译。 在Go语言中,函数参数是值传递。使用slice作为函数参数时,函数获取到的是slice的副本:一个指针,指向底层数组的起始地址,同时带有slice的长度和容量。既然各位熟知数据存储的内存的地址,现在可以对切片数据进行修改。让我们看看下面的例子: In Go, the function parameters are passed by value. With respect to use slice as a function argument, that means the function will get the copies of the slice: a pointer which points to the starting address of the underlying array, accompanied by the length and capacity of the slice. Oh boy! Since you know the address of the memory which is used to store the data, you can tweak the slice now. Let's see the following example:
羊羽shine
2019/06/05
1.2K0
python中的id( )函数
>>> a=2.0 >>> b=2.0 >>> id(a) 524440880 >>> id(b) 524440904 >>> a=2 >>> b=2 >>> id(a) 524425104 >>> id(b)524425104为什么上面输出的值有些一样,有些不一样呢,求大神详细解释下。
用户7886150
2021/01/23
1K0
下篇1:将 ConfigMap 中的键值对作为容器的环境变量
继续接上篇,《一文了解K8S的ConfigMap》。上篇聊过,官方文档中提到的可以使用下面4种方式来使用 ConfigMap 配置 Pod 中的容器:
不背锅运维
2023/05/26
2.2K0
下篇1:将 ConfigMap 中的键值对作为容器的环境变量

相似问题

JQuery\Javascript -将函数作为变量传递

90

将jQuery ID作为参数传递给JavaScript函数

47

jquery noUiSlider将外部javascript变量传递到函数中。

12

将变量作为对javascript/jquery函数的引用传递

20

将字段id作为javascript函数的变量传递时出错

39
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档