33Key types and providers for OS2Web built on the [ Key module] ( https://www.drupal.org/project/key ) .
44
55The OS2Web key module provides two _ key types_ , [ Certificate] ( #certificate ) and [ OpenID Connect
6- (OIDC)] ( #openid-connect-oidc ) . Two _ key providers _ , [ Azure Key Vault ] ( #azure-key-vault ) and [ Infisical ] ( #infisical ) , are
7- planned, but not yet implemented .
6+ (OIDC)] ( #openid-connect-oidc ) . It also comes with two _ key providers _ ,
7+ [ Azure Key Vault ] ( #azure-key-vault ) and [ HashiCorp Vault ] ( #hashicorp-vault ) .
88
99See [ the Key Developer Guide] ( https://www.drupal.org/docs/contributed-modules/key/developer-guide ) for details in how to
1010use keys in Drupal.
@@ -106,13 +106,24 @@ $key = $repository->getKey('openid_connect_ad');
106106
107107## Providers
108108
109+ The module comes with two key providers.
110+
109111### Azure Key Vault
110112
111- ` @todo ` < https://azure.microsoft.com/en-us/products/key-vault >
113+ Used for fetching certificate from Azure Key vault.
114+
115+ ### HashiCorp Vault
112116
113- ### Infisical
117+ Used to fetch any sort of secret string from HashiCorp vault. Note that
118+ this can only provide string values, i.e. no binary files.
114119
115- ` @todo ` < https://infisical.com/ >
120+ To use this provider you must configure the following in ` settings.local.php ` :
121+
122+ ``` php
123+ $settings['os2web_vault_role_id'] = '{ROLE_ID}';
124+ $settings['os2web_vault_secret_id'] = '{SECRET_ID}';
125+ $settings['os2web_vault_url'] = '{VAULT_URL}';
126+ ```
116127
117128## Coding standards
118129
@@ -122,11 +133,11 @@ below to run the checks locally.
122133### PHP
123134
124135``` shell
125- docker run --rm --volume ${PWD} :/app --workdir /app itkdev/php8.1 -fpm composer install
136+ docker run --rm --volume ${PWD} :/app --workdir /app itkdev/php8.3 -fpm composer install
126137# Fix (some) coding standards issues
127- docker run --rm --volume ${PWD} :/app --workdir /app itkdev/php8.1 -fpm composer coding-standards-apply
138+ docker run --rm --volume ${PWD} :/app --workdir /app itkdev/php8.3 -fpm composer coding-standards-apply
128139# Check that code adheres to the coding standards
129- docker run --rm --volume ${PWD} :/app --workdir /app itkdev/php8.1 -fpm composer coding-standards-check
140+ docker run --rm --volume ${PWD} :/app --workdir /app itkdev/php8.3 -fpm composer coding-standards-check
130141```
131142
132143### Markdown
@@ -140,9 +151,69 @@ docker run --rm --volume $PWD:/md peterdavehello/markdownlint markdownlint --ign
140151
141152We use [ PHPStan] ( https://phpstan.org/ ) for static code analysis.
142153
143- Running statis code analysis on a standalone Drupal module is a bit tricky, so we use a helper script to run the
154+ Running static code analysis on a standalone Drupal module is a bit tricky, so we use a helper script to run the
155+ analysis:
156+
157+ ``` shell
158+ docker run --rm --volume ${PWD} :/app --workdir /app itkdev/php8.3-fpm ./scripts/code-analysis
159+ ```
160+
161+ ## Unit tests
162+
163+ We use [ PHPUnit] ( https://phpunit.de/documentation.html ) for unit testing.
164+
165+ Testing mostly centers around the conversion and parsing of certificates. For this purpose a bunch of test
166+ certificates has been generated. See [ Test certificates] ( #test-certificates ) for how this is done.
167+
168+ Running PHPUnit tests in a standalone Drupal module is a bit tricky, so we use a helper script to run the
144169analysis:
145170
146171``` shell
147- docker run --rm --volume ${PWD} :/app --workdir /app itkdev/php8.1-fpm ./scripts/code-analysis
172+ docker run --rm --volume ${PWD} :/app --workdir /app itkdev/php8.3-fpm ./scripts/unit-tests
173+ ```
174+
175+ ### Test certificates
176+
177+ Certificates have been generated in the follow way
178+
179+ ``` shell
180+ # p12 with password
181+ openssl req -x509 -newkey rsa:4096 -days 365 -subj " /CN=example.com" -passout pass:test -keyout test.key -out test.crt
182+ openssl pkcs12 -export -out test_with_passphrase.p12 -passin pass:test -passout pass:test -inkey test.key -in test.crt
183+ openssl pkcs12 -in test_with_passphrase.p12 -passin pass:test -noenc
184+
185+ # p12 without password
186+ openssl req -x509 -newkey rsa:4096 -days 365 -subj " /CN=example.com" -passout pass:' ' -keyout test_without_passphrase.key -out test_without_passphrase.crt
187+ openssl pkcs12 -export -out test_without_passphrase.p12 -passin pass:' ' -passout pass:' ' -inkey test_without_passphrase.key -in test_without_passphrase.crt
188+ openssl pkcs12 -in test_without_passphrase.p12 -passin pass:' ' -noenc
189+
190+ # PEM with password
191+ openssl req -x509 -newkey rsa:4096 -days 365 -subj " /CN=example.com" -passout pass:test -keyout test.key -out test.crt
192+ cat test.crt test.key > test_with_passphrase.pem
193+ openssl x509 -in test_with_passphrase.pem
194+
195+ # PEM without password
196+ openssl req -x509 -newkey rsa:4096 -days 365 -subj " /CN=example.com" -passout pass:' ' -keyout test_without_passphrase.key -out test_without_passphrase.crt -noenc
197+ cat test_without_passphrase.crt test_without_passphrase.key > test_without_passphrase.pem
198+ openssl x509 -in test_without_passphrase.pem
199+ ```
200+
201+ Extraction of certificate and private key parts in the following way
202+
203+ ``` shell
204+ # P12 with passphrase
205+ openssl pkcs12 -in test_with_passphrase.p12 -passin pass:test -clcerts -nokeys | sed -ne ' /-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p' > p12_with_passphrase_cert.txt
206+ openssl pkcs12 -in test_with_passphrase.p12 -passin pass:test -nocerts -nodes | sed -ne ' /-----BEGIN PRIVATE KEY-----/,/-----END PRIVATE KEY-----/p' > p12_with_passphrase_pkey.txt
207+
208+ # P12 without passphrase
209+ openssl pkcs12 -in test_without_passphrase.p12 -passin pass: -clcerts -nokeys | sed -ne ' /-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p' > p12_without_passphrase_cert.txt
210+ openssl pkcs12 -in test_without_passphrase.p12 -passin pass: -nocerts -nodes | sed -ne ' /-----BEGIN PRIVATE KEY-----/,/-----END PRIVATE KEY-----/p' > p12_without_passphrase_pkey.txt
211+
212+ # PEM with passphrase
213+ openssl x509 -in test_with_passphrase.pem -passin pass:test -out pem_with_passphrase_cert.txt
214+ openssl pkey -in test_with_passphrase.pem -passin pass:test -out pem_with_passphrase_pkey.txt
215+
216+ # PEM without passphrase
217+ openssl x509 -in test_without_passphrase.pem -passin pass: -out pem_without_passphrase_cert.txt
218+ openssl pkey -in test_without_passphrase.pem -passin pass: -out pem_without_passphrase_pkey.txt
148219```
0 commit comments