用 Swift 编写的 JOSE 标准 JWS、JWE 和 JWK 的框架
JOSESwift 是用 Swift 编写的 JOSE 标准 JWS、JWE 和 JWK 的模块化和可扩展框架。
:灯泡:请注意,JOSE 标准的实施尚未完全完成。例如,目前只有一组有限的受支持算法可用。此外,我们目前仅支持JOSE类型的紧凑序列化。如果缺少特定功能、算法或序列化,请随时提交拉取请求。
特征
- JWS:使用 JWS 标准对任意数据进行数字签名和验证。
- JWE:使用 JWE 标准加密和解密任意数据。
- JWK:编码和解码加密密钥。
如果缺少特定功能、算法或序列化,请随时提交拉取请求。
加密算法
:lock_with_ink_pen: JWS | :closed_lock_with_key: JWE | :键: JWK | |||||||
---|---|---|---|---|---|---|---|---|---|
数字签名和 MAC | 密钥管理 | 内容加密 | 钥匙 | ||||||
HS256 | :white_check_mark: | RSA1_5 | :white_check_mark: | A128CBC-HS256 | :white_check_mark: | RSA | :white_check_mark: | ||
HS384 | :white_check_mark: | RSA-OAEP | :white_check_mark: | A192CBC-HS384 | EC | :white_check_mark: | |||
HS512 | :white_check_mark: | RSA-OAEP-256 | :white_check_mark: | A256CBC-HS512 | :white_check_mark: | oct | :white_check_mark: | ||
RS256 | :white_check_mark: | A128KW | :white_check_mark: | A128GCM | |||||
RS384 | :white_check_mark: | A192KW | :white_check_mark: | A192GCM | |||||
RS512 | :white_check_mark: | A256KW | :white_check_mark: | A256GCM | |||||
ES256 | :white_check_mark: | dir | :white_check_mark: | ||||||
ES384 | :white_check_mark: | ECDH-ES | |||||||
ES512 | :white_check_mark: | ECDH-ES+A128KW | |||||||
PS256 | :white_check_mark: | ECDH-ES+A192KW | |||||||
PS384 | :white_check_mark: | ECDH-ES+A256KW | |||||||
PS512 | :white_check_mark: | A128GCMKW | |||||||
A192GCMKW | |||||||||
A256GCMKW | |||||||||
PBES2-HS256+A128KW | |||||||||
PBES2-HS384+A192KW | |||||||||
PBES2-HS512+A256KW |
Serializations
For interchangeability JOSESwift currently supports compact serialization for JWS and for JWE.
Compact Serialization | JSON Serialization |
---|---|
:white_check_mark: |
Compression Algorithms
JOSESwift supports the DEFLATE compression algorithm for JWE.
Installation
JOSESwift integrates nicely into your iOS and macOS projects. We support the following package managers:
CocoaPods
To integrate JOSESwift into your Xcode project, include it in your :Podfile
Then install it by running . More documentation on using CocoaPods can be found here.pod install
Carthage
To integrate JOSESwift in your Xcode project, include it in your :Cartfile
github "airsidemobile/JOSESwift" ~> 2.3
Then build it by running and drag the built framework into your Xcode project. More documentation on using Carthage can be found here.carthage update
Swift Package Manager
To integrate JOSESwift in your Xcode project as a Swift package, follow Apple's article on how to add package dependencies to your app.
Alternatively, when using Swift Package Manager manually include the following dependency in your file. See Apple's documentation for more details on specifying dependency version requirements.Package.swift
Usage
JOSESwift covers three functional aspects:
JWS: Digital Signatures
A encapsulates and secures data using a digital signature which can be verified by the receiver of the .JWS
JWS
Signing Data
In order to construct a JWS we need to provide the following parts:
- Header
- Payload
- Signer
Header
Optionally you can set addtitional parameters:
Payload
Signer
The signer algorithm must match the header algorithm.
Serializing
The JWS compact serialization is a URL-safe string that can easily be transmitted to a third party using a method of your choice.
More details about constructing a JWS can be found in the wiki.
Verifying Data
More details about verifying an existing, serialized JWS can be found in the wiki.
JWE: Encryption and Decryption
A JWE encapsulates and secures data by encrypting it. It can be decrypted by the receiver of the JWE.
Encrypting Data
In order to construct a JWE we need to provide the following parts:
- Header
- Payload
- Encrypter
Header
Optionally you can set addtitional parameters:
Payload
Encrypter
The encrypter algorithms must match the header algorithms.
Note that the type of the provided encryption key must match the specified key management algorithm as shown in the following table.
Key Management Algorithm | Encryption Key Type |
---|---|
RSA1_5 | SecKey |
RSAOAEP | SecKey |
RSAOAEP256 | SecKey |
A128KW | Data |
A192KW | Data |
A256KW | Data |
direct | Data |
Serialization
The JWE compact serialization is a URL-safe string that can easily be transmitted to a third party using a method of your choice.
More details about constructing a JWE can be found in the wiki.
Decrypting Data
More details about decrypting an existing, serialized JWE can be found in the wiki.
Note that the type of the provided decryption key must match the specified key management algorithm as shown in the following table.
Key Management Algorithm | Decryption Key Type |
---|---|
RSA1_5 | SecKey |
RSAOAEP | SecKey |
RSAOAEP256 | SecKey |
A128KW | Data |
A192KW | Data |
A256KW | Data |
direct | Data |
JWK: Representing Keys
A JWK is a JSON data structure that represents a cryptographic key. You could use it, for instance, as the payload of a JWS or a JWE to transmit your public key to a server.
Encoding RSA Public Keys
More details about encoding RSA public keys can be found in the wiki.
Decoding RSA Public Keys
More details about decoding RSA public keys can be found in the wiki.
:warning: We currently ignore the key parameters "key_ops"
and "x5c"
when decoding. This is due to a bug in our decoding implementation. See #117 for details.
Security
JOSESwift uses Apple's Security framework and Apple’s CommonCrypto for cryptography.
For security disclosures or related matters, please contact joseswift@airsidemobile.com.
See our security policy for more information.
Contributing
Contributions to the project are encouraged and more than welcome. :nerd_face:
If you want to contribute, please submit a pull request.
For feature requests, discussions, or bug reports, just open an issue.
See our contributing guidelines for more information.
Resources
You can find detailed information about the relevant JOSE standards in the respective RFCs:
- RFC-7515: JSON Web Signature (JWS)
- RFC-7516: JSON Web Encryption (JWE)
- RFC-7517: JSON Web Key (JWK)
- RFC-7518: JSON Web Algorithms (JWA)
Don’t forget to check our our wiki for more detailed documentation.
Contact
Feel free to contact the project maintainers at joseswift@airsidemobile.com.
Credits
JOSESwift is maintained by Airside Mobile.
Project Authors and Maintainers
@carol-mohemian,
@daniel-mohemian,
@gigi-mohemian
Reviewers
Logo
The logo was designed by Ivan Leuzzi.
Thanks
To the following projects, which served us as reference and inspiration during development:
License
JOSESwift is licensed under the Apache License 2.0. See LICENSE for details.