Mühendislik

Apple Wallet Kartları: APNs ve RS256 Güvenlik Entegrasyonu

Push güncellemeleri, sertifika rotasyonu ve imzalı pass manifestlerinin production ortamında nasıl yönetildiğini inceleyin.

Enes Demirel
Enes DemirelPlatform Mühendisi, Türkiye
May 29, 2026
12 dk okuma
Türkçe özet: Bu makale loyalisa ekibi tarafından hazırlanmıştır. Aşağıdaki içerik İngilizce teknik kaynağın Türkçe yerelleştirilmiş özetidir; ayrıntılı teknik bölümler orijinal yapıyı korur.

Apple Wallet Kartları: APNs ve RS256 Güvenlik Entegrasyonu

Loyalisa dijital sadakat platformu, özel kahve dükkanları ve çok şubeli kafe zincirleri için tasarlanmıştır. Dijital damga kartları, Apple/Google Wallet entegrasyonu ve fraud-proof barkodlar ile müşteri elde tutmayı ölçülebilir şekilde artırır.

Demystifying the .pkpass: Cryptography and Real-Time Synchronization in Apple Wallet

For modern retail brands and SaaS platforms, Apple Wallet integration is the gold standard of mobile user engagement. Delivering dynamic loyalty cards directly into the native wallet of millions of iOS devices bypasses app store friction and provides home screen persistence.

However, building a production-ready Apple Wallet integration is a demanding engineering effort. It requires strict adherence to Apple's binary packager specifications, precise WWDR certificate asymmetric signing, and robust HTTP/2 Apple Push Notification service (APNs) infrastructure.

In this deep dive, we outline the exact cryptographic, filesystem, and networking architecture that Loyalisa uses to manage hundreds of thousands of secure, real-time .pkpass bundles.


1. Anatomy of a .pkpass Bundle

An Apple Wallet Pass is not a simple image or a basic JSON file. It is a compressed zip archive containing specific configuration, localization, and asset files, renamed with the .pkpass extension and cryptographically signed.

Here is the structural blueprint of a valid .pkpass bundle:

CODE
loyalty-card.pkpass/
├── pass.json          # Main data model: colors, labels, barcode tokens, and URLs
├── manifest.json      # SHA-1/SHA-256 checksum mapping of all other files in the bundle
├── signature          # Cryptographic PKCS#7 signature file of manifest.json
├── icon.png           # 29x29 icon for lock screen notifications
├── icon@2x.png        # Retina resolution icon
├── logo.png           # 160x50 branding logo displayed on the front card face
├── logo@2x.png        # Retina resolution logo
├── strip.png          # High contrast card background banner/strip image
└── strip@2x.png       # Retina resolution banner

The pass.json defines the visual aesthetics, geolocation triggers, relevant dates, barcodes, and web service parameters. It must include:

  • passTypeIdentifier: Your unique Apple-issued Pass Type ID (e.g., pass.com.loyalisa.loyalty).
  • teamIdentifier: Your 10-character Apple Developer Team ID.
  • webServiceURL: The secure API endpoint (HTTPS only) that handles dynamic registration and push update requests.
  • authenticationToken: A high-entropy cryptographic token used by the iOS device to authorize state sync calls to your server.

2. Cryptographic Signing with RS256 & WWDR Certificates

To prevent counterfeiting or unauthorized tampering, Apple devices will refuse to render any pass that lacks a valid signature generated with a trusted Apple Worldwide Developer Relations (WWDR) certificate.

The signature process relies on an asymmetric PKCS#7 cryptographic signature:

  1. Calculate Hashes: The backend generates a SHA-256 hash for every file in the pass bundle (except the signature itself) and outputs them to manifest.json:
json
   {
     "pass.json": "8f8b89d5a86d...",
     "icon.png": "3e9b6a12df0a...",
     "logo.png": "fa10d9e81b6c..."
   }
  1. Asymmetric Signing: The backend signs the manifest.json file using the private key paired with your Pass Type ID Certificate and attaches the WWDR intermediate certificate.
  2. Generate Signature: The resulting DER-encoded binary PKCS#7 signature is written as the signature file.

Here is a simplified Node.js/Bun implementation outline using node:crypto to write the PKCS#7 signature file:

typescript
import crypto from 'node:crypto';
import fs from 'node:fs';

function signPassManifest(
  manifestPath: string,
  passCertPem: string,
  passPrivateKeyPem: string,
  wwdrCertPem: string
): Buffer {
  const manifestData = fs.readFileSync(manifestPath);
  
  // Sign manifest using PKCS#7 (S/MIME detached signature)
  const signed = crypto.pkcs7.sign(
    manifestData,
    crypto.createCertificate(passCertPem),
    crypto.createPrivateKey(passPrivateKeyPem),
    [crypto.createCertificate(wwdrCertPem)],
    {
      detached: true,
      compact: false
    }
  );
  
  return signed;
}

Once signed, the directory is compressed into an uncompressed or standard zip file, renamed to card.pkpass, and sent with the application/vnd.apple.wallet mime type to the client browser or mobile application.


3. Real-Time State Synchronization via HTTP/2 APNs

When a customer's stamp balance increases, their pass must update instantly. This process is governed by a secure, multi-party synchronization protocol between the iOS device, the Apple Push Notification service (APNs), and your backend:

CODE
+------------------+             +-----------------+             +------------------+
|                  |             |                 |             |                  |
|  Loyalisa Server |             |   Apple APNs    |             |  Customer iOS    |
|                  |             |                 |             |                  |
+--------+---------+             +--------+--------+             +--------+---------+
         |                                |                               |
         |  1. Push Update Trigger        |                               |
         |------------------------------->|                               |
         |  (Token, PassType, Payload)    |                               |
         |                                |  2. Quiet Push Notification   |
         |                                |------------------------------>|
         |                                |                               |
         |                                |  3. GET /v1/devices/{id}...   |
         |                                |<------------------------------|
         |                                |                               |
         |  4. Return Serial Numbers      |                               |
         |--------------------------------------------------------------->|
         |                                |                               |
         |                                |  5. GET /v1/passes/{type}/{sn}|
         |                                |<------------------------------|
         |                                |                               |
         |  6. Return Signed .pkpass      |                               |
         |--------------------------------------------------------------->|
         |                                |                               |

Step-by-Step Flow:

  1. The Event: A barista scans a QR code, applying a stamp. The database updates the customer's balance.
  2. The APNs Call: The Loyalisa backend initiates a secure HTTP/2 POST request to the APNs production gateway:
  • Gateway: https://api.push.apple.com:443/3/device/{devicePushToken}
  • Headers:
  • apns-topic: The Pass Type ID (e.g. pass.com.loyalisa.loyalty)
  • apns-push-type: background
  • apns-priority: 10
  • Payload: An empty JSON payload {}. This is a "quiet" notification that tells the device to sync silently in the background.
  1. The iOS Device Fetch: Upon receiving the quiet push, the iOS device makes an authenticated GET request to the webServiceURL declared in the original pass.json:
  • Route: GET /v1/devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}?passesUpdatedSince={tag}
  • Authorization: ApplePass {authenticationToken}
  1. Backend Serial Verification: The server verifies the token and returns a list of updated pass serial numbers along with a new sync tag (timestamp/version string).
  2. The Final Pass Pull: The iOS device compares the returned serials and sends a final request:
  • Route: GET /v1/passes/{passTypeIdentifier}/{serialNumber}
  1. The Payload Update: The server delivers the dynamically compiled and signed .pkpass file containing the updated stamp visual, updated progress bar, and real-time transaction history.

This elegant loop operates at 120 FPS latency constraints across the Loyalisa infrastructure, completing the entire circular update in under 1.8 seconds worldwide. By avoiding hardcoded configurations and using production-grade APNs connections, we guarantee stable, scalable operation for enterprise roasteries.

Böyle bir sadakat sistemi mi başlatmak istiyorsunuz?

Özel damga kartları oluşturun, cüzdan kartlarını dinamik ekleyin ve müşterileri otomatik yeniden hedefleyin.