From b785b30623a0465731520e5c015b525ef5c7065d Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 23 Nov 2018 14:44:57 -0700 Subject: [PATCH] v0.0.3: project scaffold --- bin/rsa-csr.js | 17 +++++++++++++++++ fixtures/example.com-www.csr.pem | 16 ++++++++++++++++ fixtures/privkey-rsa-2048.jwk.json | 11 +++++++++++ fixtures/privkey-rsa-2048.pkcs1.pem | 27 +++++++++++++++++++++++++++ index.js | 2 ++ lib/asn1.js | 0 lib/encoding.js | 0 lib/pem.js | 0 lib/rsa-csr.js | 5 +++++ lib/x509.js | 0 package.json | 2 +- test.sh | 25 +++++++++++++++++++++++++ 12 files changed, 104 insertions(+), 1 deletion(-) create mode 100755 bin/rsa-csr.js create mode 100644 fixtures/example.com-www.csr.pem create mode 100644 fixtures/privkey-rsa-2048.jwk.json create mode 100644 fixtures/privkey-rsa-2048.pkcs1.pem create mode 100644 index.js create mode 100644 lib/asn1.js create mode 100644 lib/encoding.js create mode 100644 lib/pem.js create mode 100644 lib/rsa-csr.js create mode 100644 lib/x509.js create mode 100755 test.sh diff --git a/bin/rsa-csr.js b/bin/rsa-csr.js new file mode 100755 index 0000000..e9cbdcb --- /dev/null +++ b/bin/rsa-csr.js @@ -0,0 +1,17 @@ +#!/usr/bin/env node +'use strict'; + +var fs = require('fs'); +var rsacsr = require('../index.js'); + +var keyname = process.argv[2]; +var domains = process.argv[3].split(/,/); + +var keypem = fs.readFileSync(keyname, 'ascii'); + +rsacsr({ key: keypem, domains: domains }).then(function (csr) { + // Using error so that we can redirect stdout to file + //console.error("CN=" + domains[0]); + //console.error("subjectAltName=" + domains.join(',')); + console.log(csr); +}); diff --git a/fixtures/example.com-www.csr.pem b/fixtures/example.com-www.csr.pem new file mode 100644 index 0000000..d876ff8 --- /dev/null +++ b/fixtures/example.com-www.csr.pem @@ -0,0 +1,16 @@ +-----BEGIN CERTIFICATE REQUEST----- +MIIClTCCAX0CAQAwFjEUMBIGA1UEAwwLZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3 +DQEBAQUAA4IBDwAwggEKAoIBAQCba21UHE+VbDTpmYYFZUOV+OQ8AngOCdjROsPC +0KiEfMvEaEM3NQl58u6QL7G7QsErKViiNPm9OTFo6HF5JijfWzK7haHFuRMEsgI4 +VwIYyhvqlJDfw/wt0AiVvSmoMfEQn1p1aiaO4V/RJSE3Vw/uz2bxiT22uSkSqOyS +hyfYE6dMHnuoBkzr4jvSifT+INmbv6Nyo4+AAMCZtYeHLrsFeSTjLL9jMPjI4ZkV +dlw2n3Xn9NbltF3/8Ao8dQfElqw+LIQWqU0oFHYNIP4ttfl5ObMKHaKSvBMyNruZ +R0El/ZsrcHLkAHRCLj07KRQJ81l5CUTPtQ02P1Eamz/nT4I3AgMBAAGgOjA4Bgkq +hkiG9w0BCQ4xKzApMCcGA1UdEQQgMB6CC2V4YW1wbGUuY29tgg93d3cuZXhhbXBs +ZS5jb20wDQYJKoZIhvcNAQELBQADggEBAGOFydCZPtRqnEidrB3vkpPp1GmQVqrl +XhqVM3X7UppsD3QDtJfgoSuBuVy3X/mPvy/Ly8WqEwJ7Ur+h76e7rgeFLvN5fQIr +frlpfCXrKaxxl6vxqKJ8s3Mn2LT8VmSVNig34NCtn99/SHNAlr3aU9L3b1+R25VI +FwFbOz/i92gOchT7Xat3fOiQ02k9GrHT33pIpUUkx5WbwJY6xDrCyFKG8ktpnee6 +WjpTOBnpgHUI1/5ydnf0v29L9N+ALIJGKQxhub3iqB6EhCl93iiQtf4e7M/lzX7l +c1xqsSwVZ3RQVY9bRP9NdGuW4hVvscy5ypqRtXPXQpxMnYwfi9qW5Uo= +-----END CERTIFICATE REQUEST----- diff --git a/fixtures/privkey-rsa-2048.jwk.json b/fixtures/privkey-rsa-2048.jwk.json new file mode 100644 index 0000000..f344c22 --- /dev/null +++ b/fixtures/privkey-rsa-2048.jwk.json @@ -0,0 +1,11 @@ +{ + "kty": "RSA", + "n": "m2ttVBxPlWw06ZmGBWVDlfjkPAJ4DgnY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-ALkfXyYLXeBSGxHbyiIYuodZg6LsfMNgUJ3r3Eyhc_nAVfYPEC_2IdAG4WYmq7iXYF9LQV09qEsKbFykm7QekE3hO7wswo5k-q2tp3ieBYdVGAXJoGOdv5VpaZ7B1QE", + "dq": "kh5dyDk7YCz7sUFbpsmuAeuPjoH2ghooh2u3xN7iUVmAg-ToKjwbVnG5-7eXiC779rQVwnrD_0yh1AFJ8wjRPqDIR7ObXGHikIxT1VSQWqiJm6AfZzDsL0LUD4YS3iPdhob7-NxLKWzqao_u4lhnDQaX9PKa12HFlny6K1daL48", + "qi": "AlHWbx1gp6Z9pbw_1hlS7HuXAgWoX7IjbTUelldf4gkriDWLOrj3QCZcO4ZvZvEwJhVlsny9LO8IkbwGJEL6cXraK08ByVS2mwQyflgTgGNnpzixyEUL_mrQLx6y145FHcxfeqNInMhep-0Mxn1D5nlhmIOgRApS0t9VoXtHhFU" +} diff --git a/fixtures/privkey-rsa-2048.pkcs1.pem b/fixtures/privkey-rsa-2048.pkcs1.pem new file mode 100644 index 0000000..246bd35 --- /dev/null +++ b/fixtures/privkey-rsa-2048.pkcs1.pem @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAm2ttVBxPlWw06ZmGBWVDlfjkPAJ4DgnY0TrDwtCohHzLxGhD +NzUJefLukC+xu0LBKylYojT5vTkxaOhxeSYo31syu4WhxbkTBLICOFcCGMob6pSQ +38P8LdAIlb0pqDHxEJ9adWomjuFf0SUhN1cP7s9m8Yk9trkpEqjskocn2BOnTB57 +qAZM6+I70on0/iDZm7+jcqOPgADAmbWHhy67BXkk4yy/YzD4yOGZFXZcNp915/TW +5bRd//AKPHUHxJasPiyEFqlNKBR2DSD+LbX5eTmzCh2ikrwTMja7mUdBJf2bK3By +5AB0Qi49OykUCfNZeQlEz7UNNj9RGps/50+CNwIDAQABAoIBAAqX6OzJvTbvGDAv +8a2eeFvZihz5Ahva2fdw7PTzafkV1IG/pY02xT2VrGMRj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dA +Jlw7hm9m8TAmFWWyfL0s7wiRvAYkQvpxetorTwHJVLabBDJ+WBOAY2enOLHIRQv+ +atAvHrLXjkUdzF96o0icyF6n7QzGfUPmeWGYg6BEClLS31Whe0eEVQ== +-----END RSA PRIVATE KEY----- diff --git a/index.js b/index.js new file mode 100644 index 0000000..d2e8011 --- /dev/null +++ b/index.js @@ -0,0 +1,2 @@ +'use strict'; +module.exports = require('./lib/rsa-csr.js'); diff --git a/lib/asn1.js b/lib/asn1.js new file mode 100644 index 0000000..e69de29 diff --git a/lib/encoding.js b/lib/encoding.js new file mode 100644 index 0000000..e69de29 diff --git a/lib/pem.js b/lib/pem.js new file mode 100644 index 0000000..e69de29 diff --git a/lib/rsa-csr.js b/lib/rsa-csr.js new file mode 100644 index 0000000..e83b7ef --- /dev/null +++ b/lib/rsa-csr.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = function rsacsr(opts) { + throw new Error("not implemented yet"); +}; diff --git a/lib/x509.js b/lib/x509.js new file mode 100644 index 0000000..e69de29 diff --git a/package.json b/package.json index 0be8cc7..3a41bb8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rsa-csr", - "version": "0.0.2", + "version": "0.0.3", "description": "", "main": "index.js", "scripts": { diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..d3fb11e --- /dev/null +++ b/test.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +gencsr() { + keyfile=$1 + domain=$2 + csrfile=$3 + openssl req -key $keyfile -new -nodes \ + -config <(printf "[req] +prompt = no +req_extensions = req_ext +distinguished_name = dn + +[ dn ] +CN = $domain + +[ req_ext ] +subjectAltName = @alt_names + +[ alt_names ] +DNS.1 = $domain +DNS.2 = www.$domain") \ + -out $csrfile +} + +gencsr fixtures/privkey-rsa-2048.pkcs1.pem example.com fixtures/example.com-www.csr.pem