camper/deploy
jordi fita mas 62b54961f4 Implement Redsys request signature in PostgreSQL
Every company need to have its own merchant code and encryption key,
thus it is not possible to use environment variables to keep that data,
and i have to store it in the database.

I do not want to give SELECT permission on the encryption key to guest,
because i am going to fuck it up sooner or later, and everyone would be
able to read that secret; i know it would.  Therefore, i need a security
definer function that takes the data to encrypt, use the key to encrypt
it, and returns the result; nobody else should have access to that key,
not even admins!

By the way, i found out that every merchant receives the same key, thus
it is not a problem to keep it in the repository.

Since i need that SQL function to encrypt the data, i thought that i may
go the whole nine yards and sign the request in PostgreSQL too, after
all the data to sign comes from there, and it has JSON functions to
create and base64-code an object.

Fortunately, pg_crypto has all the functions that i need, but i can no
longer keep that extension inside the auth schema, because it is used
from others, and the public schema, like every other extensions, seems
more appropriate.

Instead of having the list of currency and language codes that Redsys
uses as constants in the code, i moved that as field to the currency
and language relations, so i can simply pass the lang_tag to the
function and it can transform that tag to the correct code; the currency
is from the company’s relation, since it is the only currency used in
the whole application (for now).

As a consequence, i had to grant execute to currency and the parse_price
functions to guest, too.

To generate the test data used in the unit tests, i used a third-party
PHP implementation[0], but i only got from that the resulting base64-coded
JSON object and signature, using the same that as in the unit test, and
did not use any code from there.

PostgreSQL formats the JSON as text differently than most
implementations i have seen: it adds spaces between the key name and
the colons, and space between the value and the separating comma.  The
first implementation used replace() to format the JSON as exactly as
the PHP implementation, so that the result matches, and then tried to do
generate the form by hand using the output from PostgreSQL without the
replace(), to verify that Redsys would still accept my input.  Finally,
i adjusted the unit test to whatever pg_prove said it was getting from
the function.

I still have the form’s action hard-codded to the test environment, but
the idea is that administrators should be able to switch from test to
live themselves.  That means that i need that info in the redsys
relation as well.  I think this is one of the few use cases for SQL’s
types, because it is unlikely to change anytime soon, and i do not need
the actual labels.

Unfortunately, i could not use enumerations for the request’s
transaction type because i can not attach an arbitrary number to the
enum’s values.  Having a relation is overkill, because i would need
a constant in Go to refer to its primary key anyway, thus i kept the
same constant i had before for that.  Language and currency constant
went out, as this is in the corresponding relations.

In setup_redsys i must have a separate update if the encrypt_key is null
because PostgreSQL checks constraints before key conflict, and i do
not want to give a default value to the key if the row is not there yet.
The problem is that i want to use null to mean “keep the same password”,
because it is what i intend to do with the user-facing form: leave the
input empty to keep the same password.

As now Go needs to pass composite types back and forth with PostgreSQL,
i need to register these types, and i have to do it every time because
the only moment i have access to the non-pooled connection is in the
AfterConnect function, but at that point i have no idea whether the
user is going to request a payment.  I do not know how much the
performance degrades because of this.

[0]: https://github.com/ssheduardo/sermepa/blob/master/src/Sermepa/Tpv/Tpv.php
2023-10-27 01:52:04 +02:00
..
add_campsite.sql Add campsite map in SVG 2023-09-24 03:17:13 +02:00
add_campsite_type.sql Add the info and facilities fields to campsite type 2023-10-13 18:09:28 +02:00
add_campsite_type_carousel_slide.sql Add the carousel for campsite types 2023-10-12 17:43:23 +02:00
add_campsite_type_feature.sql Add the list of features for campsite type 2023-10-13 20:30:31 +02:00
add_campsite_type_option.sql Add campsite type options, mainly for plots 2023-10-06 13:26:01 +02:00
add_home_carousel_slide.sql Make home page’s carousel manageable via the database 2023-09-15 01:05:38 +02:00
add_media.sql Manage all media uploads in a single place 2023-09-21 01:56:44 +02:00
add_season.sql Add seasons’ relation, functions, and admin section 2023-08-16 20:15:57 +02:00
add_service.sql Add the services page 2023-09-17 03:42:16 +02:00
add_services_carousel_slide.sql Add the services page 2023-09-17 03:42:16 +02:00
available_countries.sql Add company and company_user relations, along with their dependencies 2023-07-29 04:25:56 +02:00
available_currencies.sql Implement Redsys request signature in PostgreSQL 2023-10-27 01:52:04 +02:00
available_icons.sql Add the list of features for campsite type 2023-10-13 20:30:31 +02:00
available_languages.sql Implement Redsys request signature in PostgreSQL 2023-10-27 01:52:04 +02:00
build_cookie.sql Add authentication relations, views, and functions for PostgreSQL 2023-07-22 01:59:12 +02:00
campsite.sql Replace serial columns with ‘generated by default as identity’ 2023-09-26 19:35:16 +02:00
campsite_type.sql Add the info and facilities fields to campsite type 2023-10-13 18:09:28 +02:00
campsite_type_carousel.sql Add the carousel for campsite types 2023-10-12 17:43:23 +02:00
campsite_type_carousel_i18n.sql Add the carousel for campsite types 2023-10-12 17:43:23 +02:00
campsite_type_cost.sql Add the campsite type cost per season 2023-10-01 21:14:39 +02:00
campsite_type_feature.sql Add the list of features for campsite type 2023-10-13 20:30:31 +02:00
campsite_type_feature_i18n.sql Add the list of features for campsite type 2023-10-13 20:30:31 +02:00
campsite_type_i18n.sql Add the info and facilities fields to campsite type 2023-10-13 18:09:28 +02:00
campsite_type_option.sql Add campsite type options, mainly for plots 2023-10-06 13:26:01 +02:00
campsite_type_option_cost.sql Add campsite type options, mainly for plots 2023-10-06 13:26:01 +02:00
campsite_type_option_i18n.sql Add campsite type options, mainly for plots 2023-10-06 13:26:01 +02:00
change_password.sql Add authentication relations, views, and functions for PostgreSQL 2023-07-22 01:59:12 +02:00
check_cookie.sql Move the user role down to company_user relation 2023-08-08 02:22:16 +02:00
color.sql Add seasons’ relation, functions, and admin section 2023-08-16 20:15:57 +02:00
company.sql Add the Catalonia’s Tourism Registry number to company 2023-10-14 21:59:36 +02:00
company_geography.sql Add the contact page, containing a map with the company location 2023-10-06 21:21:00 +02:00
company_host.sql Use HTTP Host to establish the request’s company 2023-08-03 20:21:21 +02:00
company_user.sql Move the user role down to company_user relation 2023-08-08 02:22:16 +02:00
country.sql Add the first draft of the booking and payment forms 2023-10-19 21:37:34 +02:00
country_code.sql Add company and company_user relations, along with their dependencies 2023-07-29 04:25:56 +02:00
country_i18n.sql Add the first draft of the booking and payment forms 2023-10-19 21:37:34 +02:00
currency.sql Implement Redsys request signature in PostgreSQL 2023-10-27 01:52:04 +02:00
currency_code.sql Add company and company_user relations, along with their dependencies 2023-07-29 04:25:56 +02:00
current_company_id.sql Move the user role down to company_user relation 2023-08-08 02:22:16 +02:00
current_user_cookie.sql Add authentication relations, views, and functions for PostgreSQL 2023-07-22 01:59:12 +02:00
current_user_email.sql Add authentication relations, views, and functions for PostgreSQL 2023-07-22 01:59:12 +02:00
edit_campsite.sql Add campsite map in SVG 2023-09-24 03:17:13 +02:00
edit_campsite_type.sql Add the info and facilities fields to campsite type 2023-10-13 18:09:28 +02:00
edit_campsite_type_feature.sql Add the list of features for campsite type 2023-10-13 20:30:31 +02:00
edit_campsite_type_option.sql Add campsite type options, mainly for plots 2023-10-06 13:26:01 +02:00
edit_media.sql Manage all media uploads in a single place 2023-09-21 01:56:44 +02:00
edit_season.sql Add seasons’ relation, functions, and admin section 2023-08-16 20:15:57 +02:00
edit_service.sql Add the services page 2023-09-17 03:42:16 +02:00
email.sql Add authentication relations, views, and functions for PostgreSQL 2023-07-22 01:59:12 +02:00
encode_base64url.sql Implement Redsys request signature in PostgreSQL 2023-10-27 01:52:04 +02:00
encrypt_password.sql Implement Redsys request signature in PostgreSQL 2023-10-27 01:52:04 +02:00
ensure_role_exists.sql Move the user role down to company_user relation 2023-08-08 02:22:16 +02:00
extension_btree_gist.sql Add the season_calendar relation and table on the admin section 2023-09-27 02:23:09 +02:00
extension_citext.sql Add authentication relations, views, and functions for PostgreSQL 2023-07-22 01:59:12 +02:00
extension_pg_libphonenumber.sql Add company and company_user relations, along with their dependencies 2023-07-29 04:25:56 +02:00
extension_pgcrypto.sql Implement Redsys request signature in PostgreSQL 2023-10-27 01:52:04 +02:00
extension_postgis.sql Add the contact page, containing a map with the company location 2023-10-06 21:21:00 +02:00
extension_uri.sql Add company and company_user relations, along with their dependencies 2023-07-29 04:25:56 +02:00
extension_vat.sql Add company and company_user relations, along with their dependencies 2023-07-29 04:25:56 +02:00
home_carousel.sql Fix Sqitch’s requires for schema_camper in home_carousel and services_carousel 2023-10-12 16:21:32 +02:00
home_carousel_i18n.sql Make home page’s carousel manageable via the database 2023-09-15 01:05:38 +02:00
icon.sql Add the services page 2023-09-17 03:42:16 +02:00
input_is_valid.sql Add the form to update company’s tax details 2023-08-15 22:35:21 +02:00
input_is_valid_phone.sql Add the form to update company’s tax details 2023-08-15 22:35:21 +02:00
language.sql Implement Redsys request signature in PostgreSQL 2023-10-27 01:52:04 +02:00
login.sql Implement Redsys request signature in PostgreSQL 2023-10-27 01:52:04 +02:00
login_attempt.sql Replace serial columns with ‘generated by default as identity’ 2023-09-26 19:35:16 +02:00
logout.sql Add authentication relations, views, and functions for PostgreSQL 2023-07-22 01:59:12 +02:00
media.sql Replace serial columns with ‘generated by default as identity’ 2023-09-26 19:35:16 +02:00
media_content.sql Manage all media uploads in a single place 2023-09-21 01:56:44 +02:00
media_path.sql Manage all media uploads in a single place 2023-09-21 01:56:44 +02:00
media_type.sql Add media relation and add_media function 2023-09-08 20:03:26 +02:00
parse_price.sql Implement Redsys request signature in PostgreSQL 2023-10-27 01:52:04 +02:00
policies_company.sql Move the user role down to company_user relation 2023-08-08 02:22:16 +02:00
redsys.sql Implement Redsys request signature in PostgreSQL 2023-10-27 01:52:04 +02:00
redsys_encrypt.sql Implement Redsys request signature in PostgreSQL 2023-10-27 01:52:04 +02:00
redsys_environment.sql Implement Redsys request signature in PostgreSQL 2023-10-27 01:52:04 +02:00
redsys_integration.sql Implement Redsys request signature in PostgreSQL 2023-10-27 01:52:04 +02:00
redsys_request.sql Implement Redsys request signature in PostgreSQL 2023-10-27 01:52:04 +02:00
redsys_sign_request.sql Implement Redsys request signature in PostgreSQL 2023-10-27 01:52:04 +02:00
redsys_signed_request.sql Implement Redsys request signature in PostgreSQL 2023-10-27 01:52:04 +02:00
remove_campsite_type_carousel_slide.sql Add the carousel for campsite types 2023-10-12 17:43:23 +02:00
remove_home_carousel_slide.sql Make home page’s carousel manageable via the database 2023-09-15 01:05:38 +02:00
remove_service.sql Add function and HTTP handler to delete services 2023-09-26 17:29:49 +02:00
remove_services_carousel_slide.sql Add the services page 2023-09-17 03:42:16 +02:00
roles.sql Add authentication relations, views, and functions for PostgreSQL 2023-07-22 01:59:12 +02:00
schema_auth.sql Add authentication relations, views, and functions for PostgreSQL 2023-07-22 01:59:12 +02:00
schema_camper.sql Add authentication relations, views, and functions for PostgreSQL 2023-07-22 01:59:12 +02:00
schema_public.sql Add authentication relations, views, and functions for PostgreSQL 2023-07-22 01:59:12 +02:00
season.sql Replace serial columns with ‘generated by default as identity’ 2023-09-26 19:35:16 +02:00
season_calendar.sql Add the season_calendar relation and table on the admin section 2023-09-27 02:23:09 +02:00
season_i18n.sql Add internationalization and localization to seasons 2023-10-03 21:14:37 +02:00
service.sql Replace serial columns with ‘generated by default as identity’ 2023-09-26 19:35:16 +02:00
service_i18n.sql Add the services page 2023-09-17 03:42:16 +02:00
services_carousel.sql Fix Sqitch’s requires for schema_camper in home_carousel and services_carousel 2023-10-12 16:21:32 +02:00
services_carousel_i18n.sql Add the services page 2023-09-17 03:42:16 +02:00
set_campsite_type_cost.sql Add the campsite type cost per season 2023-10-01 21:14:39 +02:00
set_campsite_type_option_cost.sql Add campsite type options, mainly for plots 2023-10-06 13:26:01 +02:00
set_cookie.sql Move the user role down to company_user relation 2023-08-08 02:22:16 +02:00
set_season_range.sql Add the season_calendar relation and table on the admin section 2023-09-27 02:23:09 +02:00
setup_redsys.sql Implement Redsys request signature in PostgreSQL 2023-10-27 01:52:04 +02:00
to_color.sql Add seasons’ relation, functions, and admin section 2023-08-16 20:15:57 +02:00
to_integer.sql Add seasons’ relation, functions, and admin section 2023-08-16 20:15:57 +02:00
to_price.sql Grant execute to guest for function to_price 2023-10-06 13:23:20 +02:00
translate_campsite_type.sql Add the info and facilities fields to campsite type 2023-10-13 18:09:28 +02:00
translate_campsite_type_carousel_slide.sql Add the carousel for campsite types 2023-10-12 17:43:23 +02:00
translate_campsite_type_feature.sql Add the list of features for campsite type 2023-10-13 20:30:31 +02:00
translate_campsite_type_option.sql Add campsite type options, mainly for plots 2023-10-06 13:26:01 +02:00
translate_home_carousel_slide.sql Make home page’s carousel manageable via the database 2023-09-15 01:05:38 +02:00
translate_season.sql Add internationalization and localization to seasons 2023-10-03 21:14:37 +02:00
translate_service.sql Add the services page 2023-09-17 03:42:16 +02:00
translate_services_carousel_slide.sql Add the services page 2023-09-17 03:42:16 +02:00
translation.sql Add the edit form for services 2023-09-25 20:10:33 +02:00
unset_season_range.sql Fix error unsetting season range that corresponds to existing range 2023-09-28 02:28:33 +02:00
user.sql Replace serial columns with ‘generated by default as identity’ 2023-09-26 19:35:16 +02:00
user_profile.sql Move the user role down to company_user relation 2023-08-08 02:22:16 +02:00
zero_pad.sql Implement Redsys request signature in PostgreSQL 2023-10-27 01:52:04 +02:00