Thanks for the response!
For UDP, there’s DTLS but I’ve never looked as to whether that supports PSK or not.
I tried this and it worked
extension NWParameters {
convenience init(passcode: String) {
let udpOptions = NWProtocolUDP.Options()
self.init(dtls: NWParameters.tlsOptions(passcode: passcode), udp: udpOptions)
self.includePeerToPeer = true
}
private static func tlsOptions(passcode: String) -> NWProtocolTLS.Options {
let tlsOptions = NWProtocolTLS.Options()
let authenticationKey = SymmetricKey(data: passcode.data(using: .utf8)!)
let authenticationCode = HMAC<SHA256>.authenticationCode(for: "HI".data(using: .utf8)!, using: authenticationKey)
let authenticationDispatchData = authenticationCode.withUnsafeBytes {
DispatchData(bytes: $0)
}
sec_protocol_options_add_pre_shared_key(tlsOptions.securityProtocolOptions,
authenticationDispatchData as __DispatchData,
stringToDispatchData("HI")! as __DispatchData)
sec_protocol_options_append_tls_ciphersuite(tlsOptions.securityProtocolOptions,
tls_ciphersuite_t(rawValue: TLS_PSK_WITH_AES_128_GCM_SHA256)!)
return tlsOptions
}
// Create a utility function to encode strings as preshared key data.
private static func stringToDispatchData(_ string: String) -> DispatchData? {
guard let stringData = string.data(using: .utf8) else {
return nil
}
let dispatchData = stringData.withUnsafeBytes {
DispatchData(bytes: $0)
}
return dispatchData
}
}
I was able to send messages back and forth.
However, it sounds like you’re just testing out QUIC right now, and hard coding a digital identity for the purposes of your test is fine.
I would like to hard code a digital identity to be able to test - do you have a resource that could help along that process?
If it comes time to do this correctly, you’ll want to find a way to:
Generate the digital identity on the server side.
Distribute that digital identity to all the clients.
I am using AppWrite as my backend service (it's similar to firebase). Would the idea / flow be as follows:
user signs in on the mobile app
make request to my backend requesting identity to be generated
respond with generated identity
use identity to secure QUIC connections
In the extreme example the user would have 7 devices where they use the same credentials to sign in. Would each device need to have the same identity that was generated on my backend in order to properly connect to each other?
Topic:
App & System Services
SubTopic:
Networking
Tags: