diff --git a/docs/reference/client-side-encryption.txt b/docs/reference/client-side-encryption.txt index 8e0ab8f50d..8f93f0d7b6 100644 --- a/docs/reference/client-side-encryption.txt +++ b/docs/reference/client-side-encryption.txt @@ -361,7 +361,7 @@ Queryable Encryption ==================== Queryable encryption is a new feature in MongoDB 6.0. It also requires -libmongocrypt version 1.5.0 or above. +libmongocrypt version 1.5.2 or above. You can find more information about queryable encryption in `MongoDB Manual `_ diff --git a/gemfiles/standard.rb b/gemfiles/standard.rb index 1f07651c30..117366c1b3 100644 --- a/gemfiles/standard.rb +++ b/gemfiles/standard.rb @@ -60,6 +60,6 @@ def standard_dependencies end if ENV['FLE'] == 'helper' - gem 'libmongocrypt-helper', '~> 1.5.0' + gem 'libmongocrypt-helper', '~> 1.5.2' end end diff --git a/lib/mongo/crypt/binding.rb b/lib/mongo/crypt/binding.rb index 778f7b6c47..de0746792b 100644 --- a/lib/mongo/crypt/binding.rb +++ b/lib/mongo/crypt/binding.rb @@ -83,7 +83,7 @@ class Binding # will cause a `LoadError`. # # @api private - MIN_LIBMONGOCRYPT_VERSION = Gem::Version.new("1.5.0.alpha") + MIN_LIBMONGOCRYPT_VERSION = Gem::Version.new("1.5.2") # @!method self.mongocrypt_version(len) # @api private @@ -107,6 +107,24 @@ def self.validate_version(lmc_version) raise LoadError, "libmongocrypt version #{MIN_LIBMONGOCRYPT_VERSION} or above is required, " + "but version #{actual_version} was found." end + rescue ArgumentError => e + # Some lmc versions cannot be parsed with Gem::Version class, + # so we fall back to regex. + match = lmc_version.match(/\A(?\d+)\.(?\d+)\.(?\d+)?(-[A-Za-z\+\d]+)?\z/) + if match.nil? + raise ArgumentError.new("Malformed version number string #{lmc_version}") + end + actual_version = Gem::Version.new( + [ + match[:major], + match[:minor], + match[:patch] + ].join('.') + ) + if actual_version < MIN_LIBMONGOCRYPT_VERSION + raise LoadError, "libmongocrypt version #{MIN_LIBMONGOCRYPT_VERSION} or above is required, " + + "but version #{actual_version} was found." + end end validate_version(mongocrypt_version(nil)) diff --git a/spec/mongo/crypt/binding/version_spec.rb b/spec/mongo/crypt/binding/version_spec.rb index 4b670996a4..ffc0ac0ced 100644 --- a/spec/mongo/crypt/binding/version_spec.rb +++ b/spec/mongo/crypt/binding/version_spec.rb @@ -41,5 +41,13 @@ end.not_to raise_error(LoadError, /libmongocrypt version .* or above is required, but version .* was found./) end end + + context 'when in a non-parsable format' do + it 'does not raise ArgumentError' do + expect do + Mongo::Crypt::Binding.validate_version("1.5.3-dev+20220730git8f8675fa11") + end.not_to raise_error(ArgumentError, /Malformed version number string/) + end + end end end diff --git a/spec/spec_tests/data/client_side_encryption/unified/rewrapManyDataKey.yml b/spec/spec_tests/data/client_side_encryption/unified/rewrapManyDataKey.yml index 28009f5473..5141558683 100644 --- a/spec/spec_tests/data/client_side_encryption/unified/rewrapManyDataKey.yml +++ b/spec/spec_tests/data/client_side_encryption/unified/rewrapManyDataKey.yml @@ -2,7 +2,7 @@ # commands sort the resulting documents in ascending order by the single-element # keyAltNames array to ensure alphabetic order by original KMS provider as # defined in initialData. -description: rewrapManyDataKey-kms_providers +description: rewrapManyDataKey schemaVersion: "1.8" @@ -50,7 +50,7 @@ initialData: region: us-east-1 - _id: &azure_key_id { $binary: { base64: YXp1cmVhenVyZWF6dXJlYQ==, subType: "04" } } keyAltNames: ["azure_key"] - keyMaterial: { $binary: { base64: AQICAHhQNmWG2CzOm1dq3kWLM+iDUZhEqnhJwH9wZVpuZ94A8gEGkNTybTc7Eyif0f+qqE0lAAAAwjCBvwYJKoZIhvcNAQcGoIGxMIGuAgEAMIGoBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDB2j78AeuIQxcRh8cQIBEIB7vj9buHEaT7XHFIsKBJiyzZRmNnjvqMK5LSdzonKdx97jlqauvPvTDXSsdQDcspUs5oLrGmAXpbFResscxmbwZoKgUtWiuIOpeAcYuszCiMKt15s1WIMLDXUhYtfCmhRhekvgHnRAaK4HJMlGE+lKJXYI84E0b86Cd/g+, subType: "00" } } + keyMaterial: { $binary: { base64: pr01l7qDygUkFE/0peFwpnNlv3iIy8zrQK38Q9i12UCN2jwZHDmfyx8wokiIKMb9kAleeY+vnt3Cf1MKu9kcDmI+KxbNDd+V3ytAAGzOVLDJr77CiWjF9f8ntkXRHrAY9WwnVDANYkDwXlyU0Y2GQFTiW65jiQhUtYLYH63Tk48SsJuQvnWw1Q+PzY8ga+QeVec8wbcThwtm+r2IHsCFnc72Gv73qq7weISw+O4mN08z3wOp5FOS2ZM3MK7tBGmPdBcktW7F8ODGsOQ1FU53OrWUnyX2aTi2ftFFFMWVHqQo7EYuBZHru8RRODNKMyQk0BFfKovAeTAVRv9WH9QU7g==, subType: "00" } } creationDate: { $date: { $numberLong: "1641024000000" } } updateDate: { $date: { $numberLong: "1641024000000" } } status: 1 @@ -72,7 +72,7 @@ initialData: keyName: key-name-csfle - _id: &kmip_key_id { $binary: { base64: a21pcGttaXBrbWlwa21pcA==, subType: "04" } } keyAltNames: ["kmip_key"] - keyMaterial: { $binary: { base64: VoI9J8HusQ3u2gT9i8Awgg/6W4/igvLwRzn3SRDGx0Dl/1ayDMubphOw0ONPVKfuvS6HL3e4gAoCJ/uEz2KLFTVsEqYCpMhfAhgXxm8Ena8vDcOkCzFX+euvN/N2ES3wpzAD18b3qIH0MbBwKJP82d5GQ4pVfGnPW8Ujp9aO1qC/s0EqNqYyzJ1SyzhV9lAjHHGIENYJx+bBrekg2EeZBA==, subType: "00" } } + keyMaterial: { $binary: { base64: CklVctHzke4mcytd0TxGqvepkdkQN8NUF4+jV7aZQITAKdz6WjdDpq3lMt9nSzWGG2vAEfvRb3mFEVjV57qqGqxjq2751gmiMRHXz0btStbIK3mQ5xbY9kdye4tsixlCryEwQONr96gwlwKKI9Nubl9/8+uRF6tgYjje7Q7OjauEf1SrJwKcoQ3WwnjZmEqAug0kImCpJ/irhdqPzivRiA==, subType: "00" } } creationDate: { $date: { $numberLong: "1641024000000" } } updateDate: { $date: { $numberLong: "1641024000000" } } status: 1