MCPcopy Index your code
hub / github.com/nodeSolidServer/node-solid-server / verifyKey

Function verifyKey

lib/webid/lib/verify.mjs:37–77  ·  view source on GitHub ↗
(certificateObj, uri, profile, contentType, callback)

Source from the content-addressed store, hash-verified

35}
36
37export function verifyKey (certificateObj, uri, profile, contentType, callback) {
38 const graph = new Graph()
39 let found = false
40 if (!certificateObj.modulus) {
41 return callback(new Error('Missing modulus value in client certificate'))
42 }
43 if (!certificateObj.exponent) {
44 return callback(new Error('Missing exponent value in client certificate'))
45 }
46 if (!contentType) {
47 return callback(new Error('No value specified for the Content-Type header'))
48 }
49 const mimeType = contentType.replace(/;.*/, '')
50 parse(profile, graph, uri, mimeType, function (err) {
51 if (err) {
52 return callback(err)
53 }
54 const certExponent = parseInt(certificateObj.exponent, 16).toString()
55 const query = $rdf.SPARQLToQuery(SPARQL_QUERY, undefined, graph)
56 graph.query(
57 query,
58 function (result) {
59 if (found) {
60 return
61 }
62 const modulus = result['?m'].value
63 const exponent = result['?e'].value
64 if (modulus != null && exponent != null && (modulus.toLowerCase() === certificateObj.modulus.toLowerCase()) && exponent === certExponent) {
65 found = true
66 }
67 },
68 undefined,
69 function () {
70 if (!found) {
71 return callback(new Error("Certificate public key not found in the user's profile"))
72 }
73 return callback(null, true)
74 }
75 )
76 })
77}

Callers 1

verifyFunction · 0.85

Calls 1

parseFunction · 0.70

Tested by

no test coverage detected