1212from jose import jws
1313
1414from hyperwallet .exceptions import HyperwalletException
15- from django .core .validators import URLValidator
16- from django .core .exceptions import ValidationError
15+ try :
16+ from urlparse import urlparse
17+ except :
18+ from urllib .parse import urlparse
1719
1820
1921class Encryption (object ):
@@ -35,8 +37,11 @@ class Encryption(object):
3537 '''
3638
3739 def __init__ (self ,
38- clientPrivateKeySetLocation , hyperwalletKeySetLocation ,
39- encryptionAlgorithm = 'RSA-OAEP-256' , signAlgorithm = 'RS256' , encryptionMethod = 'A256CBC-HS512' ,
40+ clientPrivateKeySetLocation ,
41+ hyperwalletKeySetLocation ,
42+ encryptionAlgorithm = 'RSA-OAEP-256' ,
43+ signAlgorithm = 'RS256' ,
44+ encryptionMethod = 'A256CBC-HS512' ,
4045 jwsExpirationMinutes = 5 ):
4146 '''
4247 Encryption service for hyperwallet client
@@ -116,17 +121,17 @@ def __getJwkKeySet(self, location):
116121 :returns:
117122 JWK key set found at given location.
118123 '''
119-
120- try :
121- URLValidator ()( location )
122- except ValidationError :
123- if os . path . isfile ( location ):
124- with open ( location ) as f :
125- return f . read ()
126- else :
127- raise HyperwalletException ( 'Wrong JWK key set location path = ' + location )
128-
129- return requests . get ( location ). text
124+ try :
125+ url = urlparse ( location )
126+ if url . scheme and url . netloc and url . path :
127+ return requests . get ( location ). text
128+ raise HyperwalletException ( 'Failed to parse url from string = ' + location )
129+ except :
130+ if os . path . isfile ( location ):
131+ with open ( location ) as f :
132+ return f . read ( )
133+ else :
134+ raise HyperwalletException ( 'Wrong JWK key set location path = ' + location )
130135
131136 def __findJwkKeyByAlgorithm (self , jwkKeySet , algorithm ):
132137 '''
0 commit comments