@@ -303,6 +303,10 @@ IdentityProvider.prototype.get = function (req, res, next) {
303303 } )
304304}
305305
306+ function stripLineEndings ( obj ) {
307+ return obj . replace ( / ( \r \n | \n | \r ) / gm, '' ) ;
308+ }
309+
306310IdentityProvider . prototype . newCert = function ( req , res , next ) {
307311 var self = this
308312
@@ -313,6 +317,7 @@ IdentityProvider.prototype.newCert = function (req, res, next) {
313317 err . status = 500
314318 return next ( err )
315319 }
320+ var spkac = new Buffer ( stripLineEndings ( options . spkac ) , 'utf-8' )
316321
317322 debug ( 'Requesting new cert for ' + options . webid )
318323
@@ -327,7 +332,7 @@ IdentityProvider.prototype.newCert = function (req, res, next) {
327332
328333 // Get a new cert
329334 webid ( 'tls' ) . generate ( {
330- spkac : new Buffer ( options . spkac ) ,
335+ spkac : spkac ,
331336 agent : options . webid
332337 } , function ( err , cert ) {
333338 if ( err ) {
@@ -352,8 +357,10 @@ IdentityProvider.prototype.newCert = function (req, res, next) {
352357
353358 debug ( 'Sending new cert as response' )
354359 res . set ( 'Content-Type' , 'application/x-x509-user-cert' )
360+ res . set ( 'Accept-Ranges' , 'bytes' ) ;
355361 // Convert to DER
356362 var der = asn1 . toDer ( pki . certificateToAsn1 ( cert ) ) . getBytes ( )
363+ res . set ( 'Content-Length' , der . length ) ;
357364 res . send ( der )
358365 } )
359366 } )
@@ -411,13 +418,14 @@ IdentityProvider.prototype.post = function (req, res, next) {
411418 debug ( 'Create account with settings ' , options )
412419
413420 var agent = self . agent ( options )
414-
421+ var spkac = null
415422 var cert = null
416423 waterfall ( [
417424 function ( callback ) {
418425 if ( options . spkac && options . spkac . length > 0 ) {
426+ spkac = new Buffer ( stripLineEndings ( options . spkac ) , 'utf-8' )
419427 webid ( 'tls' ) . generate ( {
420- spkac : new Buffer ( options . spkac ) ,
428+ spkac : spkac ,
421429 agent : agent // TODO generate agent
422430 } , callback )
423431 } else {
0 commit comments