Part 7-8 - JWT, Hardware Tokens & Smart Cards

Updated 5 Oct 2026

7.3 JWT - JSON Web Tokens

Overview:

JWT = JSON Web Token
- Compact
- Self-contained
- URL-safe

Structure: 3 Parts

┌─────────────────────────────────┐
│   Header . Payload . Signature  │
└─────────────────────────────────┘
   Base64    Base64    HMAC/RSA

Part 1: Header

{
  "alg": "HS256",
  "typ": "JWT"
}

Contains:

  • Token type
  • Encryption algorithm

Part 2: Payload

{
  "sub": "1234567890",
  "name": "John Doe",
  "iat": 1516239022
}

Contains:

  • Claims (statements about user)
  • Additional data

Part 3: Signature

HMACSHA256(
  base64UrlEncode(header) + "." +
  base64UrlEncode(payload),
  secret)

Purpose:

  • Verify payload validity
  • Ensure data integrity

Example JWT:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.
SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

7.4 JWT Authentication Flow

┌──────────┐                    ┌──────────┐
│  Client  │                    │  Server  │
└─────┬────┘                    └────┬─────┘
      │                              │
      │ 1. Login (credentials)       │
      ├─────────────────────────────>│
      │                              │
      │                              │ 2. Verify
      │                              │    credentials
      │                              │
      │ 3. JWT Token                 │
      │<─────────────────────────────┤
      │                              │
      │ 4. Store JWT                 │
      │    (localStorage/cookie)     │
      │                              │
      │ 5. Request + JWT             │
      ├─────────────────────────────>│
      │                              │
      │                              │ 6. Verify JWT
      │                              │    signature
      │                              │
      │ 7. Response (if valid)       │
      │<─────────────────────────────┤
      │                              │

7.5 Role of HMAC in JWT

HMAC Ensures:

  1. ✅ Token has not been modified (Integrity)
  2. ✅ Token issued by trusted server (Authenticity)
  3. ✅ Payload cannot be tampered

How HMAC Works:

Input: Header + Payload + Secret Key
   ↓
HMAC-SHA256
   ↓
Output: Signature

Verification:

Server receives JWT:
1. Extract Header + Payload
2. Recompute HMAC with secret key
3. Compare signatures
   ↓
Match? → Valid ✅
No match? → Invalid ❌

Formula: HMAC(header.payload, secret key)=Signature\text{HMAC(header.payload, secret key)} = \text{Signature}

เปรียบเทียบ: HMAC เหมือนซีลป้องกันการปลอมแปลงบนพัสดุ - ถ้าใครพยายามเปิดและแก้ไขเนื้อหา ซีลจะแตก และคุณจะรู้ว่าพัสดุถูกงัดแงะ


7.6 JWT vs Traditional Sessions

Comparison:

FeatureTraditional SessionJWT
StorageServer-sideClient-side
StateStatefulStateless
ScalabilityLimitedExcellent
Mobile/APIDifficultEasy
Load BalancingComplexSimple
ExpirationServer controlsToken expiry

JWT Advantages:

✅ Stateless (no server storage)
✅ Scalable (multiple servers)
✅ Cross-domain
✅ Mobile-friendly
✅ Microservices-ready

Use Cases:

✅ REST APIs
✅ Microservices
✅ Cloud systems
✅ Mobile apps
✅ Single Page Applications (SPA)

เปรียบเทียบ: JWT stateless authentication เหมือนหนังสือเดินทางที่มีข้อมูลครบในตัว - แทนที่จะให้ด่านตรวจคนเข้าเมือง (server) เก็บบันทึกทุกคนที่ผ่าน (session storage) หนังสือเดินทาง (JWT) ของคุณมีข้อมูลทั้งหมดที่ต้องการเพื่อตรวจสอบคุณ ดังนั้นด่านตรวจแค่ตรวจหนังสือเดินทางเองก็พอ


Part 8: Hardware Tokens & Smart Cards

8.1 Hardware Token

Description:

Hardware Token = Small physical device
- Credit card size OR
- Keychain fob size

Features:

✅ Contains certificate/unique identifier
✅ Additional features:
   - LCD display
   - Keypads
   - Biometric readers

Examples:

  • RSA SecurID
  • USB tokens
  • Keychain tokens

How It Works:

1. Generate one-time code
2. Code changes every 30-60 seconds
3. User enters code + PIN
4. Server verifies both
5. Access granted if valid

เปรียบเทียบ: Hardware token เหมือนกุญแจทางกายภาพที่สร้างรหัสพิเศษที่เปลี่ยนทุกนาที ทำให้แทบเป็นไปไม่ได้ที่จะคัดลอกหรือใช้ซ้ำ


8.2 Smart Card

Physical Characteristics:

Size: 85.6 mm × 54 mm (ISO 7816-2)
Form: Credit card-like
Access: Wired or Wireless

Components:

┌─────────────────────────────────┐
│         Smart Card              │
├─────────────────────────────────┤
│  ┌──────────────────────────┐  │
│  │  Processor (CPU)         │  │
│  └──────────────────────────┘  │
│  ┌──────────────────────────┐  │
│  │  Coprocessor (Crypto)    │  │
│  └──────────────────────────┘  │
│  ┌──────────────────────────┐  │
│  │  ROM (Read-Only Memory)  │  │
│  │  - Card number           │  │
│  │  - Cardholder name       │  │
│  └──────────────────────────┘  │
│  ┌──────────────────────────┐  │
│  │  EEPROM (Programmable)   │  │
│  │  - Application data      │  │
│  │  - Programs              │  │
│  └──────────────────────────┘  │
│  ┌──────────────────────────┐  │
│  │  RAM (Temporary Data)    │  │
│  └──────────────────────────┘  │
└─────────────────────────────────┘

Memory Types:

MemoryPurposeExample Data
ROMPermanent dataCard number, Name
EEPROMVariable dataBalance, App data
RAMTemporarySession data

Features:

✅ Own processor
✅ Memory (ROM, EEPROM, RAM)
✅ I/O ports
✅ Crypto co-processor
✅ Execute protocols
✅ Available as USB drive

8.3 Smart Card Activation

Exchange Process:

Smart Card ←─────→ Card Reader

1. Initialize (ATR)
   └─ Answer to Reset
   └─ e.g., clock value

2. Protocol Negotiation (PTS)
   └─ Protocol Type Selection

3. Negotiation Answer (PTS)
   └─ Agreement on protocol

4. Command APDU
   └─ Application Protocol Data Unit
   └─ Request from reader

5. Response APDU
   └─ Response from card

6. End of Session
   └─ Terminate connection

Abbreviations:

  • APDU = Application Protocol Data Unit
  • ATR = Answer to Reset
  • PTS = Protocol Type Selection

เปรียบเทียบ: Smart card activation เหมือนพิธีการจับมือระหว่างทูตสองคน - พวกเขาแนะนำตัวก่อน (ATR), ตกลงภาษาที่จะพูด (PTS), จากนั้นแลกเปลี่ยนข้อความ (APDU)


8.4 Electronic Identity Cards (eID)

Characteristics:

Physical:
- Human-readable data on surface
- Can serve as national ID
- Can serve as driver's license

Digital:
- Access to government services
- Access to commercial services
- Stronger proof of identity
- Verified by national government

Data on eID:

Front:

  • Personal data
  • Document number
  • Card Access Number (CAN)
  • Machine Readable Zone (MRZ)
  • Photo
  • Birth date

Benefits:

✅ Stronger identity proof
✅ Wider variety of applications
✅ Government-verified smart card
✅ Valid and authentic

8.5 eID Functions

Offline Functions (Mandatory)

ePass:

Access Method: Offline inspection systems

Data Available:
- MRZ (Machine Readable Zone)
- Family and given names
- Date and place of birth
- Address and community ID
- Expiration date

Online Functions

eID PIN:

Functions:
1. Verification
   └─ Identity verification

2. Restricted Identification
   └─ Pseudonymous

3. Revocation Query
   └─ Certificate authority check

eSign (Optional):

Functions:
- Electronic signature with eSign PIN
- Signature certificate installed by CA
- Electronic signature key
- X.509 certificate

Abbreviations:

  • CAN = Card Access Number
  • MRZ = Machine Readable Zone
  • PACE = Password Authenticated Connection Establishment
  • PIN = Personal Identification Number

8.6 User Authentication with eID

Process Flow:

┌─────────┐                  ┌─────────────┐               ┌────────────┐
│  User   │                  │   Service   │               │    eID     │
│         │                  │   Provider  │               │   Server   │
└────┬────┘                  └──────┬──────┘               └─────┬──────┘
     │                              │                             │
     │ 1. Request service           │                             │
     │ (via Web browser)            │                             │
     ├─────────────────────────────>│                             │
     │                              │                             │
     │ 2. Redirect to eID server    │                             │
     │ Authentication request       │                             │
     │<─────────────────────────────┤                             │
     │                              │                             │
     │ 3. Redirect                  │                             │
     ├──────────────────────────────┼────────────────────────────>│
     │                              │                             │
     │ 4. Request authentication    │                             │
     │<─────────────────────────────┼─────────────────────────────┤
     │                              │                             │
     │ 5. Enter PIN                 │                             │
     ├──────────────────────────────┼────────────────────────────>│
     │                              │                             │
     │                              │ 6. Auth result forwarded    │
     │                              │<────────────────────────────┤
     │                              │                             │
     │ 7. Access service            │                             │
     │<─────────────────────────────┤                             │
     │                              │                             │

เปรียบเทียบ: การใช้ eID สำหรับ authentication เหมือนการแสดงบัตรประชาชนต่อพนักงานรักษาความปลอดภัยที่โทรหาหน่วยงานเพื่อตรวจสอบตัวตนก่อนปล่อยให้เข้าสถานที่พิเศษ


8.7 Certificate Authentication

Using Certificate to Authenticate Client to Server:

┌──────────────────────────────────────────────┐
│               SSL Connection                 │
└──────────────────────────────────────────────┘

Client Side:                Server Side:
1. User enters            2. Server establishes
   private-key               SSL connection
   password                  across network
   ↓                         ↓
2. Client retrieves       4. Server uses
   private key and           certificate and
   creates digital           identity evidence
   signature                 to authenticate
                             user's identity
                             ↓
                          5. Server authorizes
                             access for user

Process:

1. User Authentication
   └─ Enter private key password

2. SSL Connection
   └─ Establish secure connection

3. Digital Signature Creation
   └─ Client creates evidence using private key

4. Verification
   └─ Server verifies certificate and signature

5. Authorization
   └─ Server grants access

เปรียบเทียบ: Certificate authentication เหมือนการใช้บัตรประชาชนที่ออกโดยรัฐที่มีคุณสมบัติด้านความปลอดภัยแบบโฮโลแกรม - server สามารถตรวจสอบว่า certificate เป็นของแท้ได้โดยตรวจสอบ digital signature เหมือนเจ้าหน้าที่รักษาความปลอดภัยตรวจสอบคุณสมบัติโฮโลแกรมบนบัตรของคุณ


Part 9: Biometric Authentication

9.1 Types of Biometrics

Two Categories:

Static Biometrics (สิ่งที่เป็น - Physical)

1. Facial Characteristics
   - Location of key facial features
   - Face thermogram (infrared)

2. Fingerprints
   - Ridge endings
   - Bifurcations
   - Minutiae (detailed characteristics)

3. Hand Geometry
   - Hand anatomy
   - Finger and palm measurements

4. Retina Pattern
   - Blood vessel pattern on eyeball backside

5. Iris Structure
   - Colored portion of eye
   - Unique patterns, rifts, colors, rings

Dynamic Biometrics (สิ่งที่ทำ - Behavioral)

1. Signature
   - Handwriting patterns
   - Pressure, speed, angle

2. Voice
   - Voice pattern
   - Characteristics
   - Pitch, tone

เปรียบเทียบ: Biometric authentication เหมือนการใช้ร่างกายเป็นกุญแจ / เหมือนเกล็ดหิมะไม่มีสองเกล็ดเหมือนกัน ลายนิ้วมือ, ม่านตา, หรือรูปแบบเสียงไม่มีสองคนเหมือนกันพอดี ทำให้เป็นตัวระบุที่ดีเยี่ยม


9.2 Biometric Details

Fingerprint

Composed of:
- Ridge endings
- Bifurcations
- Minutiae (detailed characteristics)
- Friction ridge patterns

Retina Scan

Scans:
- Blood vessel pattern
- Backside of eyeball
- Very accurate but intrusive

Iris Scan

Features:
- Colored portion of eye
- Surrounds pupil
- Unique patterns
- Rifts, colors, rings
- Coronas, furrows

Accuracy: ✅ Most accurate

Accuracy Ranking:

Most Accurate ────────────→ Least Accurate
Iris > Retina > Fingerprint > Hand > Voice > Signature

9.3 How Iris Scanners Work

Process:

1. Scanner reads iris (outer to pupil edge)
   ↓
2. Maps iris structure
   ↓
3. Plots distinct markings
   ↓
4. Saves data to database
   ↓
5. Compares with database to verify identity

Iris Features Captured:

  • Patterns
  • Rifts
  • Colors
  • Rings
  • Coronas
  • Furrows

9.4 Cost vs Accuracy

Trade-off Analysis:

High Accuracy
     ↑
     │  Iris ●
     │        Retina ●
     │              Fingerprint ●
     │                    Hand ●
     │                         Voice ●
     │                              Signature ●
     └──────────────────────────────────────→
                                        High Cost
BiometricAccuracyCostBest For
IrisVery HighHighHigh security
RetinaVery HighMedium-HighSecure facilities
FingerprintHighMediumGeneral use
HandMediumMediumAccess control
VoiceMedium-LowLowPhone auth
SignatureLow-MediumLowDocuments

เปรียบเทียบ: Biometric authentication methods เหมือนกุญแจหลายประเภท - iris scans เหมือนกุญแจรักษาความปลอดภัยระดับสูงแบบไบโอเมตริก (แพงแต่ปลอดภัยมาก) ในขณะที่ voice recognition เหมือนกุญแจรหัสพื้นฐาน (ถูกแต่ปลอดภัยน้อยกว่า)


9.5 Generic Biometric System

Three Modes:

(a) Enrollment (การลงทะเบียน)

User → Enter Name/PIN
       ↓
    Provide Biometric
       ↓
    Sensor captures
       ↓
    Feature extraction
       ↓
    Store in database
       (Template)

(b) Verification (1:1 Matching)

User → Enter Name/PIN + Biometric
       ↓
    Sensor captures
       ↓
    Feature extraction
       ↓
    Compare with ONE template
       ↓
    Match? → Yes/No

(c) Identification (1:N Matching)

User → Provide Biometric only
       ↓
    Sensor captures
       ↓
    Feature extraction
       ↓
    Compare with ALL templates (N)
       ↓
    Find match? → Identity or "Unknown"

9.6 Biometric Image Processing

Pipeline:

Biometric    Image         Template      Biometric
Capture  →  Processing  →  Extraction  →  Matching
   ↓            ↓             ↓              ↓
 Raw         Enhanced      Feature        Match/
 Data         Image        Vector       No Match

Example Binary Data:

10110011
01011000
11001011
01101101
01011000

9.7 False Match Rate (FMR) & False Non-Match Rate (FNMR)

Definitions:

False Match Rate (FMR)

Also known as: False Accept Rate (FAR)

Definition:
Two pieces of biometric data from DIFFERENT people
judged to be from SAME person

Example:
Person A's fingerprint
matches Person B's fingerprint
→ System incorrectly accepts B as A

Impact: ❌ Security risk (unauthorized access)

False Non-Match Rate (FNMR)

Also known as: False Reject Rate (FRR)

Definition:
Two pieces of biometric data from SAME person
judged to be from DIFFERENT people

Example:
Person A's fingerprint
doesn't match Person A's stored fingerprint
→ System incorrectly rejects A

Impact: ❌ Usability problem (legitimate user denied)

Trade-off:

                Threshold
                    ↕
Lower Threshold ────┼──── Higher Threshold
       │            │            │
    Higher          │         Lower
    FMR (FAR)       │       FMR (FAR)
       │            │            │
    Lower           │         Higher
   FNMR (FRR)       │      FNMR (FRR)
       │            │            │
  Less Secure       │      More Secure
  More Convenient   │    Less Convenient

เปรียบเทียบ: FMR เหมือนระบบรักษาความปลอดภัยที่ปล่อยคนผิดเข้ามา (false positive) ในขณะที่ FNMR เหมือนระบบรักษาความปลอดภัยที่ล็อคคนถูกออกไป (false negative)


9.8 Biometric Accuracy Analysis

Idealized Curves:

Error Rate
     ↑
     │      FNMR
     │       ╱
     │      ╱
     │     ╱
     │    ╱  ╲
     │   ╱    ╲
     │  ╱      ╲  FMR
     │ ╱        ╲
     │╱__________╲___
     └────────────────→ Threshold
          ↑
     Optimal Point
    (Equal Error Rate)

Comparison of Methods:

Best Performance ──────────────→ Worst Performance

Iris > Retina > Fingerprint > Facial > Hand > Voice > Signature

Balancing Act:

Strict Threshold:
✅ Low FMR (more secure)
❌ High FNMR (reject legitimate users)

Lenient Threshold:
❌ High FMR (accept imposters)
✅ Low FNMR (accept legitimate users)

Goal: Find optimal balance!

เปรียบเทียบ: Biometric accuracy เป็นการหาสมดุล - เหมือนการปรับเครื่องชั่ง / ถ้าทำให้เข้มงวดเกินไป (FMR ต่ำ) จะปฏิเสธผู้ใช้ที่ถูกต้องบ่อยขึ้น (FNMR สูง) / ถ้าทำให้ผ่อนปรนเกินไป (FNMR ต่ำ) จะยอมรับคนปลอมบ่อยขึ้น (FMR สูง)