关于如何让openssl与Apache一起工作的问题

vdgimpew  于 2022-11-16  发布在  Apache
关注(0)|答案(1)|浏览(157)

所以我需要为我用Apache制作的一个网页创建一个自签名证书。我已经查阅并遵循了不同的指令集,但我遗漏了一些东西。我是一名学生,从未使用过ssl或apache。Apache已安装,localhost页面已经打开,显示了我编辑过的html文档的内容。OpenSSL已经安装。所以可能是我遗漏了什么。我一直收到这样的信息

C:\Program Files\OpenSSL-Win64\bin>openssl genrsa -des3 -out server.key 1024 genrsa: Can't 
open "server.key" for writing, Permission denied

C:\Program Files\OpenSSL-Win64\bin>openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout 
mysitename.key -out mysitename.crt
Generating a RSA private key
..........................+++++
...................................+++++
writing new private key to 'mysitename.key'
req: Can't open "mysitename.key" for writing, Permission denied

有什么建议吗?

t9eec4r0

t9eec4r01#

缺少私钥创建。
1Private key创建

openssl genrsa -out server.key 2048

结果

$ cat server.key
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAr2E2AUJ+TbptdBVMxYHmUzRpOflP69SX03NyuKh75XIO4tp6
...
Fhe+gzT7QD7Dg9SdP45eQWy5jtDYu4HIcy/ha0sikBi9+8pSs6qo
-----END RSA PRIVATE KEY-----

2用#1的专用密钥创建Certification Signing Request

openssl req -new -key server.key -out server.csr

常见需求localhost其他选项为默认选项或您的选项。

Common Name (e.g. server FQDN or YOUR name) []:localhost

结果

$ cat server.csr
-----BEGIN CERTIFICATE REQUEST-----
MIICijCCAXICAQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUx
...
sDS9gxYfks/7zxvtBzOWR3ZZzjlenpyqqu4aYZyb
-----END CERTIFICATE REQUEST-----

3Certification创建

openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

结果

$ cat server.crt
-----BEGIN CERTIFICATE-----
MIIDOTCCAiECFB0jWF04/GTmwfh8Ph1Zqeulb0IuMA0GCSqGSIb3DQEBCwUAMFkx
...
nrp0uU09oePMMMEn5g==
-----END CERTIFICATE-----

4local server代码由python编写(文件名为server.py)

from http.server import HTTPServer, BaseHTTPRequestHandler
import ssl

class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):

    def do_GET(self):
        self.send_response(200)
        self.end_headers()
        self.wfile.write(b'Hello, world!')

httpd = HTTPServer(('localhost', 4443), SimpleHTTPRequestHandler)

httpd.socket = ssl.wrap_socket (httpd.socket, 
        keyfile="./server.key", 
        certfile='./server.crt', server_side=True)

httpd.serve_forever()

5local server测试

python server.py

相关问题