[pve-devel] [PATCH widget-toolkit 2/7] add Utils used for u2f and webauthn
Wolfgang Bumiller
w.bumiller at proxmox.com
Tue Nov 9 12:27:16 CET 2021
base64url parts copied from pbs
render_u2f_error copied from pve
Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
src/Utils.js | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/src/Utils.js b/src/Utils.js
index c52bef2..9703bd9 100644
--- a/src/Utils.js
+++ b/src/Utils.js
@@ -1172,6 +1172,51 @@ utilities: {
return Proxmox.Utils.unknownText;
},
+
+ render_u2f_error: function(error) {
+ var ErrorNames = {
+ '1': gettext('Other Error'),
+ '2': gettext('Bad Request'),
+ '3': gettext('Configuration Unsupported'),
+ '4': gettext('Device Ineligible'),
+ '5': gettext('Timeout'),
+ };
+ return "U2F Error: " + ErrorNames[error] || Proxmox.Utils.unknownText;
+ },
+
+ // Convert an ArrayBuffer to a base64url encoded string.
+ // A `null` value will be preserved for convenience.
+ bytes_to_base64url: function(bytes) {
+ if (bytes === null) {
+ return null;
+ }
+
+ return btoa(Array
+ .from(new Uint8Array(bytes))
+ .map(val => String.fromCharCode(val))
+ .join(''),
+ )
+ .replace(/\+/g, '-')
+ .replace(/\//g, '_')
+ .replace(/[=]/g, '');
+ },
+
+ // Convert an a base64url string to an ArrayBuffer.
+ // A `null` value will be preserved for convenience.
+ base64url_to_bytes: function(b64u) {
+ if (b64u === null) {
+ return null;
+ }
+
+ return new Uint8Array(
+ atob(b64u
+ .replace(/-/g, '+')
+ .replace(/_/g, '/'),
+ )
+ .split('')
+ .map(val => val.charCodeAt(0)),
+ );
+ },
},
singleton: true,
--
2.30.2
More information about the pve-devel
mailing list