1+ < html > < head > < title > OnlyKey Apps - Decrypt & verify files using Onlykey, Keybase PGP, and Virtru</ title > < meta name ="viewport " content ="width=device-width,initial-scale=1 "> < link rel ="stylesheet " href ="css/gallerycss-csstable-min.css "> < link rel ="stylesheet " href ="css/gallerycss-csslist-min.css "> < link rel ="stylesheet " href ="css/gallerycss-cssform-min.css "> < link rel ="stylesheet " href ="css/cssnormalize-min.css "> < link rel ="stylesheet " href ="css/cssgrids-responsive-min.css "> < link rel ="stylesheet " href ="css/cssbutton-min.css "> < link rel ="stylesheet " type ="text/css " href ="css/ui.css "> < link href ="css/ShareTechMono.css " rel ="stylesheet "> < link href ="css/font-awesome.min.css " rel ="stylesheet "> < link href ="css/style.css " rel ="stylesheet "> < link href ="https://sdk.virtru.com/js/latest/auth-widget/index.css " rel ="stylesheet "> < script src ="https://sdk.virtru.com/js/latest/auth-widget/index.js "> </ script > < script src ="https://sdk.virtru.com/js/latest/virtru-sdk.min.js "> </ script > < style > .header {
2+ background : white;
3+ }
4+
5+ .header h1 {
6+ color : rgb (97 , 97 , 97 );
7+ }
8+
9+ .header h2 {
10+ font-weight : 300 ;
11+ margin : 0 ;
12+ color : rgb (137 , 137 , 137 );
13+ }</ style > </ head > < body class ="yui3-skin-sam "> < div id ="headerMenu " class ="yui3-menu yui3-menu-open yui3-menu-horizontal yui3-menu-fixed "> < span class ="yui3-menu-heading "> Apps</ span > < ul > < li > < a href ="https://apps.crp.to/decrypt "> < i class ="fa fa-unlock " aria-hidden ="true "> </ i > </ a > </ li > < li > < a href ="https://apps.crp.to/encrypt "> < i class ="fa fa-lock " aria-hidden ="true "> </ i > </ a > </ li > < li class ="yui3-menu-active "> < a href ="https://apps.crp.to/decrypt-file "> < i class ="fa fa-file-text " aria-hidden ="true "> </ i > </ a > </ li > < li > < a href ="https://apps.crp.to/encrypt-file "> < i class ="fa fa-file-archive-o " aria-hidden ="true "> </ i > </ a > </ li > < li > < a href ="https://apps.crp.to/search "> < i class ="fa fa-search " aria-hidden ="true "> </ i > </ a > </ li > </ ul > < span class ="yui3-menu-heading "> Links</ span > < ul > < li > < a href ="https://apps.crp.to "> < i class ="fa fa-home " aria-hidden ="true "> </ i > </ a > </ li > < li > < a href ="https://docs.crp.to/webcrypt.html "> < i class ="fa fa-question " aria-hidden ="true "> </ i > </ a > </ li > < li > < a href ="https://docs.crp.to/ "> < i class ="fa fa-book " aria-hidden ="true "> </ i > </ a > </ li > < li > < a href ="https://onlykey.io "> < i class ="fa fa-shopping-cart " aria-hidden ="true "> </ i > </ a > </ li > </ ul > </ div > < div class ="header yui3-u-1 "> < p > < img src ="ok-plugged4.png " alt ="logo " align ="middle "> </ p > < h1 > < i class ="fa fa-lock fa-2x " aria-hidden ="true "> </ i > < i class ="fa fa-long-arrow-right fa-2x " aria-hidden ="true "> </ i > < i class ="fa fa-file-text fa-2x " aria-hidden ="true "> </ i > </ h1 > < code data-language ="javascript "> < div id ="header_messages "> </ div > </ code > </ div > < h4 > < font size ="+2 "> Securely decrypt and verify files using < 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 > < div id ="container "> < fieldset > < textarea placeholder ="Sender's Keybase username... " rows ="1 " id ="pgpkeyurl "> </ textarea > < form name ="fileform "> < div id ="block "> < div id ="virtru-auth-widget-mount " align ="left " style ="overflow: hidden; text-overflow: ellipsis; text-align:left; display: -webkit-flex; display: flex; -webkit-flex-wrap: wrap; flex-wrap: wrap; -webkit-align-content: left; align-content: left; "> < label for ="virtru-auth-widget-mount " id ="virtru-auth-widget-mount_label "> Confirm your email below to decrypt TDF</ label > </ div > < h3 > Choose the file to decrypt</ h3 > < input type ="file " id ="file " name ="file "> < br > < p id ="filedetails "> </ p > < p id ="virtrudetails "> </ p > </ div > </ form > < button type ="submit " id ="onlykey_start " value ="Decrypt and Verify "> Decrypt and Verify</ button > </ fieldset > < center > < form name ="action "> < label > < input type ="radio " name ="select_one " id ="decrypt_and_verify " value ="Decrypt and Verify " checked ="checked "> Decrypt and Verify</ label > < label > < input type ="radio " name ="select_one " id ="decrypt_only " value ="Decrypt Only "> Decrypt Only</ label > </ form > </ center > </ div > < div class ="content "> < h3 > Console Messages from OnlyKey Appear Below</ h3 > < pre >
14+ < code data-language ="javascript ">
15+ < font color ="008700 ">
16+ < div id ="messages "> </ div >
17+ </ font >
18+ </ code >
19+ </ pre > </ div > < script > let client ;
20+ // Start with these hidden until the user selects to expire messages
21+ document . getElementById ( 'virtru-auth-widget-mount' ) . style . display = "none" ;
22+ document . getElementById ( 'virtru-auth-widget-mount_label' ) . style . display = "none" ;
23+ file = document . getElementById ( 'file' ) ;
24+
25+ file . addEventListener ( 'change' , e => {
26+ console . info ( document . getElementById ( 'file' ) . value ) ;
27+ if ( document . getElementById ( 'file' ) . value . includes ( '.TDF' ) == true ) {
28+ document . getElementById ( 'virtru-auth-widget-mount' ) . style . display = "initial" ;
29+ document . getElementById ( 'virtru-auth-widget-mount_label' ) . style . display = "initial" ;
30+ } else {
31+ document . getElementById ( 'virtru-auth-widget-mount' ) . style . display = "none" ;
32+ document . getElementById ( 'virtru-auth-widget-mount_label' ) . style . display = "none" ;
33+ }
34+ } ) ;
35+
36+ // Run all client code from here.
37+ // This will only be called when the user is successfully authenticated.
38+ async function afterAuth ( email ) {
39+
40+ //TODO Enable Options fields after auth for user to set encrypted file expiration date etc.
41+ console . info ( 'Virtru email ' + email ) ;
42+ client = new Virtru . Client ( { email} ) ;
43+ console . info ( 'Virtru client ' + client ) ;
44+ }
45+
46+ // Encrypt or decrypt the file by using the support functions
47+ async function encryptOrDecryptFile ( filedata , thisfilename , shouldEncrypt , completion ) {
48+ if ( shouldEncrypt ) {
49+ const encrypted = await encrypt ( filedata , thisfilename ) ;
50+ await encrypted . toFile ( thisfilename + '.tdf' ) ;
51+ } else {
52+ const decrypted = await decrypt ( filedata ) ;
53+ const finalfilename = buildDecryptFilename ( thisfilename ) . trim ( ) ;
54+ await decrypted . toFile ( finalFilename ) ;
55+ }
56+
57+ if ( completion ) {
58+ //completion();
59+ }
60+ }
61+
62+ // Handle filename parsing with parens involved
63+ function buildDecryptFilename ( filename ) {
64+ console . info ( 'buildDecryptFilename' ) ;
65+ console . info ( filename ) ;
66+ const ext = filename . substr ( - 4 ) ;
67+ let finalFilename = filename ;
68+
69+ if ( ext === '.tdf' ) {
70+ finalFilename = finalFilename . replace ( ext , '' ) ;
71+ }
72+
73+ finalFilename = finalFilename . replace ( / \( [ ^ . ] * \) $ / , '' ) ;
74+
75+ return finalFilename ;
76+ }
77+
78+ // Decrypt the file by creating an object url (for now) and return the stream content
79+ async function decrypt ( fileData ) {
80+ console . info ( 'decrypt' ) ;
81+ console . info ( fileData ) ;
82+ const decryptParams = new Virtru . DecryptParamsBuilder ( )
83+ . withArrayBufferSource ( fileData )
84+ . build ( ) ;
85+
86+ const decrypted = await client . decrypt ( decryptParams ) ;
87+ return decrypted ;
88+ }
89+
90+ // Encrypt the filedata and return the stream content and filename
91+ async function encrypt ( fileData , filename ) {
92+ console . info ( 'encrypt' ) ;
93+ console . info ( filename ) ;
94+ console . info ( fileData ) ;
95+
96+ var recipients = document . getElementById ( 'recipient-virtru' ) . value ;
97+
98+ if ( document . getElementById ( 'expire' ) . checked == true ) {
99+ const policy = new Virtru . PolicyBuilder ( )
100+ . enableExpirationDeadlineFromNow ( ( document . getElementById ( 'expire_seconds' ) . value ) * 3600 )
101+ . build ( ) ;
102+ const encryptParams = new Virtru . EncryptParamsBuilder ( )
103+ . withArrayBufferSource ( fileData )
104+ . withPolicy ( policy )
105+ . withUsersWithAccess ( [ recipients ] )
106+ . withDisplayFilename ( filename )
107+ //.withZipFormat() // Generate TDF in zip format
108+ . build ( ) ;
109+ const enc = await client . encrypt ( encryptParams ) ;
110+ console . info ( encryptParams ) ;
111+ return enc ;
112+ } else {
113+ const encryptParams = new Virtru . EncryptParamsBuilder ( )
114+ . withArrayBufferSource ( fileData )
115+ //.withPolicy(policy)
116+ . withUsersWithAccess ( [ recipients ] )
117+ . withDisplayFilename ( filename )
118+ //.withZipFormat() // Generate TDF in zip format
119+ . build ( ) ;
120+ const enc = await client . encrypt ( encryptParams ) ;
121+ console . info ( encryptParams ) ;
122+ return enc ;
123+ }
124+ }
125+
126+ // Set up the auth widget.
127+ Virtru . AuthWidget ( 'virtru-auth-widget-mount' , { afterAuth} ) ; </ script > < script type ="text/javascript " src ="bundle.fb706509706a4f5cd5b0.js?fb706509706a4f5cd5b0 " integrity ="sha256-aEJb2RsGuuly7/Nf3S2OmAsjQ1tEr7ohRjCTca3r1Gs= sha384-wya7N3fb0uJhwuQOsuGLywKxEu5k3oCbduzpVMyGkPzdyoTyejDuI7WlZ5FY8DYK " crossorigin ="anonymous "> </ script > </ body > < script > window . addEventListener ( "load" , window . initok ) ; </ script > </ html >
0 commit comments