View Javadoc
1   /*
2    * Copyright 2022 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    *   https://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  package io.netty5.handler.ssl;
17  
18  import javax.net.ssl.SSLEngine;
19  
20  /**
21   * Provides compression and decompression implementations for TLS Certificate Compression
22   * (<a href="https://tools.ietf.org/html/rfc8879">RFC 8879</a>).
23   */
24  public interface OpenSslCertificateCompressionAlgorithm {
25  
26      /**
27       * Compress the given input with the specified algorithm and return the compressed bytes.
28       *
29       * @param engine                    the {@link SSLEngine}
30       * @param uncompressedCertificate   the uncompressed certificate
31       * @return                          the compressed form of the certificate
32       * @throws Exception                thrown if an error occurs while compressing
33       */
34      byte[] compress(SSLEngine engine, byte[] uncompressedCertificate) throws Exception;
35  
36      /**
37       * Decompress the given input with the specified algorithm and return the decompressed bytes.
38       *
39       * <h3>Implementation
40       * <a href="https://tools.ietf.org/html/rfc8879#section-5">Security Considerations</a></h3>
41       * <p>Implementations SHOULD bound the memory usage when decompressing the CompressedCertificate message.</p>
42       * <p>
43       * Implementations MUST limit the size of the resulting decompressed chain to the specified {@code uncompressedLen},
44       * and they MUST abort the connection (throw an exception) if the size of the output of the decompression
45       * function exceeds that limit.
46       * </p>
47       *
48       * @param engine                    the {@link SSLEngine}
49       * @param uncompressedLen           the expected length of the decompressed certificate that will be returned.
50       * @param compressedCertificate     the compressed form of the certificate
51       * @return                          the decompressed form of the certificate
52       * @throws Exception                thrown if an error occurs while decompressing or output size exceeds
53       *                                  {@code uncompressedLen}
54       */
55      byte[] decompress(SSLEngine engine, int uncompressedLen, byte[] compressedCertificate) throws Exception;
56  
57      /**
58       * Return the ID for the compression algorithm provided for by a given implementation.
59       *
60       * @return compression algorithm ID as specified by
61       * <a href="https://datatracker.ietf.org/doc/html/rfc8879">RFC8879</a>.
62       */
63      int algorithmId();
64  }