index.js
3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
var test = require('tape')
var fs = require('fs')
var parseKey = require('../')
var rsa1024 = {
private: fs.readFileSync(__dirname + '/rsa.1024.priv'),
public: fs.readFileSync(__dirname + '/rsa.1024.pub')
}
var rsa2028 = {
private: fs.readFileSync(__dirname + '/rsa.2028.priv'),
public: fs.readFileSync(__dirname + '/rsa.2028.pub')
}
var nonrsa1024 = {
private: fs.readFileSync(__dirname + '/1024.priv'),
public: fs.readFileSync(__dirname + '/1024.pub')
}
var pass1024 = {
private: {
passphrase: 'fooo',
key: fs.readFileSync(__dirname + '/pass.1024.priv')
},
public: fs.readFileSync(__dirname + '/pass.1024.pub')
}
var ec = {
private: fs.readFileSync(__dirname + '/ec.priv'),
public: fs.readFileSync(__dirname + '/ec.pub')
}
var ecpass = {
private: {
key: fs.readFileSync(__dirname + '/ec.pass.priv'),
passphrase: 'bard'
},
public: fs.readFileSync(__dirname + '/ec.pub')
}
var dsa = {
private: fs.readFileSync(__dirname + '/dsa.1024.priv'),
public: fs.readFileSync(__dirname + '/dsa.1024.pub')
}
var dsa2 = {
private: fs.readFileSync(__dirname + '/dsa.2048.priv'),
public: fs.readFileSync(__dirname + '/dsa.2048.pub')
}
var dsapass = {
private: {
key: fs.readFileSync(__dirname + '/pass.dsa.1024.priv'),
passphrase: 'password'
},
public: fs.readFileSync(__dirname + '/pass.dsa.1024.pub')
}
var dsapass2 = {
private: {
key: fs.readFileSync(__dirname + '/pass2.dsa.1024.priv'),
passphrase: 'password'
},
public: fs.readFileSync(__dirname + '/pass2.dsa.1024.pub')
}
var rsapass = {
private: {
key: fs.readFileSync(__dirname + '/pass.rsa.1024.priv'),
passphrase: 'password'
},
public: fs.readFileSync(__dirname + '/pass.rsa.1024.pub')
}
var rsapass2 = {
private: {
key: fs.readFileSync(__dirname + '/pass.rsa.2028.priv'),
passphrase: 'password'
},
public: fs.readFileSync(__dirname + '/pass.rsa.2028.pub')
}
var cert = {
private: fs.readFileSync(__dirname + '/rsa.1024.priv'),
public: fs.readFileSync(__dirname + '/node.cert')
}
var i = 0
function testIt (keys) {
test('key ' + (++i), function (t) {
t.plan(2)
t.ok(parseKey(keys.public), 'public key')
t.ok(parseKey(keys.private), 'private key')
})
}
function testEOL (keys) {
var publicKey = keys.public.toString()
var newLineRegex = /\r?\n/g
var genPrivate = function (replace) {
if (keys.private.key) {
return { key: keys.private.key.toString().replace(newLineRegex, replace), passphrase: keys.private.passphrase }
} else {
return keys.private.toString().replace(newLineRegex, replace)
}
}
var testN = {
private: genPrivate('\n'),
public: publicKey.replace(newLineRegex, '\n')
}
testIt(testN)
var testR = {
private: genPrivate('\r'),
public: publicKey.replace(newLineRegex, '\r')
}
testIt(testR)
var testRN = {
private: genPrivate('\r\n'),
public: publicKey.replace(newLineRegex, '\r\n')
}
testIt(testRN)
}
testIt(dsa)
testIt(dsa2)
testIt(rsa1024)
testIt(ec)
testIt(rsa2028)
testIt(nonrsa1024)
testIt(ecpass)
testIt(dsapass)
testIt(dsapass2)
testIt(rsapass)
testIt(rsapass2)
testIt(pass1024)
testIt(pass1024)
testIt(cert)
testEOL(dsa)
testEOL(dsa2)
testEOL(rsa1024)
testEOL(ec)
testEOL(rsa2028)
testEOL(nonrsa1024)
testEOL(ecpass)
testEOL(dsapass)
testEOL(dsapass2)
testEOL(rsapass)
testEOL(rsapass2)
testEOL(pass1024)
testEOL(pass1024)
testEOL(cert)