Key and Certificate Discovery deprecated

Sources and lookup order for the public keys and certificates of recipients

Overview

This article describes the sources from which OX Guard obtains the public keys of recipients, and the order in which OX Guard queries these sources.

The encryption of a mail with PGP requires a PGP public key for each recipient. The encryption of a mail with S/MIME requires an S/MIME certificate for each recipient. OX Guard queries the sources in a fixed order and uses the first valid key or certificate.

Key sources and trust levels

OX Guard marks every key and every certificate with a key source, which the HTTP API returns in the field keySource.name. The key source enables the client and the user to see from which source OX Guard takes a key or a certificate for the encryption.

For PGP keys, every key source has a trust level, and a higher trust level indicates a more trusted key source. OX Guard treats a PGP key as trusted if the trust level of the key source is equal to or greater than the value of com.openexchange.guard.keySources.trustThreshold. All properties for the trust levels are config-cascade aware. Trust levels do not apply to S/MIME certificates.

The tables in the following sections list the key sources of each step that OX Guard performs to find the key or the certificate of a recipient. For PGP keys, the tables also list the properties for the trust levels and the default values of the properties.

PGP keys

Lookup order

OX Guard queries the sources for a PGP public key in the following order:

  1. Uploaded keys
  2. Guard keys
  3. New keys
  4. Autocrypt
  5. Web Key Service
  6. DNS SRV key servers
  7. Trusted key servers
  8. Untrusted key servers
  9. Guest account

Uploaded keys

A user can upload public keys of recipients to OX Guard. The user obtains the public key of a recipient outside of OX Guard, for example directly from the recipient or from a website of the recipient. The user uploads the public key in one of the following ways:

  • The user imports the public key from the attachment of a received mail.
  • The user uploads the public key from a file in the OX Guard settings.

Only the user who uploaded a public key can use the uploaded public key for encryption. If the user sends an encrypted mail to the address of an uploaded public key, OX Guard encrypts the mail with the uploaded public key.

A user can share uploaded public keys with all users of the same context. OX Guard then also uses the shared public keys for the encrypted mails of the other users of the context.

OX Guard first searches the public keys that the sender uploaded and the public keys that other users of the context shared.

Step Key source Description Trust level property Default
1 GUARD_USER_UPLOADED Key uploaded by the sender com.openexchange.guard.keySources.trustLevelGuardUserUploaded 4
1 GUARD_USER_SHARED Key shared with the sender by another user com.openexchange.guard.keySources.trustLevelGuardUserShared 3

Guard keys

OX Guard then searches the keys of the OX Guard users of the deployment.

Step Key source Description Trust level property Default
2 GUARD_KEY_PAIR Key pair of an OX Guard user of the deployment com.openexchange.guard.keySources.trustLevelGuard 5

New keys

OX Guard determines whether the recipient address belongs to a local user of the deployment (by using the Mail Resolver). For a local user without existing PGP keys, OX Guard creates a new key pair if the local user has the capabilities webmail and guard configured (see Capabilities). If the recipient is not a local user or does not have the required capabilities, OX Guard continues with the next source for the recipient key.

Step Key source Description Trust level property Default
3 GUARD_KEY_PAIR Key pair created by OX Guard for a local user com.openexchange.guard.keySources.trustLevelGuard 5

Autocrypt

If a user opens a received mail with an Autocrypt header, OX Guard stores the public key from the Autocrypt header. Only the user who received the mail can use the stored key, and OX Guard uses the stored key if the user sends an encrypted mail to the address of the key.

A user can verify a stored key in the list of Autocrypt keys in the OX Guard settings. If the user turns off the automatic import of Autocrypt keys there, the client asks the user before OX Guard stores a new key. A key that the user confirms in this dialog is verified. OX Guard replaces a verified key with a newer key only after the user confirms the newer key.

The source Autocrypt is only active if the property com.openexchange.guard.autoCryptEnabled is true.

Related specification: Autocrypt Level 1

Step Key source Description Trust level property Default
4 AUTOCRYPT_KEY Key from an Autocrypt header com.openexchange.guard.keySources.trustLevelAutoCrypt 2
4 AUTOCRYPT_KEY_USER_VERIFIED Key from an Autocrypt header, verified by the user com.openexchange.guard.keySources.trustLevelAutoCryptUserVerified 5

Web Key Service

OX Guard queries the Web Key Service of the domain of the recipient address. A Web Key Service publishes keys under the path /.well-known/openpgpkey/ of the domain or of the subdomain openpgpkey.

The source Web Key Service is only active if the property com.openexchange.guard.keySources.WKSEnabled is true.

Related specification: draft-koch-openpgp-webkey-service

Step Key source Description Trust level property Default
5 WKS_SERVER Key from a Web Key Service com.openexchange.guard.keySources.trustLevelWKSServer 3

OX Guard as Web Key Service

Every OX Guard deployment provides a Web Key Service under the path /openpgpkey. The Web Key Service publishes the public keys of all OX Guard users in the deployment. To publish the keys of the users, the deployment requires a route in the ingress from the path /.well-known/openpgpkey/ to the path /openpgpkey/ of the OX App Suite Middleware.

Clients query the Web Key Service of a mail domain with one of two methods:

  • With the advanced method, clients query the subdomain openpgpkey of the mail domain, for example openpgpkey.example.com. The advanced method requires a DNS record and a TLS certificate for the subdomain.
  • With the direct method, clients query the mail domain itself. The direct method requires that the mail domain points to the deployment.

The following command of GnuPG tests the Web Key Service:

gpg --auto-key-locate clear,nodefault,wkd --locate-keys john@example.com

HKP key servers

OX Guard queries the HKP key servers in the following order:

  1. OX Guard looks up the DNS SRV record _hkps._tcp of the domain of the recipient address. If the DNS SRV record _hkps._tcp does not exist, OX Guard looks up the DNS SRV record _hkp._tcp. The property com.openexchange.guard.forceTLSForHKPSRV restricts the connections to HKP key servers from DNS SRV records to TLS.
  2. OX Guard queries the HKP key servers in com.openexchange.guard.trustedPGPDirectory.
  3. OX Guard queries the HKP key servers in com.openexchange.guard.untrustedPGPDirectory.

The source HKP key servers is only active if the property com.openexchange.guard.keySources.HKPEnabled is true.

Related specification: draft-ietf-openpgp-hkp

Related RFCs: RFC 2782, RFC 4033

Step Key source Description Trust level property Default
6 HKP_SRV_DNSSEC_SERVER Key from an HKP key server of a DNS SRV record that is validated with DNSSEC com.openexchange.guard.keySources.trustLevelHKPSRVDNSSECServer 4
6 HKP_SRV_SERVER Key from an HKP key server of a DNS SRV record com.openexchange.guard.keySources.trustLevelHKPSRVServer 4
7 HKP_TRUSTED_SERVER Key from an HKP key server in com.openexchange.guard.trustedPGPDirectory com.openexchange.guard.keySources.trustLevelHKPTrustedServer 5
8 HKP_PUBLIC_SERVER Key from an HKP key server in com.openexchange.guard.untrustedPGPDirectory com.openexchange.guard.keySources.trustLevelHKPPublicServer 1

The two properties com.openexchange.guard.trustedPGPDirectory and com.openexchange.guard.untrustedPGPDirectory differ in the trust of the listed HKP key servers. OX Guard assigns the key source HKP_TRUSTED_SERVER to keys from the HKP key servers in com.openexchange.guard.trustedPGPDirectory, and the key source HKP_PUBLIC_SERVER to keys from the HKP key servers in com.openexchange.guard.untrustedPGPDirectory. The trust level of HKP_TRUSTED_SERVER is higher than the trust level of HKP_PUBLIC_SERVER. An HKP key server that the operator does not control, for example a public key server, belongs in com.openexchange.guard.untrustedPGPDirectory.

OX Guard as HKP key server

Every OX Guard deployment provides an HKP key server under the path /pgp. The HKP key server publishes the public keys of all OX Guard users in the deployment.

Publishing

HKP clients find the HKP key server of a mail domain through the DNS SRV record _hkps._tcp or _hkp._tcp of the domain and query the path /pks/lookup on the target host of the DNS SRV record. To publish the keys of the users, the deployment requires a DNS SRV record for each mail domain and a route in the ingress from the path /pks to the path /pgp of the OX App Suite Middleware. The following DNS SRV record points to the deployment appsuite.example.com:

_hkps._tcp.example.com. 3600 IN SRV 10 1 443 appsuite.example.com.

A lookup request for the address of a user of the deployment tests the HKP key server:

https://appsuite.example.com/pks/lookup?op=index&search=john@example.com

The HKP key server returns the public keys of the user.

Key exchange between deployments

To use the HKP key server of another OX Guard deployment as a trusted source for PGP public keys, a deployment adds the URL of the HKP key server to com.openexchange.guard.trustedPGPDirectory:

com.openexchange.guard.trustedPGPDirectory=https://appsuite.example.com/pks/lookup?

The HKP key server can also create a key pair for a user who has no key yet. The function is intended for two separate OX Guard deployments that trust each other, for example the deployments of two cooperating providers, and not for other HKP clients. If a user of one deployment encrypts a mail to a user of the other deployment who has no key yet, the other deployment creates a key pair for the recipient. The HKP key server creates the key pair only if the caller is listed in com.openexchange.guard.publicKeyWhitelist, a comma-separated list of IP addresses and networks in CIDR notation. For all other callers, the HKP key server returns only existing keys, so that a mass search does not create key pairs for many users. A lookup request from a caller in the list therefore creates a key pair for a user without a key.

The OX App Suite Middleware determines the IP address of a caller from the header X-Forwarded-For. Behind a chain of proxies, the property com.openexchange.server.knownProxies has to list the inner proxies, so that the OX App Suite Middleware finds the IP address of the caller.

Guest account

If no source provides a key, OX Guard creates a guest account for the recipient. During the encryption of the mail, OX Guard creates a new key pair for the guest account. The recipient reads the mail through the guest account. A guest cannot create another guest account.

Step Key source Description Trust level property Default
9 GUARD_KEY_PAIR Key pair created by OX Guard for a guest account com.openexchange.guard.keySources.trustLevelGuard 5

S/MIME certificates

Lookup order

OX Guard queries the sources for an S/MIME certificate in the following order:

  1. Stored certificates
  2. Public key infrastructures

OX Guard trusts an S/MIME certificate if the certificate chain is verified against a trusted certificate authority. The section Certificate authorities describes the trusted certificate authorities. The trust levels of the key sources do not apply to S/MIME certificates.

Stored certificates

OX Guard stores the S/MIME certificates of its users in the database. OX Guard also stores certificates of recipients from two sources if the certificate chain is verified:

  • A user uploads the certificate of a recipient.
  • A user opens a received mail with a verified signature, and OX Guard takes the certificate of the signer from the signature.

A stored certificate is available to all users in the deployment. OX Guard searches the stored certificates by the address of the recipient and uses a certificate only if the certificate is valid for encryption, is not expired, and the certificate chain is verified against a certificate authority that the sender trusts.

If several valid certificates are stored for an address, the recipient's own certificate takes precedence if the recipient is an OX Guard user of the deployment. Otherwise, OX Guard selects the most recent certificate that the sender uploaded or received, and as a last option the most recent of all valid certificates for the address.

Step Key source Description
1 GUARD_CERTIFICATES Certificate stored by OX Guard

Public key infrastructures

OX Guard supports several public key infrastructures as sources for S/MIME certificates. The operator has to enable each public key infrastructure explicitly. OX Guard queries every enabled public key infrastructure. The article PKI gives an overview of the supported public key infrastructures.

LDAP

OX Guard searches the configured LDAP servers for the recipient address in the attribute mail and reads the certificate from the attribute userCertificate. The article LDAP describes the configuration of the lookup in LDAP.

The source LDAP is only active if the property com.openexchange.guard.pki.ldap.enabled is true and the property com.openexchange.guard.pki.ldap.clientId lists at least one LDAP server.

Step Key source Description
21 LDAP: <clientId> Certificate from the LDAP server with the client id <clientId>

EJBCA

EJBCA is a certificate authority software that issues and manages certificates. OX Guard searches the certificates of an EJBCA server for a certificate of the recipient address. OX Guard accesses the EJBCA server through the REST API of EJBCA.

The property com.openexchange.guard.pki.ejbca.enabled enables EJBCA in general. OX Guard uses EJBCA not only for the lookup of certificates but also for other functions. Therefore, the separate property com.openexchange.guard.pki.ejbca.lookupAvail enables the lookup of certificates, and the source EJBCA is only active if both properties are true. The article EJBCA describes the connection to the EJBCA server.

Step Key source Description
21 EJBCA Certificate from the EJBCA server

1 All public key infrastructures belong to the same step of the lookup order. OX Guard queries the enabled public key infrastructures in no fixed order and uses the first certificate found.