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.internal.tcnative; 18 19 /** 20 * Session Ticket Key 21 */ 22 public final class SessionTicketKey { 23 /** 24 * Size of session ticket key name 25 */ 26 public static final int NAME_SIZE = 16; 27 /** 28 * Size of session ticket key HMAC key 29 */ 30 public static final int HMAC_KEY_SIZE = 16; 31 /** 32 * Size of session ticket key AES key 33 */ 34 public static final int AES_KEY_SIZE = 16; 35 /** 36 * Size of session ticket key 37 */ 38 public static final int TICKET_KEY_SIZE = NAME_SIZE + HMAC_KEY_SIZE + AES_KEY_SIZE; 39 40 // package private so we can access these in SSLContext without calling clone() on the byte[]. 41 final byte[] name; 42 final byte[] hmacKey; 43 final byte[] aesKey; 44 45 /** 46 * Construct SessionTicketKey. 47 * @param name the name of the session ticket key 48 * @param hmacKey the HMAC key of the session ticket key 49 * @param aesKey the AES key of the session ticket key 50 */ SessionTicketKey(byte[] name, byte[] hmacKey, byte[] aesKey)51 public SessionTicketKey(byte[] name, byte[] hmacKey, byte[] aesKey) { 52 if (name == null || name.length != NAME_SIZE) { 53 throw new IllegalArgumentException("Length of name should be " + NAME_SIZE); 54 } 55 if (hmacKey == null || hmacKey.length != HMAC_KEY_SIZE) { 56 throw new IllegalArgumentException("Length of hmacKey should be " + HMAC_KEY_SIZE); 57 } 58 if (aesKey == null || aesKey.length != AES_KEY_SIZE) { 59 throw new IllegalArgumentException("Length of aesKey should be " + AES_KEY_SIZE); 60 } 61 this.name = name; 62 this.hmacKey = hmacKey; 63 this.aesKey = aesKey; 64 } 65 66 /** 67 * Get name. 68 * 69 * @return the name of the session ticket key 70 */ getName()71 public byte[] getName() { 72 return name.clone(); 73 } 74 75 /** 76 * Get HMAC key. 77 * @return the HMAC key of the session ticket key 78 */ getHmacKey()79 public byte[] getHmacKey() { 80 return hmacKey.clone(); 81 } 82 83 /** 84 * Get AES Key. 85 * @return the AES key of the session ticket key 86 */ getAesKey()87 public byte[] getAesKey() { 88 return aesKey.clone(); 89 } 90 } 91