2017-01-27 15:55:38 +03:00
|
|
|
import QtQuick 2.0
|
|
|
|
import io.thp.pyotherside 1.4
|
|
|
|
|
2017-01-30 16:59:58 +03:00
|
|
|
|
2017-01-27 15:55:38 +03:00
|
|
|
// @disable-check M300
|
|
|
|
Python {
|
|
|
|
id: py
|
|
|
|
|
|
|
|
property int nDevices
|
|
|
|
property bool hasDevice
|
|
|
|
property string name
|
|
|
|
property string version
|
|
|
|
property string serial
|
|
|
|
property var features: []
|
|
|
|
property var connections: []
|
2017-01-30 16:59:58 +03:00
|
|
|
property var credentials: []
|
2017-01-27 15:55:38 +03:00
|
|
|
property var enabled: []
|
|
|
|
property bool ready: false
|
|
|
|
property var queue: []
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
2017-01-30 16:59:58 +03:00
|
|
|
importModule('site', function () {
|
|
|
|
call('site.addsitedir', [appDir + '/pymodules'], function () {
|
2017-01-27 15:55:38 +03:00
|
|
|
addImportPath(urlPrefix + '/py')
|
|
|
|
importModule('yubikey', function () {
|
|
|
|
ready = true
|
2017-01-30 16:59:58 +03:00
|
|
|
do_call('yubikey.controller.get_features', [],
|
|
|
|
function (res) {
|
|
|
|
features = res
|
|
|
|
for (var i in queue) {
|
|
|
|
do_call(queue[i][0], queue[i][1],
|
|
|
|
queue[i][2])
|
|
|
|
}
|
|
|
|
queue = []
|
|
|
|
})
|
2017-01-27 15:55:38 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
onError: {
|
|
|
|
console.log('Python error: ' + traceback)
|
|
|
|
}
|
|
|
|
|
|
|
|
function do_call(func, args, cb) {
|
|
|
|
if (!ready) {
|
|
|
|
queue.push([func, args, cb])
|
|
|
|
} else {
|
2017-01-30 16:59:58 +03:00
|
|
|
call(func, args, function (json) {
|
2017-01-27 15:55:38 +03:00
|
|
|
if (cb) {
|
|
|
|
cb(json ? JSON.parse(json) : undefined)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function refresh() {
|
|
|
|
do_call('yubikey.controller.count_devices', [], function (n) {
|
|
|
|
nDevices = n
|
|
|
|
if (nDevices == 1) {
|
|
|
|
do_call('yubikey.controller.refresh', [], function (dev) {
|
|
|
|
hasDevice = dev !== undefined && dev !== null
|
|
|
|
name = dev ? dev.name : ''
|
|
|
|
version = dev ? dev.version : ''
|
|
|
|
serial = dev ? dev.serial : ''
|
|
|
|
enabled = dev ? dev.enabled : []
|
|
|
|
connections = dev ? dev.connections : []
|
2017-01-31 11:57:44 +03:00
|
|
|
credentials = dev ? parseCredentials(dev.credentials) : []
|
2017-01-27 15:55:38 +03:00
|
|
|
})
|
|
|
|
} else if (hasDevice) {
|
|
|
|
hasDevice = false
|
|
|
|
}
|
|
|
|
})
|
2017-01-30 16:59:58 +03:00
|
|
|
}
|
2017-01-27 15:55:38 +03:00
|
|
|
|
2017-01-30 16:59:58 +03:00
|
|
|
function refresh_credentials() {
|
|
|
|
if (enabled.indexOf('CCID') != -1) {
|
|
|
|
do_call('yubikey.controller.refresh_credentials', [],
|
|
|
|
function (dev) {
|
2017-01-31 11:57:44 +03:00
|
|
|
credentials = dev ? parseCredentials(
|
|
|
|
dev.credentials) : []
|
2017-01-30 16:59:58 +03:00
|
|
|
})
|
|
|
|
}
|
2017-01-27 15:55:38 +03:00
|
|
|
}
|
|
|
|
|
2017-01-31 11:57:44 +03:00
|
|
|
function parseCredentials(creds) {
|
|
|
|
function hasIssuer(name) {
|
|
|
|
return name.indexOf(':') !== -1
|
|
|
|
}
|
|
|
|
function parseName(name) {
|
|
|
|
return name.split(":").slice(1).join(":")
|
|
|
|
}
|
|
|
|
function parseIssuer(name) {
|
|
|
|
return name.split(":", 1)
|
|
|
|
}
|
|
|
|
var result = []
|
|
|
|
for (var i = 0; i < creds.length; i++) {
|
|
|
|
var cred = JSON.parse(creds[i])
|
|
|
|
if (hasIssuer(cred.name)) {
|
|
|
|
cred.issuer = parseIssuer(cred.name)
|
|
|
|
cred.name = parseName(cred.name)
|
|
|
|
}
|
|
|
|
result.push(cred)
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2017-01-27 15:55:38 +03:00
|
|
|
function set_mode(connections, cb) {
|
|
|
|
do_call('yubikey.controller.set_mode', [connections], cb)
|
|
|
|
}
|
|
|
|
}
|