EU Digital COVID Certificate Kit for the Apple Platform  (unofficial)

Overview

logo

EU Digital COVID Certificate Kit

A Swift Package to decode, verify and validate EU Digital COVID Certificates
for iOS, tvOS, watchOS and macOS

Swift 5.4 Documentation Twitter

Disclaimer

The EUDCCKit is not an offical implementation of the EU Digital COVID Certificate

Features

  • Easily decode an EU Digital COVID Certificate 🧾
  • Verify cryptographic signature 🔐
  • Certificate validation

Installation

Swift Package Manager

To integrate using Apple's Swift Package Manager, add the following as a dependency to your Package.swift:

dependencies: [
    .package(url: "https://github.com/SvenTiigi/EUDCCKit.git", from: "0.0.1")
]

Or navigate to your Xcode project then select Swift Packages, click the “+” icon and search for EUDCCKit.

Usage

The EUDCCKit Swift Package is made of four distinct libraries to decode, verify and validate an EU Digital COVID Certificate.

EUDCC

The EUDCC library contains the model definition of the EU Digital COVID Certificate

import EUDCC

// The EU Digital COVID Certificate model
let eudcc: EUDCC

// Access content of EUDCC
switch eudcc.content {
case .vaccination(let vaccination):
    print("Vaccination", vaccination)
case .test(let test):
    print("Test", test)
case .recovery(let recovery):
    print("Recovery", recovery)
}

Head over to the advanced section to learn more.

EUDDCDecoder

The EUDCCDecoder library provides an EUDCCDecoder object which is capabale of decoding a Base-45 string reperesentation of the EU Digital COVID Certificate which is mostly embedded in a QR-Code.

import EUDCCDecoder

// Initialize an EUDCCDecoder
let decoder = EUDCCDecoder()

// The Base-45 encoded EU Digital COVID Certificate from a QR-Code
let qrCodeContent = "HC1:..."

// Decode EUDCC from QR-Code
let decodingResult = decoder.decode(from: qrCodeContent)

// Switch on decoding result
switch decodingResult {
case .success(let eudcc):
    // Successfully decoded Digital COVID Certificate
    print("EU Digital COVID Certificate", eudcc)
case .failure(let decodingError):
    // Decoding failed with error
    print("Failed to decode EUDCC", decodingError)
}

Head over to the advanced section to learn more.

EUDCCVerifier

The EUDCCVerifier library provides an EUDCCVerifier object which can be used to verify the cryptographic signature of the EU Digital COVID Certificate.

import EUDCCVerifier

// Initialize an EUDDCCVerifier
let verifier = EUDCCVerifier(
    trustService: EUCentralEUDCCTrustService()
)

// Verify EU Digital COVID Certificate
verifier.verify(eudcc: eudcc) { verificationResult in
    // Switch on verification result
    switch verificationResult {
    case .success(let trustCertificate):
        print("Cryptographically valid", trustCertificate)
    case .invald:
        print("Invalid EUDCC")
    case .failure(let error):
        print("Error occured during verification", error)
    }
}

Head over to the advanced section to learn more.

EUDCCValidator

The EUDCCValidator library provides an EUDCCValidator object which can be used to validate the EU Digital COVID Certifiate based on given rules.

import EUDCCValidator

// Initialize an EUDCCValidator
let validator = EUDCCValidator()

// Validate EU Digital COVID Certificate
let validationResult = validator.validate(
    eudcc: eudcc,
    rule: .isFullyImmunized() && !.isVaccinationExpired()
)

// Switch on validation result
switch validationResult {
case .success:
    // Successfully validated EU Digital COVID Certificate
    print("Successfully validated")
case .failure(let validationError):
    // Validation failure
    print("Validation failed", validationError)
}

Head over to the advanced section to learn more.

Advanced

EUDCC

Content

Beside the content property of an EUDCC you can make use of the following convenience properties to check if the EUDCC contains a vaccination, test or recovery object.

import EUDCC

// Vaccination
let vaccination: EUDCC.Vaccination? = eudcc.vaccination

// Test
let test: EUDCC.Test? = eudcc.test

// Recovery
let recovery: EUDCC.Recovery? = eudcc.recovery

Well-Known-Value

Each of the following objects are exposing a WellKnownValue enumeration which can be used to retrieve more detailed information about a certain value:

  • EUDCC.DiseaseAgentTargeted
  • EUDCC.Test.TestResult
  • EUDCC.Test.TestType
  • EUDCC.Vaccination.VaccineMarketingAuthorizationHolder
  • EUDCC.Vaccination.VaccineMedicinalProduct
  • EUDCC.Vaccination.VaccineOrProphylaxis
import EUDCC

let vaccineMedicinalProduct: EUDCC.Vaccination.VaccineMedicinalProduct

// Switch on WellKnownValue of VaccineMedicinalProduct
switch vaccineMedicinalProduct.wellKnownValue {
    case .covid19VaccineModerna:
        break
    case .vaxzevria:
        break
    default:
        break
}

Encoding

The EUDCC contains two properties cryptographicSignature and base45Representation which are convenience objects that are not an offical part of the EU Digital COVID Certificate JSON Schema.

If you wish to skip those properties when encoding an EUDCC you can set the following userInfo configuration to a JSONEncoder.

import EUDCC

let encoder = JSONEncoder()

encoder.userInfo = [
    // Skip encoding CryptographicSignature
    EUDCC.EncoderUserInfoKeys.skipCryptographicSignature: true,
    // Skip encoding Base-45 representation
    EUDCC.EncoderUserInfoKeys.skipBase45Representation: true,
]

let jsonData = try encoder.encode(eudcc)

EUDDCDecoder

Decoding

The EUDCCDecoder supports decoding a Base-45 encoded String and Data object.

import EUDCCDecoder

let eudccDecoder = EUDCCDecoder()

// Decode from Base-45 encoded String
let eudccBase45EncodedString: String
let stringDecodingResult = eudccDecoder.decode(
    from: eudccBase45EncodedString
)

// Decode from Base-45 encoded Data
let eudccBase45EncodedData: Data
let dataDecodingResult = eudccDecoder.decode(
    from: eudccBase45EncodedData
)

Convenience decoding

By importing the EUDCCDecoder library the EUDCC object will be extended with a static decode function.

import EUDCCDecoder

let decodingResult = EUDCC.decode(from: "HC1:...")

EUDCCVerifier

EUDCCTrustService

In order to verify an EUDCC the EUDCCVerifier needs to be instantiated with an instance of an EUDCCTrustService which is used to retrieve the trust certificates.

import EUDCC
import EUDCCVerifier

struct SpecificEUDCCTrustService: EUDCCTrustService {
    
    /// Retrieve EUDCC TrustCertificates
    /// - Parameter completion: The completion closure
    func getTrustCertificates(
        completion: @escaping (Result<[EUDCC.TrustCertificate], Error>) -> Void
    ) {
        // TODO: Retrieve TrustCertificates and invoke completion handler
    }
    
}

let eudccVerifier = EUDCCVerifier(
    trustService: SpecificEUDCCTrustService()
)

The EUDCCKit comes along with two pre defined EUDCCTrustService implementations:

  • EUCentralEUDCCTrustService
  • RobertKochInstituteEUDCCTrustService

If you wish to retrieve certificates from multiple EUDCCTrustService implementation you can make use of the GroupableEUDCCTrustService:

let trustService = GroupableEUDCCTrustService(
    trustServices: [
        EUCentralEUDCCTrustService(),
        RobertKochInstituteEUDCCTrustService()
    ]
)

trustService.getTrustCertificates { certificates in
    // ...
}

Convenience verification

By importing the EUDCCVerifier library the EUDCC object will be extended with a verify function.

import EUDCC
import EUDCCVerifier

let eudcc: EUDCC

eudcc.verify(
    using: EUDCCVerifier(
        trustService: EUCentralEUDCCTrustService()
    )
) { verificationResult in
    switch verificationResult {
    case .success(let trustCertificate):
        break
    case .invald:
        break
    case .failure(let error):
        break
    }
}

EUDCCValidator

ValidationRule

An EUDCC can be validated by using an EUDCCValidator and a given EUDCC.ValidationRule. An EUDCC.ValidationRule can be initialized with a simple closure wich takes in an EUDCC and returns a Bool whether the validation succeed or failed.

import EUDCC
import EUDCCValidator

// Simple EUDCC ValidationRule instantiation
let validationRule = EUDCC.ValidationRule { eudcc in
    // Process EUDCC and return Bool result
}

// EUDCC ValidationRule with Tag in order to uniquely identify a ValidationRule
let isVaccinationComplete = EUDCC.ValidationRule(
    tag: "is-vaccination-complete"
) { eudcc in
    eudcc.vaccination?.doseNumber == eudcc.vaccination?.totalSeriesOfDoses
}

The EUDCCKit comes along with many pre defined EUDCC.ValidationRule like the following ones.

import EUDCC
import EUDCCValidator

let eudcc: EUDCC
let validator = EUDCCValidator()

// Is fully immunized
validator.validate(
    eudcc: eudcc, 
    rule: .isFullyImmunized(minimumDaysPast: 15)
)

// Is tested positive
validator.validate(
    eudcc: eudcc, 
    rule: .isTestedPositive
)

Logical/Conditional operators

In order to create more complex rules each EUDCC.ValidationRule can be chained together by applying standard operators.

import EUDCC
import EUDCCValidator

let defaultValidationRule: EUDCC.ValidationRule = .if(
    .isVaccination,
    then: .isFullyImmunized() && .isWellKnownVaccineMedicinalProduct && !.isVaccinationExpired(),
    else: .if(
        .isTest,
        then: .isTestedNegative && .isTestValid(),
        else: .if(
            .isRecovery,
            then: .isRecoveryValid,
            else: .constant(false)
        )
    )
)

Convenience validation

By importing the EUDCCValidator library the EUDCC object will be extended with a validate function.

import EUDCC
import EUDCCValidator

let eudcc: EUDCC

let validationRule = eudcc.validate(
    rule: .isWellKnownVaccineMedicinalProduct
)

License

EUDCCKit
Copyright (c) 2021 Sven Tiigi [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
You might also like...
iCome Out is an open source project of an unofficial Pornub app for iPhone and iPad
iCome Out is an open source project of an unofficial Pornub app for iPhone and iPad

iCome Out is an open source project of an unofficial Pornub app for iPhone and iPad, written in Swift with some cool features Getting Started Prerequi

BTTV-for-Safari - Unofficial BTTV/ FFZ Safari Extension for Twitch
BTTV-for-Safari - Unofficial BTTV/ FFZ Safari Extension for Twitch

BTTV for Safari This unofficial Safari exention adds support for BTTV and FFZ emotes on Twitch. The extension simply injects the BTTV script from the

An unofficial iOS client for Konachan.net
An unofficial iOS client for Konachan.net

An unofficial iOS client for Konachan.net

An unofficial logbook for bouldering at Mandala. Kind of a SwiftUI playground as well.
An unofficial logbook for bouldering at Mandala. Kind of a SwiftUI playground as well.

BoulderLogbook An unofficial boulder logbook for Dresden's boulder gym Mandala. Features When finished it should allow you to: log all your tops for a

COVID-19 SwiftUI Demo
COVID-19 SwiftUI Demo

COVID-19_SwiftUI_Demo About COVID-19_SwiftUI_Demo is the coronavirus information application using SwiftUI which is first introduced in WWDC19 keynote

A simple App to Track the status of Covid-19 around the World. Using SwiftUI and GraphQL
A simple App to Track the status of Covid-19 around the World. Using SwiftUI and GraphQL

CovidUI CovidUI is a simple App to Track the status of Covid-19 around the World. This is a simple App I made to track the spread of Covid-19 for me a

Get notified about available COVID-19 vaccination appointments in Berlin's vaccination centers
Get notified about available COVID-19 vaccination appointments in Berlin's vaccination centers

VaccinationMonitor If you live in Berlin you might know how difficult it is to find an appointment to get a COVID-19 vaccination. This app notifies yo

Covid 19 Tracing Mobile Application
Covid 19 Tracing Mobile Application

PVAMU-COVID19-APP Covid 19 Tracing Mobile Application This is my Senior Design Project 2021-2022 Mobile applications are the new gateway to have easy

iOS 14 widget for stats on COVID -19.
iOS 14 widget for stats on COVID -19.

A Covid-19 Tracking Widget for iOS 14 WidgetKit WidgetKit gives users ready access to content in apps by putting widgets on the iOS Home screen or mac

Releases(0.0.4)
  • 0.0.4(Dec 19, 2021)

    What's Changed

    • .day instead of .hour in vaccination expiration check by @chili-ios in https://github.com/SvenTiigi/EUDCCKit/pull/9

    New Contributors

    • @chili-ios made their first contribution in https://github.com/SvenTiigi/EUDCCKit/pull/9

    Full Changelog: https://github.com/SvenTiigi/EUDCCKit/compare/0.0.3...0.0.4

    Source code(tar.gz)
    Source code(zip)
  • 0.0.3(Sep 15, 2021)

    Version 0.0.3

    Bug fixes

    • Fixed a bug which caused a runtime error when decoding an invalid Base-45 string (https://github.com/SvenTiigi/EUDCCKit/issues/7)

    Improvements

    • Refactored testingCentre property to an optional String of EUDCC.Test type (https://github.com/SvenTiigi/EUDCCKit/pull/4)
    Source code(tar.gz)
    Source code(zip)
  • 0.0.2(Jul 26, 2021)

    • Refactored testName and testNameAndManufacturer to be optional (https://github.com/SvenTiigi/EUDCCKit/pull/1)
    • Fixed EUCentralEUDCCTrustService bug which cause a failure when fetching TrustCertificates (https://github.com/SvenTiigi/EUDCCKit/issues/2)
    • Added GroupableEUDCCTrustService
    Source code(tar.gz)
    Source code(zip)
  • 0.0.1(Jul 18, 2021)

Owner
Sven Tiigi
iOS Engineer @opwoco
Sven Tiigi
COVID Safe Paths (based on Private Kit) is an open and privacy preserving system to use personal information to battle COVID

COVID Safe Paths is a mobile app for digital contract tracing (DCT) sponsored by Path Check a nonprofit and developed by a growing global community of engineers, designers, and contributors. Safe Paths is based on research originally conducted at the MIT Media Lab.

PathCheck Foundation 470 Nov 6, 2022
ViruSafe aims to help the fight with COVID-19 by offering people to share their symptoms as well track the spread of COVID-19 with an interactive map

ViruSafe aims to help the fight with COVID-19 by offering people to share their symptoms as well track the spread of COVID-19 with an interactive map, that shows how the infection has spread throughout Bulgaria.

scalefocus 16 Feb 9, 2022
An Unofficial Apple TV app for http://UitzendingGemist.nl

UitzendingGemist An Unofficial Apple TV app for http://UitzendingGemist.nl Installation You can install UitzendingGemist onto your Apple TV by sideloa

Jeff Kreeftmeijer 76 Sep 16, 2022
AR Basketball for Moscow Digital Academy Students

Basketball 2020 AR Basketball for Moscow Digital Academy Students Installation Clone the project and compile in Xcode 12 or above. iPhone 6s with supp

Vladimir Shevtsov 0 Dec 11, 2021
Nextflix - Integrating project of the IOS development course by Digital House

nextflix Projeto integrador do curso de desenvolvimento IOS pela Digital House A

Thiago Leite 2 Feb 1, 2022
BRD - the simple and secure wallet for bitcoin, ethereum, and other digital assets

BRD is the simple and secure wallet for bitcoin, ethereum, and other digital assets. Today, BRD is one of the largest non-custodial mobile wallets used by over 6 million users and protects an estimated nearly $7B USD.

bread 647 Jan 7, 2023
Social Media platform build with swiftUI and Firebase with google and apple account integration for Signing In Users

Social Media platform build with swiftUI and Firebase with google and apple account integration for Signing In Users . Providing Users availability to upload posts and images add caption allowing other users to comment , with Find section to explore new people , new stories , User Profile section to allow the user to take control of his account .

Devang Papinwar 2 Jul 11, 2022
iOS SwiftUI starter kit based on Sketch Elements.

iOS Sketch Elements iOS Sketch Elements is iOS SwiftUI starter kit based on Sketch Elements. More information and screenshots here. Roadmap General Na

Filip Molcik 34 Oct 4, 2022
Swift Starter Kit with Firebase & Facebook Login Onboarding

iOS Swift Starter Kit ?? ?? ?? ?? Boilerplate Onboarding App in Swift with Firebase Integration, Facebook Login and Push Notifications. Save days of a

Instamobile 105 Nov 7, 2022
An unofficial version of the Sandwiches app and pre-built materials similar to those used in the Introduction to SwiftUI session video from WWDC20

Unofficial Sandwiches The WWDC20 Session Introduction to SwiftUI provides a tutorial-like walk-through of building a list-detail SwiftUI app from scra

James Dempsey 94 Feb 11, 2022