Merge "Remove TODOs from deprecated "sign-the-hash""
Jenkins authored 7 years ago
Gerrit Code Review committed 7 years ago
85 | 85 | 'img_signature_certificate_uuid' |
86 | 86 | ) |
87 | 87 | |
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 | ||
103 | 88 | |
104 | 89 | class SignatureKeyType(object): |
105 | 90 | |
139 | 124 | |
140 | 125 | |
141 | 126 | # 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): | |
144 | 128 | """Create the verifier to use when the key type is RSA-PSS. |
145 | 129 | |
146 | 130 | :param signature: the decoded signature to use |
147 | 131 | :param hash_method: the hash method to use, as a cryptography object |
148 | 132 | :param public_key: the public key to use, as a cryptography object |
149 | :param image_properties: the key-value properties about the image | |
150 | 133 | :returns: the verifier to use to verify the signature for RSA-PSS |
151 | 134 | :raises glance.common.exception.SignatureVerificationError: if the |
152 | 135 | RSA-PSS specific properties are invalid |
153 | 136 | """ |
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 | |
177 | 142 | |
178 | 143 | # return the verifier |
179 | 144 | return public_key.verifier( |
183 | 148 | ) |
184 | 149 | |
185 | 150 | |
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): | |
188 | 152 | """Create the verifier to use when the key type is ECC_*. |
189 | 153 | |
190 | 154 | :param signature: the decoded signature to use |
191 | 155 | :param hash_method: the hash method to use, as a cryptography object |
192 | 156 | :param public_key: the public key to use, as a cryptography object |
193 | :param image_properties: the key-value properties about the image | |
194 | 157 | :return: the verifier to use to verify the signature for ECC_* |
195 | 158 | """ |
196 | 159 | # return the verifier |
200 | 163 | ) |
201 | 164 | |
202 | 165 | |
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): | |
205 | 167 | """Create verifier to use when the key type is DSA |
206 | 168 | |
207 | 169 | :param signature: the decoded signature to use |
208 | 170 | :param hash_method: the hash method to use, as a cryptography object |
209 | 171 | :param public_key: the public key to use, as a cryptography object |
210 | :param image_properties: the key-value properties about the image | |
211 | 172 | :returns: the verifier to use to verify the signature for DSA |
212 | 173 | """ |
213 | 174 | # return the verifier |
272 | 233 | try: |
273 | 234 | verifier = signature_key_type.create_verifier(signature, |
274 | 235 | hash_method, |
275 | public_key, | |
276 | image_properties) | |
236 | public_key) | |
277 | 237 | except crypto_exception.UnsupportedAlgorithm as e: |
278 | 238 | msg = (_LE("Unable to create verifier since algorithm is " |
279 | 239 | "unsupported: %(e)s") |