hooks.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. typedef enum {
  21. JOSE_HOOK_JWK_KIND_NONE = 0,
  22. JOSE_HOOK_JWK_KIND_TYPE,
  23. JOSE_HOOK_JWK_KIND_OPER,
  24. JOSE_HOOK_JWK_KIND_PREP,
  25. JOSE_HOOK_JWK_KIND_MAKE,
  26. JOSE_HOOK_JWK_KIND_LAST = JOSE_HOOK_JWK_KIND_MAKE
  27. } jose_hook_jwk_kind_t;
  28. typedef enum {
  29. JOSE_HOOK_ALG_KIND_NONE = 0,
  30. JOSE_HOOK_ALG_KIND_HASH,
  31. JOSE_HOOK_ALG_KIND_SIGN,
  32. JOSE_HOOK_ALG_KIND_WRAP,
  33. JOSE_HOOK_ALG_KIND_ENCR,
  34. JOSE_HOOK_ALG_KIND_COMP,
  35. JOSE_HOOK_ALG_KIND_EXCH,
  36. JOSE_HOOK_ALG_KIND_LAST = JOSE_HOOK_ALG_KIND_EXCH
  37. } jose_hook_alg_kind_t;
  38. typedef struct jose_hook_jwk jose_hook_jwk_t;
  39. struct jose_hook_jwk {
  40. const jose_hook_jwk_t *next;
  41. jose_hook_jwk_kind_t kind;
  42. union {
  43. struct {
  44. const char *kty;
  45. const char **req;
  46. const char **pub;
  47. const char **prv;
  48. } type;
  49. struct {
  50. const char *pub;
  51. const char *prv;
  52. const char *use;
  53. } oper;
  54. struct {
  55. bool
  56. (*handles)(jose_cfg_t *cfg, const json_t *jwk);
  57. json_t *
  58. (*execute)(jose_cfg_t *cfg, const json_t *jwk);
  59. } prep;
  60. struct {
  61. bool
  62. (*handles)(jose_cfg_t *cfg, const json_t *jwk);
  63. json_t *
  64. (*execute)(jose_cfg_t *cfg, const json_t *jwk);
  65. } make;
  66. };
  67. };
  68. typedef struct jose_hook_alg jose_hook_alg_t;
  69. struct jose_hook_alg {
  70. const jose_hook_alg_t *next;
  71. jose_hook_alg_kind_t kind;
  72. const char *name;
  73. union {
  74. struct {
  75. size_t size;
  76. jose_io_t *
  77. (*hsh)(const jose_hook_alg_t *alg, jose_cfg_t *cfg, jose_io_t *next);
  78. } hash;
  79. struct {
  80. const char *sprm;
  81. const char *vprm;
  82. const char *
  83. (*sug)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  84. const json_t *jwk);
  85. jose_io_t *
  86. (*sig)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  87. json_t *jws, json_t *sig, const json_t *jwk);
  88. jose_io_t *
  89. (*ver)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  90. const json_t *jws, const json_t *sig, const json_t *jwk);
  91. } sign;
  92. struct {
  93. const char *eprm;
  94. const char *dprm;
  95. const char *
  96. (*alg)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  97. const json_t *jwk);
  98. const char *
  99. (*enc)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  100. const json_t *jwk);
  101. bool
  102. (*wrp)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  103. json_t *jwe, json_t *rcp,
  104. const json_t *jwk, json_t *cek);
  105. bool
  106. (*unw)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  107. const json_t *jwe, const json_t *rcp,
  108. const json_t *jwk, json_t *cek);
  109. } wrap;
  110. struct {
  111. const char *eprm;
  112. const char *dprm;
  113. const char *
  114. (*sug)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  115. const json_t *cek);
  116. jose_io_t *
  117. (*enc)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  118. json_t *jwe, const json_t *cek, jose_io_t *next);
  119. jose_io_t *
  120. (*dec)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  121. const json_t *jwe, const json_t *cek, jose_io_t *next);
  122. } encr;
  123. struct {
  124. jose_io_t *
  125. (*def)(const jose_hook_alg_t *alg, jose_cfg_t *cfg, jose_io_t *next);
  126. jose_io_t *
  127. (*inf)(const jose_hook_alg_t *alg, jose_cfg_t *cfg, jose_io_t *next);
  128. } comp;
  129. struct {
  130. const char *prm;
  131. const char *
  132. (*sug)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  133. const json_t *prv, const json_t *pub);
  134. json_t *
  135. (*exc)(const jose_hook_alg_t *alg, jose_cfg_t *cfg,
  136. const json_t *prv, const json_t *pub);
  137. } exch;
  138. };
  139. };
  140. void
  141. jose_hook_jwk_push(jose_hook_jwk_t *reg);
  142. const jose_hook_jwk_t *
  143. jose_hook_jwk_list(void);
  144. void
  145. jose_hook_alg_push(jose_hook_alg_t *alg);
  146. const jose_hook_alg_t *
  147. jose_hook_alg_list(void);
  148. const jose_hook_alg_t *
  149. jose_hook_alg_find(jose_hook_alg_kind_t kind, const char *name);