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