Got DNS working, started attempt at connecting with SSL

This commit is contained in:
Darren VanBuren 2017-07-07 15:53:39 -07:00
parent c422d26a63
commit 88f29def56
2 changed files with 37 additions and 5 deletions

View file

@ -4,6 +4,8 @@
// NSPR include files
#include <prerror.h>
#include <prinit.h>
#include <prnetdb.h>
#include <nspr.h>
// NSS include files
#include <nss.h>
@ -11,6 +13,7 @@
#include <secmod.h>
#include <ssl.h>
#include <sslproto.h>
#include <prio.h>
// PK11 Password Function typedef
typedef char *(*PK11PasswordFunc)(
@ -18,10 +21,11 @@ typedef char *(*PK11PasswordFunc)(
PRBool retry,
void *arg);
int main(int argc, char* argv[]) {
// NSPR Init
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
// NSS Init
NSSInitContext *const nssContext =
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);
if(builtInRootsMod == NULL || !builtInRootsMod->loaded) {
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));
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");
app.init(argc, argv);