@@ -9,72 +9,7 @@ import {
9
9
} from "@modelcontextprotocol/sdk/shared/auth.js" ;
10
10
import { SESSION_KEYS , getServerSpecificKey } from "./constants" ;
11
11
import { generateOAuthState } from "@/utils/oauthUtils" ;
12
-
13
- // Simple obfuscation using Web Crypto API
14
- const ENCRYPTION_KEY = 'mcp-inspector-oauth-storage-key-v1' ;
15
-
16
- async function deriveKey ( salt : Uint8Array ) : Promise < CryptoKey > {
17
- const encoder = new TextEncoder ( ) ;
18
- const keyMaterial = await crypto . subtle . importKey (
19
- 'raw' ,
20
- encoder . encode ( ENCRYPTION_KEY ) ,
21
- 'PBKDF2' ,
22
- false ,
23
- [ 'deriveKey' ]
24
- ) ;
25
-
26
- return crypto . subtle . deriveKey (
27
- {
28
- name : 'PBKDF2' ,
29
- salt : salt . buffer as ArrayBuffer ,
30
- iterations : 100000 ,
31
- hash : 'SHA-256' ,
32
- } ,
33
- keyMaterial ,
34
- { name : 'AES-GCM' , length : 256 } ,
35
- false ,
36
- [ 'encrypt' , 'decrypt' ]
37
- ) ;
38
- }
39
-
40
- async function encryptData ( data : string ) : Promise < string > {
41
- const encoder = new TextEncoder ( ) ;
42
- const salt = crypto . getRandomValues ( new Uint8Array ( 16 ) ) ;
43
- const iv = crypto . getRandomValues ( new Uint8Array ( 12 ) ) ;
44
- const key = await deriveKey ( salt ) ;
45
-
46
- const encrypted = await crypto . subtle . encrypt (
47
- { name : 'AES-GCM' , iv } ,
48
- key ,
49
- encoder . encode ( data )
50
- ) ;
51
-
52
- // Combine salt + iv + encrypted data
53
- const combined = new Uint8Array ( salt . length + iv . length + encrypted . byteLength ) ;
54
- combined . set ( salt ) ;
55
- combined . set ( iv , salt . length ) ;
56
- combined . set ( new Uint8Array ( encrypted ) , salt . length + iv . length ) ;
57
-
58
- return btoa ( String . fromCharCode ( ...combined ) ) ;
59
- }
60
-
61
- async function decryptData ( encryptedData : string ) : Promise < string > {
62
- const combined = new Uint8Array ( atob ( encryptedData ) . split ( '' ) . map ( c => c . charCodeAt ( 0 ) ) ) ;
63
-
64
- const salt = combined . slice ( 0 , 16 ) ;
65
- const iv = combined . slice ( 16 , 28 ) ;
66
- const data = combined . slice ( 28 ) ;
67
-
68
- const key = await deriveKey ( salt ) ;
69
-
70
- const decrypted = await crypto . subtle . decrypt (
71
- { name : 'AES-GCM' , iv } ,
72
- key ,
73
- data
74
- ) ;
75
-
76
- return new TextDecoder ( ) . decode ( decrypted ) ;
77
- }
12
+ import { encryptData , decryptData } from "./utils" ;
78
13
79
14
export const getClientInformationFromSessionStorage = async ( {
80
15
serverUrl,
0 commit comments