Skip to content

Instantly share code, notes, and snippets.

@nicoster
Created June 13, 2014 11:04
Show Gist options
  • Save nicoster/81139d86f135a41d9b18 to your computer and use it in GitHub Desktop.
Save nicoster/81139d86f135a41d9b18 to your computer and use it in GitHub Desktop.
turn SofToken II.app into a https web service
#!/usr/bin/env node
// the pathname of the url without the leading '/' is used as softoken pin
// so make the call with http://localhost:8000/<softoken-pin>
const https = require('https'),
fs = require("fs"),
url = require('url'),
exec = require('child_process').exec;
var options = {
key: fs.readFileSync('certs/pri.pem'),
cert: fs.readFileSync('certs/cert.pem')
};
var server = https.createServer(options, function (req, res) {
pin = url.parse(req.url, true).pathname.substr(1);
console.log(pin);
res.writeHead(200, {"Content-Type": "text/plain"});
exec('echo ' + pin + '|/Applications/SofToken\\ II.app/Contents/Resources/st-wrap.sh -s -p', function (error, stdout, stderr) {
res.end(stdout);
});
});
server.listen(8000);
console.log("Server running at https://127.0.0.1:8000/");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment