Got DNS working, started attempt at connecting with SSL
This commit is contained in:
parent
c422d26a63
commit
88f29def56
2 changed files with 37 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
||||||
cmake_minimum_required(VERSION 3.7)
|
cmake_minimum_required(VERSION 3.7)
|
||||||
project(NSPRFun)
|
project(oksirc)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
|
||||||
|
@ -12,6 +12,6 @@ find_package(FOX REQUIRED)
|
||||||
include_directories(${NSPR_INCLUDE_DIRS} ${NSS_INCLUDE_DIRS} ${FOX_INCLUDE_DIR})
|
include_directories(${NSPR_INCLUDE_DIRS} ${NSS_INCLUDE_DIRS} ${FOX_INCLUDE_DIR})
|
||||||
|
|
||||||
set(SOURCE_FILES main.cpp)
|
set(SOURCE_FILES main.cpp)
|
||||||
add_executable(NSPRFun ${SOURCE_FILES})
|
add_executable(oksirc ${SOURCE_FILES})
|
||||||
|
|
||||||
target_link_libraries(NSPRFun ${NSPR_LIBRARIES} ${NSS_LIBRARIES} ${FOX_LIBRARY})
|
target_link_libraries(oksirc ${NSPR_LIBRARIES} ${NSS_LIBRARIES} ${FOX_LIBRARY})
|
36
main.cpp
36
main.cpp
|
@ -4,6 +4,8 @@
|
||||||
// NSPR include files
|
// NSPR include files
|
||||||
#include <prerror.h>
|
#include <prerror.h>
|
||||||
#include <prinit.h>
|
#include <prinit.h>
|
||||||
|
#include <prnetdb.h>
|
||||||
|
#include <nspr.h>
|
||||||
|
|
||||||
// NSS include files
|
// NSS include files
|
||||||
#include <nss.h>
|
#include <nss.h>
|
||||||
|
@ -11,6 +13,7 @@
|
||||||
#include <secmod.h>
|
#include <secmod.h>
|
||||||
#include <ssl.h>
|
#include <ssl.h>
|
||||||
#include <sslproto.h>
|
#include <sslproto.h>
|
||||||
|
#include <prio.h>
|
||||||
|
|
||||||
// PK11 Password Function typedef
|
// PK11 Password Function typedef
|
||||||
typedef char *(*PK11PasswordFunc)(
|
typedef char *(*PK11PasswordFunc)(
|
||||||
|
@ -18,10 +21,11 @@ typedef char *(*PK11PasswordFunc)(
|
||||||
PRBool retry,
|
PRBool retry,
|
||||||
void *arg);
|
void *arg);
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
// NSPR Init
|
// NSPR Init
|
||||||
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
|
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
|
||||||
|
|
||||||
|
// NSS Init
|
||||||
NSSInitContext *const nssContext =
|
NSSInitContext *const nssContext =
|
||||||
NSS_InitContext("sql:/etc/pki/nssdb", "", "", "", NULL, NSS_INIT_READONLY | NSS_INIT_PK11RELOAD);
|
NSS_InitContext("sql:/etc/pki/nssdb", "", "", "", NULL, NSS_INIT_READONLY | NSS_INIT_PK11RELOAD);
|
||||||
|
|
||||||
|
@ -69,11 +73,39 @@ int main(int argc, char* argv[]) {
|
||||||
SECMODModule *builtInRootsMod = SECMOD_LoadUserModule(module_name, NULL, PR_FALSE);
|
SECMODModule *builtInRootsMod = SECMOD_LoadUserModule(module_name, NULL, PR_FALSE);
|
||||||
if(builtInRootsMod == NULL || !builtInRootsMod->loaded) {
|
if(builtInRootsMod == NULL || !builtInRootsMod->loaded) {
|
||||||
const PRErrorCode err = PR_GetError();
|
const PRErrorCode err = PR_GetError();
|
||||||
fprintf(stderr, "Error: Loading built in roots module failed code %d: %s\n",
|
fprintf(stderr, "Error: Loading built in roots module failed, code %d: %s\n",
|
||||||
err, PR_ErrorToName(err));
|
err, PR_ErrorToName(err));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Attempt to resolve a name.
|
||||||
|
PRAddrInfo *addrInfos = PR_GetAddrInfoByName("buyvm.theoks.net", PR_AF_UNSPEC, PR_AI_ADDRCONFIG);
|
||||||
|
void *iter = nullptr;
|
||||||
|
PRNetAddr firstAddr;
|
||||||
|
PRNetAddr tempAddr;
|
||||||
|
do {
|
||||||
|
iter = PR_EnumerateAddrInfo(iter, addrInfos, 0, &tempAddr);
|
||||||
|
char ipString[80];
|
||||||
|
PRStatus status = PR_NetAddrToString(&tempAddr, ipString, 75);
|
||||||
|
if(status == PR_FAILURE) {
|
||||||
|
const PRErrorCode err = PR_GetError();
|
||||||
|
fprintf(stderr, "Error: Converting PRNetAddr to string %d: %s\n",
|
||||||
|
err, PR_ErrorToName(err));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
printf("Found IP Address: %s\n", ipString);
|
||||||
|
firstAddr = tempAddr;
|
||||||
|
} while(iter);
|
||||||
|
|
||||||
|
PRFileDesc *tcpSocket = PR_NewTCPSocket();
|
||||||
|
firstAddr.inet.port = 443;
|
||||||
|
PRFileDesc *nssSocket;
|
||||||
|
SSL_ImportFD(NULL, tcpSocket);
|
||||||
|
|
||||||
|
char *sendBuf = (char *)PR_MALLOC( 65536 * sizeof(char));
|
||||||
|
char *toSend = (char *) "GET / HTTP/1.0\r\nHost: buyvm.theoks.net\r\nUser-Agent: oksirc_net_test\r\n\r\n";
|
||||||
|
PR_Send(tcpSocket, sendBuf, null, 0, PR_INTERVAL_NO_TIMEOUT);
|
||||||
|
|
||||||
FXApp app("Hello", "FoxTest");
|
FXApp app("Hello", "FoxTest");
|
||||||
app.init(argc, argv);
|
app.init(argc, argv);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue