| 35 | } |
| 36 | |
| 37 | export 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 | } |