2 * Copyright (c) 2011-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 #ifndef _SECOTRSESSION_H_
26 #define _SECOTRSESSION_H_
28 #include <CoreFoundation/CFBase.h>
29 #include <CoreFoundation/CFData.h>
31 #include <Security/SecOTR.h>
37 enum SecOTRSMessageKind
{
38 kOTRNegotiationPacket
,
45 enum SecOTRCreateFlags
{
46 kSecOTRSendTextMessages
= 1 << 0, // OTR messages will be encoded as Base-64 with header/footer per the standard, not just given back in binary
47 kSecOTRUseAppleCustomMessageFormat
= 1 << 1, // OTR Messages will be encoded without revealing MAC keys and as compact as we can (P-256)
48 kSecOTRIncludeHashesInMessages
= 1 << 2,
49 kSecOTRSlowRoll
= 1 << 3,
54 @abstract OTRSessions encapsulate a commuincaiton between to parties using the
56 @discussion Sessions start with IDs. One end sends a start packet (created with AppendStartPacket).
57 Both sides process packets they exchange on the negotiation channel.
59 typedef struct _SecOTRSession
* SecOTRSessionRef
;
61 SecOTRSessionRef
SecOTRSessionCreateFromID(CFAllocatorRef allocator
,
62 SecOTRFullIdentityRef myID
,
63 SecOTRPublicIdentityRef theirID
);
65 SecOTRSessionRef
SecOTRSessionCreateFromIDAndFlags(CFAllocatorRef allocator
,
66 SecOTRFullIdentityRef myID
,
67 SecOTRPublicIdentityRef theirID
,
70 SecOTRSessionRef
SecOTRSessionCreateFromData(CFAllocatorRef allocator
, CFDataRef data
);
72 void SecOTRSessionReset(SecOTRSessionRef session
);
73 OSStatus
SecOTRSAppendSerialization(SecOTRSessionRef publicID
, CFMutableDataRef serializeInto
);
75 OSStatus
SecOTRSAppendStartPacket(SecOTRSessionRef session
, CFMutableDataRef appendInitiatePacket
);
77 OSStatus
SecOTRSAppendRestartPacket(SecOTRSessionRef session
, CFMutableDataRef appendPacket
);
79 OSStatus
SecOTRSProcessPacket(SecOTRSessionRef session
,
80 CFDataRef incomingPacket
,
81 CFMutableDataRef negotiationResponse
);
83 OSStatus
SecOTRSEndSession(SecOTRSessionRef session
,
84 CFMutableDataRef messageToSend
);
87 bool SecOTRSIsForKeys(SecOTRSessionRef session
, SecKeyRef myPublic
, SecKeyRef theirPublic
);
88 bool SecOTRSGetIsReadyForMessages(SecOTRSessionRef session
);
89 bool SecOTRSGetIsIdle(SecOTRSessionRef session
);
91 enum SecOTRSMessageKind
SecOTRSGetMessageKind(SecOTRSessionRef session
, CFDataRef incomingPacket
);
95 @abstract Precalculates keys for current key sets to save time when sending or receiving.
96 @param session OTRSession receiving message
98 void SecOTRSPrecalculateKeys(SecOTRSessionRef session
);
102 @abstract Encrypts and Signs a message with OTR credentials.
103 @param session OTRSession receiving message
104 @param sourceMessage Cleartext message to protect
105 @param protectedMessage Data to append the encoded protected message to
106 @result OSStatus errSecAuthFailed -> bad signature, no data appended.
109 OSStatus
SecOTRSSignAndProtectMessage(SecOTRSessionRef session
,
110 CFDataRef sourceMessage
,
111 CFMutableDataRef protectedMessage
);
115 @abstract Verifies and exposes a message sent via OTR
116 @param session OTRSession receiving message
117 @param incomingMessage Encoded message
118 @param exposedMessageContents Data to append the exposed message to
119 @result OSStatus errSecAuthFailed -> bad signature, no data appended.
122 OSStatus
SecOTRSVerifyAndExposeMessage(SecOTRSessionRef session
,
123 CFDataRef incomingMessage
,
124 CFMutableDataRef exposedMessageContents
);
128 const char *SecOTRPacketTypeString(CFDataRef message
);
130 CFDataRef
SecOTRSessionCreateRemote(CFDataRef publicPeerId
, CFErrorRef
*error
);
131 bool SecOTRSessionProcessPacketRemote(CFDataRef sessionData
, CFDataRef inputPacket
, CFDataRef
* outputSessionData
, CFDataRef
* outputPacket
, bool *readyForMessages
, CFErrorRef
*error
);
133 bool SecOTRSessionIsSessionInAwaitingState(SecOTRSessionRef session
);