Codebase list glance / 9d7efa9
Merge "Remove TODOs from deprecated "sign-the-hash"" Jenkins authored 7 years ago Gerrit Code Review committed 7 years ago
2 changed file(s) with 9 addition(s) and 55 deletion(s). Raw diff Collapse all Expand all
8585 'img_signature_certificate_uuid'
8686 )
8787
88 # TODO(bpoulos): remove when 'sign-the-hash' approach is no longer supported
89 (OLD_SIGNATURE, OLD_HASH_METHOD, OLD_KEY_TYPE, OLD_CERT_UUID) = (
90 'signature',
91 'signature_hash_method',
92 'signature_key_type',
93 'signature_certificate_uuid'
94 )
95
96 # Optional image property names for RSA-PSS
97 # TODO(bpoulos): remove when 'sign-the-hash' approach is no longer supported
98 (MASK_GEN_ALG, PSS_SALT_LENGTH) = (
99 'mask_gen_algorithm',
100 'pss_salt_length'
101 )
102
10388
10489 class SignatureKeyType(object):
10590
139124
140125
141126 # each key type will require its own verifier
142 def create_verifier_for_pss(signature, hash_method, public_key,
143 image_properties):
127 def create_verifier_for_pss(signature, hash_method, public_key):
144128 """Create the verifier to use when the key type is RSA-PSS.
145129
146130 :param signature: the decoded signature to use
147131 :param hash_method: the hash method to use, as a cryptography object
148132 :param public_key: the public key to use, as a cryptography object
149 :param image_properties: the key-value properties about the image
150133 :returns: the verifier to use to verify the signature for RSA-PSS
151134 :raises glance.common.exception.SignatureVerificationError: if the
152135 RSA-PSS specific properties are invalid
153136 """
154 # retrieve other needed properties, or use defaults if not there
155 if MASK_GEN_ALG in image_properties:
156 mask_gen_algorithm = image_properties[MASK_GEN_ALG]
157 if mask_gen_algorithm not in MASK_GEN_ALGORITHMS:
158 raise exception.SignatureVerificationError(
159 _('Invalid mask_gen_algorithm: %s') % mask_gen_algorithm
160 )
161 mgf = MASK_GEN_ALGORITHMS[mask_gen_algorithm](hash_method)
162 else:
163 # default to MGF1
164 mgf = padding.MGF1(hash_method)
165
166 if PSS_SALT_LENGTH in image_properties:
167 pss_salt_length = image_properties[PSS_SALT_LENGTH]
168 try:
169 salt_length = int(pss_salt_length)
170 except ValueError:
171 raise exception.SignatureVerificationError(
172 _('Invalid pss_salt_length: %s') % pss_salt_length
173 )
174 else:
175 # default to max salt length
176 salt_length = padding.PSS.MAX_LENGTH
137 # default to MGF1
138 mgf = padding.MGF1(hash_method)
139
140 # default to max salt length
141 salt_length = padding.PSS.MAX_LENGTH
177142
178143 # return the verifier
179144 return public_key.verifier(
183148 )
184149
185150
186 def create_verifier_for_ecc(signature, hash_method, public_key,
187 image_properties):
151 def create_verifier_for_ecc(signature, hash_method, public_key):
188152 """Create the verifier to use when the key type is ECC_*.
189153
190154 :param signature: the decoded signature to use
191155 :param hash_method: the hash method to use, as a cryptography object
192156 :param public_key: the public key to use, as a cryptography object
193 :param image_properties: the key-value properties about the image
194157 :return: the verifier to use to verify the signature for ECC_*
195158 """
196159 # return the verifier
200163 )
201164
202165
203 def create_verifier_for_dsa(signature, hash_method, public_key,
204 image_properties):
166 def create_verifier_for_dsa(signature, hash_method, public_key):
205167 """Create verifier to use when the key type is DSA
206168
207169 :param signature: the decoded signature to use
208170 :param hash_method: the hash method to use, as a cryptography object
209171 :param public_key: the public key to use, as a cryptography object
210 :param image_properties: the key-value properties about the image
211172 :returns: the verifier to use to verify the signature for DSA
212173 """
213174 # return the verifier
272233 try:
273234 verifier = signature_key_type.create_verifier(signature,
274235 hash_method,
275 public_key,
276 image_properties)
236 public_key)
277237 except crypto_exception.UnsupportedAlgorithm as e:
278238 msg = (_LE("Unable to create verifier since algorithm is "
279239 "unsupported: %(e)s")
4646 signature_utils.HASH_METHOD,
4747 signature_utils.KEY_TYPE,
4848 signature_utils.CERT_UUID
49 )
50
51 # Optional image property names for RSA-PSS
52 (MASK_GEN_ALG, PSS_SALT_LENGTH) = (
53 signature_utils.MASK_GEN_ALG,
54 signature_utils.PSS_SALT_LENGTH
5549 )
5650
5751