1
|
// from https://github.com/indutny/self-signed/blob/gh-pages/lib/asn1.js
|
2
|
// Fedor, you are amazing.
|
3
|
'use strict'
|
4
|
|
5
|
var asn1 = require('asn1.js')
|
6
|
|
7
|
exports.certificate = require('./certificate')
|
8
|
|
9
|
var RSAPrivateKey = asn1.define('RSAPrivateKey', function () {
|
10
|
this.seq().obj(
|
11
|
this.key('version').int(),
|
12
|
this.key('modulus').int(),
|
13
|
this.key('publicExponent').int(),
|
14
|
this.key('privateExponent').int(),
|
15
|
this.key('prime1').int(),
|
16
|
this.key('prime2').int(),
|
17
|
this.key('exponent1').int(),
|
18
|
this.key('exponent2').int(),
|
19
|
this.key('coefficient').int()
|
20
|
)
|
21
|
})
|
22
|
exports.RSAPrivateKey = RSAPrivateKey
|
23
|
|
24
|
var RSAPublicKey = asn1.define('RSAPublicKey', function () {
|
25
|
this.seq().obj(
|
26
|
this.key('modulus').int(),
|
27
|
this.key('publicExponent').int()
|
28
|
)
|
29
|
})
|
30
|
exports.RSAPublicKey = RSAPublicKey
|
31
|
|
32
|
var PublicKey = asn1.define('SubjectPublicKeyInfo', function () {
|
33
|
this.seq().obj(
|
34
|
this.key('algorithm').use(AlgorithmIdentifier),
|
35
|
this.key('subjectPublicKey').bitstr()
|
36
|
)
|
37
|
})
|
38
|
exports.PublicKey = PublicKey
|
39
|
|
40
|
var AlgorithmIdentifier = asn1.define('AlgorithmIdentifier', function () {
|
41
|
this.seq().obj(
|
42
|
this.key('algorithm').objid(),
|
43
|
this.key('none').null_().optional(),
|
44
|
this.key('curve').objid().optional(),
|
45
|
this.key('params').seq().obj(
|
46
|
this.key('p').int(),
|
47
|
this.key('q').int(),
|
48
|
this.key('g').int()
|
49
|
).optional()
|
50
|
)
|
51
|
})
|
52
|
|
53
|
var PrivateKeyInfo = asn1.define('PrivateKeyInfo', function () {
|
54
|
this.seq().obj(
|
55
|
this.key('version').int(),
|
56
|
this.key('algorithm').use(AlgorithmIdentifier),
|
57
|
this.key('subjectPrivateKey').octstr()
|
58
|
)
|
59
|
})
|
60
|
exports.PrivateKey = PrivateKeyInfo
|
61
|
var EncryptedPrivateKeyInfo = asn1.define('EncryptedPrivateKeyInfo', function () {
|
62
|
this.seq().obj(
|
63
|
this.key('algorithm').seq().obj(
|
64
|
this.key('id').objid(),
|
65
|
this.key('decrypt').seq().obj(
|
66
|
this.key('kde').seq().obj(
|
67
|
this.key('id').objid(),
|
68
|
this.key('kdeparams').seq().obj(
|
69
|
this.key('salt').octstr(),
|
70
|
this.key('iters').int()
|
71
|
)
|
72
|
),
|
73
|
this.key('cipher').seq().obj(
|
74
|
this.key('algo').objid(),
|
75
|
this.key('iv').octstr()
|
76
|
)
|
77
|
)
|
78
|
),
|
79
|
this.key('subjectPrivateKey').octstr()
|
80
|
)
|
81
|
})
|
82
|
|
83
|
exports.EncryptedPrivateKey = EncryptedPrivateKeyInfo
|
84
|
|
85
|
var DSAPrivateKey = asn1.define('DSAPrivateKey', function () {
|
86
|
this.seq().obj(
|
87
|
this.key('version').int(),
|
88
|
this.key('p').int(),
|
89
|
this.key('q').int(),
|
90
|
this.key('g').int(),
|
91
|
this.key('pub_key').int(),
|
92
|
this.key('priv_key').int()
|
93
|
)
|
94
|
})
|
95
|
exports.DSAPrivateKey = DSAPrivateKey
|
96
|
|
97
|
exports.DSAparam = asn1.define('DSAparam', function () {
|
98
|
this.int()
|
99
|
})
|
100
|
|
101
|
var ECPrivateKey = asn1.define('ECPrivateKey', function () {
|
102
|
this.seq().obj(
|
103
|
this.key('version').int(),
|
104
|
this.key('privateKey').octstr(),
|
105
|
this.key('parameters').optional().explicit(0).use(ECParameters),
|
106
|
this.key('publicKey').optional().explicit(1).bitstr()
|
107
|
)
|
108
|
})
|
109
|
exports.ECPrivateKey = ECPrivateKey
|
110
|
|
111
|
var ECParameters = asn1.define('ECParameters', function () {
|
112
|
this.choice({
|
113
|
namedCurve: this.objid()
|
114
|
})
|
115
|
})
|
116
|
|
117
|
exports.signature = asn1.define('signature', function () {
|
118
|
this.seq().obj(
|
119
|
this.key('r').int(),
|
120
|
this.key('s').int()
|
121
|
)
|
122
|
})
|