Compare commits

..

2 次程式碼提交

作者 SHA1 備註 提交日期
bbb7fc99ec cleaner output 2018-11-23 14:24:40 -07:00
9aa463d3d2 move use of node Buffer to encoding.js 2018-11-23 14:24:21 -07:00
共有 2 個文件被更改,包括 28 次插入19 次删除

查看文件

@ -136,7 +136,7 @@ ASN1._stringify = function(asn1) {
var ws = ''; var ws = '';
function write(asn1) { function write(asn1) {
console.log(ws, 'ch', Buffer.from([asn1.type]).toString('hex'), asn1.length); console.log(ws, 'ch', Enc.numToHex(asn1.type), asn1.length);
if (!asn1.children) { if (!asn1.children) {
return; return;
} }
@ -176,7 +176,7 @@ ASN1.tpl = function (asn1) {
if (!asn1.children) { if (!asn1.children) {
if (0x05 !== asn1.type) { if (0x05 !== asn1.type) {
if (0x06 !== asn1.type) { if (0x06 !== asn1.type) {
val = Buffer.from(asn1.value || ''); val = asn1.value || new Uint8Array(0);
vars.push("// 0x" + Enc.numToHex(val.byteLength) + " (" + val.byteLength + " bytes)\nopts.tpl" + i + " = '" vars.push("// 0x" + Enc.numToHex(val.byteLength) + " (" + val.byteLength + " bytes)\nopts.tpl" + i + " = '"
+ Enc.bufToHex(val) + "';"); + Enc.bufToHex(val) + "';");
if (0x02 !== asn1.type && 0x03 !== asn1.type) { if (0x02 !== asn1.type && 0x03 !== asn1.type) {

43
test.sh
查看文件

@ -1,13 +1,14 @@
#!/bin/bash #!/bin/bash
# cause errors to hard-fail
# (and diff non-0 exit status will cause failure)
set -e set -e
pemtojwk() { pemtojwk() {
keyid=$1 keyid=$1
if [ -z "$keyid" ]; then if [ -z "$keyid" ]; then
echo ""
echo "" echo ""
echo "Testing PEM-to-JWK PKCS#1" echo "Testing PEM-to-JWK PKCS#1"
echo ""
fi fi
# #
node bin/rasha.js ./fixtures/privkey-rsa-2048.pkcs1.${keyid}pem \ node bin/rasha.js ./fixtures/privkey-rsa-2048.pkcs1.${keyid}pem \
@ -17,13 +18,14 @@ pemtojwk() {
node bin/rasha.js ./fixtures/pub-rsa-2048.pkcs1.${keyid}pem \ node bin/rasha.js ./fixtures/pub-rsa-2048.pkcs1.${keyid}pem \
> ./fixtures/pub-rsa-2048.jwk.1.json > ./fixtures/pub-rsa-2048.jwk.1.json
diff ./fixtures/pub-rsa-2048.jwk.${keyid}json ./fixtures/pub-rsa-2048.jwk.1.json diff ./fixtures/pub-rsa-2048.jwk.${keyid}json ./fixtures/pub-rsa-2048.jwk.1.json
if [ -z "$keyid" ]; then
echo "Pass"
fi
if [ -z "$keyid" ]; then if [ -z "$keyid" ]; then
echo ""
echo "" echo ""
echo "Testing PEM-to-JWK PKCS#8" echo "Testing PEM-to-JWK PKCS#8"
echo ""
fi fi
# #
node bin/rasha.js ./fixtures/privkey-rsa-2048.pkcs8.${keyid}pem \ node bin/rasha.js ./fixtures/privkey-rsa-2048.pkcs8.${keyid}pem \
@ -33,15 +35,16 @@ pemtojwk() {
node bin/rasha.js ./fixtures/pub-rsa-2048.spki.${keyid}pem \ node bin/rasha.js ./fixtures/pub-rsa-2048.spki.${keyid}pem \
> ./fixtures/pub-rsa-2048.jwk.1.json > ./fixtures/pub-rsa-2048.jwk.1.json
diff ./fixtures/pub-rsa-2048.jwk.${keyid}json ./fixtures/pub-rsa-2048.jwk.1.json diff ./fixtures/pub-rsa-2048.jwk.${keyid}json ./fixtures/pub-rsa-2048.jwk.1.json
if [ -z "$keyid" ]; then
echo "Pass"
fi
} }
jwktopem() { jwktopem() {
keyid=$1 keyid=$1
if [ -z "$keyid" ]; then if [ -z "$keyid" ]; then
echo ""
echo "" echo ""
echo "Testing JWK-to-PEM PKCS#1" echo "Testing JWK-to-PEM PKCS#1"
echo ""
fi fi
# #
node bin/rasha.js ./fixtures/privkey-rsa-2048.jwk.${keyid}json pkcs1 \ node bin/rasha.js ./fixtures/privkey-rsa-2048.jwk.${keyid}json pkcs1 \
@ -51,13 +54,13 @@ jwktopem() {
node bin/rasha.js ./fixtures/pub-rsa-2048.jwk.${keyid}json pkcs1 \ node bin/rasha.js ./fixtures/pub-rsa-2048.jwk.${keyid}json pkcs1 \
> ./fixtures/pub-rsa-2048.pkcs1.1.pem > ./fixtures/pub-rsa-2048.pkcs1.1.pem
diff ./fixtures/pub-rsa-2048.pkcs1.${keyid}pem ./fixtures/pub-rsa-2048.pkcs1.1.pem diff ./fixtures/pub-rsa-2048.pkcs1.${keyid}pem ./fixtures/pub-rsa-2048.pkcs1.1.pem
if [ -z "$keyid" ]; then
echo "Pass"
fi
if [ -z "$keyid" ]; then if [ -z "$keyid" ]; then
echo ""
echo "" echo ""
echo "Testing JWK-to-PEM PKCS#8" echo "Testing JWK-to-PEM PKCS#8"
echo ""
fi fi
# #
node bin/rasha.js ./fixtures/privkey-rsa-2048.jwk.${keyid}json pkcs8 \ node bin/rasha.js ./fixtures/privkey-rsa-2048.jwk.${keyid}json pkcs8 \
@ -67,13 +70,13 @@ jwktopem() {
node bin/rasha.js ./fixtures/pub-rsa-2048.jwk.${keyid}json spki \ node bin/rasha.js ./fixtures/pub-rsa-2048.jwk.${keyid}json spki \
> ./fixtures/pub-rsa-2048.spki.1.pem > ./fixtures/pub-rsa-2048.spki.1.pem
diff ./fixtures/pub-rsa-2048.spki.${keyid}pem ./fixtures/pub-rsa-2048.spki.1.pem diff ./fixtures/pub-rsa-2048.spki.${keyid}pem ./fixtures/pub-rsa-2048.spki.1.pem
if [ -z "$keyid" ]; then
echo "Pass"
fi
if [ -z "$keyid" ]; then if [ -z "$keyid" ]; then
echo ""
echo "" echo ""
echo "Testing JWK-to-SSH" echo "Testing JWK-to-SSH"
echo ""
fi fi
# #
node bin/rasha.js ./fixtures/privkey-rsa-2048.jwk.${keyid}json ssh > ./fixtures/pub-rsa-2048.ssh.1.pub node bin/rasha.js ./fixtures/privkey-rsa-2048.jwk.${keyid}json ssh > ./fixtures/pub-rsa-2048.ssh.1.pub
@ -81,6 +84,9 @@ jwktopem() {
# #
node bin/rasha.js ./fixtures/pub-rsa-2048.jwk.${keyid}json ssh > ./fixtures/pub-rsa-2048.ssh.1.pub node bin/rasha.js ./fixtures/pub-rsa-2048.jwk.${keyid}json ssh > ./fixtures/pub-rsa-2048.ssh.1.pub
diff ./fixtures/pub-rsa-2048.ssh.${keyid}pub ./fixtures/pub-rsa-2048.ssh.1.pub diff ./fixtures/pub-rsa-2048.ssh.${keyid}pub ./fixtures/pub-rsa-2048.ssh.1.pub
if [ -z "$keyid" ]; then
echo "Pass"
fi
} }
rndkey() { rndkey() {
@ -117,7 +123,7 @@ jwktopem ""
echo "" echo ""
echo "" echo ""
echo "Testing different size random keys" echo "Re-running tests with random keys of varying sizes"
echo "" echo ""
rndkey 32 # minimum key size rndkey 32 # minimum key size
rndkey 64 rndkey 64
@ -127,11 +133,14 @@ rndkey 512
rndkey 768 rndkey 768
rndkey 1024 rndkey 1024
rndkey 2048 # first secure key size rndkey 2048 # first secure key size
rndkey 3072 #rndkey 3072
rndkey 4096 # largest reasonable key size #rndkey 4096 # largest reasonable key size
if [ -z "$keyid" ]; then
echo "Pass"
fi
echo "" echo ""
echo "Note:" echo "Note:"
echo "Keys larger than 4096 work as well, but they take minutes to generate, so we stop here." echo "Keys larger than 2048 have been tested and work, but are omitted from automated tests to save time."
rm fixtures/*.1.* rm fixtures/*.1.*
@ -141,4 +150,4 @@ echo ""
echo "PASSED:" echo "PASSED:"
echo "• All inputs produced valid outputs" echo "• All inputs produced valid outputs"
echo "• All outputs matched known-good values" echo "• All outputs matched known-good values"
echo "" echo "• All random tests passed reciprosity"