2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (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 * This class provides secured simple methods for sending and receiving 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 versions.
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 IDs.
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 are 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. @n
175 * For full construction, the Construct() method must be called right after calling this constructor.
182 * This destructor overrides Tizen::Base::Object::~Object().
188 virtual ~SecureSocket(void);
191 * Initializes this instance of %SecureSocket with the specified parameters. @n
192 * The secure socket is initialized in the non-blocking mode by default.
193 * Use %Ioctl() (with NET_SOCKET_FIONBIO) to use a %SecureSocket in the blocking mode.
197 * @privilege %http://tizen.org/privilege/socket
199 * @return An error code
200 * @param[in] netConnection The run-time session where a %SecureSocket instance is used
201 * @param[in] addressFamily The NetSocketAddressFamily value that
202 * @param[in] socketType The secure socket type @n
203 * The value should be @c NET_SOCKET_TYPE_STREAM.
204 * @param[in] protocol The protocol used by this secure socket @n
205 * The value should be @c NET_SOCKET_PROTOCOL_SSL.
206 * @exception E_SUCCESS The method is successful.
207 * @exception E_WOULD_BLOCK The non-blocking secure socket operation cannot be completed immediately.
208 * @exception E_OUT_OF_MEMORY The memory is insufficient.
209 * @exception E_MAX_EXCEEDED All sockets are in use.
210 * @exception E_UNSUPPORTED_OPTION A specified input parameter is not supported.
211 * @exception E_INVALID_ARG A specified input parameter is invalid.
212 * @exception E_UNSUPPORTED_PROTOCOL The protocol is not supported.
213 * @exception E_UNSUPPORTED_TYPE The secure socket type is not supported.
214 * @exception E_UNSUPPORTED_FAMILY The address family is not supported.
215 * @exception E_SYSTEM A system error has occurred.
216 * @exception E_INVALID_CONNECTION The network connection is invalid.
217 * @exception E_FAILURE The method has failed due to an undefined error.
218 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
219 * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1
221 * - @c netConnection specifies a run-time network connection. @n
222 * @c addressFamily specifies an address family. @n
223 * @c socketType specifies the type of the secure socket. SSL only supports stream-based protocols. @n
224 * @c protocol specifies the protocol used by the secure socket. SSL protocol is defined as @c NET_SOCKET_PROTOCOL_SSL. @n
225 * The first parameter must be a valid run-time network connection. The three parameters are not independent.
226 * Some address families restrict the protocols that can be used with them, and often the secure socket type is implicit in the protocol. If a combination
227 * of the address family, socket type, and protocol type results in an invalid secure socket, this method returns an error.
228 * - For each secure socket used in the non-blocking mode, an event listener (ISecureSocketEventListener) should be registered and maintained,
229 * so that it can receive asynchronous notifications of the secure socket events. AddSecureSocketListener() is used to
230 * register an event listener. @n
231 * If a secure socket in the blocking mode needs to be used, %Ioctl() (with @c NET_SOCKET_FIONBIO) should be called after initializing the secure socket
232 * through this method.
233 * @see Ioctl() for understanding the blocking/non-blocking mode
235 result Construct(const Tizen::Net::NetConnection& netConnection, NetSocketAddressFamily addressFamily, NetSocketType socketType, NetSocketProtocol protocol);
238 * Initializes this instance of %SecureSocket with the specified parameters. @n
239 * The secure socket is initialized in the non-blocking mode by default.
240 * Use %Ioctl() (with @c NET_SOCKET_FIONBIO) to use a %SecureSocket in the blocking mode.
244 * @privilege %http://tizen.org/privilege/socket
246 * @return An error code
247 * @param[in] addressFamily The ::NetSocketAddressFamily value
248 * @param[in] socketType The secure socket type @n
249 * The value should be @c NET_SOCKET_TYPE_STREAM.
250 * @param[in] protocol The protocol used by this secure socket @n
251 * The value should be @c NET_SOCKET_PROTOCOL_SSL.
252 * @exception E_SUCCESS The method is successful.
253 * @exception E_WOULD_BLOCK The non-blocking secure socket operation cannot be completed immediately.
254 * @exception E_OUT_OF_MEMORY The memory is insufficient.
255 * @exception E_MAX_EXCEEDED All sockets are in use.
256 * @exception E_UNSUPPORTED_OPTION A specified input parameter is not supported.
257 * @exception E_INVALID_ARG A specified input parameter is invalid.
258 * @exception E_UNSUPPORTED_PROTOCOL The protocol is not supported.
259 * @exception E_UNSUPPORTED_TYPE The secure socket type is not supported.
260 * @exception E_UNSUPPORTED_FAMILY The address family is not supported.
261 * @exception E_SYSTEM A system error has occurred.
262 * @exception E_INVALID_CONNECTION The network connection is invalid.
263 * @exception E_FAILURE The method has failed due to an undefined error.
264 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
265 * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1
267 * - @c addressFamily specifies an address family. @n
268 * @c socketType specifies the type of the secure socket. SSL only supports stream-based protocols. @n
269 * @c protocol specifies the protocol used by the secure socket. The SSL protocol is defined as @c NET_SOCKET_PROTOCOL_SSL. @n
270 * The three parameters are not independent. Some address families restrict the protocols that can be used with them, and often the
271 * secure socket type is implicit in the protocol. If a combination of the address family, socket type, and protocol type results in
272 * an invalid secure socket, this method returns an error.
273 * - For each secure socket used in the non-blocking mode, an event listener
274 * (ISecureSocketEventListener) should be registered and maintained, so that it can receive asynchronous notifications of the secure socket
275 * events. AddSecureSocketListener() is used to register an event listener. @n
276 * If a secure socket in the blocking mode needs to be used, %Ioctl() (with @c NET_SOCKET_FIONBIO) should be called after initializing the secure socket
277 * through this method.
278 * @see Ioctl() for understanding the blocking/non-blocking mode
280 result Construct(NetSocketAddressFamily addressFamily, NetSocketType socketType, NetSocketProtocol protocol);
284 * Closes the secure socket. @n
285 * All the resources associated with the secure socket are freed.
289 * @privilege %http://tizen.org/privilege/socket
291 * @return An error code
292 * @exception E_SUCCESS The method is successful.
293 * @exception E_INVALID_STATE The secure socket is not in a valid state.
294 * @exception E_INVALID_SOCKET The secure socket is invalid.
295 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
296 * @exception E_OUT_OF_MEMORY The memory is insufficient.
297 * @exception E_SYSTEM A system error has occurred.
298 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
299 * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1
300 * @remarks If the %SecureSocket class is not initialized through one of the Construct() methods or this method is called more than once,
301 * then this method returns @c E_INVALID_STATE.
306 * Establishes a connection with a remote host.
309 * @brief <i> [Compatibility] </i>
313 * @compatibility This method has compatibility issues with OSP compatible applications. @n
314 * For more information, see @ref SecureSocketConnectPage "here".
317 * @privilege %http://tizen.org/privilege/socket
319 * @return An error code
320 * @param[in] remoteEndPoint An instance of NetEndPoint that represents the remote device
321 * @exception E_SUCCESS The method is successful.
322 * @exception E_INVALID_SOCKET The secure socket is invalid.
323 * @exception E_INVALID_STATE The secure socket is not in a valid state.
324 * @exception E_HOST_UNREACHABLE The network cannot be reached from this host at this time.
325 * @exception E_IN_PROGRESS A previous request is in progress.
326 * @exception E_INVALID_ARG The specified input parameter is invalid.
327 * @exception E_WOULD_BLOCK The non-blocking secure socket operation cannot be completed immediately.
328 * @exception E_INVALID_CERTIFICATE The client certificate verification has failed on the server.
329 * @exception E_CERTIFICATE_VERIFICATION_FAILED The server certificate verification has failed.
330 * @exception E_CONNECTION_FAILED The secure socket is not connected.
331 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
332 * @exception E_ALREADY_CONNECTED The secure socket is already connected.
333 * @exception E_UNSUPPORTED_FAMILY The address family is not supported.
334 * @exception E_UNSUPPORTED_PROTOCOL The protocol is not supported.
335 * @exception E_OUT_OF_MEMORY The memory is insufficient.
336 * @exception E_SYSTEM A system error has occurred.
337 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
338 * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1
341 * - Starts a connection with a remote peer including SSL handshaking. @n
342 * After this method is called, ISecureSocketEventListener::OnSecureSocketConnected() is called.
343 * - The data is sent to and received from the remote device using Send() and Receive() respectively.
344 * - If the Bind() method is not called before calling this method, the underlying service provider assigns the local network address and port number.
346 result Connect(const Tizen::Net::NetEndPoint& remoteEndPoint);
349 * @page SecureSocketConnectPage Compatibility for Connect()
351 * @section SecureSocketConnectPageIssueSection Issues
352 * Implementation of this method in %Tizen API versions prior to 2.1 has the following issue: @n
353 * -# If the application provides a loopback address in NetEndPoint, it returns @c E_SYSTEM.
355 * @section SecureSocketConnectPageResolutionSection Resolutions
356 * The issue mentioned above is resolved in %Tizen API version 2.1 as follows: @n
357 * -# If the application provides a loopback address in NetEndPoint, it returns @c E_SUCCESS instead of @c E_SYSTEM.
361 * Sends data to a secure socket of type ::NET_SOCKET_TYPE_STREAM.
365 * @return An error code
366 * @param[in] buffer An instance of Tizen::Base::ByteBuffer that contains the data to send
367 * @exception E_SUCCESS The method is successful.
368 * @exception E_INVALID_SOCKET The secure socket is invalid.
369 * @exception E_INVALID_STATE The secure socket is not in a valid state.
370 * @exception E_UNSUPPORTED_OPTION The specified input parameter is not supported.
371 * @exception E_INVALID_ARG The specified input parameter is invalid.
372 * @exception E_WOULD_BLOCK The non-blocking secure socket operation cannot be completed immediately.
373 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
374 * @exception E_CONNECTION_FAILED The secure socket is not connected.
375 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
376 * @exception E_OUT_OF_MEMORY The memory is insufficient.
377 * @exception E_SYSTEM A system error has occurred.
379 * - This method sends data to the remote host specified in the Connect() method.
380 * - This method sends data in @c buffer, starting from the current position of the buffer.@n
381 * After the operation, the position of the buffer is incremented by the number of bytes successfully sent. The new position cannot be larger than the
383 * - This method can be used only for connection-oriented sockets.
384 * - In the blocking mode, if space is not available in the send queue, the secure socket blocks until space becomes available.
385 * In the non-blocking mode, this method returns the error @c E_WOULD_BLOCK.
386 * - This method may complete successfully even if it sends less bytes than the number of bytes present in the buffer. The application
387 * should keep track of the number of bytes sent and retry the operation until the application sends the bytes in the
389 * - There is no guarantee that the data that is sent appears on the network immediately. To increase network efficiency, the
390 * underlying system may delay the transmission until a significant amount of outgoing data is collected. A successful completion of this
391 * method means that the underlying system has room to buffer the data sent for a network. If it is important for the
392 * application to send every byte to the remote host immediately, use SetSockOpt() (with ::NET_SOCKET_TCP_NODELAY) of type
393 * ::NetSocketOptName to enable no delay.
395 result Send(Tizen::Base::ByteBuffer& buffer);
398 * Sends data to a secure socket of type ::NET_SOCKET_TYPE_STREAM.
402 * @return An error code
403 * @param[in] pBuffer A pointer to the buffer that contains the data to send
404 * @param[in] length The length of the data in the buffer
405 * @param[out] sentLength The length of the data sent successfully
406 * @exception E_SUCCESS The method is successful.
407 * @exception E_INVALID_SOCKET The secure socket is invalid.
408 * @exception E_INVALID_STATE The secure socket is not in a valid state.
409 * @exception E_UNSUPPORTED_OPTION A specified input parameter is not supported.
410 * @exception E_INVALID_ARG A specified input parameter is invalid.
411 * @exception E_WOULD_BLOCK The non-blocking secure socket operation cannot be completed immediately.
412 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
413 * @exception E_CONNECTION_FAILED The secure socket is not connected.
414 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
415 * @exception E_OUT_OF_MEMORY The memory is insufficient.
416 * @exception E_SYSTEM A system error has occurred.
418 * - This method sends data to a remote host specified in the Connect() method.
419 * - This method sends data in the buffer of length @c length, starting from the current position of the buffer.
420 * - In the blocking mode, if space is not available in the send queue, the secure socket blocks until space becomes available.
421 * In the non-blocking mode, this method returns the error @c E_WOULD_BLOCK.
422 * - This method may complete successfully even if it sends less bytes than the number of bytes
423 * in the buffer. The application should keep track of the number of bytes sent
424 * and retry the operation until the application sends the bytes in the buffer.
425 * - There is no guarantee that the data that is sent appears on the network immediately.
426 * To increase the network efficiency, the underlying system may delay the transmission until a significant amount
427 * of outgoing data is collected. A successful completion of this method means that the underlying
428 * system has room to buffer the data sent for a network. @n
429 * If it is important for the application to send every byte to the remote host immediately,
430 * use SetSockOpt() (with ::NET_SOCKET_TCP_NODELAY) of type ::NetSocketOptName to enable no delay.
432 result Send(void* pBuffer, int length, int& sentLength);
435 * Receives data from a secure socket of type ::NET_SOCKET_TYPE_STREAM.
439 * @return An error code
440 * @param[out] buffer An instance of Tizen::Base::ByteBuffer that is the storage location for the received data
441 * @exception E_SUCCESS The method is successful.
442 * @exception E_INVALID_SOCKET The secure socket is invalid.
443 * @exception E_INVALID_STATE The secure socket is not in a valid state.
444 * @exception E_UNSUPPORTED_OPTION The specified input parameter is not supported.
445 * @exception E_INVALID_ARG The specified input parameter is invalid.
446 * @exception E_WOULD_BLOCK The non-blocking secure socket operation cannot be completed immediately.
447 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
448 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
449 * @exception E_IN_PROGRESS A previous request is in progress.
450 * @exception E_OUT_OF_MEMORY The memory is insufficient.
451 * @exception E_SYSTEM A system error has occurred.
453 * - This method copies the data into @c buffer, starting from the current position of the buffer.
454 * After the operation, the position of the buffer is incremented by the number of bytes successfully received.
455 * The new position cannot be larger than the original limit.
456 * - This method can be called from connection-oriented sockets only.
457 * - If there is no data at the secure socket in the blocking mode,
458 * this method blocks until the data arrives. If the secure socket is in the non-blocking mode,
459 * the error @c E_WOULD_BLOCK is returned.
462 result Receive(Tizen::Base::ByteBuffer& buffer) const;
465 * Receives data from a secure socket of type ::NET_SOCKET_TYPE_STREAM.
469 * @return An error code
470 * @param[out] pBuffer A pointer to the buffer that is the storage location for the received data
471 * @param[in] length The length of the data in the buffer
472 * @param[out] rcvdLength The length of the data that is received successfully
473 * @exception E_SUCCESS The method is successful.
474 * @exception E_INVALID_SOCKET The secure socket is invalid.
475 * @exception E_INVALID_STATE The secure socket is not in a valid state.
476 * @exception E_UNSUPPORTED_OPTION A specified input parameter is not supported.
477 * @exception E_INVALID_ARG A specified input parameter is invalid.
478 * @exception E_WOULD_BLOCK The non-blocking secure socket operation cannot be completed immediately.
479 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
480 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
481 * @exception E_IN_PROGRESS A previous request is in progress.
482 * @exception E_OUT_OF_MEMORY The memory is insufficient.
483 * @exception E_SYSTEM A system error has occurred.
485 * - This method copies the data into the buffer of length @c length, starting from the current position of the buffer.
486 * - This method can be called from the connection-oriented sockets only.
487 * - If there is no data at the secure socket in the blocking mode,
488 * this method blocks until the data arrives. If the secure socket is in the non-blocking mode,
489 * the error @c E_WOULD_BLOCK is returned.
491 result Receive(void* pBuffer, int length, int& rcvdLength) const;
494 * Binds the secure socket to a local address.
498 * @privilege %http://tizen.org/privilege/socket
500 * @return An error code
501 * @param[in] localEndPoint The local NetEndPoint to associate with the secure socket
502 * @exception E_SUCCESS The method is successful.
503 * @exception E_INVALID_SOCKET The secure socket is invalid.
504 * @exception E_INVALID_STATE The secure socket is not in a valid state.
505 * @exception E_UNSUPPORTED_OPTION The specified input parameter is not supported.
506 * @exception E_INVALID_ARG The specified input parameter is invalid.
507 * @exception E_ALREADY_BOUND The address is already in use.
508 * @exception E_OUT_OF_MEMORY The memory is insufficient.
509 * @exception E_SYSTEM A system error has occurred.
510 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
511 * @exception E_USER_NOT_CONSENTED The user bhas blocked the application from calling this method. @b Since: @b 2.1
513 * - Use this method if a specific local endpoint should be used.
514 * - This method can be used on both the connectionless and connection-oriented protocols.
515 * For connection-oriented sockets, this method need not be called
516 * before using the Connect() method, unless a specific local endpoint needs to be used.
517 * - This method must be called before the Listen() method.
519 result Bind(const Tizen::Net::NetEndPoint& localEndPoint);
522 * Places the secure socket in the listening state.
525 * @pre Before calling this method, the Bind() method must be called.
527 * @privilege %http://tizen.org/privilege/socket
529 * @return An error code
530 * @param[in] backLog The maximum length of the pending connections queue
531 * @exception E_SUCCESS The method is successful.
532 * @exception E_WOULD_BLOCK The non-blocking secure socket operation cannot be completed immediately.
533 * @exception E_INVALID_SOCKET The secure socket is invalid.
534 * @exception E_INVALID_STATE The secure socket is not in a valid state.
535 * @exception E_UNSUPPORTED_OPTION The specified input parameter is not supported.
536 * @exception E_UNSUPPORTED_PROTOCOL The protocol is not supported.
537 * @exception E_ALREADY_CONNECTED The secure socket is already connected.
538 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
539 * @exception E_OUT_OF_MEMORY The memory is insufficient.
540 * @exception E_SYSTEM A system error has occurred.
541 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
542 * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1
543 * @remarks This method causes a connection-oriented socket to listen for
544 * incoming connection attempts. @c backLog specifies
545 * the number of incoming connections that can be queued for acceptance.
547 result Listen(int backLog);
550 * Accepts an incoming connection. @n
551 * The %AcceptN() method extracts the first connection from the queue of pending connections, and
552 * creates a new secure socket with the same socket type, protocol type, and protocol family
553 * as the listening secure socket.
556 * @pre Before calling this method, the Listen() method must be called first to listen for and queue the incoming connection requests.
558 * @privilege %http://tizen.org/privilege/socket
560 * @return The new secure socket for the newly created connection with the same socket type, protocol type, and protocol family, @n
561 * else @c null if an error occurs
562 * @exception E_SUCCESS The method is successful.
563 * @exception E_WOULD_BLOCK The non-blocking secure socket operation cannot be completed immediately.
564 * @exception E_INVALID_CERTIFICATE The server certificate verification has failed at the client's side.
565 * @exception E_CERTIFICATE_VERIFICATION_FAILED The client certificate verification has failed.
566 * @exception E_INVALID_SOCKET The secure socket is invalid.
567 * @exception E_INVALID_STATE The secure socket is not in a valid state.
568 * @exception E_UNSUPPORTED_OPTION This operation is not supported for this socket.
569 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
570 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
571 * @exception E_OUT_OF_MEMORY The memory is insufficient.
572 * @exception E_SYSTEM A system error has occurred.
573 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
574 * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1
576 * - In the blocking mode, this method blocks until an incoming connection attempt is queued. After accepting a connection, the original socket
577 * continues queuing the incoming connection requests until it is closed. @n
578 * Note that if no connection is pending in the queue and the secure socket is in the blocking mode,
579 * this method blocks until a new connection arrives. If the secure socket is in the non-blocking mode, the @c E_WOULD_BLOCK exception is thrown.
580 * - The specific error code can be accessed using the GetLastResult() method.
582 SecureSocket* AcceptN(void) const;
585 * Executes the specified command on the socket.
589 * @privilege %http://tizen.org/privilege/socket
591 * @return An error code
592 * @param[in] cmd The command to execute on the secure socket
593 * @param[in,out] value The value of the IOCTL command
594 * @exception E_SUCCESS The method is successful.
595 * @exception E_INVALID_SOCKET The secure socket is invalid.
596 * @exception E_UNSUPPORTED_OPTION A specified input parameter is not supported.
597 * @exception E_INVALID_ARG A specified input parameter is invalid.
598 * @exception E_INVALID_STATE The secure socket is not in a valid state.
599 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
600 * @exception E_OUT_OF_MEMORY The memory is insufficient.
601 * @exception E_SYSTEM A system error has occurred.
602 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
603 * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1
604 * @remarks This method manipulates the underlying device parameters of the secure socket descriptors. @n
605 * The @c NET_SOCKET_FIONBIO option is used for setting the non-blocking/blocking mode on a secure socket. @n
606 * Set the value to zero for enabling the blocking mode, or to a non-zero value for enabling the non-blocking mode. @n
607 * When a secure socket is created, by default, it operates in the non-blocking mode and the blocking mode is disabled.
610 result Ioctl(NetSocketIoctlCmd cmd, unsigned long& value) const;
613 * Sets the secure socket to the asynchronous mode by the specified message to the specified event handler when the secure socket events occur.
617 * @return An error code
618 * @param[in] socketEventType The secure socket events of ::NetSocketEventType @n
619 * Multiple events can be combined using the bitwise "|" operator.
620 * @exception E_SUCCESS The method is successful.
621 * @exception E_INVALID_SOCKET The secure socket is invalid.
622 * @exception E_INVALID_STATE The secure socket is not in a valid state.
623 * @exception E_INVALID_ARG The specified input parameter is invalid.
624 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
625 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
627 * The following example demonstrates how to use the %AsyncSelectByListener() method to set a secure socket to the asynchronous mode.
630 * result res = E_SUCCESS;
632 * // Creates the secure socket.
633 * SecureSocket* pClientSocket = new SecureSocket();
634 * res = pClientSocket->Construct(NET_SOCKET_AF_IPV4,NET_SOCKET_TYPE_STREAM,NET_SOCKET_PROTOCOL_SSL);
637 * MySocketSecureClientListener* pSockClientListener = new MySocketSecureClientListener();
638 * res = pClientSocket->AddSecureSocketListener(*pSockClientListener);
640 * // Selects asynchronous event (non-blocking mode).
641 * res = pClientSocket->AsyncSelectByListener(NET_SOCKET_EVENT_CONNECT| NET_SOCKET_EVENT_CLOSE);
643 * // Creates peer endpoint.
644 * Ip4Address peerAddr("XXX.XXX.XXX.XXX"); //Secure socket server address.
645 * unsigned short peerPort = YYY; // Port
646 * NetEndPoint* pPeerEndPoint = new NetEndPoint(peerAddr, peerPort);
648 * // Connects the secure socket.
649 * res = pClientSocket->Connect(*pPeerEndPoint);
652 result AsyncSelectByListener(unsigned long socketEventType);
655 * Adds a listener to the secure socket. @n
656 * The listener can listen to the events when they are fired.
660 * @return An error code
661 * @param[in] listener A reference to ISecureSocketEventListener
662 * @exception E_SUCCESS The method is successful.
663 * @exception E_OUT_OF_MEMORY The memory is insufficient.
664 * @exception E_INVALID_SOCKET The secure socket is invalid.
665 * @exception E_INVALID_STATE The associated secure socket is not in a valid state.
666 * @exception E_SYSTEM A system error has occurred.
667 * @exception E_OBJ_ALREADY_EXIST The listener is already added.
668 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation, @n
669 * because the caller thread is a worker thread.
671 result AddSecureSocketListener(ISecureSocketEventListener& listener);
674 * Removes a listener from the secure socket.
678 * @return An error code
679 * @param[in] listener A reference to ISecureSocketEventListener
680 * @exception E_SUCCESS The method is successful.
681 * @exception E_OBJ_NOT_FOUND The specified object is not found within the indicated range.
682 * @exception E_INVALID_SOCKET The secure socket is invalid.
683 * @exception E_INVALID_STATE The associated secure socket is not in a valid state.
684 * @exception E_SYSTEM A system error has occurred.
686 result RemoveSecureSocketListener(ISecureSocketEventListener& listener);
689 * Gets an option of the secure socket.
693 * @return An error code
694 * @param[in] optionLevel The ::NetSocketOptLevel value
695 * @param[in] optionName The ::NetSocketOptName value
696 * @param[out] optionValue The integer to receive the option setting
697 * @exception E_SUCCESS The method is successful.
698 * @exception E_INVALID_SOCKET The secure socket is invalid.
699 * @exception E_INIT_FAILED The secure socket is not initialized.
700 * @exception E_UNSUPPORTED_OPTION A specified input parameter is not supported.
701 * @exception E_INVALID_ARG A specified input parameter is invalid.
702 * @exception E_INVALID_STATE The secure socket is not in a valid state.
703 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
704 * @exception E_IN_PROGRESS A previous request is in progress.
705 * @exception E_CONNECTION_FAILED The secure socket is not connected.
706 * @exception E_SYSTEM A system error has occurred.
708 * - The secure socket options determine the behavior of the current secure socket.
709 * - Upon successful completion of this method, the integer variable specified
710 * by @c optionValue contains the value of the specified secure socket option.
711 * For an option with a @c bool data type, a non-zero value is returned if the option is enabled. Otherwise,
712 * a zero value is returned.
713 * For an option with an integer data type, the method returns the appropriate value.
714 * - The secure socket options are grouped by the level of protocol support.
715 * Listed below are the various secure socket options that can be obtained using this overload. These options are
716 * grouped by the appropriate NetSocketOptLevel.
717 * If any of these options are to be obtained, use the appropriate %NetSocketOptLevel for @c optionLevel. The option that
718 * is chosen, must be specified in @c optionName. To set the current value of some of the listed options, use the
719 * SetSockOpt() method. @n@n
720 * @c The NET_SOCKET_SOL_SOCKET options that can be set using this overloaded method are: @n
721 * @c NET_SOCKET_SO_SSLVERSION: Gets the SSL version of the secure socket. @n
722 * @c NET_SOCKET_SO_SSLCIPHERSUITEID: Gets the SSL cipher suite ID of the secure socket.
724 result GetSockOpt(NetSocketOptLevel optionLevel, NetSocketOptName optionName, int& optionValue) const;
727 * Changes an option of the secure socket.
731 * @return An error code
732 * @param[in] optionLevel The ::NetSocketOptLevel value
733 * @param[in] optionName The ::NetSocketOptName value
734 * @param[in] optionValue The option value
735 * @exception E_SUCCESS The method is successful.
736 * @exception E_INVALID_SOCKET The secure socket is invalid.
737 * @exception E_INIT_FAILED The secure socket is not initialized.
738 * @exception E_UNSUPPORTED_OPTION A specified input parameter is not supported.
739 * @exception E_INVALID_ARG A specified input parameter is invalid.
740 * @exception E_INVALID_STATE The secure socket is not in a valid state.
741 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
742 * @exception E_IN_PROGRESS A previous request is in progress.
743 * @exception E_CONNECTION_FAILED The secure socket is not connected.
744 * @exception E_SYSTEM A system error has occurred.
746 * - This method is used to change the value of the option specified by @c optionName. @n
747 * The secure socket options determine the behavior of the current secure socket. For an option with a @c bool data type,
748 * specify a non-zero value to enable the option, and a zero value to disable the option.
749 * For an option with an integer data type, specify the appropriate value.
750 * - The secure socket options are grouped by the level of protocol support. @n
751 * Listed below are the various secure socket options that can be set using this overload. These options are
752 * grouped by the appropriate NetSocketOptLevel. @n If any of these options are to be set, use the appropriate %NetSocketOptLevel for
753 * @c optionLevel. The chosen option must be specified in @c optionName. @n@n
754 * @c NET_SOCKET_SO_SSLVERSION: To enable the SSL version of the secure socket. @n
755 * @c NET_SOCKET_SO_SSLCIPHERSUITEID: To set the SSL cipher suite ID of the secure socket. @n
756 * @c NET_SOCKET_SO_SSLCERTVERIFY: To disable server certificate verification on the secure client socket. @n
757 * @c NET_SOCKET_SO_SSLCLIENTCERTVERIFY: To enable client certificate verification on the secure server socket. @n
758 * @c 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
761 result SetSockOpt(NetSocketOptLevel optionLevel, NetSocketOptName optionName, int optionValue);
765 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
767 * @param[in] rhs An instance of %SecureSocket
769 SecureSocket(const SecureSocket& rhs);
772 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
774 * @return A reference to this instance
775 * @param[in] rhs An instance of %SecureSocket
777 SecureSocket& operator =(const SecureSocket& rhs);
780 _SecureSocketImpl* __pSecureSocketImpl;
782 friend class _SecureSocketImpl;
785 } } } // Tizen::Net::Sockets
786 #endif // _FNET_SOCK_SECURE_SOCKET_H_