Skip to content

Commit b6db022

Browse files
author
nicola
committed
webid lib returns a certificate object
1 parent 513b52d commit b6db022

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

‎lib/identity-provider.js‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ var waterfall = async.waterfall
1111
var debug = require('./debug').idp
1212
var express = require('express')
1313
var bodyParser = require('body-parser')
14-
var errorHandler = require('./handlers/error');
14+
var errorHandler = require('./handlers/error')
1515
var url = require('url')
1616
var uriBase = require('./utils').uriBase
17+
var forge = require('node-forge')
18+
var asn1 = forge.asn1
19+
var pki = forge.pki
1720

1821
function defaultBuildURI (account, host, port) {
1922
var hostAndPort = (host || 'localhost') + (port || '')
@@ -152,14 +155,17 @@ function addKey (graph, agent, cert) {
152155
sym(key),
153156
sym('http://www.w3.org/2000/01/rdf-schema#label'),
154157
lit('Created on ' + (new Date()).toString()))
158+
159+
var modulus = cert.publicKey.n.toString()
160+
var exponent = cert.publicKey.e.toString()
155161
graph.add(
156162
sym(key),
157163
sym('http://www.w3.org/ns/auth/cert#modulus'),
158-
lit(cert.mod, 'http://www.w3.org/2001/XMLSchema#hexBinary')) // TODO add Datatype "http://www.w3.org/2001/XMLSchema#hexBinary"
164+
lit(modulus, 'http://www.w3.org/2001/XMLSchema#hexBinary')) // TODO add Datatype "http://www.w3.org/2001/XMLSchema#hexBinary"
159165
graph.add(
160166
sym(key),
161167
sym('http://www.w3.org/ns/auth/cert#exponent'),
162-
lit(cert.exponent, 'http://www.w3.org/2001/XMLSchema#int')) // TODO add Datatype "http://www.w3.org/2001/XMLSchema#int"
168+
lit(exponent, 'http://www.w3.org/2001/XMLSchema#int')) // TODO add Datatype "http://www.w3.org/2001/XMLSchema#int"
163169
}
164170

165171
// Create an ACL for the WebID card
@@ -296,7 +302,6 @@ IdentityProvider.prototype.post = function (req, res, next) {
296302
var self = this
297303
var options = req.body
298304
options.host = req.get('host')
299-
console.log(options.host)
300305
debug('Create account with settings ', options)
301306

302307
if (!options || !options.username) {
@@ -319,8 +324,8 @@ IdentityProvider.prototype.post = function (req, res, next) {
319324
return callback(null, false)
320325
}
321326
},
322-
function (newSpkac, callback) {
323-
cert = newSpkac
327+
function (newCert, callback) {
328+
cert = newCert
324329

325330
self.create(options, cert, callback)
326331
}
@@ -335,9 +340,11 @@ IdentityProvider.prototype.post = function (req, res, next) {
335340
res.status(201)
336341

337342
if (cert) {
338-
res.set('Content-Type', 'text/html')
339-
var encodedSpkac = new Buffer(cert).toString('base64')
340-
res.send('<iframe width="0" height="0" style="display: none;" src="data:application/x-x509-user-cert;base64,' + encodedSpkac + '"></iframe>')
343+
res.set('Accept-Ranges', 'bytes');
344+
res.set('Content-Type', 'application/x-x509-user-cert')
345+
// Convert to DER
346+
var der = asn1.toDer(pki.certificateToAsn1(cert)).getBytes()
347+
res.send(der)
341348
} else {
342349
res.end()
343350
}

0 commit comments

Comments
 (0)