Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from valeriomazzeo/feature/jwk
Added JWK and JWKS support
- Loading branch information
Showing
37 changed files
with
1,309 additions
and
484 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ Packages | |
Package.pins | ||
Package.resolved | ||
DerivedData | ||
.swiftpm | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
// swift-tools-version:4.0 | ||
// swift-tools-version:5.0 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "JWT", | ||
name: "jwt-kit", | ||
products: [ | ||
.library(name: "JWT", targets: ["JWT"]), | ||
], | ||
dependencies: [ | ||
// 🌎 Utility package containing tools for byte manipulation, Codable, OS APIs, and debugging. | ||
.package(url: "https://github.com/vapor/core.git", from: "3.0.0"), | ||
|
||
// 🔑 Hashing (BCrypt, SHA, HMAC, etc), encryption, and randomness. | ||
.package(url: "https://github.com/vapor/crypto.git", from: "3.0.0"), | ||
.library(name: "JWTKit", targets: ["JWTKit"]), | ||
], | ||
dependencies: [ ], | ||
targets: [ | ||
.target(name: "JWT", dependencies: ["Core", "Crypto"]), | ||
.testTarget(name: "JWTTests", dependencies: ["JWT"]), | ||
.systemLibrary( | ||
name: "CJWTKitOpenSSL", | ||
pkgConfig: "openssl", | ||
providers: [ | ||
.apt(["openssl libssl-dev"]), | ||
.brew(["openssl"]) | ||
] | ||
), | ||
.target(name: "CJWTKitCrypto", dependencies: ["CJWTKitOpenSSL"]), | ||
.target(name: "JWTKit", dependencies: ["CJWTKitCrypto"]), | ||
.testTarget(name: "JWTKitTests", dependencies: ["JWTKit"]), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "include/c_jwtkit_crypto.h" | ||
|
||
#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER) | ||
EVP_MD_CTX *EVP_MD_CTX_new(void) { | ||
return EVP_MD_CTX_create(); | ||
}; | ||
|
||
void EVP_MD_CTX_free(EVP_MD_CTX *ctx) { | ||
EVP_MD_CTX_cleanup(ctx); | ||
free(ctx); | ||
}; | ||
|
||
int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d) { | ||
r->n = n; | ||
r->e = e; | ||
r->d = d; | ||
return 0; | ||
}; | ||
|
||
HMAC_CTX *HMAC_CTX_new(void) { | ||
HMAC_CTX *ptr = malloc(sizeof(HMAC_CTX)); | ||
HMAC_CTX_init(ptr); | ||
return ptr; | ||
}; | ||
|
||
void HMAC_CTX_free(HMAC_CTX *ctx) { | ||
HMAC_CTX_cleanup(ctx); | ||
free(ctx); | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef C_JWTKIT_OPENSSL_H | ||
#define C_JWTKIT_OPENSSL_H | ||
|
||
#include <openssl/conf.h> | ||
#include <openssl/evp.h> | ||
#include <openssl/err.h> | ||
#include <openssl/bio.h> | ||
#include <openssl/ssl.h> | ||
#include <openssl/sha.h> | ||
#include <openssl/md5.h> | ||
#include <openssl/hmac.h> | ||
#include <openssl/rand.h> | ||
#include <openssl/rsa.h> | ||
#include <openssl/pkcs12.h> | ||
#include <openssl/x509v3.h> | ||
|
||
#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER) | ||
EVP_MD_CTX *EVP_MD_CTX_new(void); | ||
void EVP_MD_CTX_free(EVP_MD_CTX *ctx); | ||
int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d); | ||
HMAC_CTX *HMAC_CTX_new(void); | ||
void HMAC_CTX_free(HMAC_CTX *ctx); | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module CJWTKitOpenSSL [system] { | ||
link "ssl" | ||
link "crypto" | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Foundation | ||
|
||
public extension JWK { | ||
public enum KeyOperation: String, Codable { | ||
/// Compute digital signature or MAC. | ||
case sign | ||
/// Verify digital signature or MAC. | ||
case verify | ||
/// Encrypt content. | ||
case encrypt | ||
/// Decrypt content and validate decryption, if applicable. | ||
case decrypt | ||
/// Encrypt key. | ||
case wrapKey | ||
/// Decrypt key and validate decryption, if applicable. | ||
case unwrapKey | ||
/// Derive key. | ||
case deriveKey | ||
/// Derive bits not to be used as a key. | ||
case deriveBits | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import Foundation | ||
|
||
public extension JWK { | ||
public enum PublicKeyUse: RawRepresentable, Codable { | ||
case signature | ||
case encryption | ||
case other(String) | ||
|
||
public var rawValue: String { | ||
switch self { | ||
case .signature: | ||
return "sig" | ||
case .encryption: | ||
return "enc" | ||
case .other(let value): | ||
return value | ||
} | ||
} | ||
|
||
public init(rawValue: String) { | ||
switch rawValue { | ||
case "sig": | ||
self = .signature | ||
case "enc": | ||
self = .encryption | ||
default: | ||
self = .other(rawValue) | ||
} | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
let rawValue = try container.decode(String.self) | ||
self.init(rawValue: rawValue) | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.singleValueContainer() | ||
try container.encode(self.rawValue) | ||
} | ||
} | ||
} |
Oops, something went wrong.