~ubuntu-branches/ubuntu/saucy/resiprocate/saucy-proposed

« back to all changes in this revision

Viewing changes to reflow/dtls_wrapper/DtlsFactory.cxx

  • Committer: Package Import Robot
  • Author(s): Daniel Pocock
  • Date: 2012-05-17 19:29:59 UTC
  • Revision ID: package-import@ubuntu.com-20120517192959-vv00m77isztdy64q
Tags: upstream-1.8.2
ImportĀ upstreamĀ versionĀ 1.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifdef HAVE_CONFIG_H
 
2
#include "config.h"
 
3
#endif
 
4
 
 
5
#ifdef USE_SSL
 
6
 
 
7
#include <cassert>
 
8
#include <iostream>
 
9
#include <rutil/ssl/OpenSSLInit.hxx>
 
10
 
 
11
#include <openssl/e_os2.h>
 
12
#include <openssl/rand.h>
 
13
#include <openssl/err.h>
 
14
#include <openssl/crypto.h>
 
15
#include <openssl/ssl.h>
 
16
 
 
17
#include "DtlsFactory.hxx"
 
18
#include "DtlsSocket.hxx"
 
19
 
 
20
using namespace dtls;
 
21
const char* DtlsFactory::DefaultSrtpProfile = "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32";
 
22
 
 
23
DtlsFactory::DtlsFactory(std::auto_ptr<DtlsTimerContext> tc,X509 *cert, EVP_PKEY *privkey):
 
24
   mTimerContext(tc),
 
25
   mCert(cert)
 
26
{
 
27
   int r;
 
28
 
 
29
   mContext=SSL_CTX_new(DTLSv1_method());
 
30
   assert(mContext);
 
31
 
 
32
   r=SSL_CTX_use_certificate(mContext, cert);
 
33
   assert(r==1);
 
34
 
 
35
   r=SSL_CTX_use_PrivateKey(mContext, privkey);
 
36
   assert(r==1);
 
37
 
 
38
   // Set SRTP profiles
 
39
   r=SSL_CTX_set_tlsext_use_srtp(mContext, DefaultSrtpProfile);
 
40
   assert(r==0);
 
41
}
 
42
 
 
43
DtlsFactory::~DtlsFactory()
 
44
{
 
45
   SSL_CTX_free(mContext);
 
46
}
 
47
 
 
48
 
 
49
DtlsSocket*
 
50
DtlsFactory::createClient(std::auto_ptr<DtlsSocketContext> context)
 
51
{
 
52
   return new DtlsSocket(context,this,DtlsSocket::Client);
 
53
}
 
54
 
 
55
DtlsSocket*
 
56
DtlsFactory::createServer(std::auto_ptr<DtlsSocketContext> context)
 
57
{
 
58
   return new DtlsSocket(context,this,DtlsSocket::Server);  
 
59
}
 
60
 
 
61
void
 
62
DtlsFactory::getMyCertFingerprint(char *fingerprint)
 
63
{
 
64
   DtlsSocket::computeFingerprint(mCert,fingerprint);
 
65
}
 
66
 
 
67
void
 
68
DtlsFactory::setSrtpProfiles(const char *str)
 
69
{
 
70
   int r;
 
71
 
 
72
   r=SSL_CTX_set_tlsext_use_srtp(mContext,str);
 
73
 
 
74
   assert(r==0);
 
75
}
 
76
 
 
77
void
 
78
DtlsFactory::setCipherSuites(const char *str)
 
79
{
 
80
   int r;
 
81
 
 
82
   r=SSL_CTX_set_cipher_list(mContext,str);
 
83
   assert(r==1);
 
84
}
 
85
 
 
86
DtlsFactory::PacketType
 
87
DtlsFactory::demuxPacket(const unsigned char *data, unsigned int len) 
 
88
{
 
89
   assert(len>=1);
 
90
 
 
91
   if((data[0]==0)   || (data[0]==1))
 
92
      return stun;
 
93
   if((data[0]>=128) && (data[0]<=191))
 
94
      return rtp;
 
95
   if((data[0]>=20)  && (data[0]<=64))
 
96
      return dtls;
 
97
 
 
98
   return unknown;
 
99
}
 
100
 
 
101
#endif //USE_SSL
 
102
 
 
103
 
 
104
/* ====================================================================
 
105
 
 
106
 Copyright (c) 2007-2008, Eric Rescorla and Derek MacDonald 
 
107
 All rights reserved.
 
108
 
 
109
 Redistribution and use in source and binary forms, with or without
 
110
 modification, are permitted provided that the following conditions are 
 
111
 met:
 
112
 
 
113
 1. Redistributions of source code must retain the above copyright 
 
114
    notice, this list of conditions and the following disclaimer. 
 
115
 
 
116
 2. Redistributions in binary form must reproduce the above copyright
 
117
    notice, this list of conditions and the following disclaimer in the
 
118
    documentation and/or other materials provided with the distribution. 
 
119
 
 
120
 3. None of the contributors names may be used to endorse or promote 
 
121
    products derived from this software without specific prior written 
 
122
    permission. 
 
123
 
 
124
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 
125
 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 
126
 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 
127
 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 
128
 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
129
 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 
130
 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 
131
 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 
132
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 
133
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 
134
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
135
 
 
136
 ==================================================================== */