@@ -14,18 +14,47 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- const { app} = require ( 'electron' ) ;
17+ const { app} = require ( "electron" ) ;
18+ const crypto = require ( "crypto" ) ;
1819
1920const PROTOCOL = "riot://" ;
20- const SEARCH_PARAM = "riot-desktop-user-data-path " ;
21+ const SEARCH_PARAM = "riot-desktop-args " ;
2122
2223const processUrl = ( url ) => {
2324 if ( ! global . mainWindow ) return ;
2425 console . log ( "Handling link: " , url ) ;
2526 global . mainWindow . loadURL ( url . replace ( PROTOCOL , "vector://" ) ) ;
2627} ;
2728
29+ const algorithm = "aes-192-cbc" ;
30+
31+ const getKeyIv = ( ) => ( {
32+ key : crypto . scryptSync ( app . getPath ( "exe" ) , "salt" , 24 ) ,
33+ iv : Buffer . alloc ( 16 , 0 ) ,
34+ } ) ;
35+
36+ const encrypt = ( plaintext ) => {
37+ const { key, iv} = getKeyIv ( ) ;
38+ const cipher = crypto . createCipheriv ( algorithm , key , iv ) ;
39+ let ciphertext = cipher . update ( plaintext , "utf8" , "hex" ) ;
40+ ciphertext += cipher . final ( "hex" ) ;
41+ return ciphertext ;
42+ } ;
43+
44+ const decrypt = ( ciphertext ) => {
45+ const { key, iv} = getKeyIv ( ) ;
46+ const decipher = crypto . createDecipheriv ( algorithm , key , iv ) ;
47+ let plaintext = decipher . update ( ciphertext , "hex" , "utf8" ) ;
48+ plaintext += decipher . final ( "utf8" ) ;
49+ return plaintext ;
50+ } ;
51+
2852module . exports = {
53+ getArgs : ( argv ) => {
54+ if ( argv [ 'profile-dir' ] || argv [ 'profile' ] ) {
55+ return encrypt ( app . getPath ( 'userData' ) ) ;
56+ }
57+ } ,
2958 getProfileFromDeeplink : ( args ) => {
3059 // check if we are passed a profile in the SSO callback url
3160 const deeplinkUrl = args . find ( arg => arg . startsWith ( 'riot://' ) ) ;
@@ -34,7 +63,7 @@ module.exports = {
3463 if ( parsedUrl . protocol === 'riot:' ) {
3564 const profile = parsedUrl . searchParams . get ( SEARCH_PARAM ) ;
3665 console . log ( "Forwarding to profile: " , profile ) ;
37- return profile ;
66+ return decrypt ( profile ) ;
3867 }
3968 }
4069 } ,
0 commit comments