1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.eclipse.aether.transfer;
20
21 /**
22 * Defines transport property keys specific to HTTP transporters.
23 * These keys can be used to expose additional information about the HTTP transport operation.
24 * Additionally it defines types for the values of these keys, such as {@link HttpVersion} and {@link SslProtocol}.
25 * @see TransferEvent#getTransportProperties()
26 * @since 2.0.21
27 */
28 public final class HttpTransportProperty {
29
30 private HttpTransportProperty() {
31 // Private constructor to prevent instantiation
32 }
33
34 /**
35 * Transport property keys specific to HTTP transporters.
36 * @see TransferEvent#getTransportProperties()
37 */
38 public enum Key implements TransferEvent.TransportPropertyKey {
39 /**
40 * Transport property key for HTTP version. Value is a {@link HttpVersion} representing the HTTP version used.
41 */
42 HTTP_VERSION,
43 /**
44 * Transport property key for SSL protocol. Value is a {@link SslProtocol} representing the SSL protocol used.
45 */
46 SSL_PROTOCOL,
47 /**
48 * Transport property key for SSL cipher suite. Value is a String representing the SSL cipher suite used (e.g., "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256").
49 * @see <a href="https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#jsse-cipher-suite-names">JSSE Cipher Suite Names</a>.
50 */
51 SSL_CIPHER_SUITE,
52 /**
53 * Transport property key for content coding (usually compression). Value is a String representing the compression algorithm used (e.g., "gzip", "br", or "zstd")
54 * @see <a href="https://www.iana.org/assignments/http-parameters/http-parameters.xhtml#content-coding">Content Coding Values</a>
55 */
56 CONTENT_CODING,
57 }
58
59 /**
60 * HTTP version used for the HTTP transport.
61 */
62 public enum HttpVersion {
63 /** HTTP/1.0. */
64 HTTP_1_0("HTTP/1.0"),
65 /** HTTP/1.1. */
66 HTTP_1_1("HTTP/1.1"),
67 /** HTTP/2. */
68 HTTP_2("HTTP/2"),
69 /** HTTP/3. */
70 HTTP_3("HTTP/3");
71
72 private final String label;
73
74 HttpVersion(String label) {
75 this.label = label;
76 }
77
78 @Override
79 public String toString() {
80 return label;
81 }
82 }
83
84 /**
85 * SSL protocol including version used for the HTTP transport.
86 */
87 public enum SslProtocol {
88 /** SSL 3.0. */
89 SSL_3_0("SSLv3"),
90 /** TLS 1.0. */
91 TLS_1_0("TLSv1"),
92 /** TLS 1.1. */
93 TLS_1_1("TLSv1.1"),
94 /** TLS 1.2. */
95 TLS_1_2("TLSv1.2"),
96 /** TLS 1.3. */
97 TLS_1_3("TLSv1.3");
98
99 private final String label;
100
101 SslProtocol(String label) {
102 this.label = label;
103 }
104
105 @Override
106 public String toString() {
107 return label;
108 }
109
110 /**
111 * Converts a standard SSL protocol name to the corresponding SslProtocol enum value.
112 *
113 * @param name the standard algorithm name of the SSL protocol (e.g., "TLSv1.2", "TLSv1.3")
114 * @return the corresponding SslProtocol enum value
115 * @see <a href="https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#sslcontext-algorithms">Standard Names for SSLContext Algorithms</a>
116 */
117 public static SslProtocol fromStandardName(String name) {
118 switch (name) {
119 case "SSLv3":
120 return SSL_3_0;
121 case "TLSv1":
122 return TLS_1_0;
123 case "TLSv1.1":
124 return TLS_1_1;
125 case "TLSv1.2":
126 return TLS_1_2;
127 case "TLSv1.3":
128 return TLS_1_3;
129 default:
130 throw new IllegalArgumentException("Unknown SSL protocol: " + name);
131 }
132 }
133 }
134 }