| OLD | NEW |
| 1 # Copyright 2015 The LUCI Authors. All rights reserved. | 1 # Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed by the Apache v2.0 license that can be | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 """Generation of OAuth2 token for a service account. | 5 """Generation of OAuth2 token for a service account. |
| 6 | 6 |
| 7 A fancier version of app_identity.get_access_token(...) that can be used if | 7 A fancier version of app_identity.get_access_token(...) that can be used if |
| 8 app_identity is not appropriate for some reasons. For example, there's no way | 8 app_identity is not appropriate for some reasons. For example, there's no way |
| 9 to invite @appspot.gserviceaccount.com account to some Cloud API projects, | 9 to invite @appspot.gserviceaccount.com account to some Cloud API projects, |
| 10 while it is possible to create @developer.gserviceaccount.com belonging to such | 10 while it is possible to create @developer.gserviceaccount.com belonging to such |
| 11 project. | 11 project. |
| 12 | 12 |
| 13 Supports three ways to generate OAuth2 tokens: | 13 Supports three ways to generate OAuth2 tokens: |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 168 |
| 169 | 169 |
| 170 def _rsa_sign(blob, private_key_pem): | 170 def _rsa_sign(blob, private_key_pem): |
| 171 """Byte blob + PEM key => RSA-SHA256 signature byte blob.""" | 171 """Byte blob + PEM key => RSA-SHA256 signature byte blob.""" |
| 172 # Lazy import crypto. It is not available in unit tests outside of sandbox. | 172 # Lazy import crypto. It is not available in unit tests outside of sandbox. |
| 173 from Crypto.Hash import SHA256 | 173 from Crypto.Hash import SHA256 |
| 174 from Crypto.PublicKey import RSA | 174 from Crypto.PublicKey import RSA |
| 175 from Crypto.Signature import PKCS1_v1_5 | 175 from Crypto.Signature import PKCS1_v1_5 |
| 176 pkey = RSA.importKey(private_key_pem) | 176 pkey = RSA.importKey(private_key_pem) |
| 177 return PKCS1_v1_5.new(pkey).sign(SHA256.new(blob)) | 177 return PKCS1_v1_5.new(pkey).sign(SHA256.new(blob)) |
| OLD | NEW |