2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 * @file FNetSockSecureSocket.h
21 * @brief This is the header file for the %SecureSocket class.
23 * This header file contains the declarations of the %SecureSocket class. @n
24 * The %SecureSocket class provides secured simple methods for sending and receiving the data over a network.
27 #ifndef _FNET_SOCK_SECURE_SOCKET_H_
28 #define _FNET_SOCK_SECURE_SOCKET_H_
30 #include <FBaseObject.h>
31 #include <FNetNetEndPoint.h>
32 #include <FNetNetConnection.h>
33 #include <FNetSockSocketTypes.h>
34 #include <FNetSockISecureSocketEventListener.h>
36 namespace Tizen { namespace Net { namespace Sockets
39 class _SecureSocketImpl;
42 * @enum NetSecureSocketSslVersion
44 * Defines the secure socket version.
48 enum NetSecureSocketSslVersion
50 NET_SOCK_SSL_VERSION_SSLV3 = 0x0300, /**< The secure socket version is SSLv3 @n
51 The value for SSLv3 is 0x0300. */
52 NET_SOCK_SSL_VERSION_TLSV1 = 0x0301, /**< The secure socket version is TLSv1 @n
53 The value for TLSv1 is 0x0301. */
54 NET_SOCK_SSL_VERSION_NONE = 0x0000 // This enum value is for internal use only. Using this enum value can cause behavioral, security-related, and consistency-related issues in the application. SSL version not set
58 * @enum NetSecureSocketSslCipherSuiteID
60 * Defines the CipherSuite ID.
64 enum NetSecureSocketSslCipherSuiteID
66 //NET_SOCK_TLS_SSL_RSA_WITH_NULL_MD5 = 0x0001, /*< The CipherSuite ID is 0x0001 */
67 //NET_SOCK_TLS_SSL_RSA_WITH_NULL_SHA = 0x0002, /*< The CipherSuite ID is 0x0002 */
68 //NET_SOCK_TLS_SSL_RSA_EXPORT_WITH_RC4_40_MD5 = 0x0003, /**< The CipherSuite ID is 0x0003 */
69 NET_SOCK_TLS_SSL_RSA_WITH_RC4_128_MD5 = 0x0004, /**< The CipherSuite ID is 0x0004 */
70 NET_SOCK_TLS_SSL_RSA_WITH_RC4_128_SHA = 0x0005, /**< The CipherSuite ID is 0x0005 */
71 //NET_SOCK_TLS_SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5 = 0x0006, /*< The CipherSuite ID is 0x0006 */
72 //NET_SOCK_TLS_SSL_RSA_WITH_IDEA_CBC_SHA = 0x0007, /*< The CipherSuite ID is 0x0007 */
73 NET_SOCK_TLS_SSL_RSA_EXPORT_WITH_DES40_CBC_SHA = 0x0008, /**< The CipherSuite ID is 0x0008 */
74 NET_SOCK_TLS_SSL_RSA_WITH_DES_CBC_SHA = 0x0009, /**< The CipherSuite ID is 0x0009 */
75 NET_SOCK_TLS_SSL_RSA_WITH_3DES_EDE_CBC_SHA = 0x000A, /**< The CipherSuite ID is 0x000A */
76 //NET_SOCK_TLS_SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA = 0x000D, /*< The CipherSuite ID is 0x000D */
77 //NET_SOCK_TLS_SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA = 0x0010, /*< The CipherSuite ID is 0x0010 */
78 //NET_SOCK_TLS_SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA = 0x0011, /*< The CipherSuite ID is 0x0001 */
79 //NET_SOCK_TLS_SSL_DHE_DSS_WITH_DES_CBC_SHA = 0x0012, /*< The CipherSuite ID is 0x0002 */
80 //NET_SOCK_TLS_SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA = 0x0013, /*< The CipherSuite ID is 0x0003 */
81 //NET_SOCK_TLS_SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA = 0x0014, /*< The CipherSuite ID is 0x0004 */
82 //NET_SOCK_TLS_SSL_DHE_RSA_WITH_DES_CBC_SHA = 0x0015, /*< The CipherSuite ID is 0x0005 */
83 //NET_SOCK_TLS_SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA = 0x0016, /*< The CipherSuite ID is 0x0006 */
84 //NET_SOCK_TLS_SSL_DH_anon_EXPORT_WITH_RC4_40_MD5 = 0x0017, /*< The CipherSuite ID is 0x0007 */
85 //NET_SOCK_TLS_SSL_DH_anon_WITH_RC4_128_MD5 = 0x0018, /*< The CipherSuite ID is 0x0008 */
86 //NET_SOCK_TLS_SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA = 0x0019, /*< The CipherSuite ID is 0x0009 */
87 //NET_SOCK_TLS_SSL_DH_anon_WITH_DES_CBC_SHA = 0x001A, /*< The CipherSuite ID is 0x001A */
88 //NET_SOCK_TLS_SSL_DH_anon_WITH_3DES_EDE_CBC_SHA = 0x001B, /*< The CipherSuite ID is 0x001B */
89 NET_SOCK_TLS_SSL_RSA_WITH_AES_128_CBC_SHA = 0x002F, /**< The CipherSuite ID is 0x002F */
90 //NET_SOCK_TLS_SSL_DH_DSS_WITH_AES_128_CBC_SHA = 0x0030, /*< The CipherSuite ID is 0x0030 */
91 //NET_SOCK_TLS_SSL_DH_RSA_WITH_AES_128_CBC_SHA = 0x0031, /*< The CipherSuite ID is 0x0031 */
92 //NET_SOCK_TLS_SSL_DHE_DSS_WITH_AES_128_CBC_SHA = 0x0032, /*< The CipherSuite ID is 0x0032 */
93 //NET_SOCK_TLS_SSL_DHE_RSA_WITH_AES_128_CBC_SHA = 0x0033, /*< The CipherSuite ID is 0x0033 */
94 //NET_SOCK_TLS_SSL_DH_anon_WITH_AES_128_CBC_SHA = 0x0034, /*< The CipherSuite ID is 0x0034 */
95 //NET_SOCK_TLS_SSL_RSA_WITH_AES_256_CBC_SHA = 0x0035, /*< The CipherSuite ID is 0x0035 */
96 //NET_SOCK_TLS_SSL_DH_DSS_WITH_AES_256_CBC_SHA = 0x0036, /*< The CipherSuite ID is 0x0036 */
97 //NET_SOCK_TLS_SSL_DH_RSA_WITH_AES_256_CBC_SHA = 0x0037, /*< The CipherSuite ID is 0x0037 */
98 //NET_SOCK_TLS_SSL_DHE_DSS_WITH_AES_256_CBC_SHA = 0x0038, /*< The CipherSuite ID is 0x0038 */
99 //NET_SOCK_TLS_SSL_DHE_RSA_WITH_AES_256_CBC_SHA = 0x0039, /*< The CipherSuite ID is 0x0039 */
100 //NET_SOCK_TLS_SSL_DH_anon_WITH_AES_256_CBC_SHA = 0x003A, /*< The CipherSuite ID is 0x003A */
102 // Samsung does not support below cipher suites
103 //TLS_SSL_ECDH_ECDSA_WITH_NULL_SHA_DRAFT09 = 0x0047,
104 //TLS_SSL_ECDH_ECDSA_NULL_SHA = 0x0047,
105 //TLS_SSL_ECDH_ECDSA_WITH_RC4_128_SHA_DRAFT09 = 0x0048,
106 //TLS_SSL_ECDH_ECDSA_WITH_DES_CBC_SHA_DRAFT09 = 0x0049,
107 //TLS_SSL_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA_DRAFT09 = 0x004A,
108 //TLS_SSL_ECDH_ECDSA_WITH_AES_128_CBC_SHA_DRAFT09 = 0x004B,
109 //TLS_SSL_ECDH_ECDSA_WITH_AES_256_CBC_SHA_DRAFT09 = 0x004C,
110 //TLS_SSL_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA = 0x0063,
111 //TLS_SSL_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA = 0x0065,
112 //TLS_SSL_DHE_DSS_WITH_RC4_128_SHA = 0x0066,
113 //TLS_SSL_PSK_WITH_RC4_128_SHA = 0x008A,
114 //TLS_SSL_PSK_WITH_3DES_EDE_CBC_SHA = 0x008B,
115 //TLS_SSL_PSK_WITH_AES_128_CBC_SHA = 0x008C,
116 //TLS_SSL_PSK_WITH_AES_256_CBC_SHA = 0x008D,
117 //TLS_SSL_DHE_PSK_WITH_RC4_128_SHA = 0x008E,
118 //TLS_SSL_DHE_PSK_WITH_3DES_EDE_CBC_SHA = 0x008F,
119 //TLS_SSL_DHE_PSK_WITH_AES_128_CBC_SHA = 0x0090,
120 //TLS_SSL_DHE_PSK_WITH_AES_256_CBC_SHA = 0x0091,
121 //TLS_SSL_RSA_PSK_WITH_RC4_128_SHA = 0x0092,
122 //TLS_SSL_RSA_PSK_WITH_3DES_EDE_CBC_SHA = 0x0093,
123 //TLS_SSL_RSA_PSK_WITH_AES_128_CBC_SHA = 0x0094,
124 //TLS_SSL_RSA_PSK_WITH_AES_256_CBC_SHA = 0x0095,
125 //TLS_SSL_ECDH_ECDSA_WITH_NULL_SHA = 0xC001,
126 //TLS_SSL_ECDH_ECDSA_WITH_RC4_128_SHA = 0xC002,
127 //TLS_SSL_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA = 0xC003,
128 //TLS_SSL_ECDH_ECDSA_WITH_AES_128_CBC_SHA = 0xC004,
129 //TLS_SSL_ECDH_ECDSA_WITH_AES_256_CBC_SHA = 0xC005,
130 //TLS_SSL_ECDHE_ECDSA_WITH_NULL_SHA = 0xC006,
131 //TLS_SSL_ECDHE_ECDSA_WITH_RC4_128_SHA = 0xC007,
132 //TLS_SSL_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA = 0xC008,
133 //TLS_SSL_ECDHE_ECDSA_WITH_AES_128_CBC_SHA = 0xC009,
134 //TLS_SSL_ECDHE_ECDSA_WITH_AES_256_CBC_SHA = 0xC00A,
135 //TLS_SSL_ECDH_anon_WITH_NULL_SHA = 0xC015,
136 //TLS_SSL_ECDH_anon_WITH_RC4_128_SHA = 0xC016,
137 //TLS_SSL_ECDH_anon_WITH_3DES_EDE_CBC_SHA = 0xC017,
138 //TLS_SSL_ECDH_anon_WITH_AES_128_CBC_SHA = 0xC018,
139 //TLS_SSL_ECDH_anon_WITH_AES_256_CBC_SHA = 0xC019,
140 //TLS_SSL_ECMQV_ECDSA_WITH_NULL_SHA = 0xFF4F,
141 //TLS_SSL_ECMQV_ECDSA_WITH_RC4_128_SHA = 0xFF50,
142 //TLS_SSL_ECMQV_ECDSA_WITH_3DES_EDE_CBC_SHA = 0xFF52,
143 //TLS_SSL_ECMQV_ECDSA_WITH_AES_128_CBC_SHA = 0xFF53,
144 //TLS_SSL_ECMQV_ECDSA_WITH_AES_256_CBC_SHA = 0xFF54,
146 NET_SOCK_TLS_SSL_SYSTEM_DEFAULT_CIPHERSUITES = 0xFFFF, /**< If the user selects this ID, the %SecureSocket instance decides the cipher suite bundle itself @n
147 * For the OAF SSL, the below cipher suites will be included in "ClientHello" message: @n
148 * NET_SOCK_TLS_SSL_RSA_WITH_RC4_128_MD5
149 * NET_SOCK_TLS_SSL_RSA_WITH_RC4_128_SHA
150 * NET_SOCK_TLS_SSL_RSA_EXPORT_WITH_DES40_CBC_SHA
151 * NET_SOCK_TLS_SSL_RSA_WITH_DES_CBC_SHA
152 * NET_SOCK_TLS_SSL_RSA_WITH_3DES_EDE_CBC_SHA
153 * NET_SOCK_TLS_SSL_RSA_WITH_AES_128_CBC_SHA
155 NET_SOCK_TLS_SSL_NULL_WITH_NULL_NULL = 0x0000 // This enum value is for internal use only. Using this enum value can cause behavioral, security-related, and consistency-related issues in the application. The CipherSuite ID is 0x0000
159 * @class SecureSocket
160 * @brief This class provides the Secure %Sockets Layer (SSL) supported socket with security features.
164 * The %SecureSocket class provides the Secure Sockets Layer (SSL) supported socket with security features.
166 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/net/sockets.htm">Sockets Guide</a>.
168 class _OSP_EXPORT_ SecureSocket
169 : public Tizen::Base::Object
174 * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
181 * This destructor overrides Tizen::Base::Object::~Object().
187 virtual ~SecureSocket(void);
190 * Initializes this instance of %SecureSocket with the specified parameters. @n
191 * The secure socket is initialized in a non-blocking mode by default.
192 * Use Ioctl() (with NET_SOCKET_FIONBIO) to use a %SecureSocket in the blocking mode.
196 * @privilege http://tizen.org/privilege/socket
198 * @return An error code
199 * @param[in] netConnection A run-time session where a %SecureSocket instance is used
200 * @param[in] addressFamily A ::NetSocketAddressFamily value
201 * @param[in] socketType The secure socket type @n
202 * The value should be NET_SOCKET_TYPE_STREAM.
203 * @param[in] protocol The protocol used by this secure socket @n
204 * The value should be NET_SOCKET_PROTOCOL_SSL.
205 * @exception E_SUCCESS The method is successful.
206 * @exception E_WOULD_BLOCK A non-blocking secure socket operation cannot be completed immediately.
207 * @exception E_OUT_OF_MEMORY The memory is insufficient.
208 * @exception E_MAX_EXCEEDED All sockets are in use.
209 * @exception E_UNSUPPORTED_OPTION The specified parameters are not supported.
210 * @exception E_INVALID_ARG A specified input parameter is invalid.
211 * @exception E_UNSUPPORTED_PROTOCOL The protocol is not supported.
212 * @exception E_UNSUPPORTED_TYPE The secure socket type is not supported.
213 * @exception E_UNSUPPORTED_FAMILY The address family is not supported.
214 * @exception E_SYSTEM A system error has occurred.
215 * @exception E_INVALID_CONNECTION The network connection is invalid.
216 * @exception E_FAILURE The method has failed due to an undefined error.
217 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
218 * @remarks The @c netConnection parameter specifies a run-time network connection. @n
219 * The @c addressFamily parameter specifies an address family. @n
220 * The @c socketType parameter specifies the type of the secure socket. SSL only supports stream-based protocols. @n
221 * The @c protocol parameter specifies the protocol used by the secure socket. SSL protocol is defined as NET_SOCKET_PROTOCOL_SSL. @n
222 * The first parameter must be a valid run-time network connection. The three parameters are not independent. Some address families
223 * restrict the protocols that can be used with them, and often the secure socket type is implicit in the protocol. If the combination
224 * of the address family, socket type, and protocol type results in an invalid secure socket, this method returns an error. @n For each
225 * secure socket used in the non-blocking mode, an event listener (ISecureSocketEventListener) should be registered and maintained.
226 * so that it can receive asynchronous notifications of the secure socket events. AddSecureSocketListener() is used to
227 * register an event listener. @n
228 * If a secure socket in the blocking mode needs to be used, Ioctl() (with NET_SOCKET_FIONBIO) should be called after initializing the secure socket
229 * through this method.
230 * @see Ioctl() for understanding the blocking/non-blocking mode
232 result Construct(const Tizen::Net::NetConnection& netConnection, NetSocketAddressFamily addressFamily, NetSocketType socketType, NetSocketProtocol protocol);
235 * Initializes this instance of %SecureSocket with the specified parameters. @n
236 * The secure socket is initialized in a non-blocking mode by default.
237 * Use Ioctl() (with NET_SOCKET_FIONBIO) to use a %SecureSocket in the blocking mode.
241 * @privilege http://tizen.org/privilege/socket
243 * @return An error code
244 * @param[in] addressFamily A ::NetSocketAddressFamily value
245 * @param[in] socketType The secure socket type @n
246 * The value should be NET_SOCKET_TYPE_STREAM.
247 * @param[in] protocol The protocol used by this secure socket @n
248 * The value should be NET_SOCKET_PROTOCOL_SSL.
249 * @exception E_SUCCESS The method is successful.
250 * @exception E_WOULD_BLOCK A non-blocking secure socket operation cannot be completed immediately.
251 * @exception E_OUT_OF_MEMORY The memory is insufficient.
252 * @exception E_MAX_EXCEEDED All sockets are in use.
253 * @exception E_UNSUPPORTED_OPTION The specified parameters are not supported.
254 * @exception E_INVALID_ARG A specified input parameter is invalid.
255 * @exception E_UNSUPPORTED_PROTOCOL The protocol is not supported.
256 * @exception E_UNSUPPORTED_TYPE The secure socket type is not supported.
257 * @exception E_UNSUPPORTED_FAMILY The address family is not supported.
258 * @exception E_SYSTEM A system error has occurred.
259 * @exception E_INVALID_CONNECTION The network connection is invalid.
260 * @exception E_FAILURE The method has failed due to an undefined error.
261 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
262 * @remarks The @c addressFamily parameter specifies an address family. @n
263 * The @c socketType parameter specifies the type of the secure socket. SSL only supports stream-based protocols. @n
264 * The @c protocol parameter specifies the protocol used by the secure socket. The SSL protocol is defined as NET_SOCKET_PROTOCOL_SSL. @n
265 * The three parameters are not independent. Some address families restrict the protocols that can be used with them, and often the
266 * secure socket type is implicit in the protocol. If the combination of the address family, socket type, and protocol type results in
267 * an invalid secure socket, this method returns an error. @n
268 * For each secure socket used in the non-blocking mode, an event listener
269 * (ISecureSocketEventListener) should be registered and maintained, so that it can receive asynchronous notifications of the secure socket
270 * events. AddSecureSocketListener() is used to register an event listener. @n
271 * If a secure socket in the blocking mode needs to be used, Ioctl() (with NET_SOCKET_FIONBIO) should be called after initializing the secure socket
272 * through this method.
273 * @see Ioctl() for understanding the blocking/non-blocking mode
275 result Construct(NetSocketAddressFamily addressFamily, NetSocketType socketType, NetSocketProtocol protocol);
279 * Closes the secure socket. @n
280 * All the resources associated with the secure socket are freed.
284 * @privilege http://tizen.org/privilege/socket
286 * @return An error code
287 * @exception E_SUCCESS The method is successful.
288 * @exception E_INVALID_STATE The secure socket is not in a valid state.
289 * @exception E_INVALID_SOCKET The secure socket is invalid.
290 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
291 * @exception E_OUT_OF_MEMORY The memory is insufficient.
292 * @exception E_SYSTEM A system error has occurred.
293 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
294 * @remarks If the %SecureSocket class is not initialized through one of the Construct() methods or this method is called more than once,
295 * then this method returns E_INVALID_STATE.
300 * Establishes a connection to a remote host.
303 * @brief <i> [Compatibility] </i>
307 * @compatibility This method has compatibility issues with OSP compatible applications. @n
308 * For more information, see @ref SecureSocketConnectPage "here".
311 * @privilege http://tizen.org/privilege/socket
313 * @return An error code
314 * @param[in] remoteEndPoint An instance of NetEndPoint representing the remote device
315 * @exception E_SUCCESS The method is successful.
316 * @exception E_INVALID_SOCKET The secure socket is invalid.
317 * @exception E_INVALID_STATE The secure socket is not in a valid state.
318 * @exception E_HOST_UNREACHABLE The network cannot be reached from this host at this time.
319 * @exception E_IN_PROGRESS A previous request is in progress.
320 * @exception E_INVALID_ARG The specified input parameter is invalid.
321 * @exception E_WOULD_BLOCK A non-blocking secure socket operation cannot be completed immediately.
322 * @exception E_INVALID_CERTIFICATE The client certificate verification has failed on server.
323 * @exception E_CERTIFICATE_VERIFICATION_FAILED The server certificate verification has failed.
324 * @exception E_CONNECTION_FAILED The secure socket is not connected.
325 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
326 * @exception E_ALREADY_CONNECTED The secure socket is already connected.
327 * @exception E_UNSUPPORTED_FAMILY The address family is not supported.
328 * @exception E_UNSUPPORTED_PROTOCOL The protocol is not supported.
329 * @exception E_OUT_OF_MEMORY The memory is insufficient.
330 * @exception E_SYSTEM A system error has occurred.
331 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
333 * @remarks Starts connection to a remote peer including SSL handshaking.
334 * After this method is called, OnSecureSocketConnected() is called. The data is sent to and received from the remote
335 * device using Send() and Receive() respectively. If the Bind() method is not called before calling this
336 * method, the underlying service provider assigns the local network address and port number.
338 result Connect(const Tizen::Net::NetEndPoint& remoteEndPoint);
341 * @page SecureSocketConnectPage Compatibility for Connect()
343 * @section SecureSocketConnectPageIssueSection Issues
344 * Implementation of this method in %Tizen API versions prior to 2.1 has the following issue: @n
345 * -# If the application provides a loopback address in NetEndPoint, it returns E_SYSTEM.
347 * @section SecureSocketConnectPageResolutionSection Resolutions
348 * The issue mentioned above is resolved in %Tizen API version 2.1 as follows: @n
349 * -# If the application provides a loopback address in NetEndPoint, it returns E_SUCCESS instead of E_SYSTEM.
353 * Sends the data to a secure socket of the type NET_SOCKET_TYPE_STREAM.
357 * @return An error code
358 * @param[in] buffer An instance of ByteBuffer that contains the data to send
359 * @exception E_SUCCESS The method is successful.
360 * @exception E_INVALID_SOCKET The secure socket is invalid.
361 * @exception E_INVALID_STATE The secure socket is not in a valid state.
362 * @exception E_UNSUPPORTED_OPTION The specified parameter is not supported.
363 * @exception E_INVALID_ARG The specified input parameter is invalid.
364 * @exception E_WOULD_BLOCK A non-blocking secure socket operation cannot be completed immediately.
365 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
366 * @exception E_CONNECTION_FAILED The secure socket is not connected.
367 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
368 * @exception E_OUT_OF_MEMORY The memory is insufficient.
369 * @exception E_SYSTEM A system error has occurred.
370 * @remarks This method sends the data to the remote host specified in the Connect() method.
371 * This method sends the data in the @c buffer parameter, starting from the current position of the buffer. After the operation,
372 * the position of the buffer is incremented by the number of bytes successfully sent. The new position cannot be larger than the
373 * original limit. This method can be used only for connection-oriented sockets.
374 * In the blocking mode, if space is not available in the send queue, the secure socket blocks until space becomes available.
375 * In the non-blocking mode, this method returns the error E_WOULD_BLOCK. This method may
376 * complete successfully even if it sends less bytes than the number of bytes present in the buffer. The application
377 * should keep track of the number of bytes sent and retry the operation until the application sends the bytes in the
378 * buffer. There is no guarantee that the data that is sent appears on the network immediately. To increase network efficiency, the
379 * underlying system may delay the transmission until a significant amount of outgoing data is collected. A successful completion of this
380 * method means that the underlying system has had room to buffer the data for a network send. If it is important for the
381 * application to send every byte to the remote host immediately, use SetSockOpt() (with NET_SOCKET_TCP_NODELAY) of the type
382 * ::NetSocketOptName to enable no delay.
384 result Send(Tizen::Base::ByteBuffer& buffer);
387 * Sends the data to a secure socket of the type NET_SOCKET_TYPE_STREAM.
391 * @return An error code
392 * @param[in] pBuffer The pointer to the buffer containing the data to send
393 * @param[in] length The length of the data in the buffer
394 * @param[out] sentLength The length of the data sent successfully
395 * @exception E_SUCCESS The method is successful.
396 * @exception E_INVALID_SOCKET The secure socket is invalid.
397 * @exception E_INVALID_STATE The secure socket is not in a valid state.
398 * @exception E_UNSUPPORTED_OPTION The specified parameters are not supported.
399 * @exception E_INVALID_ARG A specified input parameter is invalid.
400 * @exception E_WOULD_BLOCK A non-blocking secure socket operation cannot be completed immediately.
401 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
402 * @exception E_CONNECTION_FAILED The secure socket is not connected.
403 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
404 * @exception E_OUT_OF_MEMORY The memory is insufficient.
405 * @exception E_SYSTEM A system error has occurred.
406 * @remarks This method sends the data to the remote host specified in the Connect() method.
407 * This method sends the data in the buffer of length @c length, starting from the current position of the buffer.
408 * In the blocking mode, if space is not available in the send queue, the secure socket blocks until space becomes available.
409 * In the non-blocking mode, this method returns the error E_WOULD_BLOCK.
410 * This method may complete successfully even if it sends less bytes than the number of bytes
411 * in the buffer. The application should keep track of the number of bytes sent
412 * and retry the operation until the application sends the bytes in the buffer.
413 * There is no guarantee that the data that is sent appears on the network immediately.
414 * To increase the network efficiency, the underlying system may delay the transmission until a significant amount
415 * of outgoing data is collected. A successful completion of this method means that the underlying
416 * system has had room to buffer the data for a network send.
417 * If it is important for the application to send every byte to the remote host immediately,
418 * use SetSockOpt() (with NET_SOCKET_TCP_NODELAY) of the type ::NetSocketOptName to enable no delay.
420 result Send(void* pBuffer, int length, int& sentLength);
423 * Receives the data from a secure socket of the type NET_SOCKET_TYPE_STREAM.
427 * @return An error code
428 * @param[out] buffer An instance of ByteBuffer that is the storage location for the received data
429 * @exception E_SUCCESS The method is successful.
430 * @exception E_INVALID_SOCKET The secure socket is invalid.
431 * @exception E_INVALID_STATE The secure socket is not in a valid state.
432 * @exception E_UNSUPPORTED_OPTION The specified parameter is not supported.
433 * @exception E_INVALID_ARG The specified input parameter is invalid.
434 * @exception E_WOULD_BLOCK A non-blocking secure socket operation cannot be completed immediately.
435 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
436 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
437 * @exception E_IN_PROGRESS A previous request is in progress.
438 * @exception E_OUT_OF_MEMORY The memory is insufficient.
439 * @exception E_SYSTEM A system error has occurred.
440 * @remarks This method copies the data into the @c buffer parameter, starting from the current position of the buffer.
441 * After the operation, the position of the buffer is incremented by the number of bytes successfully received.
442 * The new position cannot be larger than the original limit. This method can be called from connection-oriented sockets only.
443 * If there is no data at the secure socket in the blocking mode,
444 * this method blocks until the data arrives. If the secure socket is in the non-blocking mode,
445 * the error E_WOULD_BLOCK is returned.
448 result Receive(Tizen::Base::ByteBuffer& buffer) const;
451 * Receives the data from a secure socket of the type NET_SOCKET_TYPE_STREAM.
455 * @return An error code
456 * @param[out] pBuffer The pointer to the buffer that is the storage location for the received data
457 * @param[in] length The length of the data in the buffer
458 * @param[out] rcvdLength The length of the data that is received successfully
459 * @exception E_SUCCESS The method is successful.
460 * @exception E_INVALID_SOCKET The secure socket is invalid.
461 * @exception E_INVALID_STATE The secure socket is not in a valid state.
462 * @exception E_UNSUPPORTED_OPTION The specified parameters are not supported.
463 * @exception E_INVALID_ARG A specified input parameter is invalid.
464 * @exception E_WOULD_BLOCK A non-blocking secure socket operation cannot be completed immediately.
465 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
466 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
467 * @exception E_IN_PROGRESS A previous request is in progress.
468 * @exception E_OUT_OF_MEMORY The memory is insufficient.
469 * @exception E_SYSTEM A system error has occurred.
470 * @remarks This method copies the data into the buffer of length @c length, starting from the current position of the buffer.
471 * This method can be called from the connection-oriented sockets only.
472 * If there is no data at the secure socket in the blocking mode,
473 * this method blocks until the data arrives. If the secure socket is in the non-blocking mode,
474 * the error E_WOULD_BLOCK is returned.
476 result Receive(void* pBuffer, int length, int& rcvdLength) const;
479 * Binds the secure socket to a local address.
483 * @privilege http://tizen.org/privilege/socket
485 * @return An error code
486 * @param[in] localEndPoint The local NetEndPoint to associate with the secure socket
487 * @exception E_SUCCESS The method is successful.
488 * @exception E_INVALID_SOCKET The secure socket is invalid.
489 * @exception E_INVALID_STATE The secure socket is not in a valid state.
490 * @exception E_UNSUPPORTED_OPTION The specified parameter is not supported.
491 * @exception E_INVALID_ARG The specified input parameter is invalid.
492 * @exception E_ALREADY_BOUND The address is already in use.
493 * @exception E_OUT_OF_MEMORY The memory is insufficient.
494 * @exception E_SYSTEM A system error has occurred.
495 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
496 * @remarks Use this method if a specific local endpoint should be used.
497 * This method can be used on both the connectionless and connection-oriented protocols.
498 * For connection-oriented sockets, this method need not be called
499 * before using the Connect() method, unless a specific local endpoint needs to be used.
500 * This method must be called before the Listen() method.
502 result Bind(const Tizen::Net::NetEndPoint& localEndPoint);
505 * Places the secure socket in a listening state.
509 * @privilege http://tizen.org/privilege/socket
511 * @return An error code
512 * @param[in] backLog The maximum length of the pending connections queue
513 * @exception E_SUCCESS The method is successful.
514 * @exception E_WOULD_BLOCK A non-blocking secure socket operation cannot be completed immediately.
515 * @exception E_INVALID_SOCKET The secure socket is invalid.
516 * @exception E_INVALID_STATE The secure socket is not in a valid state.
517 * @exception E_UNSUPPORTED_OPTION The specified parameter is not supported.
518 * @exception E_UNSUPPORTED_PROTOCOL The protocol is not supported.
519 * @exception E_ALREADY_CONNECTED The secure socket is already connected.
520 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
521 * @exception E_OUT_OF_MEMORY The memory is insufficient.
522 * @exception E_SYSTEM A system error has occurred.
523 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
524 * @remarks This method causes a connection-oriented socket to listen for
525 * the incoming connection attempts. The @c backlog parameter specifies
526 * the number of incoming connections that can be queued for acceptance.
527 * The Bind() method must be called before calling this method.
529 result Listen(int backLog);
532 * Accepts an incoming connection. @n
533 * This method extracts the first connection from the queue of pending connections, and
534 * creates a new secure socket with the same socket type, protocol type, and protocol family
535 * as the listening secure socket.
539 * @privilege http://tizen.org/privilege/socket
541 * @return A new secure socket for a newly created connection with the same socket type, protocol type, and protocol family, @n
542 * else @c null if an error occurs
543 * @exception E_SUCCESS The method is successful.
544 * @exception E_WOULD_BLOCK A non-blocking secure socket operation cannot be completed immediately.
545 * @exception E_INVALID_CERTIFICATE The server certificate verification has failed on client.
546 * @exception E_CERTIFICATE_VERIFICATION_FAILED The client certificate verification has failed.
547 * @exception E_INVALID_SOCKET The secure socket is invalid.
548 * @exception E_INVALID_STATE The secure socket is not in a valid state.
549 * @exception E_UNSUPPORTED_OPTION This operation is not supported for this socket.
550 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
551 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
552 * @exception E_OUT_OF_MEMORY The memory is insufficient.
553 * @exception E_SYSTEM A system error has occurred.
554 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
555 * @remarks Before calling this method, the Listen() method must be called first
556 * to listen for and queue the incoming connection requests.
557 * In the blocking mode, this method blocks until an incoming connection attempt
558 * is queued. After accepting a connection, the original socket
559 * continues queuing the incoming connection requests until it is closed.
560 * Note that if no connection is pending in the queue and the secure socket is in the blocking mode,
561 * this method blocks until a new connection arrives. If the secure socket is in the non-blocking mode,
562 * the E_WOULD_BLOCK exception is thrown. The specific error code can be accessed using the GetLastResult() method.
564 SecureSocket* AcceptN(void) const;
567 * Executes the specified command on the socket.
571 * @privilege http://tizen.org/privilege/socket
573 * @return An error code
574 * @param[in] cmd The command to execute on the secure socket
575 * @param[in,out] value The value of the IOCTL command
576 * @exception E_SUCCESS The method is successful.
577 * @exception E_INVALID_SOCKET The secure socket is invalid.
578 * @exception E_UNSUPPORTED_OPTION The specified parameters are not supported.
579 * @exception E_INVALID_ARG A specified input parameter is invalid.
580 * @exception E_INVALID_STATE The secure socket is not in a valid state.
581 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
582 * @exception E_OUT_OF_MEMORY The memory is insufficient.
583 * @exception E_SYSTEM A system error has occurred.
584 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
585 * @remarks This method manipulates the underlying device parameters of the secure socket descriptors. @n@n
586 * The NET_SOCKET_FIONBIO option is used for setting the non-blocking/blocking mode on a secure socket.
587 * Set the value to zero for enabling the blocking mode, or to a non-zero value for enabling the non-blocking mode.
588 * When a secure socket is created, by default, it operates in the non-blocking mode and the blocking mode is disabled.
591 result Ioctl(NetSocketIoctlCmd cmd, unsigned long& value) const;
594 * Sets the secure socket to the asynchronous mode by a specified message to the specified event handler when the secure socket events occur.
598 * @return An error code
599 * @param[in] socketEventType The secure socket events of ::NetSocketEventType @n
600 * Multiple events can be combined using the bitwise "|" operator.
601 * @exception E_SUCCESS The method is successful.
602 * @exception E_INVALID_SOCKET The secure socket is invalid.
603 * @exception E_INVALID_STATE The secure socket is not in a valid state.
604 * @exception E_INVALID_ARG The specified input parameter is invalid.
605 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
606 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
608 * The following example demonstrates how to use the %AsyncSelectByListener() method to set a secure socket to the asynchronous mode.
611 * result res = E_SUCCESS;
613 * // Creates the secure socket.
614 * SecureSocket* pClientSocket = new SecureSocket();
615 * res = pClientSocket->Construct(NET_SOCKET_AF_IPV4,NET_SOCKET_TYPE_STREAM,NET_SOCKET_PROTOCOL_SSL);
618 * MySocketSecureClientListener* pSockClientListener = new MySocketSecureClientListener();
619 * res = pClientSocket->AddSecureSocketListener(*pSockClientListener);
621 * // Selects asynchronous event (non-blocking mode).
622 * res = pClientSocket->AsyncSelectByListener(NET_SOCKET_EVENT_CONNECT| NET_SOCKET_EVENT_CLOSE);
624 * // Creates peer endpoint.
625 * Ip4Address peerAddr("XXX.XXX.XXX.XXX"); //Secure socket server address.
626 * unsigned short peerPort = YYY; // Port
627 * NetEndPoint* pPeerEndPoint = new NetEndPoint(peerAddr, peerPort);
629 * // Connects the secure socket.
630 * res = pClientSocket->Connect(*pPeerEndPoint);
633 result AsyncSelectByListener(unsigned long socketEventType);
636 * Adds a listener to the secure socket. @n
637 * The listener can listen to the events when they are fired.
641 * @return An error code
642 * @param[in] listener A reference to ISecureSocketEventListener
643 * @exception E_SUCCESS The method is successful.
644 * @exception E_OUT_OF_MEMORY The memory is insufficient.
645 * @exception E_INVALID_SOCKET The secure socket is invalid.
646 * @exception E_INVALID_STATE The associated secure socket is not in a valid state.
647 * @exception E_SYSTEM A system error has occurred.
648 * @exception E_OBJ_ALREADY_EXIST The listener is already added.
649 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation, @n
650 * because the caller thread is a worker thread.
652 result AddSecureSocketListener(ISecureSocketEventListener& listener);
655 * Removes a listener from the secure socket.
659 * @return An error code
660 * @param[in] listener A reference to ISecureSocketEventListener
661 * @exception E_SUCCESS The method is successful.
662 * @exception E_OBJ_NOT_FOUND The specified object is not found within the indicated range.
663 * @exception E_INVALID_SOCKET The secure socket is invalid.
664 * @exception E_INVALID_STATE The associated secure socket is not in a valid state.
665 * @exception E_SYSTEM A system error has occurred.
667 result RemoveSecureSocketListener(ISecureSocketEventListener& listener);
670 * Gets an option of the secure socket.
674 * @return An error code
675 * @param[in] optionLevel A ::NetSocketOptLevel value
676 * @param[in] optionName A ::NetSocketOptName value
677 * @param[out] optionValue The integer to receive the option setting
678 * @exception E_SUCCESS The method is successful.
679 * @exception E_INVALID_SOCKET The secure socket is invalid.
680 * @exception E_INIT_FAILED The secure socket is not initialized.
681 * @exception E_UNSUPPORTED_OPTION The specified parameters are not supported.
682 * @exception E_INVALID_ARG A specified input parameter is invalid.
683 * @exception E_INVALID_STATE The secure socket is not in a valid state.
684 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
685 * @exception E_IN_PROGRESS A previous request is in progress.
686 * @exception E_CONNECTION_FAILED The secure socket is not connected.
687 * @exception E_SYSTEM A system error has occurred.
688 * @remarks The secure socket options determine the behavior of the current secure socket.
689 * Upon the successful completion of this method, the integer variable specified
690 * by the @c optionValue parameter contains the value of the specified secure socket option.
691 * For an option with a bool data type, a non-zero value is returned if the option is enabled. Otherwise,
692 * a zero value is returned. For an option with an integer data type, the method returns the appropriate value.
693 * The secure socket options are grouped by the level of protocol support.
694 * Listed below are the various secure socket options that can be obtained using this overload. These options are
695 * grouped by the appropriate NetSocketOptLevel.
696 * If any of these options are to be obtained, use the appropriate %NetSocketOptLevel for the @c optionLevel parameter. The option that
697 * is chosen, must be specified in the @c optionName parameter. To set the current value of some of the listed options, use the
698 * SetSockOpt() method. @n@n
699 * The NET_SOCKET_SOL_SOCKET options that can be set using this overloaded method are: @n
700 * NET_SOCKET_SO_SSLVERSION: Gets the SSL version of the secure socket. @n
701 * NET_SOCKET_SO_SSLCIPHERSUITEID: Gets the SSL cipher suite ID of the secure socket.
704 result GetSockOpt(NetSocketOptLevel optionLevel, NetSocketOptName optionName, int& optionValue) const;
707 * Changes an option of the secure socket.
711 * @return An error code
712 * @param[in] optionLevel A ::NetSocketOptLevel value
713 * @param[in] optionName A ::NetSocketOptName value
714 * @param[in] optionValue The option value
715 * @exception E_SUCCESS The method is successful.
716 * @exception E_INVALID_SOCKET The secure socket is invalid.
717 * @exception E_INIT_FAILED The secure socket is not initialized.
718 * @exception E_UNSUPPORTED_OPTION The specified parameters are not supported.
719 * @exception E_INVALID_ARG A specified input parameter is invalid.
720 * @exception E_INVALID_STATE The secure socket is not in a valid state.
721 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
722 * @exception E_IN_PROGRESS A previous request is in progress.
723 * @exception E_CONNECTION_FAILED The secure socket is not connected.
724 * @exception E_SYSTEM A system error has occurred.
725 * @remarks This method is used to change the value of the option specified by the @c optionName parameter.
726 * The secure socket options determine the behavior of the current secure socket. For an option with a bool data type,
727 * specify a non-zero value to enable the option, and a zero value to disable the option.
728 * For an option with an integer data type, specify the appropriate value. The secure socket options are grouped
729 * by the level of protocol support.
730 * Listed below are the various secure socket options that can be set using this overload. These options are
731 * grouped by the appropriate NetSocketOptLevel. If any of these options are to be set, use the appropriate %NetSocketOptLevel for the
732 * @c optionLevel parameter. The chosen option must be specified in the @c optionName parameter.
733 * To get the current value of some of the options listed, use the GetSockOpt() method. @n@n
734 * NET_SOCKET_SO_SSLVERSION: To enable the SSL version of the secure socket. @n
735 * NET_SOCKET_SO_SSLCIPHERSUITEID: To set the SSL cipher suite ID of the secure socket. @n
736 * NET_SOCKET_SO_SSLCERTVERIFY: To disable server certificate verification on the secure client socket. @n
737 * NET_SOCKET_SO_SSLCLIENTCERTVERIFY: To enable client certificate verification on the secure server socket. @n
738 * NET_SOCKET_SO_SSLCERTID: To set the SSL certificate ID for the client authentication. Start the Application control (L"tizen.certificatemanager") for getting the selected client certificate. For more information, see <a href="../org.tizen.native.appprogramming/html/guide/app/appcontrol_certmgr.htm">here</a>. @n
740 result SetSockOpt(NetSocketOptLevel optionLevel, NetSocketOptName optionName, int optionValue);
744 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
746 * @param[in] rhs An instance of %SecureSocket
748 SecureSocket(const SecureSocket& rhs);
751 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
753 * @return A reference to this instance
754 * @param[in] rhs An instance of %SecureSocket
756 SecureSocket& operator =(const SecureSocket& rhs);
759 _SecureSocketImpl* __pSecureSocketImpl;
761 friend class _SecureSocketImpl;
764 } } } // Tizen::Net::Sockets
765 #endif // _FNET_SOCK_SECURE_SOCKET_H_