SQL store: use authenticated encryption
SQL store: use authenticated encryption

Data were encrypted using AES-CFB, with a properly randomized IV,
but without any authenticators. This allows the data to be tampered
with, without being noticed by the application.

This diff slightly changes the encryption/decryption functions in
sql_store.go to add a HMAC-SHA256 authenticator to encrypted messages.

Two keys are derived from AtRestEncryptKey: the first half of
SHA512(AtRestEncryptKey) for the block cipher and the second half for
the MAC. This can be changed to a KDF if needed.

The decryption function also checks that base64 decoding actually
worked, and that the ciphertext is long enough to include the IV and
the MAC.

Unfortunately, it breaks backward compatibility. But if such a change
has to be made, it has to be made early.

tbolon/platform,lawrenae/mattermost,gluwaile/platform,cadecairos/mattermoz,no2key/platform,florianorben/platform,xogeny/platform,justyns/platform,no2key/platform,mozilla/mattermoz,coraxster/platform,numericube/platform,tbalthazar/platform,jmptrader/platform,stralsi/platform,jdeng/platform,trigrass2/platform,ljshj/platform,stralsi/platform,npcode/platform,folpindo/platform,ninja-/platform,davidkuhta/platform,driou/platform,killix/platform,codevlabs/platform,jdeng/platform,IQ2022/platform,dimitertodorov/platform,coraxster/platform,fosstp/platform,harryross/platform,LawrenceHan/platform,npcode/platform,rompic/platform,baiwyc119/platform,florianorben/platform,narita-takeru/platform,andela/mattermost-platform,npcode/platform,StateFarmIns/mattermost,driou/platform,npcode/platform,nota-ja/platform,xogeny/platform,stralsi/platform,hungle90/platform,cagomezt/platform,Huangyan9188/platform,cadecairos/mattermoz,saitodisse/platform,lawrenae/mattermost,sharp/platform,saitodisse/platform,wavelets/platform,kitgary/platform,StateFarmIns/mattermost,xogeny/platform,gaev2003/platform,ljshj/platform,kitgary/platform,hustlzp/platform,samogot/platform,samogot/platform,gaev2003/platform,jdeng/platform,raghavenc5/TabGen,apaatsio/platform,asaadmahmoodspin/platform,narita-takeru/platform,saitodisse/platform,trashcan/platform,numericube/platform,pokemonmegaman/platform,cyanlime/platform,hustlzp/platform,IQ2022/platform,wavelets/platform,wavelets/platform,FabianFrancoRoldan/platform,42wim/platform,fosstp/platform,dotcominternet/platform,andela/mattermost-platform,killix/platform,apaatsio/platform,Huangyan9188/platform,dotcominternet/platform,baiwyc119/platform,yaoyasong/platform,gluwaile/platform,LAndreas/platform,pokemonmegaman/platform,folpindo/platform,xogeny/platform,coraxster/platform,sjmog/platform,bkeroack/platform,yaoyasong/platform,TSlean/platform,davidkuhta/platform,tbolon/platform,kernicPanel/platform,kernicPanel/platform,justyns/platform,baiwyc119/platform,yaoyasong/platform,kernicPanel/platform,LawrenceHan/platform,cadecairos/mattermoz,rgarmsen2295/platform,sjmog/platform,mozilla/mattermoz,narita-takeru/platform,justyns/platform,jdeng/platform,kitgary/platform,no2key/platform,Huangyan9188/platform,mozilla/mattermoz,cagomezt/platform,LAndreas/platform,coraxster/platform,rgarmsen2295/platform,michaelkacher/platform,LawrenceHan/platform,samogot/platform,LAndreas/platform,bkeroack/platform,trigrass2/platform,tbalthazar/platform,cyanlime/platform,cadecairos/mattermoz,killix/platform,saitodisse/platform,michaelkacher/platform,TSlean/platform,tbalthazar/platform,tbolon/platform,florianorben/platform,oblank/platform,LawrenceHan/platform,rgarmsen2295/platform,nota-ja/platform,killix/platform,apaatsio/platform,hustlzp/platform,cadecairos/mattermoz,trashcan/platform,codevlabs/platform,TSlean/platform,asaadmahmoodspin/platform,rahulltkr/platform,ttyniwa/platform,sjmog/platform,oblank/platform,baiwyc119/platform,harryross/platform,stralsi/platform,pokemonmegaman/platform,tbolon/platform,Huangyan9188/platform,ninja-/platform,TSlean/platform,ttyniwa/platform,harryross/platform,no2key/platform,folpindo/platform,apaatsio/platform,baiwyc119/platform,bartuspan/platform,michaelkacher/platform,rompic/platform,gluwaile/platform,42wim/platform,gaev2003/platform,lawrenae/mattermost,driou/platform,trigrass2/platform,HackerHappyHour/platform,florianorben/platform,cagomezt/platform,hungle90/platform,trigrass2/platform,ZBoxApp/platform,dotcominternet/platform,fosstp/platform,42wim/platform,davidkuhta/platform,bkeroack/platform,andela/mattermost-platform,ttyniwa/platform,ttyniwa/platform,IQ2022/platform,saitodisse/platform,raghavenc5/TabGen,bartuspan/platform,bkeroack/platform,bartuspan/platform,oblank/platform,StateFarmIns/mattermost,sharp/platform,sharp/platform,cagomezt/platform,daizenberg/platform,raghavenc5/TabGen,dimitertodorov/platform,rahulltkr/platform,ljshj/platform,raghavenc5/TabGen,hustlzp/platform,ttyniwa/platform,pokemonmegaman/platform,daizenberg/platform,rgarmsen2295/platform,andela/mattermost-platform,dimitertodorov/platform,jmptrader/platform,gaev2003/platform,TSlean/platform,kernicPanel/platform,bartuspan/platform,yaoyasong/platform,Huangyan9188/platform,rahulltkr/platform,bartuspan/platform,codevlabs/platform,rahulltkr/platform,hustlzp/platform,trashcan/platform,no2key/platform,ninja-/platform,ninja-/platform,jmptrader/platform,rompic/platform,wavelets/platform,FabianFrancoRoldan/platform,kitgary/platform,rgarmsen2295/platform,codevlabs/platform,ZBoxApp/platform,michaelkacher/platform,harryross/platform,LAndreas/platform,gluwaile/platform,LawrenceHan/platform,raghavenc5/TabGen,HackerHappyHour/platform,narita-takeru/platform,cyanlime/platform,narita-takeru/platform,bkeroack/platform,wavelets/platform,ljshj/platform,daizenberg/platform,mozilla/mattermoz,driou/platform,lawrenae/mattermost,sharp/platform,nota-ja/platform,folpindo/platform,codevlabs/platform,StateFarmIns/mattermost,florianorben/platform,pokemonmegaman/platform,HackerHappyHour/platform,yaoyasong/platform,hungle90/platform,stralsi/platform,andela/mattermost-platform,trashcan/platform,fosstp/platform,apaatsio/platform,ZBoxApp/platform,oblank/platform,hungle90/platform,coraxster/platform,davidkuhta/platform,sharp/platform,oblank/platform,StateFarmIns/mattermost,FabianFrancoRoldan/platform,LAndreas/platform,michaelkacher/platform,IQ2022/platform,sjmog/platform,davidkuhta/platform,kitgary/platform,tbolon/platform,lawrenae/mattermost,jmptrader/platform,ninja-/platform,asaadmahmoodspin/platform,nota-ja/platform,trashcan/platform,mozilla/mattermoz,IQ2022/platform,ZBoxApp/platform,gluwaile/platform,numericube/platform,nota-ja/platform,harryross/platform,driou/platform,dotcominternet/platform,jmptrader/platform,ljshj/platform,killix/platform,kernicPanel/platform,xogeny/platform,HackerHappyHour/platform,justyns/platform,gaev2003/platform,sjmog/platform,justyns/platform,cyanlime/platform,npcode/platform,hungle90/platform,ZBoxApp/platform,trigrass2/platform,FabianFrancoRoldan/platform,FabianFrancoRoldan/platform,jdeng/platform,HackerHappyHour/platform,cagomezt/platform,folpindo/platform