| 1 |
/* cms.h - Internal definitions for the CMS functions |
| 2 |
* Copyright (C) 2001, 2012 g10 Code GmbH |
| 3 |
* |
| 4 |
* This file is part of KSBA. |
| 5 |
* |
| 6 |
* KSBA is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of either |
| 8 |
* |
| 9 |
* - the GNU Lesser General Public License as published by the Free |
| 10 |
* Software Foundation; either version 3 of the License, or (at |
| 11 |
* your option) any later version. |
| 12 |
* |
| 13 |
* or |
| 14 |
* |
| 15 |
* - the GNU General Public License as published by the Free |
| 16 |
* Software Foundation; either version 2 of the License, or (at |
| 17 |
* your option) any later version. |
| 18 |
* |
| 19 |
* or both in parallel, as here. |
| 20 |
* |
| 21 |
* KSBA is distributed in the hope that it will be useful, but WITHOUT |
| 22 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 23 |
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
| 24 |
* License for more details. |
| 25 |
* |
| 26 |
* You should have received a copies of the GNU General Public License |
| 27 |
* and the GNU Lesser General Public License along with this program; |
| 28 |
* if not, see <http://www.gnu.org/licenses/>. |
| 29 |
*/ |
| 30 |
|
| 31 |
#ifndef CMS_H |
| 32 |
#define CMS_H 1 |
| 33 |
|
| 34 |
#include "ksba.h" |
| 35 |
|
| 36 |
#ifndef HAVE_TYPEDEFD_ASNNODE |
| 37 |
typedef struct asn_node_struct *AsnNode; /* FIXME: should not go here */ |
| 38 |
#define HAVE_TYPEDEFD_ASNNODE |
| 39 |
#endif |
| 40 |
|
| 41 |
|
| 42 |
/* This structure is used to store the results of a BER parser run. */ |
| 43 |
struct value_tree_s { |
| 44 |
struct value_tree_s *next; |
| 45 |
AsnNode root; /* root of the tree with the values */ |
| 46 |
unsigned char *image; |
| 47 |
size_t imagelen; |
| 48 |
}; |
| 49 |
|
| 50 |
|
| 51 |
struct enc_val_s { |
| 52 |
char *algo; |
| 53 |
unsigned char *value; /* RSA's "a" or ECDH's "s". (malloced) */ |
| 54 |
size_t valuelen; |
| 55 |
struct { |
| 56 |
unsigned char *e; /* Malloced buffer. */ |
| 57 |
size_t elen; /* Length of E. */ |
| 58 |
char *encr_algo; /* Malloced OID string. */ |
| 59 |
char *wrap_algo; /* Malloced OID string. */ |
| 60 |
} ecdh; |
| 61 |
}; |
| 62 |
|
| 63 |
|
| 64 |
struct oidlist_s { |
| 65 |
struct oidlist_s *next; |
| 66 |
char *oid; |
| 67 |
}; |
| 68 |
|
| 69 |
/* A structure to store an OID and a parameter. */ |
| 70 |
struct oidparmlist_s { |
| 71 |
struct oidparmlist_s *next; |
| 72 |
int unprotected; /* Used by ksba_cms_add_attribute. */ |
| 73 |
int signeridx; /* Used by ksba_cms_add_attribute. */ |
| 74 |
char *oid; |
| 75 |
size_t parmlen; |
| 76 |
unsigned char parm[1]; |
| 77 |
}; |
| 78 |
|
| 79 |
|
| 80 |
struct certlist_s { |
| 81 |
struct certlist_s *next; |
| 82 |
ksba_cert_t cert; |
| 83 |
int msg_digest_len; /* used length of .. */ |
| 84 |
char msg_digest[64]; /* enough space to store a SHA-512 hash */ |
| 85 |
ksba_isotime_t signing_time; |
| 86 |
struct { |
| 87 |
AsnNode root; |
| 88 |
unsigned char *image; |
| 89 |
} sa; |
| 90 |
struct enc_val_s enc_val; /* used for creating enveloped data */ |
| 91 |
}; |
| 92 |
|
| 93 |
|
| 94 |
struct signer_info_s { |
| 95 |
struct signer_info_s *next; |
| 96 |
AsnNode root; /* root of the tree with the values */ |
| 97 |
unsigned char *image; |
| 98 |
size_t imagelen; |
| 99 |
struct { |
| 100 |
char *digest_algo; |
| 101 |
} cache; |
| 102 |
}; |
| 103 |
|
| 104 |
struct sig_val_s { |
| 105 |
struct sig_val_s *next; |
| 106 |
char *algo; |
| 107 |
unsigned char *value; /* Malloced buffer for parameter "s". */ |
| 108 |
size_t valuelen; /* Used length of VALUE. */ |
| 109 |
struct { |
| 110 |
unsigned char *r; /* Malloced buffer for parameter "r". */ |
| 111 |
size_t rlen; /* Length of R. */ |
| 112 |
} ecc; |
| 113 |
}; |
| 114 |
|
| 115 |
|
| 116 |
struct ksba_cms_s { |
| 117 |
gpg_error_t last_error; |
| 118 |
|
| 119 |
ksba_reader_t reader; |
| 120 |
ksba_writer_t writer; |
| 121 |
|
| 122 |
void (*hash_fnc)(void *, const void *, size_t); |
| 123 |
void *hash_fnc_arg; |
| 124 |
|
| 125 |
ksba_stop_reason_t stop_reason; |
| 126 |
|
| 127 |
struct { |
| 128 |
char *oid; |
| 129 |
unsigned long length; |
| 130 |
int ndef; |
| 131 |
ksba_content_type_t ct; |
| 132 |
gpg_error_t (*handler)(ksba_cms_t); |
| 133 |
} content; |
| 134 |
|
| 135 |
/* Data used with auth enveloped data. */ |
| 136 |
struct { |
| 137 |
unsigned char *mac; /* The MAC (authtag) */ |
| 138 |
int mac_len; |
| 139 |
unsigned char *attr; /* DER encoded authAttr. */ |
| 140 |
int attr_len; |
| 141 |
} authdata; |
| 142 |
|
| 143 |
int auth_mode; /* Flag indicating KSBA_CT_AUTHENVELOPED_DATA. */ |
| 144 |
int cms_version; |
| 145 |
|
| 146 |
struct oidlist_s *digest_algos; |
| 147 |
struct certlist_s *cert_list; |
| 148 |
char *inner_cont_oid; /* Encapsulated or Encrypted |
| 149 |
ContentInfo.contentType as string */ |
| 150 |
unsigned long inner_cont_len; |
| 151 |
int inner_cont_ndef; |
| 152 |
int detached_data; /* no actual data */ |
| 153 |
char *encr_algo_oid; |
| 154 |
char *encr_iv; |
| 155 |
size_t encr_ivlen; |
| 156 |
|
| 157 |
struct certlist_s *cert_info_list; /* A list with certificates intended |
| 158 |
to be send with a signed message */ |
| 159 |
|
| 160 |
struct oidparmlist_s *capability_list; /* A list of S/MIME capabilities. */ |
| 161 |
|
| 162 |
struct oidparmlist_s *attribute_list; /* A list of other attributes. */ |
| 163 |
|
| 164 |
struct signer_info_s *signer_info; |
| 165 |
|
| 166 |
struct value_tree_s *recp_info; |
| 167 |
|
| 168 |
struct sig_val_s *sig_val; |
| 169 |
|
| 170 |
struct enc_val_s *enc_val; |
| 171 |
}; |
| 172 |
|
| 173 |
|
| 174 |
/*-- cms.c --*/ |
| 175 |
|
| 176 |
|
| 177 |
/*-- cms-parser.c --*/ |
| 178 |
gpg_error_t _ksba_cms_parse_content_info (ksba_cms_t cms); |
| 179 |
gpg_error_t _ksba_cms_parse_signed_data_part_1 (ksba_cms_t cms); |
| 180 |
gpg_error_t _ksba_cms_parse_signed_data_part_2 (ksba_cms_t cms); |
| 181 |
gpg_error_t _ksba_cms_parse_enveloped_data_part_1 (ksba_cms_t cms); |
| 182 |
gpg_error_t _ksba_cms_parse_enveloped_data_part_2 (ksba_cms_t cms); |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
#endif /*CMS_H*/ |