From: server Date: Mon, 20 Jan 2025 18:22:51 +0000 (-0500) Subject: Mon Jan 20 01:22:51 PM EST 2025 X-Git-Url: http://www.foleosoft.com/?a=commitdiff_plain;h=1fa84f3455c0ab1a1d0eff7d0089e9aa6eb5d296;p=RosadoAPI.git Mon Jan 20 01:22:51 PM EST 2025 --- diff --git a/README.md b/README.md index 409bc59..56c0e88 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# EstousAPI +# RosadoAPI Easily transform as many CLI programs as you wish into web APIs. @@ -48,8 +48,15 @@ used to set up a CLI program to be used as an API. Below is the structure for this table. ```sql - - +MariaDB [RosadoAPI]> describe ServiceInfo; ++------------+---------+------+-----+---------+----------------+ +| Field | Type | Null | Key | Default | Extra | ++------------+---------+------+-----+---------+----------------+ +| id | int(11) | NO | PRI | NULL | auto_increment | +| service | text | YES | | NULL | | +| path | text | YES | | NULL | | +| parameters | text | YES | | NULL | | ++------------+---------+------+-----+---------+----------------+ ``` The `service` field is the name of the service and also corresponds @@ -66,7 +73,16 @@ authentication for users trying to ping the API. Below is the structure for this table. ```sql - +MariaDB [RosadoAPI]> describe AuthInfo; ++----------+---------+------+-----+---------+----------------+ +| Field | Type | Null | Key | Default | Extra | ++----------+---------+------+-----+---------+----------------+ +| id | int(11) | NO | PRI | NULL | auto_increment | +| service | text | YES | | NULL | | +| username | text | YES | | NULL | | +| authkey | text | YES | | NULL | | +| timeout | int(11) | YES | | NULL | | ++----------+---------+------+-----+---------+----------------+ ``` The `service` field must correspond to a `service` in the `ServiceInfo` @@ -82,14 +98,15 @@ To generate a unique `authkey` for a user, use the command below. openssl rand -hex 32 ``` -Communication with the API service is encrypted with ChaCha20-HMAC +Communication with the API service is encrypted with ChaCha20-HMAC-SHA256 This means it cannot be pinged using plaintext. To ping it and get a -response, the request must be encrypted using ChaCha20-HMAC, and +response, the request must be encrypted in this way, and the response also must be decrypted in the same way. Below are variables that will need to be populated in order to ping the API service. +- `$addr`: The address of the server to send the request to. - `$srvc`: The service to send a request to. - `$user`: The user requesting the service. - `$auth`: The authentication key. @@ -102,9 +119,10 @@ itself which comes from standard input as well as the session ID which is randomly generated. ```sh - srvc=$1 - user=$2 - auth=$3 + addr=$1 + srvc=$2 + user=$3 + auth=$4 read rqst sess=$(openssl rand -hex 12) ``` @@ -114,10 +132,9 @@ simply by taking the plaintext request and encrypting it with ChaCha20 using the authentication key. Then, a digest will also need to be computed for the message which allows the server to verify the message has not been tampered with. This must be -calculated from the plaintext message using HMAC-SHA256. - -Both of these values also need to be encoded as base64. Below -is a Bash script that generates the body and digest for the +calculated from the encrypted data using HMAC-SHA256. Both of +these values also need to be encoded as base64. Below is a Bash +script that generates the encrypted data and digest for the request. ```sh @@ -131,7 +148,7 @@ format. Below is an example of how to produce such a request and store the response in variable in Bash. ```sh - resp=$(curl -s -X POST -d "user=$user&sess=$sess&dgst=$dgst&data=$data" "$srvr/$srvc") + resp=$(curl -s -X POST -d "user=$user&sess=$sess&dgst=$dgst&data=$data" "$addr/$srvc") ``` The response from the server is in a similar format, so it diff --git a/build.sh b/build.sh index 5efefdf..514cc74 100644 --- a/build.sh +++ b/build.sh @@ -3,11 +3,17 @@ if [ "$1" == "run" ] then while [ 1 ] do - ./bin/APIServer + ./bin/rosado done +elif [ "$1" = "install" ] +then + sudo cp bin/rosado /usr/local/bin/rosado +elif [ "$1" = "uninstall" ] +then + sudo rm /usr/local/bin/rosado else xxd -i ./rcs/frontend.html ./src/frontend.h - gcc ./src/main.c -o ./bin/APIServer $(mysql_config --cflags --libs) -lCryptoFoleo + gcc ./src/main.c -o ./bin/rosado $(mysql_config --cflags --libs) -lCryptoFoleo rm ./src/frontend.h cp ./rcs/* ./bin/ fi diff --git a/rcs/EstoulsAPI.apk b/rcs/EstoulsAPI.apk deleted file mode 100644 index fb5f8d6..0000000 Binary files a/rcs/EstoulsAPI.apk and /dev/null differ diff --git a/rcs/favicon.ico b/rcs/favicon.ico deleted file mode 100644 index e33686d..0000000 Binary files a/rcs/favicon.ico and /dev/null differ diff --git a/rcs/frontend.html b/rcs/frontend.html deleted file mode 100644 index b77d983..0000000 --- a/rcs/frontend.html +++ /dev/null @@ -1,1069 +0,0 @@ - - - - EstoulsAPI - - - - - - - - - -
- -
-    -    -    - - -    -
  
- -
- - - - - - -
1
-
-
-
-
-
-
- - - - - diff --git a/src/main.c b/src/main.c index 91f6241..50ecbfa 100644 --- a/src/main.c +++ b/src/main.c @@ -9,6 +9,7 @@ uint8_t HOSTNAME[1024]; uint8_t HOSTNAME_I[1024]; uint8_t SQLPASS[1024]; +uint8_t WEBPORT[1024]; //grabs auth info from the database uint8_t* getDatabaseInfo(uint8_t type, uint8_t* a, uint8_t* b, uint8_t* c) @@ -400,6 +401,33 @@ void get_sqlpass() SQLPASS[plen] = 0; } +void get_webport() +{ + FILE *f = fopen("/usr/share/rosadoapi/port", "r"); + if (!f) + { + WEBPORT[0] = '8'; + WEBPORT[1] = '6'; + WEBPORT[2] = '6'; + WEBPORT[3] = '6'; + WEBPORT[4] = 0; + fprintf(stderr, "RosadoAPI: Could not access /usr/share/rosadoapi/port\n"); + fprintf(stderr, "RosadoAPI: Using default port %s.\n", WEBPORT); + printf("RosadoAPI: Listening on port %s...\n", WEBPORT); + return; + } + int c; + int plen = 0; + while ( (c = fgetc(f)) != EOF) + { + if (c == '\n' || c == '\r' || c == ' ') break; + WEBPORT[plen++] = c; + if (plen == sizeof(WEBPORT) - 2) break; + } + WEBPORT[plen] = 0; + printf("RosadoAPI: Listening on port %s...\n", WEBPORT); +} + void get_hostname() { for (uint8_t i = 0; i <= 1; i++) @@ -437,6 +465,7 @@ void main() { get_hostname(); get_sqlpass(); + get_webport(); MYSQL *conn; MYSQL_RES *res; @@ -488,7 +517,7 @@ void main() mysql_close(conn); //Open the socket - int socket_fd = httpOpenSocket(HOSTNAME_I, "8080"); + int socket_fd = httpOpenSocket(HOSTNAME_I, WEBPORT); //Begin processing packets for (;;) diff --git a/src/www/favicon.ico b/src/www/favicon.ico new file mode 100644 index 0000000..e33686d Binary files /dev/null and b/src/www/favicon.ico differ diff --git a/src/www/frontend.html b/src/www/frontend.html new file mode 100644 index 0000000..b77d983 --- /dev/null +++ b/src/www/frontend.html @@ -0,0 +1,1069 @@ + + + + EstoulsAPI + + + + + + + + + +
+ +
+    +    +    + + +    +
  
+ +
+ + + + + + +
1
+
+
+
+
+
+
+ + + + +