Coda Distributed File System
secure.h
Go to the documentation of this file.
1/* BLURB lgpl
2
3 Coda File System
4 Release 6
5
6 Copyright (c) 2005-2016 Carnegie Mellon University
7 Additional copyrights listed below
8
9This code is distributed "AS IS" without warranty of any kind under
10the terms of the GNU Library General Public Licence Version 2, as
11shown in the file LICENSE. The technical and financial contributors to
12Coda are listed in the file CREDITS.
13
14 Additional copyrights
15#*/
16
17#ifndef _RPC2_SECURE_H_
18#define _RPC2_SECURE_H_
19
20#include <sys/types.h>
21#include <sys/socket.h>
22#include <stdint.h>
23
24/* RFC2460 - Internet Protocol, Version 6 (IPv6) Specification
25 * Section 5 - Packet Size Issues
26 *
27 * a minimal IPv6 implementation (e.g., in a boot ROM) may simply restrict
28 * itself to sending packets no larger than 1280 octets, and omit
29 * implementation of Path MTU Discovery.
30 *...
31 * In response to an IPv6 packet that is sent to an IPv4 destination ... the
32 * IPv6 node is not required to reduce the size of subsequent packets to less
33 * than 1280, but must include a Fragment header ... this means the payload
34 * may have to be reduced to 1232 octets (1280 minus 40 for the IPv6 header
35 * and 8 for the Fragment header), and smaller still if additional extension
36 * headers are used.
37 *
38 * So until someone implements Path MTU Discovery, fragmentation, and
39 * reassembly in RPC2, we're just going to follow the minimal IPv6
40 * implementation guidelines.
41 *
42 * We limit the maximum packet size to: IPv6 minimum MTU - sizeof(IPv6 header) -
43 * sizeof(Fragment header) - sizeof(UDP header) = 1224
44 */
45//#define MAXPACKETSIZE (1280 - 40 - 8 - 8)
46
47/* sigh, the default ValidateAttrsPlusSHA packet (21 piggybacked fids) is
48 * exactly 1376 bytes, so we cannot be a drop-in replacement for existing
49 * clients and servers unless we support a larger MTU.
50 * I guess we'll keep the MTU the same as that used by RPC2 for now. */
51#define MAXPACKETSIZE (4500)
52
53#define MAXIVLEN 32
54#define MAXICVLEN 32
55
56/* Identifiers for authentication algorithms (IANA) */
57#define SECURE_ENCR_NULL 11
58#define SECURE_ENCR_AES_CBC 12
59//#define SECURE_ENCR_AES_CTR 13
60#define SECURE_ENCR_AES_CCM_8 14
61#define SECURE_ENCR_AES_CCM_12 15
62#define SECURE_ENCR_AES_CCM_16 16
63//#define SECURE_ENCR_AES_GCM_8 18
64//#define SECURE_ENCR_AES_GCM_12 19
65//#define SECURE_ENCR_AES_GCM_16 20
66
68 const int id;
69 const char *name;
70 int (*encrypt_init)(void **ctx, const uint8_t *key, size_t len);
71 void (*encrypt_free)(void **ctx);
72 int (*encrypt)(void *ctx, const uint8_t *in, uint8_t *out, size_t len,
73 uint8_t *iv, const uint8_t *aad, size_t aad_len);
74 int (*decrypt_init)(void **ctx, const uint8_t *key, size_t len);
75 void (*decrypt_free)(void **ctx);
76 int (*decrypt)(void *ctx, const uint8_t *in, uint8_t *out, size_t len,
77 const uint8_t *iv, const uint8_t *aad, size_t aad_len);
78 const size_t min_keysize;
79 const size_t max_keysize;
80 const size_t blocksize;
81 const size_t iv_len;
82 const size_t icv_len;
83};
84
85/* Identifiers for authentication algorithms (IANA) */
86#define SECURE_AUTH_NONE 0
87//#define SECURE_AUTH_HMAC_SHA_1_96 2
88#define SECURE_AUTH_AES_XCBC_96 9
89
91 const int id;
92 const char *name;
93 int (*auth_init)(void **ctx, const uint8_t *key, size_t len);
94 void (*auth_free)(void **ctx);
95 void (*auth)(void *ctx, const uint8_t *in, size_t len, uint8_t *icv);
96 const size_t keysize;
97 const size_t icv_len;
98};
99
101 /* incoming packets */
102
103 /* identifier to match an incoming packet with the the correct logical
104 * connection. Really only here for the convenience of the application,
105 * it is not used by secure_recvfrom. Security identifiers < 256 are
106 * considered 'reserved', see secure_sendto/secure_recvfrom */
108
109 /* The following are used for to detect replay attacks and should be
110 * initialized to 0 */
112 unsigned long recv_win;
113
114 /* function descriptor and state for packet validation */
115 const struct secure_auth *validate;
117
118 /* function descriptor and state for decryption */
119 const struct secure_encr *decrypt;
121
122 /* outgoing packets */
123 /* remote connection identifier */
125
126 /* sequence number used for outgoing packets, should be initialized to 0 */
128
129 /* trusted address of the peer, outgoing encrypted packets will be sent to
130 * this address, this will be updates when we receive a packet that
131 * is correctly validated */
134
135 /* initialization vector/counter, should be initialized to a random value,
136 * secure_sendto will properly increment it */
138
139 /* function descriptor and context for encryption */
140 const struct secure_encr *encrypt;
142
143 /* function descriptor and context for packet authentication */
146};
147
148/* initialization */
149void secure_init(int verbose);
150void secure_release(void);
151
152const struct secure_auth *secure_get_auth_byid(int id);
153const struct secure_encr *secure_get_encr_byid(int id);
154
155/* version 0 - was using incorrect AES-CCM counter block initialization */
156#define SECURE_VERSION 1
157int secure_setup_encrypt(uint32_t secure_version,
158 struct security_association *sa,
159 const struct secure_auth *authenticate,
160 const struct secure_encr *encrypt, const uint8_t *key,
161 size_t len);
162int secure_setup_decrypt(uint32_t secure_version,
163 struct security_association *sa,
164 const struct secure_auth *validate,
165 const struct secure_encr *decrypt, const uint8_t *key,
166 size_t len);
167
168/* Password based key derivation function */
169#define SECURE_PBKDF_ITERATIONS 10000 /* see comments in secure_aes.c */
170int secure_pbkdf(const uint8_t *password, size_t plen, const uint8_t *salt,
171 size_t slen, size_t iterations, uint8_t *key, size_t keylen);
172
173/* cryptographically strong deterministic pseudo random number generator */
174void secure_random_bytes(void *buf, size_t len);
175
176/* low level socket interface */
177ssize_t secure_sendto(int s, const void *buf, size_t len, int flags,
178 /* to/tolen only used to send non-encrypted packets */
179 const struct sockaddr *to, socklen_t tolen,
180 struct security_association *sa);
181
182ssize_t secure_recvfrom(int s, void *buf, size_t len, int flags,
183 struct sockaddr *peer, socklen_t *peerlen, /*untrusted*/
184 struct security_association **sa,
185 struct security_association *(*GETSA)(uint32_t spi));
186
187/* time-constant comparison */
188int secure_compare(const void *user_data, size_t user_len, const void *secret,
189 size_t secret_len);
190
191#endif /* _RPC2_SECURE_H_ */
unsigned int uint32_t
Definition: coda.h:105
unsigned char uint8_t
Definition: coda.h:101
int socklen_t
Definition: mariner.cc:73
int verbose
Definition: mkcodabf.c:30
def validate(configuration)
Definition: make_certs.py:157
void encrypt(char *buff)
Definition: rijndael-mikescott.c:267
void decrypt(char *buff)
Definition: rijndael-mikescott.c:314
int secure_setup_decrypt(uint32_t secure_version, struct security_association *sa, const struct secure_auth *validate, const struct secure_encr *decrypt, const uint8_t *key, size_t len)
Definition: secure_setup.c:77
int secure_compare(const void *user_data, size_t user_len, const void *secret, size_t secret_len)
Definition: secure_init.c:147
const struct secure_auth * secure_get_auth_byid(int id)
Definition: secure_init.c:70
int secure_setup_encrypt(uint32_t secure_version, struct security_association *sa, const struct secure_auth *authenticate, const struct secure_encr *encrypt, const uint8_t *key, size_t len)
Definition: secure_setup.c:24
int secure_pbkdf(const uint8_t *password, size_t plen, const uint8_t *salt, size_t slen, size_t iterations, uint8_t *key, size_t keylen)
Definition: secure_pbkdf.c:51
ssize_t secure_sendto(int s, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen, struct security_association *sa)
Definition: secure_sendto.c:30
void secure_init(int verbose)
Definition: secure_init.c:49
void secure_random_bytes(void *buf, size_t len)
Definition: secure_random.c:365
ssize_t secure_recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *peer, socklen_t *peerlen, struct security_association **sa, struct security_association *(*GETSA)(uint32_t spi))
Definition: secure_recvfrom.c:156
#define MAXIVLEN
Definition: secure.h:53
const struct secure_encr * secure_get_encr_byid(int id)
Definition: secure_init.c:78
void secure_release(void)
Definition: secure_init.c:64
Definition: secure.h:90
void(* auth_free)(void **ctx)
Definition: secure.h:94
const int id
Definition: secure.h:91
const char * name
Definition: secure.h:92
const size_t icv_len
Definition: secure.h:97
int(* auth_init)(void **ctx, const uint8_t *key, size_t len)
Definition: secure.h:93
void(* auth)(void *ctx, const uint8_t *in, size_t len, uint8_t *icv)
Definition: secure.h:95
const size_t keysize
Definition: secure.h:96
Definition: secure.h:67
void(* encrypt_free)(void **ctx)
Definition: secure.h:71
void(* decrypt_free)(void **ctx)
Definition: secure.h:75
int(* decrypt_init)(void **ctx, const uint8_t *key, size_t len)
Definition: secure.h:74
const size_t max_keysize
Definition: secure.h:79
const size_t icv_len
Definition: secure.h:82
int(* encrypt_init)(void **ctx, const uint8_t *key, size_t len)
Definition: secure.h:70
const size_t iv_len
Definition: secure.h:81
const size_t min_keysize
Definition: secure.h:78
int(* decrypt)(void *ctx, const uint8_t *in, uint8_t *out, size_t len, const uint8_t *iv, const uint8_t *aad, size_t aad_len)
Definition: secure.h:76
const int id
Definition: secure.h:68
const char * name
Definition: secure.h:69
int(* encrypt)(void *ctx, const uint8_t *in, uint8_t *out, size_t len, uint8_t *iv, const uint8_t *aad, size_t aad_len)
Definition: secure.h:72
const size_t blocksize
Definition: secure.h:80
Definition: secure.h:100
unsigned long recv_win
Definition: secure.h:112
void * encrypt_context
Definition: secure.h:141
uint32_t peer_spi
Definition: secure.h:124
uint32_t peer_seq
Definition: secure.h:127
void * validate_context
Definition: secure.h:116
const struct secure_auth * authenticate
Definition: secure.h:144
struct sockaddr_storage peer
Definition: secure.h:132
void * authenticate_context
Definition: secure.h:145
uint32_t recv_seq
Definition: secure.h:111
const struct secure_auth * validate
Definition: secure.h:115
socklen_t peerlen
Definition: secure.h:133
const struct secure_encr * encrypt
Definition: secure.h:140
uint32_t recv_spi
Definition: secure.h:107
uint8_t send_iv[MAXIVLEN]
Definition: secure.h:137
const struct secure_encr * decrypt
Definition: secure.h:119
void * decrypt_context
Definition: secure.h:120
Definition: rpc2.private.h:63