Skip to content

Commit df67141

Browse files
committed
Remove optional x509 dependency.
Didn't compile on Node 10, and was probably not widely used anyway.
1 parent f189e10 commit df67141

File tree

8 files changed

+10
-190
lines changed

8 files changed

+10
-190
lines changed

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
- Fix the use of allow handler.
1010
- Misc. cleanups and improvements.
1111
- Add .well-known folder and set up with public access.
12-
- Node.js 8 is required, Node.js 10 will also work, except for the
13-
x509 optional dependency, which is only needed in corner cases.
1412

1513
## 4.0.0
1614
- OIDC is now supported as authentication method in addition to WebID-TLS.

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ $ solid start --help
166166
--config-path [value]
167167
--db-path [value]
168168
--auth [value] Pick an authentication strategy for WebID: `tls` or `oidc`
169-
--certificate-header [value]
170169
--owner [value] Set the owner of the storage (overwrites the root ACL file)
171170
--ssl-key [value] Path to the SSL private key in PEM format
172171
--ssl-cert [value] Path to the SSL certificate key in PEM format

bin/lib/options.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,6 @@ module.exports = [
8181
return answers.webid
8282
}
8383
},
84-
{
85-
name: 'certificate-header',
86-
question: 'Accept client certificates through this HTTP header (for reverse proxies)',
87-
default: '',
88-
prompt: false
89-
},
9084
{
9185
name: 'useOwner',
9286
question: 'Do you already have a WebID?',

lib/api/authn/webid-tls.js

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
const webid = require('webid/tls')
22
const debug = require('../../debug').authentication
3-
let x509 // optional dependency, load lazily
4-
5-
const CERTIFICATE_MATCHER = /^-----BEGIN CERTIFICATE-----\n(?:[A-Za-z0-9+/=]+\n)+-----END CERTIFICATE-----$/m
63

74
function initialize (app, argv) {
85
app.use('/', handler)
9-
if (argv.certificateHeader) {
10-
app.locals.certificateHeader = argv.certificateHeader.toLowerCase()
11-
}
126
}
137

148
function handler (req, res, next) {
@@ -20,7 +14,7 @@ function handler (req, res, next) {
2014
}
2115

2216
// No certificate? skip
23-
const certificate = getCertificateViaTLS(req) || getCertificateViaHeader(req)
17+
const certificate = getCertificateViaTLS(req)
2418
if (!certificate) {
2519
setEmptySession(req)
2620
return next()
@@ -50,47 +44,6 @@ function getCertificateViaTLS (req) {
5044
debug('No peer certificate received during TLS handshake.')
5145
}
5246

53-
// Tries to obtain a client certificate retrieved through an HTTP header
54-
function getCertificateViaHeader (req) {
55-
// Only allow header-based certificates if explicitly enabled
56-
const headerName = req.app.locals.certificateHeader
57-
if (!headerName) return
58-
59-
// Try to retrieve the certificate from the header
60-
const header = req.headers[headerName]
61-
if (!header) {
62-
return debug(`No certificate received through the ${headerName} header.`)
63-
}
64-
// The certificate's newlines have been replaced by tabs
65-
// in order to fit in an HTTP header (NGINX does this automatically)
66-
const rawCertificate = header.replace(/\t/g, '\n')
67-
68-
// Ensure the header contains a valid certificate
69-
// (x509 unsafely interprets it as a file path otherwise)
70-
if (!CERTIFICATE_MATCHER.test(rawCertificate)) {
71-
return debug(`Invalid value for the ${headerName} header.`)
72-
}
73-
74-
// Parse and convert the certificate to the format the webid library expects
75-
if (!x509) {
76-
try {
77-
x509 = require('x509')
78-
} catch (e) {
79-
x509 = { parseCert: () => { throw new Error() } }
80-
}
81-
}
82-
try {
83-
const { publicKey, extensions } = x509.parseCert(rawCertificate)
84-
return {
85-
modulus: publicKey.n,
86-
exponent: '0x' + parseInt(publicKey.e, 10).toString(16),
87-
subjectaltname: extensions && extensions.subjectAlternativeName
88-
}
89-
} catch (error) {
90-
debug(`Invalid certificate received through the ${headerName} header.`)
91-
}
92-
}
93-
9447
function setEmptySession (req) {
9548
req.session.userId = ''
9649
}

lib/create-server.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ function createServer (argv, app) {
3434
}
3535

3636
let server
37-
const needsTLS = argv.sslKey || argv.sslCert ||
38-
(ldp.webid || ldp.multiuser) && !argv.certificateHeader
37+
const needsTLS = argv.sslKey || argv.sslCert
3938
if (!needsTLS) {
4039
server = http.createServer(app)
4140
} else {

package-lock.json

Lines changed: 8 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@
7373
"vhost": "^3.0.2",
7474
"webid": "^0.3.10"
7575
},
76-
"optionalDependencies": {
77-
"x509": "^0.3.2"
78-
},
7976
"devDependencies": {
8077
"@trust/oidc-op": "^0.3.0",
8178
"chai": "^3.5.0",

test/integration/acl-tls-test.js

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -936,107 +936,3 @@ describe('ACL with WebID+TLS', function () {
936936
})
937937
})
938938
})
939-
940-
describe('ACL with WebID through X-SSL-Cert', function () {
941-
let hasX509
942-
try {
943-
require('x509')
944-
hasX509 = true
945-
} catch (error) {
946-
hasX509 = false
947-
}
948-
949-
var ldpHttpsServer
950-
before(function (done) {
951-
const ldp = ldnode.createServer({
952-
mount: '/test',
953-
root: rootPath,
954-
webid: true,
955-
auth: 'tls',
956-
certificateHeader: 'X-SSL-Cert'
957-
})
958-
ldpHttpsServer = ldp.listen(3456, done)
959-
})
960-
961-
after(function () {
962-
if (ldpHttpsServer) ldpHttpsServer.close()
963-
fs.removeSync(path.join(rootPath, 'index.html'))
964-
fs.removeSync(path.join(rootPath, 'index.html.acl'))
965-
})
966-
967-
function prepareRequest (certHeader, setResponse) {
968-
return done => {
969-
const options = {
970-
url: address.replace('https', 'http') + '/acl-tls/write-acl/.acl',
971-
headers: { 'X-SSL-Cert': certHeader }
972-
}
973-
request(options, function (error, response) {
974-
setResponse(response)
975-
done(error)
976-
})
977-
}
978-
}
979-
980-
describe('without certificate', function () {
981-
var response
982-
before(prepareRequest('', res => { response = res }))
983-
984-
it('should return 401', function () {
985-
assert.propertyVal(response, 'statusCode', 401)
986-
})
987-
})
988-
989-
describe('with a valid certificate', function () {
990-
// Escape certificate for usage in HTTP header
991-
const escapedCert = userCredentials.user1.cert.toString()
992-
.replace(/\n/g, '\t')
993-
994-
var response
995-
before(prepareRequest(escapedCert, res => { response = res }))
996-
997-
it('should return 200', function () {
998-
hasX509 || this.skip()
999-
assert.propertyVal(response, 'statusCode', 200)
1000-
})
1001-
1002-
it('should set the User header', function () {
1003-
hasX509 || this.skip()
1004-
assert.propertyVal(response.headers, 'user', 'https://user1.databox.me/profile/card#me')
1005-
})
1006-
})
1007-
1008-
describe('with a local filename as certificate', function () {
1009-
const certFile = path.join(__dirname, '../keys/user1-cert.pem')
1010-
1011-
var response
1012-
before(prepareRequest(certFile, res => { response = res }))
1013-
1014-
it('should return 401', function () {
1015-
assert.propertyVal(response, 'statusCode', 401)
1016-
})
1017-
})
1018-
1019-
describe('with an invalid certificate value', function () {
1020-
var response
1021-
before(prepareRequest('xyz', res => { response = res }))
1022-
1023-
it('should return 401', function () {
1024-
assert.propertyVal(response, 'statusCode', 401)
1025-
})
1026-
})
1027-
1028-
describe('with an invalid certificate', function () {
1029-
const invalidCert =
1030-
`-----BEGIN CERTIFICATE-----
1031-
ABCDEF
1032-
-----END CERTIFICATE-----`
1033-
.replace(/\n/g, '\t')
1034-
1035-
var response
1036-
before(prepareRequest(invalidCert, res => { response = res }))
1037-
1038-
it('should return 401', function () {
1039-
assert.propertyVal(response, 'statusCode', 401)
1040-
})
1041-
})
1042-
})

0 commit comments

Comments
 (0)