Skip to content

Commit

Permalink
project rename
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnzhou committed May 12, 2024
1 parent 4a1370a commit 29ee084
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 28 deletions.
8 changes: 4 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import PackageDescription

let package = Package(
name: "lcl-ping-auth",
name: "lcl-auth",
platforms: [.iOS(.v13), .macOS(.v11), .tvOS(.v13), .watchOS(.v6)],
products: [
.library(name: "LCLPingAuth", targets: ["LCLPingAuth"])
.library(name: "LCLAuth", targets: ["LCLAuth"])
],
dependencies: [
.package(url: "https://github.com/johnnzhou/lcl-k1.git", branch: "main"),
Expand All @@ -17,12 +17,12 @@ let package = Package(
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "LCLPingAuth",
name: "LCLAuth",
dependencies: [
.product(name: "LCLK1", package: "lcl-k1"),
.product(name: "Crypto", package: "swift-crypto")
]
),
.testTarget(name: "ECDSATests", dependencies: ["LCLPingAuth"])
.testTarget(name: "ECDSATests", dependencies: ["LCLAuth"])
]
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// This source file is part of the LCLPing open source project
// This source file is part of the LCL open source project
//
// Copyright (c) 2021-2024 Local Connectivity Lab and the project authors
// Licensed under Apache License v2.0
Expand All @@ -18,27 +18,27 @@ public func deserialize<T: Decodable>(json: Data, as: T.Type) throws -> T? {

public func validate(credential: Data) throws -> ValidationResult {
guard let qrCode = try? deserialize(json: credential, as: Keys.self) else {
throw LCLPingAuthError.invalidCredential
throw LCLAuthError.invalidCredential
}

guard let pkA: Data = try? .init(hexString: qrCode.pk_a), let skT: Data = try? .init(hexString: qrCode.skT), let sigmaT: Data = try? .init(hexString: qrCode.sigmaT) else {
throw LCLPingAuthError.invalidCredential
throw LCLAuthError.invalidCredential
}

guard let pk_a = try? ECDSA.deserializePublicKey(raw: pkA) else {
throw LCLPingAuthError.invalidPublicKey
throw LCLAuthError.invalidPublicKey
}

guard let isValidSignature = try? ECDSA.verify(message: skT, signature: sigmaT, publicKey: pk_a) else {
throw LCLPingAuthError.invalidSignature
throw LCLAuthError.invalidSignature
}

if !isValidSignature {
throw LCLPingAuthError.corruptedCredential
throw LCLAuthError.corruptedCredential
}

guard let sk_t = try? ECDSA.deserializePrivateKey(raw: skT) else {
throw LCLPingAuthError.invalidPrivateKey
throw LCLAuthError.invalidPrivateKey
}

let pk_t = ECDSA.derivePublicKey(from: sk_t)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// This source file is part of the LCLPing open source project
// This source file is part of the LCL open source project
//
// Copyright (c) 2021-2024 Local Connectivity Lab and the project authors
// Licensed under Apache License v2.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// This source file is part of the LCLPing open source project
// This source file is part of the LCL open source project
//
// Copyright (c) 2021-2024 Local Connectivity Lab and the project authors
// Licensed under Apache License v2.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// This source file is part of the LCLPing open source project
// This source file is part of the LCL open source project
//
// Copyright (c) 2021-2024 Local Connectivity Lab and the project authors
// Licensed under Apache License v2.0
Expand All @@ -26,7 +26,7 @@ private func htoi(_ value: UInt8) throws -> UInt8 {
case charA...charA + 5:
return value - charA + 10
default:
throw LCLPingAuthError.incorrectHexValue
throw LCLAuthError.incorrectHexValue
}
}

Expand All @@ -37,7 +37,7 @@ extension Data {
self.init()

if hexString.count % 2 != 0 || hexString.count == 0 {
throw LCLPingAuthError.invalidFormatError
throw LCLAuthError.invalidFormatError
}

let stringBytes: ByteArray = Array(hexString.lowercased().data(using: String.Encoding.utf8)!)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// This source file is part of the LCLPing open source project
// This source file is part of the LCL open source project
//
// Copyright (c) 2021-2024 Local Connectivity Lab and the project authors
// Licensed under Apache License v2.0
Expand All @@ -12,7 +12,7 @@

import Foundation

public enum LCLPingAuthError: Error {
public enum LCLAuthError: Error {
case incorrectHexValue
case invalidFormatError
case invalidCredential
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// This source file is part of the LCLPing open source project
// This source file is part of the LCL open source project
//
// Copyright (c) 2021-2024 Local Connectivity Lab and the project authors
// Licensed under Apache License v2.0
Expand All @@ -26,9 +26,9 @@ import Crypto
- Precondition: count has to be greater than 0
- Parameters:
- count: the number of bytes to generate
- Returns: A `Result` type. When succeeded, the associated secure random data will be return; When failed, `LCLPingAuthError` will be returned
- Returns: A `Result` type. When succeeded, the associated secure random data will be return; When failed, `LCLAuthError` will be returned
*/
public func generateSecureRandomBytes(count: Int) -> Result<Data, LCLPingAuthError> {
public func generateSecureRandomBytes(count: Int) -> Result<Data, LCLAuthError> {
var bytes: ByteArray = ByteArray(repeating: 0, count: count)

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// This source file is part of the LCLPing open source project
// This source file is part of the LCL open source project
//
// Copyright (c) 2021-2024 Local Connectivity Lab and the project authors
// Licensed under Apache License v2.0
Expand Down
11 changes: 5 additions & 6 deletions Tests/ECDSATests/ECDSATests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// This source file is part of the LCLPing open source project
// This source file is part of the LCL open source project
//
// Copyright (c) 2021-2024 Local Connectivity Lab and the project authors
// Licensed under Apache License v2.0
Expand All @@ -11,7 +11,7 @@
//

import XCTest
@testable import LCLPingAuth
@testable import LCLAuth

final class ECDSATests: XCTestCase {

Expand All @@ -34,11 +34,10 @@ final class ECDSATests: XCTestCase {
XCTAssertFalse(verifyFalse)
}


func testECDSASignature() throws {
let sigHex = "304502201d3ea6680d007b751d4e3c1d928a270a1e5ce06cd9b77a46a95542766bb50cb90221008666a33c7e3362a18795d5b96cc36541f8ca79d9190c4341642145d41feb6605";
let messageHex = "308184020100301006072a8648ce3d020106052b8104000a046d306b0201010420798116c5c26ccfd95e4e13fdf4df9e46cf3629223b190da6c891d48e4de5da57a144034200044552ed599a2d855f59286447d687fbd1ed05793025a7994268f29baef5ca1e3432f9b1d48301a85e4bd8ed77e2c6f3e834f947540b144dbc5a71a548c046c9e2";
let pkHex = "3056301006072a8648ce3d020106052b8104000a03420004da754f3ede85eec8b7dec3fda5dbdc35662f807f29433e2810743c889de15e1f5d4338453fc13c45e856287cc7849554f92aca832c66a094c7f7f231c50afebf";
let sigHex = "304502201d3ea6680d007b751d4e3c1d928a270a1e5ce06cd9b77a46a95542766bb50cb90221008666a33c7e3362a18795d5b96cc36541f8ca79d9190c4341642145d41feb6605"
let messageHex = "308184020100301006072a8648ce3d020106052b8104000a046d306b0201010420798116c5c26ccfd95e4e13fdf4df9e46cf3629223b190da6c891d48e4de5da57a144034200044552ed599a2d855f59286447d687fbd1ed05793025a7994268f29baef5ca1e3432f9b1d48301a85e4bd8ed77e2c6f3e834f947540b144dbc5a71a548c046c9e2"
let pkHex = "3056301006072a8648ce3d020106052b8104000a03420004da754f3ede85eec8b7dec3fda5dbdc35662f807f29433e2810743c889de15e1f5d4338453fc13c45e856287cc7849554f92aca832c66a094c7f7f231c50afebf"

// The messageHex is the SK_t encoded which is signed by the server
let skBytes = try Data(hexString: messageHex)
Expand Down

0 comments on commit 29ee084

Please sign in to comment.