# ACE-88 Authentication Context Extension (RFC 7773)
`synta.AuthenticationContextsBuilder` constructs DER-encoded
`AuthenticationContexts` structures for the `id-ce-authContext` X.509v3
extension (OID `1.2.752.201.5.1`), as defined in RFC 7773. The builder is
exported directly from the top-level `synta` module.
The authentication context extension binds one or more authentication context
identifiers to an end-entity certificate. Each context entry has a mandatory
`contextType` URI and an optional `contextInfo` URL pointing to a machine- or
human-readable document that describes the context. The resulting DER bytes go
inside the OCTET STRING wrapper of an `Extension` SEQUENCE.
This extension is used by the Swedish e-ID infrastructure
(e-Legitimationsnämnden) to link certificates to specific authentication
frameworks.
## AuthenticationContextsBuilder
Fluent builder for an `AuthenticationContexts` DER SEQUENCE OF (RFC 7773 /
ACE-88).
At least one entry must be added before calling `build()`.
```python
class AuthenticationContextsBuilder:
def __init__(self) -> None: ...
def add(
self,
context_type: str,
context_info: str | None = None,
) -> AuthenticationContextsBuilder: ...
# Add an AuthenticationContext entry.
# context_type: URI string identifying the authentication context,
# e.g. "urn:id:skatteverket:2:1.0".
# context_info: optional URL pointing to a document describing the context,
# or None to omit the field.
# Raises ValueError if DER encoding fails (deferred to build()).
def build(self) -> bytes: ...
# Build the DER-encoded AuthenticationContexts SEQUENCE OF.
# Raises ValueError if no entries were added or DER encoding fails.
```
## Extension OID
| `1.2.752.201.5.1` | `id-ce-authContext` | Authentication Contexts extension |
## Usage
### Single context, no context info
```python,ignore
import synta
extn_der = (
synta.AuthenticationContextsBuilder()
.add("urn:id:skatteverket:2:1.0")
.build()
)
```
### Multiple contexts with context info URLs
```python,ignore
import synta
extn_der = (
synta.AuthenticationContextsBuilder()
.add(
"urn:id:skatteverket:2:1.0",
"https://www.skatteverket.se/ac/context2.xml",
)
.add(
"urn:id:skatteverket:1:1.0",
"https://www.skatteverket.se/ac/context1.xml",
)
.build()
)
```
### Embedding in a certificate extension
The bytes from `build()` are the raw `extnValue` content. To embed the
extension in a certificate, wrap the DER in an OCTET STRING and encode the
`Extension` SEQUENCE:
```python,ignore
import synta
extn_der = (
synta.AuthenticationContextsBuilder()
.add("urn:id:skatteverket:2:1.0")
.build()
)
# OID arc components for id-ce-authContext
ID_CE_AUTH_CONTEXT = [1, 2, 752, 201, 5, 1]
# Build the Extension SEQUENCE and add it to a certificate builder
cert_der = (
synta.CertificateBuilder()
# ... set subject, issuer, validity, public key ...
.extension(ID_CE_AUTH_CONTEXT, critical=False, value=extn_der)
.build()
)
```
See also [X.509 Extension Value Builders](ext-builders.md) for the standard
extension value helpers, and [Logotype Extension](logotype.md) for another
X.509v3 extension builder.