Cloak Swift - a tool and Tuist plugin to encrypt secrets and then pass them in an obfuscated form into applications

Overview

Cloak Swift

Swift Package Manager Latest release Twitter: @lordcodes


This is Cloak Swift - a tool and Tuist plugin to encrypt secrets and then pass them in an obfuscated form into applications.

 

FeaturesInstallUsageContributing

Features

☑️ Keep your secrets out of Git

Set up secrets locally outside of the Git repository to avoid them being embedded into the code.

☑️ Encrypt secrets

Create encryption key and encrypt secrets ready for use.

☑️ Access secrets from your app

Generate a Swift file to access the secrets from your app's code.

☑️ Obfuscation

The generated Swift uses obfuscation of the values rather than as raw strings.

 

Install

The primary intention was to use Cloak Swift as a Tuist plugin, however, it can also be used as a standard CLI tool as well.

▶︎ 🖥 As a Tuist Plugin

To set up as a Tuist plugin in your project simply follow the Tuist plugin install instructions using the latest version.

Add the plugin to Config.swift.

import ProjectDescription

let config = Config(
    plugins: [
        .git(url: "https://github.com/lordcodes/cloak-swift.git", tag: "v0.1.0")
    ]
)

▶︎ 🖥 Standalone via Swift Package Manager

Cloak Swift can be easily installed globally using Swift Package Manager.

 git clone https://github.com/lordcodes/cloak-swift
 cd cloak-swift
 make install

This will install cloakswift into /usr/local/bin. If you get a permission error it may be that you don't have permission to write there in which case you just need to adjust permissions using sudo chown -R $(whoami) /usr/local/bin.

You can uninstall it again using make uninstall which simply deletes it from /usr/local/bin.

▶︎ 🍺 Homebrew

Support for Homebrew may be planned in the future.

▶︎ 📦 As a Swift package

To install Cloak Swift for use in your own Swift code, add it is a Swift Package Manager dependency within your Package.swift file. For help in doing this, please check out the Swift Package Manager documentation.

.package(url: "https://github.com/lordcodes/cloak-swift", exact: "0.1.0")

 

Usage

Set up configuration

Create a configuration file within your project: .cloak/config, this file should be kept in Git and shared between contributors. Enter key-value pairs into the file EnvironmentKey.

  • CLOAK_SECRETS_CLASS_NAME -> Name to give the generated Swift enum that contains the secrets in-app.
  • CLOAK_SECRETS_OUTPUT_FILEPATH -> File path to put the generated Swift file.
  • CLOAK_SECRETS_ACCESS_LEVEL -> Swift access level to give to the enum and each secret static property. E.g. public.

Each of these settings can be provided as an environment variable instead of listed in the configuration file. The config file will take precedance.

For example:

CLOAK_SECRETS_CLASS_NAME=AppSecrets
CLOAK_SECRETS_OUTPUT_FILEPATH=Sources/Generated/AppSecrets.swift
CLOAK_SECRETS_ACCESS_LEVEL=public

Configure required secret keys

You can list the required secret keys for your project in a .cloak/secret-keys file, which can be kept in Git. This ensures each contributor has provided all required secrets locally. Secret keys should be listed one on each line.

For example:

ANALYTICS_WRITE_KEY
API_CLIENT_ID
API_CLIENT_SECRET

Configure secrets

Each contributor on a project will need to create a file at .cloak/secrets that uses the same format as the config file but that lists secret key names and values. This file should be added to your project's .gitignore to keep them out of Git.

You should also add your encryption key to this file using the key name CLOAK_ENCRYPTION_KEY. This will allow the encrypt/decrypt commands to function and will also allow it to be included into the generated Swift file so that your app can decrypt the secrets at runtime in order to use them.

If the secret keys are specified in the required keys file secret-keys, then they will be read as environment variables as well, where the environment variables take precendence. This is useful in a CI environment where you can specify them as environment variables and avoid having to write them to a file as you would locally.

IMPORTANT NOTE: The secrets aren't read as environment variables correctly when using Cloak as a Tuist plugin, due to the environment Tuist plugins are executed in. Therefore, it is best to write the secrets to a file in a setup step of your CI workflow.

The best practice is that the values should be encrypted first.

🖥 Via the Tuist Plugin

Run Cloak's tasks via Tuist. The tool will check paths relative to the working directory for the .cloak directory configured above.

USAGE: tuist cloak  [-q|--quiet]

SUBCOMMANDS:
  createkey  Create encryption key.
  decrypt    Decrypt a value encrypted using cloak.
  encrypt    Encrypt a value.
  generate   Read in secrets, obfuscate them and then generate a Swift file to access them within an app.
  version    Print version.

OPTIONS:
  -q, --quiet             Silence any output except errors 

You can obtain help using tuist cloak --help and also obtain help for each subcommand using tuist cloak --help.

Create encryption key

Generates an encryption key, that can then be used within your project to encrypt secrets. This key is then passed into your app so that you can decrypt them at runtime.

tuist cloak createkey

Encrypt a value

Provide a value and the encrypted version will be returned. Your encryption key should be provided as described above.

tuist cloak encrypt

Decrypt an encrypted value

Provide an encrypted value and the decrypted version will be returned. Your encryption key should be provided as described above.

tuist cloak decrypt

Generate a secrets file in-app

Generate a Swift file that can be used to access your secrets within your app at runtime. Certain aspects of the generated file can be customised using the config file as described above. The secrets will be obfuscated and included as [UInt8], but with Swift properties to return them as String in their usable form.

tuist cloak generate

🖥 Via the Standalone CLI

Run Cloak's tasks via a standalone executable. The tool will check paths relative to the working directory for the .cloak directory configured above.

USAGE: cloakswift  [-q|--quiet]

Same usage as the Tuist plugin, except tuist cloak is replaced with cloakswift.

📦 As a Swift Package

To use Cloak Swift within your own Swift code, import and use the public API of CloakKit.

import CloakKit

// Configure printing
Cloak.shared.printer = ConsolePrinter(quiet: false)

EncryptionService().createKey()

Contributing or Help

If you notice any bugs or have a new feature to suggest, please check out the contributing guide. If you want to make changes, please make sure to discuss anything big before putting in the effort of creating the PR.

To reach out, please contact @lordcodes on Twitter.

You might also like...
RSA public/private key encryption, private key signing and public key verification in Swift using the Swift Package Manager. Works on iOS, macOS, and Linux (work in progress).

BlueRSA Swift cross-platform RSA wrapper library for RSA encryption and signing. Works on supported Apple platforms (using Security framework). Linux

RSA public/private key encryption, private key signing and public key verification in Swift using the Swift Package Manager. Works on iOS, macOS, and Linux (work in progress).

BlueRSA Swift cross-platform RSA wrapper library for RSA encryption and signing. Works on supported Apple platforms (using Security framework). Linux

Swift-problem-solving - Swift 알고리즘 맛보기 😋

swift-problem-solving Swift 로 알고리즘 익히기 😆 Programmers 난이도 풀이 문제 바로가기 Lv.2 오픈채팅방 링크 Lv.3 다단계 칫솔 판매 링크 Lv.3 합승 택시 요금 링크 Leetcode 난이도 풀이 문제 바로가기 Medium 1

Swift-cuckoo-collections - Cross-platform Swift dictionaries & sets that use a cuckoo hashing algorithm

CuckooCollections A Swift package for open-addressed sets and dictionaries that

CryptoSwift is a growing collection of standard and secure cryptographic algorithms implemented in Swift
CryptoSwift is a growing collection of standard and secure cryptographic algorithms implemented in Swift

CryptoSwift Crypto related functions and helpers for Swift implemented in Swift. (#PureSwift) Note: The master branch follows the latest currently rel

A framework for the JOSE standards JWS, JWE, and JWK written in Swift.

JOSESwift is a modular and extensible framework for the JOSE standards JWS, JWE, and JWK written in Swift. 💡 Please note that this implementation of

CCCryptor (AES encryption) wrappers for iOS and Mac in Swift. -- For ObjC, see RNCryptor/RNCryptor-objc

RNCryptor Cross-language AES Encryptor/Decryptor data format. The primary targets are Swift and Objective-C, but implementations are available in C, C

Simple and secure hashing in Swift with the SipHash algorithm

SipHash ⚠️ WARNING This package has been obsoleted by the Hasher type and the Hashable.hash(into:) requirement introduced in Swift 4.2. Using this pac

Simple Swift wrapper for Keychain that works on iOS, watchOS, tvOS and macOS.
Simple Swift wrapper for Keychain that works on iOS, watchOS, tvOS and macOS.

KeychainAccess KeychainAccess is a simple Swift wrapper for Keychain that works on iOS and OS X. Makes using Keychain APIs extremely easy and much mor

Comments
  • SwiftFormat

    SwiftFormat

    Checklist

    • [X] I've read the guide for contributing.
    • [X] I've checked there are no other open pull requests for the same change.
    • [X] I've updated documentation if needed.
    • [X] I've tested all changes are working as intended.

    Reason for change

    Format project code using SwiftFormat and check it is formatted on CI.

    Description

    Add SwiftFormat Tuist plugin, add configuration and run it on project.

    changelog:added 
    opened by lordcodes 0
Releases(v0.3.0)
Owner
Andrew Lord
Lead Mobile Developer @GetBusyHQ. Builder of Android and iOS apps. Blogs at lordcodes.com. Avid gamer and music fan. All views and opinions shared are my own.
Andrew Lord
A tiny and easy to use Swift class to encrypt strings using HMAC algorithms.

#Sweet HMAC SweetHMAC is a tiny and easy to use Swift class to encrypt strings using HMAC algorithms. A special thanks to jernejstrasner for shared HM

Jan Cássio 37 Jul 27, 2022
RSA encrypt and decrypt in Swift

MZRSA_Swift MZRSA_Swift是一个轻量级框架,框架功能包含RSA加密/解密Data、RSA加密/解密String,支持字符串密钥和证书密钥 公钥加密&私钥解密(字符串密钥) 代码示例 let PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8

null 8 Jan 5, 2023
PGPro can encrypt and decrypt messages as well as manage all your OpenPGP keys. It is free, simple and lightweight. Everything stays on your device. PGPro is made in Switzerland.

PGPro can encrypt and decrypt messages as well as manage all your OpenPGP keys. It is free, simple and lightweight. Everything stays on your device. P

Luca Näf 250 Jan 4, 2023
Generate passwords and save them in Keychain. Made with SwiftUI.

lockd Generate strong passwords and save them in Keychain. Join lockd Beta on TestFlight: https://testflight.apple.com/join/xJ5AlvS3 Features: Generat

Iliane 56 Dec 29, 2022
Decrypts FairPlay applications on iOS 13.4.1 and lower, no jb required

yacd (Yet Another Code Decrypter) Decrypts FairPlay (App Store) applications on iOS 13.4.1 and lower, no jb required Use for research purposes only, I

Derek 669 Dec 10, 2022
PassDrop is a fully-featured secure password management system, compatible with the free KeePass 1.x (Classic) and multi-platform KeePassX desktop applications.

passdrop This is a modern, updated build of Rudis Muiznieks's PassDrop application. PassDrop is a fully-featured secure password management system, co

Chad Austin 33 Sep 23, 2022
Ported Shamirs Secret Sharing Into A Swift Package

Shamirs-Secret-Sharing-Swift Ported Shamirs Secret Sharing Into A Swift Package Based on Adi Shamir's Secret Sharing (https://en.wikipedia.org/wiki/Sh

Charles Edge 5 May 15, 2022
A super simple tool for macOS Swift developers to check validity of a Gumroad-issued software license keys

Gumroad License Validator Overview A super simple tool for macOS Swift developers to check validity of a Gumroad-issued software license keys Requirem

Daniel Kašaj 13 Sep 2, 2022
SuccessorCLI A CLI tool to restore iOS Devices on versions they're already on, based on the original Succession

A tool to restore iOS Devices on versions they're already on, based on the original Succession

Dabezt 11 Dec 26, 2022
Open-source jailbreaking tool for many iOS devices

Open-source jailbreaking tool for many iOS devices *Read disclaimer before using this software. checkm8 permanent unpatchable bootrom exploit for hund

null 0 Nov 6, 2021