001/* 002 * Copyright 2017-2019 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2017-2019 Ping Identity Corporation 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021package com.unboundid.util.ssl.cert; 022 023 024 025import com.unboundid.util.OID; 026import com.unboundid.util.ThreadSafety; 027import com.unboundid.util.ThreadSafetyLevel; 028 029 030 031/** 032 * This enum defines a set of OIDs that are known to be associated with elliptic 033 * curve keys. 034 */ 035@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 036public enum NamedCurve 037{ 038 /** 039 * The brainpoolP256r1 curve. 040 */ 041 BRAINPOOLP256R1("1.3.36.3.3.2.8.1.1.7", "brainpoolP256r1"), 042 043 044 045 /** 046 * The brainpoolP384r1 curve. 047 */ 048 BRAINPOOLP384R1("1.3.36.3.3.2.8.1.1.11", "brainpoolP384r1"), 049 050 051 052 /** 053 * The brainpoolP512r1 curve. 054 */ 055 BRAINPOOLP512R1("1.3.36.3.3.2.8.1.1.13", "brainpoolP512r1"), 056 057 058 059 /** 060 * The secP160k1 curve. 061 */ 062 SECP160K1("1.3.132.0.9", "secP160k1"), 063 064 065 066 /** 067 * The secP160r1 curve. 068 */ 069 SECP160R1("1.3.132.0.8", "secP160r1"), 070 071 072 073 /** 074 * The secP160r2 curve. 075 */ 076 SECP160R2("1.3.132.0.30", "secP160r2"), 077 078 079 080 /** 081 * The secP192k1 curve. 082 */ 083 SECP192K1("1.3.132.0.31", "secP192k1"), 084 085 086 087 /** 088 * The secP192r1 curve (also known as nistP192). 089 */ 090 SECP192R1("1.2.840.10045.3.1.1", "secP192r1"), 091 092 093 094 /** 095 * The secP224k1 curve. 096 */ 097 SECP224K1("1.3.132.0.32", "secP224k1"), 098 099 100 101 /** 102 * The secP224r1 curve (also known as nistP224). 103 */ 104 SECP224R1("1.3.132.0.33", "secP224r1"), 105 106 107 108 /** 109 * The secP256k1 curve. 110 */ 111 SECP256K1("1.3.132.0.10", "secP256k1"), 112 113 114 115 /** 116 * The secP256r1 curve (also known as nistP256). 117 */ 118 SECP256R1("1.2.840.10045.3.1.7", "secP256r1"), 119 120 121 122 /** 123 * The secP384r1 curve (also known as nistP384). 124 */ 125 SECP384R1("1.3.132.0.34", "secP384r1"), 126 127 128 129 /** 130 * The secP521r1 curve (also known as nistP521). 131 */ 132 SECP521R1("1.3.132.0.35", "secP521r1"), 133 134 135 136 /** 137 * The secT163k1 curve. 138 */ 139 SECT163K1("1.3.132.0.1", "secT163k1"), 140 141 142 143 /** 144 * The secT163r2 curve. 145 */ 146 SECT163R2("1.3.132.0.15", "secT163r2"), 147 148 149 150 /** 151 * The secT233k1 curve. 152 */ 153 SECT233K1("1.3.132.0.26", "secT233k1"), 154 155 156 157 /** 158 * The secT233r1 curve. 159 */ 160 SECT233R1("1.3.132.0.27", "secT233r1"), 161 162 163 164 /** 165 * The secT283k1 curve. 166 */ 167 SECT283K1("1.3.132.0.16", "secT283k1"), 168 169 170 171 /** 172 * The secT283r1 curve. 173 */ 174 SECT283R1("1.3.132.0.17", "secT283r1"), 175 176 177 178 /** 179 * The secT409k1 curve. 180 */ 181 SECT409K1("1.3.132.0.36", "secT409k1"), 182 183 184 185 /** 186 * The secT409r1 curve. 187 */ 188 SECT409R1("1.3.132.0.37", "secT409r1"), 189 190 191 192 /** 193 * The secT571k1 curve. 194 */ 195 SECT571K1("1.3.132.0.38", "secT571k1"), 196 197 198 199 /** 200 * The secT571r1 curve. 201 */ 202 SECT571R1("1.3.132.0.39", "secT571r1"); 203 204 205 206 // The OID for this extended key usage ID value. 207 private final OID oid; 208 209 // The name for this extended key usage ID value. 210 private final String name; 211 212 213 214 /** 215 * Creates a new named curve value with the provided information. 216 * 217 * @param oidString The string representation of the OID for this named 218 * curve value. 219 * @param name The name for this named curve value. 220 */ 221 NamedCurve(final String oidString, final String name) 222 { 223 this.name = name; 224 225 oid = new OID(oidString); 226 } 227 228 229 230 /** 231 * Retrieves the OID for this named curve value. 232 * 233 * @return The OID for this named curve value. 234 */ 235 public OID getOID() 236 { 237 return oid; 238 } 239 240 241 242 /** 243 * Retrieves the name for this named curve value. 244 * 245 * @return The name for this named curve value. 246 */ 247 public String getName() 248 { 249 return name; 250 } 251 252 253 254 /** 255 * Retrieves the named curve value with the specified OID. 256 * 257 * @param oid The OID of the named curve value to retrieve. It must not be 258 * {@code null}. 259 * 260 * @return The named curve value with the specified OID, or {@code null} if 261 * there is no value with the specified OID. 262 */ 263 public static NamedCurve forOID(final OID oid) 264 { 265 for (final NamedCurve curve : values()) 266 { 267 if (curve.oid.equals(oid)) 268 { 269 return curve; 270 } 271 } 272 273 return null; 274 } 275 276 277 278 /** 279 * Retrieves the name for the named curve value with the provided OID, or a 280 * string representation of the OID if there is no value with that OID. 281 * 282 * @param oid The OID for the named curve to retrieve. 283 * 284 * @return The name for the named curve value with the provided OID, or a 285 * string representation of the OID if there is no value with that 286 * OID. 287 */ 288 public static String getNameOrOID(final OID oid) 289 { 290 final NamedCurve curve = forOID(oid); 291 if (curve == null) 292 { 293 return oid.toString(); 294 } 295 else 296 { 297 return curve.name; 298 } 299 } 300 301 302 303 /** 304 * Retrieves the named curve with the specified name. 305 * 306 * @param name The name of the named curve to retrieve. It must not be 307 * {@code null}. 308 * 309 * @return The requested named curve, or {@code null} if no such curve is 310 * defined. 311 */ 312 public static NamedCurve forName(final String name) 313 { 314 for (final NamedCurve namedCurve : NamedCurve.values()) 315 { 316 if (namedCurve.name.equalsIgnoreCase(name) || 317 namedCurve.name().equalsIgnoreCase(name)) 318 { 319 return namedCurve; 320 } 321 } 322 323 return null; 324 } 325}