Documentation
¶
Overview ¶
Package josebp is a self-contained JOSE (JWS/JWT/JWK/JWE) implementation for the Brainpool elliptic curves used by the gematik telematik infrastructure (IDP-Dienst, SMC-B, ePA).
It deliberately does NOT depend on github.com/lestrrat-go/jwx: the signing/verification crypto is done with stdlib crypto/ecdsa over the Brainpool curve (which jwx cannot do for x5c with a Brainpool cert, opaque smartcard signers, or ECDH-ES over Brainpool). It builds only on the low-level brainpool package (curves, PKI parsers, SignFunc).
Index ¶
- Constants
- func BitSizeForAlg(alg string) (int, error)
- func CurveForJWA(name string) (elliptic.Curve, error)
- func DeriveECDHES(algorithm string, apuData, apvData []byte, privateKey *ecdsa.PrivateKey, ...) ([]byte, error)
- func HashFunctionForCurve(curve elliptic.Curve) (hash.Hash, error)
- func JWAForCurve(curve elliptic.Curve) string
- type Claims
- type Headers
- type JSONWebKey
- type JWEBuilder
- type JWT
- type JWTBuilder
- type VerifierErrorUnsupportedSignatureAlgorithm
- type VerifierFunc
Constants ¶
const ( AlgorithmNameES256 = "ES256" AlgorithmNameES384 = "ES384" AlgorithmNameES512 = "ES512" AlgorithmNameBP256R1 = "BP256R1" AlgorithmNameBP384R1 = "BP384R1" AlgorithmNameBP512R1 = "BP512R1" )
JOSE signature algorithm names used in the gematik telematik infrastructure.
Variables ¶
This section is empty.
Functions ¶
func BitSizeForAlg ¶
BitSizeForAlg returns the curve bit size implied by a JOSE signature algorithm name as used in the gematik stack: ES256/BP256R1 → 256, ES384/BP384R1 → 384, ES512/BP512R1 → 512. It is the basis for the alg↔curve consistency check on verification (rejecting e.g. ES384 with a 256-bit key).
func CurveForJWA ¶
CurveForJWA maps a JOSE "crv" name to a Brainpool elliptic curve.
func DeriveECDHES ¶
func DeriveECDHES(algorithm string, apuData, apvData []byte, privateKey *ecdsa.PrivateKey, publicKey *ecdsa.PublicKey, keySize int) ([]byte, error)
DeriveECDHES performs the ECDH-ES Concat KDF (RFC 7518 §4.6) over an elliptic curve.
func HashFunctionForCurve ¶
HashFunctionForCurve returns the hash to use with ECDSA for the given curve's bit size.
func JWAForCurve ¶
JWAForCurve maps a Brainpool elliptic curve to its JOSE "crv" name.
Types ¶
type JSONWebKey ¶
type JSONWebKey struct {
KeyType string `json:"kty"`
Use string `json:"use,omitempty"`
Algortihm string `json:"alg,omitempty"`
KeyID string `json:"kid,omitempty"`
Key any `json:"-"`
CertificatesRaw [][]byte `json:"x5c,omitempty"`
Certificates []*x509.Certificate `json:"-"`
X string `json:"x"`
Y string `json:"y"`
D string `json:"d,omitempty"`
CurveName string `json:"crv"`
}
JSONWebKey is a Brainpool-aware JWK (RFC 7517) — it understands the "BP-256/384/512" crv names and parses x5c Brainpool certificates via brainpool.ParseCertificate (crypto/x509 cannot).
func (*JSONWebKey) MarshalJSON ¶
func (jwk *JSONWebKey) MarshalJSON() ([]byte, error)
func (*JSONWebKey) UnmarshalJSON ¶
func (jwk *JSONWebKey) UnmarshalJSON(data []byte) error
type JWEBuilder ¶
type JWEBuilder struct {
// contains filtered or unexported fields
}
func NewJWEBuilder ¶
func NewJWEBuilder() *JWEBuilder
func (*JWEBuilder) EncryptECDHES ¶
func (b *JWEBuilder) EncryptECDHES(recipient any) ([]byte, error)
EncryptECDHES builds a compact JWE (alg=ECDH-ES direct, enc=A256GCM) for the recipient's Brainpool public key, as required by the gematik IDP-Dienst. The ephemeral public key (epk) is serialized via josebp.JSONWebKey, so it carries the Brainpool crv (e.g. "BP-256").
func (*JWEBuilder) Header ¶
func (b *JWEBuilder) Header(key string, value any) *JWEBuilder
func (*JWEBuilder) Plaintext ¶
func (b *JWEBuilder) Plaintext(plaintext []byte) *JWEBuilder
type JWT ¶
type JWT struct {
Raw []byte
HeadersJson []byte
PayloadJson []byte
Signature []byte
Headers Headers
Claims Claims
}
func ParseToken ¶
func ParseToken(rawToken []byte, verifiers ...VerifierFunc) (*JWT, error)
type JWTBuilder ¶
type JWTBuilder struct {
// contains filtered or unexported fields
}
func NewJWTBuilder ¶
func NewJWTBuilder() *JWTBuilder
func (*JWTBuilder) Claim ¶
func (b *JWTBuilder) Claim(key string, value any) *JWTBuilder
func (*JWTBuilder) Header ¶
func (b *JWTBuilder) Header(key string, value any) *JWTBuilder
func (*JWTBuilder) Sign ¶
Sign produces a compact JWS over the builder's header + claims, hashing the signing input with hashFunc and signing the digest with signFunc (an opaque SignFunc — software key, smartcard, or connector). The signature is the raw fixed-width r‖s ECDSA encoding (RFC 7518 §3.4).
type VerifierErrorUnsupportedSignatureAlgorithm ¶
type VerifierErrorUnsupportedSignatureAlgorithm error
type VerifierFunc ¶
func WithEcdsaPublicKey ¶
func WithEcdsaPublicKey(pubKey *ecdsa.PublicKey) VerifierFunc
func WithKey ¶
func WithKey(key *JSONWebKey) VerifierFunc