-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-fido2.js
More file actions
79 lines (66 loc) · 2.36 KB
/
Copy pathtest-fido2.js
File metadata and controls
79 lines (66 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env node
/**
* Test script for FIDO2 provider
*
* This script tests:
* 1. Encrypting a test string with FIDO2/Yubikey
* 2. Decrypting it back
* 3. Verifying the result matches the original
*
* Requirements:
* - A FIDO2-compatible device (Yubikey, etc.)
* - The device must be plugged in
* - A web browser for WebAuthn authentication
*/
import { FIDO2Provider, isFIDO2Available } from './dist/index.js';
async function testFIDO2() {
console.log('=== FIDO2/Yubikey Provider Test ===\n');
// Check availability
console.log(`FIDO2 Available: ${isFIDO2Available()}\n`);
if (!isFIDO2Available()) {
console.log('❌ FIDO2 provider is not available');
process.exit(1);
}
try {
// Create provider
console.log('Creating FIDO2 provider...');
const provider = new FIDO2Provider();
console.log(`✅ Provider created: ${provider.name}`);
console.log(` Requires interaction: ${provider.requiresInteraction}\n`);
// Test string
const testString = 'dotenvx_private_key_1234567890abcdef';
console.log(`Original string: ${testString}\n`);
// Encrypt
console.log('Encrypting with FIDO2...');
console.log('A browser window will open. Please follow the instructions.\n');
const encrypted = await provider.encrypt(testString);
console.log(`✅ Encrypted: ${encrypted.substring(0, 100)}...\n`);
// Wait a moment
console.log('Waiting 2 seconds before decryption...\n');
await new Promise(resolve => setTimeout(resolve, 2000));
// Decrypt
console.log('Decrypting with FIDO2...');
console.log('A browser window will open. Please touch your Yubikey when prompted.\n');
const decrypted = await provider.decrypt(encrypted);
console.log(`✅ Decrypted: ${decrypted}\n`);
// Verify
if (decrypted === testString) {
console.log('✅ Success! Decrypted string matches original');
console.log('\n=== Test Complete ===');
process.exit(0);
} else {
console.log('❌ Error: Decrypted string does not match original');
console.log(` Expected: ${testString}`);
console.log(` Got: ${decrypted}`);
process.exit(1);
}
} catch (error) {
console.error('❌ Error:', error.message);
if (error.stack) {
console.error('\nStack trace:');
console.error(error.stack);
}
process.exit(1);
}
}
testFIDO2();