qopanza 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +202 -0
- data/README.md +71 -0
- data/lib/qopanza.rb +233 -0
- metadata +64 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 9071c080539ac74f1fa070c1e483569f6b513ce5a1a17c5b1380a13aa2e0f169
|
|
4
|
+
data.tar.gz: c4a7c0d2e86d3d63cb2015a4a4b8231225013d56036d0393872e4eb84c57e909
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b368d3c86f3d45ada955de54da48abd63f54f3d9f3c1a08db1cf92893a9699db2c4c383ca0ec2753448150fa51b17773289028bf5640da35de857b9c561104ce
|
|
7
|
+
data.tar.gz: 7ef1d0973573fde568c1fe8d774e8f390d17ac6f85fb8e1cbb4210e386d1156bde46928e49c47697bb17db5a637384de7013f450b5249ba4bed1fceaa9752f40
|
data/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Gsente LLC
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# qopanza (Ruby)
|
|
2
|
+
|
|
3
|
+
Ruby client for the Qopanza API.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
gem "qopanza"
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Requires Ruby 3.0+. **No runtime dependencies** — `net/http`, `json` and
|
|
12
|
+
`base64` are all standard library. A security gem that drags in a tree of
|
|
13
|
+
transitive dependencies is a harder sell to exactly the teams most likely
|
|
14
|
+
to care about supply chain.
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
Get an API key by signing up first — it is shown exactly once.
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
require "qopanza"
|
|
22
|
+
|
|
23
|
+
client = Qopanza::Client.new(base_url: "http://localhost:8000", api_key: api_key)
|
|
24
|
+
|
|
25
|
+
# One-line encryption: no key management at all.
|
|
26
|
+
sealed = client.encrypt(plaintext: "customer sensitive information")
|
|
27
|
+
client.decrypt(sealed) # => "customer sensitive information"
|
|
28
|
+
|
|
29
|
+
# Full control.
|
|
30
|
+
key = client.create_key(purpose: "kem", label: "order-service")
|
|
31
|
+
sealed = client.encrypt(key_id: key["id"], plaintext: "hello quantum-safe world")
|
|
32
|
+
|
|
33
|
+
sig_key = client.create_key(purpose: "signature")
|
|
34
|
+
signed = client.sign(key_id: sig_key["id"], message: "order-42-confirmed")
|
|
35
|
+
client.verify(key_id: sig_key["id"], message: "order-42-confirmed", signature: signed["signature"])
|
|
36
|
+
|
|
37
|
+
# Discovery.
|
|
38
|
+
run = client.scan_tls(host: "api.example.com")
|
|
39
|
+
posture = client.security_posture
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Run the quickstart:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
QOPANZA_API_KEY=qsk_... QOPANZA_BASE_URL=http://localhost:8000 \
|
|
46
|
+
ruby examples/quickstart.rb
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Notes
|
|
50
|
+
|
|
51
|
+
- **Raw strings, not base64.** Base64 is applied internally.
|
|
52
|
+
- **`verify` returns `false` only for a genuinely invalid signature.** A
|
|
53
|
+
failed call raises `Qopanza::ApiError` instead — treating an
|
|
54
|
+
unreachable API as "invalid signature" is how a verification step
|
|
55
|
+
silently becomes a no-op.
|
|
56
|
+
- **A failed scan has a nil `risk_score`**, not zero.
|
|
57
|
+
- `ApiError#status_code` is separate from the message, so a 409 from a
|
|
58
|
+
revoked key can be handled differently from a 429 rate limit. A status
|
|
59
|
+
of `0` means the request never reached the API.
|
|
60
|
+
- `decrypt` accepts either string or symbol keys, since Ruby callers
|
|
61
|
+
reasonably build hashes both ways.
|
|
62
|
+
|
|
63
|
+
This client holds a secret API key, so it belongs server-side.
|
|
64
|
+
|
|
65
|
+
## Tests
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
rake test
|
|
69
|
+
# or, without rake:
|
|
70
|
+
ruby -Ilib -Itest test/test_client.rb
|
|
71
|
+
```
|
data/lib/qopanza.rb
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "base64"
|
|
4
|
+
require "json"
|
|
5
|
+
require "net/http"
|
|
6
|
+
require "uri"
|
|
7
|
+
|
|
8
|
+
# Ruby client for the Qopanza API.
|
|
9
|
+
#
|
|
10
|
+
# Covers the crypto endpoints (keys, encrypt, decrypt, sign, verify), the
|
|
11
|
+
# AI analysis endpoint, and the scanner/posture endpoints that make the API
|
|
12
|
+
# useful from CI. Account signup, billing and support are dashboard
|
|
13
|
+
# concerns and are not part of this SDK — the same scoping the Python, Go,
|
|
14
|
+
# Rust, PHP, TypeScript and Java SDKs use.
|
|
15
|
+
#
|
|
16
|
+
# client = Qopanza::Client.new(base_url: "http://localhost:8000", api_key: key)
|
|
17
|
+
#
|
|
18
|
+
# # One-line encryption: no key management at all.
|
|
19
|
+
# sealed = client.encrypt(plaintext: "customer sensitive information")
|
|
20
|
+
# client.decrypt(sealed) # => "customer sensitive information"
|
|
21
|
+
#
|
|
22
|
+
# Byte handling is raw strings at the API boundary with base64 applied
|
|
23
|
+
# internally: base64 is a wire-format detail, and making callers encode it
|
|
24
|
+
# themselves is how a plaintext ends up double-encoded in production.
|
|
25
|
+
#
|
|
26
|
+
# Deliberately stdlib-only (net/http, json, base64). A security library
|
|
27
|
+
# that drags in a tree of transitive gems is a harder sell to exactly the
|
|
28
|
+
# teams most likely to care about supply chain.
|
|
29
|
+
#
|
|
30
|
+
# This client holds a secret API key, so it belongs server-side.
|
|
31
|
+
module Qopanza
|
|
32
|
+
VERSION = "0.1.0"
|
|
33
|
+
DEFAULT_BASE_URL = "http://localhost:8000"
|
|
34
|
+
|
|
35
|
+
# Raised for any non-2xx response, or a transport failure.
|
|
36
|
+
#
|
|
37
|
+
# +status_code+ is kept separate from the message so callers can branch
|
|
38
|
+
# on it — a 409 from a revoked key needs different handling from a 429
|
|
39
|
+
# from a rate limit. A status of 0 means the request never reached the
|
|
40
|
+
# API at all.
|
|
41
|
+
class ApiError < StandardError
|
|
42
|
+
attr_reader :status_code, :detail
|
|
43
|
+
|
|
44
|
+
def initialize(status_code, detail)
|
|
45
|
+
@status_code = status_code
|
|
46
|
+
@detail = detail
|
|
47
|
+
super("qopanza: [#{status_code}] #{detail}")
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class Client
|
|
52
|
+
# @param transport [#call] optional override with the signature
|
|
53
|
+
# call(method, uri, body, headers) -> [status, body]. Exists so the
|
|
54
|
+
# test suite can exercise request encoding and response decoding
|
|
55
|
+
# without a network, which is where a client library actually breaks.
|
|
56
|
+
def initialize(base_url: DEFAULT_BASE_URL, api_key: nil, timeout: 15, transport: nil)
|
|
57
|
+
base_url = DEFAULT_BASE_URL if base_url.nil? || base_url.empty?
|
|
58
|
+
@base_url = base_url.sub(%r{/+\z}, "")
|
|
59
|
+
@api_key = api_key
|
|
60
|
+
@timeout = timeout
|
|
61
|
+
@transport = transport
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# ---- Keys ---------------------------------------------------------------
|
|
65
|
+
|
|
66
|
+
# Generate a keypair. +purpose+ is "kem", "signature", or "hybrid_kem".
|
|
67
|
+
def create_key(purpose:, label: nil)
|
|
68
|
+
body = { purpose: purpose }
|
|
69
|
+
body[:label] = label if label
|
|
70
|
+
request(:post, "/keys", body)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def get_key(key_id)
|
|
74
|
+
request(:get, "/keys/#{escape(key_id)}")
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# ---- Encrypt / decrypt --------------------------------------------------
|
|
78
|
+
|
|
79
|
+
# Seal +plaintext+.
|
|
80
|
+
#
|
|
81
|
+
# Omit +key_id+ for the one-line path, where the platform provisions
|
|
82
|
+
# and reuses a managed key for the account and reports which one it
|
|
83
|
+
# used in "used_managed_key".
|
|
84
|
+
def encrypt(plaintext:, key_id: nil)
|
|
85
|
+
body = { plaintext: Base64.strict_encode64(plaintext) }
|
|
86
|
+
body[:key_id] = key_id if key_id
|
|
87
|
+
request(:post, "/encrypt", body)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Open what #encrypt sealed. Pass the hash it returned straight back.
|
|
91
|
+
def decrypt(sealed)
|
|
92
|
+
result = request(:post, "/decrypt", {
|
|
93
|
+
key_id: sealed["key_id"] || sealed[:key_id],
|
|
94
|
+
ciphertext_kem: sealed["ciphertext_kem"] || sealed[:ciphertext_kem],
|
|
95
|
+
ciphertext_payload: sealed["ciphertext_payload"] || sealed[:ciphertext_payload],
|
|
96
|
+
nonce: sealed["nonce"] || sealed[:nonce]
|
|
97
|
+
})
|
|
98
|
+
Base64.strict_decode64(result["plaintext"])
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# ---- Sign / verify ------------------------------------------------------
|
|
102
|
+
|
|
103
|
+
def sign(key_id:, message:)
|
|
104
|
+
request(:post, "/sign", { key_id: key_id, message: Base64.strict_encode64(message) })
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Check a signature.
|
|
108
|
+
#
|
|
109
|
+
# Returns false only when the signature genuinely did not verify. A
|
|
110
|
+
# failed call raises instead — treating an unreachable API as "invalid
|
|
111
|
+
# signature" is how a verification step silently becomes a no-op.
|
|
112
|
+
def verify(key_id:, message:, signature:)
|
|
113
|
+
result = request(:post, "/verify", {
|
|
114
|
+
key_id: key_id,
|
|
115
|
+
message: Base64.strict_encode64(message),
|
|
116
|
+
signature: signature
|
|
117
|
+
})
|
|
118
|
+
result["valid"]
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# ---- AI analysis --------------------------------------------------------
|
|
122
|
+
|
|
123
|
+
def analyze(context)
|
|
124
|
+
request(:post, "/analyze", { context: context })
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# ---- Scanner ------------------------------------------------------------
|
|
128
|
+
|
|
129
|
+
# Scan submitted source or manifest text. Nothing is fetched — only
|
|
130
|
+
# what you pass is scanned.
|
|
131
|
+
#
|
|
132
|
+
# The returned run has a nil "risk_score" when it failed, rather than
|
|
133
|
+
# zero: a scan that could not run must never read as a clean result.
|
|
134
|
+
def scan_code(filename:, content:)
|
|
135
|
+
request(:post, "/scan/code", { filename: filename, content: content })
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Probe a live TLS endpoint and record what it actually negotiates,
|
|
139
|
+
# including its certificate's key algorithm.
|
|
140
|
+
def scan_tls(host:, port: 443)
|
|
141
|
+
request(:post, "/scan/tls", { host: host, port: port.zero? ? 443 : port })
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def scan_assets(scan_id)
|
|
145
|
+
request(:get, "/scans/#{escape(scan_id)}/assets")
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# ---- Posture / inventory ------------------------------------------------
|
|
149
|
+
|
|
150
|
+
# The account's quantum risk score and what drives it.
|
|
151
|
+
#
|
|
152
|
+
# "score" runs 0-100 where higher is better, so it moves opposite to
|
|
153
|
+
# "quantum_risk". A score of 100 with a nil "last_scan_at" means "no
|
|
154
|
+
# vulnerable cryptography found" on an empty inventory — an absence of
|
|
155
|
+
# evidence, not evidence of safety.
|
|
156
|
+
def security_posture
|
|
157
|
+
request(:get, "/security/posture")
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def crypto_inventory
|
|
161
|
+
request(:get, "/inventory")
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
private
|
|
165
|
+
|
|
166
|
+
def escape(value)
|
|
167
|
+
URI.encode_www_form_component(value.to_s).gsub("+", "%20")
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def request(method, path, body = nil)
|
|
171
|
+
uri = URI.parse("#{@base_url}/v1#{path}")
|
|
172
|
+
headers = { "Content-Type" => "application/json" }
|
|
173
|
+
headers["X-API-Key"] = @api_key if @api_key
|
|
174
|
+
|
|
175
|
+
encoded = body.nil? ? nil : JSON.generate(body)
|
|
176
|
+
status, response_body =
|
|
177
|
+
if @transport
|
|
178
|
+
@transport.call(method, uri, encoded, headers)
|
|
179
|
+
else
|
|
180
|
+
send_request(method, uri, encoded, headers)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
raise ApiError.new(status, extract_detail(response_body)) if status >= 400
|
|
184
|
+
return {} if response_body.nil? || response_body.empty?
|
|
185
|
+
|
|
186
|
+
JSON.parse(response_body)
|
|
187
|
+
rescue JSON::ParserError => e
|
|
188
|
+
raise ApiError.new(status || 0, "Response was not valid JSON: #{e.message}")
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
# The API returns {"detail": "..."} for its own errors. Anything else —
|
|
192
|
+
# a proxy's HTML error page, say — is surfaced raw rather than
|
|
193
|
+
# swallowed, because "unknown error" helps nobody debug.
|
|
194
|
+
def extract_detail(response_body)
|
|
195
|
+
return "" if response_body.nil?
|
|
196
|
+
|
|
197
|
+
parsed = begin
|
|
198
|
+
JSON.parse(response_body)
|
|
199
|
+
rescue JSON::ParserError
|
|
200
|
+
nil
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
if parsed.is_a?(Hash) && parsed.key?("detail")
|
|
204
|
+
detail = parsed["detail"]
|
|
205
|
+
return detail.is_a?(String) ? detail : JSON.generate(detail)
|
|
206
|
+
end
|
|
207
|
+
response_body.strip
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def send_request(method, uri, body, headers)
|
|
211
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
212
|
+
http.use_ssl = uri.scheme == "https"
|
|
213
|
+
http.open_timeout = @timeout
|
|
214
|
+
http.read_timeout = @timeout
|
|
215
|
+
|
|
216
|
+
request_class = {
|
|
217
|
+
get: Net::HTTP::Get,
|
|
218
|
+
post: Net::HTTP::Post,
|
|
219
|
+
put: Net::HTTP::Put,
|
|
220
|
+
delete: Net::HTTP::Delete
|
|
221
|
+
}.fetch(method)
|
|
222
|
+
|
|
223
|
+
req = request_class.new(uri.request_uri)
|
|
224
|
+
headers.each { |name, value| req[name] = value }
|
|
225
|
+
req.body = body if body
|
|
226
|
+
|
|
227
|
+
response = http.request(req)
|
|
228
|
+
[response.code.to_i, response.body]
|
|
229
|
+
rescue StandardError => e
|
|
230
|
+
raise ApiError.new(0, "Transport error: #{e.message}")
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: qopanza
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Gsente LLC
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-09-10 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: minitest
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '5.0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '5.0'
|
|
27
|
+
description: Post-quantum cryptography (ML-KEM, ML-DSA) and cryptographic discovery
|
|
28
|
+
from Ruby.
|
|
29
|
+
email:
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- LICENSE
|
|
35
|
+
- README.md
|
|
36
|
+
- lib/qopanza.rb
|
|
37
|
+
homepage: https://qopanza.com
|
|
38
|
+
licenses:
|
|
39
|
+
- Apache-2.0
|
|
40
|
+
metadata:
|
|
41
|
+
homepage_uri: https://qopanza.com
|
|
42
|
+
source_code_uri: https://github.com/isingomajoel2023/qopanza-sdks
|
|
43
|
+
bug_tracker_uri: https://github.com/isingomajoel2023/qopanza-sdks/issues
|
|
44
|
+
rubygems_mfa_required: 'true'
|
|
45
|
+
post_install_message:
|
|
46
|
+
rdoc_options: []
|
|
47
|
+
require_paths:
|
|
48
|
+
- lib
|
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '3.0'
|
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
|
+
requirements:
|
|
56
|
+
- - ">="
|
|
57
|
+
- !ruby/object:Gem::Version
|
|
58
|
+
version: '0'
|
|
59
|
+
requirements: []
|
|
60
|
+
rubygems_version: 3.5.22
|
|
61
|
+
signing_key:
|
|
62
|
+
specification_version: 4
|
|
63
|
+
summary: Ruby client for the Qopanza API
|
|
64
|
+
test_files: []
|