00001 #include "orbsvcs/SSLIOP/SSLIOP_Credentials.h"
00002
00003 #include "tao/ORB_Constants.h"
00004
00005 #include "ace/SString.h"
00006
00007
00008 ACE_RCSID (SSLIOP,
00009 SSLIOP_Credentials,
00010 "SSLIOP_Credentials.cpp,v 1.25 2006/03/14 06:14:35 jtc Exp")
00011
00012
00013 #if !defined (__ACE_INLINE__)
00014 # include "orbsvcs/SSLIOP/SSLIOP_Credentials.inl"
00015 #endif
00016
00017 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00018
00019 TAO::SSLIOP_Credentials::SSLIOP_Credentials (::X509 *cert, ::EVP_PKEY *evp)
00020 : x509_ (TAO::SSLIOP::OpenSSL_traits< ::X509 >::_duplicate (cert)),
00021 evp_ (TAO::SSLIOP::OpenSSL_traits< ::EVP_PKEY >::_duplicate (evp)),
00022 id_ (),
00023 creds_usage_ (SecurityLevel3::CU_Indefinite),
00024 expiry_time_ (),
00025 creds_state_ (SecurityLevel3::CS_Invalid)
00026 {
00027 ::X509 *x = cert;
00028
00029 if (x != 0)
00030 {
00031
00032
00033 BIGNUM * bn = ASN1_INTEGER_to_BN (::X509_get_serialNumber (x), 0);
00034 if (BN_is_zero (bn))
00035 this->id_ = CORBA::string_dup ("X509: 00");
00036 else
00037 {
00038 char * id = BN_bn2hex (bn);
00039
00040 ACE_CString s =
00041 ACE_CString ("X509: ")
00042 + ACE_CString (const_cast<const char *> (id));
00043
00044 this->id_ = CORBA::string_dup (s.c_str ());
00045
00046 #ifdef OPENSSL_free
00047 OPENSSL_free (id);
00048 #else
00049
00050
00051 CRYPTO_free (id);
00052 #endif
00053 }
00054
00055
00056
00057 TimeBase::UtcT & t = this->expiry_time_;
00058
00059 const ASN1_TIME * exp = X509_get_notAfter (x);
00060
00061 if (exp->length > ACE_SIZEOF_LONG_LONG)
00062 {
00063
00064
00065
00066 t.time = ACE_UINT64_LITERAL (0xffffffffffffffff);
00067 }
00068 else
00069 {
00070 t.time = 0;
00071 for (int i = 0; i < exp->length; ++i)
00072 {
00073 t.time <<= 8;
00074 t.time |= (unsigned char) exp->data[i];
00075 }
00076 }
00077 }
00078 }
00079
00080 TAO::SSLIOP_Credentials::~SSLIOP_Credentials (void)
00081 {
00082 }
00083
00084 char *
00085 TAO::SSLIOP_Credentials::creds_id (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
00086 ACE_THROW_SPEC ((CORBA::SystemException))
00087 {
00088 return CORBA::string_dup (this->id_.in ());
00089 }
00090
00091 SecurityLevel3::CredentialsUsage
00092 TAO::SSLIOP_Credentials::creds_usage (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
00093 ACE_THROW_SPEC ((CORBA::SystemException))
00094 {
00095 return SecurityLevel3::CU_Indefinite;
00096 }
00097
00098 TimeBase::UtcT
00099 TAO::SSLIOP_Credentials::expiry_time (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
00100 ACE_THROW_SPEC ((CORBA::SystemException))
00101 {
00102 return this->expiry_time_;
00103 }
00104
00105 SecurityLevel3::CredentialsState
00106 TAO::SSLIOP_Credentials::creds_state (ACE_ENV_SINGLE_ARG_DECL)
00107 ACE_THROW_SPEC ((CORBA::SystemException))
00108 {
00109 const ::X509 *x = this->x509_.in ();
00110
00111
00112
00113 if (x == 0)
00114 ACE_THROW_RETURN (CORBA::BAD_OPERATION (),
00115 SecurityLevel3::CS_Invalid);
00116
00117 if (this->creds_state_ == SecurityLevel3::CS_Valid)
00118 {
00119
00120
00121 const int after_status =
00122 ::X509_cmp_current_time (X509_get_notAfter (x));
00123
00124 if (after_status == 0)
00125 {
00126
00127 ACE_THROW_RETURN (CORBA::BAD_PARAM (),
00128 SecurityLevel3::CS_Invalid);
00129 }
00130 else if (after_status > 0)
00131 this->creds_state_ = SecurityLevel3::CS_Expired;
00132 }
00133 else if (this->creds_state_ == SecurityLevel3::CS_Invalid)
00134 {
00135
00136
00137 const int before_status =
00138 ::X509_cmp_current_time (X509_get_notBefore (x));
00139
00140 if (before_status == 0)
00141 {
00142
00143 ACE_THROW_RETURN (CORBA::BAD_PARAM (),
00144 SecurityLevel3::CS_Invalid);
00145 }
00146 else if (before_status < 0)
00147 this->creds_state_ = SecurityLevel3::CS_Valid;
00148 }
00149
00150 return this->creds_state_;
00151 }
00152
00153 char *
00154 TAO::SSLIOP_Credentials::add_relinquished_listener (
00155 SecurityLevel3::RelinquishedCredentialsListener_ptr
00156 ACE_ENV_ARG_DECL)
00157 ACE_THROW_SPEC ((CORBA::SystemException))
00158 {
00159 ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), 0);
00160 }
00161
00162 void
00163 TAO::SSLIOP_Credentials::remove_relinquished_listener (const char *
00164 ACE_ENV_ARG_DECL)
00165 ACE_THROW_SPEC ((CORBA::SystemException))
00166 {
00167 ACE_THROW (CORBA::NO_IMPLEMENT ());
00168 }
00169
00170 bool
00171 TAO::SSLIOP_Credentials::operator== (const TAO::SSLIOP_Credentials &rhs)
00172 {
00173 ::X509 * xa = this->x509_.in ();
00174 ::X509 * xb = rhs.x509_.in ();
00175
00176
00177
00178 ACE_DECLARE_NEW_CORBA_ENV;
00179
00180
00181 const SecurityLevel3::CredentialsType lct =
00182 this->creds_type (ACE_ENV_SINGLE_ARG_PARAMETER);
00183 ACE_CHECK_RETURN (false);
00184
00185 const SecurityLevel3::CredentialsType rct =
00186 const_cast<TAO::SSLIOP_Credentials &> (rhs).creds_type (
00187 ACE_ENV_SINGLE_ARG_PARAMETER);
00188 ACE_CHECK_RETURN (false);
00189
00190
00191
00192
00193
00194
00195
00196
00197 return
00198 lct == rct
00199 && this->creds_usage_ == rhs.creds_usage_
00200 && ((xa == xb) || (xa != 0 && xb != 0 && ::X509_cmp (xa, xb) == 0))
00201
00202 ;
00203 }
00204
00205 CORBA::ULong
00206 TAO::SSLIOP_Credentials::hash (void) const
00207 {
00208 ::X509 * x509 = this->x509_.in ();
00209
00210 return (x509 == 0 ? 0 : ::X509_issuer_name_hash (x509));
00211 }
00212
00213 TAO::SSLIOP::Credentials_ptr
00214 TAO::SSLIOP_Credentials::_narrow (CORBA::Object_ptr obj
00215 ACE_ENV_ARG_DECL_NOT_USED)
00216 {
00217 return TAO::SSLIOP_Credentials::_duplicate (
00218 dynamic_cast<TAO::SSLIOP_Credentials *> (obj));
00219 }
00220
00221 TAO::SSLIOP::Credentials_ptr
00222 TAO::SSLIOP_Credentials::_duplicate (TAO::SSLIOP::Credentials_ptr obj)
00223 {
00224 if (!CORBA::is_nil (obj))
00225 obj->_add_ref ();
00226
00227 return obj;
00228 }
00229
00230
00231
00232 TAO::SSLIOP::Credentials_ptr
00233 tao_TAO_SSLIOP_Credentials_duplicate (TAO::SSLIOP::Credentials_ptr p)
00234 {
00235 return TAO::SSLIOP_Credentials::_duplicate (p);
00236 }
00237
00238 void
00239 tao_TAO_SSLIOP_Credentials_release (TAO::SSLIOP::Credentials_ptr p)
00240 {
00241 CORBA::release (p);
00242 }
00243
00244 TAO::SSLIOP::Credentials_ptr
00245 tao_TAO_SSLIOP_Credentials_nil (void)
00246 {
00247 return TAO::SSLIOP_Credentials::_nil ();
00248 }
00249
00250 TAO::SSLIOP::Credentials_ptr
00251 tao_TAO_SSLIOP_Credentials_narrow (CORBA::Object *p
00252 ACE_ENV_ARG_DECL)
00253 {
00254 return TAO::SSLIOP_Credentials::_narrow (p
00255 ACE_ENV_ARG_PARAMETER);
00256 }
00257
00258 CORBA::Object_ptr
00259 tao_TAO_SSLIOP_Credentials_upcast (void *src)
00260 {
00261 TAO::SSLIOP_Credentials **tmp =
00262 static_cast<TAO::SSLIOP_Credentials **> (src);
00263
00264 return *tmp;
00265 }
00266
00267 TAO_END_VERSIONED_NAMESPACE_DECL