1// Copyright 2012 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef POLO_PAIRING_PAIRINGCONTEXT_H_
16#define POLO_PAIRING_PAIRINGCONTEXT_H_
17
18#include <openssl/x509v3.h>
19#include <openssl/ssl.h>
20
21namespace polo {
22namespace pairing {
23
24// Context for a Polo pairing session.
25class PairingContext {
26 public:
27  // Creates a new Polo pairing context. This class does not take ownership of
28  // the certificates but they must remain valid for as long as this context
29  // exists.
30  // @param local_certificate the local SSL certificate
31  // @param peer_certificate the peer SSL certificate
32  // @param server whether this client is acting as the pairing server
33  PairingContext(X509* local_certificate,
34                 X509* peer_certificate,
35                 bool server);
36
37  // Sets the local certificate. No ownership is taken of the given pointer.
38  void set_local_certificate(X509 *local_certificate);
39
40  // Sets the peer certificate. No ownership is taken of the given pointer.
41  void set_peer_certificate(X509 *peer_certificate);
42
43  // Gets the client certificate.
44  X509* client_certificate() const;
45
46  // Gets the server certificate.
47  X509* server_certificate() const;
48
49  // Determines whether this client is the pairing server.
50  bool is_server() const;
51
52  // Determines whether this client is the pairing client.
53  bool is_client() const;
54
55 private:
56  X509 *local_certificate_;
57  X509 *peer_certificate_;
58  bool server_;
59};
60
61}  // namespace pairing
62}  // namespace polo
63
64#endif  // POLO_PAIRING_PAIRINGCONTEXT_H_
65