Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ jobs:
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Install Swift-sh
run: brew install swift-sh
- name: Install Swift-sh and FlatBuffers
run: brew install swift-sh flatbuffers
- name: Build and Archive
env:
APP_PROVISIONING_PROFILE_UUID: ${{ secrets.APP_PROVISIONING_PROFILE_UUID }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Install FlatBuffers
run: brew install flatbuffers

# Creating sample files needed to build, but not needed for CodeQL.
# .plist files need a sample structure to avoid error: "unable to read input file as a property list"
- name: Create sample files
Expand Down
97 changes: 28 additions & 69 deletions CryptoLib/CryptoLib.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion CryptoLib/CryptoLib/AbstractSmartToken.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import Foundation

@objc public protocol AbstractSmartToken {
func getCertificate() throws -> Data
func getCertificate() async throws -> Data
func decrypt(_ data: Data) throws -> Data
func derive(_ data: Data) throws -> Data
func authenticate(_ data: Data) throws -> Data
Expand Down
33 changes: 0 additions & 33 deletions CryptoLib/CryptoLib/Addressee.h

This file was deleted.

28 changes: 0 additions & 28 deletions CryptoLib/CryptoLib/Addressee.m

This file was deleted.

66 changes: 66 additions & 0 deletions CryptoLib/CryptoLib/Addressee.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// Addressee.swift
// CryptoLib
/*
* Copyright 2017 - 2024 Riigi Infosüsteemi Amet
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

import ASN1Decoder

public class Addressee: NSObject {
@objc public var data: Data
public let identifier: String
public let givenName: String?
public let surname: String?
public let serialNumber: String?
public let certType: CertType
public var validTo: Date?

init(cert: Data, x509: X509Certificate?) {
data = cert
let cn = x509?.subject(oid: .commonName)?.joined(separator: ",") ?? ""
let split = cn.split(separator: ",").map { String($0) }
if split.count > 1 {
surname = split[0]
givenName = split[1]
identifier = split[2]
} else {
surname = nil
givenName = nil
identifier = cn
}
serialNumber = x509?.subject(oid: .serialNumber)?.joined(separator: ",")
certType = x509?.certType() ?? .UnknownType
validTo = x509?.notAfter
}

convenience init(cert: Data) {
self.init(cert: cert, x509: try? X509Certificate(der: cert))
}

public override func isEqual(_ object: Any?) -> Bool {
guard let other = object as? Addressee else { return false }
return
data == other.data &&
identifier == other.identifier &&
givenName == other.givenName &&
surname == other.surname &&
certType == other.certType &&
validTo == other.validTo
}
}
31 changes: 0 additions & 31 deletions CryptoLib/CryptoLib/CdocInfo.h

This file was deleted.

27 changes: 0 additions & 27 deletions CryptoLib/CryptoLib/CdocInfo.m

This file was deleted.

91 changes: 91 additions & 0 deletions CryptoLib/CryptoLib/CdocInfo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// CdocInfo.swift
// CryptoLib
/*
* Copyright 2017 - 2024 Riigi Infosüsteemi Amet
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

import Foundation

public class CdocInfo: NSObject {
public let format: String
public let addressees: [Addressee]
public let dataFiles: [CryptoDataFile]

@objc public init(cdoc1Path path: String) throws {
guard let parser = XMLParser(contentsOf: URL(fileURLWithPath: path)) else {
NSLog("Error: Unable to read file at \(path)")
throw NSError(domain: XMLParser.errorDomain, code: XMLParser.ErrorCode.internalError.rawValue, userInfo: [
NSLocalizedDescriptionKey: "Failed to create XML parser for file at \(path)"
])
}
let delegate = CdocParserDelegate()
parser.externalEntityResolvingPolicy = .never
parser.delegate = delegate;
guard parser.parse() else {
NSLog("Error: Failed to parse XML")
throw parser.parserError!
}
format = delegate.format
addressees = delegate.addressees
dataFiles = delegate.dataFiles
}
}

class CdocParserDelegate: NSObject, XMLParserDelegate {
public var format = String()
public var addressees: [Addressee] = []
public var dataFiles: [CryptoDataFile] = []
var data: String? = nil
var attr = String()

func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String: String]) {
switch elementName {
case "ds:X509Certificate":
data = String()
case "denc:EncryptionProperty" where attributeDict["Name"] == "orig_file" || attributeDict["Name"] == "DocumentFormat":
attr = attributeDict["Name"] ?? ""
data = String()
default: break
}
}

func parser(_ parser: XMLParser, foundCharacters string: String) {
if data != nil {
data! += string
}
}

func parser(_ parser: XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
guard data != nil else { return }
switch (elementName, attr) {
case ("ds:X509Certificate", _):
if let data = Data(base64Encoded: data!, options: .ignoreUnknownCharacters) {
addressees.append(Addressee(cert: data))
}
case ("denc:EncryptionProperty", "orig_file"):
if let filename = data!.split(separator: "|").first {
dataFiles.append(CryptoDataFile(filename: String(filename)))
}
case ("denc:EncryptionProperty", "DocumentFormat"):
format = data!
default: break
}
data = nil
}
}
30 changes: 0 additions & 30 deletions CryptoLib/CryptoLib/CdocParser.h

This file was deleted.

39 changes: 0 additions & 39 deletions CryptoLib/CryptoLib/CdocParser.m

This file was deleted.

Loading