Skip to content

Commit 44e6dac

Browse files
committed
Initial commit
0 parents  commit 44e6dac

File tree

9 files changed

+2109
-0
lines changed

9 files changed

+2109
-0
lines changed

.github/workflows/build.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 check
18+
19+
- name: Build tests
20+
run: make test
21+
22+
- name: Run tests
23+
run: make run-tests
24+
25+
- name: Build example
26+
run: make example
27+
28+
- name: Run example
29+
run: make run-example

.gitignore

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
oci-req-signer-c/deps
59+
60+
test
61+
example
62+
63+
# IDEs and editors
64+
.vscode/
65+
*.code-workspace
66+
.idea/

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 OCI Request Signer Contributors
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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Makefile for OCI Request Signer C implementation
2+
3+
CC = gcc
4+
CFLAGS = -Wall -g -Wextra -std=c99 -fPIC $(shell pkg-config --cflags libssl)
5+
LIB_NAME = liboci_signer.so
6+
LIB_SRC = oci_signer.c
7+
LIB_HDR = oci_signer.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. -loci_signer $(OPENSSL_LIBS)
22+
23+
$(TEST_BIN): $(TEST_SRC) $(LIB_NAME)
24+
$(CC) -Wall -g -Wextra -std=c99 $(shell pkg-config --cflags libssl,check) -o $@ $(TEST_SRC) -L. -loci_signer $(OPENSSL_LIBS) $(CHECK_LIBS)
25+
26+
run-tests: $(TEST_BIN)
27+
LD_LIBRARY_PATH=. ./$(TEST_BIN)
28+
29+
run-example: $(EXAMPLE_BIN)
30+
LD_LIBRARY_PATH=. ./$(EXAMPLE_BIN)
31+
32+
clean:
33+
rm -f $(LIB_NAME) $(EXAMPLE_BIN) $(TEST_BIN) *.o

README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# OCI Request Signer for C
2+
3+
This project provides a C implementation of [Oracle Cloud Infrastructure (OCI) request signature](https://docs.oracle.com/en-us/iaas/Content/API/Concepts/signingrequests.htm), 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+
7+
- Produces the HTTP `Authorization` header (key and value) for OCI requests, including the computed signature and all required metadata
8+
- OCI request signing for HTTP requests
9+
- No dynamic memory allocations
10+
- Support for DER format private keys
11+
- Default headers and automatic body hashing based on request method
12+
- Simple API for integration into C projects
13+
- Example usage and tests included
14+
- System header configurability via `OCI_SYSTEM_HEADER`
15+
16+
## Building
17+
18+
### Prerequisites
19+
20+
- GCC or compatible C compiler
21+
- `pkg-config` utility
22+
- [OpenSSL](https://github.com/openssl/openssl) for testing and examples
23+
- [libcheck](https://github.com/libcheck/check) for testing
24+
25+
### Build Instructions
26+
27+
```sh
28+
sudo apt install libssl-dev check
29+
```
30+
31+
To build the shared library and example application, run:
32+
33+
```sh
34+
make
35+
```
36+
37+
This will produce:
38+
- `libocisigner.so`: Shared library implementing OCI request signing
39+
- `example`: Example application using the library
40+
41+
### Run Tests
42+
43+
```sh
44+
make run-tests
45+
```
46+
47+
### Clean Build Artifacts
48+
49+
```sh
50+
make clean
51+
```
52+
53+
## Usage
54+
55+
### Private Key Format
56+
57+
This library **only** accepts RSA private keys in DER format. The private key is stored in a dedicated binary data type (`oci_signer_binary_t`) to clearly indicate that it contains binary data rather than a string.
58+
59+
If you have a PEM format key, you need to convert it to DER format before using it with this library:
60+
61+
```sh
62+
# Convert PEM to DER format
63+
openssl rsa -in private_key.pem -outform DER -out private_key.der
64+
```
65+
66+
### Key ID Format
67+
68+
The library supports two formats for the `key_id` parameter:
69+
70+
1. **Standard format**: `tenancy/user/fingerprint`
71+
```
72+
ocid1.tenancy.oc1..aaaaaaaaba3pv6wkcr4jqae5f15p2b2m2yt2j6rx32uzr4h25vqstifsfdsq/ocid1.user.oc1..aaaaaaaat5nvwcna5j6aqzjcaty5eqbb6qt2jvpkanghtgdaqedqw3rynjq/20:3b:97:13:55:1c:5b:0d:d3:37:d8:50:4e:c5:3a:34
73+
```
74+
75+
2. **Session token format**: `ST$<user principal session token>`
76+
```
77+
ST$aaaaaaaa7tz3aaaaaaaaaymq2maaaaaaabfwiljtdnfgqaaaa
78+
```
79+
80+
### System Header Configurability
81+
82+
You can configure the system header used by the library by defining the macro `OCI_SYSTEM_HEADER` during compilation. This allows integration with custom or platform-specific headers as needed.
83+
84+
Example:
85+
```sh
86+
gcc -DOCI_SYSTEM_HEADER='<your_header.h>' ...
87+
```
88+
89+
### Linking
90+
91+
Include the header in your application:
92+
93+
```c
94+
#include "oci_signer.h"
95+
```
96+
97+
Link against the shared library and OpenSSL:
98+
99+
```
100+
-L. -locisigner -lssl -lcrypto
101+
```
102+
103+
104+
### Example Usage
105+
106+
The main output of this library is the HTTP `Authorization` header, which you add to your request:
107+
108+
```c
109+
oci_signer_header_t auth_header;
110+
// ... set up signer parameters ...
111+
oci_signer_sign(&signer_params, &auth_header, buffer_size);
112+
// Now add:
113+
// Header key: (char*)auth_header.key.data // will be "Authorization"
114+
// Header value: (char*)auth_header.value.data // contains the computed signature and metadata
115+
```
116+
117+
See `example.c` for a complete usage demonstration, including examples of how to use custom crypto functions.
118+
119+
## Custom Crypto Implementation
120+
121+
For integration with custom environments (like Linux kernel modules), you can provide your own implementations of the required crypto functions:
122+
123+
1. Define `OCI_SYSTEM_HEADER` to include environment-specific headers instead of standard C library headers
124+
2. Provide custom implementations of the required crypto functions:
125+
- SHA256 hash function
126+
- RSA signing function
127+
- Base64 encoding function
128+
129+
## License
130+
131+
This project is licensed under the MIT License - see the LICENSE file for details.
132+
133+
## Acknowledgments
134+
135+
This implementation of computing the request authorization header is based on the [OCI Go SDK's HTTP signer](https://github.com/oracle/oci-go-sdk/blob/907df66346f4bd3b0e898b5c884422253e86cee3/common/http_signer.go#L244)

0 commit comments

Comments
 (0)