1 
2 /* ****************************************************************************
3 
4  * eID Middleware Project.
5  * Copyright (C) 2008-2012 FedICT.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License version
9  * 3.0 as published by the Free Software Foundation.
10  *
11  * This software is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this software; if not, see
18  * http://www.gnu.org/licenses/.
19 
20 **************************************************************************** */
21 #ifndef __CERT_H__
22 #define __CERT_H__
23 
24 #include "asn1.h"
25 
26 #ifdef WIN32
27 #define snprintf _snprintf
28 #else
29 #define strnicmp strncasecmp
30 #endif
31 
32 /* constants */
33 #define LEN_DATE  14
34 #define MAX_OID_SIZE  32
35 #define MAX_OID_STR_SIZE 1024
36 #define MAX_DATE_STR_SIZE 1024
37 
38 /* errors */
39 #define E_X509_BUF_TOO_SMALL         -1
40 #define E_X509_TIME_WRONG_FORMAT     -2
41 #define E_X509_DECODE                -3
42 #define E_X509_ALLOC                 -4
43 #define E_X509_UNKNOWN_KEYTYPE       -5
44 #define E_X509_DN_BAD_ENC            -6
45 #define E_X509_INCOMPLETE            -7
46 
47 #ifdef __cplusplus
48 extern "C"
49 {
50 #endif
51 	/* x509v3:
52 		SubjectPublicKeyInfo																		/1 1 7/
53 
54 		SubjectPublicKeyInfo  ::=  SEQUENCE  {
55         algorithm            AlgorithmIdentifier,													/1 1 7 1/
56 		subjectPublicKey     BIT STRING  }															/1 1 7 2/
57 
58 		AlgorithmIdentifier  ::=  SEQUENCE  {														/1 1 7 1/
59 		algorithm               OBJECT IDENTIFIER,													/1 1 7 1 1/
60 		parameters              ANY DEFINED BY algorithm OPTIONAL 									/1 1 7 1 2/(should be NULL for RSA, defines curve type for EC (see EcpkParameters))
61 
62 	 for RSA:
63 		in subjectPublicKey     BIT STRING:															/1 1 7 2/
64 		RSAPublicKey ::= SEQUENCE {																	/1 1 7 2 1/(sequence in the bitstring, so first jump into the bitstring, then one deeper into the sequence)
65 		modulus            INTEGER,    -- n															/1 1 7 2 1 1/
66 		publicExponent     INTEGER  }  -- e															/1 1 7 2 1 2/
67 
68 	 for EC:
69 
70 		in subjectPublicKey     BIT STRING:															/1 1 7 2/
71 		The elliptic curve public key (an ECPoint which is an OCTET STRING)
72 		is mapped to a subjectPublicKey (a BIT STRING)												/1 1 7 2 1/(jump into the bitstring)
73 
74 		EcpkParameters ::= CHOICE {
75 		ecParameters  ECParameters(SEQUENCE),
76 		namedCurve    OBJECT IDENTIFIER,															/1 1 7 1 2/
77 		implicitlyCA  NULL }
78 
79 */
80 
81 
82 #define X509_VERSION          "\1\1\1\1"
83 #define X509_SERIAL           "\1\1\2"
84 #define X509_SIGN_ALGO	      "\1\1\3"
85 #define X509_ISSUER           "\1\1\4"
86 #define X509_VALID_FROM       "\1\1\5\1"
87 #define X509_VALID_UNTIL      "\1\1\5\2"
88 #define X509_SUBJECT          "\1\1\6"
89 #define X509_KEYTYPE          "\1\1\7\1\1"
90 #define X509_EC_CURVE	      "\1\1\7\1\2"
91 #define X509_PUBLIC_KEY       "\1\1\7\2"
92 #define X509_PKINFO           "\1\1\7\2\1"
93 #define X509_RSA_MOD          "\1\1\7\2\1\1"
94 #define X509_RSA_EXP          "\1\1\7\2\1\2"
95 
96 #define X509_SIGNATURE_OID    "\1\2\1"
97 #define X509_SIGNATURE        "\1\3"
98 
99 	typedef struct
100 	{
101 		unsigned int lcert;
102 		char *subject;
103 		unsigned int l_subject;
104 		char *issuer;
105 		unsigned int l_issuer;
106 		char *mod;
107 		unsigned int l_mod;
108 		char *exp;
109 		unsigned int l_exp;
110 		char *pkinfo;
111 		unsigned int l_pkinfo;
112 		char *serial;
113 		unsigned int l_serial;
114 		char *validfrom;
115 		unsigned int l_validfrom;
116 		char *validto;
117 		unsigned int l_validto;
118 		char *curve;
119 		unsigned int l_curve;
120 	} T_CERT_INFO;
121 
122 
123 	int cert_get_info(const unsigned char *pcert, unsigned int lcert,
124 			  T_CERT_INFO * info);
125 	void cert_free_info(T_CERT_INFO * info);
126 
127 #ifdef __cplusplus
128 }
129 #endif
130 
131 
132 #endif
133