Skip to content

Commit

Permalink
add defines for test package and secitem options test
Browse files Browse the repository at this point in the history
  • Loading branch information
sbSteveK committed Oct 7, 2024
1 parent f6b1371 commit 8d80134
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 17 deletions.
6 changes: 6 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ cSettingsIO.append(.define("AWS_USE_EPOLL"))
awsCIoPlatformExcludes.append("source/windows")
awsCIoPlatformExcludes.append("source/linux")
awsCIoPlatformExcludes.append("source/s2n")
cSettingsIO.append(.define("AWS_OS_APPLE"))
cSettingsIO.append(.define("__APPLE__"))
cSettingsIO.append(.define("AWS_USE_DISPATCH_QUEUE", .when(platforms: [.iOS, .tvOS])))
cSettingsIO.append(.define("AWS_USE_SECITEM", .when(platforms: [.iOS, .tvOS])))
Expand Down Expand Up @@ -310,6 +311,11 @@ packageTargets.append(contentsOf: [
path: "Test/AwsCommonRuntimeKitTests",
resources: [
.process("Resources")
],
cSettings: [
.define("AWS_USE_SECITEM", .when(platforms: [.iOS, .tvOS])),
.define("AWS_USE_DISPATCH_QUEUE", .when(platforms: [.iOS, .tvOS])),
.define("AWS_USE_KQUEUE", .when(platforms: [.macOS]))
]
),
.executableTarget(
Expand Down
17 changes: 17 additions & 0 deletions Test/AwsCommonRuntimeKitTests/io/TLSContextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,21 @@ class TLSContextTests: XCBaseTestCase {
_ = TLSConnectionOptions(context: context)
}
#endif

#if AWS_USE_SECITEM
func testCreateTlsContextWithSecitemOptions() throws {
let certPath = try getEnvironmentVarOrSkipTest(environmentVarName: "AWS_TEST_MQTT311_IOT_CORE_X509_CERT")
let privateKeyPath = try getEnvironmentVarOrSkipTest(environmentVarName: "AWS_TEST_MQTT311_IOT_CORE_X509_KEY")

let certificateData = try Data(contentsOf: URL(fileURLWithPath: certPath))
let privateKeyData = try Data(contentsOf: URL(fileURLWithPath: privateKeyPath))

let options = try TLSContextOptions.makeMTLS(certificateData: certificateData, privateKeyData: privateKeyData)
try options.setSecitemLabels(certLabel: "TEST_CERT_LABEL", keyLabel: "TEST_KEY_LABEL")

let context = try TLSContext(options:options, mode: .client)
_ = TLSConnectionOptions(context: context)
}

#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
A63CEBC82C2387CD003A71B7 /* AwsCommonRuntimeKit in Frameworks */ = {isa = PBXBuildFile; productRef = A63CEBC72C2387CD003A71B7 /* AwsCommonRuntimeKit */; };
A6C798772C238DD30055AE09 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A6C798762C238DD30055AE09 /* Assets.xcassets */; };
A6C7987B2C2A2A340055AE09 /* AwsCommonRuntimeKit in Frameworks */ = {isa = PBXBuildFile; productRef = A6C7987A2C2A2A340055AE09 /* AwsCommonRuntimeKit */; };
C88382BA2CAC799800EC5E5E /* AwsCommonRuntimeKit in Frameworks */ = {isa = PBXBuildFile; productRef = C88382B92CAC799800EC5E5E /* AwsCommonRuntimeKit */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -30,6 +31,7 @@
A6C7987B2C2A2A340055AE09 /* AwsCommonRuntimeKit in Frameworks */,
A63CEBC62C2387A3003A71B7 /* AwsCommonRuntimeKit in Frameworks */,
A63CEBC82C2387CD003A71B7 /* AwsCommonRuntimeKit in Frameworks */,
C88382BA2CAC799800EC5E5E /* AwsCommonRuntimeKit in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -82,6 +84,7 @@
A63CEBC52C2387A3003A71B7 /* AwsCommonRuntimeKit */,
A63CEBC72C2387CD003A71B7 /* AwsCommonRuntimeKit */,
A6C7987A2C2A2A340055AE09 /* AwsCommonRuntimeKit */,
C88382B92CAC799800EC5E5E /* AwsCommonRuntimeKit */,
);
productName = MqttClient;
productReference = A63CEBB12C238347003A71B7 /* MqttClient.app */;
Expand Down Expand Up @@ -112,7 +115,7 @@
);
mainGroup = A63CEBA82C238347003A71B7;
packageReferences = (
A6C798792C2A2A340055AE09 /* XCLocalSwiftPackageReference "../../.." */,
C88382B82CAC799800EC5E5E /* XCLocalSwiftPackageReference "../../../../aws-crt-swift" */,
);
productRefGroup = A63CEBB22C238347003A71B7 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -274,7 +277,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = ML5AUYTTTK;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
Expand Down Expand Up @@ -350,9 +353,9 @@
/* End XCConfigurationList section */

/* Begin XCLocalSwiftPackageReference section */
A6C798792C2A2A340055AE09 /* XCLocalSwiftPackageReference "../../.." */ = {
C88382B82CAC799800EC5E5E /* XCLocalSwiftPackageReference "../../../../aws-crt-swift" */ = {
isa = XCLocalSwiftPackageReference;
relativePath = ../../..;
relativePath = "../../../../aws-crt-swift";
};
/* End XCLocalSwiftPackageReference section */

Expand All @@ -369,6 +372,10 @@
isa = XCSwiftPackageProductDependency;
productName = AwsCommonRuntimeKit;
};
C88382B92CAC799800EC5E5E /* AwsCommonRuntimeKit */ = {
isa = XCSwiftPackageProductDependency;
productName = AwsCommonRuntimeKit;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = A63CEBA92C238347003A71B7 /* Project object */;
Expand Down
44 changes: 31 additions & 13 deletions Test/IntegrationTests/MqttClient/MqttClient/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import AwsCommonRuntimeKit
// Update the host and port before run the app.
let TEST_HOST = "<endpoint>"
let TEST_PORT: UInt32 = 1883

let TLS_HOST = "a2yvr5l8sc9814-ats.iot.us-east-1.amazonaws.com"
let TLS_PORT: UInt32 = 8883

var mqttTestContext = MqttTestContext()
var client: Mqtt5Client?

Expand Down Expand Up @@ -196,7 +200,7 @@ func createClient(clientOptions: MqttClientOptions, testContext: MqttTestContext

/// Init CRT library
func library_init() {
try? Logger.initialize(target: .standardOutput, level: .debug)
try? Logger.initialize(target: .standardOutput, level: .trace)
CommonRuntimeKit.initialize()
}

Expand All @@ -206,20 +210,34 @@ func setupClientAndStart() {
qos: .background)

backgroundQueue.async {

let ConnectPacket = MqttConnectOptions(keepAliveInterval: 60, clientId: createClientId())

let clientOptions = MqttClientOptions(
hostName: TEST_HOST,
port: TEST_PORT,
connectOptions: ConnectPacket,
connackTimeout: TimeInterval(10))

do {
client = try createClient(clientOptions: clientOptions, testContext: mqttTestContext)
try connectClient(client: client!, testContext: mqttTestContext)
let certFile = "/Users/sbstevek/workplace/swift-bindings-secitem/aws-crt-swift/.vscode/sdk_mqtt5_thing_cert.pem"
let keyFile = "/Users/sbstevek/workplace/swift-bindings-secitem/aws-crt-swift/.vscode/sdk_mqtt5_thing_key.pem"


let tlsOptions = try TLSContextOptions.makeMTLS(certificatePath: certFile, privateKeyPath: keyFile)
try tlsOptions.setSecitemLabels(certLabel: "DUMB_CERT_LABEL", keyLabel: "Test_Key_Label")

let tlsContext = try TLSContext(options: tlsOptions, mode: .client)

let ConnectPacket = MqttConnectOptions(keepAliveInterval: 60, clientId: createClientId())


let clientOptions = MqttClientOptions(
hostName: TLS_HOST,
port: TLS_PORT,
tlsCtx: tlsContext,
connectOptions: ConnectPacket,
connackTimeout: TimeInterval(10))

do {
client = try createClient(clientOptions: clientOptions, testContext: mqttTestContext)
try connectClient(client: client!, testContext: mqttTestContext)
} catch {
mqttTestContext.printView("Failed to setup client.")
}
} catch {
mqttTestContext.printView("Failed to setup client.")
print("Error occurred: \(error)")
}
}
}

0 comments on commit 8d80134

Please sign in to comment.