SSLIOP_Current_Impl.cpp

Go to the documentation of this file.
00001 #include "orbsvcs/SSLIOP/SSLIOP_Current_Impl.h"
00002 
00003 #include "ace/OS_String.h"
00004 
00005 
00006 ACE_RCSID (SSLIOP,
00007            SSLIOP_Current_Impl,
00008            "SSLIOP_Current_Impl.cpp,v 1.19 2006/03/14 06:14:35 jtc Exp")
00009 
00010 
00011 #if !defined (__ACE_INLINE__)
00012 # include "orbsvcs/SSLIOP/SSLIOP_Current_Impl.inl"
00013 #endif /* __ACE_INLINE__ */
00014 
00015 #include "orbsvcs/SSLIOP/SSLIOP_X509.h"
00016 #include "orbsvcs/SSLIOP/SSLIOP_ClientCredentials.h"
00017 
00018 #include "tao/ORB_Constants.h"
00019 
00020 #include <openssl/x509.h>
00021 
00022 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00023 
00024 TAO::SSLIOP::Current_Impl::~Current_Impl (void)
00025 {
00026 }
00027 
00028 SecurityLevel3::ClientCredentials_ptr
00029 TAO::SSLIOP::Current_Impl::client_credentials (
00030     ACE_ENV_SINGLE_ARG_DECL)
00031   ACE_THROW_SPEC ((CORBA::SystemException))
00032 {
00033   TAO::SSLIOP::X509_var cert = ::SSL_get_peer_certificate (this->ssl_);
00034   if (cert.ptr () == 0)
00035     ACE_THROW_RETURN (CORBA::BAD_OPERATION (),
00036                       SecurityLevel3::ClientCredentials::_nil ());
00037 
00038   SecurityLevel3::ClientCredentials_ptr creds;
00039   ACE_NEW_THROW_EX (creds,
00040                     TAO::SSLIOP::ClientCredentials (cert.in (),
00041                                                     0,
00042                                                     this->ssl_),
00043                     CORBA::NO_MEMORY (
00044                       CORBA::SystemException::_tao_minor_code (
00045                         TAO::VMCID,
00046                         ENOMEM),
00047                       CORBA::COMPLETED_NO));
00048   ACE_CHECK_RETURN (SecurityLevel3::ClientCredentials::_nil ());
00049 
00050   return creds;
00051 }
00052 
00053 CORBA::Boolean
00054 TAO::SSLIOP::Current_Impl::request_is_local (ACE_ENV_SINGLE_ARG_DECL)
00055   ACE_THROW_SPEC ((CORBA::SystemException))
00056 {
00057   ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), 0);
00058 }
00059 
00060 void
00061 TAO::SSLIOP::Current_Impl::get_peer_certificate (
00062   ::SSLIOP::ASN_1_Cert *certificate)
00063 {
00064   if (this->ssl_ == 0)
00065     return;
00066 
00067   TAO::SSLIOP::X509_var cert = ::SSL_get_peer_certificate (this->ssl_);
00068   if (cert.ptr () == 0)
00069     return;
00070 
00071   // Get the size of the ASN.1 encoding.
00072   const int cert_length = ::i2d_X509 (cert.in (), 0);
00073   if (cert_length <= 0)
00074     return;
00075 
00076   certificate->length (cert_length);
00077 
00078   CORBA::Octet *buffer = certificate->get_buffer ();
00079 
00080   // Convert from the internal X509 representation to the DER encoding
00081   // representation.
00082   (void) ::i2d_X509 (cert.in (), &buffer);
00083 }
00084 
00085 void
00086 TAO::SSLIOP::Current_Impl::get_peer_certificate_chain (
00087   ::SSLIOP::SSL_Cert *cert_chain)
00088 {
00089   if (this->ssl_ == 0)
00090     return;
00091 
00092   STACK_OF (X509) *certs = ::SSL_get_peer_cert_chain (this->ssl_);
00093   if (certs == 0)
00094     return;
00095 
00096   const int chain_length = sk_X509_num (certs);
00097   cert_chain->length (chain_length);
00098 
00099   // Copy the peer certificate chain to the SSLIOP::SSL_Cert
00100   // sequence.
00101   for (int i = 0; i < chain_length; ++i)
00102     {
00103       // Extract the certificate from the OpenSSL X509 stack.
00104       ::X509 *x = sk_X509_value (certs, i);
00105 
00106       // Get the size of the ASN.1 encoding.
00107       const int cert_length = ::i2d_X509 (x, 0);
00108       if (cert_length <= 0)
00109         continue;  // @@ What do we do if there is an error?
00110 
00111       ::SSLIOP::ASN_1_Cert &certificate = (*cert_chain)[i];
00112       certificate.length (cert_length);
00113 
00114       CORBA::Octet *buffer = certificate.get_buffer ();
00115 
00116       // Convert from the internal X509 representation to the DER
00117       // encoding representation.
00118       (void) ::i2d_X509 (x, &buffer);
00119     }
00120 }
00121 
00122 CORBA::ULong
00123 TAO::SSLIOP::Current_Impl::tag (void) const
00124 {
00125   return ::SSLIOP::TAG_SSL_SEC_TRANS;
00126 }
00127 
00128 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 13:54:14 2006 for TAO_SSLIOP by doxygen 1.3.6