Skip to content

Latest commit

 

History

History
86 lines (58 loc) · 3.57 KB

File metadata and controls

86 lines (58 loc) · 3.57 KB

Fix: ICAO Master Certificate File Not Found

Problem Analysis

The app was throwing a FileNotFoundException when trying to read masters_asset.pem:

Error reading ICAO
java.io.FileNotFoundException: masters_asset.pem
    at android.content.res.AssetManager.open(...)
    at com.rarilabs.rarime.manager.ProofGenerationManager.readICAO(ProofGenerationManager.kt:868)

Root Cause

  1. Missing Assets Directory: The app/src/main/assets/ directory did not exist in the project.
  2. Missing Certificate File: The masters_asset.pem file was not present in the assets folder.
  3. Suboptimal Context Usage: The code was using createPackageContext() unnecessarily, which could cause issues in some scenarios.

Solution Implemented

1. Created Assets Directory

  • Created app/src/main/assets/ directory structure

2. Created Placeholder Certificate File

  • Created app/src/main/assets/masters_asset.pem as a placeholder
  • IMPORTANT: This is a placeholder file. You must replace it with the actual ICAO master certificate PEM file.

3. Improved Code Implementation

  • Updated readICAO() method in ProofGenerationManager.kt:
    • Simplified context usage (removed unnecessary createPackageContext())
    • Added proper error handling with specific FileNotFoundException catch
    • Added validation for empty file
    • Added debug logging for successful file loading
    • Improved error messages to guide developers

4. Added Missing Import

  • Added import java.io.FileNotFoundException to handle the specific exception type

Files Modified

  1. app/src/main/assets/masters_asset.pem (NEW)

    • Placeholder PEM certificate file
    • Location: app/src/main/assets/masters_asset.pem
  2. app/src/main/java/com/rarilabs/rarime/manager/ProofGenerationManager.kt

    • Updated readICAO() method (lines 865-890)
    • Added FileNotFoundException import

Next Steps - ACTION REQUIRED

⚠️ You must replace the placeholder certificate with the real ICAO master certificate:

  1. Obtain the actual ICAO master certificate PEM file from your project administrator or ICAO authority
  2. Replace app/src/main/assets/masters_asset.pem with the real certificate file
  3. Ensure the file is a valid PEM format certificate
  4. The file should contain the ICAO master certificate used for passport certificate validation

Why This Error Happened

  1. Missing Directory Structure: Android assets must be in app/src/main/assets/ directory, which didn't exist
  2. Missing File: The certificate file was never added to the project
  3. Build System: Android's build system automatically includes files from the assets/ directory, but only if the directory exists

How the Fix Resolves It

  1. Directory Created: The assets directory now exists, so Android's build system will include it
  2. File Present: The placeholder file ensures the code won't crash, but you must replace it with the real certificate
  3. Better Error Handling: Improved error messages will help identify issues if the file is missing or invalid
  4. Simplified Context: Using applicationContext directly is more reliable than createPackageContext()

Testing

After replacing the placeholder with the real certificate:

  1. Clean and rebuild the project
  2. Test the registration flow
  3. Verify that readICAO() successfully loads the certificate
  4. Check logs for "Successfully loaded ICAO master certificate" message

Build Configuration

No changes to build.gradle.kts were needed. Android automatically includes files from app/src/main/assets/ in the APK/AAB during the build process.