1
0

hooks.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80: */
  2. /*
  3. * Copyright 2016 Red Hat, Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #pragma once
  18. #include <jose/jws.h>
  19. #include <jose/jwe.h>
  20. #define MAX_COMPRESSED_SIZE (256*1024)
  21. typedef enum {
  22. JOSE_HOOK_JWK_KIND_NONE = 0,
  23. JOSE_HOOK_JWK_KIND_TYPE,
  24. JOSE_HOOK_JWK_KIND_OPER,
  25. JOSE_HOOK_JWK_KIND_PREP,
  26. JOSE_HOOK_JWK_KIND_MAKE,
  27. JOSE_HOOK_JWK_KIND_LAST = JOSE_HOOK_JWK_KIND_MAKE
  28. } jose_hook_jwk_kind_t;
  29. typedef enum {
  30. JOSE_HOOK_ALG_KIND_NONE = 0,
  31. JOSE_HOOK_ALG_KIND_HASH,
  32. JOSE_HOOK_ALG_KIND_SIGN,
  33. JOSE_HOOK_ALG_KIND_WRAP,
  34. JOSE_HOOK_ALG_KIND_ENCR,
  35. JOSE_HOOK_ALG_KIND_COMP,
  36. JOSE_HOOK_ALG_KIND_EXCH,
  37. JOSE_HOOK_ALG_KIND_LAST = JOSE_HOOK_ALG_KIND_EXCH
  38. } jose_hook_alg_kind_t;
  39. typedef struct jose_hook_jwk jose_hook_jwk_t;
  40. struct jose_hook_jwk {
  41. const jose_hook_jwk_t *next;
  42. jose_hook_jwk_kind_t kind;
  43. union {
  44. struct {
  45. const char *kty;
  46. const char **req;
  47. const char **pub;
  48. const char **prv;
  49. } type;
  50. struct {
  51. const char *pub;
  52. const char *prv;
  53. const char *use;
  54. } oper;
  55. struct {
  56. bool
  57. (*handles)(jose_cfg_t *cfg, const json_t *jwk);
  58. bool
  59. (*execute)(jose_cfg_t *cfg, json_t *jwk);
  60. } prep;
  61. struct {
  62. bool
  63. (*handles)(jose_cfg_t *cfg, const json_t *jwk);
  64. bool
  65. (*execute)(jose_cfg_t *cfg, json_t *jwk);
  66. } make;
  67. };
  68. };
  69. typedef struct jose_hook_alg jose_hook_alg_t;
  70. struct jose_hook_alg {
  71. const jose_hook_alg_t *next;
  72. jose_hook_alg_kind_t kind;
  73. const char *name;
  74. union {
  75. struct {
  76. size_t size;
  77. jose_io_t *
  78. (*hsh)(const jose_hook_alg_t *alg, jose_cfg_t *cfg, jose_io_t *next);
  79. } hash;
  80. struct {
  81. const char *sprm;
  82. const char *vprm;
  83. const char *
  84. (*sug)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  85. const json_t *jwk);
  86. jose_io_t *
  87. (*sig)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  88. json_t *jws, json_t *sig, const json_t *jwk);
  89. jose_io_t *
  90. (*ver)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  91. const json_t *jws, const json_t *sig, const json_t *jwk);
  92. } sign;
  93. struct {
  94. const char *eprm;
  95. const char *dprm;
  96. const char *
  97. (*alg)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  98. const json_t *jwk);
  99. const char *
  100. (*enc)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  101. const json_t *jwk);
  102. bool
  103. (*wrp)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  104. json_t *jwe, json_t *rcp,
  105. const json_t *jwk, json_t *cek);
  106. bool
  107. (*unw)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  108. const json_t *jwe, const json_t *rcp,
  109. const json_t *jwk, json_t *cek);
  110. } wrap;
  111. struct {
  112. const char *eprm;
  113. const char *dprm;
  114. const char *
  115. (*sug)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  116. const json_t *cek);
  117. jose_io_t *
  118. (*enc)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  119. json_t *jwe, const json_t *cek, jose_io_t *next);
  120. jose_io_t *
  121. (*dec)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  122. const json_t *jwe, const json_t *cek, jose_io_t *next);
  123. } encr;
  124. struct {
  125. jose_io_t *
  126. (*def)(const jose_hook_alg_t *alg, jose_cfg_t *cfg, jose_io_t *next);
  127. jose_io_t *
  128. (*inf)(const jose_hook_alg_t *alg, jose_cfg_t *cfg, jose_io_t *next);
  129. } comp;
  130. struct {
  131. const char *prm;
  132. const char *
  133. (*sug)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  134. const json_t *prv, const json_t *pub);
  135. json_t *
  136. (*exc)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  137. const json_t *prv, const json_t *pub);
  138. } exch;
  139. };
  140. };
  141. void
  142. jose_hook_jwk_push(jose_hook_jwk_t *reg);
  143. const jose_hook_jwk_t *
  144. jose_hook_jwk_list(void);
  145. void
  146. jose_hook_alg_push(jose_hook_alg_t *alg);
  147. const jose_hook_alg_t *
  148. jose_hook_alg_list(void);
  149. const jose_hook_alg_t *
  150. jose_hook_alg_find(jose_hook_alg_kind_t kind, const char *name);
  151. const jose_hook_alg_t *
  152. jose_hook_alg_find_any(const char *name);