sroebert / mqtt-nio

Non-blocking, event-driven Swift client for MQTT (3.1.1 and 5.0).
MIT License
54 stars 13 forks source link

How to pass PEM string to get acknowledgement from server #17

Closed sivasubm1 closed 1 year ago

sivasubm1 commented 1 year ago

Thanks for your response.

We are trying to connect our company message broker via (MQTT over websockets) our url will be - wss://msgvip.s05587.us.pkij.com:56789/mqtt

Question 1: will your package appends mqtt at the end or i can use the below code to connect it

  let client = MQTTClient(
    configuration: .init(
    url: URL(string: "wss://msgvip.s05587.us.pkij.com:56789/mqtt")!,
    credentials: .init(username: "username", password: "password")
    ),
    eventLoopGroupProvider: .createNew
    )

    client.connect()

Question 2:

Our server team has provided a PEM string which we consume from API response in our code. we cant have a physical copy of .pem file in our code repository and i cant pass any client-key also ( In production we cant pass any client-keys )

I need to pass that PEM string , so that my request will be acknowledged by the server.

could you please give me the sample piece of code how to achieve that in swift with this package.

Our earlier Objective-c code - which decodes the PEM string , converts it into array . It uses below package and pins the certificate. https://github.com/novastone-media/MQTT-Client-Framework

MQTTSSLSecurityPolicy securityPolicy = [MQTTSSLSecurityPolicy policyWithPinningMode:MQTTSSLPinningModeCertificate]; NSString pem = [self.options valueForKey:@"sslCert"];

    if (pem != nil) {
        NSData *certData = [[NSData alloc]initWithBase64EncodedString: pem options:NSDataBase64DecodingIgnoreUnknownCharacters];
        securityPolicy.pinnedCertificates = @[certData];
    }
sivasubm1 commented 1 year ago

i was addressed with the solution..Thanks

michael-aiphone commented 4 months ago

I have a similar need in that I need to pass a pem cert (also have private key) at runtime. Do you remember what your solution was? 🙏