has anyone scripted SFTP file transfer with PGP en...
# suitescript
a
has anyone scripted SFTP file transfer with PGP encryption? so far we've run into issues because PGP libraries seem to be all browser-based, but i'm not too familiar with it so maybe we're missing something
s
I haven't run across the need to PGP encrypt in a script. Are you sure you need both SFTP and PGP?
i.e. you're needing to encrypt the plaintext content yourself then send it over an encrypted connectin (SFTP)?
a
yeah, the client is requesting that specifically
r
agreed. it's already encrypted.
i meant to say ssh, which is the protocol sftp uses, stands for secure shell. secure meaning encrypted
a
I understand this is a customer request but still overkilling, sFTP is good enough for data transfers, if they want to have the files encrypted in the FTP side(server) they should probably do that on the fly in the server side(sFTP side).
s
well, using PGP does leave encryption in their control rather than relying on the endpoint to encrypt-in-place
@amy have you tried openpgpjs?
a
I bet there is sFTP servers implementations that uses this and there is easy(enough) ways to implement this in the sFTP side.
s
I would also recommend using it with SuiteScript 2.1 in order to have all the ES2018 goodies available.
a
yeah, from my colleague who was testing, he said he tried OpenPGPJS: *"*couldn’t even load this one in SuiteScript 2.0 – got syntax errors; in 2.1 – got a navigator is not defined (navigator is built into window object)". Also tried KBPGP "loaded in 2.1, successfully generated a KeyManager with a Public Key I’d generated using a website, but when I went to box (encrypt) a string I got setTimeout is not defined – pretty sure that’s another built in function of window." So based on those two errors about setTimeout and navigator is why he was thinking it's browser-based and not working in a server-side script
s
if it were me, I'd push a little harder on OpenPGPjs
perhaps force it to think it's in browser mode
almost all JS libraries expect you to be either in a browser or nodejs compatible environment.... so strong-arming things a bit to make them work in NetSuite is nothing new.
alternately, some folks seem to avoid libraries with SuiteScript altogether, so you could always also try writing a PGP implementation from scratch in SuiteScript.
s
I was looking for PGP encryption and couldn't find any library that is browser independent.
Our final solution was to build robot that will login to NetSuite and go to a Suitelet url which will do the encryption. Then SFTP script will pick up encrypted files and upload.
If you'll find any way that can run on server side script, I will be appreciated.
b
i recommend doing what was suggested before and do the pgp elsewhere like in a client, or a different server
if you must do everything serverside in suitescript, then you can shim all the browser stuff used by openpgp
i've never been able to make the require.js shim configuration work in netsuite, but you can rely on a quirk of netsuite's require.js implementation
the global context is shared between different modules. you can add a global in one module and use it in another
so you can define the browser globals used by openpgp in the module loaded before it
for openpgp, that means creating globals for self, navigator.userAgent, crypo.getRandomValues, atob, and btoa
maybe more