Release 0.12.1

This commit is contained in:
Yarmo Mackenbach 2021-04-26 16:01:40 +02:00
parent e0dc5f4b21
commit 780d4d0c69
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
4 changed files with 234 additions and 214 deletions

View file

@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [0.12.1] - 2021-04-26
## Fixed
- Bad interpretation of proxy policy
- Proxy URL protocol
## [0.12.0] - 2021-04-22 ## [0.12.0] - 2021-04-22
## Added ## Added
- Proxy server functionality - Proxy server functionality

437
dist/doip.js vendored
View file

@ -7541,7 +7541,7 @@ module.exports={
"chai": "^4.2.0", "chai": "^4.2.0",
"chai-as-promised": "^7.1.1", "chai-as-promised": "^7.1.1",
"chai-match-pattern": "^1.2.0", "chai-match-pattern": "^1.2.0",
"docdash": "^1.2.0", "clean-jsdoc-theme": "^3.2.4",
"jsdoc": "^3.6.6", "jsdoc": "^3.6.6",
"license-check-and-add": "^3.0.4", "license-check-and-add": "^3.0.4",
"minify": "^6.0.1", "minify": "^6.0.1",
@ -9493,7 +9493,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
const dns = require('dns') const jsEnv = require("browser-or-node")
/** /**
* @module fetcher/dns * @module fetcher/dns
@ -9505,46 +9505,51 @@ const dns = require('dns')
*/ */
module.exports.timeout = 5000 module.exports.timeout = 5000
/** if (!jsEnv.isNode) {
* Execute a fetch request const dns = require('dns')
* @function
* @async
* @param {object} data - Data used in the request
* @param {string} data.domain - The targeted domain
* @returns {object}
*/
module.exports.fn = async (data, opts) => {
let timeoutHandle
const timeoutPromise = new Promise((resolve, reject) => {
timeoutHandle = setTimeout(
() => reject(new Error('Request was timed out')),
data.fetcherTimeout ? data.fetcherTimeout : module.exports.timeout
)
})
const fetchPromise = new Promise((resolve, reject) => { /**
dns.resolveTxt(data.domain, (err, records) => { * Execute a fetch request
if (err) { * @function
reject(err) * @async
return * @param {object} data - Data used in the request
} * @param {string} data.domain - The targeted domain
* @returns {object}
*/
module.exports.fn = async (data, opts) => {
let timeoutHandle
const timeoutPromise = new Promise((resolve, reject) => {
timeoutHandle = setTimeout(
() => reject(new Error('Request was timed out')),
data.fetcherTimeout ? data.fetcherTimeout : module.exports.timeout
)
})
resolve({ const fetchPromise = new Promise((resolve, reject) => {
domain: data.domain, dns.resolveTxt(data.domain, (err, records) => {
records: { if (err) {
txt: records, reject(err)
}, return
}
resolve({
domain: data.domain,
records: {
txt: records,
},
})
}) })
}) })
})
return Promise.race([fetchPromise, timeoutPromise]).then((result) => { return Promise.race([fetchPromise, timeoutPromise]).then((result) => {
clearTimeout(timeoutHandle) clearTimeout(timeoutHandle)
return result return result
}) })
}
} else {
module.exports.fn = null
} }
},{"browser-or-node":"/home/yarmo/dev/doip/doipjs/node_modules/browser-or-node/lib/index.js","dns":"/home/yarmo/dev/doip/doipjs/node_modules/browserify/lib/_empty.js"}],"/home/yarmo/dev/doip/doipjs/src/fetcher/gitlab.js":[function(require,module,exports){
},{"dns":"/home/yarmo/dev/doip/doipjs/node_modules/browserify/lib/_empty.js"}],"/home/yarmo/dev/doip/doipjs/src/fetcher/gitlab.js":[function(require,module,exports){
/* /*
Copyright 2021 Yarmo Mackenbach Copyright 2021 Yarmo Mackenbach
@ -9756,8 +9761,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
const irc = require('irc-upd') const jsEnv = require("browser-or-node")
const validator = require('validator')
/** /**
* @module fetcher/irc * @module fetcher/irc
@ -9769,68 +9773,75 @@ const validator = require('validator')
*/ */
module.exports.timeout = 20000 module.exports.timeout = 20000
/** if (jsEnv.isNode) {
* Execute a fetch request const irc = require('irc-upd')
* @function const validator = require('validator')
* @async
* @param {object} data - Data used in the request /**
* @param {string} data.nick - The nick of the targeted account * Execute a fetch request
* @param {string} data.domain - The domain on which the targeted account is registered * @function
* @param {object} opts - Options used to enable the request * @async
* @param {string} opts.claims.irc.nick - The nick to be used by the library to log in * @param {object} data - Data used in the request
* @returns {object} * @param {string} data.nick - The nick of the targeted account
*/ * @param {string} data.domain - The domain on which the targeted account is registered
module.exports.fn = async (data, opts) => { * @param {object} opts - Options used to enable the request
let timeoutHandle * @param {string} opts.claims.irc.nick - The nick to be used by the library to log in
const timeoutPromise = new Promise((resolve, reject) => { * @returns {object}
timeoutHandle = setTimeout( */
() => reject(new Error('Request was timed out')), module.exports.fn = async (data, opts) => {
data.fetcherTimeout ? data.fetcherTimeout : module.exports.timeout let timeoutHandle
) const timeoutPromise = new Promise((resolve, reject) => {
}) timeoutHandle = setTimeout(
() => reject(new Error('Request was timed out')),
const fetchPromise = new Promise((resolve, reject) => { data.fetcherTimeout ? data.fetcherTimeout : module.exports.timeout
try { )
validator.isAscii(opts.claims.irc.nick) })
} catch (err) {
throw new Error(`IRC fetcher was not set up properly (${err.message})`) const fetchPromise = new Promise((resolve, reject) => {
} try {
validator.isAscii(opts.claims.irc.nick)
try { } catch (err) {
const client = new irc.Client(data.domain, opts.claims.irc.nick, { throw new Error(`IRC fetcher was not set up properly (${err.message})`)
port: 6697, }
secure: true,
channels: [], try {
}) const client = new irc.Client(data.domain, opts.claims.irc.nick, {
const reKey = /[a-zA-Z0-9\-\_]+\s+:\s(openpgp4fpr\:.*)/ port: 6697,
const reEnd = /End\sof\s.*\staxonomy./ secure: true,
let keys = [] channels: [],
})
client.addListener('registered', (message) => { const reKey = /[a-zA-Z0-9\-\_]+\s+:\s(openpgp4fpr\:.*)/
client.send(`PRIVMSG NickServ :TAXONOMY ${data.nick}`) const reEnd = /End\sof\s.*\staxonomy./
}) let keys = []
client.addListener('notice', (nick, to, text, message) => {
if (reKey.test(text)) { client.addListener('registered', (message) => {
const match = text.match(reKey) client.send(`PRIVMSG NickServ :TAXONOMY ${data.nick}`)
keys.push(match[1]) })
} client.addListener('notice', (nick, to, text, message) => {
if (reEnd.test(text)) { if (reKey.test(text)) {
client.disconnect() const match = text.match(reKey)
resolve(keys) keys.push(match[1])
} }
}) if (reEnd.test(text)) {
} catch (error) { client.disconnect()
reject(error) resolve(keys)
} }
}) })
} catch (error) {
return Promise.race([fetchPromise, timeoutPromise]).then((result) => { reject(error)
clearTimeout(timeoutHandle) }
return result })
})
return Promise.race([fetchPromise, timeoutPromise]).then((result) => {
clearTimeout(timeoutHandle)
return result
})
}
} else {
module.exports.fn = null
} }
},{"irc-upd":"irc-upd","validator":"/home/yarmo/dev/doip/doipjs/node_modules/validator/index.js"}],"/home/yarmo/dev/doip/doipjs/src/fetcher/matrix.js":[function(require,module,exports){ },{"browser-or-node":"/home/yarmo/dev/doip/doipjs/node_modules/browser-or-node/lib/index.js","irc-upd":"irc-upd","validator":"/home/yarmo/dev/doip/doipjs/node_modules/validator/index.js"}],"/home/yarmo/dev/doip/doipjs/src/fetcher/matrix.js":[function(require,module,exports){
/* /*
Copyright 2021 Yarmo Mackenbach Copyright 2021 Yarmo Mackenbach
@ -10010,10 +10021,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
const jsdom = require('jsdom') const jsEnv = require("browser-or-node")
const { client, xml } = require('@xmpp/client')
const debug = require('@xmpp/debug')
const validator = require('validator')
/** /**
* @module fetcher/xmpp * @module fetcher/xmpp
@ -10025,115 +10033,124 @@ const validator = require('validator')
*/ */
module.exports.timeout = 5000 module.exports.timeout = 5000
let xmpp = null, if (jsEnv.isNode) {
iqCaller = null const jsdom = require('jsdom')
const { client, xml } = require('@xmpp/client')
const xmppStart = async (service, username, password) => { const debug = require('@xmpp/debug')
return new Promise((resolve, reject) => { const validator = require('validator')
const xmpp = client({
service: service, let xmpp = null,
username: username, iqCaller = null
password: password,
}) const xmppStart = async (service, username, password) => {
if (process.env.NODE_ENV !== 'production') { return new Promise((resolve, reject) => {
debug(xmpp, true) const xmpp = client({
} service: service,
const { iqCaller } = xmpp username: username,
xmpp.start() password: password,
xmpp.on('online', (address) => { })
resolve({ xmpp: xmpp, iqCaller: iqCaller }) if (process.env.NODE_ENV !== 'production') {
}) debug(xmpp, true)
xmpp.on('error', (error) => {
reject(error)
})
})
}
/**
* Execute a fetch request
* @function
* @async
* @param {object} data - Data used in the request
* @param {string} data.id - The identifier of the targeted account
* @param {string} data.field - The vCard field to return (should be "note")
* @param {object} opts - Options used to enable the request
* @param {string} opts.claims.xmpp.service - The server hostname on which the library can log in
* @param {string} opts.claims.xmpp.username - The username used to log in
* @param {string} opts.claims.xmpp.password - The password used to log in
* @returns {object}
*/
module.exports.fn = async (data, opts) => {
let timeoutHandle
const timeoutPromise = new Promise((resolve, reject) => {
timeoutHandle = setTimeout(
() => reject(new Error('Request was timed out')),
data.fetcherTimeout ? data.fetcherTimeout : module.exports.timeout
)
})
const fetchPromise = new Promise(async (resolve, reject) => {
try {
validator.isFQDN(opts.claims.xmpp.service)
validator.isAscii(opts.claims.xmpp.username)
validator.isAscii(opts.claims.xmpp.password)
} catch (err) {
throw new Error(`XMPP fetcher was not set up properly (${err.message})`)
}
if (!xmpp || xmpp.status !== 'online') {
const xmppStartRes = await xmppStart(
opts.claims.xmpp.service,
opts.claims.xmpp.username,
opts.claims.xmpp.password
)
xmpp = xmppStartRes.xmpp
iqCaller = xmppStartRes.iqCaller
}
const response = await iqCaller.request(
xml('iq', { type: 'get', to: data.id }, xml('vCard', 'vcard-temp')),
30 * 1000
)
const vcardRow = response.getChild('vCard', 'vcard-temp').toString()
const dom = new jsdom.JSDOM(vcardRow)
try {
let vcard
switch (data.field.toLowerCase()) {
case 'desc':
case 'note':
vcard = dom.window.document.querySelector('note text')
if (!vcard) {
vcard = dom.window.document.querySelector('DESC')
}
if (vcard) {
vcard = vcard.textContent
} else {
throw new Error('No DESC or NOTE field found in vCard')
}
break
default:
vcard = dom.window.document.querySelector(data).textContent
break
} }
xmpp.stop() const { iqCaller } = xmpp
resolve(vcard) xmpp.start()
} catch (error) { xmpp.on('online', (address) => {
reject(error) resolve({ xmpp: xmpp, iqCaller: iqCaller })
} })
}) xmpp.on('error', (error) => {
reject(error)
return Promise.race([fetchPromise, timeoutPromise]).then((result) => { })
clearTimeout(timeoutHandle) })
return result }
})
/**
* Execute a fetch request
* @function
* @async
* @param {object} data - Data used in the request
* @param {string} data.id - The identifier of the targeted account
* @param {string} data.field - The vCard field to return (should be "note")
* @param {object} opts - Options used to enable the request
* @param {string} opts.claims.xmpp.service - The server hostname on which the library can log in
* @param {string} opts.claims.xmpp.username - The username used to log in
* @param {string} opts.claims.xmpp.password - The password used to log in
* @returns {object}
*/
module.exports.fn = async (data, opts) => {
let timeoutHandle
const timeoutPromise = new Promise((resolve, reject) => {
timeoutHandle = setTimeout(
() => reject(new Error('Request was timed out')),
data.fetcherTimeout ? data.fetcherTimeout : module.exports.timeout
)
})
const fetchPromise = new Promise(async (resolve, reject) => {
try {
validator.isFQDN(opts.claims.xmpp.service)
validator.isAscii(opts.claims.xmpp.username)
validator.isAscii(opts.claims.xmpp.password)
} catch (err) {
throw new Error(`XMPP fetcher was not set up properly (${err.message})`)
}
if (!xmpp || xmpp.status !== 'online') {
const xmppStartRes = await xmppStart(
opts.claims.xmpp.service,
opts.claims.xmpp.username,
opts.claims.xmpp.password
)
xmpp = xmppStartRes.xmpp
iqCaller = xmppStartRes.iqCaller
}
const response = await iqCaller.request(
xml('iq', { type: 'get', to: data.id }, xml('vCard', 'vcard-temp')),
30 * 1000
)
const vcardRow = response.getChild('vCard', 'vcard-temp').toString()
const dom = new jsdom.JSDOM(vcardRow)
try {
let vcard
switch (data.field.toLowerCase()) {
case 'desc':
case 'note':
vcard = dom.window.document.querySelector('note text')
if (!vcard) {
vcard = dom.window.document.querySelector('DESC')
}
if (vcard) {
vcard = vcard.textContent
} else {
throw new Error('No DESC or NOTE field found in vCard')
}
break
default:
vcard = dom.window.document.querySelector(data).textContent
break
}
xmpp.stop()
resolve(vcard)
} catch (error) {
reject(error)
}
})
return Promise.race([fetchPromise, timeoutPromise]).then((result) => {
clearTimeout(timeoutHandle)
return result
})
}
} else {
module.exports.fn = null
} }
}).call(this)}).call(this,require('_process')) }).call(this)}).call(this,require('_process'))
},{"@xmpp/client":"@xmpp/client","@xmpp/debug":"@xmpp/debug","_process":"/home/yarmo/dev/doip/doipjs/node_modules/process/browser.js","jsdom":"jsdom","validator":"/home/yarmo/dev/doip/doipjs/node_modules/validator/index.js"}],"/home/yarmo/dev/doip/doipjs/src/index.js":[function(require,module,exports){ },{"@xmpp/client":"@xmpp/client","@xmpp/debug":"@xmpp/debug","_process":"/home/yarmo/dev/doip/doipjs/node_modules/process/browser.js","browser-or-node":"/home/yarmo/dev/doip/doipjs/node_modules/browser-or-node/lib/index.js","jsdom":"jsdom","validator":"/home/yarmo/dev/doip/doipjs/node_modules/validator/index.js"}],"/home/yarmo/dev/doip/doipjs/src/index.js":[function(require,module,exports){
/* /*
Copyright 2021 Yarmo Mackenbach Copyright 2021 Yarmo Mackenbach
@ -10530,9 +10547,7 @@ const handleBrowserRequests = (data, opts) => {
return createFallbackRequestPromise(data, opts) return createFallbackRequestPromise(data, opts)
break break
case E.ProofAccess.SERVER: case E.ProofAccess.SERVER:
throw new Error( return createProxyRequestPromise(data, opts)
'Impossible to fetch proof (bad combination of service access and proxy policy)'
)
break break
default: default:
throw new Error('Invalid proof access value') throw new Error('Invalid proof access value')
@ -10834,7 +10849,7 @@ const generateProxyURL = (type, data, opts) => {
queryStrings.push(`${key}=${encodeURIComponent(data[key])}`) queryStrings.push(`${key}=${encodeURIComponent(data[key])}`)
}) })
return `http://${opts.proxy.hostname}/api/2/get/${type}?${queryStrings.join( return `https://${opts.proxy.hostname}/api/2/get/${type}?${queryStrings.join(
'&' '&'
)}` )}`
} }

2
dist/doip.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{ {
"name": "doipjs", "name": "doipjs",
"version": "0.12.0", "version": "0.12.1",
"description": "Decentralized OpenPGP Identity Proofs library in Node.js", "description": "Decentralized OpenPGP Identity Proofs library in Node.js",
"main": "src/index.js", "main": "src/index.js",
"dependencies": { "dependencies": {
@ -35,7 +35,7 @@
"prettier": "^2.1.2" "prettier": "^2.1.2"
}, },
"scripts": { "scripts": {
"release:bundle": "./node_modules/.bin/browserify ./src/index.js --full-paths --standalone doip -x openpgp -x jsdom -x @xmpp/client -x @xmpp/debug -x irc-upd -o ./dist/doip.js", "release:bundle": "./node_modules/.bin/browserify ./src/index.js --standalone doip -x openpgp -x jsdom -x @xmpp/client -x @xmpp/debug -x irc-upd -o ./dist/doip.js",
"release:minify": "./node_modules/.bin/minify ./dist/doip.js > ./dist/doip.min.js", "release:minify": "./node_modules/.bin/minify ./dist/doip.js > ./dist/doip.min.js",
"prettier:check": "./node_modules/.bin/prettier --check .", "prettier:check": "./node_modules/.bin/prettier --check .",
"prettier:write": "./node_modules/.bin/prettier --write .", "prettier:write": "./node_modules/.bin/prettier --write .",