@@ -6,6 +6,14 @@ module.exports.createCertificate = createCertificate;
6
6
module . exports . readCertificateInfo = readCertificateInfo ;
7
7
module . exports . getPublicKey = getPublicKey ;
8
8
9
+ // PUBLIC API
10
+
11
+ /**
12
+ * Creates a private key
13
+ *
14
+ * @param {Number } [keyBitsize=1024] Size of the key, defaults to 1024bit
15
+ * @param {Function } callback Callback function with an error object and {key}
16
+ */
9
17
function createPrivateKey ( keyBitsize , callback ) {
10
18
if ( ! callback && typeof keyBitsize == "function" ) {
11
19
callback = keyBitsize ;
@@ -28,6 +36,25 @@ function createPrivateKey(keyBitsize, callback){
28
36
} ) ;
29
37
}
30
38
39
+ /**
40
+ * Creates a Certificate Signing Request
41
+ *
42
+ * If client key is undefined, a new key is created automatically. The used key is included
43
+ * in the callback return as clientKey
44
+ *
45
+ * @param {Object } [options] Optional options object
46
+ * @param {String } [options.clientKey] Optional client key to use
47
+ * @param {Number } [options.keyBitsize] If clientKey is undefined, bit size to use for generating a new key (defaults to 1024)
48
+ * @param {String } [options.hash] Hash function to use (either md5 or sha1, defaults to sha1)
49
+ * @param {String } [options.country] CSR country field
50
+ * @param {String } [options.state] CSR state field
51
+ * @param {String } [options.locality] CSR locality field
52
+ * @param {String } [options.organization] CSR organization field
53
+ * @param {String } [options.organizationUnit] CSR organizational unit field
54
+ * @param {String } [options.commonName="localhost"] CSR common name field
55
+ * @param {String } [options.emailAddress] CSR email address field
56
+ * @param {Function } callback Callback function with an error object and {csr, clientKey}
57
+ */
31
58
function createCSR ( options , callback ) {
32
59
if ( ! callback && typeof options == "function" ) {
33
60
callback = options ;
@@ -69,6 +96,18 @@ function createCSR(options, callback){
69
96
} ) ;
70
97
}
71
98
99
+ /**
100
+ * Creates a certificate based on a CSR. If CSR is not defined, a new one
101
+ * will be generated automatically. For CSR generation all the options values
102
+ * can be used as with createCSR.
103
+ *
104
+ * @param {Object } [options] Optional options object
105
+ * @param {String } [options.serviceKey] Private key for signing the certificate, if not defined a new one is generated
106
+ * @param {Boolean } [options.selfSigned] If set to true and serviceKey is not defined, use clientKey for signing
107
+ * @param {String } [options.csr] CSR for the certificate, if not defined a new one is generated
108
+ * @param {Number } [options.days] Certificate expire time in days
109
+ * @param {Function } callback Callback function with an error object and {certificate, csr, clientKey, serviceKey}
110
+ */
72
111
function createCertificate ( options , callback ) {
73
112
if ( ! callback && typeof options == "function" ) {
74
113
callback = options ;
@@ -129,6 +168,12 @@ function createCertificate(options, callback){
129
168
} ) ;
130
169
}
131
170
171
+ /**
172
+ * Exports a public key from a private key, CSR or certificate
173
+ *
174
+ * @param {String } certificate PEM encoded private key, CSR or certificate
175
+ * @param {Function } callback Callback function with an error object and {publicKey}
176
+ */
132
177
function getPublicKey ( certificate , callback ) {
133
178
if ( ! callback && typeof certificate == "function" ) {
134
179
callback = certificate ;
@@ -166,6 +211,12 @@ function getPublicKey(certificate, callback){
166
211
} ) ;
167
212
}
168
213
214
+ /**
215
+ * Reads subject data from a certificate or a CSR
216
+ *
217
+ * @param {String } certificate PEM encoded CSR or certificate
218
+ * @param {Function } callback Callback function with an error object and {country, state, locality, organization, organizationUnit, commonName, emailAddress}
219
+ */
169
220
function readCertificateInfo ( certificate , callback ) {
170
221
if ( ! callback && typeof certificate == "function" ) {
171
222
callback = certificate ;
@@ -208,6 +259,8 @@ function readCertificateInfo(certificate, callback){
208
259
} ) ;
209
260
}
210
261
262
+ // HELPER FUNCTIONS
263
+
211
264
function fetchCertificateData ( certData , callback ) {
212
265
certData = ( certData || "" ) . toString ( ) ;
213
266
@@ -268,6 +321,9 @@ function generateCSRSubject(options){
268
321
return csrBuilder . join ( "" ) ;
269
322
}
270
323
324
+ /**
325
+ * Spawn an openssl command
326
+ */
271
327
function execOpenSSL ( params , searchStr , stdin , callback ) {
272
328
var openssl = spawn ( "openssl" , params ) ,
273
329
stdout = "" ,
0 commit comments