Skip to content

Commit

Permalink
init: updated swagger hashes and added Makefile for different distrib…
Browse files Browse the repository at this point in the history
…utions
  • Loading branch information
Abhinandan-Khurana committed Oct 23, 2024
1 parent ab3c9d8 commit 4e5ba96
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 16 deletions.
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Makefile for building go-verify-swagger for multiple platforms

# Project name
BINARY_NAME=go-verify-swagger

# Source file
SRC_FILE=main.go

# Output directories
OUTPUT_DIR=dist

# Platforms and architectures
PLATFORMS=\
darwin amd64 \
darwin arm64 \
linux amd64 \
linux arm64 \
windows amd64 \
windows arm64

# Build command
build:
mkdir -p $(OUTPUT_DIR)
$(foreach platform_arch,$(PLATFORMS), \
$(eval GOOS=$(word 1,$(subst _, ,$(platform_arch)))) \
$(eval GOARCH=$(word 2,$(subst _, ,$(platform_arch)))) \
echo "Building for $(GOOS)/$(GOARCH)..." \
&& GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $(OUTPUT_DIR)/$(BINARY_NAME)-$(GOOS)-$(GOARCH)$(if $(filter windows,$(GOOS)),.exe) $(SRC_FILE) \
;)

# Clean build files
clean:
rm -rf $(OUTPUT_DIR)

# Default target
all: clean build


23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ A robust and efficient tool to verify Swagger URLs by fetching and validating th
- **Hash Matching**: Compares favicon hashes against predefined valid Swagger hashes.
- **Concurrent Processing**: Optimized with goroutines for faster URL verification.
- **Flexible Output**: Supports TXT, JSON, and CSV formats for result storage.
- **Verbose Logging**: Offers multiple logging levels for detailed insights.
- **Verbose Logging**: Offers logging for detailed insights.
- **Favicon Hash Retrieval**: Option to fetch and display favicon hashes for given URLs.

## Direct Installation

```bash
go install -v github.com/Abhinandan-Khurana/go-verify-swagger@v1.0.2
go install -v github.com/Abhinandan-Khurana/go-verify-swagger@v1.0.3
```

## Installation
Expand All @@ -24,14 +24,14 @@ Ensure you have [Go](https://golang.org/dl/) installed.
1. **Clone the Repository**:

```bash
git clone https://github.com/Abhinandan-Khurana/swagger-verifier.git
git clone https://github.com/Abhinandan-Khurana/go-verify-swagger.git
cd swagger-verifier
```

2. **Build the Executable**:

```bash
go build -o swagger_verifier swagger_verifier.go
go build -o dist/go-verify-swagger main.go
```

## Usage
Expand All @@ -41,31 +41,31 @@ Ensure you have [Go](https://golang.org/dl/) installed.
Verify URLs from an input file:

```bash
./swagger_verifier -i urls.txt
go-verify-swagger -i urls.txt
```

### Enable Verbose Logging

```bash
./swagger_verifier -i urls.txt -v
go-verify-swagger -i urls.txt -v
```

### Fetch and Display Favicon Hashes

```bash
./swagger_verifier -i urls.txt -get-hash
go-verify-swagger -i urls.txt -get-hash
```

### Output Results to a JSON File

```bash
./swagger_verifier -i urls.txt -o results.json -format json
go-verify-swagger -i urls.txt -o results.json -format json
```

### Enable Ultra Verbose Logging

```bash
./swagger_verifier -i urls.txt -vv
go-verify-swagger -i urls.txt -vv
```

### Command-Line Flags
Expand All @@ -74,7 +74,6 @@ Verify URLs from an input file:
- `-o, --output`: Path to the output file. Choose format with extension (`.txt`, `.json`, `.csv`).
- `-format`: Output format (`txt`, `json`, `csv`). Default is `txt`.
- `-v`: Enable verbose logging.
- `-vv`: Enable ultra verbose logging for debugging.
- `-silent`: Silent mode; only show results.
- `-get-hash`: Fetch and display favicon hashes for the input URLs.

Expand All @@ -96,11 +95,11 @@ Run the verifier:

## Logs

Logs are written to both the console and `swagger_verifier.log`. Use verbose modes (`-v` or `-vv`) for detailed logs.
Logs are written to both the console and `swagger_verifier.log`. Use verbose mode (`-v`) for detailed logs.

## Notes

- **Valid Swagger Hashes**: Update the `validSwaggerHashes` map with actual FNV hash values corresponding to valid Swagger favicons for accurate verification.
- **Valid Swagger Hashes**: Update the `validSwaggerHashes` map with actual FNV32 hash values corresponding to valid Swagger favicons for accurate verification.
- **TLS Verification**: Currently, TLS certificate verification is disabled (`InsecureSkipVerify: true`). For enhanced security, consider enabling it in production environments.
- **Error Handling**: The tool exits on critical errors like missing input files. Ensure input files are correctly formatted and accessible.
- **Fallback Mechanism**: If no `<link rel="icon">` tag is found, the tool attempts to fetch `/favicon.ico` as a fallback.
Binary file not shown.
Binary file added dist/go-verify-swagger-linux-
Binary file not shown.
Binary file added dist/go-verify-swagger-windows-.exe
Binary file not shown.
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var validSwaggerHashes = map[uint32]string{
1109606820: "swagger-favicon2",
1906814157: "swagger-favicon3",
932778223: "swagger-favicon4",
667846612: "swagger-favicon5",
1574961625: "swagger-favicon6",
}

var (
Expand All @@ -35,9 +37,9 @@ var (
outputFormat string
inputFile string
getFaviconHash bool
ultraVerbose bool
wg sync.WaitGroup
logger *log.Logger

wg sync.WaitGroup
logger *log.Logger
)

// Result struct to hold each URL result
Expand Down Expand Up @@ -67,7 +69,6 @@ func init() {
flag.StringVar(&inputFile, "i", "", "Input file containing potential Swagger URLs")
flag.StringVar(&outputFormat, "format", "txt", "Output format (txt, json, csv)")
flag.BoolVar(&getFaviconHash, "get-hash", false, "Fetch and display favicon hashes for the input URLs")
flag.BoolVar(&ultraVerbose, "vv", false, "Enable ultra verbose logging for debugging")
}

func main() {
Expand Down
1 change: 1 addition & 0 deletions swagger_verifier.log
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SWAGGER_VERIFIER: 2024/10/22 15:40:59 main.go:91: No input file provided. Use -i to specify a file containing potential Swagger URLs.
SWAGGER_VERIFIER: 2024/10/23 15:21:40 main.go:83: Verbose mode activated

0 comments on commit 4e5ba96

Please sign in to comment.