33< head >
44 < title > OnlyKey Apps - Encrypt & sign files using Keybase PGP and Virtru</ title >
55 < meta name ="viewport " content ="width=device-width,initial-scale=1 ">
6- < META HTTP-EQUIV ='Content-Security-Policy ' CONTENT ="default-src 'none' ; script-src 'self' 'sha256-P1WP1KTz9iiHN5Bfeec+pIgBDay5qWNQZh9HujWa94o=' 'sha256-pBDNHyFUtn3XsRvFveaLkaEupq1l96neUvZm5/c1PmQ='; style-src 'self' 'sha256-ujVZuuvwuQ+epdwqO8AhlbOQSx68+ci+dDIwrFrzI+Q=' 'sha256-zsMKYSOY0gzTtULlMRDwkny+ocnOJuA+B49b0BIIQXU='; img-src 'self' ; font-src 'self' ; connect-src 'self' https://keybase.io ; connect-src 'self' https://sdk.virtru.com ; base-uri 'none'; form-action 'none'; ">
76 < link href ="https://sdk.virtru.com/js/latest/auth-widget/index.css " rel ="stylesheet "/>
87 < script src ="https://sdk.virtru.com/js/latest/auth-widget/index.js "> </ script >
98 < script src ="https://sdk.virtru.com/js/latest/virtru-sdk.min.js "> </ script >
@@ -105,9 +104,12 @@ <h1>
105104 </ code >
106105 </ div >
107106 < h4 > < font size ="+2 "> Securely encrypt and sign files using
108- < a href ="https://onlykey.io " target ="_blank "> OnlyKey</ a > and < a href ="https://keybase.io/kbpgp " target ="_blank "> Keybase PGP</ a > </ font > </ h4 >
107+ < a href ="https://onlykey.io " target ="_blank "> OnlyKey</ a > , < a href ="https://keybase.io/kbpgp " target ="_blank "> Keybase PGP</ a > , and < a href ="https://keybase.io/kbpgp " target ="_blank "> Virtru</ a > </ font > </ h4 >
108+
109109 < div id ="container ">
110+ < div id ="virtru-auth-widget-mount "> </ div >
110111 < fieldset >
112+ < textarea placeholder ="Email to send to... " rows ="1 " id ="recipient-virtru "> </ textarea >
111113 < textarea placeholder ="Your Keybase username or URL to your public pgp key or paste your key... " rows ="1 " id ="pgpkeyurl2 "> </ textarea >
112114 < textarea placeholder ="Recipient's Keybase username or URL to their public PGP key or paste their key... " rows ="1 " id ="pgpkeyurl "> </ textarea >
113115 < textarea placeholder ="Enter a name to use for your encrypted files (optional)... " rows ="1 " id ="filename "> </ textarea >
@@ -139,29 +141,40 @@ <h3>Console Messages from OnlyKey Appear Below</h3>
139141 </ code >
140142 </ pre >
141143 </ div >
142- < div id ="virtru-auth-widget-mount "> </ div >
143144< script >
144145
145- let sender_email ;
146+ let client ;
146147
148+ // Run all client code from here.
149+ // This will only be called when the user is successfully authenticated.
147150 async function afterAuth ( email ) {
148- // Run all client code from here.
149- // This will only be called when the user is successfully authenticated.
150- // sender_email = email;
151- // window.initok();
152- const client = new Virtru . Client ( { email} ) ;
153- const encryptParams = new Virtru . EncryptParamsBuilder ( )
154- . withStringSource ( 'Sokath, his eyes open!' )
155- . withDisplayFilename ( 'darmok.txt' )
156- . build ( ) ;
157- ct = await client . encrypt ( encryptParams ) ;
158- await ct . toFile ( 'encrypted.html' ) ;
151+
152+ //TODO Enable Options fields after auth for user to set encrypted file expiration date etc.
153+ console . info ( 'Virtru email ' + email ) ;
154+ client = new Virtru . Client ( { email} ) ;
155+ console . info ( 'Virtru client ' + client ) ;
156+ }
157+
158+ // Encrypt or decrypt the file by using the support functions
159+ async function encryptOrDecryptFile ( filedata , thisfilename , shouldEncrypt , completion ) {
160+ if ( shouldEncrypt ) {
161+ const encrypted = await encrypt ( filedata , thisfilename ) ;
162+ await encrypted . toFile ( thisfilename + '.tdf' ) ;
163+ } else {
164+ const decrypted = await decrypt ( filedata ) ;
165+ const finalfilename = buildDecryptFilename ( thisfilename ) . trim ( ) ;
166+ await decrypted . toFile ( finalFilename ) ;
167+ }
168+
169+ if ( completion ) {
170+ //completion();
171+ }
159172 }
160- // Set up the auth widget.
161- Virtru . AuthWidget ( 'virtru-auth-widget-mount' , { afterAuth} ) ;
162173
163174 // Handle filename parsing with parens involved
164175 function buildDecryptFilename ( filename ) {
176+ console . info ( 'buildDecryptFilename' ) ;
177+ console . info ( filename ) ;
165178 const ext = filename . substr ( - 4 ) ;
166179 let finalFilename = filename ;
167180
@@ -176,7 +189,8 @@ <h3>Console Messages from OnlyKey Appear Below</h3>
176189
177190 // Decrypt the file by creating an object url (for now) and return the stream content
178191 async function decrypt ( fileData ) {
179- const client = new Virtru . Client ( sender_email ) ;
192+ console . info ( 'decrypt' ) ;
193+ console . info ( fileData ) ;
180194 const decryptParams = new Virtru . DecryptParamsBuilder ( )
181195 . withArrayBufferSource ( fileData )
182196 . build ( ) ;
@@ -187,19 +201,35 @@ <h3>Console Messages from OnlyKey Appear Below</h3>
187201
188202 // Encrypt the filedata and return the stream content and filename
189203 async function encrypt ( fileData , filename ) {
190- const client = new Virtru . Client ( sender_email ) ;
204+ console . info ( 'encrypt' ) ;
205+ console . info ( filename ) ;
206+ console . info ( fileData ) ;
207+
208+ //const encryptParams = new Virtru.EncryptParamsBuilder()
209+ // .withStringSource('Sokath, his eyes open!')
210+ // .withDisplayFilename('darmok.txt')
211+ // .build();
212+ //console.info(encryptParams);
213+ //ct = await client.encrypt(encryptParams);
214+ //await ct.toFile('encrypted.html');
191215
192216 //const policy = new Virtru.PolicyBuilder().build();
217+ var recipients = document . getElementById ( 'recipient-virtru' ) . value ;
193218
194219 const encryptParams = new Virtru . EncryptParamsBuilder ( )
195220 . withArrayBufferSource ( fileData )
196221 //.withPolicy(policy)
197- //.withDisplayFilename(filename)
222+ . addUsersWithAccess ( [ recipients ] )
223+ . withDisplayFilename ( filename )
198224 . build ( ) ;
199-
225+ console . info ( encryptParams ) ;
200226 const enc = await client . encrypt ( encryptParams ) ;
227+ console . info ( enc ) ;
201228 return enc ;
202229 }
230+
231+ // Set up the auth widget.
232+ Virtru . AuthWidget ( 'virtru-auth-widget-mount' , { afterAuth} ) ;
203233</ script >
204- < script type ="text/javascript " src ="bundle.1a74f91abca795b5ab22 .js "> </ script > </ body >
234+ < script type ="text/javascript " src ="bundle.859948db7d9b715a9705 .js "> </ script > </ body >
205235</ html >
0 commit comments