ARC SDK
CertUtil.h
1 #ifndef __ARC_CERTUTIL_H__
2 #define __ARC_CERTUTIL_H__
3 
4 #include <string>
5 #include <openssl/pem.h>
6 #include <openssl/x509.h>
7 #include <openssl/stack.h>
8 
9 #include <arc/credential/Proxycertinfo.h>
10 
11 namespace ArcCredential {
12 
13  #define PROXYCERTINFO_V3 "1.3.6.1.4.1.3536.1.222"
14  #ifdef HAVE_OPENSSL_PROXY
15  #define PROXYCERTINFO_V4 "1.3.6.1.5.5.7.1.1400"
16  #else
17  #define PROXYCERTINFO_V4 "1.3.6.1.5.5.7.1.14"
18  #endif
19  #define PROXYCERTINFO_OPENSSL "1.3.6.1.5.5.7.1.14"
20 
21 
23 
24  typedef enum {
51  } certType;
52 
54  #define CERT_IS_PROXY(cert_type) \
55  (cert_type == CERT_TYPE_GSI_3_IMPERSONATION_PROXY || \
56  cert_type == CERT_TYPE_GSI_3_INDEPENDENT_PROXY || \
57  cert_type == CERT_TYPE_GSI_3_LIMITED_PROXY || \
58  cert_type == CERT_TYPE_GSI_3_RESTRICTED_PROXY || \
59  cert_type == CERT_TYPE_RFC_IMPERSONATION_PROXY || \
60  cert_type == CERT_TYPE_RFC_INDEPENDENT_PROXY || \
61  cert_type == CERT_TYPE_RFC_LIMITED_PROXY || \
62  cert_type == CERT_TYPE_RFC_RESTRICTED_PROXY || \
63  cert_type == CERT_TYPE_RFC_ANYLANGUAGE_PROXY || \
64  cert_type == CERT_TYPE_GSI_2_PROXY || \
65  cert_type == CERT_TYPE_GSI_2_LIMITED_PROXY)
66 
68  #define CERT_IS_RFC_PROXY(cert_type) \
69  (cert_type == CERT_TYPE_RFC_IMPERSONATION_PROXY || \
70  cert_type == CERT_TYPE_RFC_INDEPENDENT_PROXY || \
71  cert_type == CERT_TYPE_RFC_LIMITED_PROXY || \
72  cert_type == CERT_TYPE_RFC_RESTRICTED_PROXY || \
73  cert_type == CERT_TYPE_RFC_ANYLANGUAGE_PROXY)
74 
76  #define CERT_IS_GSI_3_PROXY(cert_type) \
77  (cert_type == CERT_TYPE_GSI_3_IMPERSONATION_PROXY || \
78  cert_type == CERT_TYPE_GSI_3_INDEPENDENT_PROXY || \
79  cert_type == CERT_TYPE_GSI_3_LIMITED_PROXY || \
80  cert_type == CERT_TYPE_GSI_3_RESTRICTED_PROXY)
81 
83  #define CERT_IS_GSI_2_PROXY(cert_type) \
84  (cert_type == CERT_TYPE_GSI_2_PROXY || \
85  cert_type == CERT_TYPE_GSI_2_LIMITED_PROXY)
86 
87  #define CERT_IS_INDEPENDENT_PROXY(cert_type) \
88  (cert_type == CERT_TYPE_RFC_INDEPENDENT_PROXY || \
89  cert_type == CERT_TYPE_GSI_3_INDEPENDENT_PROXY)
90 
91  #define CERT_IS_RESTRICTED_PROXY(cert_type) \
92  (cert_type == CERT_TYPE_RFC_RESTRICTED_PROXY || \
93  cert_type == CERT_TYPE_GSI_3_RESTRICTED_PROXY)
94 
95  #define CERT_IS_LIMITED_PROXY(cert_type) \
96  (cert_type == CERT_TYPE_RFC_LIMITED_PROXY || \
97  cert_type == CERT_TYPE_GSI_3_LIMITED_PROXY || \
98  cert_type == CERT_TYPE_GSI_2_LIMITED_PROXY)
99 
100  #define CERT_IS_IMPERSONATION_PROXY(cert_type) \
101  (cert_type == CERT_TYPE_RFC_IMPERSONATION_PROXY || \
102  cert_type == CERT_TYPE_RFC_LIMITED_PROXY || \
103  cert_type == CERT_TYPE_GSI_3_IMPERSONATION_PROXY || \
104  cert_type == CERT_TYPE_GSI_3_LIMITED_PROXY || \
105  cert_type == CERT_TYPE_GSI_2_PROXY || \
106  cert_type == CERT_TYPE_GSI_2_LIMITED_PROXY)
107 
108  /* VERIFY_CTX_STORE_EX_DATA_IDX here could be temporal solution.
109  * OpenSSL >= 098 has get_proxy_auth_ex_data_idx() which is
110  * specific for proxy extention.
111  */
112  #define VERIFY_CTX_STORE_EX_DATA_IDX 1
113 
115  typedef struct {
116  X509_STORE_CTX * cert_store;
117  int cert_depth;
118  int proxy_depth;
119  int max_proxy_depth;
120  int limited_proxy;
121  certType cert_type;
122  STACK_OF(X509) * cert_chain; /* X509 */
123  std::string ca_dir;
124  std::string ca_file;
125  std::string proxy_policy; /* The policy attached to proxy cert info extension*/
127 
128  int verify_cert_chain(X509* cert, STACK_OF(X509)** certchain, cert_verify_context* vctx);
129  bool check_cert_type(X509* cert, certType& type);
130  const char* certTypeToString(certType type);
131 
132 }
133 
134 #endif // __ARC_CERTUTIL_H__
135