-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathJwtSharedSecretConfiguration.py
More file actions
188 lines (153 loc) · 8.08 KB
/
Copy pathJwtSharedSecretConfiguration.py
File metadata and controls
188 lines (153 loc) · 8.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
"""
Configuration for JWT authentication with Shared Secret (symmetric / HS256).
Why JWT with Shared Secret?
----------------------------
* HTTP Signature is being deprecated. JWT with Shared Secret provides a
seamless migration path — it uses the **same** merchantKeyId and
merchantsecretKey credentials you already have for HTTP Signature.
* Enables MLE (Message Level Encryption). MLE requires JWT authentication.
By switching to JWT with Shared Secret, you can enable MLE without managing
a P12 certificate file.
* Zero credential changes. Your existing Key ID and Shared Secret from the
CyberSource Business Center work as-is.
Credentials
-----------
The merchantKeyId and merchantsecretKey are the same credentials used for
HTTP Signature authentication. You can obtain them from the CyberSource
Business Center:
- Test: https://businesscentertest.cybersource.com/ebc2
- Production: https://businesscenter.cybersource.com/ebc2
"""
import os
from CyberSource.logging.log_configuration import LogConfiguration
class JwtSharedSecretConfiguration:
"""Configuration class for JWT with Shared Secret authentication."""
def __init__(self):
# Authentication: JWT with Shared Secret (HS256)
self.authentication_type = "jwt"
self.jwt_key_type = "SHARED_SECRET"
self.merchantid = "testrest"
self.run_environment = "apitest.cybersource.com"
# Shared Secret credentials — same as HTTP Signature credentials
self.merchant_keyid = "08c94330-f618-42a3-b09d-e1e43be5efda"
self.merchant_secretkey = "yBJxy6LjM2TmcPGu+GaJrHtkke25fPpUX+UY6/L/1tE="
# MetaKey Parameters
self.portfolio_id = ""
self.use_metakey = False
# Timeout
self.timeout = 1000
# Log Parameters
self.enable_log = True
self.log_file_name = "cybs"
self.log_maximum_size = 10487560
self.log_directory = os.path.join(os.getcwd(), "Logs")
self.log_level = "Debug"
self.enable_masking = True
self.log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
self.log_date_format = "%Y-%m-%d %H:%M:%S"
def get_configuration(self):
"""
Returns merchant configuration for JWT authentication with Shared Secret.
This is a drop-in replacement for HTTP Signature authentication.
The only changes from a typical HTTP Signature configuration are:
1. authentication_type = 'jwt' (instead of 'http_signature')
2. jwt_key_type = 'SHARED_SECRET' (new property)
The merchantKeyId and merchantsecretKey remain the same.
Returns:
dict: Configuration dictionary for JWT with Shared Secret
"""
configuration_dictionary = {}
configuration_dictionary["authentication_type"] = self.authentication_type
configuration_dictionary["jwt_key_type"] = self.jwt_key_type
configuration_dictionary["merchantid"] = self.merchantid
configuration_dictionary["run_environment"] = self.run_environment
configuration_dictionary["merchant_keyid"] = self.merchant_keyid
configuration_dictionary["merchant_secretkey"] = self.merchant_secretkey
configuration_dictionary["use_metakey"] = self.use_metakey
configuration_dictionary["portfolio_id"] = self.portfolio_id
configuration_dictionary["timeout"] = self.timeout
# Log configuration
log_config = LogConfiguration()
log_config.set_enable_log(self.enable_log)
log_config.set_log_directory(self.log_directory)
log_config.set_log_file_name(self.log_file_name)
log_config.set_log_maximum_size(self.log_maximum_size)
log_config.set_log_level(self.log_level)
log_config.set_enable_masking(self.enable_masking)
log_config.set_log_format(self.log_format)
log_config.set_log_date_format(self.log_date_format)
configuration_dictionary["log_config"] = log_config
return configuration_dictionary
class JwtSharedSecretConfigurationWithMLE:
"""Configuration class for JWT with Shared Secret + MLE authentication."""
def __init__(self):
# Authentication: JWT with Shared Secret (HS256)
self.authentication_type = "jwt"
self.jwt_key_type = "SHARED_SECRET"
self.merchantid = "testrest"
self.run_environment = "apitest.cybersource.com"
# Shared Secret credentials — same as HTTP Signature credentials
self.merchant_keyid = "08c94330-f618-42a3-b09d-e1e43be5efda"
self.merchant_secretkey = "yBJxy6LjM2TmcPGu+GaJrHtkke25fPpUX+UY6/L/1tE="
# MLE Configuration
self.enableRequestMLEForOptionalApisGlobally = True
self.mleForRequestPublicCertPath = os.path.join(os.getcwd(), "resources", "mle_cert.pem")
self.enableResponseMleGlobally = False
self.responseMlePrivateKeyFilePath = ""
self.responseMlePrivateKeyFilePassword = ""
self.responseMleKID = ""
# MetaKey Parameters
self.portfolio_id = ""
self.use_metakey = False
# Timeout
self.timeout = 1000
# Log Parameters
self.enable_log = True
self.log_file_name = "cybs"
self.log_maximum_size = 10487560
self.log_directory = os.path.join(os.getcwd(), "Logs")
self.log_level = "Debug"
self.enable_masking = True
self.log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
self.log_date_format = "%Y-%m-%d %H:%M:%S"
def get_configuration(self):
"""
Returns merchant configuration for JWT with Shared Secret + MLE enabled.
This configuration enables Message Level Encryption (MLE) for request payloads.
Response MLE is also supported — set enableResponseMleGlobally to True
and provide the response MLE private key settings.
Returns:
dict: Configuration dictionary for JWT with Shared Secret + MLE
"""
configuration_dictionary = {}
configuration_dictionary["authentication_type"] = self.authentication_type
configuration_dictionary["jwt_key_type"] = self.jwt_key_type
configuration_dictionary["merchantid"] = self.merchantid
configuration_dictionary["run_environment"] = self.run_environment
configuration_dictionary["merchant_keyid"] = self.merchant_keyid
configuration_dictionary["merchant_secretkey"] = self.merchant_secretkey
configuration_dictionary["use_metakey"] = self.use_metakey
configuration_dictionary["portfolio_id"] = self.portfolio_id
configuration_dictionary["timeout"] = self.timeout
# MLE Configuration
configuration_dictionary["enableRequestMLEForOptionalApisGlobally"] = self.enableRequestMLEForOptionalApisGlobally
configuration_dictionary["mleForRequestPublicCertPath"] = self.mleForRequestPublicCertPath
configuration_dictionary["enableResponseMleGlobally"] = self.enableResponseMleGlobally
if self.responseMlePrivateKeyFilePath:
configuration_dictionary["responseMlePrivateKeyFilePath"] = self.responseMlePrivateKeyFilePath
if self.responseMlePrivateKeyFilePassword:
configuration_dictionary["responseMlePrivateKeyFilePassword"] = self.responseMlePrivateKeyFilePassword
if self.responseMleKID:
configuration_dictionary["responseMleKID"] = self.responseMleKID
# Log configuration
log_config = LogConfiguration()
log_config.set_enable_log(self.enable_log)
log_config.set_log_directory(self.log_directory)
log_config.set_log_file_name(self.log_file_name)
log_config.set_log_maximum_size(self.log_maximum_size)
log_config.set_log_level(self.log_level)
log_config.set_enable_masking(self.enable_masking)
log_config.set_log_format(self.log_format)
log_config.set_log_date_format(self.log_date_format)
configuration_dictionary["log_config"] = log_config
return configuration_dictionary