#include <stdlib.h>
#include <unistd.h>
#include "rpcclt_openapi.h"
#include "proc_util.h"
static void printAppMenu(char *name)
{
printf("Usage: %s <test#> <arg1> <arg2> ... \n", name);
printf("Test 1: Sets admin Mode of the SSL Tunnel server: %s 1 <mode>\n", name);
printf("Test 2: Gets admin mode of SSL Tunnel server: %s 2\n", name);
printf("Test 3: Sets secure port number to listen on for SSLT connections: %s 3 <port>\n", name);
printf("Test 4: Gets secure port number that the SSLT connection is using: %s 4\n", name);
printf("Test 5: Sets SSL Protocol Level to be used by SSL Tunnel codes: %s 5 <protocolId><mode>\n", name);
printf("Test 6: Gets SSL Protocol mode status in use by the SSL Tunnel code: %s 6 <protocolId>\n", name);
printf("Test 7: Sets Soft Timeout (in minutes) for SSLT sessions: %s 7 <timeout>\n", name);
printf("Test 8: Gets SSLT session soft timeout information.(in minutes): %s 8\n", name);
printf("Test 9: Sets SSLT session hard timeout (in hours): %s 9 <timeout>\n", name);
printf("Test 10: Gets SSLT session hard timeout information (in hours): %s 10\n", name);
printf("Test 11: Sets maximum allowable SSLT sessions: %s 11 <maxSession>\n", name);
printf("Test 12: Gets maximum number of SSLT sessions supported: %s 12\n", name);
printf("Test 13: Gets operation mode of SSL Tunnel server: %s 13\n", name);
printf("Test 14: Determine if self-signed server certificate exists: %s 14 <certNum>\n", name);
printf("Test 15: Determine if self-signed server and rootcert certificates exist: %s 15 <certNum>\n", name);
printf("Test 16: Generate a self-signed server certificate for SSL tunnel: %s 16 <certNum><keyLength><commonName>\n", name);
printf(" <orgName><orgUnit><location>\n");
printf(" <state><country><email><days>\n");
printf("Test 17: Remove SSLT certificate: %s 17 <certNum>\n", name);
printf("Test 18: Gets the active certificate for the SSL tunnel: %s 18\n", name);
printf("Test 19: Gets operational active SSL certificate: %s 19 \n", name);
printf("Test 20: Gets status of SSL certificate expiry: %s 20 <certNum>\n", name);
printf("Test 21: Set the active certificate for the SSL tunnel: %s 21 <certNum>\n", name);
printf("Test 22: Check if HTTPS mode is enabled and the certificate is active: %s 22 <certNum>\n", name);
printf("Test 23: Run API sanity checks: %s 23 \n", name);
return;
}
{
uint32_t port;
uint32_t protocolId = 10;
uint32_t timeout;
uint32_t session;
uint32_t certNum;
printf("Testing openapiSsltAdminModeGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
printf("Testing openapiSsltSecurePortGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
printf("Testing openapiSsltProtocolLevelGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 3:(result = %d)\n", result);
printf("Testing openapiSsltSessionSoftTimeOutGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
printf("Testing openapiSsltSessionHardTimeOutGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
printf("Testing openapiSsltNumSessionsGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
printf("Testing openapiSsltOperModeGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
printf("Testing openapiSsltCertificateActiveGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
printf("Testing openapiSsltCertificateOperActiveGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
printf("Testing openapiSsltCertificateExpiryStatusGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 3:(result = %d)\n", result);
printf("Testing openapiSsltCheckHTTPSEnabledAndOperational():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 3:(result = %d)\n", result);
return;
}
{
{
printf("Bad return code trying to sets admin Mode of the SSL Tunnel server. (result = %d)\n", result);
}
else
{
printf(
"Admin mode of SSL Tunnel server is successfully %s\n", (
OPEN_ENABLE == mode) ?
"enabled" :
"disabled");
}
return;
}
{
{
printf("Bad return code trying to gets admin mode of SSL Tunnel server. (result = %d)\n", result);
}
else
{
printf(
"Admin mode of SSL Tunnel server is in %s state\n", (
OPEN_ENABLE == *pMode) ?
"enabled" :
"disabled");
}
return;
}
{
{
printf("Bad return code trying to sets secure port number to listen on for SSLT connections. (result = %d)\n", result);
}
else
{
printf("SSLT connection secure port number is succesfully set\n");
}
return;
}
{
{
printf("Bad return code trying to gets secure port number that the SSLT connection is using. (result = %d)\n", result);
}
else
{
printf("SSLT connection secure port number is %d\n", *pPort);
}
return;
}
{
{
printf("Bad return code trying to sets SSL Protocol Level to be used by SSL Tunnel codes. (result = %d)\n", result);
}
else
{
printf(
"SSL tunnel protocol level admin mode is successfully %s\n", (
OPEN_ENABLE == mode) ?
"enabled" :
"disabled");
}
return;
}
{
{
printf("Bad return code trying to gets SSL Protocol mode status in use by the SSL Tunnel code. (result = %d)\n", result);
}
else
{
printf(
"SSL tunnel protocol level admin mode is in %s state\n", (
OPEN_ENABLE == *pMode) ?
"enabled" :
"disabled");
}
return;
}
{
{
printf("Bad return code trying to sets Soft Timeout (in minutes) for SSLT sessions. (result = %d)\n", result);
}
else
{
printf("SSLT session soft timeout is succesfully set to %d minutes\n", timeout);
}
return;
}
{
{
printf("Bad return code trying to gets SSLT session soft timeout information.(in minutes) (result = %d)\n", result);
}
else
{
printf("SSLT session soft timeout is %d minutes\n", *pTimeout);
}
return;
}
{
{
printf("Bad return code trying to sets SSLT session hard timeout (in hours). (result = %d)\n", result);
}
else
{
printf("SSLT session hard timeout is succesfully set to %d hours\n", timeout);
}
return;
}
{
{
printf("Bad return code trying to gets SSLT session hard timeout information (in hours). (result = %d)\n", result);
}
else
{
printf("SSLT session hard timeout is %d hours\n", *pTimeout);
}
return;
}
{
{
printf("Bad return code trying to sets maximum allowable SSLT sessions. (result = %d)\n", result);
}
else
{
printf("maximum allowable SSLT sessions is succesfully set to %d\n", maxSession);
}
return;
}
{
{
printf("Bad return code trying to gets maximum number of SSLT sessions supported. (result = %d)\n", result);
}
else
{
printf("maximum number of SSLT sessions is %d\n", *pSession);
}
return;
}
{
{
printf("Bad return code trying to gets operation mode of SSL Tunnel server. (result = %d)\n", result);
}
else
{
printf("operation mode of SSL Tunnel server is in %s state\n",
}
return;
}
{
{
printf("Bad return code trying to determine if self-signed server certificate exists. (result = %d)\n", result);
}
else
{
printf("self-signed server certificate %s\n",
}
return;
}
{
{
printf("Bad return code trying to determine if self-signed server and rootcert certificates exist. (result = %d)\n", result);
}
else
{
printf("self-signed server and rootcert certificate %s\n",
}
return;
}
uint32_t certNum, uint32_t keyLength,
char *pCommonName, char *pOrgName,
char *pOrgUnit, char *pLocation,
char *pState, char *pCountry,
char *pEmail, uint32_t days)
{
char cnStr[256] = {0};
open_buffdesc cnBufDesc = {.
pstart = cnStr, .size =
sizeof(cnStr)};
char onStr[256] = {0};
open_buffdesc onBufDesc = {.pstart = onStr, .size =
sizeof(onStr)};
char ouStr[256] = {0};
open_buffdesc ouBufDesc = {.pstart = ouStr, .size =
sizeof(ouStr)};
char locStr[256] = {0};
open_buffdesc locBufDesc = {.pstart = locStr, .size =
sizeof(locStr)};
char stateStr[256] = {0};
open_buffdesc stateBufDesc = {.pstart = stateStr, .size =
sizeof(stateStr)};
char cntryStr[256] = {0};
open_buffdesc cntryBufDesc = {.pstart = cntryStr, .size =
sizeof(cntryStr)};
char emailStr[256] = {0};
open_buffdesc emailBufDesc = {.pstart = emailStr, .size =
sizeof(emailStr)};
strncpy(cnStr, pCommonName, sizeof(cnStr)-1);
cnBufDesc.
size = strlen(cnStr);
strncpy(onStr, pOrgName, sizeof(onStr)-1);
onBufDesc.size = strlen(onStr);
strncpy(ouStr, pOrgUnit, sizeof(ouStr)-1);
ouBufDesc.size = strlen(ouStr);
strncpy(locStr, pLocation, sizeof(locStr)-1);
locBufDesc.size = strlen(locStr);
strncpy(stateStr, pState, sizeof(stateStr)-1);
stateBufDesc.size = strlen(stateStr);
strncpy(cntryStr, pCountry, sizeof(cntryStr)-1);
cntryBufDesc.size = strlen(cntryStr);
strncpy(emailStr, pEmail, sizeof(emailStr)-1);
emailBufDesc.size = strlen(emailStr);
certNum, keyLength,
&cnBufDesc, &onBufDesc,
&ouBufDesc, &locBufDesc,
&stateBufDesc, &cntryBufDesc,
&emailBufDesc, days)))
{
printf("Bad return code trying to generate a self-signed server certificate for SSL tunnel. (result = %d)\n", result);
}
else
{
printf("self-signed server certificate for SSL tunnel is succesfully generated.\n");
}
return;
}
{
{
printf("Bad return code trying to remove SSLT certificate. (result = %d)\n", result);
}
else
{
printf("SSLT certificate %d is removed.\n", certNum);
}
return;
}
{
{
printf("Bad return code trying to gets the active certificate for the SSL tunnel. (result = %d)\n", result);
}
else
{
printf("Active SSL tunnel certificate is %d.\n", *pCertNum);
}
return;
}
{
{
printf("Bad return code trying to gets operational active SSL certificate. (result = %d)\n", result);
}
else
{
printf("Operational active SSL tunnel certificate is %d.\n", *pCertNum);
}
return;
}
{
{
printf("Bad return code trying to gets status of SSL certificate expiry. (result = %d)\n", result);
}
else
{
printf(
"SSL certificate is %s.\n", (
OPEN_TRUE == *pIsExpired) ?
"expired" :
"active");
}
return;
}
{
{
printf("Bad return code trying to set the active certificate for the SSL tunnel. (result = %d)\n", result);
}
else
{
printf("SSLT certificate %d is set to active.\n", certNum);
}
return;
}
{
{
printf("Bad return code trying to check if HTTPS mode is enabled and the certificate is active. (result = %d)\n", result);
}
else
{
printf("HTTPS mode and certicate is %s\n",
(
OPEN_TRUE == *pIsHttpModeEnabled) ?
"active" :
"in-active");
}
return;
}
int main(int argc, char **argv)
{
uint32_t testNum;
char switch_os_revision_string[100];
int show_help = 1;
uint32_t port;
uint32_t protocolId;
uint32_t timeout;
uint32_t session;
uint32_t certNum;
uint32_t recvMode;
uint32_t keyLength;
uint32_t days;
if (argc < 2)
{
printAppMenu(argv[0]);
return -1;
}
testNum = atoi(argv[1]);
l7proc_crashlog_register();
{
printf("\nFailed to initialize RPC to OpEN. Exiting (result = %d)\n", result);
return -1;
}
{
sleep(1);
}
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Starting sslt API example application");
printf("\n");
switch_os_revision.pstart = switch_os_revision_string;
switch_os_revision.size = sizeof(switch_os_revision_string);
printf("Network OS version = %s\n", switch_os_revision_string);
else
printf("Network OS version retrieve error\n");
printf("\n");
switch (testNum)
{
case 1:
if (argc == 3)
{
recvMode = atoi(argv[2]);
if ((0 == recvMode) || (1 == recvMode))
{
ssltAdminModeSet(&clientHandle, mode);
}
show_help = 0;
}
break;
case 2:
if (argc == 2)
{
ssltAdminModeGet(&clientHandle, &mode);
show_help = 0;
}
break;
case 3:
if (argc == 3)
{
port = atoi(argv[2]);
ssltSecurePortSet(&clientHandle, port);
show_help = 0;
}
break;
case 4:
if (argc == 2)
{
ssltSecurePortGet(&clientHandle, &port);
show_help = 0;
}
break;
case 5:
if (argc == 4)
{
protocolId = atoi(argv[2]);
recvMode = atoi(argv[3]);
if ((0 == recvMode) || (1 == recvMode))
{
ssltProtocolLevelSet(&clientHandle, protocolId, mode);
}
show_help = 0;
}
break;
case 6:
if (argc == 3)
{
protocolId = atoi(argv[2]);
ssltProtocolLevelGet(&clientHandle, protocolId, &mode);
show_help = 0;
}
break;
case 7:
if (argc == 3)
{
timeout = atoi(argv[2]);
ssltSessionSoftTimeOutSet(&clientHandle, timeout);
show_help = 0;
}
break;
case 8:
if (argc == 2)
{
ssltSessionSoftTimeOutGet(&clientHandle, &timeout);
show_help = 0;
}
break;
case 9:
if (argc == 3)
{
timeout = atoi(argv[2]);
ssltSessionHardTimeOutSet(&clientHandle, timeout);
show_help = 0;
}
break;
case 10:
if (argc == 2)
{
ssltSessionHardTimeOutGet(&clientHandle, &timeout);
show_help = 0;
}
break;
case 11:
if (argc == 3)
{
session = atoi(argv[2]);
ssltNumSessionsSet(&clientHandle, session);
show_help = 0;
}
break;
case 12:
if (argc == 2)
{
ssltNumSessionsGet(&clientHandle, &session);
show_help = 0;
}
break;
case 13:
if (argc == 2)
{
ssltOperModeGet(&clientHandle, &mode);
show_help = 0;
}
break;
case 14:
if (argc == 3)
{
certNum = atoi(argv[2]);
ssltCertificateExists(&clientHandle, certNum);
show_help = 0;
}
break;
case 15:
if (argc == 3)
{
certNum = atoi(argv[2]);
ssltCertificateAndServerKeyExists(&clientHandle, certNum);
show_help = 0;
}
break;
case 16:
if (argc == 12)
{
certNum = atoi(argv[2]);
keyLength = atoi(argv[3]);
days = atoi(argv[11]);
ssltCertificateGenerate(&clientHandle, certNum, keyLength,
argv[4], argv[5], argv[6], argv[7],
argv[8], argv[9], argv[10], days);
show_help = 0;
}
break;
case 17:
if (argc == 3)
{
certNum = atoi(argv[2]);
ssltCertRemove(&clientHandle, certNum);
show_help = 0;
}
break;
case 18:
if (argc == 2)
{
ssltCertificateActiveGet(&clientHandle, &certNum);
show_help = 0;
}
break;
case 19:
if (argc == 2)
{
ssltCertificateOperActiveGet(&clientHandle, &certNum);
show_help = 0;
}
break;
case 20:
if (argc == 3)
{
certNum = atoi(argv[2]);
ssltCertificateExpiryStatusGet(&clientHandle, certNum, &isExpired);
show_help = 0;
}
break;
case 21:
if (argc == 3)
{
certNum = atoi(argv[2]);
ssltCertificateActiveSet(&clientHandle, certNum);
show_help = 0;
}
break;
case 22:
if (argc == 3)
{
certNum = atoi(argv[2]);
ssltCheckHTTPSEnabledAndOperational(&clientHandle, certNum, &isHttpModeEnabled);
show_help = 0;
}
break;
case 23:
if (argc == 2)
{
runSanity(&clientHandle);
show_help = 0;
}
break;
default:
break;
}
if (show_help == 1)
{
printAppMenu(argv[0]);
}
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Stopping sslt API example application");
return 0;
}