Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
ffdacc91
Commit
ffdacc91
authored
Apr 15, 2016
by
Bill DeRusha
Committed by
Peter Fogg
May 02, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use asymmetric key for signing JWTs
parent
f3b33ef1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
118 additions
and
0 deletions
+118
-0
lms/envs/aws.py
+2
-0
lms/envs/common.py
+4
-0
lms/envs/devstack.py
+41
-0
openedx/core/lib/rsa_key_utils.py
+21
-0
openedx/core/lib/token_utils.py
+49
-0
requirements/edx/base.txt
+1
-0
No files found.
lms/envs/aws.py
View file @
ffdacc91
...
@@ -769,6 +769,8 @@ CREDIT_HELP_LINK_URL = ENV_TOKENS.get('CREDIT_HELP_LINK_URL', CREDIT_HELP_LINK_U
...
@@ -769,6 +769,8 @@ CREDIT_HELP_LINK_URL = ENV_TOKENS.get('CREDIT_HELP_LINK_URL', CREDIT_HELP_LINK_U
JWT_ISSUER
=
ENV_TOKENS
.
get
(
'JWT_ISSUER'
,
JWT_ISSUER
)
JWT_ISSUER
=
ENV_TOKENS
.
get
(
'JWT_ISSUER'
,
JWT_ISSUER
)
JWT_EXPIRATION
=
ENV_TOKENS
.
get
(
'JWT_EXPIRATION'
,
JWT_EXPIRATION
)
JWT_EXPIRATION
=
ENV_TOKENS
.
get
(
'JWT_EXPIRATION'
,
JWT_EXPIRATION
)
JWT_AUTH
.
update
(
ENV_TOKENS
.
get
(
'JWT_AUTH'
,
{}))
JWT_AUTH
.
update
(
ENV_TOKENS
.
get
(
'JWT_AUTH'
,
{}))
PUBLIC_RSA_KEY
=
ENV_TOKENS
.
get
(
'PUBLIC_RSA_KEY'
,
PUBLIC_RSA_KEY
)
PRIVATE_RSA_KEY
=
ENV_TOKENS
.
get
(
'PRIVATE_RSA_KEY'
,
PRIVATE_RSA_KEY
)
################# PROCTORING CONFIGURATION ##################
################# PROCTORING CONFIGURATION ##################
...
...
lms/envs/common.py
View file @
ffdacc91
...
@@ -2784,6 +2784,10 @@ LTI_AGGREGATE_SCORE_PASSBACK_DELAY = 15 * 60
...
@@ -2784,6 +2784,10 @@ LTI_AGGREGATE_SCORE_PASSBACK_DELAY = 15 * 60
JWT_EXPIRATION
=
30
JWT_EXPIRATION
=
30
JWT_ISSUER
=
None
JWT_ISSUER
=
None
# For help generating a key pair import and run `openedx.core.lib.rsa_key_utils.generate_rsa_key_pair()`
PUBLIC_RSA_KEY
=
None
PRIVATE_RSA_KEY
=
None
# Credit notifications settings
# Credit notifications settings
NOTIFICATION_EMAIL_CSS
=
"templates/credit_notifications/credit_notification.css"
NOTIFICATION_EMAIL_CSS
=
"templates/credit_notifications/credit_notification.css"
NOTIFICATION_EMAIL_EDX_LOGO
=
"templates/credit_notifications/edx-logo-header.png"
NOTIFICATION_EMAIL_EDX_LOGO
=
"templates/credit_notifications/edx-logo-header.png"
...
...
lms/envs/devstack.py
View file @
ffdacc91
...
@@ -225,6 +225,47 @@ CORS_ORIGIN_WHITELIST = ()
...
@@ -225,6 +225,47 @@ CORS_ORIGIN_WHITELIST = ()
CORS_ORIGIN_ALLOW_ALL
=
True
CORS_ORIGIN_ALLOW_ALL
=
True
# JWT settings for devstack
# JWT settings for devstack
PUBLIC_RSA_KEY
=
"""
\
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApCujf5oZBGK4MafMRGY9
+zdRRI9YDm1r+81coDCysSrw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_KEY'
:
'lms-secret'
,
'JWT_SECRET_KEY'
:
'lms-secret'
,
...
...
openedx/core/lib/rsa_key_utils.py
0 → 100644
View file @
ffdacc91
""" Utils for RSA keys"""
from
cryptography.hazmat.backends
import
default_backend
from
cryptography.hazmat.primitives.asymmetric
import
rsa
from
cryptography.hazmat.primitives.serialization
import
(
Encoding
,
PublicFormat
,
PrivateFormat
,
NoEncryption
)
def
generate_rsa_key_pair
(
key_size
=
2048
):
""" Generates a public and private RSA PEM encoded key pair"""
private_key
=
rsa
.
generate_private_key
(
public_exponent
=
65537
,
key_size
=
key_size
,
backend
=
default_backend
()
)
private_key_str
=
private_key
.
private_bytes
(
Encoding
.
PEM
,
PrivateFormat
.
PKCS8
,
NoEncryption
())
public_key_str
=
private_key
.
public_key
()
.
public_bytes
(
Encoding
.
PEM
,
PublicFormat
.
SubjectPublicKeyInfo
)
# Not intented for programmatic use, so we print the keys out
print
public_key_str
print
private_key_str
openedx/core/lib/token_utils.py
View file @
ffdacc91
"""Utilities for working with ID tokens."""
"""Utilities for working with ID tokens."""
import
datetime
import
datetime
from
cryptography.hazmat.backends
import
default_backend
from
cryptography.hazmat.primitives.serialization
import
load_pem_private_key
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.exceptions
import
ImproperlyConfigured
from
django.core.exceptions
import
ImproperlyConfigured
import
jwt
import
jwt
...
@@ -63,3 +65,50 @@ def get_id_token(user, client_name):
...
@@ -63,3 +65,50 @@ def get_id_token(user, client_name):
}
}
return
jwt
.
encode
(
payload
,
client
.
client_secret
)
return
jwt
.
encode
(
payload
,
client
.
client_secret
)
def
get_asymmetric_token
(
user
):
"""Construct a JWT signed with this app's private key.
The JWT includes the following claims:
preferred_username (str): The user's username. The claim name is borrowed from edx-oauth2-provider.
name (str): The user's full name.
email (str): The user's email address.
administrator (Boolean): Whether the user has staff permissions.
iss (str): Registered claim. Identifies the principal that issued the JWT.
exp (int): Registered claim. Identifies the expiration time on or after which
the JWT must NOT be accepted for processing.
iat (int): Registered claim. Identifies the time at which the JWT was issued.
sub (int): Registered claim. Identifies the user. This implementation uses the raw user id.
Arguments:
user (User): User for which to generate the JWT.
Returns:
str: the JWT
"""
private_key
=
load_pem_private_key
(
settings
.
PRIVATE_RSA_KEY
,
None
,
default_backend
())
try
:
# Service users may not have user profiles.
full_name
=
UserProfile
.
objects
.
get
(
user
=
user
)
.
name
except
UserProfile
.
DoesNotExist
:
full_name
=
None
now
=
datetime
.
datetime
.
utcnow
()
expires_in
=
getattr
(
settings
,
'OAUTH_ID_TOKEN_EXPIRATION'
,
30
)
payload
=
{
'preferred_username'
:
user
.
username
,
'name'
:
full_name
,
'email'
:
user
.
email
,
'administrator'
:
user
.
is_staff
,
'iss'
:
settings
.
OAUTH_OIDC_ISSUER
,
'exp'
:
now
+
datetime
.
timedelta
(
seconds
=
expires_in
),
'iat'
:
now
,
'sub'
:
anonymous_id_for_user
(
user
,
None
),
}
return
jwt
.
encode
(
payload
,
private_key
,
algorithm
=
'RS512'
)
requirements/edx/base.txt
View file @
ffdacc91
...
@@ -10,6 +10,7 @@ bleach==1.4
...
@@ -10,6 +10,7 @@ bleach==1.4
html5lib==0.999
html5lib==0.999
boto==2.39.0
boto==2.39.0
celery==3.1.18
celery==3.1.18
cryptography==1.3.1
cssselect==0.9.1
cssselect==0.9.1
dealer==2.0.4
dealer==2.0.4
defusedxml==0.4.1
defusedxml==0.4.1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment