@@ -32,6 +32,7 @@ var util = require('util');
32
32
var cons = require ( 'consolidate' ) ;
33
33
var params = require ( 'express-params' ) ;
34
34
var querystring = require ( 'querystring' ) ;
35
+ var path = require ( 'path' ) ;
35
36
36
37
var loadApp = function ( loadpath ) {
37
38
@@ -136,11 +137,13 @@ var startSSLRedirect = function() {
136
137
137
138
var startSSL = function ( ) {
138
139
140
+ privateKeyFile = path . normalize ( 'certs/server.key' ) ;
141
+ certificateFile = path . normalize ( 'certs/server.cert' ) ;
139
142
var privateKey = "" ;
140
143
var certificate = "" ;
141
144
try {
142
- privateKey = fs . readFileSync ( 'certs/server.key' ) . toString ( ) ;
143
- certificate = fs . readFileSync ( 'certs/server.cert' ) . toString ( ) ;
145
+ privateKey = fs . readFileSync ( privateKeyFile ) . toString ( ) ;
146
+ certificate = fs . readFileSync ( certificateFile ) . toString ( ) ;
144
147
} catch ( e ) {
145
148
util . print ( "no certificate found. generating self signed cert.\n" ) ;
146
149
}
@@ -150,30 +153,30 @@ var startSSL = function() {
150
153
} else {
151
154
var spawn = require ( 'child_process' ) . spawn ;
152
155
153
- var genSelfSignedCert = function ( ) {
156
+ var genSelfSignedCert = function ( keyFile , certFile ) {
154
157
var genkey = spawn ( 'openssl' , [
155
158
'req' , '-x509' , '-nodes' ,
156
159
'-days' , '365' ,
157
160
'-newkey' , 'rsa:2048' ,
158
- '-keyout' , 'certs/server.key' ,
159
- '-out' , 'certs/server.cert' ,
161
+ '-keyout' , keyFile ,
162
+ '-out' , certFile ,
160
163
'-subj' ,
161
164
'/C=' + config . country + '/ST=' + config . state + "/L=" + config . locale + "/CN=" + config . commonName + "/subjectAltName=" + config . subjectAltName
162
165
] ) ;
163
166
genkey . stdout . on ( 'data' , function ( d ) { util . print ( d ) } ) ;
164
167
genkey . stderr . on ( 'data' , function ( d ) { util . print ( d ) } ) ;
165
168
genkey . addListener ( 'exit' , function ( code , signal ) {
166
- fs . chmodSync ( 'certs/server.key' , '600' ) ;
169
+ fs . chmodSync ( privateKeyFile , '600' ) ;
167
170
loadServer ( ) ;
168
171
} ) ;
169
172
} ;
170
173
var loadServer = function ( ) {
171
- privateKey = fs . readFileSync ( 'certs/server.key' ) . toString ( ) ;
172
- certificate = fs . readFileSync ( 'certs/server.cert' ) . toString ( ) ;
174
+ privateKey = fs . readFileSync ( privateKeyFile ) . toString ( ) ;
175
+ certificate = fs . readFileSync ( certificateFile ) . toString ( ) ;
173
176
https . createServer ( { key : privateKey , cert : certificate } , sslapp ) . listen ( config . listenPort , config . listenIP ) ;
174
177
} ;
175
178
176
- genSelfSignedCert ( ) ;
179
+ genSelfSignedCert ( privateKeyFile , certificateFile ) ;
177
180
}
178
181
} ;
179
182
0 commit comments