Documentation
¶
Overview ¶
Package attestation provides device attestation verification for iOS App Attest and Android Play Integrity.
This library allows server-side verification of device authenticity to ensure requests are coming from legitimate, unmodified apps running on genuine devices.
iOS App Attest ¶
Verifies attestations and assertions from Apple's App Attest service. See: https://developer.apple.com/documentation/devicecheck/establishing_your_app_s_integrity
Android Play Integrity ¶
Verifies integrity tokens from Google's Play Integrity API. See: https://developer.android.com/google/play/integrity
Basic Usage ¶
verifier, err := attestation.NewVerifier(attestation.Config{
IOSBundleIDs: []string{"com.example.app"},
IOSTeamID: "TEAM123456",
AndroidPackageNames: []string{"com.example.app"},
GCPProjectID: "my-project",
})
result, err := verifier.Verify(ctx, &attestation.Request{
Platform: attestation.PlatformIOS,
Attestation: attestationData,
Challenge: challenge,
KeyID: keyID,
BundleID: "com.example.app",
})
Package attestation provides device attestation verification for iOS App Attest and Android Play Integrity.
This library allows server-side verification of device authenticity to ensure requests are coming from legitimate, unmodified apps running on genuine devices.
iOS App Attest ¶
Verifies attestations and assertions from Apple's App Attest service. See: https://developer.apple.com/documentation/devicecheck/establishing_your_app_s_integrity
Android Play Integrity ¶
Verifies integrity tokens from Google's Play Integrity API. See: https://developer.android.com/google/play/integrity
Basic Usage ¶
verifier, err := attestation.NewVerifier(attestation.Config{
IOSBundleIDs: []string{"com.example.app"},
IOSTeamID: "TEAM123456",
AndroidPackageNames: []string{"com.example.app"},
GCPProjectID: "my-project",
})
if err != nil {
log.Fatal(err)
}
result, err := verifier.Verify(ctx, &attestation.Request{
Platform: attestation.PlatformIOS,
Attestation: attestationData,
Challenge: challenge,
KeyID: keyID,
BundleID: "com.example.app",
})
Subpackages ¶
The library is organized into the following subpackages:
- ios: iOS App Attest verification (attestation and assertion)
- android: Android Play Integrity verification
- challenge: Secure challenge generation and validation
For more details, see the README at https://github.com/kacy/device-attestation
Index ¶
- Variables
- type AndroidConfig
- type AssertionRequest
- type Config
- type IOSConfig
- type Platform
- type Request
- type Result
- type Server
- func (s *Server) Challenges() challenge.Store
- func (s *Server) Close() error
- func (s *Server) GenerateChallenge(identifier string) (string, error)
- func (s *Server) KeyStore() ios.KeyStore
- func (s *Server) Verifier() Verifier
- func (s *Server) VerifyAssertion(ctx context.Context, req AssertionRequest) (*Result, error)
- func (s *Server) VerifyAttestation(ctx context.Context, identifier string, req VerifyRequest) (*Result, error)
- type ServerConfig
- type Verifier
- type VerifyRequest
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidAttestation = errors.New("invalid attestation") ErrAttestationExpired = errors.New("attestation expired") ErrUnsupportedPlatform = errors.New("unsupported platform") ErrVerificationFailed = errors.New("attestation verification failed") ErrMissingAttestation = errors.New("missing attestation data") ErrInvalidBundleID = errors.New("invalid bundle ID") ErrInvalidKeyID = errors.New("invalid key ID") ErrInvalidChallenge = errors.New("invalid challenge") ErrInvalidPackageName = errors.New("invalid package name") ErrDeviceCompromised = errors.New("device integrity check failed") ErrAppNotRecognized = errors.New("app not recognized") ErrNotConfigured = errors.New("platform not configured") )
Common errors returned by the attestation package.
Functions ¶
This section is empty.
Types ¶
type AndroidConfig ¶
type AndroidConfig struct {
// PackageNames is the list of allowed app package names (required).
PackageNames []string
// GCPProjectID is your Google Cloud project ID (required).
GCPProjectID string
// GCPCredentialsFile is the path to service account credentials (optional).
// If empty, uses Application Default Credentials.
GCPCredentialsFile string
// APKCertDigests is the list of allowed APK signing certificate SHA-256 digests (optional).
APKCertDigests []string
// RequireStrongIntegrity requires hardware-backed attestation (default: false).
RequireStrongIntegrity bool
}
AndroidConfig holds Android-specific configuration.
type AssertionRequest ¶
type AssertionRequest struct {
// Assertion is the base64-encoded assertion from the device.
Assertion string
// ClientData is the request-specific data that was signed.
ClientData []byte
// KeyID is the key identifier from the original attestation.
KeyID string
// BundleID is the app bundle identifier.
BundleID string
}
AssertionRequest contains the assertion data from the client.
type Config ¶
type Config struct {
// iOS App Attest configuration
IOSBundleIDs []string
IOSTeamID string
// Android Play Integrity configuration
AndroidPackageNames []string
AndroidAPKCertDigests []string
GCPProjectID string
GCPCredentialsFile string
// Shared configuration
ChallengeTimeout time.Duration
HTTPClient *http.Client
// Device integrity requirements
// When true, Android requires MEETS_STRONG_INTEGRITY verdict
RequireStrongIntegrity bool
// KeyStore for storing iOS attestation public keys (optional).
// Required for assertion verification.
KeyStore ios.KeyStore
// SkipCertificateVerification skips the certificate chain verification for iOS.
// WARNING: Only use this for development/testing. Never in production!
SkipCertificateVerification bool
}
Config holds configuration for the attestation verifier.
type IOSConfig ¶
type IOSConfig struct {
// BundleIDs is the list of allowed app bundle identifiers (required).
BundleIDs []string
// TeamID is your Apple Developer Team ID (required).
TeamID string
}
IOSConfig holds iOS-specific configuration.
type Request ¶
type Request struct {
// Platform is the mobile platform (ios or android).
Platform Platform
// Attestation is the base64-encoded attestation data.
// For iOS: the attestation object from DCAppAttestService.attestKey
// For Android: the integrity token from Play Integrity API
Attestation string
// Challenge is the server-generated challenge that was signed.
Challenge string
// KeyID is the key identifier (iOS only).
// This is the key ID returned by DCAppAttestService.generateKey
KeyID string
// BundleID is the app bundle identifier (iOS only).
BundleID string
}
Request represents an attestation or assertion verification request.
type Result ¶
type Result struct {
// Valid indicates whether the attestation was successfully verified.
Valid bool
// DeviceID is a unique identifier for the device/key.
// For iOS: the key ID
// For Android: derived from the nonce
DeviceID string
// Platform is the verified platform.
Platform Platform
// Timestamp is when the verification was performed.
Timestamp time.Time
}
Result represents the result of attestation verification.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server provides a batteries-included attestation server that handles challenge generation, validation, and key storage automatically.
This is the recommended way to use the library for most use cases. For advanced customization, use NewVerifier directly with your own challenge store and key store implementations.
func NewServer ¶
func NewServer(cfg ServerConfig) (*Server, error)
NewServer creates a new attestation server with sensible defaults.
Example:
server, err := attestation.NewServer(attestation.ServerConfig{
IOS: &attestation.IOSConfig{
BundleIDs: []string{"com.example.app"},
TeamID: "ABCD123456",
},
Android: &attestation.AndroidConfig{
PackageNames: []string{"com.example.app"},
GCPProjectID: "my-project",
},
})
func (*Server) Challenges ¶
Challenges returns the underlying challenge store for advanced use cases.
func (*Server) GenerateChallenge ¶
GenerateChallenge creates a new challenge for the given identifier. The identifier should be unique per attestation flow (e.g., user ID, session ID).
Returns the challenge string that should be sent to the client.
func (*Server) VerifyAssertion ¶
VerifyAssertion verifies an iOS assertion for subsequent requests.
This requires a previous successful attestation for the given KeyID. The assertion counter is automatically tracked to prevent replay attacks.
func (*Server) VerifyAttestation ¶
func (s *Server) VerifyAttestation(ctx context.Context, identifier string, req VerifyRequest) (*Result, error)
VerifyAttestation verifies a device attestation.
The identifier must match the one used in GenerateChallenge. On success, the challenge is consumed and cannot be reused.
Example:
result, err := server.VerifyAttestation(ctx, "user-123", attestation.VerifyRequest{
Platform: attestation.PlatformIOS,
Attestation: attestationFromClient,
Challenge: challengeFromClient,
KeyID: keyIDFromClient,
BundleID: "com.example.app",
})
type ServerConfig ¶
type ServerConfig struct {
// iOS configuration (optional - omit to disable iOS support)
IOS *IOSConfig
// Android configuration (optional - omit to disable Android support)
Android *AndroidConfig
// ChallengeTimeout is how long challenges remain valid (default: 5 minutes).
ChallengeTimeout time.Duration
}
ServerConfig holds configuration for the attestation server.
type Verifier ¶
type Verifier interface {
// Verify verifies an attestation request.
Verify(ctx context.Context, req *Request) (*Result, error)
// VerifyAssertion verifies an iOS assertion (requires KeyStore).
VerifyAssertion(ctx context.Context, req *ios.AssertionRequest) (*Result, error)
}
Verifier verifies device attestations.
func NewVerifier ¶
NewVerifier creates a new attestation verifier.
type VerifyRequest ¶
type VerifyRequest struct {
// Platform is the device platform (PlatformIOS or PlatformAndroid).
Platform Platform
// Attestation is the base64-encoded attestation data from the device.
Attestation string
// Challenge is the challenge that was sent to the client.
Challenge string
// KeyID is the key identifier (iOS only).
KeyID string
// BundleID is the app bundle identifier (iOS only).
BundleID string
}
VerifyRequest contains the attestation data from the client.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package android provides Android Play Integrity verification.
|
Package android provides Android Play Integrity verification. |
|
Package challenge provides secure challenge generation and validation for device attestation flows.
|
Package challenge provides secure challenge generation and validation for device attestation flows. |
|
examples
|
|
|
basic
command
Example: Basic device attestation verification server
|
Example: Basic device attestation verification server |
|
Package ios provides iOS App Attest verification.
|
Package ios provides iOS App Attest verification. |
|
Package redis provides Redis-backed implementations of the challenge store and key store interfaces for distributed deployments.
|
Package redis provides Redis-backed implementations of the challenge store and key store interfaces for distributed deployments. |