Home » U++ Library support » U++ Library : Other (not classified elsewhere) » HTTPS?
HTTPS? [message #6849] |
Fri, 01 December 2006 13:59 |
zsolt
Messages: 698 Registered: December 2005 Location: Budapest, Hungary
|
Contributor |
|
|
Is it possible in U++, to get data from secure HTTP servers?
|
|
|
|
|
|
|
|
|
|
|
|
Re: HTTPS? [message #6864 is a reply to message #6861] |
Fri, 01 December 2006 20:36 |
rylek
Messages: 79 Registered: November 2005
|
Member |
|
|
Hi!
This is a short snippet of code I use in a commercial application to get the SSL sockets up and running. I suppose it solves a very specific situation but I hope you'll be able to use it at least to stumble upon some ideas.
Regards
Tomas
socket.Clear();
if(encrypt) {
if(!ssl_context) {
ssl_context = new SSLContext;
if(!ssl_context->Create(SSLv3_client_method())) {
WhenConsole(NFormat("Error creating SSL context: %s", SSLGetLastError()), 0);
return false;
}
if(!IsNull(certificate_file) || !IsNull(private_key_file)) {
String cdata = LoadFile(certificate_file);
if(IsNull(cdata)) {
WhenConsole(NFormat("Error reading certificate file '%s'.", certificate_file), 0);
return false;
}
String pdata = LoadFile(private_key_file);
if(IsNull(pdata)) {
WhenConsole(NFormat("Error reading private key file '%s'.", private_key_file), 0);
return false;
}
if(!ssl_context->UseCertificate(cdata, pdata)) {
WhenConsole(NFormat("Invalid certificate '%s' / private key '%s': %s",
certificate_file, private_key_file, SSLGetLastError()), 0);
return false;
}
}
}
SSLClientSocket(socket, *ssl_context, host, port, true, NULL, timeout_msecs);
}
else
ClientSocket(socket, host, port, true, NULL, timeout_msecs);
if(!socket.IsOpen()) {
WhenConsole(NFormat(t_("Error opening socket %s:%d: %s\n"), host, port, Socket::GetErrorText()), 0);
return false;
}
|
|
|
Re: HTTPS? [message #6865 is a reply to message #6863] |
Fri, 01 December 2006 20:43 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
rylek wrote on Fri, 01 December 2006 14:29 | Hello,
the 'problem' with Socket implementing pick semantics is honestly more about getting Mirek to like it than a problem with the socket class as such. From the code point of view I believe the current implementation with a separate interface wrapper object and its internal socket handler object is most logical as the sockets use a completely different access interface than SSL sockets. Mixing the implementation of the two together would work well if the Open / OpenSSL methods did only some initialization of setup stuff, which they don't. The only result would be that practically every access method would have to begin with an if() distinguishing the two interfaces and wanting the code buildable without SSL would require tens of #if-#endif pairs to mask off all these SSL variants.
|
No, that is not why I am suggesting. In fact, the only change that I suggest is to transform current functions
bool ServerSocket(Socket& socket, int port, bool nodelay = true, int listen_count = 5, bool is_blocking = true);
bool ClientSocket(Socket& socket, const char *host, int port, bool nodelay = true, dword *my_addr = NULL, int timeout = DEFAULT_CONNECT_TIMEOUT, bool is_blocking = true);
bool SSLServerSocket(Socket& socket, SSLContext& ssl_context, int port, bool nodelay = true, int listen_count = 5, bool is_blocking = true);
bool SSLClientSocket(Socket& socket, SSLContext& ssl_context, const char *host, int port, bool nodelay = true, dword *my_addr = NULL, int timeout = DEFAULT_CONNECT_TIMEOUT, bool is_blocking = true);
into methods, which would eliminate the need for exposing internal Data in Socket contructor interface. (and also would activate Assist++ hints
In fact, for backwards compatibility, I would even retain both them and that constructor...
Implementation could be as trivial as:
bool Socket::OpenClient(const char *host, int port, bool nodelay = true, dword *my_addr = NULL, int timeout = DEFAULT_CONNECT_TIMEOUT, bool is_blocking = true) {
ClientSocket(*this, host, port, nodelay, my_addr, timeout, is_blocking);
}
Mirek
[Updated on: Fri, 01 December 2006 20:45] Report message to a moderator
|
|
|
|
|
|
Re: HTTPS? [message #22962 is a reply to message #22942] |
Wed, 02 September 2009 23:18 |
rylek
Messages: 79 Registered: November 2005
|
Member |
|
|
Hello!
So far I've always downloaded the OpenSSL source package from www.openssl.org and used it to build the libraries. Remember that normally it's easier to link the SSL libraries statically to the final application because then you don't have to worry about search paths or different versions of the (very frequently used) SSL libraries; in such case you would need no dll's at all, only the lib's. However, all three versions (DLL version, single-threaded and multi-threaded statically linked version) can be built using some options of the OpenSSL build script. Remember that in order to build OpenSSL you need three main things:
1) working installation of a compiler, I built it under MSC but MinGW should be fine
2) an assembler installed (MASM or NASM)
3) the Perl interpreter; this can be downloaded and installed separately, certain software packages install it automatically (like the Oracle server).
After you manage to make the build scripts produce the "libeay32.lib" and "ssleay32.lib" in the out32 / out32dll / out32mt output directories, to complete OpenSSL "installation" under U++ it should be sufficient to add the include path (<openssl installation directory>/include) and the library path (out32 or variants) to the respective path lists in your desired build method definition.
If you fail to complete the above described process, please write how far you managed to get and I'll try to describe the relevant step in greater detail.
Regards
Tomas
|
|
|
Goto Forum:
Current Time: Sat May 04 12:36:17 CEST 2024
Total time taken to generate the page: 0.03224 seconds
|