@andrewheberle/serverless-ssh-ca 0.18.1 → 0.19.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.
Files changed (80) hide show
  1. package/README.md +14 -2
  2. package/dist/api/v3/index.d.ts +1 -1
  3. package/dist/api/v3/index.d.ts.map +1 -1
  4. package/dist/api/v3/index.js +9 -7
  5. package/dist/api/v3/index.js.map +1 -1
  6. package/dist/api/v3/schema.d.ts +13 -13
  7. package/dist/api/v3/schema.d.ts.map +1 -1
  8. package/dist/api/v3/schema.js +2 -2
  9. package/dist/api/v3/schema.js.map +1 -1
  10. package/dist/certificate.d.ts +2 -2
  11. package/dist/certificate.d.ts.map +1 -1
  12. package/dist/certificate.js +4 -2
  13. package/dist/certificate.js.map +1 -1
  14. package/dist/db/index.d.ts +2 -2
  15. package/dist/db/index.d.ts.map +1 -1
  16. package/dist/db/index.js +2 -2
  17. package/dist/db/index.js.map +1 -1
  18. package/dist/db/migrations/index.js +1 -1
  19. package/dist/db/migrations/index.js.map +1 -1
  20. package/dist/index.d.ts +4 -3
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +2 -2
  23. package/dist/index.js.map +1 -1
  24. package/dist/krl.js +1 -1
  25. package/dist/krl.js.map +1 -1
  26. package/dist/logger.d.ts +1 -1
  27. package/dist/logger.d.ts.map +1 -1
  28. package/dist/proof.d.ts +2 -2
  29. package/dist/proof.d.ts.map +1 -1
  30. package/dist/proof.js +5 -3
  31. package/dist/proof.js.map +1 -1
  32. package/dist/router.d.ts +1 -2
  33. package/dist/router.d.ts.map +1 -1
  34. package/dist/router.js +2 -2
  35. package/dist/router.js.map +1 -1
  36. package/dist/sshsig/formats.d.ts +1 -1
  37. package/dist/sshsig/formats.d.ts.map +1 -1
  38. package/dist/sshsig/index.d.ts +1 -1
  39. package/dist/sshsig/index.d.ts.map +1 -1
  40. package/dist/sshsig/index.js +2 -2
  41. package/dist/sshsig/index.js.map +1 -1
  42. package/dist/sshsig/sig.d.ts +1 -1
  43. package/dist/sshsig/sig.d.ts.map +1 -1
  44. package/dist/sshsig/sig_parser.d.ts +1 -1
  45. package/dist/sshsig/sig_parser.d.ts.map +1 -1
  46. package/dist/sshsig/sig_parser.js +3 -3
  47. package/dist/sshsig/sig_parser.js.map +1 -1
  48. package/dist/sshsig/verifier.d.ts +1 -1
  49. package/dist/sshsig/verifier.d.ts.map +1 -1
  50. package/dist/sshsig/verifier.js +2 -2
  51. package/dist/sshsig/verifier.js.map +1 -1
  52. package/dist/types.d.ts +25 -2
  53. package/dist/types.d.ts.map +1 -1
  54. package/dist/utils.d.ts +5 -5
  55. package/dist/utils.d.ts.map +1 -1
  56. package/dist/utils.js +6 -4
  57. package/dist/utils.js.map +1 -1
  58. package/dist/verify.d.ts +2 -2
  59. package/dist/verify.d.ts.map +1 -1
  60. package/dist/verify.js +1 -1
  61. package/dist/verify.js.map +1 -1
  62. package/package.json +3 -3
  63. package/src/api/v3/index.ts +13 -12
  64. package/src/api/v3/schema.ts +3 -3
  65. package/src/certificate.ts +8 -12
  66. package/src/db/index.ts +4 -4
  67. package/src/db/migrations/index.ts +1 -1
  68. package/src/index.ts +13 -6
  69. package/src/krl.ts +2 -2
  70. package/src/logger.ts +1 -1
  71. package/src/proof.ts +8 -4
  72. package/src/router.ts +3 -4
  73. package/src/sshsig/formats.ts +1 -1
  74. package/src/sshsig/index.ts +3 -3
  75. package/src/sshsig/sig.ts +1 -1
  76. package/src/sshsig/sig_parser.ts +4 -4
  77. package/src/sshsig/verifier.ts +3 -3
  78. package/src/types.ts +27 -2
  79. package/src/utils.ts +11 -7
  80. package/src/verify.ts +3 -3
package/src/router.ts CHANGED
@@ -1,11 +1,10 @@
1
1
  import { fromHono } from "chanfana"
2
2
  import { Hono, type Context } from "hono"
3
- import { createApi as apiv3 } from "./api/v3"
3
+ import { createApi as apiv3 } from "./api/v3/index.js"
4
4
  import { HTTPException } from "hono/http-exception"
5
- import { logger } from "./logger"
6
- import type { SshCaBindings } from "./types"
5
+ import { logger } from "./logger.js"
6
+ import type { SshCaBindings } from "./types.js"
7
7
 
8
- export type CFArgs = [SshCaBindings, ExecutionContext]
9
8
  export type AppContext = Context<{ Bindings: SshCaBindings }>
10
9
 
11
10
  export const createApp = (env: SshCaBindings) => {
@@ -1,4 +1,4 @@
1
- import { Reader } from "./reader";
1
+ import { Reader } from "./reader.js";
2
2
 
3
3
  /**
4
4
  * Represents an SSH public key.
@@ -1,6 +1,6 @@
1
- import { Sig } from "./sig";
2
- import { verify as rawVerify } from "./verifier";
3
- import { parse } from "./sig_parser";
1
+ import { Sig } from "./sig.js";
2
+ import { verify as rawVerify } from "./verifier.js";
3
+ import { parse } from "./sig_parser.js";
4
4
 
5
5
  /**
6
6
  * Verifies SSH signature against provided data.
package/src/sshsig/sig.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Pubkey } from "./formats";
1
+ import { Pubkey } from "./formats.js";
2
2
 
3
3
  /**
4
4
  * Represents a parsed SSH signature.
@@ -1,7 +1,7 @@
1
- import { Sig } from "./sig";
2
- import { Reader } from "./reader";
3
- import { parsePubkey } from "./formats";
4
- import { dearmor } from "./armor";
1
+ import { Sig } from "./sig.js";
2
+ import { Reader } from "./reader.js";
3
+ import { parsePubkey } from "./formats.js";
4
+ import { dearmor } from "./armor.js";
5
5
 
6
6
  /**
7
7
  * ECDSA signature algorithms whose signatures need converting from SSH
@@ -1,6 +1,6 @@
1
- import { Sig } from "./sig";
2
- import { convertAlgorithm, convertHash, convertPublicKey } from "./formats";
3
- import { Writer } from "./writer";
1
+ import { Sig } from "./sig.js";
2
+ import { convertAlgorithm, convertHash, convertPublicKey } from "./formats.js";
3
+ import { Writer } from "./writer.js";
4
4
 
5
5
  export async function verify(
6
6
  subtle: SubtleCrypto,
package/src/types.ts CHANGED
@@ -26,10 +26,35 @@ export type SSHExtension = {
26
26
  data: Buffer<ArrayBuffer>
27
27
  }
28
28
 
29
+ /**
30
+ * The subset of a Cloudflare D1 database binding used by the CA.
31
+ *
32
+ * A Workers `D1Database` binding satisfies this structurally, so the package
33
+ * does not need to depend on `@cloudflare/workers-types`.
34
+ */
35
+ export interface CaDatabase {
36
+ prepare(query: string): unknown
37
+ batch(statements: never[]): Promise<unknown>
38
+ exec(query: string): Promise<unknown>
39
+ }
40
+
41
+ /**
42
+ * The subset of a Cloudflare Secrets Store binding used to load the CA private key.
43
+ *
44
+ * A Workers `SecretsStoreSecret` binding satisfies this structurally.
45
+ */
46
+ export interface CaSecret {
47
+ get(): Promise<string>
48
+ }
49
+
50
+ /**
51
+ * The bindings (environment) the CA expects, see {@link CaDatabase} and
52
+ * {@link CaSecret} for the non-string bindings.
53
+ */
29
54
  export interface SshCaBindings {
30
- DB: D1Database
55
+ DB: CaDatabase
31
56
  DB_CERTIFICATE_RETENTION: string
32
- PRIVATE_KEY: SecretsStoreSecret
57
+ PRIVATE_KEY: CaSecret
33
58
  SSH_CERTIFICATE_EXTENSIONS: string
34
59
  SSH_CERTIFICATE_LIFETIME: string
35
60
  SSH_CERTIFICATE_INCLUDE_SELF?: string | boolean
package/src/utils.ts CHANGED
@@ -1,15 +1,19 @@
1
- import type { SshCaBindings } from "./types"
1
+ import type { SshCaBindings } from "./types.js"
2
2
  import { JWKInvalid, JWKSInvalid, JWSInvalid, JWSSignatureVerificationFailed, JWTClaimValidationFailed, JWTExpired, JWTInvalid } from "jose/errors"
3
- import { Certificate, Key, KeyParseError, CertificateParseError, parseCertificate, parseKey, parsePrivateKey, PrivateKey } from "sshpk"
3
+ import sshpk from "sshpk"
4
+ import type { Certificate, Key, PrivateKey } from "sshpk"
4
5
  import z from "zod"
5
- import { verifyJWT } from "./verify"
6
- import { CertificateRequestJWTPayload } from "./types"
7
- import { RenewalProofOfPossession, ProofOfPossession, PossessionParseError } from "./proof"
8
- import type { isRevoked as IsRevokedFn } from "./db"
9
- import { logger } from "./logger"
6
+ import { verifyJWT } from "./verify.js"
7
+ import { CertificateRequestJWTPayload } from "./types.js"
8
+ import { RenewalProofOfPossession, ProofOfPossession, PossessionParseError } from "./proof.js"
9
+ import type { isRevoked as IsRevokedFn } from "./db/index.js"
10
+ import { logger } from "./logger.js"
10
11
  import { ms } from "itty-time"
11
12
  import { InternalServerErrorException } from "chanfana"
12
13
 
14
+ // sshpk is CommonJS and Node's ESM loader cannot detect most of its named exports, so values are taken from the default import
15
+ const { KeyParseError, CertificateParseError, parseCertificate, parseKey, parsePrivateKey } = sshpk
16
+
13
17
  export const fatalIssue = (ctx: z.RefinementCtx, message: string, val: unknown) => {
14
18
  ctx.issues.push({
15
19
  code: "custom",
package/src/verify.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createRemoteJWKSet, jwtVerify } from "jose"
2
- import { CertificateRequestJWTPayload } from "./types"
3
- import type { SshCaBindings } from "./types"
4
- import { split } from "./utils"
2
+ import { CertificateRequestJWTPayload } from "./types.js"
3
+ import type { SshCaBindings } from "./types.js"
4
+ import { split } from "./utils.js"
5
5
 
6
6
  type VerifyOptions = {
7
7
  aud?: string | string[]