1/* 2 * Copyright (c) 2011-2012,2014 Apple Inc. All Rights Reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24/* 25 * sslTypes.h - internal ssl types 26 */ 27 28/* This header should be kernel compatible */ 29 30#ifndef _SSLTYPES_H_ 31#define _SSLTYPES_H_ 1 32 33#include <stdbool.h> 34#include <stdint.h> 35#include <sys/types.h> 36 37#include <tls_types.h> 38 39enum { 40 errSSLRecordInternal = -10000, 41 errSSLRecordWouldBlock = -10001, 42 errSSLRecordProtocol = -10002, 43 errSSLRecordNegotiation = -10003, 44 errSSLRecordClosedAbort = -10004, 45 errSSLRecordConnectionRefused = -10005, /* peer dropped connection before responding */ 46 errSSLRecordDecryptionFail = -10006, /* decryption failure */ 47 errSSLRecordBadRecordMac = -10007, /* bad MAC */ 48 errSSLRecordRecordOverflow = -10008, /* record overflow */ 49 errSSLRecordUnexpectedRecord = -10009, /* unexpected (skipped) record in DTLS */ 50}; 51 52typedef enum 53{ 54 /* This value never appears in the actual protocol */ 55 SSL_Version_Undetermined = 0, 56 /* actual protocol values */ 57 SSL_Version_2_0 = 0x0002, 58 SSL_Version_3_0 = 0x0300, 59 TLS_Version_1_0 = 0x0301, /* TLS 1.0 == SSL 3.1 */ 60 TLS_Version_1_1 = 0x0302, 61 TLS_Version_1_2 = 0x0303, 62 DTLS_Version_1_0 = 0xfeff, 63} SSLProtocolVersion; 64 65/* FIXME: This enum and the SSLRecord are exposed because they 66 are used at the interface between the Record and Handshake layer. 67 This might not be the best idea */ 68 69enum 70{ SSL_RecordTypeV2_0, 71 SSL_RecordTypeV3_Smallest = 20, 72 SSL_RecordTypeChangeCipher = 20, 73 SSL_RecordTypeAlert = 21, 74 SSL_RecordTypeHandshake = 22, 75 SSL_RecordTypeAppData = 23, 76 SSL_RecordTypeV3_Largest = 23 77}; 78 79typedef enum 80{ 81 kSSLRecordOptionSendOneByteRecord = 0, 82} SSLRecordOption; 83 84/* 85 * This is the buffer type used internally. 86 */ 87typedef tls_buffer SSLBuffer; 88 89/* 90struct 91{ size_t length; 92 uint8_t *data; 93} SSLBuffer; 94*/ 95 96typedef struct 97{ 98 uint8_t contentType; 99 SSLProtocolVersion protocolVersion; 100 SSLBuffer contents; 101} SSLRecord; 102 103 104/* 105 * We should remove this and use uint64_t all over. 106 */ 107typedef uint64_t sslUint64; 108 109 110/* Opaque reference to a Record Context */ 111typedef void * SSLRecordContextRef; 112 113 114typedef int 115(*SSLRecordReadFunc) (SSLRecordContextRef ref, 116 SSLRecord *rec); 117 118typedef int 119(*SSLRecordWriteFunc) (SSLRecordContextRef ref, 120 SSLRecord rec); 121 122typedef int 123(*SSLRecordInitPendingCiphersFunc) (SSLRecordContextRef ref, 124 uint16_t selectedCipher, 125 bool server, 126 SSLBuffer key); 127 128typedef int 129(*SSLRecordAdvanceWriteCipherFunc) (SSLRecordContextRef ref); 130 131typedef int 132(*SSLRecordRollbackWriteCipherFunc) (SSLRecordContextRef ref); 133 134typedef int 135(*SSLRecordAdvanceReadCipherFunc) (SSLRecordContextRef ref); 136 137typedef int 138(*SSLRecordSetProtocolVersionFunc) (SSLRecordContextRef ref, 139 SSLProtocolVersion protocolVersion); 140 141typedef int 142(*SSLRecordFreeFunc) (SSLRecordContextRef ref, 143 SSLRecord rec); 144 145typedef int 146(*SSLRecordServiceWriteQueueFunc) (SSLRecordContextRef ref); 147 148typedef int 149(*SSLRecordSetOptionFunc) (SSLRecordContextRef ref, 150 SSLRecordOption option, 151 bool value); 152 153struct SSLRecordFuncs 154{ 155 SSLRecordReadFunc read; 156 SSLRecordWriteFunc write; 157 SSLRecordInitPendingCiphersFunc initPendingCiphers; 158 SSLRecordAdvanceWriteCipherFunc advanceWriteCipher; 159 SSLRecordRollbackWriteCipherFunc rollbackWriteCipher; 160 SSLRecordAdvanceReadCipherFunc advanceReadCipher; 161 SSLRecordSetProtocolVersionFunc setProtocolVersion; 162 SSLRecordFreeFunc free; 163 SSLRecordServiceWriteQueueFunc serviceWriteQueue; 164 SSLRecordSetOptionFunc setOption; 165}; 166 167#endif /* _SSLTYPES_H_ */ 168