lib/epics/client.rb in epics-1.8.1 vs lib/epics/client.rb in epics-2.0.0
- old
+ new
@@ -141,14 +141,10 @@
def XDS(document)
upload(Epics::XDS, document)
end
- def CDZ(document)
- upload(Epics::CDZ, document)
- end
-
def CCT(document)
upload(Epics::CCT, document)
end
def CCS(document)
@@ -165,10 +161,18 @@
def VMK(from = nil, to = nil)
download(Epics::VMK, from, to)
end
+ def CDZ(from = nil, to = nil)
+ download_and_unzip(Epics::CDZ, from, to)
+ end
+
+ def CRZ(from = nil, to = nil)
+ download_and_unzip(Epics::CRZ, from, to)
+ end
+
def C52(from, to)
download_and_unzip(Epics::C52, from, to)
end
def C53(from, to)
@@ -263,32 +267,36 @@
def dump_keys
JSON.dump(keys.each_with_object({}) {|(k,v),m| m[k]= encrypt(v.key.to_pem)})
end
- def cipher
- @cipher ||= OpenSSL::Cipher.new("aes-256-cbc")
+ def new_cipher
+ # Re-using the cipher between keys has weird behaviours with openssl3
+ # Using a fresh key instead of memoizing it on the client simplifies things
+ OpenSSL::Cipher.new('aes-256-cbc')
end
def encrypt(data)
salt = OpenSSL::Random.random_bytes(8)
- setup_cipher(:encrypt, self.passphrase, salt)
+ cipher = setup_cipher(:encrypt, self.passphrase, salt)
Base64.strict_encode64([salt, cipher.update(data) + cipher.final].join)
end
def decrypt(data)
data = Base64.strict_decode64(data)
salt = data[0..7]
data = data[8..-1]
- setup_cipher(:decrypt, self.passphrase, salt)
+ cipher = setup_cipher(:decrypt, self.passphrase, salt)
cipher.update(data) + cipher.final
end
def setup_cipher(method, passphrase, salt)
+ cipher = new_cipher
cipher.send(method)
cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(passphrase, salt, 1, cipher.key_len)
+ cipher
end
def verify_ssl?
ENV['EPICS_VERIFY_SSL'] != 'false'
end