merged the modularization branch (credentials) back to trunk
This commit is contained in:
@@ -1,14 +1,6 @@
|
||||
/**
|
||||
* @file asn1.c
|
||||
*
|
||||
* @brief Simple ASN.1 parser
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006 Martin Will
|
||||
* Copyright (C) 2000-2008 Andreas Steffen
|
||||
*
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
@@ -21,7 +13,7 @@
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* RCSID $Id$
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -833,20 +825,6 @@ chunk_t asn1_wrap(asn1_t type, const char *mode, ...)
|
||||
return construct;
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a MP integer into a DER coded ASN.1 object
|
||||
*/
|
||||
chunk_t asn1_integer_from_mpz(const mpz_t value)
|
||||
{
|
||||
size_t bits = mpz_sizeinbase(value, 2); /* size in bits */
|
||||
chunk_t n;
|
||||
|
||||
n.len = 1 + bits / 8; /* size in bytes */
|
||||
n.ptr = mpz_export(NULL, NULL, 1, n.len, 1, 0, value);
|
||||
|
||||
return asn1_wrap(ASN1_INTEGER, "m", n);
|
||||
}
|
||||
|
||||
/**
|
||||
* ASN.1 definition of time
|
||||
*/
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
/**
|
||||
* @file asn1.h
|
||||
*
|
||||
* @brief Simple ASN.1 parser
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006 Martin Will
|
||||
* Copyright (C) 2000-2008 Andreas Steffen
|
||||
@@ -21,11 +14,16 @@
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* RCSID $Id$
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup asn1 asn1
|
||||
* @{ @ingroup asn1
|
||||
*/
|
||||
|
||||
#ifndef _ASN1_H
|
||||
#define _ASN1_H
|
||||
#ifndef ASN1_H_
|
||||
#define ASN1_H_
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <gmp.h>
|
||||
@@ -35,9 +33,7 @@
|
||||
|
||||
|
||||
/**
|
||||
* @brief Definition of some primitive ASN1 types
|
||||
*
|
||||
* @ingroup asn1
|
||||
* Definition of some primitive ASN1 types
|
||||
*/
|
||||
typedef enum {
|
||||
ASN1_EOC = 0x00,
|
||||
@@ -87,7 +83,6 @@ typedef enum {
|
||||
} asn1_t;
|
||||
|
||||
/* Definition of ASN1 flags */
|
||||
|
||||
#define ASN1_NONE 0x00
|
||||
#define ASN1_DEF 0x01
|
||||
#define ASN1_OPT 0x02
|
||||
@@ -100,7 +95,6 @@ typedef enum {
|
||||
#define ASN1_INVALID_LENGTH 0xffffffff
|
||||
|
||||
/* definition of an ASN.1 object */
|
||||
|
||||
typedef struct {
|
||||
u_int level;
|
||||
const u_char *name;
|
||||
@@ -141,9 +135,8 @@ extern bool is_asn1(chunk_t blob);
|
||||
|
||||
extern void code_asn1_length(size_t length, chunk_t *code);
|
||||
extern u_char* build_asn1_object(chunk_t *object, asn1_t type, size_t datalen);
|
||||
extern chunk_t asn1_integer_from_mpz(const mpz_t value);
|
||||
extern chunk_t asn1_simple_object(asn1_t tag, chunk_t content);
|
||||
extern chunk_t asn1_bitstring(const char *mode, chunk_t content);
|
||||
extern chunk_t asn1_wrap(asn1_t type, const char *mode, ...);
|
||||
|
||||
#endif /* _ASN1_H */
|
||||
#endif /* ASN1_H_ @}*/
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* RCSID $Id$
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -95,10 +95,16 @@ static err_t pem_decrypt(chunk_t *blob, encryption_algorithm_t alg, size_t key_s
|
||||
u_int8_t padding, *last_padding_pos, *first_padding_pos;
|
||||
|
||||
if (passphrase == NULL || passphrase->len == 0)
|
||||
{
|
||||
return "missing passphrase";
|
||||
}
|
||||
|
||||
/* build key from passphrase and IV */
|
||||
hasher = hasher_create(HASH_MD5);
|
||||
hasher = lib->crypto->create_hasher(lib->crypto, HASH_MD5);
|
||||
if (hasher == NULL)
|
||||
{
|
||||
return "MD5 hasher not supported";
|
||||
}
|
||||
hash.len = hasher->get_hash_size(hasher);
|
||||
hash.ptr = alloca(hash.len);
|
||||
hasher->get_hash(hasher, *passphrase, NULL);
|
||||
@@ -115,7 +121,7 @@ static err_t pem_decrypt(chunk_t *blob, encryption_algorithm_t alg, size_t key_s
|
||||
hasher->destroy(hasher);
|
||||
|
||||
/* decrypt blob */
|
||||
crypter = crypter_create(alg, key_size);
|
||||
crypter = lib->crypto->create_crypter(lib->crypto, alg, key_size);
|
||||
crypter->set_key(crypter, key);
|
||||
if (crypter->decrypt(crypter, *blob, *iv, &decrypted) != SUCCESS)
|
||||
{
|
||||
@@ -310,8 +316,8 @@ err_t pem_to_bin(chunk_t *blob, chunk_t *passphrase, bool *pgp)
|
||||
/* load a coded key or certificate file with autodetection
|
||||
* of binary DER or base64 PEM ASN.1 formats and armored PGP format
|
||||
*/
|
||||
bool pem_asn1_load_file(const char *filename, chunk_t *passphrase,
|
||||
const char *type, chunk_t *blob, bool *pgp)
|
||||
bool pem_asn1_load_file(char *filename, chunk_t *passphrase,
|
||||
chunk_t *blob, bool *pgp)
|
||||
{
|
||||
err_t ugh = NULL;
|
||||
|
||||
@@ -326,7 +332,7 @@ bool pem_asn1_load_file(const char *filename, chunk_t *passphrase,
|
||||
blob->ptr = malloc(blob->len);
|
||||
bytes = fread(blob->ptr, 1, blob->len, fd);
|
||||
fclose(fd);
|
||||
DBG1(" loading %s file '%s' (%d bytes)", type, filename, bytes);
|
||||
DBG2(" loading '%s' (%d bytes)", filename, bytes);
|
||||
|
||||
*pgp = FALSE;
|
||||
|
||||
@@ -364,7 +370,7 @@ bool pem_asn1_load_file(const char *filename, chunk_t *passphrase,
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG1(" could not open %s file '%s'", type, filename);
|
||||
DBG1(" reading file '%s' failed", filename);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
err_t pem_to_bin(chunk_t *blob, chunk_t *passphrase, bool *pgp);
|
||||
|
||||
bool pem_asn1_load_file(const char *filename, chunk_t *passphrase,
|
||||
const char *type, chunk_t *blob, bool *pgp);
|
||||
bool pem_asn1_load_file(char *filename, chunk_t *passphrase,
|
||||
chunk_t *blob, bool *pgp);
|
||||
|
||||
#endif /*PEM_H_*/
|
||||
#endif /*PEM_H_ @} */
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
|
||||
* License for more details.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include "ttodata.h"
|
||||
@@ -34,7 +36,7 @@ static const char *badch(const char *, int, char *, size_t);
|
||||
#define BADOFF(code) (BADCH0-(code))
|
||||
|
||||
/**
|
||||
* @brief convert text to data, with verbose error reports
|
||||
* convert text to data, with verbose error reports
|
||||
*
|
||||
* If some of this looks slightly odd, it's because it has changed
|
||||
* repeatedly (from the original atodata()) without a major rewrite.
|
||||
@@ -197,7 +199,7 @@ const char *ttodatav(const char *src, size_t srclen, int base, char *dst, size_t
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ttodata - convert text to data
|
||||
* ttodata - convert text to data
|
||||
*
|
||||
* @param src
|
||||
* @param srclen 0 means apply strlen()
|
||||
@@ -214,7 +216,7 @@ const char *ttodata(const char *src, size_t srclen, int base, char *dst, size_t
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief atodata - convert ASCII to data
|
||||
* atodata - convert ASCII to data
|
||||
*
|
||||
* backward-compatibility interface
|
||||
*
|
||||
@@ -234,7 +236,7 @@ size_t atodata(const char *src, size_t srclen, char *dst, size_t dstlen)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief atobytes - convert ASCII to data bytes
|
||||
* atobytes - convert ASCII to data bytes
|
||||
*
|
||||
* another backward-compatibility interface
|
||||
*/
|
||||
@@ -244,7 +246,7 @@ const char *atobytes(const char *src, size_t srclen, char *dst, size_t dstlen, s
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief unhex - convert two ASCII hex digits to byte
|
||||
* unhex - convert two ASCII hex digits to byte
|
||||
*
|
||||
* @param src known to be full length
|
||||
* @param dstnumber of result bytes, or error code
|
||||
@@ -290,7 +292,7 @@ static int unhex(const char *src, char *dst, size_t dstlen)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief unb64 - convert four ASCII base64 digits to three bytes
|
||||
* unb64 - convert four ASCII base64 digits to three bytes
|
||||
*
|
||||
* Note that a base64 digit group is padded out with '=' if it represents
|
||||
* less than three bytes: one byte is dd==, two is ddd=, three is dddd.
|
||||
@@ -368,7 +370,7 @@ static int unb64(const char *src, char *dst, size_t dstlen)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief untext - convert one ASCII character to byte
|
||||
* untext - convert one ASCII character to byte
|
||||
*
|
||||
* @param src known to be full length
|
||||
* @param dst
|
||||
@@ -386,7 +388,7 @@ static int untext(const char *src, char *dst, size_t dstlen)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief badch - produce a nice complaint about an unknown character
|
||||
* badch - produce a nice complaint about an unknown character
|
||||
*
|
||||
* If the compiler complains that the array bigenough[] has a negative
|
||||
* size, that means the TTODATAV_BUF constant has been set too small.
|
||||
|
||||
@@ -25,4 +25,4 @@
|
||||
err_t ttodata(const char *src, size_t srclen, int base, char *buf, size_t buflen, size_t *needed);
|
||||
|
||||
|
||||
#endif /* TTODATA_H_ */
|
||||
#endif /* TTODATA_H_ @} */
|
||||
|
||||
Reference in New Issue
Block a user