Skip to content

Commit ab2c7ce

Browse files
authored
Merge pull request #525 from herbdool/issue-503
Issue #503: add encryption instructions and allow private://
2 parents 64bf560 + fbe9b2b commit ab2c7ce

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

payment/uc_credit/uc_credit.admin.inc

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,31 @@ function uc_credit_settings_form($form, &$form_state) {
7070
$form['cc_security']['uc_credit_encryption_path'] = array(
7171
'#type' => 'textfield',
7272
'#title' => t('Encryption key directory'),
73-
'#description' => t('The card type, expiration date and last four digits of the card number are encrypted and stored temporarily while the customer is in the process of checking out.<br /><b>You must enable encryption</b> by following the <a href="!url">encryption instructions</a> in order to accept credit card payments.<br />In short, you must enter the path of a directory outside of your document root where the encryption key may be stored.<br />Relative paths will be resolved relative to the Backdrop installation directory.<br />Once this directory is set, you should not change it.', array('!url' => 'http://drupal.org/node/1309226')),
73+
'#description' => t('The card type, expiration date and last four digits of the card number are encrypted and stored temporarily while the customer is in the process of checking out.<br /><b>You must enable encryption</b> by following the <em>encryption instructions</em> in order to accept credit card payments.<br />In short, you must enter the path of a directory outside of your document root where the encryption key may be stored.<br />Relative paths will be resolved relative to the Backdrop installation directory. Alternatively, you can specify the <a href="!url">private file system</a> if it is set, for example: <code>private://</code> or <code>private://keys</code><br />Once this directory is set, you should not change it.', array('!url' => '/admin/config/media/file-system')),
7474
'#default_value' => uc_credit_encryption_key() ? $config->get('uc_credit_encryption_path') : t('Not configured.'),
7575
);
76+
$encryption_instructions = '<p>';
77+
$encryption_instructions .= t('Security is extremely important for websites handling customer credit card data. You should be as careful as possible in the way you protect the data to prevent credit card fraud. Please be sure you are selecting the right options, as some choices may decrease the security of credit card data on your website and should be avoided if at all possible. Most payment gateways will require compliance with a set of security standards called the PCI DSS. When the Ubercart credit card module is used in conjunction with an SSL certificate and your site redirects to https, your site will conform to these standards.');
78+
$encryption_instructions .= '</p>';
79+
$encryption_instructions .= '<p>';
80+
$encryption_instructions .= t('First, you must configure the encryption settings for card data during checkout. To do this, you\'ll need to fill in the filepath textfield. Here you should specify a folder that is outside of your document root (i.e. not in your www or public_html directory) where Ubercart can create a file to hold an encryption key. You can also specify the private file location, if it is set for this website, by entering something like <code>private://keys</code>. You will need to grant permissions on the folder that allow Backdrop to write to it, but you can change this once the encryption key file has been created. Relative paths will be resolved relative to the Backdrop installation directory, so if you have a directory structure like the following:');
81+
$encryption_instructions .= '</p>';
82+
$encryption_instructions .= '<pre>';
83+
$encryption_instructions .= 'mysite
84+
mysite/www <-- Backdrop installed here.
85+
mysite/keys';
86+
$encryption_instructions .= '</pre>';
87+
$encryption_instructions .= '<p>';
88+
$encryption_instructions .= t('You would be able to specify ../keys on Encryption key directory field and Backdrop will make sure the credit card encryption key is created in the proper directory. For security reasons, you should not use your site\'s files directory except in testing.');
89+
$encryption_instructions .= '</p>';
90+
$form['cc_security']['encryption_instructions'] = array(
91+
'#type' => 'details',
92+
'#summary' => t('Encryption instructions'),
93+
'#details' => $encryption_instructions,
94+
'#attributes' => array(
95+
'class' => array('description'),
96+
),
97+
);
7698

7799
// Form elements that deal with the type of data requested at checkout.
78100
$form['cc_fields'] = array(
@@ -242,13 +264,20 @@ function uc_credit_settings_form($form, &$form_state) {
242264
function uc_credit_settings_form_validate($form, &$form_state) {
243265

244266
// Trim trailing whitespace and any trailing / or \ from the key path name.
245-
$key_path = rtrim(trim($form_state['values']['uc_credit_encryption_path']), '/\\');
267+
$original_key_path = $key_path = rtrim(trim($form_state['values']['uc_credit_encryption_path']), '/\\');
246268

247269
// Test to see if a path was entered.
248270
if (empty($key_path)) {
249271
form_set_error('uc_credit_encryption_path', t('A key path must be specified in the "Security settings" tab.'));
250272
}
251273

274+
$scheme = file_uri_scheme($key_path);
275+
if ($scheme == 'private') {
276+
$directory_path = file_stream_wrapper_get_instance_by_uri($key_path)->getDirectoryPath();
277+
278+
$key_path = $directory_path . '/' . file_uri_target($key_path);
279+
}
280+
252281
// Construct complete key file path.
253282
$key_file = $key_path . '/' . UC_CREDIT_KEYFILE_NAME;
254283

@@ -264,7 +293,7 @@ function uc_credit_settings_form_validate($form, &$form_state) {
264293
else {
265294
// Key file exists and is valid, save result of trim() back into
266295
// $form_state and proceed to submit handler.
267-
$form_state['values']['uc_credit_encryption_path'] = $key_path;
296+
$form_state['values']['uc_credit_encryption_path'] = $original_key_path;
268297
return;
269298
}
270299
}
@@ -314,7 +343,7 @@ function uc_credit_settings_form_validate($form, &$form_state) {
314343
}
315344

316345
// If validation succeeds, save result of trim() back into $form_state.
317-
$form_state['values']['uc_credit_encryption_path'] = $key_path;
346+
$form_state['values']['uc_credit_encryption_path'] = $original_key_path;
318347
}
319348

320349
/**

0 commit comments

Comments
 (0)