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 * This 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 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
219 * @remarks The @c netConnection parameter specifies a run-time network connection. @n
220 * The @c addressFamily parameter specifies an address family. @n
221 * The @c socketType parameter specifies the type of the secure socket. SSL only supports stream-based protocols. @n
222 * The @c protocol parameter specifies the protocol used by the secure socket. SSL protocol is defined as NET_SOCKET_PROTOCOL_SSL. @n
223 * The first parameter must be a valid run-time network connection. The three parameters are not independent. Some address families
224 * restrict the protocols that can be used with them, and often the secure socket type is implicit in the protocol. If the combination
225 * of the address family, socket type, and protocol type results in an invalid secure socket, this method returns an error. @n For each
226 * secure socket used in the non-blocking mode, an event listener (ISecureSocketEventListener) should be registered and maintained.
227 * so that it can receive asynchronous notifications of the secure socket events. AddSecureSocketListener() is used to
228 * register an event listener. @n
229 * 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
230 * through this method.
231 * @see Ioctl() for understanding the blocking/non-blocking mode
233 result Construct(const Tizen::Net::NetConnection& netConnection, NetSocketAddressFamily addressFamily, NetSocketType socketType, NetSocketProtocol protocol);
236 * Initializes this instance of %SecureSocket with the specified parameters. @n
237 * The secure socket is initialized in a non-blocking mode by default.
238 * Use Ioctl() (with NET_SOCKET_FIONBIO) to use a %SecureSocket in the blocking mode.
242 * @privilege %http://tizen.org/privilege/socket
244 * @return An error code
245 * @param[in] addressFamily A ::NetSocketAddressFamily value
246 * @param[in] socketType The secure socket type @n
247 * The value should be NET_SOCKET_TYPE_STREAM.
248 * @param[in] protocol The protocol used by this secure socket @n
249 * The value should be NET_SOCKET_PROTOCOL_SSL.
250 * @exception E_SUCCESS The method is successful.
251 * @exception E_WOULD_BLOCK A non-blocking secure socket operation cannot be completed immediately.
252 * @exception E_OUT_OF_MEMORY The memory is insufficient.
253 * @exception E_MAX_EXCEEDED All sockets are in use.
254 * @exception E_UNSUPPORTED_OPTION The specified parameters are not supported.
255 * @exception E_INVALID_ARG A specified input parameter is invalid.
256 * @exception E_UNSUPPORTED_PROTOCOL The protocol is not supported.
257 * @exception E_UNSUPPORTED_TYPE The secure socket type is not supported.
258 * @exception E_UNSUPPORTED_FAMILY The address family is not supported.
259 * @exception E_SYSTEM A system error has occurred.
260 * @exception E_INVALID_CONNECTION The network connection is invalid.
261 * @exception E_FAILURE The method has failed due to an undefined error.
262 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
263 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
264 * @remarks The @c addressFamily parameter specifies an address family. @n
265 * The @c socketType parameter specifies the type of the secure socket. SSL only supports stream-based protocols. @n
266 * The @c protocol parameter specifies the protocol used by the secure socket. The SSL protocol is defined as NET_SOCKET_PROTOCOL_SSL. @n
267 * The three parameters are not independent. Some address families restrict the protocols that can be used with them, and often the
268 * secure socket type is implicit in the protocol. If the combination of the address family, socket type, and protocol type results in
269 * an invalid secure socket, this method returns an error. @n
270 * For each secure socket used in the non-blocking mode, an event listener
271 * (ISecureSocketEventListener) should be registered and maintained, so that it can receive asynchronous notifications of the secure socket
272 * events. AddSecureSocketListener() is used to register an event listener. @n
273 * 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
274 * through this method.
275 * @see Ioctl() for understanding the blocking/non-blocking mode
277 result Construct(NetSocketAddressFamily addressFamily, NetSocketType socketType, NetSocketProtocol protocol);
281 * Closes the secure socket. @n
282 * All the resources associated with the secure socket are freed.
286 * @privilege %http://tizen.org/privilege/socket
288 * @return An error code
289 * @exception E_SUCCESS The method is successful.
290 * @exception E_INVALID_STATE The secure socket is not in a valid state.
291 * @exception E_INVALID_SOCKET The secure socket is invalid.
292 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
293 * @exception E_OUT_OF_MEMORY The memory is insufficient.
294 * @exception E_SYSTEM A system error has occurred.
295 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
296 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
297 * @remarks If the %SecureSocket class is not initialized through one of the Construct() methods or this method is called more than once,
298 * then this method returns E_INVALID_STATE.
303 * Establishes a connection to a remote host.
306 * @brief <i> [Compatibility] </i>
310 * @compatibility This method has compatibility issues with OSP compatible applications. @n
311 * For more information, see @ref SecureSocketConnectPage "here".
314 * @privilege %http://tizen.org/privilege/socket
316 * @return An error code
317 * @param[in] remoteEndPoint An instance of NetEndPoint representing the remote device
318 * @exception E_SUCCESS The method is successful.
319 * @exception E_INVALID_SOCKET The secure socket is invalid.
320 * @exception E_INVALID_STATE The secure socket is not in a valid state.
321 * @exception E_HOST_UNREACHABLE The network cannot be reached from this host at this time.
322 * @exception E_IN_PROGRESS A previous request is in progress.
323 * @exception E_INVALID_ARG The specified input parameter is invalid.
324 * @exception E_WOULD_BLOCK A non-blocking secure socket operation cannot be completed immediately.
325 * @exception E_INVALID_CERTIFICATE The client certificate verification has failed on server.
326 * @exception E_CERTIFICATE_VERIFICATION_FAILED The server certificate verification has failed.
327 * @exception E_CONNECTION_FAILED The secure socket is not connected.
328 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
329 * @exception E_ALREADY_CONNECTED The secure socket is already connected.
330 * @exception E_UNSUPPORTED_FAMILY The address family is not supported.
331 * @exception E_UNSUPPORTED_PROTOCOL The protocol is not supported.
332 * @exception E_OUT_OF_MEMORY The memory is insufficient.
333 * @exception E_SYSTEM A system error has occurred.
334 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
335 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
337 * @remarks Starts connection to a remote peer including SSL handshaking.
338 * After this method is called, ISecureSocketEventListener::OnSecureSocketConnected() is called. The data is sent to and received from the remote
339 * device using Send() and Receive() respectively. If the Bind() method is not called before calling this
340 * method, the underlying service provider assigns the local network address and port number.
342 result Connect(const Tizen::Net::NetEndPoint& remoteEndPoint);
345 * @page SecureSocketConnectPage Compatibility for Connect()
347 * @section SecureSocketConnectPageIssueSection Issues
348 * Implementation of this method in %Tizen API versions prior to 2.1 has the following issue: @n
349 * -# If the application provides a loopback address in NetEndPoint, it returns E_SYSTEM.
351 * @section SecureSocketConnectPageResolutionSection Resolutions
352 * The issue mentioned above is resolved in %Tizen API version 2.1 as follows: @n
353 * -# If the application provides a loopback address in NetEndPoint, it returns E_SUCCESS instead of E_SYSTEM.
357 * Sends the data to a secure socket of the type NET_SOCKET_TYPE_STREAM.
361 * @return An error code
362 * @param[in] buffer An instance of Tizen::Base::ByteBuffer that contains the data to send
363 * @exception E_SUCCESS The method is successful.
364 * @exception E_INVALID_SOCKET The secure socket is invalid.
365 * @exception E_INVALID_STATE The secure socket is not in a valid state.
366 * @exception E_UNSUPPORTED_OPTION The specified parameter is not supported.
367 * @exception E_INVALID_ARG The specified input parameter is invalid.
368 * @exception E_WOULD_BLOCK A non-blocking secure socket operation cannot be completed immediately.
369 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
370 * @exception E_CONNECTION_FAILED The secure socket is not connected.
371 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
372 * @exception E_OUT_OF_MEMORY The memory is insufficient.
373 * @exception E_SYSTEM A system error has occurred.
374 * @remarks This method sends the data to the remote host specified in the Connect() method.
375 * This method sends the data in the @c buffer parameter, starting from the current position of the buffer. After the operation,
376 * the position of the buffer is incremented by the number of bytes successfully sent. The new position cannot be larger than the
377 * original limit. This method can be used only for connection-oriented sockets.
378 * In the blocking mode, if space is not available in the send queue, the secure socket blocks until space becomes available.
379 * In the non-blocking mode, this method returns the error E_WOULD_BLOCK. This method may
380 * complete successfully even if it sends less bytes than the number of bytes present in the buffer. The application
381 * should keep track of the number of bytes sent and retry the operation until the application sends the bytes in the
382 * buffer. There is no guarantee that the data that is sent appears on the network immediately. To increase network efficiency, the
383 * underlying system may delay the transmission until a significant amount of outgoing data is collected. A successful completion of this
384 * method means that the underlying system has had room to buffer the data for a network send. If it is important for the
385 * application to send every byte to the remote host immediately, use SetSockOpt() (with NET_SOCKET_TCP_NODELAY) of the type
386 * ::NetSocketOptName to enable no delay.
388 result Send(Tizen::Base::ByteBuffer& buffer);
391 * Sends the data to a secure socket of the type NET_SOCKET_TYPE_STREAM.
395 * @return An error code
396 * @param[in] pBuffer The pointer to the buffer containing the data to send
397 * @param[in] length The length of the data in the buffer
398 * @param[out] sentLength The length of the data sent successfully
399 * @exception E_SUCCESS The method is successful.
400 * @exception E_INVALID_SOCKET The secure socket is invalid.
401 * @exception E_INVALID_STATE The secure socket is not in a valid state.
402 * @exception E_UNSUPPORTED_OPTION The specified parameters are not supported.
403 * @exception E_INVALID_ARG A specified input parameter is invalid.
404 * @exception E_WOULD_BLOCK A non-blocking secure socket operation cannot be completed immediately.
405 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
406 * @exception E_CONNECTION_FAILED The secure socket is not connected.
407 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
408 * @exception E_OUT_OF_MEMORY The memory is insufficient.
409 * @exception E_SYSTEM A system error has occurred.
410 * @remarks This method sends the data to the remote host specified in the Connect() method.
411 * This method sends the data in the buffer of length @c length, starting from the current position of the buffer.
412 * In the blocking mode, if space is not available in the send queue, the secure socket blocks until space becomes available.
413 * In the non-blocking mode, this method returns the error E_WOULD_BLOCK.
414 * This method may complete successfully even if it sends less bytes than the number of bytes
415 * in the buffer. The application should keep track of the number of bytes sent
416 * and retry the operation until the application sends the bytes in the buffer.
417 * There is no guarantee that the data that is sent appears on the network immediately.
418 * To increase the network efficiency, the underlying system may delay the transmission until a significant amount
419 * of outgoing data is collected. A successful completion of this method means that the underlying
420 * system has had room to buffer the data for a network send.
421 * If it is important for the application to send every byte to the remote host immediately,
422 * use SetSockOpt() (with NET_SOCKET_TCP_NODELAY) of the type ::NetSocketOptName to enable no delay.
424 result Send(void* pBuffer, int length, int& sentLength);
427 * Receives the data from a secure socket of the type NET_SOCKET_TYPE_STREAM.
431 * @return An error code
432 * @param[out] buffer An instance of Tizen::Base::ByteBuffer that is the storage location for the received data
433 * @exception E_SUCCESS The method is successful.
434 * @exception E_INVALID_SOCKET The secure socket is invalid.
435 * @exception E_INVALID_STATE The secure socket is not in a valid state.
436 * @exception E_UNSUPPORTED_OPTION The specified parameter is not supported.
437 * @exception E_INVALID_ARG The specified input parameter is invalid.
438 * @exception E_WOULD_BLOCK A non-blocking secure socket operation cannot be completed immediately.
439 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
440 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
441 * @exception E_IN_PROGRESS A previous request is in progress.
442 * @exception E_OUT_OF_MEMORY The memory is insufficient.
443 * @exception E_SYSTEM A system error has occurred.
444 * @remarks This method copies the data into the @c buffer parameter, starting from the current position of the buffer.
445 * After the operation, the position of the buffer is incremented by the number of bytes successfully received.
446 * The new position cannot be larger than the original limit. This method can be called from connection-oriented sockets only.
447 * If there is no data at the secure socket in the blocking mode,
448 * this method blocks until the data arrives. If the secure socket is in the non-blocking mode,
449 * the error E_WOULD_BLOCK is returned.
452 result Receive(Tizen::Base::ByteBuffer& buffer) const;
455 * Receives the data from a secure socket of the type NET_SOCKET_TYPE_STREAM.
459 * @return An error code
460 * @param[out] pBuffer The pointer to the buffer that is the storage location for the received data
461 * @param[in] length The length of the data in the buffer
462 * @param[out] rcvdLength The length of the data that is received successfully
463 * @exception E_SUCCESS The method is successful.
464 * @exception E_INVALID_SOCKET The secure socket is invalid.
465 * @exception E_INVALID_STATE The secure socket is not in a valid state.
466 * @exception E_UNSUPPORTED_OPTION The specified parameters are not supported.
467 * @exception E_INVALID_ARG A specified input parameter is invalid.
468 * @exception E_WOULD_BLOCK A non-blocking secure socket operation cannot be completed immediately.
469 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
470 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
471 * @exception E_IN_PROGRESS A previous request is in progress.
472 * @exception E_OUT_OF_MEMORY The memory is insufficient.
473 * @exception E_SYSTEM A system error has occurred.
474 * @remarks This method copies the data into the buffer of length @c length, starting from the current position of the buffer.
475 * This method can be called from the connection-oriented sockets only.
476 * If there is no data at the secure socket in the blocking mode,
477 * this method blocks until the data arrives. If the secure socket is in the non-blocking mode,
478 * the error E_WOULD_BLOCK is returned.
480 result Receive(void* pBuffer, int length, int& rcvdLength) const;
483 * Binds the secure socket to a local address.
487 * @privilege %http://tizen.org/privilege/socket
489 * @return An error code
490 * @param[in] localEndPoint The local NetEndPoint to associate with the secure socket
491 * @exception E_SUCCESS The method is successful.
492 * @exception E_INVALID_SOCKET The secure socket is invalid.
493 * @exception E_INVALID_STATE The secure socket is not in a valid state.
494 * @exception E_UNSUPPORTED_OPTION The specified parameter is not supported.
495 * @exception E_INVALID_ARG The specified input parameter is invalid.
496 * @exception E_ALREADY_BOUND The address is already in use.
497 * @exception E_OUT_OF_MEMORY The memory is insufficient.
498 * @exception E_SYSTEM A system error has occurred.
499 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
500 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
501 * @remarks Use this method if a specific local endpoint should be used.
502 * This method can be used on both the connectionless and connection-oriented protocols.
503 * For connection-oriented sockets, this method need not be called
504 * before using the Connect() method, unless a specific local endpoint needs to be used.
505 * This method must be called before the Listen() method.
507 result Bind(const Tizen::Net::NetEndPoint& localEndPoint);
510 * Places the secure socket in a listening state.
514 * @privilege %http://tizen.org/privilege/socket
516 * @return An error code
517 * @param[in] backLog The maximum length of the pending connections queue
518 * @exception E_SUCCESS The method is successful.
519 * @exception E_WOULD_BLOCK A non-blocking secure socket operation cannot be completed immediately.
520 * @exception E_INVALID_SOCKET The secure socket is invalid.
521 * @exception E_INVALID_STATE The secure socket is not in a valid state.
522 * @exception E_UNSUPPORTED_OPTION The specified parameter is not supported.
523 * @exception E_UNSUPPORTED_PROTOCOL The protocol is not supported.
524 * @exception E_ALREADY_CONNECTED The secure socket is already connected.
525 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
526 * @exception E_OUT_OF_MEMORY The memory is insufficient.
527 * @exception E_SYSTEM A system error has occurred.
528 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
529 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
530 * @remarks This method causes a connection-oriented socket to listen for
531 * the incoming connection attempts. The @c backlog parameter specifies
532 * the number of incoming connections that can be queued for acceptance.
533 * The Bind() method must be called before calling this method.
535 result Listen(int backLog);
538 * Accepts an incoming connection. @n
539 * The %AcceptN() method extracts the first connection from the queue of pending connections, and
540 * creates a new secure socket with the same socket type, protocol type, and protocol family
541 * as the listening secure socket.
545 * @privilege %http://tizen.org/privilege/socket
547 * @return A new secure socket for a newly created connection with the same socket type, protocol type, and protocol family, @n
548 * else @c null if an error occurs
549 * @exception E_SUCCESS The method is successful.
550 * @exception E_WOULD_BLOCK A non-blocking secure socket operation cannot be completed immediately.
551 * @exception E_INVALID_CERTIFICATE The server certificate verification has failed on client.
552 * @exception E_CERTIFICATE_VERIFICATION_FAILED The client certificate verification has failed.
553 * @exception E_INVALID_SOCKET The secure socket is invalid.
554 * @exception E_INVALID_STATE The secure socket is not in a valid state.
555 * @exception E_UNSUPPORTED_OPTION This operation is not supported for this socket.
556 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
557 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
558 * @exception E_OUT_OF_MEMORY The memory is insufficient.
559 * @exception E_SYSTEM A system error has occurred.
560 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
561 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
562 * @remarks Before calling this method, the Listen() method must be called first
563 * to listen for and queue the incoming connection requests.
564 * In the blocking mode, this method blocks until an incoming connection attempt
565 * is queued. After accepting a connection, the original socket
566 * continues queuing the incoming connection requests until it is closed.
567 * Note that if no connection is pending in the queue and the secure socket is in the blocking mode,
568 * this method blocks until a new connection arrives. If the secure socket is in the non-blocking mode,
569 * the E_WOULD_BLOCK exception is thrown. The specific error code can be accessed using the GetLastResult() method.
571 SecureSocket* AcceptN(void) const;
574 * Executes the specified command on the socket.
578 * @privilege %http://tizen.org/privilege/socket
580 * @return An error code
581 * @param[in] cmd The command to execute on the secure socket
582 * @param[in,out] value The value of the IOCTL command
583 * @exception E_SUCCESS The method is successful.
584 * @exception E_INVALID_SOCKET The secure socket is invalid.
585 * @exception E_UNSUPPORTED_OPTION The specified parameters are not supported.
586 * @exception E_INVALID_ARG A specified input parameter is invalid.
587 * @exception E_INVALID_STATE The secure socket is not in a valid state.
588 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
589 * @exception E_OUT_OF_MEMORY The memory is insufficient.
590 * @exception E_SYSTEM A system error has occurred.
591 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
592 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
593 * @remarks This method manipulates the underlying device parameters of the secure socket descriptors. @n@n
594 * The NET_SOCKET_FIONBIO option is used for setting the non-blocking/blocking mode on a secure socket.
595 * Set the value to zero for enabling the blocking mode, or to a non-zero value for enabling the non-blocking mode.
596 * When a secure socket is created, by default, it operates in the non-blocking mode and the blocking mode is disabled.
599 result Ioctl(NetSocketIoctlCmd cmd, unsigned long& value) const;
602 * Sets the secure socket to the asynchronous mode by a specified message to the specified event handler when the secure socket events occur.
606 * @return An error code
607 * @param[in] socketEventType The secure socket events of ::NetSocketEventType @n
608 * Multiple events can be combined using the bitwise "|" operator.
609 * @exception E_SUCCESS The method is successful.
610 * @exception E_INVALID_SOCKET The secure socket is invalid.
611 * @exception E_INVALID_STATE The secure socket is not in a valid state.
612 * @exception E_INVALID_ARG The specified input parameter is invalid.
613 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
614 * @exception E_TIMEOUT An attempt to connect to the server has timed out.
616 * The following example demonstrates how to use the %AsyncSelectByListener() method to set a secure socket to the asynchronous mode.
619 * result res = E_SUCCESS;
621 * // Creates the secure socket.
622 * SecureSocket* pClientSocket = new SecureSocket();
623 * res = pClientSocket->Construct(NET_SOCKET_AF_IPV4,NET_SOCKET_TYPE_STREAM,NET_SOCKET_PROTOCOL_SSL);
626 * MySocketSecureClientListener* pSockClientListener = new MySocketSecureClientListener();
627 * res = pClientSocket->AddSecureSocketListener(*pSockClientListener);
629 * // Selects asynchronous event (non-blocking mode).
630 * res = pClientSocket->AsyncSelectByListener(NET_SOCKET_EVENT_CONNECT| NET_SOCKET_EVENT_CLOSE);
632 * // Creates peer endpoint.
633 * Ip4Address peerAddr("XXX.XXX.XXX.XXX"); //Secure socket server address.
634 * unsigned short peerPort = YYY; // Port
635 * NetEndPoint* pPeerEndPoint = new NetEndPoint(peerAddr, peerPort);
637 * // Connects the secure socket.
638 * res = pClientSocket->Connect(*pPeerEndPoint);
641 result AsyncSelectByListener(unsigned long socketEventType);
644 * Adds a listener to the secure socket. @n
645 * The listener can listen to the events when they are fired.
649 * @return An error code
650 * @param[in] listener A reference to ISecureSocketEventListener
651 * @exception E_SUCCESS The method is successful.
652 * @exception E_OUT_OF_MEMORY The memory is insufficient.
653 * @exception E_INVALID_SOCKET The secure socket is invalid.
654 * @exception E_INVALID_STATE The associated secure socket is not in a valid state.
655 * @exception E_SYSTEM A system error has occurred.
656 * @exception E_OBJ_ALREADY_EXIST The listener is already added.
657 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation, @n
658 * because the caller thread is a worker thread.
660 result AddSecureSocketListener(ISecureSocketEventListener& listener);
663 * Removes a listener from the secure socket.
667 * @return An error code
668 * @param[in] listener A reference to ISecureSocketEventListener
669 * @exception E_SUCCESS The method is successful.
670 * @exception E_OBJ_NOT_FOUND The specified object is not found within the indicated range.
671 * @exception E_INVALID_SOCKET The secure socket is invalid.
672 * @exception E_INVALID_STATE The associated secure socket is not in a valid state.
673 * @exception E_SYSTEM A system error has occurred.
675 result RemoveSecureSocketListener(ISecureSocketEventListener& listener);
678 * Gets an option of the secure socket.
682 * @return An error code
683 * @param[in] optionLevel A ::NetSocketOptLevel value
684 * @param[in] optionName A ::NetSocketOptName value
685 * @param[out] optionValue The integer to receive the option setting
686 * @exception E_SUCCESS The method is successful.
687 * @exception E_INVALID_SOCKET The secure socket is invalid.
688 * @exception E_INIT_FAILED The secure socket is not initialized.
689 * @exception E_UNSUPPORTED_OPTION The specified parameters are not supported.
690 * @exception E_INVALID_ARG A specified input parameter is invalid.
691 * @exception E_INVALID_STATE The secure socket is not in a valid state.
692 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
693 * @exception E_IN_PROGRESS A previous request is in progress.
694 * @exception E_CONNECTION_FAILED The secure socket is not connected.
695 * @exception E_SYSTEM A system error has occurred.
696 * @remarks The secure socket options determine the behavior of the current secure socket.
697 * Upon the successful completion of this method, the integer variable specified
698 * by the @c optionValue parameter contains the value of the specified secure socket option.
699 * For an option with a bool data type, a non-zero value is returned if the option is enabled. Otherwise,
700 * a zero value is returned. For an option with an integer data type, the method returns the appropriate value.
701 * The secure socket options are grouped by the level of protocol support.
702 * Listed below are the various secure socket options that can be obtained using this overload. These options are
703 * grouped by the appropriate NetSocketOptLevel.
704 * If any of these options are to be obtained, use the appropriate %NetSocketOptLevel for the @c optionLevel parameter. The option that
705 * is chosen, must be specified in the @c optionName parameter. To set the current value of some of the listed options, use the
706 * SetSockOpt() method. @n@n
707 * The NET_SOCKET_SOL_SOCKET options that can be set using this overloaded method are: @n
708 * NET_SOCKET_SO_SSLVERSION: Gets the SSL version of the secure socket. @n
709 * NET_SOCKET_SO_SSLCIPHERSUITEID: Gets the SSL cipher suite ID of the secure socket.
712 result GetSockOpt(NetSocketOptLevel optionLevel, NetSocketOptName optionName, int& optionValue) const;
715 * Changes an option of the secure socket.
719 * @return An error code
720 * @param[in] optionLevel A ::NetSocketOptLevel value
721 * @param[in] optionName A ::NetSocketOptName value
722 * @param[in] optionValue The option value
723 * @exception E_SUCCESS The method is successful.
724 * @exception E_INVALID_SOCKET The secure socket is invalid.
725 * @exception E_INIT_FAILED The secure socket is not initialized.
726 * @exception E_UNSUPPORTED_OPTION The specified parameters are not supported.
727 * @exception E_INVALID_ARG A specified input parameter is invalid.
728 * @exception E_INVALID_STATE The secure socket is not in a valid state.
729 * @exception E_NETWORK_UNAVAILABLE The network is unavailable.
730 * @exception E_IN_PROGRESS A previous request is in progress.
731 * @exception E_CONNECTION_FAILED The secure socket is not connected.
732 * @exception E_SYSTEM A system error has occurred.
733 * @remarks This method is used to change the value of the option specified by the @c optionName parameter.
734 * The secure socket options determine the behavior of the current secure socket. For an option with a bool data type,
735 * specify a non-zero value to enable the option, and a zero value to disable the option.
736 * For an option with an integer data type, specify the appropriate value. The secure socket options are grouped
737 * by the level of protocol support.
738 * Listed below are the various secure socket options that can be set using this overload. These options are
739 * grouped by the appropriate NetSocketOptLevel. If any of these options are to be set, use the appropriate %NetSocketOptLevel for the
740 * @c optionLevel parameter. The chosen option must be specified in the @c optionName parameter.
741 * To get the current value of some of the options listed, use the GetSockOpt() method. @n@n
742 * NET_SOCKET_SO_SSLVERSION: To enable the SSL version of the secure socket. @n
743 * NET_SOCKET_SO_SSLCIPHERSUITEID: To set the SSL cipher suite ID of the secure socket. @n
744 * NET_SOCKET_SO_SSLCERTVERIFY: To disable server certificate verification on the secure client socket. @n
745 * NET_SOCKET_SO_SSLCLIENTCERTVERIFY: To enable client certificate verification on the secure server socket. @n
746 * 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
748 result SetSockOpt(NetSocketOptLevel optionLevel, NetSocketOptName optionName, int optionValue);
752 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
754 * @param[in] rhs An instance of %SecureSocket
756 SecureSocket(const SecureSocket& rhs);
759 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
761 * @return A reference to this instance
762 * @param[in] rhs An instance of %SecureSocket
764 SecureSocket& operator =(const SecureSocket& rhs);
767 _SecureSocketImpl* __pSecureSocketImpl;
769 friend class _SecureSocketImpl;
772 } } } // Tizen::Net::Sockets
773 #endif // _FNET_SOCK_SECURE_SOCKET_H_