-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Sodium for secret encryption and decryption
Fixes an openSSL warning: ``` openssl aes-256-cbc -md sha256 -d -in .circleci/.firebase.secrets.json.enc -out .circleci/.firebase.secrets.json -k “${FIREBASE_SECRETS_ENCRYPTION_KEY}” *** WARNING : deprecated key derivation used. Using -iter or -pbkdf2 would be better. ``` Also gets us out of manual crypto. This is a breaking change and should be carefully merged to avoid breaking projects.
- Loading branch information
Showing
4 changed files
with
22 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 5 additions & 33 deletions
38
lib/fastlane/plugin/wpmreleasetoolkit/helper/encryption_helper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,17 @@ | ||
require 'spec_helper.rb' | ||
require 'securerandom' | ||
|
||
describe Fastlane::Helper::EncryptionHelper do | ||
let(:cipher) { double('cipher') } | ||
|
||
before(:each) do | ||
allow(OpenSSL::Cipher::AES256).to receive(:new).with(:CBC).and_return(cipher) | ||
it 'can encrypt and decrypt data' do | ||
string = SecureRandom.hex | ||
key = Fastlane::Helper::EncryptionHelper.generate_key | ||
encrypted = Fastlane::Helper::EncryptionHelper.encrypt(string, key) | ||
decrypted = Fastlane::Helper::EncryptionHelper.decrypt(encrypted, key) | ||
expect(string).to eq decrypted | ||
end | ||
|
||
it 'encrypts the input' do | ||
expect(cipher).to receive(:encrypt) | ||
expect(cipher).to receive(:key=).with('key') | ||
|
||
expect(cipher).to receive(:update).with('plain text').and_return('encrypted') | ||
expect(cipher).to receive(:final).and_return('!') | ||
|
||
expect(Fastlane::Helper::EncryptionHelper.encrypt('plain text', 'key')).to eq('encrypted!') | ||
end | ||
|
||
it 'decrypts the input' do | ||
expect(cipher).to receive(:decrypt) | ||
expect(cipher).to receive(:key=).with('key') | ||
|
||
expect(cipher).to receive(:update).with('encrypted').and_return('plain text') | ||
expect(cipher).to receive(:final).and_return('!') | ||
|
||
expect(Fastlane::Helper::EncryptionHelper.decrypt('encrypted', 'key')).to eq('plain text!') | ||
end | ||
|
||
it 'generates a random key' do | ||
expect(cipher).to receive(:encrypt) | ||
expect(cipher).to receive(:random_key).and_return('random key') | ||
|
||
expect(Fastlane::Helper::EncryptionHelper.generate_key).to eq('random key') | ||
it 'generates a random key that is 32 bytes long' do | ||
expect(Fastlane::Helper::EncryptionHelper.generate_key.length).to eq(32) | ||
end | ||
end |