-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3927c1a
commit e1ef859
Showing
18 changed files
with
470 additions
and
78 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 |
---|---|---|
@@ -1,16 +1,25 @@ | ||
1574a1575,1589 | ||
1671a1672,1695 | ||
> "ios64sim-cross" => { | ||
> inherit_from => [ "darwin-common", asm("no_asm") ], | ||
> inherit_from => [ "ios-common" ], | ||
> cflags => add("-arch x86_64 -DOPENSSL_NO_ASM -mios-version-min=7.0.0 -isysroot \$(CROSS_TOP)/SDKs/\$(CROSS_SDK) -fno-common"), | ||
> module_ldflags => "-shared", | ||
> LDFLAGS => "-shared", | ||
> sys_id => "iOS", | ||
> bn_ops => "SIXTY_FOUR_BIT_LONG RC4_CHAR", | ||
> perlasm_scheme => "ios64", | ||
> }, | ||
> "ios64sim-arm64-cross" => { | ||
> inherit_from => [ "darwin-common", asm("no_asm") ], | ||
> inherit_from => [ "darwin-common" ], | ||
> CC => "xcrun -sdk iphonesimulator cc", | ||
> cflags => add("-arch arm64 -DOPENSSL_NO_ASM -mios-simulator-version-min=14.0.0 -isysroot \$(CROSS_TOP)/SDKs/\$(CROSS_SDK) -fno-common"), | ||
> sys_id => "iOS", | ||
> module_ldflags => "-shared", | ||
> LDFLAGS => "-shared", | ||
> bn_ops => "SIXTY_FOUR_BIT_LONG RC4_CHAR", | ||
> perlasm_scheme => "ios64", | ||
> }, | ||
> "ios64-cross-fix" => { | ||
> inherit_from => [ "ios64-cross" ], | ||
> module_ldflags => "-shared", | ||
> LDFLAGS => "-shared", | ||
> }, |
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,7 @@ | ||
--- Configurations/shared-info.pl 2022-03-25 13:37:12.000000000 +0100 | ||
+++ Configurations/shared-info.pl 2022-03-25 13:37:18.000000000 +0100 | ||
@@ -44,2 +44,2 @@ | ||
- module_ldflags => '-bundle', | ||
- shared_ldflag => '-dynamiclib -current_version $(SHLIB_VERSION_NUMBER) -compatibility_version $(SHLIB_VERSION_NUMBER)', | ||
+ module_ldflags => '', | ||
+ shared_ldflag => '-current_version $(SHLIB_VERSION_NUMBER) -compatibility_version $(SHLIB_VERSION_NUMBER)', |
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 |
---|---|---|
|
@@ -296,4 +296,4 @@ RUBY VERSION | |
ruby 2.6.5p114 | ||
|
||
BUNDLED WITH | ||
2.2.16 | ||
2.3.11 |
Large diffs are not rendered by default.
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
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
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,119 @@ | ||
// | ||
// Copyright (c) 2022 gematik GmbH | ||
// | ||
// Licensed under the EUPL, Version 1.2 or – as soon they will be approved by | ||
// the European Commission - subsequent versions of the EUPL (the Licence); | ||
// You may not use this work except in compliance with the Licence. | ||
// You may obtain a copy of the Licence at: | ||
// | ||
// https://joinup.ec.europa.eu/software/page/eupl | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the Licence is distributed on an "AS IS" basis, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the Licence for the specific language governing permissions and | ||
// limitations under the Licence. | ||
// | ||
// | ||
|
||
@_implementationOnly import COpenSSL | ||
import Foundation | ||
|
||
/// CMSContentInfo | ||
public class CMSContentInfo { | ||
let cms: OpaquePointer | ||
|
||
init() { | ||
cms = CMS_ContentInfo_new() | ||
} | ||
|
||
required init(owningNoCopy cms: OpaquePointer) { | ||
self.cms = cms | ||
} | ||
|
||
/// De-initialize | ||
deinit { | ||
CMS_ContentInfo_free(cms) | ||
} | ||
|
||
/// Get the DER byte representation as `Data` | ||
public var derBytes: Data? { | ||
var dataPtr: UnsafeMutablePointer<UInt8>? | ||
let length = i2d_CMS_ContentInfo(cms, &dataPtr) | ||
guard length > 0, let safeDataPtr = dataPtr else { | ||
return nil | ||
} | ||
|
||
return Data(bytesNoCopy: safeDataPtr, count: Int(length), deallocator: .free) | ||
} | ||
|
||
/// Entry step for the `encryptPartial`, `addRecipients`, `final` (as in `init`, `update`, `final`) cycle. | ||
/// | ||
/// - Important: Encryption is done by `aes_256_gcm` | ||
/// - Parameter data: Data (e.g. a message) to be encrypted | ||
/// - Returns: A (partially) initialized `CMSContentInfo` | ||
/// - Throws: `OpenSSLError` | ||
public static func encryptPartial(data: Data) throws -> Self { | ||
let flagPartial = UInt32(CMS_PARTIAL) // don't call `finalize` immediately | ||
let flags = flagPartial | ||
|
||
let cms: OpaquePointer! | ||
cms = try data.withUnsafeBytes { unsafeRawBufferPointer in | ||
let bytesPtr = unsafeRawBufferPointer.bindMemory(to: UInt8.self).baseAddress | ||
let dataBio = BIO_new_mem_buf(bytesPtr, Int32(unsafeRawBufferPointer.count)) | ||
defer { BIO_free(dataBio) } | ||
|
||
guard let ret = CMS_encrypt(nil, dataBio, EVP_aes_256_gcm(), flags) else { | ||
throw OpenSSLError(name: "Error calling CMS_encrypt()") | ||
} | ||
return ret | ||
} | ||
return .init(owningNoCopy: cms) | ||
} | ||
|
||
/// Update step for the `encryptPartial`, `addRecipients`, `final` (as in `init`, `update`, `final`) cycle. | ||
/// | ||
/// - Important: This will only work with `X509` certificates that contain a RSA public key! | ||
/// - Parameter recipients: | ||
/// - Throws: `OpenSSLError` | ||
public func addRecipientsRSAOnly(_ recipients: [X509]) throws { | ||
let flagPartial = UInt32(CMS_PARTIAL) // don't call `finalize` immediately | ||
let flags = flagPartial | ||
|
||
for recipient in recipients { | ||
var ri: OpaquePointer! // swiftlint:disable:this identifier_name | ||
var pctx: OpaquePointer! | ||
ri = CMS_add1_recipient_cert(cms, recipient.x509, flags | UInt32(CMS_KEY_PARAM)) | ||
pctx = CMS_RecipientInfo_get0_pkey_ctx(ri) | ||
guard EVP_PKEY_CTX_set_rsa_oaep_md(pctx, EVP_sha256()) == 1 else { | ||
throw OpenSSLError(name: "Error calling EVP_PKEY_CTX_set_rsa_oaep_md()") | ||
} | ||
guard EVP_PKEY_CTX_set_rsa_mgf1_md(pctx, EVP_sha256()) == 1 else { | ||
throw OpenSSLError(name: "Error calling EVP_PKEY_CTX_set_rsa_mgf1_md()") | ||
} | ||
guard EVP_PKEY_CTX_set_rsa_padding(pctx, RSA_PKCS1_OAEP_PADDING) == 1 else { | ||
throw OpenSSLError(name: "Error calling EVP_PKEY_CTX_set_rsa_padding()") | ||
} | ||
} | ||
} | ||
|
||
/// Final step for the `encryptPartial`, `addRecipients`, `final` (as in `init`, `update`, `final`) cycle. | ||
/// | ||
/// - Parameter data: Data (e.g. a message) to be encrypted | ||
/// - Throws: `OpenSSLError` | ||
public func final(data: Data) throws { | ||
let flagPartial = UInt32(CMS_PARTIAL) // don't call `finalize` immediately | ||
let flags = flagPartial | ||
|
||
try data.withUnsafeBytes { unsafeRawBufferPointer in | ||
let bytesPtr = unsafeRawBufferPointer.bindMemory(to: UInt8.self).baseAddress | ||
let dataBio = BIO_new_mem_buf(bytesPtr, Int32(unsafeRawBufferPointer.count)) | ||
defer { | ||
BIO_free(dataBio) | ||
} | ||
guard CMS_final(cms, dataBio, nil, flags) == 1 else { | ||
throw OpenSSLError(name: "Error calling CMS_final()") | ||
} | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.