Skip to content

Commit a3ba674

Browse files
committed
initial import
0 parents  commit a3ba674

File tree

9 files changed

+981
-0
lines changed

9 files changed

+981
-0
lines changed

.github/workflows/build.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
# - name: Install prerequisites
17+
# run: sudo apt-get install -y libssl-dev check
18+
19+
- name: Build tests
20+
run: make test
21+
22+
- name: Run tests
23+
run: ./test

.gitignore

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Object files
5+
*.o
6+
*.ko
7+
*.obj
8+
*.elf
9+
10+
# Linker output
11+
*.ilk
12+
*.map
13+
*.exp
14+
15+
# Precompiled Headers
16+
*.gch
17+
*.pch
18+
19+
# Libraries
20+
*.lib
21+
*.a
22+
*.la
23+
*.lo
24+
25+
# Shared objects (inc. Windows DLLs)
26+
*.dll
27+
*.so
28+
*.so.*
29+
*.dylib
30+
31+
# Executables
32+
*.exe
33+
*.out
34+
*.app
35+
*.i*86
36+
*.x86_64
37+
*.hex
38+
39+
# Debug files
40+
*.dSYM/
41+
*.su
42+
*.idb
43+
*.pdb
44+
45+
# Kernel Module Compile Results
46+
*.mod*
47+
*.cmd
48+
.tmp_versions/
49+
modules.order
50+
Module.symvers
51+
Mkfile.old
52+
dkms.conf
53+
54+
# Build directories
55+
build/
56+
57+
# Dependencies
58+
aws_sigv4/deps
59+
60+
test
61+
example

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Riptides Labs
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Makefile for AWS SigV4 C implementation
2+
3+
CC = gcc
4+
CFLAGS = -Wall -Wextra -std=c99 -fPIC $(shell pkg-config --cflags libssl)
5+
LIB_NAME = libsigv4.so
6+
LIB_SRC = sigv4.c
7+
LIB_HDR = sigv4.h
8+
EXAMPLE_SRC = example.c
9+
EXAMPLE_BIN = example
10+
TEST_SRC = test.c
11+
TEST_BIN = test
12+
OPENSSL_LIBS = $(shell pkg-config --libs libssl,libcrypto)
13+
CHECK_LIBS = $(shell pkg-config --libs check)
14+
15+
all: $(LIB_NAME) $(EXAMPLE_BIN)
16+
17+
$(LIB_NAME): $(LIB_SRC) $(LIB_HDR)
18+
$(CC) $(CFLAGS) -shared -o $@ $(LIB_SRC) $(OPENSSL_LIBS)
19+
20+
$(EXAMPLE_BIN): $(EXAMPLE_SRC) $(LIB_NAME)
21+
$(CC) -Wall -Wextra -std=c99 $(shell pkg-config --cflags libssl) -o $@ $(EXAMPLE_SRC) -L. -lsigv4 $(OPENSSL_LIBS)
22+
23+
$(TEST_BIN): $(TEST_SRC) $(LIB_NAME)
24+
$(CC) -Wall -Wextra -std=c99 $(shell pkg-config --cflags libssl,check) -o $@ $(TEST_SRC) -L. -lsigv4 $(OPENSSL_LIBS) $(CHECK_LIBS)
25+
26+
clean:
27+
rm -f $(LIB_NAME) $(EXAMPLE_BIN) $(TEST_BIN) *.o

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# AWS SigV4 C Library
2+
3+
This project provides a C implementation of AWS Signature Version 4 (SigV4) signing, suitable for use in embedded, kernel, or user-space applications. It includes a shared library and an example application demonstrating usage.
4+
5+
## Features
6+
- AWS SigV4 signing for HTTP requests
7+
- OpenSSL integration for cryptographic operations
8+
- Simple API for integration into C projects
9+
- Example usage included
10+
- System header configurability via `SIGV4_SYSTEM_HEADER`
11+
12+
## Building
13+
14+
### Prerequisites
15+
- GCC or compatible C compiler
16+
- OpenSSL development libraries
17+
- `pkg-config` utility
18+
19+
### Build Instructions
20+
21+
To build the shared library and example application, run:
22+
23+
```sh
24+
make
25+
```
26+
27+
This will produce:
28+
- `libsigv4.so`: Shared library implementing SigV4
29+
- `example`: Example application using the library
30+
31+
### Clean Build Artifacts
32+
33+
```sh
34+
make clean
35+
```
36+
37+
## Usage
38+
39+
### System Header Configurability
40+
You can configure the system header used by the library by defining the macro `SIGV4_SYSTEM_HEADER` during compilation. This allows integration with custom or platform-specific headers as needed.
41+
42+
Example:
43+
```sh
44+
gcc -DSIGV4_SYSTEM_HEADER='<your_header.h>' ...
45+
```
46+
47+
### Linking
48+
Include the header in your application:
49+
50+
```c
51+
#include "sigv4.h"
52+
```
53+
54+
Link against the shared library and OpenSSL:
55+
56+
```
57+
-L. -lsigv4 $(pkg-config --libs libssl)
58+
```
59+
60+
### Example
61+
See `example.c` for a usage demonstration.
62+
63+
## License
64+
See `LICENSE` for details.
65+
66+
## Contributing
67+
Pull requests and issues are welcome!

example.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <stdio.h>
2+
#include <openssl/hmac.h>
3+
#include <openssl/sha.h>
4+
5+
#include "sigv4.h"
6+
7+
int HMAC_SHA256(const unsigned char *data, size_t data_len,
8+
const unsigned char *key, size_t key_len,
9+
unsigned char *out, size_t *out_len)
10+
{
11+
unsigned int len = 0;
12+
HMAC(EVP_sha256(), key, key_len, data, data_len, out, &len);
13+
*out_len = len;
14+
return 0;
15+
}
16+
17+
int main()
18+
{
19+
aws_sigv4_params_t sigv4_params = {
20+
.access_key_id = aws_sigv4_string((unsigned char *)"your_access_key"),
21+
.secret_access_key = aws_sigv4_string((unsigned char *)"your_secret_key"),
22+
.method = aws_sigv4_string((unsigned char *)"GET"),
23+
.uri = aws_sigv4_string((unsigned char *)"/"),
24+
.query_str = aws_sigv4_string((unsigned char *)"encoding-type=url"),
25+
.host = aws_sigv4_string((unsigned char *)"riptides-sigv4.s3.eu-central-1.amazonaws.com"),
26+
.region = aws_sigv4_string((unsigned char *)"eu-central-1"),
27+
.service = aws_sigv4_string((unsigned char *)"s3"),
28+
.x_amz_date = aws_sigv4_string((unsigned char *)"20250815T071550Z"),
29+
.hmac_sha256 = HMAC_SHA256,
30+
.sha256 = (void *)SHA256,
31+
.sort = qsort,
32+
};
33+
34+
char auth_buf[AWS_SIGV4_AUTH_HEADER_MAX_LEN] = {0};
35+
aws_sigv4_header_t auth_header = {
36+
.value = aws_sigv4_string((unsigned char *)auth_buf)};
37+
38+
// Initialize sigv4_params and auth_header as needed
39+
40+
int status = aws_sigv4_sign(&sigv4_params, &auth_header);
41+
if (status == AWS_SIGV4_OK)
42+
{
43+
printf("Signature: %s\n", auth_header.value.data);
44+
}
45+
else
46+
{
47+
printf("Failed to sign request, status: %d\n", status);
48+
}
49+
50+
return 0;
51+
}

0 commit comments

Comments
 (0)