Skip to main content

libs & stu_capture

Within libs, the wacom and will folders may be deleted. Optionally, the libs folder itself may also be deleted, provided users retrieve the stu_capture folder inside and place it within sigCaptDialog, so that the final folder structure looks like so: sigCaptDialog/libs/stu_capture.

For the purposes of this guide, it will be assumed that the folder structure is sigCaptDialog/stu_capture.

Within stu_capture, the file stu_capture_encryption.js will require the following adjustments:

On clearKeys

    /**
* Reset all encryption key values
*/
clearKeys() {
this.bigint_p = null;
this.bigint_g = null;
this.sjcl_keyAES = null;
}

On computeSharedKey and decrypt:

    /**
* Calculate a shared key, given the tablet's public key
* @param devicePublicKey the tablet's public key
*/
computeSharedKey(devicePublicKey) {
var B = devicePublicKey;

var bigint_B = BigInt("0x"+arrayToHex(B));

var bigint_shared = powMod(bigint_B, this.bigint_a, this.bigint_p);

var str_shared = padLeft(bigint_shared.toString(16), 32, '0');

this.sjcl_keyAES = new sjcl.cipher.aes( sjcl.codec.hex.toBits(str_shared) );
}

/**
* Decrypts a block of encrypted data
* @param data an array of bytes to decrypt
* @return decrypted data
*/
decrypt(data) {
var arr_cipherText = data;
var hex_cipherText = arrayToHex(arr_cipherText);
var sjcl_cipherText = sjcl.codec.hex.toBits(hex_cipherText);

var sjcl_plainText = this.sjcl_keyAES.decrypt(sjcl_cipherText);

var hex_plainText = sjcl.codec.hex.fromBits(sjcl_plainText);
var arr_plainText = hexToArray(hex_plainText);
return arr_plainText;
}

And finally, computeSessionKey and decrypt:

	// replace additional left zeros
const decryptKey = BigInt("0x"+arrayToHex(new Uint8Array(key)));
const hexKey = padLeft(decryptKey.toString(16), 64, '0');

// SubtleCrypto only supports AES-CBC with PKCS#7 padding.
// so we need to use another library as STU devices uses no padding.
this.keyAES = new sjcl.cipher.aes(sjcl.codec.hex.toBits(hexKey));
}

/**
* Decrypts a block of encrypted data
* @param data an array of bytes to decrypt
* @return decrypted data
*/
decrypt(data) {
var hex_cipherText = arrayToHex(data);
var sjcl_cipherText = sjcl.codec.hex.toBits(hex_cipherText);

var sjcl_plainText = this.keyAES.decrypt(sjcl_cipherText);

var hex_plainText = sjcl.codec.hex.fromBits(sjcl_plainText);
var arr_plainText = hexToArray(hex_plainText);

return arr_plainText;
}

Delete the remaining files, stu_capture.js and package.json. From there, add the file sjcl.js, a dependency that's still required for the sample.

This can be downloaded here: https://www.npmjs.com/package/sjcl