Get closer to actually connecting, add hitting enter on text entry
This commit is contained in:
parent
1af0632037
commit
4ff4d4d93d
3 changed files with 105 additions and 7 deletions
99
main.cpp
99
main.cpp
|
@ -103,15 +103,106 @@ int main(int argc, char *argv[]) {
|
|||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
PRFileDesc *tcpSocket = PR_NewTCPSocket();
|
||||
theAddr.inet.port = 443;
|
||||
PRFileDesc *tcpSocket = PR_OpenTCPSocket(PR_AF_INET6);
|
||||
PRFileDesc *model = PR_NewTCPSocket();
|
||||
theAddr.ipv6.port = 443;
|
||||
theAddr.raw.family = PR_AF_INET6;
|
||||
PRFileDesc *nssSocket;
|
||||
SSL_ImportFD(NULL, tcpSocket);
|
||||
PRFileDesc *sslModel = SSL_ImportFD(NULL, model);
|
||||
|
||||
// Set SSL options
|
||||
if(SSL_OptionSet(sslModel, SSL_ENABLE_SSL2, PR_FALSE) != SECSuccess) {
|
||||
const PRErrorCode err = PR_GetError();
|
||||
fprintf(stderr, "Error disabling SSLv2, code %d: %s\n", err, PR_ErrorToName(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if(SSL_OptionSet(sslModel, SSL_V2_COMPATIBLE_HELLO, PR_FALSE) != SECSuccess) {
|
||||
const PRErrorCode err = PR_GetError();
|
||||
fprintf(stderr, "Error disabling SSLv2 compatible hello, code %d: %s\n", err, PR_ErrorToName(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if(SSL_OptionSet(sslModel, SSL_ENABLE_SSL3, PR_FALSE) != SECSuccess) {
|
||||
const PRErrorCode err = PR_GetError();
|
||||
fprintf(stderr, "Error disabling SSLv3, code %d: %s\n", err, PR_ErrorToName(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if(SSL_OptionSet(sslModel, SSL_ENABLE_TLS, PR_TRUE) != SECSuccess) {
|
||||
const PRErrorCode err = PR_GetError();
|
||||
fprintf(stderr, "Error enabling TLS, code %d: %s\n", err, PR_ErrorToName(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Open base TCP connection
|
||||
if(PR_Connect(tcpSocket, &theAddr, PR_INTERVAL_NO_TIMEOUT) != PR_SUCCESS) {
|
||||
const PRErrorCode err = PR_GetError();
|
||||
fprintf(stderr, "Error opening TCP connection, code %d: %s\n", err, PR_ErrorToName(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Wrap TCP connection with SSL layer
|
||||
nssSocket = SSL_ImportFD(sslModel, tcpSocket);
|
||||
if(nssSocket == nullptr) {
|
||||
const PRErrorCode err = PR_GetError();
|
||||
fprintf(stderr, "Error importing TCP Socket to NSS, code %d: %s\n", err, PR_ErrorToName(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
PR_Close(model);
|
||||
|
||||
// Do the handshake
|
||||
if(SSL_ResetHandshake(nssSocket, PR_FALSE) != SECSuccess) {
|
||||
const PRErrorCode err = PR_GetError();
|
||||
fprintf(stderr, "Failed resetting handshake, code %d: %s\n", err, PR_ErrorToName(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if(SSL_SetURL(nssSocket, "buyvm.theoks.net") != SECSuccess) {
|
||||
const PRErrorCode err = PR_GetError();
|
||||
fprintf(stderr, "Error setting domain for connection, code %d: %s\n", err, PR_ErrorToName(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if(SSL_ForceHandshake(nssSocket) != SECSuccess) {
|
||||
const PRErrorCode err = PR_GetError();
|
||||
fprintf(stderr, "Error forcing handshake, code %d: %s\n", err, PR_ErrorToName(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ui *uiInstance = new ui(argc, argv);
|
||||
|
||||
char netBuf[8192];
|
||||
|
||||
// TEMP: Retreiving test file from HTTP daemon w/ TLS
|
||||
// Send the request
|
||||
snprintf(netBuf, sizeof(netBuf), "GET /junk/testfile.txt HTTP/1.0\r\nHost: buyvm.theoks.net\r\nUser-Agent: oksirc-testing\r\n\r\n");
|
||||
PRInt32 ret = PR_Write(nssSocket, netBuf, strlen(netBuf));
|
||||
if(ret < 0) {
|
||||
const PRErrorCode err = PR_GetError();
|
||||
fprintf(stderr, "Error writing data to socket, code %d: %s\n", err, PR_ErrorToName(err));
|
||||
uiInstance->mainLog->appendPlainText("Error writing data to socket, see stderr.");
|
||||
}
|
||||
|
||||
// Get the response
|
||||
ret = PR_Read(nssSocket, netBuf, sizeof(netBuf));
|
||||
if(ret < 0) {
|
||||
const PRErrorCode err = PR_GetError();
|
||||
fprintf(stderr, "Error reading data from socket, code %d: %s\n", err, PR_ErrorToName(err));
|
||||
uiInstance->mainLog->appendPlainText("Error writing data from socket, see stderr.");
|
||||
} else {
|
||||
uiInstance->mainLog->appendPlainText(netBuf);
|
||||
}
|
||||
|
||||
if(PR_Shutdown(nssSocket, PR_SHUTDOWN_BOTH) != PR_SUCCESS) {
|
||||
const PRErrorCode err = PR_GetError();
|
||||
fprintf(stderr, "Error shutting down socket, code %d: %s\n", err, PR_ErrorToName(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
PR_Close(nssSocket);
|
||||
|
||||
char messageBuf[1024];
|
||||
sprintf(messageBuf, "Found IP Address: %s", ipString);
|
||||
uiInstance->mainLog->appendPlainText(messageBuf);
|
||||
|
|
13
ui.cpp
13
ui.cpp
|
@ -11,6 +11,7 @@ ui::ui(int argc, char **argv) {
|
|||
textEntry = new QLineEdit();
|
||||
QPushButton *sendButton = new QPushButton(QApplication::translate("send", "Send"));
|
||||
QObject::connect(sendButton, &QPushButton::clicked, this, &ui::sendButtonClicked);
|
||||
QObject::connect(textEntry, &QLineEdit::returnPressed, this, &ui::returnOnTextEntry);
|
||||
|
||||
QHBoxLayout *entryLineLayout = new QHBoxLayout();
|
||||
entryLineLayout->addWidget(textEntry);
|
||||
|
@ -28,8 +29,14 @@ int ui::exec() {
|
|||
return app->exec();
|
||||
}
|
||||
|
||||
void ui::sendButtonClicked(bool checked) {
|
||||
this->mainLog->appendPlainText("Send button clicked!");
|
||||
this->mainLog->appendPlainText(textEntry->text());
|
||||
void ui::returnOnTextEntry() {
|
||||
mainLog->appendPlainText("Return key pressed!");
|
||||
mainLog->appendPlainText(textEntry->text());
|
||||
textEntry->clear();
|
||||
}
|
||||
|
||||
void ui::sendButtonClicked(bool checked) {
|
||||
mainLog->appendPlainText("Send button clicked!");
|
||||
mainLog->appendPlainText(textEntry->text());
|
||||
textEntry->clear();
|
||||
}
|
2
ui.h
2
ui.h
|
@ -9,7 +9,7 @@ public:
|
|||
|
||||
int exec();
|
||||
void sendButtonClicked(bool);
|
||||
|
||||
void returnOnTextEntry();
|
||||
|
||||
QPlainTextEdit *mainLog;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue