Purpose
An ABAP system calls SAP Cloud Integration through a SOAP consumer proxy and authenticates with an X.509 client certificate. On BTP you create a service key with key type Certificate, and SAP generates the certificate and private key for you. The ABAP side needs them as an SSL client PSE in STRUST, assigned to the logical port in SOAMANAGER.
Done by hand, that is a chain of small steps, and every one of them has a trap:
- The service key JSON stores certificate and key with
\nescapes. People delete them instead of turning them into line breaks, and openssl fails. - The PSE is built with
sapgenpseandSECUDIR. One wrongSECUDIRor the nameSAPSSLS.pse, and you overwrite the system's SSL server PSE. - The target's leaf certificate gets imported as trusted instead of its CA. It works until the day the server certificate is renewed.
- Private keys stay behind in home directories, mail and shared folders.
- Certificates expire, and nobody wrote down when.
Certificates are renewed regularly, so this is a task that comes back. I wanted it done the same way every time.
What the script does
Swipe to see the whole diagram. One run on the application server as <sid>adm. Only the STRUST import and the logical port stay manual.
Proxy and CLI setup
It takes the proxy from -P, K2P_PROXY or the shell, or asks for it. It finds the btp CLI the same way.
Pick the key
You get menus for the subaccount, the service instance and the service key. It runs btp login only if you are not logged on.
Download
The credentials go straight into a private temp folder. They are never printed, and they are shredded at the end.
Checks
Certificate and key are extracted with real line breaks. The script checks that the chain is present, that the key matches the certificate, and that it has not expired, and it warns 30 days before expiry.
PKCS#12 → PSE
openssl builds the PKCS#12, with SAP-readable encryption on OpenSSL 3. sapgenpse import_p12 then runs with SECUDIR set to a folder you choose.
Verify
sapgenpse get_my_name shows the own certificate of the new PSE.
Target CA (optional)
It saves the CA certificates of the Cloud Integration host for STRUST, never the leaf.
Summary
A text file with the source of the key, subject, issuer, expiry date and the remaining SAP GUI steps. No secrets.
Lesson learned: the btp CLI does not see Cloud Foundry keys
In the first real run the btp CLI listed all service instances of the subaccount, including the Cloud Integration runtime instance, but showed no service keys for it. That instance runs in the Cloud Foundry environment, and its keys are Cloud Foundry service keys. The BTP cockpit shows them, the btp CLI does not.
So the script now has a second route. If the btp CLI returns no keys for the instance, it reads the Cloud Foundry org and API endpoint from the subaccount, runs cf login if needed, and reads the keys through the CF v3 API:
btp --format json list accounts/environment-instance --subaccount <id> # org + API endpoint
cf curl "/v3/service_instances?names=<instance>&organization_guids=<org>"
cf curl "/v3/service_credential_bindings?type=key&service_instance_guids=<guid>"
cf curl "/v3/service_credential_bindings/<key-guid>/details" # credentials
Reading the key details needs the Space Developer role in that space. The script tells you if Cloud Foundry refuses.
Using it
Interactive
./btp_key2pse.sh
It asks for everything it doesn't know: proxy, btp folder, subaccount, instance, key, PSE file name, temp folder and SECUDIR folder.
Command line
./btp_key2pse.sh -N -O -a "<subaccount>" -i <instance> -b <service-key> \
-n <PSE-name> -w /tmp -s ~/btp_pse -t <cpi-runtime-host>
Site defaults
The script contains no customer values. Put yours once into <sid>adm's profile or a small wrapper:
export K2P_PROXY=<proxy-host>:<port>
export K2P_BTP_DIR=<folder with btp and cf>
Options
| Option | Meaning |
|---|---|
-a / -i / -b | Subaccount (name, subdomain or GUID), service instance, service key |
-k file | Use a key JSON downloaded from the cockpit instead of the CLIs |
-n | PSE file name. The STRUST identity is chosen at import. |
-w / -s | Temp folder (only its own sub-folder is shredded) / SECUDIR folder for sapgenpse |
-t host | Save the target's CA certificates for STRUST |
-N | No password on the PKCS#12 and no PIN on the PSE |
-O | Overwrite an existing PSE without asking (otherwise: overwrite / new name / quit) |
-R auto|sm|cf | Where to read keys: btp CLI, Cloud Foundry, or automatic |
-P / -B / -C / -U | Proxy, btp folder, cf folder, btp CLI server URL |
-g / -S | Global account subdomain for btp login / log on with SSO |
Safety built in
- Refuses system PSE names (
SAPSSLS,SAPSSLC,SAPSYS…), any/usr/sap/*/secfolder, the session's ownSECUDIRand any folder that already holds system PSEs. - A re-generated PSE is built under a temporary name. It replaces the old file only after sapgenpse succeeded, so a failed run leaves the working PSE alone.
- Credentials, private key and PKCS#12 live only in a private temp folder (
umask 077) and are shredded on exit, also on errors and Ctrl-C. - Passwords and PINs are typed in or left empty. They are never passed as options and never land in shell history.
- For STRUST it saves the target's CA, never the leaf certificate.
The manual part
Transfer
Copy the .pse to your PC via a secure transfer.
STRUST identity
Environment → SSL Client Identities → create the identity (for a renewal, export the current PSE first).
Import
Change mode → PSE → Import → PSE → Save as → SSL Client → your identity. Check that all application servers are green.
Trust the target
Same node: import the target CA → Add to Certificate List → Save.
SOAMANAGER
Logical port → Consumer Security → X.509 SSL Client Certificate → your identity.
Test
Ping Web Service and one real call: the ping proves TLS, only a real call proves the certificate is accepted. Then delete the .pse from the PC and the server.
Is this the best way?
It is the right way for SAP-generated certificates (service key type Certificate): quick, no CA process, and the script removes the manual risks.
The alternative is key type External Certificate. There you create the key pair and the certificate request in STRUST, have it signed by a CA, and register only the certificate on BTP. The private key then never leaves the ABAP system.
The chain must end in a root CA that SAP BTP trusts, so self-signed certificates are rejected. If your security policy requires keys to be created on the system that uses them, it is still the cleaner long-term pattern.
Practical tips
Use scp/WinSCP. If you paste it, use cat > btp_key2pse.sh + paste + Ctrl-D, or :set paste in vi first. Plain vi auto-indent shifts every line and breaks the embedded Python. Then check the md5 below.
Many <sid>adm accounts use csh as login shell. The script runs in bash through its shebang, but multi-line commands pasted at a csh prompt fail. Start bash first.
- Needs openssl, sapgenpse, and python3 or RHEL's
/usr/libexec/platform-python(Python 3.6 is enough). - Write the expiry date from the summary into your calendar. Renewal is the same run, and saving the new PSE as the same STRUST identity keeps the logical ports unchanged.
- Run it on a non-production system first.
Download
46d735c846b72925b9c7ac389d864e25Provided as is, without warranty. Test it on a non-production system first.