| 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 |
#include <assert.h> |
|---|
| 30 |
#include <ctype.h> |
|---|
| 31 |
#include <stdlib.h> |
|---|
| 32 |
#include <time.h> |
|---|
| 33 |
|
|---|
| 34 |
#include "mapserver.h" |
|---|
| 35 |
|
|---|
| 36 |
MS_CVSID("$Id$") |
|---|
| 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 |
static void encipher(const ms_uint32 *const v, ms_uint32 *const w, |
|---|
| 88 |
const ms_uint32 *const k) |
|---|
| 89 |
{ |
|---|
| 90 |
register ms_uint32 y=v[0],z=v[1],sum=0,delta=0x9E3779B9,n=32; |
|---|
| 91 |
|
|---|
| 92 |
while(n-->0) |
|---|
| 93 |
{ |
|---|
| 94 |
y += ((z << 4 ^ z >> 5) + z) ^ (sum + k[sum&3]); |
|---|
| 95 |
sum += delta; |
|---|
| 96 |
z += ((y << 4 ^ y >> 5) + y) ^ (sum + k[sum>>11 & 3]); |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
w[0]=y; w[1]=z; |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
static void decipher(const ms_uint32 *const v, ms_uint32 *const w, |
|---|
| 103 |
const ms_uint32 *const k) |
|---|
| 104 |
{ |
|---|
| 105 |
register ms_uint32 y=v[0],z=v[1],sum=0xC6EF3720, delta=0x9E3779B9,n=32; |
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
while(n-->0) |
|---|
| 110 |
{ |
|---|
| 111 |
z -= ((y << 4 ^ y >> 5) + y) ^ (sum + k[sum>>11 & 3]); |
|---|
| 112 |
sum -= delta; |
|---|
| 113 |
y -= ((z << 4 ^ z >> 5) + z) ^ (sum + k[sum&3]); |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
w[0]=y; w[1]=z; |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
void msHexEncode(const unsigned char *in, char *out, int numbytes) |
|---|
| 128 |
{ |
|---|
| 129 |
char *hex = "0123456789ABCDEF"; |
|---|
| 130 |
|
|---|
| 131 |
while (numbytes-- > 0) |
|---|
| 132 |
{ |
|---|
| 133 |
*out++ = hex[*in/16]; |
|---|
| 134 |
*out++ = hex[*in%16]; |
|---|
| 135 |
in++; |
|---|
| 136 |
} |
|---|
| 137 |
*out = '\0'; |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
int msHexDecode(const char *in, unsigned char *out, int numchars) |
|---|
| 155 |
{ |
|---|
| 156 |
int numbytes_out = 0; |
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
numchars = (numchars/2) * 2; |
|---|
| 160 |
|
|---|
| 161 |
if (numchars < 2) |
|---|
| 162 |
numchars = -1; |
|---|
| 163 |
|
|---|
| 164 |
while (*in != '\0' && *(in+1) != '\0' && numchars != 0) |
|---|
| 165 |
{ |
|---|
| 166 |
*out = 0x10 * (*in >= 'A' ? ((*in & 0xdf) - 'A')+10 : (*in - '0')); |
|---|
| 167 |
in++; |
|---|
| 168 |
*out += (*in >= 'A' ? ((*in & 0xdf) - 'A')+10 : (*in - '0')); |
|---|
| 169 |
in++; |
|---|
| 170 |
|
|---|
| 171 |
out++; |
|---|
| 172 |
numbytes_out++; |
|---|
| 173 |
|
|---|
| 174 |
numchars -= 2; |
|---|
| 175 |
} |
|---|
| 176 |
|
|---|
| 177 |
return numbytes_out; |
|---|
| 178 |
} |
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
int msGenerateEncryptionKey(unsigned char *k) |
|---|
| 190 |
{ |
|---|
| 191 |
int i; |
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
srand( (unsigned int) time( NULL )); |
|---|
| 195 |
|
|---|
| 196 |
for(i=0; i<MS_ENCRYPTION_KEY_SIZE; i++) |
|---|
| 197 |
k[i] = (unsigned char)rand(); |
|---|
| 198 |
|
|---|
| 199 |
return MS_SUCCESS; |
|---|
| 200 |
} |
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
int msReadEncryptionKeyFromFile(const char *keyfile, unsigned char *k) |
|---|
| 213 |
{ |
|---|
| 214 |
FILE *fp; |
|---|
| 215 |
char szBuf[100]; |
|---|
| 216 |
int numchars; |
|---|
| 217 |
|
|---|
| 218 |
if ((fp = fopen(keyfile, "rt")) == NULL) |
|---|
| 219 |
{ |
|---|
| 220 |
msSetError(MS_MISCERR, "Cannot open key file.", |
|---|
| 221 |
"msReadEncryptionKeyFromFile()"); |
|---|
| 222 |
return MS_FAILURE; |
|---|
| 223 |
} |
|---|
| 224 |
|
|---|
| 225 |
numchars = fread(szBuf, sizeof(unsigned char), MS_ENCRYPTION_KEY_SIZE*2, fp); |
|---|
| 226 |
fclose(fp); |
|---|
| 227 |
szBuf[MS_ENCRYPTION_KEY_SIZE*2] = '\0'; |
|---|
| 228 |
|
|---|
| 229 |
if (numchars != MS_ENCRYPTION_KEY_SIZE*2) |
|---|
| 230 |
{ |
|---|
| 231 |
msSetError(MS_MISCERR, "Invalid key file, got %d chars, expected %d.", |
|---|
| 232 |
"msReadEncryptionKeyFromFile()", |
|---|
| 233 |
numchars, MS_ENCRYPTION_KEY_SIZE*2); |
|---|
| 234 |
return MS_FAILURE; |
|---|
| 235 |
} |
|---|
| 236 |
|
|---|
| 237 |
msHexDecode(szBuf, k, MS_ENCRYPTION_KEY_SIZE*2); |
|---|
| 238 |
|
|---|
| 239 |
return MS_SUCCESS; |
|---|
| 240 |
} |
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
static int msLoadEncryptionKey(mapObj *map) |
|---|
| 261 |
{ |
|---|
| 262 |
const char *keyfile; |
|---|
| 263 |
|
|---|
| 264 |
if (map == NULL) |
|---|
| 265 |
{ |
|---|
| 266 |
msSetError(MS_MISCERR, "NULL MapObj.", "msLoadEncryptionKey()"); |
|---|
| 267 |
return MS_FAILURE; |
|---|
| 268 |
} |
|---|
| 269 |
|
|---|
| 270 |
if (map->encryption_key_loaded) |
|---|
| 271 |
return MS_SUCCESS; |
|---|
| 272 |
|
|---|
| 273 |
keyfile = msGetConfigOption(map, "MS_ENCRYPTION_KEY"); |
|---|
| 274 |
|
|---|
| 275 |
if (keyfile == NULL) |
|---|
| 276 |
keyfile = getenv("MS_ENCRYPTION_KEY"); |
|---|
| 277 |
|
|---|
| 278 |
if (keyfile && |
|---|
| 279 |
msReadEncryptionKeyFromFile(keyfile,map->encryption_key) == MS_SUCCESS) |
|---|
| 280 |
{ |
|---|
| 281 |
map->encryption_key_loaded = MS_TRUE; |
|---|
| 282 |
} |
|---|
| 283 |
else |
|---|
| 284 |
{ |
|---|
| 285 |
msSetError(MS_MISCERR, "Failed reading encryption key. Make sure " |
|---|
| 286 |
"MS_ENCRYPTION_KEY is set and points to a valid key file.", |
|---|
| 287 |
"msLoadEncryptionKey()"); |
|---|
| 288 |
return MS_FAILURE; |
|---|
| 289 |
} |
|---|
| 290 |
|
|---|
| 291 |
return MS_SUCCESS; |
|---|
| 292 |
} |
|---|
| 293 |
|
|---|
| 294 |
|
|---|
| 295 |
|
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 |
void msEncryptStringWithKey(const unsigned char *key, const char *in, char *out) |
|---|
| 304 |
{ |
|---|
| 305 |
ms_uint32 v[4], w[4]; |
|---|
| 306 |
const ms_uint32 *k; |
|---|
| 307 |
int last_block = MS_FALSE; |
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
assert(sizeof(ms_uint32) == 4); |
|---|
| 312 |
k = (const ms_uint32 *) key; |
|---|
| 313 |
|
|---|
| 314 |
while(!last_block) |
|---|
| 315 |
{ |
|---|
| 316 |
int i, j; |
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
|
|---|
| 320 |
|
|---|
| 321 |
v[0] = 0; |
|---|
| 322 |
v[1] = 0; |
|---|
| 323 |
for(i=0; !last_block && i<2; i++) |
|---|
| 324 |
{ |
|---|
| 325 |
for(j=0; j<4; j++) |
|---|
| 326 |
{ |
|---|
| 327 |
if (*in == '\0') |
|---|
| 328 |
{ |
|---|
| 329 |
last_block = MS_TRUE; |
|---|
| 330 |
break; |
|---|
| 331 |
} |
|---|
| 332 |
|
|---|
| 333 |
v[i] |= *in << (j*8); |
|---|
| 334 |
in++; |
|---|
| 335 |
} |
|---|
| 336 |
} |
|---|
| 337 |
|
|---|
| 338 |
if (*in == '\0') |
|---|
| 339 |
last_block = MS_TRUE; |
|---|
| 340 |
|
|---|
| 341 |
|
|---|
| 342 |
encipher(v, w, k); |
|---|
| 343 |
|
|---|
| 344 |
|
|---|
| 345 |
msHexEncode((unsigned char *)w, out, 4); |
|---|
| 346 |
out += 8; |
|---|
| 347 |
msHexEncode((unsigned char *)(w+1), out, 4); |
|---|
| 348 |
out += 8; |
|---|
| 349 |
|
|---|
| 350 |
} |
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
*out = '\0'; |
|---|
| 354 |
} |
|---|
| 355 |
|
|---|
| 356 |
|
|---|
| 357 |
|
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
void msDecryptStringWithKey(const unsigned char *key, const char *in, char *out) |
|---|
| 366 |
{ |
|---|
| 367 |
ms_uint32 v[4], w[4]; |
|---|
| 368 |
const ms_uint32 *k; |
|---|
| 369 |
int last_block = MS_FALSE; |
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 373 |
assert(sizeof(ms_uint32) == 4); |
|---|
| 374 |
k = (const ms_uint32 *) key; |
|---|
| 375 |
|
|---|
| 376 |
while(!last_block) |
|---|
| 377 |
{ |
|---|
| 378 |
int i; |
|---|
| 379 |
|
|---|
| 380 |
|
|---|
| 381 |
|
|---|
| 382 |
|
|---|
| 383 |
v[0] = 0; |
|---|
| 384 |
v[1] = 0; |
|---|
| 385 |
|
|---|
| 386 |
if (msHexDecode(in, (unsigned char *)v, 8) != 4) |
|---|
| 387 |
last_block = MS_TRUE; |
|---|
| 388 |
else |
|---|
| 389 |
{ |
|---|
| 390 |
in += 8; |
|---|
| 391 |
if (msHexDecode(in, (unsigned char *)(v+1), 8) != 4) |
|---|
| 392 |
last_block = MS_TRUE; |
|---|
| 393 |
else |
|---|
| 394 |
in += 8; |
|---|
| 395 |
} |
|---|
| 396 |
|
|---|
| 397 |
|
|---|
| 398 |
decipher(v, w, k); |
|---|
| 399 |
|
|---|
| 400 |
|
|---|
| 401 |
for(i=0; i<2; i++) |
|---|
| 402 |
{ |
|---|
| 403 |
*out++ = (w[i] & 0x000000ff); |
|---|
| 404 |
*out++ = (w[i] & 0x0000ff00) >> 8; |
|---|
| 405 |
*out++ = (w[i] & 0x00ff0000) >> 16; |
|---|
| 406 |
*out++ = (w[i] & 0xff000000) >> 24; |
|---|
| 407 |
} |
|---|
| 408 |
|
|---|
| 409 |
if (*in == '\0') |
|---|
| 410 |
last_block = MS_TRUE; |
|---|
| 411 |
} |
|---|
| 412 |
|
|---|
| 413 |
|
|---|
| 414 |
*out = '\0'; |
|---|
| 415 |
} |
|---|
| 416 |
|
|---|
| 417 |
|
|---|
| 418 |
|
|---|
| 419 |
|
|---|
| 420 |
|
|---|
| 421 |
|
|---|
| 422 |
|
|---|
| 423 |
|
|---|
| 424 |
|
|---|
| 425 |
|
|---|
| 426 |
char *msDecryptStringTokens(mapObj *map, const char *in) |
|---|
| 427 |
{ |
|---|
| 428 |
char *outbuf, *out; |
|---|
| 429 |
|
|---|
| 430 |
if (map == NULL) |
|---|
| 431 |
{ |
|---|
| 432 |
msSetError(MS_MISCERR, "NULL MapObj.", "msLoadEncryptionKey()"); |
|---|
| 433 |
return NULL; |
|---|
| 434 |
} |
|---|
| 435 |
|
|---|
| 436 |
|
|---|
| 437 |
|
|---|
| 438 |
if ((outbuf = (char *)malloc((strlen(in)+1)*sizeof(char))) == NULL) |
|---|
| 439 |
{ |
|---|
| 440 |
msSetError(MS_MEMERR, NULL, "msDecryptStringTokens()"); |
|---|
| 441 |
return NULL; |
|---|
| 442 |
} |
|---|
| 443 |
out = outbuf; |
|---|
| 444 |
|
|---|
| 445 |
while(*in != '\0') |
|---|
| 446 |
{ |
|---|
| 447 |
if (*in == '{') |
|---|
| 448 |
{ |
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
|
|---|
| 452 |
const char *pszStart, *pszEnd; |
|---|
| 453 |
int valid_token = MS_FALSE; |
|---|
| 454 |
|
|---|
| 455 |
pszStart = in+1; |
|---|
| 456 |
if ( (pszEnd = strchr(pszStart, '}')) != NULL && |
|---|
| 457 |
pszEnd - pszStart > 1) |
|---|
| 458 |
{ |
|---|
| 459 |
const char *pszTmp; |
|---|
| 460 |
valid_token = MS_TRUE; |
|---|
| 461 |
for(pszTmp = pszStart; pszTmp < pszEnd; pszTmp++) |
|---|
| 462 |
{ |
|---|
| 463 |
if (!isxdigit(*pszTmp)) |
|---|
| 464 |
{ |
|---|
| 465 |
valid_token = MS_FALSE; |
|---|
| 466 |
break; |
|---|
| 467 |
} |
|---|
| 468 |
} |
|---|
| 469 |
} |
|---|
| 470 |
|
|---|
| 471 |
if (valid_token) |
|---|
| 472 |
{ |
|---|
| 473 |
|
|---|
| 474 |
char *pszTmp; |
|---|
| 475 |
|
|---|
| 476 |
|
|---|
| 477 |
|
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
if (msLoadEncryptionKey(map) != MS_SUCCESS) |
|---|
| 482 |
return NULL; |
|---|
| 483 |
|
|---|
| 484 |
pszTmp = (char*)malloc( (pszEnd-pszStart+1)*sizeof(char)); |
|---|
| 485 |
strncpy(pszTmp, pszStart, pszEnd-pszStart); |
|---|
| 486 |
pszTmp[pszEnd-pszStart] = '\0'; |
|---|
| 487 |
|
|---|
| 488 |
msDecryptStringWithKey(map->encryption_key, pszTmp, out); |
|---|
| 489 |
|
|---|
| 490 |
out += strlen(out); |
|---|
| 491 |
in = pszEnd+1; |
|---|
| 492 |
} |
|---|
| 493 |
else |
|---|
| 494 |
{ |
|---|
| 495 |
|
|---|
| 496 |
*out++ = *in++; |
|---|
| 497 |
} |
|---|
| 498 |
} |
|---|
| 499 |
else |
|---|
| 500 |
{ |
|---|
| 501 |
|
|---|
| 502 |
*out++ = *in++; |
|---|
| 503 |
} |
|---|
| 504 |
} |
|---|
| 505 |
*out = '\0'; |
|---|
| 506 |
|
|---|
| 507 |
return outbuf; |
|---|
| 508 |
} |
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 |
#ifdef TEST_MAPCRYPTO |
|---|
| 512 |
|
|---|
| 513 |
|
|---|
| 514 |
|
|---|
| 515 |
|
|---|
| 516 |
|
|---|
| 517 |
|
|---|
| 518 |
|
|---|
| 519 |
|
|---|
| 520 |
|
|---|
| 521 |
int main(int argc, char *argv[]) |
|---|
| 522 |
{ |
|---|
| 523 |
const unsigned char bytes_in[] = {0x12, 0x34, 0xff, 0x00, 0x44, 0x22}; |
|---|
| 524 |
unsigned char bytes_out[8], encryption_key[MS_ENCRYPTION_KEY_SIZE*2+1]; |
|---|
| 525 |
char string_buf[256], string_buf2[256]; |
|---|
| 526 |
int numbytes = 0; |
|---|
| 527 |
|
|---|
| 528 |
|
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 |
msHexEncode(bytes_in, string_buf, 6); |
|---|
| 532 |
printf("msHexEncode returned '%s'\n", string_buf); |
|---|
| 533 |
|
|---|
| 534 |
|
|---|
| 535 |
|
|---|
| 536 |
|
|---|
| 537 |
memset(bytes_out, 0, 8); |
|---|
| 538 |
numbytes = msHexDecode(string_buf, bytes_out, -1); |
|---|
| 539 |
printf("msHexDecode(%s, -1) = %d, bytes_out = %x, %x, %x, %x, %x, %x, %x, %x\n", |
|---|
| 540 |
string_buf, numbytes, |
|---|
| 541 |
bytes_out[0], bytes_out[1], bytes_out[2], bytes_out[3], |
|---|
| 542 |
bytes_out[4], bytes_out[5], bytes_out[6], bytes_out[7]); |
|---|
| 543 |
|
|---|
| 544 |
memset(bytes_out, 0, 8); |
|---|
| 545 |
numbytes = msHexDecode(string_buf, bytes_out, 4); |
|---|
| 546 |
printf("msHexDecode(%s, 4) = %d, bytes_out = %x, %x, %x, %x, %x, %x, %x, %x\n", |
|---|
| 547 |
string_buf, numbytes, |
|---|
| 548 |
bytes_out[0], bytes_out[1], bytes_out[2], bytes_out[3], |
|---|
| 549 |
bytes_out[4], bytes_out[5], bytes_out[6], bytes_out[7]); |
|---|
| 550 |
|
|---|
| 551 |
memset(bytes_out, 0, 8); |
|---|
| 552 |
numbytes = msHexDecode(string_buf, bytes_out, 20); |
|---|
| 553 |
printf("msHexDecode(%s, 20) = %d, bytes_out = %x, %x, %x, %x, %x, %x, %x, %x\n", |
|---|
| 554 |
string_buf, numbytes, |
|---|
| 555 |
bytes_out[0], bytes_out[1], bytes_out[2], bytes_out[3], |
|---|
| 556 |
bytes_out[4], bytes_out[5], bytes_out[6], bytes_out[7]); |
|---|
| 557 |
|
|---|
| 558 |
|
|---|
| 559 |
|
|---|
| 560 |
|
|---|
| 561 |
if (msReadEncryptionKeyFromFile("/tmp/test.key", encryption_key) != MS_SUCCESS) |
|---|
| 562 |
{ |
|---|
| 563 |
printf("msReadEncryptionKeyFromFile() = MS_FAILURE\n"); |
|---|
| 564 |
printf("Aborting tests!\n"); |
|---|
| 565 |
msWriteError(stderr); |
|---|
| 566 |
return -1; |
|---|
| 567 |
} |
|---|
| 568 |
else |
|---|
| 569 |
{ |
|---|
| 570 |
msHexEncode(encryption_key, string_buf, MS_ENCRYPTION_KEY_SIZE); |
|---|
| 571 |
printf("msReadEncryptionKeyFromFile() returned '%s'\n", string_buf); |
|---|
| 572 |
} |
|---|
| 573 |
|
|---|
| 574 |
|
|---|
| 575 |
|
|---|
| 576 |
|
|---|
| 577 |
|
|---|
| 578 |
|
|---|
| 579 |
msEncryptStringWithKey(encryption_key, "test1234", string_buf); |
|---|
| 580 |
printf("msEncryptStringWithKey('test1234') returned '%s'\n", string_buf); |
|---|
| 581 |
|
|---|
| 582 |
msDecryptStringWithKey(encryption_key, string_buf, string_buf2); |
|---|
| 583 |
printf("msDecryptStringWithKey('%s') returned '%s'\n", string_buf, string_buf2); |
|---|
| 584 |
|
|---|
| 585 |
|
|---|
| 586 |
msEncryptStringWithKey(encryption_key, "t", string_buf); |
|---|
| 587 |
printf("msEncryptStringWithKey('t') returned '%s'\n", string_buf); |
|---|
| 588 |
|
|---|
| 589 |
msDecryptStringWithKey(encryption_key, string_buf, string_buf2); |
|---|
| 590 |
printf("msDecryptStringWithKey('%s') returned '%s'\n", string_buf, string_buf2); |
|---|
| 591 |
|
|---|
| 592 |
|
|---|
| 593 |
msEncryptStringWithKey(encryption_key, "test123456", string_buf); |
|---|
| 594 |
printf("msEncryptStringWithKey('test123456') returned '%s'\n", string_buf); |
|---|
| 595 |
|
|---|
| 596 |
msDecryptStringWithKey(encryption_key, string_buf, string_buf2); |
|---|
| 597 |
printf("msDecryptStringWithKey('%s') returned '%s'\n", string_buf, string_buf2); |
|---|
| 598 |
|
|---|
| 599 |
|
|---|
| 600 |
|
|---|
| 601 |
|
|---|
| 602 |
{ |
|---|
| 603 |
char *pszBuf; |
|---|
| 604 |
mapObj *map; |
|---|
| 605 |
|
|---|
| 606 |
map = msLoadMap("/tmp/test.map", NULL); |
|---|
| 607 |
|
|---|
| 608 |
sprintf(string_buf2, "string with a {%s} encrypted token", string_buf); |
|---|
| 609 |
|
|---|
| 610 |
pszBuf = msDecryptStringTokens(map, string_buf2); |
|---|
| 611 |
if (pszBuf == NULL) |
|---|
| 612 |
{ |
|---|
| 613 |
printf("msDecryptStringTokens() failed.\n"); |
|---|
| 614 |
printf("Aborting tests!\n"); |
|---|
| 615 |
msWriteError(stderr); |
|---|
| 616 |
return -1; |
|---|
| 617 |
} |
|---|
| 618 |
else |
|---|
| 619 |
{ |
|---|
| 620 |
printf("msDecryptStringTokens('%s') returned '%s'\n", |
|---|
| 621 |
string_buf2, pszBuf); |
|---|
| 622 |
} |
|---|
| 623 |
msFree(pszBuf); |
|---|
| 624 |
msFreeMap(map); |
|---|
| 625 |
} |
|---|
| 626 |
|
|---|
| 627 |
return 0; |
|---|
| 628 |
} |
|---|
| 629 |
|
|---|
| 630 |
|
|---|
| 631 |
#endif |
|---|