Compare commits

..

No commits in common. "main" and "1.0" have entirely different histories.
main ... 1.0

4 changed files with 11 additions and 25 deletions

View file

@ -1,6 +1,6 @@
# Auth - Signal-CLI HTTP
This module handles the reading and parsing of the auth JSON file. It also acts as a verifier in relation to that information. The file is a JSON object. It acts as a whitelist for which bearer token can do what action. It is passed to the HTTP endpoint via the `Authorization: <bearerToken>` header. Note that this is not `Authorization: Bearer <token>`
This module handles the reading and parsing of the auth JSON file. It also acts as a verifier in relation to that information. The file is a JSON object. It acts as a whitelist for which bearer token can do what action. It is passed to the HTTP endpoint via the `Authorization: <bearerToken>` header. Nore that this is not `Authorization: Bearer <token>`
Here's a sample auth JSON:
@ -35,8 +35,7 @@ Here's some examples for each case:
1. the request `{"method":"send","params":{"recipient":["+16028675309"],"message":"message"},"id":"SomeID"},` would not match the filter `["+5555555555"]` because one is a JSON map and the other a JSON array.
2. the request `{"method":"something","params":{"recipient":["+16028675309"],"message":"message"},"id":"SomeID"},` would not match the filter `{"method":"send","params":{"recipient":["+16028675309"],"message":"message"}}` because the "method" differs. This would also fail to match if the `method` key was missing in the request JSON.
3. `{"method":"send","params":{"recipient":["+16028675309","someBadNumber"]}}` would not match the filter `{"method":"send","params":{"recipient":["+16028675309",]}}` because of the `someBadNumber` number in the request. This rule exists so that a malicious request cant send a message to both a room/concact that it's whitelisted for, and one that it isn't.
4. `{"method":"send","params":{"recipient":["+15555555555","someBadNumber"]}}` would not match the filter `{"method":"send","params":{"recipient":["+16028675309","someBadNumber"]}}` because of the difference in phone number
4. `"+16028675309"` would not match the filter `"+15555555555"` because their values differ.
Here's what each filter JSON object in the above sample JSON does:
`{"method":"send","params":{"recipient":["+16028675309"]}}` allows sending to `+16028675309` (any message, timestamp, etc.)

View file

@ -1,5 +1,7 @@
# Signal-CLI HTTP
**Very** early in development.
Very simple HTTP frontend to [signal-cli](https://github.com/AsamK/signal-cli) JSON RPC.
Please see the JSONRPC documentation for `signal-cli`: [https://github.com/AsamK/signal-cli/blob/master/man/signal-cli-jsonrpc.5.adoc](https://github.com/AsamK/signal-cli/blob/master/man/signal-cli-jsonrpc.5.adoc)

View file

@ -21,10 +21,6 @@ var f *os.File;
var fLock sync.RWMutex;
var reader *bufio.Scanner;
// This is here to ignore lines written to STDIN echoed back through STDOUT
var ignoreEcho map[string]bool = make(map[string]bool);
var ignoreEchoMutex sync.RWMutex;
func SetupCMD(binaryLocation string) error {
// Avoid double set-up
if cmdStarted {return errors.New("cmd already started")};
@ -68,13 +64,6 @@ func readCMD() {
// Read the line
line := reader.Text();
// Check for echo
ignoreEchoMutex.Lock();
_, exists := ignoreEcho[line];
if exists {delete(ignoreEcho, line)}
ignoreEchoMutex.Unlock();
if exists {continue}
// Unmarshal the JSON
var unmarshaledJSON any;
if err := json.Unmarshal([]byte(line), &unmarshaledJSON); err != nil {continue}
@ -85,26 +74,22 @@ func readCMD() {
// Get method
method, ok := unmarshaledJSONMap["method"];
if ok && method == "receive" {
if !ok {continue}
// Redirect to handlers based off method
if method == "receive" {
handleIncoming(line, unmarshaledJSONMap);
continue;
} else {
handleResponse(line, unmarshaledJSONMap);
}
handleResponse(line, unmarshaledJSONMap);
}
}
/* Write a line into the subprocess */
func writeCMD(line string) (ok bool) {
// Write into ignoreEcho map so reader can skip the echoed line
ignoreEchoMutex.Lock();
ignoreEcho[line] = true;
ignoreEchoMutex.Unlock();
fLock.Lock();
if line[len(line)-1] != '\n' {line += "\n"}
f.WriteString(line);
fLock.Unlock();
return true;
}

View file

@ -12,7 +12,7 @@ Possible response codes:
There is no body content with non-200 response codes. With 200 the response is a valid JSON map or array.
This program simply relays requests to the signal-cli program. **It will not prevent you from breaking anything, outside of not whitelisting certain requests. This program does not understand what requests mean.** Each request comes formatted as a JSON object outlined in the [JSON-RPC documentation](https://github.com/AsamK/signal-cli/blob/master/man/signal-cli-jsonrpc.5.adoc).
This program simply relays requests to the signal-cli program. **It will not prevent you from breaking anything, outside of not whitelisting certain requests. This program does not understand what requests mean.** Each request comes formatted as a JSON object outlined in the [JSON-RPC documentation](https://github.com/AsamK/signal-cli/blob/master/man/signal-cli-jsonrpc.5.adoc](https://github.com/AsamK/signal-cli/blob/master/man/signal-cli-jsonrpc.5.adoc).
The program will ensure that the request object is a JSON map, and that the `request` key is present. For any request type that is not `receive`, the program will generate an ID for your request (do not put on in the request, it will return an error) and return the program's response.