-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ops flag mask master #4649
Fix ops flag mask master #4649
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
name: CA with HSM and custom operation key flags | ||
|
||
on: workflow_call | ||
|
||
env: | ||
DB_IMAGE: ${{ vars.DB_IMAGE || 'quay.io/389ds/dirsrv' }} | ||
|
||
jobs: | ||
# docs/installation/ca/Installing_CA_with_HSM.md | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
env: | ||
SHARED: /tmp/workdir/pki | ||
steps: | ||
- name: Clone repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Retrieve PKI images | ||
uses: actions/cache@v3 | ||
with: | ||
key: pki-images-${{ github.sha }} | ||
path: pki-images.tar | ||
|
||
- name: Load PKI images | ||
run: docker load --input pki-images.tar | ||
|
||
- name: Create network | ||
run: docker network create example | ||
|
||
- name: Set up DS container | ||
run: | | ||
tests/bin/ds-container-create.sh ds | ||
env: | ||
IMAGE: ${{ env.DB_IMAGE }} | ||
HOSTNAME: ds.example.com | ||
PASSWORD: Secret.123 | ||
|
||
- name: Connect DS container to network | ||
run: docker network connect example ds --alias ds.example.com | ||
|
||
- name: Set up PKI container | ||
run: | | ||
tests/bin/runner-init.sh pki | ||
env: | ||
HOSTNAME: pki.example.com | ||
|
||
- name: Connect PKI container to network | ||
run: docker network connect example pki --alias pki.example.com | ||
|
||
- name: Install dependencies | ||
run: | | ||
docker exec pki dnf install -y softhsm | ||
|
||
- name: Create SoftHSM token | ||
run: | | ||
# allow PKI user to access SoftHSM files | ||
docker exec pki usermod pkiuser -a -G ods | ||
|
||
# create SoftHSM token for PKI server | ||
docker exec pki runuser -u pkiuser -- \ | ||
softhsm2-util \ | ||
--init-token \ | ||
--label HSM \ | ||
--so-pin Secret.HSM \ | ||
--pin Secret.HSM \ | ||
--free | ||
|
||
docker exec pki ls -laR /var/lib/softhsm/tokens | ||
|
||
- name: Install CA with HSM and no sign flag | ||
run: | | ||
docker exec pki pkispawn \ | ||
-f /usr/share/pki/server/examples/installation/ca.cfg \ | ||
-s CA \ | ||
-D pki_instance_name=pki-failing-tomcat \ | ||
-D pki_ds_url=ldap://ds.example.com:3389 \ | ||
-D pki_hsm_enable=True \ | ||
-D pki_token_name=HSM \ | ||
-D pki_token_password=Secret.HSM \ | ||
-D pki_server_database_password=Secret.123 \ | ||
-D pki_ca_signing_token=HSM \ | ||
-D pki_ocsp_signing_token=HSM \ | ||
-D pki_audit_signing_token=HSM \ | ||
-D pki_subsystem_token=HSM \ | ||
-D pki_sslserver_token=internal \ | ||
-D pki_ca_signing_opsFlagMask=sign \ | ||
-v | ||
continue-on-error: true | ||
id: hsm_no_sign | ||
|
||
- name: Check the install with no sign ops failed | ||
if: job.steps.hsm_no_sign.status != failure() | ||
run: exit 1 | ||
|
||
- name: Install CA with HSM reintroducing sign flag | ||
run: | | ||
docker exec pki pkispawn \ | ||
-f /usr/share/pki/server/examples/installation/ca.cfg \ | ||
-s CA \ | ||
-D pki_ds_url=ldap://ds.example.com:3389 \ | ||
-D pki_hsm_enable=True \ | ||
-D pki_token_name=HSM \ | ||
-D pki_token_password=Secret.HSM \ | ||
-D pki_server_database_password=Secret.123 \ | ||
-D pki_ca_signing_token=HSM \ | ||
-D pki_ocsp_signing_token=HSM \ | ||
-D pki_audit_signing_token=HSM \ | ||
-D pki_subsystem_token=HSM \ | ||
-D pki_sslserver_token=internal \ | ||
-D pki_ca_signing_opsFlag=sign \ | ||
-D pki_ca_signing_opsFlagMask=sign \ | ||
-v | ||
|
||
- name: Gather artifacts | ||
if: always() | ||
run: | | ||
tests/bin/ds-artifacts-save.sh --output=/tmp/artifacts/pki ds | ||
tests/bin/pki-artifacts-save.sh pki | ||
continue-on-error: true | ||
|
||
- name: Remove CA | ||
run: docker exec pki pkidestroy -i pki-tomcat -s CA -v | ||
|
||
- name: Remove SoftHSM token | ||
run: | | ||
docker exec pki ls -laR /var/lib/softhsm/tokens | ||
docker exec pki runuser -u pkiuser -- softhsm2-util --delete-token --token HSM | ||
|
||
- name: Upload artifacts | ||
if: always() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: ca-hsm | ||
path: | | ||
/tmp/artifacts/pki |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,14 @@ public void createOptions() { | |
option.setArgName("boolean"); | ||
options.addOption(option); | ||
|
||
option = new Option(null, "ops-flag", true, "Custom flags for key usage (empty for HSM default)"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just thinking, would It's probably not necessary to mention There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about the wording but your clarification seems reasonable so I'll update. |
||
option.setArgName("usage list"); | ||
options.addOption(option); | ||
|
||
option = new Option(null, "ops-flag-mask", true, "Custom flags mask for key usage (empty for HSM default)"); | ||
option.setArgName("usage list"); | ||
options.addOption(option); | ||
|
||
option = new Option(null, "output-format", true, "Output format: text (default), json."); | ||
option.setArgName("format"); | ||
options.addOption(option); | ||
|
@@ -129,6 +137,9 @@ public void execute(CommandLine cmd) throws Exception { | |
extractable = Boolean.valueOf(extractableStr); | ||
} | ||
|
||
String opsFlag = cmd.getOptionValue("ops-flag"); | ||
String opsFlagMask = cmd.getOptionValue("ops-flag-mask"); | ||
|
||
MainCLI mainCLI = (MainCLI) getRoot(); | ||
mainCLI.init(); | ||
|
||
|
@@ -141,11 +152,21 @@ public void execute(CommandLine cmd) throws Exception { | |
|
||
logger.info("Creating " + keyType + " in token " + tokenName); | ||
|
||
if ("RSA".equalsIgnoreCase(keyType)) { | ||
Usage[] usages = null; | ||
Usage[] usagesMask = null; | ||
|
||
if ("RSA".equalsIgnoreCase(keyType)) { | ||
if (keySize == null) keySize = "2048"; | ||
Usage[] usages = keyWrap ? CryptoUtil.RSA_KEYPAIR_USAGES : null; | ||
Usage[] usagesMask = keyWrap ? CryptoUtil.RSA_KEYPAIR_USAGES_MASK : null; | ||
if (opsFlag != null && !opsFlag.isEmpty()) { | ||
usages = CryptoUtil.generateUsage(opsFlag); | ||
} else { | ||
usages = keyWrap ? CryptoUtil.RSA_KEYPAIR_USAGES : null; | ||
} | ||
if (opsFlagMask != null && !opsFlagMask.isEmpty()) { | ||
usagesMask = CryptoUtil.generateUsage(opsFlagMask); | ||
} else { | ||
usagesMask = keyWrap ? CryptoUtil.RSA_KEYPAIR_USAGES_MASK : null; | ||
} | ||
|
||
KeyPair keyPair = nssdb.createRSAKeyPair( | ||
token, | ||
|
@@ -164,9 +185,14 @@ public void execute(CommandLine cmd) throws Exception { | |
keyInfo.setAlgorithm(privateKey.getAlgorithm()); | ||
|
||
} else if ("EC".equalsIgnoreCase(keyType)) { | ||
|
||
Usage[] usages = null; | ||
Usage[] usagesMask = sslECDH ? CryptoUtil.ECDH_USAGES_MASK : CryptoUtil.ECDHE_USAGES_MASK; | ||
if (opsFlag != null && !opsFlag.isEmpty()) { | ||
usages = CryptoUtil.generateUsage(opsFlagMask); | ||
} | ||
if (opsFlagMask != null && !opsFlagMask.isEmpty()) { | ||
usagesMask = CryptoUtil.generateUsage(opsFlagMask); | ||
} else { | ||
usagesMask = sslECDH ? CryptoUtil.ECDH_USAGES_MASK : CryptoUtil.ECDHE_USAGES_MASK; | ||
} | ||
|
||
KeyPair keyPair = nssdb.createECKeyPair( | ||
token, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,13 @@ To install a new KRA with the legacy sequential serial numbers specify the follo | |
|
||
* `pki_key_id_generator=legacy` | ||
* `pki_request_id_generator=legacy` | ||
|
||
|
||
== Add pki_<cert_id>_opsFlag and pki_<cert_id>_opsFlagMask parameters == | ||
|
||
Two new parameters are added to pkispawn configuration for setting the key flags in HSM. | ||
The new parameters are available for all certificates created during the subsystem installation | ||
and their value is a comma separated list of the following flags: encrypt, decrypt, sign, | ||
sign_recover, verify, verify_recover, wrap, unwrap and derive. The first parameter add flags to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest adding back quotes for the actual values that can be specified in these params, e.g. |
||
the list identified by underneath module while the second remove them. | ||
Default values are empty lists to get the HSM default key flags. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too familiar with how the flag & mask work in NSS, but does this mean the mask should ultimately disable the
sign
operation in NSS so the installation should fail too? Or doesopsFlagMask
simply remove the values fromopsFlag
(in that case the mask might not be that useful since the user can just specify the correctopsFlag
without the masked value in the first place)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opsFlagMask is applied to the flags identified by NSS, then the opsFlag are added to the remaining operation. This test show that the opsFlag are added to the resulting list. (I will change all opsFlag* is opFlags*)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, does it mean the
opsFlag
param overridesopsFlagMask
? Does it work that way too with--keyOpFlagsOn
and--keyOpFlagsOff
incertutil
? We probably should document this behavior.