Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

https-cert

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

https-cert - npm Package Compare versions

Comparing version 1.1.2 to 1.2.0

.idea/vcs.xml

122

index.js

@@ -1,10 +0,16 @@

var fs = require('fs')
var forge = require('node-forge')
var rsa = forge.pki.rsa
const PATH = require("path");
const FS = require("fs");
const forge = require("node-forge");
var CACERTPATH = __dirname + '/rootCA.crt';
const KEYPAIR = forge.pki.rsa.generateKeyPair({bits: 1024, e: 0x10001});
var CACERT = fs.readFileSync(CACERTPATH, 'utf8')
var CAKEY = fs.readFileSync(__dirname + '/rootCA.key', 'utf8')
const CACERTPATH = PATH.join(__dirname, "ca/rootCA.crt");
const CAKEYPATH = PATH.join(__dirname, "ca/rootCA.key");
const CACERT = FS.readFileSync(CACERTPATH, "utf8");
const CAKEY = FS.readFileSync(CAKEYPATH, "utf8");
const CACERTOBJ = forge.pki.certificateFromPem(CACERT);
const CAKEYOBJ = forge.pki.privateKeyFromPem(CAKEY);
module.exports = {

@@ -14,55 +20,62 @@ root: CACERT,

sign: function (domain, cb) {
var subject = [{
name: 'commonName',
value: domain
}, {
name: 'countryName',
value: 'CN'
}, {
shortName: 'ST',
value: 'ZJ'
}, {
name: 'localityName',
value: 'HZ'
}, {
name: 'organizationName',
value: 'Alibaba'
}, {
shortName: 'OU',
value: 'FE'
}]
let subject = [
{
name: "commonName",
value: domain
},
{
name: "countryName",
value: "CN"
},
{
shortName: "ST",
value: "ZJ"
},
{
name: "localityName",
value: "HZ"
},
{
name: "organizationName",
value: "Alibaba"
},
{
shortName: "OU",
value: "FE"
}
];
//make csr
var keypair = rsa.generateKeyPair({bits: 1024, e: 0x10001})
var csr = forge.pki.createCertificationRequest()
csr.publicKey = keypair.publicKey
csr.setSubject(subject)
csr.sign(keypair.privateKey, forge.md.sha256.create())
// 生成证书签发请求
let csr = forge.pki.createCertificationRequest();
var output_key = forge.pki.privateKeyToPem(keypair.privateKey)
csr.publicKey = KEYPAIR.publicKey;
csr.setSubject(subject);
csr.sign(KEYPAIR.privateKey, forge.md.sha256.create());
// Read CA cert and key
var caCert = forge.pki.certificateFromPem(CACERT)
var caKey = forge.pki.privateKeyFromPem(CAKEY)
var cert = forge.pki.createCertificate()
// 签发证书
let cert = forge.pki.createCertificate();
cert.serialNumber = 'C41C8AA3025C0808'
let md5 = forge.md.md5.create();
md5.update(domain);
cert.serialNumber = md5.digest().toHex();
var notBefore = new Date()
notBefore.setFullYear(notBefore.getFullYear() - 1)
cert.validity.notBefore = notBefore
let notBefore = new Date();
notBefore.setFullYear(notBefore.getFullYear() - 1);
cert.validity.notBefore = notBefore;
var notAfter = new Date()
notAfter.setFullYear(notAfter.getFullYear() + 1)
cert.validity.notAfter = notAfter
let notAfter = new Date();
notAfter.setFullYear(notAfter.getFullYear() + 1);
cert.validity.notAfter = notAfter;
// subject from CSR
cert.setSubject(csr.subject.attributes)
cert.setSubject(csr.subject.attributes);
cert.setIssuer(CACERTOBJ.subject.attributes);
// Chrome 58后需要证书中包含subjectAltName(SAN)等信息
cert.setExtensions([
{
name: 'basicConstraints',
name: "basicConstraints",
cA: true
},
{
name: 'subjectAltName',
name: "subjectAltName",
altNames: [

@@ -75,14 +88,9 @@ {

}
])
// issuer from CA
cert.setIssuer(caCert.subject.attributes)
]);
cert.publicKey = csr.publicKey
cert.publicKey = csr.publicKey;
cert.sign(CAKEYOBJ, forge.md.sha256.create());
cert.sign(caKey, forge.md.sha256.create())
var output_cert = forge.pki.certificateToPem(cert)
cb(null, output_key, output_cert)
cb(null, forge.pki.privateKeyToPem(KEYPAIR.privateKey), forge.pki.certificateToPem(cert));
}
}
};
{
"name": "https-cert",
"version": "1.1.2",
"version": "1.2.0",
"description": "https-cert",

@@ -9,2 +9,6 @@ "main": "index.js",

},
"repository": {
"type": "git",
"url": "git@gitlab.alibaba-inc.com:liming.mlm/https-cert.git"
},
"author": "limingv5",

@@ -11,0 +15,0 @@ "license": "ISC",

# https-cert
```js
var httpsCert = require("https-cert");
const httpsCert = require("https-cert");
// 根证书,下载注入电脑或手机中
httpsCert.root
httpsCert.path
httpsCert.root(证书内容)
httpsCert.path(证书路径)

@@ -10,0 +10,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc