Skip to content
Merged
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
33 changes: 13 additions & 20 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ on:
required: true
type: boolean
swift:
description: Publish a swift version (cocoapods)
description: Publish a swift version (swift package)
default: true
required: true
type: boolean
Expand Down Expand Up @@ -186,42 +186,35 @@ jobs:
- name: Setup rust
run: |
rustup target add aarch64-apple-ios
rustup target add x86_64-apple-ios
cargo install cargo-lipo
rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-ios-sim
rustup target add aarch64-apple-darwin

- name: Setup version
id: version
run: |
VERSION=$(grep -E "^\s*s\.version" Slauth.podspec \
| awk -F"[\"\']" '{print $2}')
VERSION=$(grep -E "^version\s*=" Cargo.toml | head -1 | awk -F'"' '{print $2}')
echo "version=$VERSION" >> $GITHUB_OUTPUT

- name: Run build.sh
- name: Generate package
run: sh wrappers/swift/build.sh

- name: Package Pod
- name: Package Swift Package
run: |
VERSION=${{ steps.version.outputs.version }}
# locate all .a libraries under any release folder
AFILES=$(find target -type f -path '*/release/*.a')
zip -r Slauth-$VERSION.zip \
Slauth.podspec \
LICENSE \
wrappers/swift/classes \
slauth.h \
$AFILES
echo "PACKAGE=Slauth-$VERSION.zip" >> $GITHUB_ENV
mv package Slauth-$VERSION
zip -r Slauth-$VERSION.zip Slauth-$VERSION

- name: Upload artifact
- name: Upload package
uses: actions/upload-artifact@v4.3.6
with:
name: Cocoapods
path: Slauth-${{ steps.version.outputs.version }}.zip
name: swift-zip
path: ./Slauth-${{ steps.version.outputs.version }}.zip

- name: Install Cloudsmith CLI
run: pip install --upgrade cloudsmith-cli

- name: Push package to Cloudsmith
run: cloudsmith push cocoapods devolutions/swift-public Slauth-${{ steps.version.outputs.version }}.zip
run: cloudsmith push swift devolutions/swift-public Slauth-${{ steps.version.outputs.version }}.zip --name Slauth --version ${{ steps.version.outputs.version }} --scope devolutions
env:
CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ android/NDK/
.gradle
local.properties
wrappers/android/build
build/
build/
libslauth.xcframework/
.swiftpm/
package/
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ serde_cbor = { version = "0.11", optional = true }
webpki = { version = "0.22", optional = true, features = ["alloc"] }
bytes = { version = "1.10", optional = true }
http = { version = "1.3", optional = true }
uuid = { version = "1.16", optional = true }
ed25519-dalek = { version = "2.1.1", features = [
uuid = { version = "1.18", optional = true }
ed25519-dalek = { version = "2.2.0", features = [
"rand_core",
"pkcs8",
], optional = true }
p256 = { version = "0.13.2", optional = true }
indexmap = { version = "2.9.0", features = ["serde"], optional = true }
indexmap = { version = "2.12.0", features = ["serde"], optional = true }

[target.'cfg(target_os = "android")'.dependencies]
jni = { version = "0.21.1", optional = true }

[target.'cfg(target_arch="wasm32")'.dependencies]
wasm-bindgen = { version = "0.2.100" }
js-sys = "0.3.77"
wasm-bindgen = { version = "0.2.104" }
js-sys = "0.3.81"
# FIXME: https://docs.rs/getrandom/0.2.2/getrandom/#webassembly-support
# let `getrandom` know that JavaScript is available for our targets
# `getrandom` is not used directly, but by adding the right feature here
Expand All @@ -92,7 +92,7 @@ getrandom = { version = "0.2", features = ["js"] }
serde-wasm-bindgen = "0.6.5"

[target.'cfg(target_arch="wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3.50"
wasm-bindgen-test = "0.3.54"

[target.'cfg(not(target_arch="wasm32"))'.dev-dependencies]
saphir = { version = "3.1.0", git = "https://github.com/richerarc/saphir.git", tag = "v3.1.0", features = [
Expand All @@ -104,7 +104,7 @@ async-stream = ">= 0.3, < 0.3.4" # 0.3.4 and up currently break saphir
[dev-dependencies]
serde_json = "1.0"
serde_cbor = "0.11"
uuid = "1.16"
uuid = "1.18"
rand = "0.9"
bytes = "1.10"

Expand Down
19 changes: 0 additions & 19 deletions Slauth.podspec

This file was deleted.

3 changes: 3 additions & 0 deletions src/oath/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//Have to allow deprecated because hmac crate hasn't been updated yet to GenericArray 1.0
#[allow(deprecated)]
use hmac::{
digest::{generic_array::GenericArray, FixedOutputReset, InvalidLength, OutputSizeUser},
Mac, SimpleHmac,
Expand Down Expand Up @@ -47,6 +49,7 @@ impl MacHashKey {
}
}

#[allow(deprecated)]
pub(crate) enum HmacShaResult {
RSHA1(GenericArray<u8, <Sha1 as OutputSizeUser>::OutputSize>),
RSHA256(GenericArray<u8, <Sha256 as OutputSizeUser>::OutputSize>),
Expand Down
8 changes: 8 additions & 0 deletions src/u2f/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ pub mod client {

let mut data = Vec::with_capacity(64);


//Allowing deprecated because hmac library hasn't updated yet
#[allow(deprecated)]
data.extend_from_slice(challenge_param.as_slice());
#[allow(deprecated)]
data.extend_from_slice(application_parameter.as_slice());

let raw_req = RawRequest {
Expand Down Expand Up @@ -133,7 +137,11 @@ pub mod client {

let mut data = Vec::new();


//Allow deprecated pending rust crypto generic_array removal
#[allow(deprecated)]
data.extend_from_slice(challenge_param.as_slice());
#[allow(deprecated)]
data.extend_from_slice(application_parameter.as_slice());
data.push(signing_key.key_handle.len() as u8);
data.extend_from_slice(signing_key.key_handle.as_bytes());
Expand Down
4 changes: 4 additions & 0 deletions src/webauthn/proto/tpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,14 @@ impl TPM {
let (scheme, hashed) = match self.alg.into() {
CoseAlgorithmIdentifier::RS1 => (
Pkcs1v15Sign::new::<Sha1>(),
//Allow deprecated pending rust crypto generic_array removal
#[allow(deprecated)]
sha1::Sha1::digest(self.cert_info.as_slice()).as_slice().to_vec(),
),
CoseAlgorithmIdentifier::RSA => (
Pkcs1v15Sign::new::<Sha256>(),
//Allow deprecated pending rust crypto generic_array removal
#[allow(deprecated)]
sha2::Sha256::digest(self.cert_info.as_slice()).as_slice().to_vec(),
),
_ => return Err(Error::TpmError(TpmError::SignatureHashInvalid(self.alg))),
Expand Down
5 changes: 5 additions & 0 deletions src/webauthn/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ impl CredentialCreationVerifier {
} else {
hasher.update(get_default_rp_id(&self.origin));
}

//Allow deprecated pending rust crypto generic_array removal
#[allow(deprecated)]
if attestation.auth_data.rp_id_hash != hasher.finalize().as_slice() {
return Err(Error::CredentialError(CredentialError::Rp));
}
Expand Down Expand Up @@ -601,6 +604,8 @@ impl CredentialRequestVerifier {
} else {
hasher.update(get_default_rp_id(&self.origin));
}
//Allow deprecated pending rust crypto generic_array removal
#[allow(deprecated)]
if auth_data.rp_id_hash != hasher.finalize_reset().as_slice() {
return Err(Error::CredentialError(CredentialError::Rp));
}
Expand Down
33 changes: 33 additions & 0 deletions wrappers/swift/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// swift-tools-version: 5.10
import PackageDescription

let package = Package(
name: "Slauth",
platforms: [
.iOS(.v16)
],
products: [
.library(
name: "Slauth",
targets: ["Slauth"]
)
],
targets: [
.systemLibrary(
name: "SlauthFFI",
path: "ffi"
),
.binaryTarget(
name: "libslauth",
path: "libslauth.xcframework"
),
.target(
name: "Slauth",
dependencies: [
"SlauthFFI",
"libslauth"
],
path: "classes"
)
]
)
32 changes: 28 additions & 4 deletions wrappers/swift/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
cargo lipo --release
mv target/universal/release/libslauth.a target/universal/release/libslauth_universal.a
mv target/x86_64-apple-ios/release/libslauth.a target/x86_64-apple-ios/release/libslauth_x86.a
mv target/aarch64-apple-ios/release/libslauth.a target/aarch64-apple-ios/release/libslauth_arm64.a
#!/bin/bash
set -e

rm -rf ./package

# Build Rust libraries for iOS targets
cargo build --target aarch64-apple-ios --release
cargo build --target aarch64-apple-ios-sim --release
cargo build --target aarch64-apple-darwin --release
cargo build --target x86_64-apple-darwin --release

lipo target/x86_64-apple-darwin/release/libslauth.a target/aarch64-apple-darwin/release/libslauth.a -create -output target/libslauth.a

mkdir package
mkdir ./package/headers
cp slauth.h ./package/headers

# Create XCFramework
xcodebuild -create-xcframework \
-library target/aarch64-apple-ios/release/libslauth.a -headers ./package/headers \
-library target/aarch64-apple-ios-sim/release/libslauth.a -headers ./package/headers \
-library target/libslauth.a -headers ./package/headers \
-output ./package/libslauth.xcframework

cp wrappers/swift/Package.swift ./package
cp -R wrappers/swift/classes ./package
cp -R wrappers/swift/ffi ./package

4 changes: 4 additions & 0 deletions wrappers/swift/classes/Hotp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

import Foundation

#if canImport(SlauthFFI)
import SlauthFFI
#endif

public class Hotp: NSObject, RustObject {
var raw: OpaquePointer

Expand Down
6 changes: 5 additions & 1 deletion wrappers/swift/classes/SlauthUtils.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import Foundation

#if canImport(SlauthFFI)
import SlauthFFI
#endif

public class SlauthUtils {
public static func convertPkcs8ToPrivateKey(pkcs8String: String) -> String {
let cString = pkcs8_to_custom_private_key(pkcs8String)
Expand All @@ -14,4 +18,4 @@ public class SlauthUtils {
free(cString)
return pkcs8String
}
}
}
4 changes: 4 additions & 0 deletions wrappers/swift/classes/Totp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

import Foundation

#if canImport(SlauthFFI)
import SlauthFFI
#endif

public class Totp: NSObject, RustObject {
var raw: OpaquePointer

Expand Down
4 changes: 4 additions & 0 deletions wrappers/swift/classes/U2f.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

import Foundation

#if canImport(SlauthFFI)
import SlauthFFI
#endif

public class WebRequest : RustObject {
var raw: OpaquePointer

Expand Down
4 changes: 4 additions & 0 deletions wrappers/swift/classes/WebAuthnCreationResponse.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Foundation
import AuthenticationServices

#if canImport(SlauthFFI)
import SlauthFFI
#endif

@available(iOS 15.0, *)
public class WebAuthnCreationResponse: NSObject {

Expand Down
6 changes: 6 additions & 0 deletions wrappers/swift/classes/WebAuthnRequestResponse.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import Foundation

#if canImport(SlauthFFI)
import SlauthFFI
#endif

@available(iOS 15.0, *)
public class WebAuthnRequestResponse: NSObject, RustObject {

Expand Down
6 changes: 6 additions & 0 deletions wrappers/swift/ffi/framework.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
framework module SlauthFFI {
umbrella header "../headers/slauth.h"

export *
module * { export * }
}
4 changes: 4 additions & 0 deletions wrappers/swift/ffi/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module SlauthFFI [system] {
header "../headers/slauth.h"
export *
}