keystone  18.0.0
About: OpenStack Keystone (Core Service: Identity) provides an authentication and authorization service for other OpenStack services. Provides a catalog of endpoints for all OpenStack services.
The "Victoria" series (maintained release).
  Fossies Dox: keystone-18.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

jwt_utils.py
Go to the documentation of this file.
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12 
13 from cryptography.hazmat.backends import default_backend
14 from cryptography.hazmat.primitives.asymmetric import ec
15 from cryptography.hazmat.primitives import serialization
16 
17 
18 def create_jws_keypair(private_key_path, public_key_path):
19  """Create an ECDSA key pair using an secp256r1, or NIST P-256, curve.
20 
21  :param private_key_path: location to save the private key
22  :param public_key_path: location to save the public key
23 
24  """
25  private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
26 
27  with open(private_key_path, 'wb') as f:
28  f.write(
29  private_key.private_bytes(
30  encoding=serialization.Encoding.PEM,
31  format=serialization.PrivateFormat.PKCS8,
32  encryption_algorithm=serialization.NoEncryption()
33  )
34  )
35 
36  public_key = private_key.public_key()
37  with open(public_key_path, 'wb') as f:
38  f.write(
39  public_key.public_bytes(
40  encoding=serialization.Encoding.PEM,
41  format=serialization.PublicFormat.SubjectPublicKeyInfo
42  )
43  )
keystone.common.jwt_utils.create_jws_keypair
def create_jws_keypair(private_key_path, public_key_path)
Definition: jwt_utils.py:18