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
- Version 1
- Version 2
/**
* Reset all encryption key values
*/
clearKeys() {
this.bigint_p = null;
this.bigint_g = null;
this.sjcl_keyAES = null;
}
/**
* Reset all encryption key values
*/
clearKeys() {
this.bigint_p = null;
this.bigint_g = null;
this.aesCipher = null;
}
On computeSharedKey
and decrypt
:
- Version 1
- Version 2
/**
* 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;
}
/**
* Calculate a shared key, given the tablet's public key
* @param devicePublicKey the tablet's public key
*/
computeSharedKey(devicePublicKey) {
const B = devicePublicKey;
const bigint_B = BigInt("0x"+arrayToHex(B));
const bigint_shared = powMod(bigint_B, this.bigint_a, this.bigint_p);
const str_shared = padLeft(bigint_shared.toString(16), 32, '0');
const keyAES = AES.Codec.Hex.toBits(str_shared);
// SubtleCrypto does not supports AES-ECB so we need to use a custom code.
this.aesCipher = new AES.ECB(keyAES);
}
/**
* Decrypts a block of encrypted data
* @param data an array of bytes to decrypt
* @return decrypted data
*/
decrypt(data) {
const hexCipherText = arrayToHex(data);
const cipherText = AES.Codec.Hex.toBits(hexCipherText);
const plainText = this.aesCipher.decrypt(cipherText);
const hexPlainText = AES.Codec.Hex.fromBits(plainText);
return hexToArray(hexPlainText);
}
And finally, computeSessionKey
and decrypt
:
- Version 1
- Version 2
// 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;
}
// replace additional left zeros
const decryptKey = BigInt("0x"+arrayToHex(new Uint8Array(key)));
const hexKey = padLeft(decryptKey.toString(16), 64, '0');
const keyAES = AES.Codec.Hex.toBits(hexKey);
// SubtleCrypto does not supports AES-ECB so we need to use a custom code.
this.aesCipher = new AES.ECB(keyAES);
}
/**
* Decrypts a block of encrypted data
* @param data an array of bytes to decrypt
* @return decrypted data
*/
decrypt(data) {
const hexCipherText = arrayToHex(data);
const cipherText = AES.Codec.Hex.toBits(hexCipherText);
const plainText = this.aesCipher.decrypt(cipherText);
const hexPlainText = AES.Codec.Hex.fromBits(plainText);
return hexToArray(hexPlainText);
}
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