|
1 | | -# Certificate Authority |
| 1 | +<a id="readme-top"></a> |
2 | 2 |
|
3 | | -WIP |
| 3 | +<!-- PROJECT SHIELDS --> |
| 4 | +[](https://github.com/android-sms-gateway/ca-backend/actions) |
| 5 | +[](go.mod) |
| 6 | +[](LICENSE) |
| 7 | + |
| 8 | +<br /> |
| 9 | +<div align="center"> |
| 10 | + <h3 align="center">🔒 Android SMS Gateway CA</h3> |
| 11 | + |
| 12 | + <p align="center"> |
| 13 | + Private Certificate Authority for Secure Local Communications |
| 14 | + <br /> |
| 15 | + <a href="https://ca.sms-gate.app/docs/index.html"><strong>Explore the API docs »</strong></a> |
| 16 | + <br /> |
| 17 | + <br /> |
| 18 | + <a href="https://github.com/android-sms-gateway/ca-backend/issues/new?labels=bug">Report Bug</a> |
| 19 | + · |
| 20 | + <a href="https://github.com/android-sms-gateway/ca-backend/issues/new?labels=enhancement">Request Feature</a> |
| 21 | + </p> |
| 22 | +</div> |
| 23 | + |
| 24 | +<!-- TABLE OF CONTENTS --> |
| 25 | +- [📖 About The Project](#-about-the-project) |
| 26 | + - [🛠️ Built With](#️-built-with) |
| 27 | +- [🚀 Getting Started](#-getting-started) |
| 28 | + - [Prerequisites](#prerequisites) |
| 29 | + - [Installation](#installation) |
| 30 | +- [💻 Usage](#-usage) |
| 31 | + - [Method Comparison](#method-comparison) |
| 32 | + - [CLI Method](#cli-method) |
| 33 | + - [API Method](#api-method) |
| 34 | +- [⚠️ Limitations](#️-limitations) |
| 35 | +- [🚨 Migration Guide](#-migration-guide) |
| 36 | +- [❓ FAQ](#-faq) |
| 37 | +- [🤝 Contributing](#-contributing) |
| 38 | +- [📄 License](#-license) |
| 39 | + |
| 40 | + |
| 41 | +<!-- ABOUT THE PROJECT --> |
| 42 | +## 📖 About The Project |
| 43 | + |
| 44 | +This private Certificate Authority simplifies secure communications within local networks while maintaining security standards. By operating its own [Certificate Authority (CA)](https://en.wikipedia.org/wiki/Certificate_authority), the project eliminates common security pitfalls associated with self-signed certificates and manual certificate management. |
| 45 | + |
| 46 | +> **Important** Security Value Proposition |
| 47 | +> - **🌍 Solves private IP validation** - Public CAs cannot validate private IP addresses |
| 48 | +> - **⚠️ Reduces security risks** - Eliminates manual certificate installation on client devices |
| 49 | +
|
| 50 | +The CA enforces strict security boundaries through multiple layers: |
| 51 | + |
| 52 | +1. **Private IP Enforcement** - All issued certificates validated against RFC 1918 address ranges |
| 53 | +2. **Key Management** - CA private key loaded securely (PEM/PKCS#8); certificates parsed using x509 |
| 54 | +3. **Request Validation** - CSRs validated to ensure SAN entries are private IPs (RFC 1918) |
| 55 | + |
| 56 | +### 🛠️ Built With |
| 57 | + |
| 58 | +- [](https://golang.org/) |
| 59 | +- [](https://www.docker.com/) |
| 60 | +- [](https://www.gnu.org/software/make/) |
| 61 | + |
| 62 | +<p align="right">(<a href="#readme-top">back to top</a>)</p> |
| 63 | + |
| 64 | +<!-- GETTING STARTED --> |
| 65 | +## 🚀 Getting Started |
| 66 | + |
| 67 | +### Prerequisites |
| 68 | + |
| 69 | +- Go 1.24.1+ (for building from source) |
| 70 | +- Docker (optional, for containerized deployment) |
| 71 | +- OpenSSL (for manual key/CSR generation) |
| 72 | +- curl and jq (for API examples) |
| 73 | + |
| 74 | +### Installation |
| 75 | + |
| 76 | +You don't need to install the CA locally to use it. You can use the [API](#api-method) or the [CLI](#cli-method) to issue a certificate with the project's CA at [ca.sms-gate.app](https://ca.sms-gate.app). |
| 77 | + |
| 78 | +<p align="right">(<a href="#readme-top">back to top</a>)</p> |
| 79 | + |
| 80 | +<!-- USAGE EXAMPLES --> |
| 81 | +## 💻 Usage |
| 82 | + |
| 83 | +### Method Comparison |
| 84 | + |
| 85 | +| Feature | CLI Method 🖥️ | API Method 🌐 | |
| 86 | +| --------------- | ------------ | ----------------- | |
| 87 | +| Difficulty | ⭐ Easy | ⭐⭐ Medium | |
| 88 | +| Customization | ❌ No | ✅ Available | |
| 89 | +| Automation | ✅ Full | ❌ Manual | |
| 90 | +| Recommended For | Most users ✅ | CI/CD pipelines 🤖 | |
| 91 | + |
| 92 | +### CLI Method |
| 93 | + |
| 94 | +You can use the [SMSGate CLI](https://github.com/android-sms-gateway/cli/releases/latest) to issue a certificate. |
| 95 | + |
| 96 | +1. 📥 **Generate Certificate** |
| 97 | + ```bash |
| 98 | + # Generate webhook certificate |
| 99 | + ./smsgate-ca webhooks --out=server.crt --keyout=server.key 192.168.1.10 |
| 100 | + ``` |
| 101 | + |
| 102 | +2. 🔐 **Install Certificates** |
| 103 | + ```bash |
| 104 | + # Nginx example |
| 105 | + ssl_certificate /path/to/server.crt; |
| 106 | + ssl_certificate_key /path/to/server.key; |
| 107 | + ``` |
| 108 | + |
| 109 | +### API Method |
| 110 | + |
| 111 | +1. 🔑 **Generate Key Pair** |
| 112 | + ```bash |
| 113 | + openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out server.key |
| 114 | + ``` |
| 115 | + |
| 116 | +2. 📝 **Create Config** |
| 117 | + ```ini |
| 118 | + # server.cnf |
| 119 | + [req] |
| 120 | + distinguished_name = req_distinguished_name |
| 121 | + x509_extensions = v3_req |
| 122 | + prompt = no |
| 123 | + |
| 124 | + [req_distinguished_name] |
| 125 | + CN = 192.168.1.10 # replace with your private IP |
| 126 | + |
| 127 | + [v3_req] |
| 128 | + keyUsage = nonRepudiation, digitalSignature, keyEncipherment |
| 129 | + extendedKeyUsage = serverAuth |
| 130 | + subjectAltName = @alt_names |
| 131 | + |
| 132 | + [alt_names] |
| 133 | + IP.0 = 192.168.1.10 |
| 134 | + ``` |
| 135 | + |
| 136 | +3. 📋 **Generate CSR** |
| 137 | + ```bash |
| 138 | + openssl req -new -key server.key -out server.csr -extensions v3_req \ |
| 139 | + -config ./server.cnf |
| 140 | + ``` |
| 141 | + |
| 142 | +4. 📨 **Submit CSR** |
| 143 | + ```sh |
| 144 | + jq -Rs '{content: .}' < server.csr | \ |
| 145 | + curl -sSf -X POST \ |
| 146 | + -H "Content-Type: application/json" \ |
| 147 | + -d @- \ |
| 148 | + https://ca.sms-gate.app/api/v1/csr |
| 149 | + ``` |
| 150 | + |
| 151 | + You will receive a Request ID in the response. |
| 152 | + |
| 153 | +5. 🕒 **Check Status** |
| 154 | + ```bash |
| 155 | + curl https://ca.sms-gate.app/api/v1/csr/REQ_12345 # replace with your Request ID |
| 156 | + ``` |
| 157 | + |
| 158 | +6. 📥 **Save Certificate** |
| 159 | + When the request is approved, the certificate content will be provided in the `certificate` field of the response. Save the certificate content to the file `server.crt`. |
| 160 | + |
| 161 | +7. 🔐 **Install Certificate** |
| 162 | + Install the `server.crt` and `server.key` (from step 1) files to your server. |
| 163 | + |
| 164 | +Full API documentation is available [here](https://ca.sms-gate.app/docs/index.html). |
| 165 | + |
| 166 | +<p align="right">(<a href="#readme-top">back to top</a>)</p> |
| 167 | + |
| 168 | +<!-- LIMITATIONS --> |
| 169 | +## ⚠️ Limitations |
| 170 | + |
| 171 | +The Certificate Authority service has the following limitations: |
| 172 | + |
| 173 | +- 🔐 Only issues certificates for private IP ranges: |
| 174 | + ```text |
| 175 | + 10.0.0.0/8 |
| 176 | + 172.16.0.0/12 |
| 177 | + 192.168.0.0/16 |
| 178 | + ``` |
| 179 | +- ⏳ Certificate validity: 1 year |
| 180 | +- 📛 Maximum 1 `POST` request per minute |
| 181 | + |
| 182 | +<p align="right">(<a href="#readme-top">back to top</a>)</p> |
| 183 | + |
| 184 | +<!-- MIGRATION GUIDE --> |
| 185 | +## 🚨 Migration Guide |
| 186 | + |
| 187 | +Self-signed certificates will be deprecated after v2.0 release. It is recommended to use the project's CA instead. |
| 188 | +
|
| 189 | +Migration checklist: |
| 190 | +- [ ] Replace self-signed certs before v2.0 release |
| 191 | +- [ ] Update automation scripts to use CLI tool or API |
| 192 | +- [ ] Rotate certificates every 1 year |
| 193 | +
|
| 194 | +<p align="right">(<a href="#readme-top">back to top</a>)</p> |
| 195 | +
|
| 196 | +<!-- FAQ --> |
| 197 | +## ❓ FAQ |
| 198 | +
|
| 199 | +**Why don't I need to install CA on devices?** |
| 200 | +The root CA certificate is embedded in the SMSGate app (v1.31+). |
| 201 | +Note: other clients (browsers, third‑party services) that do not embed this CA will not trust these certificates unless you install the CA in their trust store. |
| 202 | + |
| 203 | +**Certificate issuance failed?** |
| 204 | +Ensure your IP matches private ranges and hasn't exceeded quota |
| 205 | +
|
| 206 | +<p align="right">(<a href="#readme-top">back to top</a>)</p> |
| 207 | +
|
| 208 | +<!-- CONTRIBUTING --> |
| 209 | +## 🤝 Contributing |
| 210 | +
|
| 211 | +Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**. |
| 212 | +
|
| 213 | +If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". |
| 214 | +
|
| 215 | +1. Fork the Project |
| 216 | +2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`) |
| 217 | +3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`) |
| 218 | +4. Push to the Branch (`git push origin feature/AmazingFeature`) |
| 219 | +5. Open a Pull Request |
| 220 | +
|
| 221 | +<p align="right">(<a href="#readme-top">back to top</a>)</p> |
| 222 | +
|
| 223 | +<!-- LICENSE --> |
| 224 | +## 📄 License |
| 225 | +
|
| 226 | +Distributed under the Apache-2.0 License. See [`LICENSE`](LICENSE) for more information. |
| 227 | +
|
| 228 | +<p align="right">(<a href="#readme-top">back to top</a>)</p> |
0 commit comments