/
crypto_none.cc
242 lines (201 loc) · 5.49 KB
/
crypto_none.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2005-2011 Free Software Foundation Europe e.V.
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
/*
* crypto_none.c Encryption support functions when no backend.
*
* Author: Landon Fuller <landonf@opendarwin.org>
*/
#include "include/bareos.h"
#if !defined(HAVE_OPENSSL)
#include "jcr.h"
#include <assert.h>
/* Message Digest Structure */
struct Digest {
crypto_digest_t type;
JobControlRecord *jcr;
union {
SHA1_CTX sha1;
MD5_CTX md5;
};
};
/* Dummy Signature Structure */
struct Signature {
JobControlRecord *jcr;
};
DIGEST *crypto_digest_new(JobControlRecord *jcr, crypto_digest_t type)
{
DIGEST *digest;
digest = (DIGEST *)malloc(sizeof(DIGEST));
digest->type = type;
digest->jcr = jcr;
switch (type) {
case CRYPTO_DIGEST_MD5:
MD5_Init(&digest->md5);
break;
case CRYPTO_DIGEST_SHA1:
SHA1Init(&digest->sha1);
break;
default:
Jmsg1(jcr, M_ERROR, 0, _("Unsupported digest type=%d specified\n"), type);
free(digest);
return NULL;
}
return (digest);
}
bool CryptoDigestUpdate(DIGEST *digest, const uint8_t *data, uint32_t length)
{
switch (digest->type) {
case CRYPTO_DIGEST_MD5:
/* Doesn't return anything ... */
MD5_Update(&digest->md5, (unsigned char *) data, length);
return true;
case CRYPTO_DIGEST_SHA1:
/* Doesn't return anything ... */
SHA1Update(&digest->sha1, (const u_int8_t *) data, (unsigned int)length);
return true;
default:
return false;
}
}
bool CryptoDigestFinalize(DIGEST *digest, uint8_t *dest, uint32_t *length)
{
switch (digest->type) {
case CRYPTO_DIGEST_MD5:
/* Guard against programmer error by either the API client or
* an out-of-sync CRYPTO_DIGEST_MAX_SIZE */
assert(*length >= CRYPTO_DIGEST_MD5_SIZE);
*length = CRYPTO_DIGEST_MD5_SIZE;
/* Doesn't return anything ... */
MD5_Final((unsigned char *)dest, &digest->md5);
return true;
case CRYPTO_DIGEST_SHA1:
/* Guard against programmer error by either the API client or
* an out-of-sync CRYPTO_DIGEST_MAX_SIZE */
assert(*length >= CRYPTO_DIGEST_SHA1_SIZE);
*length = CRYPTO_DIGEST_SHA1_SIZE;
SHA1Final((u_int8_t *) dest, &digest->sha1);
return true;
default:
return false;
}
return false;
}
void CryptoDigestFree(DIGEST *digest)
{
free(digest);
}
SIGNATURE *crypto_sign_new(JobControlRecord *jcr)
{
return NULL;
}
crypto_error_t CryptoSignGetDigest(SIGNATURE *sig, X509_KEYPAIR *keypair,
crypto_digest_t &type, DIGEST **digest)
{
return CRYPTO_ERROR_INTERNAL;
}
crypto_error_t CryptoSignVerify(SIGNATURE *sig, X509_KEYPAIR *keypair, DIGEST *digest)
{
return CRYPTO_ERROR_INTERNAL;
}
int CryptoSignAddSigner(SIGNATURE *sig, DIGEST *digest, X509_KEYPAIR *keypair)
{
return false;
}
int CryptoSignEncode(SIGNATURE *sig, uint8_t *dest, uint32_t *length)
{
return false;
}
SIGNATURE *crypto_sign_decode(JobControlRecord *jcr, const uint8_t *sigData, uint32_t length)
{
return NULL;
}
void CryptoSignFree(SIGNATURE *sig)
{
}
X509_KEYPAIR *crypto_keypair_new(void)
{
return NULL;
}
X509_KEYPAIR *crypto_keypair_dup(X509_KEYPAIR *keypair)
{
return NULL;
}
int CryptoKeypairLoadCert(X509_KEYPAIR *keypair, const char *file)
{
return false;
}
bool CryptoKeypairHasKey(const char *file)
{
return false;
}
int CryptoKeypairLoadKey(X509_KEYPAIR *keypair, const char *file, CRYPTO_PEM_PASSWD_CB *pem_callback, const void *pem_userdata)
{
return false;
}
void CryptoKeypairFree(X509_KEYPAIR *keypair)
{
}
CRYPTO_SESSION *crypto_session_new(crypto_cipher_t cipher, alist *pubkeys)
{
return NULL;
}
void CryptoSessionFree(CRYPTO_SESSION *cs)
{
}
bool CryptoSessionEncode(CRYPTO_SESSION *cs, uint8_t *dest, uint32_t *length)
{
return false;
}
crypto_error_t CryptoSessionDecode(const uint8_t *data, uint32_t length, alist *keypairs, CRYPTO_SESSION **session)
{
return CRYPTO_ERROR_INTERNAL;
}
CIPHER_CONTEXT *crypto_cipher_new(CRYPTO_SESSION *cs, bool encrypt, uint32_t *blocksize)
{
return NULL;
}
bool CryptoCipherUpdate(CIPHER_CONTEXT *cipher_ctx, const uint8_t *data, uint32_t length, const uint8_t *dest, uint32_t *written)
{
return false;
}
bool CryptoCipherFinalize(CIPHER_CONTEXT *cipher_ctx, uint8_t *dest, uint32_t *written)
{
return false;
}
void CryptoCipherFree(CIPHER_CONTEXT *cipher_ctx)
{
}
const char *crypto_digest_name(DIGEST *digest)
{
return crypto_digest_name(digest->type);
}
#endif /* HAVE_CRYPTO */
#if !defined(HAVE_OPENSSL) && \
!defined(HAVE_GNUTLS) && \
!defined(HAVE_NSS)
/*
* Dummy initialization functions when no crypto framework found.
*/
int InitCrypto(void)
{
return 0;
}
int CleanupCrypto(void)
{
return 0;
}
#endif /* !HAVE_OPENSSL && !HAVE_GNUTLS && !HAVE_NSS */