@@ -14,6 +14,7 @@ const letsencryptStaging = process.env.NODE_ENV !== 'production';
1414const letsencryptConfig = '/etc/letsencrypt.ini' ;
1515const certbotCommand = 'certbot' ;
1616const archiver = require ( 'archiver' ) ;
17+ const path = require ( 'path' ) ;
1718
1819function omissions ( ) {
1920 return [ 'is_deleted' ] ;
@@ -350,22 +351,25 @@ const internalCertificate = {
350351 } )
351352 . then ( ( certificate ) => {
352353 if ( certificate . provider === 'letsencrypt' ) {
353- const zipDirectory = '/etc/letsencrypt/archive /npm-' + data . id ;
354+ const zipDirectory = '/etc/letsencrypt/live /npm-' + data . id ;
354355
355356 if ( ! fs . existsSync ( zipDirectory ) ) {
356357 throw new error . ItemNotFoundError ( 'Certificate ' + certificate . nice_name + ' does not exists' ) ;
357358 }
358359
360+ let certFiles = fs . readdirSync ( zipDirectory )
361+ . filter ( ( fn ) => fn . endsWith ( '.pem' ) )
362+ . map ( ( fn ) => fs . realpathSync ( path . join ( zipDirectory , fn ) ) ) ;
359363 const downloadName = 'npm-' + data . id + '-' + `${ Date . now ( ) } .zip` ;
360364 const opName = '/tmp/' + downloadName ;
361- internalCertificate . zipDirectory ( zipDirectory , opName )
365+ internalCertificate . zipFiles ( certFiles , opName )
362366 . then ( ( ) => {
363367 logger . debug ( 'zip completed : ' , opName ) ;
364368 const resp = {
365369 fileName : opName
366370 } ;
367371 resolve ( resp ) ;
368- } ) ;
372+ } ) . catch ( ( err ) => reject ( err ) ) ;
369373 } else {
370374 throw new error . ValidationError ( 'Only Let\'sEncrypt certificates can be downloaded' ) ;
371375 }
@@ -378,21 +382,26 @@ const internalCertificate = {
378382 * @param {String } out
379383 * @returns {Promise }
380384 */
381- zipDirectory ( source , out ) {
385+ zipFiles ( source , out ) {
382386 const archive = archiver ( 'zip' , { zlib : { level : 9 } } ) ;
383387 const stream = fs . createWriteStream ( out ) ;
384388
385389 return new Promise ( ( resolve , reject ) => {
390+ source
391+ . map ( ( fl ) => {
392+ let fileName = path . basename ( fl ) ;
393+ logger . debug ( fileName , ' added to certificate download zip' ) ;
394+ archive . file ( fl , { name : fileName } ) ;
395+ } ) ;
386396 archive
387- . directory ( source , false )
388397 . on ( 'error' , ( err ) => reject ( err ) )
389398 . pipe ( stream ) ;
390399
391400 stream . on ( 'close' , ( ) => resolve ( ) ) ;
392401 archive . finalize ( ) ;
393402 } ) ;
394403 } ,
395-
404+
396405 /**
397406 * @param {Access } access
398407 * @param {Object } data
0 commit comments