HTTPS & SSL & localhost All In One
HTTPS & SSL & localhost All In One
https://github.com/xgqfrms/FEIQA/issues/43#issuecomment-421241295
https://github.com/FiloSottile/mkcert/issues/73
https://github.com/xgqfrms/FEIQA/issues/43
.pem
What are PEM files?
Privacy Enhanced Mail
(PEM) files are a type of Public Key Infrastructure (PKI) file used for keys and certificates. PEM, initially invented to make e-mail secure, is now an Internet security standard. HPE Service Manager uses OpenSSL libraries to encrypt and decrypt SOAP messages over HTTP and requires certificates and keys in PEM format. The typical PEM files are:
key.pem
contains the private encryption key
cert.pem
contains certificate information
Because it is a standard, any PKI implementation can use .pem
files as a repository for keys or certificates. OpenSSL supports a variety of standard formats in addition to .pem, including Distinguished Encoding Rules (DER) and X.509. OpenSSL has several utility functions that can convert these formats.
https://docs.microfocus.com/SM/9.52/Hybrid/Content/security/concepts/what_are_pem_files.htm
html to pdf
https://github.com/xgqfrms/url-to-pdf-api
https://github.com/alvarcarto/url-to-pdf-api/issues/81
url to pdf
.env
node
#!/usr/bin/env node
export NODE_ENV=development
export PORT=9000
export ALLOW_HTTP=true
# Warning: PDF rendering does not work in Chrome when it is in headed mode.
export DEBUG_MODE=false
echo "Environment variables set!"
bash
#!/bin/bash
export NODE_ENV=development
export PORT=9000
export ALLOW_HTTP=true
# Warning: PDF rendering does not work in Chrome when it is in headed mode.
export DEBUG_MODE=false
echo "Environment variables set!"
admin
$ E:\FastView\url-to-pdf-api\package.json
test
GET
http://localhost:9000/api/render
http://localhost:9000/api/render?url=https://developer.mozilla.org/en-US/docs/Web/CSS/calc#Examples
POST
// let url = `https://url-to-pdf-api.herokuapp.com/api/render`,
// let url = `https://localhost:9000/api/render`,
let url = `http://localhost:9000/api/render`,
obj = {
url: "https://developer.mozilla.org/en-US/docs/Web/CSS/calc",
output: "pdf",
// output: "screenshot",
ignoreHttpsErrors: true,
};
fetch(url,
{
method: "POST",
mode: "cors",
headers: {
"Content-Type": "application/json; charset=utf-8",
},
body: JSON.stringify(obj),
})
.then(res => res.blob())
.then(blob => {
// base64
let objectURL = URL.createObjectURL(blob);
let a = document.createElement(`a`);
a.href = objectURL;
console.log(`a =`, a);
// let title = document.querySelector(`title`).innerText;
let title = `test`;
// png
// a.setAttribute(`download`, `${title}.png`);
// pdf
a.setAttribute(`download`, `${title}.pdf`);
a.click();
})
.catch((err) => {
console.log(`There has been a problem with your fetch operation: `, err);
});
x = 'true';
!x;
// false
x = 'false';
!x;
// false
y = true;
!y;
// false
y = false;
!y;
// true
OpenSSL
# 1. 生成服务器端的私钥( root.key文件):
$ openssl genrsa -des3 -out root.key 1024
# 密码为:123456
# 2. 请求建立证书的申请文件 root.csr: (输入国家,省份,城市,公司信息,证书发送邮箱地址和证书密码:)
$ openssl req -new -key root.key -out root.csr
# 密码为:123456
# 3. 创立一个为期10年的根证书 root.crt
$ openssl x509 -req -days 3650 -sha1 -extensions v3_ca -signkey root.key -in root.csr -out root.crt
# 密码为:123456
# 4. 建立服务器证书秘钥:
$ openssl genrsa -des3 -out server.key 2048
# 密码为:123456
# 5. 创立服务器证书申请文件 (输入国家,省份,城市,公司信息,证书发送邮箱地址和证书密码:)
$ openssl req -new -key server.key -out server.csr
# 密码为: 123456
# 6. 创立一个为期 2年的服务器证书 server.crt
$ openssl x509 -req -days 730 -md5 -extensions v3_req -CA root.crt -CAkey root.key -CAcreateserial -in server.csr -out server.crt
# 密码为:123456
mkcert
pem
https://github.com/FiloSottile/mkcert
const https = require('https');
const express = require('express');
const fs = require('fs');
// const fs = require('fs');
// OpenSSL
// const privateKey = fs.readFileSync('./https-ssl/server.key');
// const certificate = fs.readFileSync('./https-ssl/server.crt');
// pem
const privateKey = fs.readFileSync('./ssl/webgeeker.xyz+3-key.pem');
const certificate = fs.readFileSync('./ssl/webgeeker.xyz+3.pem');
const credentials = {
key: privateKey,
cert: certificate,
};
const app = express();
// const app = express.createServer(credentials);
// https://localhost:8888
https.createServer(credentials, app).listen(8888);
app.get('/', function (req, res) {
// console.log('req =', req);
res.header('Content-type', 'text/html');
return res.end('<h1>Hello, HTTPS!</h1>');
});
demos
(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
refs
https://www.cnblogs.com/xgqfrms/p/13845919.html
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/9649577.html
未经授权禁止转载,违者必究!