<html><body><p><font size="2">Hi Brent,</font><br><br><font size="2">I have some answers in line. </font><br><br>I think perhaps there is misunderstanding about the role of TransportManager (perhaps naming is the problem after all!). This is not a singleton type of manager - rather it is a per connection manager and it "manages" for example the system socket calls. An instance of transport manager handles one connection. An instance of transport manager has one TLS delegate associated with that connection. Therefore, the delegate is associated with only one connection at a time.<br><br>If we assume the above, then it is not hard to see that once a context is created for a specific TLS connection, and stored by the TLS service object, the context can be passed between the various OpenSSL or Secure Transport calls. <br>With OpenSSL, we set the connection fd say to the socket pointer.<br>In Secure Transport, we implement connection read, write callback functions that read/write from the socket.<br><br>Hopefully that makes more sense!<br><br>gelareh<br> <br><font size="2"> </font><br><br><img width="16" height="16" src="cid:2__=8FBB0A6BDFDCA6408f9e8a93df938690918c8FB@" border="0" alt="Inactive hide details for Brent Royal-Gordon ---04/04/2017 07:06:52 AM---> On Apr 3, 2017, at 12:40 PM, Gelareh Taban <gtaban@u"><font size="2" color="#424282">Brent Royal-Gordon ---04/04/2017 07:06:52 AM---> On Apr 3, 2017, at 12:40 PM, Gelareh Taban <gtaban@us.ibm.com> wrote: ></font><br><br><font size="2" color="#5F5F5F">From: </font><font size="2">Brent Royal-Gordon <brent@architechies.com></font><br><font size="2" color="#5F5F5F">To: </font><font size="2">Gelareh Taban/Austin/IBM@IBMUS</font><br><font size="2" color="#5F5F5F">Cc: </font><font size="2">Bill Abt/Cambridge/IBM@IBMUS, swift-server-dev@swift.org</font><br><font size="2" color="#5F5F5F">Date: </font><font size="2">04/04/2017 07:06 AM</font><br><font size="2" color="#5F5F5F">Subject: </font><font size="2">Re: [swift-server-dev] Draft proposal for TLS Service APIs (please review)</font><br><hr width="100%" size="2" align="left" noshade style="color:#8091A5; "><br><br>
<ul><ul>On Apr 3, 2017, at 12:40 PM, Gelareh Taban <<a href="mailto:gtaban@us.ibm.com"><u><font color="#0000FF">gtaban@us.ibm.com</font></u></a>> wrote:<br>
<p><font size="2">Hi Brent,<br>The answers are in line. <br>gelareh</font></ul></ul>Thank you for your detailed answers. I'm going to try to synthesize your answers about the lifecycle into a single description of how the TLSService is used. For clarity, I'll use the names from the proposal, even when we've discussed changing the names.<br>
<ul><ol type="1"><li>Some high-level part of the application configures a TLSService-conforming instance and conveys it through several layers to the transport management layer. At this point, the TLSService knows the certificates, domains, security settings, etc. it should use, but does not know whether it will be handling the client side or the server side of a connection.<br>
<li>Time passes. Eventually, the transport manager looks at its configuration and figures out whether it's a client or a server.<br>
<li>If it is a client, it:<br>
<ul><ol type="1"><li>Calls `onClientCreate()`.<br>
<li>Attempts to establish one or more TCP connections to other hosts.<br>
<li>For each connection it successfully establishes, creates a `TransportManagementDelegate` and passes it as the parameter to `onConnect(IORef:)`.<br>
<li>Goes to step 5 below.<br></ol></ul>
<li>If it is a server, it:<br>
<ul><ol type="1"><li>Calls `onServerCreate()`.<br>
<li>Starts listening for TCP connections from other hosts.<br>
<li>For each connection it receives and accepts, creates a `TransportManagementDelegate` and passes it as the parameter to `onAccept(IORef:)`.<br>
<li>Goes to step 5 below.<br></ol></ul>
<li>It enters a "connected" state where:<br>
<ul><ol type="1"><li>After it receives data from the connection, it allocates an empty buffer and passes it to `onReceive(buffer:bufSize:)`. `onReceive(buffer:bufSize:)` reads bytes from the network from <b>[where?]</b>, interpreting TLS protocol messages and extracting whatever plaintext is present in them, using state from <b>[where?]</b> to distinguish between this connection and other simultaneous connections. `onReceive(buffer:bufSize:)` then writes the extracted plaintext to the buffer and returns.<br><br><br>[g] Assume IORef is a socket pointer. If using OpenSSL, the SSL socket is created using SSL_set_fd() and from then on, onReceive, once data is received on the socket, it is extracted and decrypted from the socket by OpenSSL using SSL_read and copied into buffer. This is all handled by OpenSSL, for a given context that is passed between the various OpenSSL calls for a specific connection.<br>
<li>Before it sends data to the connection, it puts that data in a buffer and passes it to `onSend(buffer:bufSize:)`. `onSend(buffer:bufSize:)` processes the data, converting it to ciphertext and adding TLS protocol messages, using state from <b>[where?]</b> to distinguish between this connection and other simultaneous connections. `onSend(buffer:bufSize:)` then <b>[does what?]</b> with the TLS protocol data to cause it to be sent and returns. `onSend(buffer:bufSize:)` can indicate that the connection should be closed by returning 0.<br><br><br>[g] SImilar to above, once a given context is created associated with an SSL socket, then SSL_write would obtain data from buffer, and encrypt and pass to connection to send.<br>
<li>If the connection is closed. either because the peer closed it or because `onSend(buffer:bufSize:)` indicated it should be closed, it calls `onDestroy()`. `onDestroy()` tears down the SSL engine's state for the connection, using state from <b>[where?]</b> to distinguish between this connection and other simultaneous connections.<br></ol></ul>
<li>Eventually, the transport manager may stop listening or shut down entirely. The TLSService gets no signal that this has happened.</ol></ul><br>First of all, if any of the above is inaccurate, please correct me.<br><br>Assuming I haven't misunderstood any of the above in a material way: As you can see, there are a number of holes in my understanding. I would like your help in filling them in.<br>
<ul><ul type="disc"><li>Since this is to be used for a server, I assume that the transport manager may have several TLS connections open to different clients at the same time. However, I don't see a means for the TLSService to know which of these connections the transport manager is currently talking about. Only the `onAccept(IORef:)` and `onConnect(IORef:)` calls are passed some kind of connection object, so how do `onReceive(buffer:bufSize:)`, `onSend(buffer:bufSize:)`, and `onDestroy()` know which connection is experiencing the event in question?<br><br><br>[g] once socket is passed, a context is created and stored by that instance of TLS service which is then passed to other OpenSSL/SecureTranport calls. <br><a href="https://github.com/IBM-Swift/BlueSSLService/blob/master/Sources/SSLService.swift#L308">https://github.com/IBM-Swift/BlueSSLService/blob/master/Sources/SSLService.swift#L308</a> for OpenSSL<br><br><br><br>There are a few possibilities I can think of, but none of them really fit my understanding of the design:<br>
<ul><ul type="disc"><li>The transport manager makes sure that there is only one TLS connection open at a time—it accepts one connection, handles it from start to finish with the help of the TLSService, and then accepts the next connection and begins handling it. `onAccept(IORef:)` and `onConnection(IORef:)` should store the `IORef` parameter into a property on `self`, and `onSend`, `onReceive`, and `onDestroy` should use that property later.<br>
<li>The transport manager handles many TLS connections at a time. At the beginning of a connection, it copies the TLSService instance <b>[how?]</b> and uses the copy for that connection. `onAccept(IORef:)` and `onConnection(IORef:)` should store the `IORef` parameter into a property on `self`, and `onSend`, `onReceive`, and `onDestroy` should use that property later.<br>
<li>The transport manager handles many TLS connections at a time. At the beginning of a connection, it asks higher layers in the stack to make a new TLSService instance <b>[how?]</b> and uses the new instance for that connection. `onAccept(IORef:)` and `onConnection(IORef:)` should store the `IORef` parameter into a property on `self`, and `onSend`, `onReceive`, and `onDestroy` should use that property later.<br>
<li>The transport manager handles many TLS connections at a time, up to the number of TLSService instances provided by higher layers <b>[how?]</b> to use as a pool of TLSService instances. At the beginning of a connection, it chooses an unused TLSService instance from its pool and assigns it to the connection. `onAccept(IORef:)` and `onConnection(IORef:)` should store the `IORef` parameter into a property on `self`, and `onSend`, `onReceive`, and `onDestroy` should use that property later.<br>
<li>The transport manager handles many TLS connections at a time using a single TLSService instance. Thus, a TLSService instance may receive calls concerning many different connections, all interleaved with one another. `onAccept(IORef:)` and `onConnection(IORef:)` know which connection to use because it's passed in their `IORef` parameter; `onSend`, `onReceive`, and `onDestroy` know <b>[how?]</b>.<br></ul></ul>
<li>How does `onReceive(buffer:bufSize:)` get the data that was received from the network? Does it call some not-yet-specified method on the `IORef` that fetches data to act upon, or does it use some other mechanism?<br>
<li>What does `onSend(buffer:bufSize:)` do with the data to cause it to be sent across the network? Does it call some not-yet-specified method on the `IORef` that sends data over the network, or does it use some other mechanism?</ul></ul><br>I think that, once I have these final questions locked down, I'll be able to understand what's being proposed here, and I can make more detailed suggestions about names and similar issues.<br><br>Thank you for your patience with me on this!
<ul><ul><ul><ul><ul><ul><b>4.1 - TLS service protocol</b><font size="2"><br><br>The TLS service protocol describes the methods that the transport layer calls to handle transport-level events for the TLS service object.</font></ul></ul></ul></ul><br>I have a bunch of questions about the design you're presenting, and I think many of them ultimately stem from not understanding some of the high-level aspects of the proposal. For instance:<br><br>> * What types conform to this protocol? From the diagram, it looks like there's a type for each "engine"—a SecureTransportService, an OpenSSLService, etc.—and each instance represents a particular configuration of that engine. So you create a WhateverTLSService, configure it, and then hand it off (through several layers) to the transport management layer, which calls methods on it to handle various events. The transport management layer then uses that one TLSService to handle many connections. Is that correct?<br><br><br>[g]<br>More or less. As long as the implementation conforms to the protocol, it can use whatever underlying security library it wants. This way we can have a plug and play architecture which allows the user to pick the security library implementation of its choice (eg. LibreSSL, OpenSSL, etc)<br><br><br>> * What is the lifecycle of a connection? Does the TLSService create them itself, does the transport management layer create them and hand them off, or does the transport management layer retain control over them from beginning to end?<br><br><br>[g] The connection life cycle is handled by levels higher than TLS. For all intents and purposes, the transport management layers owns a TLS service delegate which calls the appropriate TLS-related functionality at the right time (eg. at socket creation time, at connection time, etc).<br><br><br>> * You discuss the higher layers creating a TLSService object and caching it in a property, then ultimately handing it down to the transport management layer, which then attaches it to socket objects. But presumably you can have many socket objects, possibly simultaneously. Are they all served by a single TLSService instance, or by many? If they share a TLSService, how does the TLSService know which socket is talking to it at a given moment? If they have separate ones, how does the transport management layer acquire a new one when it needs it?<br><br>[g]<br>Each socket instance would have its own TLS service delegate -- this is important because each socket might have its own specific TLS channel properties.<br><br><br>> You mention that this proposal is very small in scope, and it's fine to describe some of these details in general ways. For instance, you don't need to describe the interface to a Swift socket or the transport layer in detail. But currently, the description of these surrounding systems is *so* vague that I'm struggling to assess this design.<br><br>Perhaps some of these details have been described in other documents or meetings; if so, they really need to be presented in this document, too.<br><br>[g] fair enough. The problem is that right now in the servers working group, we have not defined *any* of our interfaces. This is the first proposal and we are trying to only pin the things which this service requires. <br>In any case, if you think other things should be included, please let us know.<br>
<ul><ul><ul><ul><b><font size="2">- onClientCreate</font></b></ul></ul></ul></ul>> Why do these methods all have "on" prefixes? I'm not totally sure I understand the intended usage here, but I see two possibilities:<br><br>> * These are imperative commands. `onAccept` says that the TLS engine should accept a connection, `onSend` means it should send some data, etc. In that case, these should not have any prefix—they should just be `accept`, `send`, etc.<br><br>> * These are essentially delegate methods notifying the TLS engine of an event. `onAccept` says that the system has accepted a connection and the TLS engine should do what it needs to do with it, `onSend` means the system is about to send data and it needs the TLS engine to modify it, etc. If so, Swift APIs more often use words like `should`, `will`, or `did` than `on`, particularly since they're more precise about the timing of the delegate method compared to the actual event.<br><br>> In either case, I don't think "on" is the best naming for these. It needlessly bucks platform conventions.<br><br>[g]<br>The latter description is the intended. Your points are fair and perhaps we can modify the delegate method names to, perhaps:<br><br>onClientCreate --> didClientCreate<br>onServerCreate --> didServerCreate<br>onDestroy --> willDestroy<br>onAccept --> didAccept(on connection: TransportManagementDelegate)<br>onConnect --> didConnect(on connection: TransportManagementDelegate)<br>onSend --> willSend(with data: UnsafeRawPointer, dataSize: Int))<br>onReceive --> willReceive(with data: UnsafeRawPointer, dataSize: Int))
<ul><ul><ul><ul><font size="2">This will be called when a client I/O connection is created and appropriate TLS connection needs to be configured, including context creation, the handshake and connection verification.<br><br>This is a client only method.<br><br>///<br>/// Setup the contexts and process the TLSService configurations (certificates, etc)<br>///<br><br>func onClientCreate() throws</font><p><b><font size="2">- onServerCreate</font></b><font size="2"><br><br>This will be called when a server I/O connection is created and appropriate TLS connection needs to be setup, including context creation, the handshake and connection verification.<br><br>This is a server only method.<br><br>///<br>/// Setup the contexts and process the TLSService configurations (certificates, etc)<br>///<br><br>func onServerCreate() throws</font></ul></ul></ul></ul>> What are these methods supposed to do, exactly?<br><br>> * Do they put `self` into either a client state or a server state? If so, what happens if you call both, or neither, or call one twice? Would it be better to do this as part of initialization, or to have them make a client TLS object or server TLS object, or to require whatever code hands the TLSService to the TransportManager to pre-configure it as either client or server?<br><br><br>[g] <br>They setup the TLS contexts and process the certificates. They do put self in either a client or server state via associated parameter sets in OpenSSL and SecureTransport.<br>(I am pretty sure) if you call them multiple times, they simply over write the previous setting. But we can test this during implementation.<br><br>These methods are essentially initialization that gets called when the TransportManager decides it has enough information to set it as client or server.<br><br><br>> * Do they create a new instance that's either a client or a server? If so, how do they return it?<br>> * Do they configure something recently created as either client or server? If so, how do they access whatever they need to configure?<br><br>> Basically, what state are these supposed to operate upon?<br><br>[g]<br>Most of the functionality is the same for client or server except for setting the server/client flag/function in the underlying security library. The instance is stored in the delegate.<br>
<ul><ul><ul><ul><b><font size="2">- onDestroy</font></b><font size="2"><br><br>This will be called when an I/O instance connection is closed and any remaining TLS context needs to be destroyed.<br><br>This is both a client and server method.<br><br>///<br>/// Destroy any remaining contexts <br>///<br>func onDestroy()</font></ul></ul></ul></ul>> Is this called at the end of each connection, or is it called once when the transport management layer is totally finished with the TLSService, or are these the same thing?<br><br>> If per-connection, how does it know which connection?<br><br>> If during destruction, should we just class-constrain and use `deinit` for this purpose?<br><br>[g] this is per-connection and the TLS service would keep a context for the connection.<br>So the transport manager has a delegate instance pointing to this TLS service instance which itself has a context.
<ul><ul><ul><ul><b><font size="2">- onAccept</font></b><font size="2"><br><br>This will be called once an I/O instance connection has been accepted, to setup the TLS connection, do the handshake and connection verification.<br><br>This is both a client and server method.<br><br>///<br>/// Processing on acceptance from a listening connection<br>/// <br>///<br>/// - Parameter IORef: The connected I/O instance<br>///<br>func onAccept(IORef: TransportManagementDelegate) throws</font></ul></ul></ul></ul>> I take it the parameter is some sort of abstraction wrapping e.g. a socket. So why is it called a `TransportManagementDelegate`? Shouldn't its name include words like `Connection` or `Socket` or `IOHandle` or something?<br><br><br>[g] we can simply call it ConnectionDelegate. I was trying to be consistent in my terminology.<br><br>> Do we want the parameter to be labeled `IORef`? That's not very idiomatic; it doesn't read well or follow the Swift naming guidelines.<br><br>[g] great feedback. Thanks!<br><br><br>> You say this is for both clients and servers. When does a TLS client have a listening connection that it `accept`s connections on?<br><br>Is it called at different times or in different ways than `onServerCreate`?<br><br>[g] Bad copy/paste! for both onConnect and onAccept. They are obviously server and client specific.
<ul><ul><ul><ul><b><font size="2">- onConnect</font></b><font size="2"><br><br>This will be called once a socket connection has been made, to setup the TLS connection, do the handshake and connection verification.<br><br>This is both a client and server method.<br><br>///<br>/// Processing on connection to a listening connection<br>///<br>/// - Parameter connectionRef: The connected I/O instance<br>///<br>func onConnect(IORef: TransportManagementDelegate) throws</font></ul></ul></ul></ul>The same as above, with appropriate substitutions.
<ul><ul><ul><ul><b><font size="2">- onSend</font></b><font size="2"><br><br>This will be called when data is to be written to an I/O instance. The input data buffer is written to the TLS connection associated with that I/O instance.<br><br>This is both a client and server method.<br><br>///<br>/// Low level writer<br>///<br>/// - Parameters:<br>/// - buffer: Buffer pointer<br>/// - bufSize: Size of the buffer<br>///<br>/// - Returns the number of bytes written. Zero indicates TLS shutdown, less than zero indicates error.<br>///<br>func onSend(buffer: UnsafeRawPointer, bufSize: Int) throws -> Int</font></ul></ul></ul></ul>> Is there a reason you use an UnsafeRawPointer and a buffer size, instead of using an UnsafeRawBufferPointer which would encapsulate both?
<p>[g] it was pointed our rightly by others that it's not good to have either of them :-) Right now, we are looking at have Data and more efficient versions.
<p><br><br>> Why is shutdown indicated with zero, rather than the return value being Optional and being nil? Why are errors signaled with negative values instead of being thrown? (Or are you saying that negative returns are invalid? That's different from saying "indicates error".)<br><br>[g] This is actually implementation details which shouldnt have been included in this pitch in the first place.<br><br><br>> If a TLSService return less than `bufSize`, will the enclosing later try to.re-send the remaining data in subsequent calls?<br><br>This sounds like the TLS engine owns the network connection (at least by this point) and is responsible for writing to it. Does that mean `accept` and `connect` take ownership of the connection and hold on to it? If you have several different simultaneous connections, how do you know which connection this should write to? Or does a given TLSService only own one connection at a time? If so, does the transport management layer create a new TLSService instance for each connection? How? If each TLSService is bound to one connection, shouldn't it be created already knowing the connection it's going to use?<br><br>[g] I believe I have talked about the relationship between connections and TLS service. <br>BlueSSLService implements a very similar protocol and you can get more information on it here:<u><font color="#0000FF"><br></font></u><a href="https://github.com/IBM-Swift/BlueSSLService/blob/master/Sources/SSLService.swift"><u><font color="#0000FF">https://github.com/IBM-Swift/BlueSSLService/blob/master/Sources/SSLService.swift</font></u></a><br>
<ul><ul><ul><ul><b><font size="2">- onReceive</font></b><font size="2"><br><br>This will be called when data is to be read from an I/O instance. Encrypted data is read from TLS connection associated with that I/O instance and decrypted and written to the buffer passed in.<br><br>This is both a client and server method.<br><br>///<br>/// Low level reader<br>///<br>/// - Parameters:<br>/// - buffer: Buffer pointer<br>/// - bufSize: Size of the buffer<br>///<br>/// - Returns the number of bytes read. Zero indicates TLS shutdown, less than zero indicates error.<br>///<br>func onReceive(buffer: UnsafeMutableRawPointer, bufSize: Int) throws -> Int</font></ul></ul></ul></ul>> If I understand correctly, `buffer` is an uninitialized memory region that the type should fill with data. Is that correct?<br><br>Otherwise, the same as above, with appropriate substitutions.
<ul><ul><ul><ul><b><font size="4">5 - Non-goals</font></b><font size="2"><br><br>This proposal:<br><br>1- DOES NOT describe the TLS service configuration, which includes information on certificate types, formats and chains, cipher suites, etc. We expect this to be specified in a future proposal.<br><br>2- DOES NOT describe the TLS service trust policies, which define trust and validation policies of the incoming connection. We expect this to be specified in a future proposal.<br><br>3- DOES NOT describe the interface between the TLS service and the transport layer and any dependencies. We expect this to be specified in a future proposal.</font></ul></ul></ul></ul>> I feel like #3 in particular really hurts this proposal. It's impossible to evaluate this without at least a general idea of how the TLS service and the transport layer communicate. It's okay to handwave the details—for instance, you could say "Type X represents a network connection, and has methods to read, write, and close it", without describing those methods in detail—but without at least an overview of how this will be used, it's very difficult to evaluate.<br><br>I think this is probably a good design that just isn't being explained very clearly. I hope you can clarify some of these points.<br><font size="2"><br>-- <br>Brent Royal-Gordon<br>Architechies</font><br><br><br><br><graycol.gif><font size="2" color="#424282">Brent Royal-Gordon ---04/01/2017 01:15:32 AM---> On Mar 20, 2017, at 1:04 PM, Gelareh Taban via swift-server-dev <</font><a href="mailto:swift-server-dev@swift.org"><u><font size="2" color="#0000FF">swift-server-dev@swift.org</font></u></a><font size="2" color="#424282">> wrote</font><br><font size="2" color="#5F5F5F"><br>From: </font><font size="2">Brent Royal-Gordon <</font><a href="mailto:brent@architechies.com"><u><font size="2" color="#0000FF">brent@architechies.com</font></u></a><font size="2">></font><font size="2" color="#5F5F5F"><br>To: </font><font size="2">Gelareh Taban/Austin/IBM@IBMUS</font><font size="2" color="#5F5F5F"><br>Cc: </font><a href="mailto:swift-server-dev@swift.org"><u><font size="2" color="#0000FF">swift-server-dev@swift.org</font></u></a><font size="2">, Bill Abt/Cambridge/IBM@IBMUS</font><font size="2" color="#5F5F5F"><br>Date: </font><font size="2">04/01/2017 01:15 AM</font><font size="2" color="#5F5F5F"><br>Subject: </font><font size="2">Re: [swift-server-dev] Draft proposal for TLS Service APIs (please review)</font><br><hr width="100%" size="2" align="left" noshade><br>
<ul><ul><ul><ul>On Mar 20, 2017, at 1:04 PM, Gelareh Taban via swift-server-dev <<a href="mailto:swift-server-dev@swift.org"><u><font color="#0000FF">swift-server-dev@swift.org</font></u></a>> wrote:
<p><b>4.1 - TLS service protocol</b><font size="2"><br><br>The TLS service protocol describes the methods that the transport layer calls to handle transport-level events for the TLS service object.</font></ul></ul></ul></ul><br>I have a bunch of questions about the design you're presenting, and I think many of them ultimately stem from not understanding some of the high-level aspects of the proposal. For instance:<br><br>* What types conform to this protocol? From the diagram, it looks like there's a type for each "engine"—a SecureTransportService, an OpenSSLService, etc.—and each instance represents a particular configuration of that engine. So you create a WhateverTLSService, configure it, and then hand it off (through several layers) to the transport management layer, which calls methods on it to handle various events. The transport management layer then uses that one TLSService to handle many connections. Is that correct?<br><br>* What is the lifecycle of a connection? Does the TLSService create them itself, does the transport management layer create them and hand them off, or does the transport management layer retain control over them from beginning to end?<br><br>* You discuss the higher layers creating a TLSService object and caching it in a property, then ultimately handing it down to the transport management layer, which then attaches it to socket objects. But presumably you can have many socket objects, possibly simultaneously. Are they all served by a single TLSService instance, or by many? If they share a TLSService, how does the TLSService know which socket is talking to it at a given moment? If they have separate ones, how does the transport management layer acquire a new one when it needs it?<br><br>You mention that this proposal is very small in scope, and it's fine to describe some of these details in general ways. For instance, you don't need to describe the interface to a Swift socket or the transport layer in detail. But currently, the description of these surrounding systems is *so* vague that I'm struggling to assess this design.<br><br>Perhaps some of these details have been described in other documents or meetings; if so, they really need to be presented in this document, too.
<ul><ul><ul><ul><b><font size="2">- onClientCreate</font></b></ul></ul></ul></ul>Why do these methods all have "on" prefixes? I'm not totally sure I understand the intended usage here, but I see two possibilities:<br><br>* These are imperative commands. `onAccept` says that the TLS engine should accept a connection, `onSend` means it should send some data, etc. In that case, these should not have any prefix—they should just be `accept`, `send`, etc.<br><br>* These are essentially delegate methods notifying the TLS engine of an event. `onAccept` says that the system has accepted a connection and the TLS engine should do what it needs to do with it, `onSend` means the system is about to send data and it needs the TLS engine to modify it, etc. If so, Swift APIs more often use words like `should`, `will`, or `did` than `on`, particularly since they're more precise about the timing of the delegate method compared to the actual event.<br><br>In either case, I don't think "on" is the best naming for these. It needlessly bucks platform conventions.
<ul><ul><ul><ul><font size="2">This will be called when a client I/O connection is created and appropriate TLS connection needs to be configured, including context creation, the handshake and connection verification.<br><br>This is a client only method.<br><br>///<br>/// Setup the contexts and process the TLSService configurations (certificates, etc)<br>///<br><br>func onClientCreate() throws</font><p><b><font size="2">- onServerCreate</font></b><font size="2"><br><br>This will be called when a server I/O connection is created and appropriate TLS connection needs to be setup, including context creation, the handshake and connection verification.<br><br>This is a server only method.<br><br>///<br>/// Setup the contexts and process the TLSService configurations (certificates, etc)<br>///<br><br>func onServerCreate() throws</font></ul></ul></ul></ul>What are these methods supposed to do, exactly?<br><br>* Do they put `self` into either a client state or a server state? If so, what happens if you call both, or neither, or call one twice? Would it be better to do this as part of initialization, or to have them make a client TLS object or server TLS object, or to require whatever code hands the TLSService to the TransportManager to pre-configure it as either client or server?<br><br>* Do they create a new instance that's either a client or a server? If so, how do they return it?<br><br>* Do they configure something recently created as either client or server? If so, how do they access whatever they need to configure?<br><br>Basically, what state are these supposed to operate upon?
<ul><ul><ul><ul><b><font size="2">- onDestroy</font></b><font size="2"><br><br>This will be called when an I/O instance connection is closed and any remaining TLS context needs to be destroyed.<br><br>This is both a client and server method.<br><br>///<br>/// Destroy any remaining contexts <br>///<br>func onDestroy()</font></ul></ul></ul></ul>Is this called at the end of each connection, or is it called once when the transport management layer is totally finished with the TLSService, or are these the same thing?<br><br>If per-connection, how does it know which connection?<br><br>If during destruction, should we just class-constrain and use `deinit` for this purpose?
<ul><ul><ul><ul><b><font size="2">- onAccept</font></b><font size="2"><br><br>This will be called once an I/O instance connection has been accepted, to setup the TLS connection, do the handshake and connection verification.<br><br>This is both a client and server method.<br><br>///<br>/// Processing on acceptance from a listening connection<br>/// <br>///<br>/// - Parameter IORef: The connected I/O instance<br>///<br>func onAccept(IORef: TransportManagementDelegate) throws</font></ul></ul></ul></ul>I take it the parameter is some sort of abstraction wrapping e.g. a socket. So why is it called a `TransportManagementDelegate`? Shouldn't its name include words like `Connection` or `Socket` or `IOHandle` or something?<br><br>Do we want the parameter to be labeled `IORef`? That's not very idiomatic; it doesn't read well or follow the Swift naming guidelines.<br><br>You say this is for both clients and servers. When does a TLS client have a listening connection that it `accept`s connections on?<br><br>Is it called at different times or in different ways than `onServerCreate`?
<ul><ul><ul><ul><b><font size="2">- onConnect</font></b><font size="2"><br><br>This will be called once a socket connection has been made, to setup the TLS connection, do the handshake and connection verification.<br><br>This is both a client and server method.<br><br>///<br>/// Processing on connection to a listening connection<br>///<br>/// - Parameter connectionRef: The connected I/O instance<br>///<br>func onConnect(IORef: TransportManagementDelegate) throws</font></ul></ul></ul></ul>The same as above, with appropriate substitutions.
<ul><ul><ul><ul><b><font size="2">- onSend</font></b><font size="2"><br><br>This will be called when data is to be written to an I/O instance. The input data buffer is written to the TLS connection associated with that I/O instance.<br><br>This is both a client and server method.<br><br>///<br>/// Low level writer<br>///<br>/// - Parameters:<br>/// - buffer: Buffer pointer<br>/// - bufSize: Size of the buffer<br>///<br>/// - Returns the number of bytes written. Zero indicates TLS shutdown, less than zero indicates error.<br>///<br>func onSend(buffer: UnsafeRawPointer, bufSize: Int) throws -> Int</font></ul></ul></ul></ul>Is there a reason you use an UnsafeRawPointer and a buffer size, instead of using an UnsafeRawBufferPointer which would encapsulate both?<br><br>Why is shutdown indicated with zero, rather than the return value being Optional and being nil? Why are errors signaled with negative values instead of being thrown? (Or are you saying that negative returns are invalid? That's different from saying "indicates error".)<br><br>If a TLSService return less than `bufSize`, will the enclosing later try to.re-send the remaining data in subsequent calls?<br><br>This sounds like the TLS engine owns the network connection (at least by this point) and is responsible for writing to it. Does that mean `accept` and `connect` take ownership of the connection and hold on to it? If you have several different simultaneous connections, how do you know which connection this should write to? Or does a given TLSService only own one connection at a time? If so, does the transport management layer create a new TLSService instance for each connection? How? If each TLSService is bound to one connection, shouldn't it be created already knowing the connection it's going to use?
<ul><ul><ul><ul><b><font size="2">- onReceive</font></b><font size="2"><br><br>This will be called when data is to be read from an I/O instance. Encrypted data is read from TLS connection associated with that I/O instance and decrypted and written to the buffer passed in.<br><br>This is both a client and server method.<br><br>///<br>/// Low level reader<br>///<br>/// - Parameters:<br>/// - buffer: Buffer pointer<br>/// - bufSize: Size of the buffer<br>///<br>/// - Returns the number of bytes read. Zero indicates TLS shutdown, less than zero indicates error.<br>///<br>func onReceive(buffer: UnsafeMutableRawPointer, bufSize: Int) throws -> Int</font></ul></ul></ul></ul>If I understand correctly, `buffer` is an uninitialized memory region that the type should fill with data. Is that correct?<br><br>Otherwise, the same as above, with appropriate substitutions.
<ul><ul><ul><ul><b><font size="4">5 - Non-goals</font></b><font size="2"><br><br>This proposal:<br><br>1- DOES NOT describe the TLS service configuration, which includes information on certificate types, formats and chains, cipher suites, etc. We expect this to be specified in a future proposal.<br><br>2- DOES NOT describe the TLS service trust policies, which define trust and validation policies of the incoming connection. We expect this to be specified in a future proposal.<br><br>3- DOES NOT describe the interface between the TLS service and the transport layer and any dependencies. We expect this to be specified in a future proposal.</font></ul></ul></ul></ul>I feel like #3 in particular really hurts this proposal. It's impossible to evaluate this without at least a general idea of how the TLS service and the transport layer communicate. It's okay to handwave the details—for instance, you could say "Type X represents a network connection, and has methods to read, write, and close it", without describing those methods in detail—but without at least an overview of how this will be used, it's very difficult to evaluate.<br><br>I think this is probably a good design that just isn't being explained very clearly. I hope you can clarify some of these points.<br><font size="2"><br>-- <br>Brent Royal-Gordon<br>Architechies</font><br><br><br></ul></ul><br><font size="2">-- </font><br><font size="2">Brent Royal-Gordon</font><br><font size="2">Architechies</font><br><br><br><BR>
</body></html>