Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example usage for iOS? #322

Open
Streebor opened this issue Jul 23, 2023 · 3 comments
Open

Example usage for iOS? #322

Streebor opened this issue Jul 23, 2023 · 3 comments

Comments

@Streebor
Copy link

Is there an example usage for iOS project?

I want to include MSL into my iOS project, but I am having issues successfully compiling the project. Even after, what appears to be a successful compile, the project I add the compiled lib is acting up. So my guess is that I did not to something properly. I have used ios-cmake.

Thank you!

@wmiaw
Copy link
Contributor

wmiaw commented Jul 23, 2023

Unfortunately there isn't any example iOS code available in the MSL repository. Just the C++ code base. If there is more specific issue you could share, then I may be able to help depending on what the problem is.

@Streebor
Copy link
Author

Streebor commented Aug 1, 2023

Unfortunately there isn't any example iOS code available in the MSL repository. Just the C++ code base. If there is more specific issue you could share, then I may be able to help depending on what the problem is.

@wmiaw

Hey. Thank you for the response. <3

I was able to fix the original issue and compile the lib and add it to another iOS project.

Now, I am looking for an example from the client (iOS device perspective).

What would the code look like in C++ for sending an encrypted message to the server? What classes should I use and how should I configure them or create new ones?

Here is what I was able to figure out by reading your docs and the code:

  • MslControl is the main class. I should use one of the send methods
  • I should inherit from MslContext and create my own context to pass as a param to the send method
  • I should inherit from MessageContext and create my own message context to pass as a param to the send method

Some specific questions that I am hoping a simple example would clarify are:

  1. What do I need to override and the contexts and what is optional?
  2. How do I actually send the message "body". I do not see MslControl send method accepting some kind of payload/body param. Shoud I be using the MessageOutputStream to send the actual data? If so, how?

Thank you!

@wmiaw
Copy link
Contributor

wmiaw commented Aug 1, 2023

  1. What do I need to override and the contexts and what is optional?

In MslContext you should implement everything. The base MslContext.cpp has in-memory time management stuff in updateRemoteTime() and getRemoteTime(), so you can use those unless you need something more sophisticated. There are default/usable implementations for many of the types you need, like DefaultMslEncoderFactory that you could use. But you need to pick the appropriate auth schemes and configuration information (e.g. MessageCapabilities).

MessageContext is what you provide in order to actually define the message you're trying to send. So set the properties you require (e.g. isEncrypted() should return true if you need your data to be encrypted over the wire), any usable values (e.g. KeyRequestData for the key exchange you are using), and implement write() in order to send the actual message body.

  1. How do I actually send the message "body". I do not see MslControl send method accepting some kind of payload/body param. Shoud I be using the MessageOutputStream to send the actual data? If so, how?

Yes, use MessageContext.write() to write the message body into the MessageOutputStream. This function will be called when MSL is ready to send your message body.

When you call MslControl.send() you provide the MessageContext that should be used to define the message data, and required properties. Also implement the other methods on MessageContext to provide the stuff that will be used to satisfy those properties, like UserAuthenticationData and KeyRequestData.

There isn't really any C++ example code, but if you look at the other examples it all works the same way, just in a different language. The APIs and implementation are all basically the same in all the languages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants