Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
Removed JWK/E/S stuff since that is handled by another module.
Browse files Browse the repository at this point in the history
  • Loading branch information
Roland Hedberg committed Jan 1, 2013
1 parent f8667e2 commit 6c4a778
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 92 deletions.
47 changes: 9 additions & 38 deletions src/oic/oic/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ def srvdir_deser(val, format="urlencoded"):
format = "json"
return SWDServiceRedirect().deserialize(val, format)

def keyobj_list_deser(val_list, format="urlencoded"):
return [JWKKeyObject().deserialize(val, format) for val in val_list]

def msg_ser(inst, format, lev=0):
if format in ["urlencoded", "json"]:
if isinstance(inst, dict) or isinstance(inst, Message):
Expand Down Expand Up @@ -132,8 +129,6 @@ def claims_ser(val, format="urlencoded", lev=0):
SINGLE_OPTIONAL_USERINFO_CLAIM = (Message, False, msg_ser, userinfo_deser)
SINGLE_OPTIONAL_ID_TOKEN_CLAIM = (Message, False, msg_ser, idtokenclaim_deser)

REQUIRED_LIST_OF_KEYOBJECTS = ([Message], True, msg_list_ser,
keyobj_list_deser)
SINGLE_OPTIONAL_SERVICE_REDIRECT = (Message, True, msg_ser, srvdir_deser)
SINGLE_OPTIONAL_JWT = (basestring, False, msg_ser, None)
SINGLE_OPTIONAL_IDTOKEN = (basestring, False, msg_ser, None)
Expand Down Expand Up @@ -345,7 +340,7 @@ class AddressClaim(Message):

class OpenIDSchema(Message):
c_param= {
"user_id": SINGLE_OPTIONAL_STRING,
"sub": SINGLE_OPTIONAL_STRING,
"name": SINGLE_OPTIONAL_STRING,
"given_name": SINGLE_OPTIONAL_STRING,
"family_name": SINGLE_OPTIONAL_STRING,
Expand Down Expand Up @@ -384,7 +379,7 @@ class RegistrationRequest(Message):
"x509_url": SINGLE_OPTIONAL_STRING,
"x509_encryption_url": SINGLE_OPTIONAL_STRING,
"sector_identifier_url": SINGLE_OPTIONAL_STRING,
"user_id_type": SINGLE_OPTIONAL_STRING,
"subject_type": SINGLE_OPTIONAL_STRING,
"request_object_signing_alg": SINGLE_OPTIONAL_STRING,
"userinfo_signed_response_algs": SINGLE_OPTIONAL_STRING,
"userinfo_encrypted_response_alg": SINGLE_OPTIONAL_STRING,
Expand All @@ -396,6 +391,7 @@ class RegistrationRequest(Message):
"require_auth_time": OPTIONAL_LOGICAL,
"default_acr":SINGLE_OPTIONAL_STRING,
"javascript_origin_uris":OPTIONAL_LIST_OF_SP_SEP_STRINGS,
"tos_url": SINGLE_OPTIONAL_STRING
#"client_id": SINGLE_OPTIONAL_STRING,
#"client_secret": SINGLE_OPTIONAL_STRING,
}
Expand All @@ -404,7 +400,7 @@ class RegistrationRequest(Message):
c_allowed_values = {
"type" : ["client_associate", "client_update", "rotate_secret"],
"application_type": ["native", "web"],
"user_id_type": ["public", "pairwise"]
"subject_type": ["public", "pairwise"]
}

def verify(self, **kwargs):
Expand Down Expand Up @@ -448,7 +444,7 @@ class ClientRegistrationErrorResponse(message.ErrorResponse):
class IdToken(OpenIDSchema):
c_param = OpenIDSchema.c_param.copy()
c_param.update({"iss": SINGLE_REQUIRED_STRING,
"user_id": SINGLE_REQUIRED_STRING,
"sub": SINGLE_REQUIRED_STRING,
"aud": SINGLE_REQUIRED_STRING,
"exp": SINGLE_REQUIRED_INT,
"iat": SINGLE_REQUIRED_INT,
Expand Down Expand Up @@ -527,8 +523,8 @@ class ProviderConfigurationResponse(Message):
"registration_endpoint": SINGLE_OPTIONAL_STRING,
"scopes_supported": OPTIONAL_LIST_OF_STRINGS,
"response_types_supported": OPTIONAL_LIST_OF_STRINGS,
"acrs_supported": OPTIONAL_LIST_OF_STRINGS,
"user_id_types_supported": OPTIONAL_LIST_OF_STRINGS,
"acr_values_supported": OPTIONAL_LIST_OF_STRINGS,
"subbject_types_supported": OPTIONAL_LIST_OF_STRINGS,
"userinfo_signing_alg_values_supported": OPTIONAL_LIST_OF_STRINGS,
"userinfo_encryption_alg_values_supported":
OPTIONAL_LIST_OF_STRINGS,
Expand Down Expand Up @@ -562,27 +558,6 @@ def verify(self, **kwargs):
return super(self.__class__, self).verify(**kwargs)


class JWKKeyObject(Message):
c_param = {"algorithm": SINGLE_REQUIRED_STRING,
"use": SINGLE_OPTIONAL_STRING, "keyid": SINGLE_OPTIONAL_STRING}

class JWKEllipticKeyObject(JWKKeyObject):
c_param = JWKKeyObject.c_param.copy()
c_param.update({"curve": SINGLE_REQUIRED_STRING,
"x": SINGLE_OPTIONAL_STRING,
"y": SINGLE_OPTIONAL_STRING})

c_default = {"algorithm": "EC"}

class JWKRSAKeyObject(JWKKeyObject):
c_param = JWKKeyObject.c_param.copy()
c_param.update({"exponent": SINGLE_REQUIRED_STRING,
"modulus": SINGLE_OPTIONAL_STRING})
c_default = {"algorithm": "RSA"}

class JWKContainerObject(Message):
c_param = {"keyvalues": REQUIRED_LIST_OF_KEYOBJECTS}

class IssuerRequest(Message):
c_param = {"service": SINGLE_REQUIRED_STRING,
"principal": SINGLE_REQUIRED_STRING}
Expand All @@ -598,7 +573,7 @@ class IssuerResponse(Message):
class AuthnToken(Message):
c_param = {
"iss": SINGLE_REQUIRED_STRING,
"prn": SINGLE_REQUIRED_STRING,
"sub": SINGLE_REQUIRED_STRING,
"aud": SINGLE_REQUIRED_STRING,
"jti": SINGLE_REQUIRED_STRING,
"exp": SINGLE_REQUIRED_INT,
Expand All @@ -620,7 +595,7 @@ class ResourceRequest(Message):
c_param = {"access_token": SINGLE_OPTIONAL_STRING}

SCOPE2CLAIMS = {
"openid": ["user_id"],
"openid": ["sub"],
"profile": ["name", "given_name", "family_name", "middle_name",
"nickname", "profile", "picture", "website", "gender",
"birthday", "zoneinfo", "locale", "updated_time",
Expand Down Expand Up @@ -657,10 +632,6 @@ class ResourceRequest(Message):
"IDTokenClaim": IDTokenClaim,
"OpenIDRequest": OpenIDRequest,
"ProviderConfigurationResponse": ProviderConfigurationResponse,
"JWKKeyObject": JWKKeyObject,
"JWKEllipticKeyObject": JWKEllipticKeyObject,
"JWKRSAKeyObject": JWKRSAKeyObject,
"JWKContainerObject": JWKContainerObject,
"IssuerRequest": IssuerRequest,
"SWDServiceRedirect": SWDServiceRedirect,
"IssuerResponse": IssuerResponse,
Expand Down
58 changes: 4 additions & 54 deletions tests/test_oic_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@

import json

from oic.oic.message import ProviderConfigurationResponse, msg_ser, msg_list_ser, claims_ser, RegistrationRequest
from oic.oic.message import ProviderConfigurationResponse
from oic.oic.message import msg_ser
from oic.oic.message import claims_ser
from oic.oic.message import RegistrationRequest
from oic.oic.message import IDTokenClaim
from oic.oic.message import UserInfoClaim
from oic.oic.message import userinfo_deser
from oic.oic.message import claims_deser
from oic.oic.message import AddressClaim
from oic.oic.message import address_deser
from oic.oic.message import keyobj_list_deser
#from oic.oic.message import AccessTokenResponse
from oic.oic.message import Claims
from oic.oic.message import idtokenclaim_deser
from oic.oic.message import SWDServiceRedirect
from oic.oic.message import JWKEllipticKeyObject
from oic.oic.message import JWKRSAKeyObject
from oic.oic.message import JWKKeyObject
from oic.oic.message import IssuerResponse


def _eq(l1, l2):
return set(l1) == set(l2)

Expand Down Expand Up @@ -58,30 +55,6 @@ def test_iss():

assert res == '{"SWD_service_redirect": {"location": "https://example.net"}}'

def test_JWKEllipticKeyObject():
jeko = JWKEllipticKeyObject(algorithm="EC", curve="P-256",
x="MKBCTNIcKUSDii11ySs3526iDZ8AiTo7Tu6KPAqv7D4",
y="4Etl6SRW2YiLUrN5vfvVHuhp7x8PxltmWWlbbM4IFyM",
use="encryption", keyid="1")

assert jeko["keyid"] == "1"
assert jeko["use"] == "encryption"
assert jeko["curve"] == "P-256"

def test_JWKRSAKeyObject():
jrsa = JWKRSAKeyObject(algorithm="RSA", exponent="AQAB",
keyid="2011-04-29",
modulus="0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw"
)

assert jrsa["algorithm"] == "RSA"
assert jrsa["exponent"] == "AQAB"

def test_JWKKeyObject():
jwk = JWKKeyObject(algorithm="RSA", exponent="AQAB", keyid="2011-04-29",
modulus="0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw")

assert _eq(jwk.keys(), ['keyid', 'algorithm', 'modulus', 'exponent'])

def test_idtokenclaim_deser():
claims = Claims(weather={"acr": "2"})
Expand Down Expand Up @@ -123,17 +96,6 @@ def test_address_deser():
adc = address_deser(pre.to_dict(), format="json")
assert _eq(adc.keys(), ['street_address', 'locality', 'country'])

def test_keyobj_list_deser():
jko1 = JWKKeyObject(algorithm="RSA", exponent="AQAB", keyid="2011-04-29",
modulus="0vx7agoebGcQSuuPiLJ")
jko2 = JWKKeyObject(algorithm="RSA", exponent="AQAB", keyid="2012-05-29",
modulus="Marsupilami")

jkos = keyobj_list_deser([jko1.to_json(), jko2.to_json()], "json")

assert len(jkos) == 2
assert isinstance(jkos[0], JWKKeyObject)
assert isinstance(jkos[1], JWKKeyObject)

def test_msg_ser_json():
pre = AddressClaim(street_address="Kasamark 114", locality="Umea",
Expand Down Expand Up @@ -171,18 +133,6 @@ def test_msg_ser_dictionary():
adc = address_deser(ser, "dict")
assert _eq(adc.keys(), ['street_address', 'locality', 'country'])

def test_msg_list_ser():
jko1 = JWKKeyObject(algorithm="RSA", exponent="AQAB", keyid="2011-04-29",
modulus="0vx7agoebGcQSuuPiLJ")
jko2 = JWKKeyObject(algorithm="RSA", exponent="AQAB", keyid="2012-05-29",
modulus="Marsupilami")

ser = msg_list_ser([jko1, jko2], "dict")

jkos = keyobj_list_deser(ser, "dict")
assert len(jkos) == 2
assert isinstance(jkos[0], JWKKeyObject)
assert isinstance(jkos[1], JWKKeyObject)

CLAIMS = Claims(name={"essential": True}, nickname=None,
email={"essential": True},
Expand Down

0 comments on commit 6c4a778

Please sign in to comment.