diff options
Diffstat (limited to 'examples/client.js')
| -rw-r--r-- | examples/client.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/examples/client.js b/examples/client.js index 49e38d0..737b381 100644 --- a/examples/client.js +++ b/examples/client.js @@ -1,7 +1,28 @@ 'use strict' +const {createInterface} = require('readline') const {request} = require('..') +// https://gemini.circumlunar.space/docs/spec-spec.txt, 1.4.3 +// > Interactive clients for human users MUST inform users that such a session +// > has been requested and require the user to approve generation of such a +// > certificate. Transient certificates MUST NOT be generated automatically. +const letUserConfirmClientCertUsage = ({host, reason}, cb) => { + const prompt = createInterface({ + input: process.stdin, + output: process.stdout, + history: 0, + }) + prompt.question([ + `Send client cert to ${host}?`, + reason ? ` Server says: "${reason}".` : '', + ' y/n > ' + ].join(''), (confirmed) => { + prompt.close() + cb(confirmed === 'y' || confirmed === 'Y') + }) +} + const onError = (err) => { console.error(err) process.exit(1) @@ -9,6 +30,7 @@ const onError = (err) => { request('/bar', { followRedirects: true, + useClientCerts: true, letUserConfirmClientCertUsage, tlsOpt: { rejectUnauthorized: false, }, |
