View Javadoc
1   /*
2    * Copyright 2016 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  
17  package io.netty.handler.codec.haproxy;
18  
19  import io.netty.buffer.ByteBuf;
20  
21  import java.util.Collections;
22  import java.util.List;
23  
24  /**
25   * Represents a {@link HAProxyTLV} of the type {@link HAProxyTLV.Type#PP2_TYPE_SSL}.
26   * This TLV encapsulates other TLVs and has additional information like verification information and a client bitfield.
27   */
28  public final class HAProxySSLTLV extends HAProxyTLV {
29  
30      private final int verify;
31      private final List<HAProxyTLV> tlvs;
32      private final byte clientBitField;
33  
34      /**
35       * Creates a new HAProxySSLTLV
36       *
37       * @param verify the verification result as defined in the specification for the pp2_tlv_ssl struct (see
38       * http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt)
39       * @param clientBitField the bitfield with client information
40       * @param tlvs the encapsulated {@link HAProxyTLV}s
41       * @param rawContent the raw TLV content
42       */
43      HAProxySSLTLV(final int verify, final byte clientBitField, final List<HAProxyTLV> tlvs, final ByteBuf rawContent) {
44          super(Type.PP2_TYPE_SSL, (byte) 0x20, rawContent);
45  
46          this.verify = verify;
47          this.tlvs = Collections.unmodifiableList(tlvs);
48          this.clientBitField = clientBitField;
49      }
50  
51      /**
52       * Returns {@code true} if the bit field for PP2_CLIENT_CERT_CONN was set
53       */
54      public boolean isPP2ClientCertConn() {
55          return (clientBitField & 0x2) != 0;
56      }
57  
58      /**
59       * Returns {@code true} if the bit field for PP2_CLIENT_SSL was set
60       */
61      public boolean isPP2ClientSSL() {
62          return (clientBitField & 0x1) != 0;
63      }
64  
65      /**
66       * Returns {@code true} if the bit field for PP2_CLIENT_CERT_SESS was set
67       */
68      public boolean isPP2ClientCertSess() {
69          return (clientBitField & 0x4) != 0;
70      }
71  
72      /**
73       * Returns the verification result
74       */
75      public int verify() {
76          return verify;
77      }
78  
79      /**
80       * Returns an unmodifiable Set of encapsulated {@link HAProxyTLV}s.
81       */
82      public List<HAProxyTLV> encapsulatedTLVs() {
83          return tlvs;
84      }
85  
86  }