Compare commits

..

No commits in common. "bbb7fc99ec9b1958eba0a3b7d206acfaddefe21d" and "ec826aa906c1f32186372863880d1f6417c947da" have entirely different histories.

2 changed files with 19 additions and 28 deletions

View File

@ -136,7 +136,7 @@ ASN1._stringify = function(asn1) {
var ws = ''; var ws = '';
function write(asn1) { function write(asn1) {
console.log(ws, 'ch', Enc.numToHex(asn1.type), asn1.length); console.log(ws, 'ch', Buffer.from([asn1.type]).toString('hex'), 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 = asn1.value || new Uint8Array(0); val = Buffer.from(asn1.value || '');
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
View File

@ -1,14 +1,13 @@
#!/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 \
@ -18,14 +17,13 @@ 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 \
@ -35,16 +33,15 @@ 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 \
@ -54,13 +51,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 \
@ -70,13 +67,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
@ -84,9 +81,6 @@ 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() {
@ -123,7 +117,7 @@ jwktopem ""
echo "" echo ""
echo "" echo ""
echo "Re-running tests with random keys of varying sizes" echo "Testing different size random keys"
echo "" echo ""
rndkey 32 # minimum key size rndkey 32 # minimum key size
rndkey 64 rndkey 64
@ -133,14 +127,11 @@ 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 2048 have been tested and work, but are omitted from automated tests to save time." echo "Keys larger than 4096 work as well, but they take minutes to generate, so we stop here."
rm fixtures/*.1.* rm fixtures/*.1.*
@ -150,4 +141,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 "• All random tests passed reciprosity" echo ""